Class: PeopleController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::SharedDataControllerConfiguration
Defined in:
app/controllers/people_controller.rb

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::SharedDataControllerConfiguration

#set_is_shared_data_model

Methods included from RedirectHelper

#destroy_redirect

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#api_indexObject

GET /api/v1/people



142
143
144
145
146
147
148
# File 'app/controllers/people_controller.rb', line 142

def api_index
  @people = Queries::Person::Filter.new(params.merge!(api: true)).all
    .order('people.id')
    .page(params[:page])
    .per(params[:per])
  render '/people/api/v1/index'
end

#api_showObject

GET /api/v1/people/:id



151
152
153
# File 'app/controllers/people_controller.rb', line 151

def api_show
  render '/people/api/v1/show'
end

#autocompleteObject



98
99
100
101
102
103
# File 'app/controllers/people_controller.rb', line 98

def autocomplete
  @people = Queries::Person::Autocomplete.new(
    params.permit(:term)[:term],
    **autocomplete_params
  ).autocomplete
end

#autocomplete_paramsObject (private)



157
158
159
160
161
162
163
# File 'app/controllers/people_controller.rb', line 157

def autocomplete_params
  params.permit(
    :in_project,
    :role_type,
    role_type: []
  ).to_h.symbolize_keys.merge(project_id: sessions_current_project_id)
end

#createObject

POST /people POST /people.json



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/people_controller.rb', line 41

def create
  @person = Person.new(person_params)
  respond_to do |format|
    if @person.save
      format.html {redirect_to url_for(@person.metamorphosize),
                   notice: "Person '#{@person.name}' was successfully created."}
      format.json {render action: 'show', status: :created, location: @person}
    else
      format.html {render action: 'new'}
      format.json {render json: @person.errors, status: :unprocessable_entity}
    end
  end
end

#destroyObject

DELETE /people/1 DELETE /people/1.json



71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/people_controller.rb', line 71

def destroy
  @person.destroy
  respond_to do |format|
    if @person.destroyed?
      format.html { destroy_redirect @person, notice: 'Person was successfully destroyed.' }
      format.json {head :no_content}
    else
      format.html { destroy_redirect @person, notice: 'Person was not destroyed, ' + @person.errors.full_messages.join('; ') }
      format.json { render json: @person.errors, status: :unprocessable_entity }
    end
  end
end

#detailsObject

GET /person/:id/details



136
137
138
139
# File 'app/controllers/people_controller.rb', line 136

def details
  @person = Person.includes(:roles).find(params[:id])
  render partial: '/people/picker_details', locals: {person: @person}
end

#downloadObject

GET /people/download



122
123
124
# File 'app/controllers/people_controller.rb', line 122

def download
  send_data Export::Csv.generate_csv(Person.all), type: 'text', filename: "people_#{DateTime.now}.tsv"
end

#editObject

GET /people/1/edit



36
37
# File 'app/controllers/people_controller.rb', line 36

def edit
end

#indexObject

GET /people GET /people.json



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/people_controller.rb', line 9

def index
  respond_to do |format|
    format.html {
      @people = Person.order(updated_at: :desc).limit(10)
      @recent_objects = @people
      render '/shared/data/all/index'
    }
    format.json {
      @people = Queries::Person::Filter.new(params).all
      .order(:cached)
      .page(params[:page])
      .per(params[:per])
    }
  end
end

#listObject



84
85
86
# File 'app/controllers/people_controller.rb', line 84

def list
  @people = Person.order(:cached).page(params[:page])
end

#mergeObject

POST /people/merge



111
112
113
114
115
116
117
118
119
# File 'app/controllers/people_controller.rb', line 111

def merge
  @person = Person.find(params[:id]) # the person to *keep*
  person_to_remove = Person.find(params[:person_to_destroy])
  if @person.hard_merge(person_to_remove.id)
    render 'show'
  else
    render json: { error: 'Failed. Check to see that both People are not linked to the same record, e.g. Authors on the same Source.' }, status: :conflict
  end
end

#merge_paramsObject (private)



180
181
182
183
184
185
# File 'app/controllers/people_controller.rb', line 180

def merge_params
  params.require(:person).permit(
    :old_person_id,
    :new_person_id
  )
end

#newObject

GET /people/new



31
32
33
# File 'app/controllers/people_controller.rb', line 31

def new
  @person = Person.new
end

#person_paramsObject (private)



170
171
172
173
174
175
176
177
178
# File 'app/controllers/people_controller.rb', line 170

def person_params
  params.require(:person).permit(
    :type,
    :no_namecase,
    :last_name, :first_name,
    :suffix, :prefix,
    :year_born, :year_died, :year_active_start, :year_active_end
  )
end

#role_typesObject

GET /people/role_types.json



131
132
133
# File 'app/controllers/people_controller.rb', line 131

def role_types
  render json: ROLES
end

#rolesObject

GET /people/123/roles



127
128
# File 'app/controllers/people_controller.rb', line 127

def roles
end

#searchObject

TODO: deprecate!



89
90
91
92
93
94
95
96
# File 'app/controllers/people_controller.rb', line 89

def search
  if params[:id].blank?
    redirect_to people_path, notice: 'You must select an item from the list with a click ' \
      'or tab press before clicking show.'
  else
    redirect_to person_path(params[:id])
  end
end

#select_optionsObject

GET /people/select_options



106
107
108
# File 'app/controllers/people_controller.rb', line 106

def select_options
  @people = Person.select_optimized(sessions_current_user_id, sessions_current_project_id, params[:target])
end

#set_personObject (private)



165
166
167
168
# File 'app/controllers/people_controller.rb', line 165

def set_person
  @person = Person.find(params[:id])
  @recent_object = @person
end

#showObject

GET /people/1 GET /people/1.json



27
28
# File 'app/controllers/people_controller.rb', line 27

def show
end

#updateObject

PATCH/PUT /people/1 PATCH/PUT /people/1.json



57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/people_controller.rb', line 57

def update
  respond_to do |format|
    if @person.update(person_params)
      format.html {redirect_to url_for(@person.metamorphosize), notice: 'Person was successfully updated.'}
      format.json {head :no_content}
    else
      format.html {render action: 'edit'}
      format.json {render json: @person.errors, status: :unprocessable_entity}
    end
  end
end