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 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
134 135 136 137 138 139 |
# File 'app/controllers/people_controller.rb', line 134 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)
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'app/controllers/people_controller.rb', line 175 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
142 143 144 |
# File 'app/controllers/people_controller.rb', line 142 def api_show render '/people/api/v1/show' end |
#autocomplete ⇒ Object
90 91 92 93 94 95 |
# File 'app/controllers/people_controller.rb', line 90 def autocomplete @people = Queries::Person::Autocomplete.new( params.permit(:term)[:term], autocomplete_params ).autocomplete end |
#autocomplete_params ⇒ Object (private)
202 203 204 |
# File 'app/controllers/people_controller.rb', line 202 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 |
# File 'app/controllers/people_controller.rb', line 68 def destroy @person.destroy! respond_to do |format| format.html {redirect_to people_url} format.json {head :no_content} end end |
#details ⇒ Object
GET /person/:id/details
128 129 130 131 |
# File 'app/controllers/people_controller.rb', line 128 def details @person = Person.includes(:roles).find(params[:id]) render partial: '/people/picker_details', locals: {person: @person} end |
#download ⇒ Object
GET /people/download
114 115 116 |
# File 'app/controllers/people_controller.rb', line 114 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)
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'app/controllers/people_controller.rb', line 148 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
76 77 78 |
# File 'app/controllers/people_controller.rb', line 76 def list @people = Person.order(:cached).page(params[:page]) end |
#merge ⇒ Object
POST /people/merge
103 104 105 106 107 108 109 110 111 |
# File 'app/controllers/people_controller.rb', line 103 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: {status: 'Failed. Check to see that both People are not linked to the same record, e.g. Authors on the same Source.'} end end |
#merge_params ⇒ Object (private)
221 222 223 224 225 226 |
# File 'app/controllers/people_controller.rb', line 221 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)
211 212 213 214 215 216 217 218 219 |
# File 'app/controllers/people_controller.rb', line 211 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
123 124 125 |
# File 'app/controllers/people_controller.rb', line 123 def role_types render json: ROLES end |
#roles ⇒ Object
GET /people/123/roles
119 120 |
# File 'app/controllers/people_controller.rb', line 119 def roles end |
#search ⇒ Object
TODO: deprecate!
81 82 83 84 85 86 87 88 |
# File 'app/controllers/people_controller.rb', line 81 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
98 99 100 |
# File 'app/controllers/people_controller.rb', line 98 def @people = Person.select_optimized(sessions_current_user_id, sessions_current_project_id, params[:role_type]) end |
#set_person ⇒ Object (private)
206 207 208 209 |
# File 'app/controllers/people_controller.rb', line 206 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 |