Class: PeopleController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- PeopleController
- Defined in:
- app/controllers/people_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
-
#api_index ⇒ Object
GET /api/v1/people.
-
#api_show ⇒ Object
GET /api/v1/people/:id.
- #autocomplete ⇒ Object
- #autocomplete_params ⇒ Object private
-
#create ⇒ Object
POST /people POST /people.json.
-
#destroy ⇒ Object
DELETE /people/1 DELETE /people/1.json.
-
#details ⇒ Object
GET /person/:id/details.
-
#download ⇒ Object
GET /people/download.
-
#edit ⇒ Object
GET /people/1/edit.
-
#index ⇒ Object
GET /people GET /people.json.
- #list ⇒ Object
-
#merge ⇒ Object
POST /people/merge.
- #merge_params ⇒ Object private
-
#new ⇒ Object
GET /people/new.
- #person_params ⇒ Object private
-
#role_types ⇒ Object
GET /people/role_types.json.
-
#roles ⇒ Object
GET /people/123/roles.
-
#search ⇒ Object
TODO: deprecate!.
-
#select_options ⇒ Object
GET /people/select_options.
- #set_person ⇒ Object private
-
#show ⇒ Object
GET /people/1 GET /people/1.json.
-
#update ⇒ Object
PATCH/PUT /people/1 PATCH/PUT /people/1.json.
Methods included from DataControllerConfiguration::SharedDataControllerConfiguration
Methods included from RedirectHelper
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
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, #week_in_review_graphs
Methods included from Api::Intercept
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#api_index ⇒ Object
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_show ⇒ Object
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 |
#autocomplete ⇒ Object
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_params ⇒ Object (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 |
#create ⇒ Object
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.), 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 |
#destroy ⇒ Object
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..join('; ') } format.json { render json: @person.errors, status: :unprocessable_entity } end end end |
#details ⇒ Object
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 |
#download ⇒ Object
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 |
#edit ⇒ Object
GET /people/1/edit
36 37 |
# File 'app/controllers/people_controller.rb', line 36 def edit end |
#index ⇒ Object
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 |
#list ⇒ Object
84 85 86 |
# File 'app/controllers/people_controller.rb', line 84 def list @people = Person.order(:cached).page(params[:page]) end |
#merge ⇒ Object
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_params ⇒ Object (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 |
#new ⇒ Object
GET /people/new
31 32 33 |
# File 'app/controllers/people_controller.rb', line 31 def new @person = Person.new end |
#person_params ⇒ Object (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_types ⇒ Object
GET /people/role_types.json
131 132 133 |
# File 'app/controllers/people_controller.rb', line 131 def role_types render json: ROLES end |
#roles ⇒ Object
GET /people/123/roles
127 128 |
# File 'app/controllers/people_controller.rb', line 127 def roles end |
#search ⇒ Object
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_options ⇒ Object
GET /people/select_options
106 107 108 |
# File 'app/controllers/people_controller.rb', line 106 def @people = Person.select_optimized(sessions_current_user_id, sessions_current_project_id, params[:target]) end |
#set_person ⇒ Object (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 |
#show ⇒ Object
GET /people/1 GET /people/1.json
27 28 |
# File 'app/controllers/people_controller.rb', line 27 def show end |
#update ⇒ Object
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.), 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 |