Class: PeopleController

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

Instance Method Summary collapse

Methods included from DataControllerConfiguration::SharedDataControllerConfiguration

#set_is_shared_data_model

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

#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form

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



133
134
135
136
137
138
# File 'app/controllers/people_controller.rb', line 133

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_paramsObject (private)



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'app/controllers/people_controller.rb', line 173

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_ids: [],
    role: [],
    person_wildcard: []
  )
end

#api_showObject

GET /api/v1/people/:id



141
142
143
# File 'app/controllers/people_controller.rb', line 141

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

#autocompleteObject



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_paramsObject (private)



199
200
201
# File 'app/controllers/people_controller.rb', line 199

def autocomplete_params
  params.permit(roles: []).to_h.symbolize_keys
end

#createObject

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.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



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

#detailsObject

GET /person/:id/details



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

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

#downloadObject

GET /people/download



113
114
115
# File 'app/controllers/people_controller.rb', line 113

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

#editObject

GET /people/1/edit



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

def edit
end

#filter_paramsObject (private)



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'app/controllers/people_controller.rb', line 147

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_ids: [],
    role: [],
    person_wildcard: [],
    user_id: []
  )
end

#indexObject

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

#listObject



76
77
78
# File 'app/controllers/people_controller.rb', line 76

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

#mergeObject



102
103
104
105
106
107
108
109
110
# File 'app/controllers/people_controller.rb', line 102

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'}
  end
end

#merge_paramsObject (private)



218
219
220
221
222
223
# File 'app/controllers/people_controller.rb', line 218

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

#newObject

GET /people/new



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

def new
  @person = Person.new
end

#person_paramsObject (private)



208
209
210
211
212
213
214
215
216
# File 'app/controllers/people_controller.rb', line 208

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



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

def role_types
  render json: ROLES
end

#rolesObject

GET /people/123/roles



118
119
# File 'app/controllers/people_controller.rb', line 118

def roles
end

#searchObject

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_optionsObject

GET /people/select_options



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

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

#set_personObject (private)



203
204
205
206
# File 'app/controllers/people_controller.rb', line 203

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

#showObject

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



24
25
# File 'app/controllers/people_controller.rb', line 24

def show
end

#updateObject

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.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