Class: PeopleController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#is_data_controller, #is_task_controller, #meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary (collapse)

Methods included from DataControllerConfiguration::SharedDataControllerConfiguration

#set_is_shared_data_model

Methods inherited from ApplicationController

#digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #project_matches, #record_not_found, #set_project_from_params

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Methods included from InterceptApi

#intercept_api, #token_authenticate

Instance Method Details

- (Object) autocomplete



94
95
96
97
98
99
# File 'app/controllers/people_controller.rb', line 94

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

- (Object) autocomplete_params (private)



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

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

- (Object) create

POST /people POST /people.json



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/people_controller.rb', line 37

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

- (Object) destroy

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



72
73
74
75
76
77
78
# File 'app/controllers/people_controller.rb', line 72

def destroy
  @person.destroy!
  respond_to do |format|
    format.html {redirect_to people_url}
    format.json {head :no_content}
  end
end

- (Object) details

GET /person/:id/details



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

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

- (Object) download

GET /people/download



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

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

- (Object) edit

GET /people/1/edit



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

def edit
end

- (Object) filter_params (private)



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

def filter_params
  params.permit(:last_name, :first_name, :last_name_starts_with, roles: [])
end

- (Object) index

GET /people GET /people.json



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

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

- (Object) list



80
81
82
# File 'app/controllers/people_controller.rb', line 80

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

- (Object) merge



105
106
107
108
109
110
111
112
113
# File 'app/controllers/people_controller.rb', line 105

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

- (Object) merge_params (private)



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

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

- (Object) new

GET /people/new



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

def new
  @person = Person.new
end

- (Object) person_params (private)



149
150
151
152
153
154
155
156
# File 'app/controllers/people_controller.rb', line 149

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

- (Object) role_types

GET /people/role_types.json



124
125
126
# File 'app/controllers/people_controller.rb', line 124

def role_types
  render json: ROLES
end

- (Object) roles



120
121
# File 'app/controllers/people_controller.rb', line 120

def roles
end

- (Object) search

TODO: deprecate!



85
86
87
88
89
90
91
92
# File 'app/controllers/people_controller.rb', line 85

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

- (Object) select_options



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

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

- (Object) set_person (private)



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

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

- (Object) show

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



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

def show
end

- (Object) similar



51
52
53
54
# File 'app/controllers/people_controller.rb', line 51

def similar
  @people =  Queries::Person::Filter.new(last_name: @person.last_name, first_name: @person.first_name, levenshtein_cuttoff: 3).levenshtein_similar.order(:last_name, :first_name) 
  render '/people/index'
end

- (Object) update

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



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

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