Class: PeopleController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- PeopleController
- Defined in:
- app/controllers/people_controller.rb
Instance Method Summary collapse
-
#api_index ⇒ Object
GET /api/v1/people.
- #api_params ⇒ Object private
-
#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.
- #filter_params ⇒ Object private
-
#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
#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form
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
139 140 141 142 143 144 |
# File 'app/controllers/people_controller.rb', line 139 def api_index @people = Queries::Person::Filter.new(api_params).all .order('people.id') .page(params[:page]).per(params[:per]) render '/people/api/v1/index' end |
#api_params ⇒ Object (private)
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'app/controllers/people_controller.rb', line 180 def api_params params.permit( :name, :last_name, :first_name, :last_name_starts_with, :born_after_year, :born_before_year, :active_after_year, :active_before_year, :died_before_year, :died_after_year, :role, :identifier, :identifier_end, :identifier_exact, :identifier_start, :user_date_end, :user_date_start, :user_id, :user_target, :tags, # user_id: [], keyword_id_and: [], keyword_id_or: [], role: [], person_wildcard: [] ) end |
#api_show ⇒ Object
GET /api/v1/people/:id
147 148 149 |
# File 'app/controllers/people_controller.rb', line 147 def api_show render '/people/api/v1/show' end |
#autocomplete ⇒ Object
95 96 97 98 99 100 |
# File 'app/controllers/people_controller.rb', line 95 def autocomplete @people = Queries::Person::Autocomplete.new( params.permit(:term)[:term], **autocomplete_params ).autocomplete end |
#autocomplete_params ⇒ Object (private)
207 208 209 |
# File 'app/controllers/people_controller.rb', line 207 def autocomplete_params params.permit(roles: []).to_h.symbolize_keys end |
#create ⇒ Object
POST /people POST /people.json
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/people_controller.rb', line 38 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
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/people_controller.rb', line 68 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
133 134 135 136 |
# File 'app/controllers/people_controller.rb', line 133 def details @person = Person.includes(:roles).find(params[:id]) render partial: '/people/picker_details', locals: {person: @person} end |
#download ⇒ Object
GET /people/download
119 120 121 |
# File 'app/controllers/people_controller.rb', line 119 def download send_data Export::Download.generate_csv(Person.all), type: 'text', filename: "people_#{DateTime.now}.csv" end |
#edit ⇒ Object
GET /people/1/edit
33 34 |
# File 'app/controllers/people_controller.rb', line 33 def edit end |
#filter_params ⇒ Object (private)
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'app/controllers/people_controller.rb', line 153 def filter_params params.permit( :name, :last_name, :first_name, :last_name_starts_with, :born_after_year, :born_before_year, :active_after_year, :active_before_year, :died_before_year, :died_after_year, :levenshtein_cuttoff, :identifier, :identifier_end, :identifier_exact, :identifier_start, :user_date_end, :user_date_start, :user_id, :user_target, used_in_project_id: [], keyword_id_and: [], keyword_id_or: [], role: [], person_wildcard: [], user_id: [] ) end |
#index ⇒ Object
GET /people GET /people.json
9 10 11 12 13 14 15 16 17 18 19 20 |
# 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(filter_params).all.order(:cached).page(params[:page]).per(params[:per]) } end end |
#list ⇒ Object
81 82 83 |
# File 'app/controllers/people_controller.rb', line 81 def list @people = Person.order(:cached).page(params[:page]) end |
#merge ⇒ Object
POST /people/merge
108 109 110 111 112 113 114 115 116 |
# File 'app/controllers/people_controller.rb', line 108 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)
226 227 228 229 230 231 |
# File 'app/controllers/people_controller.rb', line 226 def merge_params params.require(:person).permit( :old_person_id, :new_person_id ) end |
#new ⇒ Object
GET /people/new
28 29 30 |
# File 'app/controllers/people_controller.rb', line 28 def new @person = Person.new end |
#person_params ⇒ Object (private)
216 217 218 219 220 221 222 223 224 |
# File 'app/controllers/people_controller.rb', line 216 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
128 129 130 |
# File 'app/controllers/people_controller.rb', line 128 def role_types render json: ROLES end |
#roles ⇒ Object
GET /people/123/roles
124 125 |
# File 'app/controllers/people_controller.rb', line 124 def roles end |
#search ⇒ Object
TODO: deprecate!
86 87 88 89 90 91 92 93 |
# File 'app/controllers/people_controller.rb', line 86 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
103 104 105 |
# File 'app/controllers/people_controller.rb', line 103 def @people = Person.select_optimized(sessions_current_user_id, sessions_current_project_id, params[:target]) end |
#set_person ⇒ Object (private)
211 212 213 214 |
# File 'app/controllers/people_controller.rb', line 211 def set_person @person = Person.find(params[:id]) @recent_object = @person end |
#show ⇒ Object
GET /people/1 GET /people/1.json
24 25 |
# File 'app/controllers/people_controller.rb', line 24 def show end |
#update ⇒ Object
PATCH/PUT /people/1 PATCH/PUT /people/1.json
54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/people_controller.rb', line 54 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 |