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

#clear_project_and_user_variables, #digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #intercept_api, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #notice_user, #project_matches, #record_not_found, #set_project_and_user_variables, #set_project_from_params, #token_authenticate, #whitelist_constantize

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

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.require(:term),
      autocomplete_params
  ).autocomplete
end

- (Object) autocomplete_params (private)



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

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



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

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

- (Object) download

GET /people/download



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

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)



132
133
134
# File 'app/controllers/people_controller.rb', line 132

def filter_params
  params.permit(:last_name, :first_name, 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
    }
  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



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

def merge
  old_person = Person.find(params[:id])
  @person = Person.find(params[:new_person_id])
  if old_person.merge_with(@person.id)
    render 'show'
  else
    render json: {status: 'Failed'}
  end
end

- (Object) merge_params (private)



154
155
156
157
158
159
# File 'app/controllers/people_controller.rb', line 154

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)



145
146
147
148
149
150
151
152
# File 'app/controllers/people_controller.rb', line 145

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



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

def role_types
  render json: ROLES
end

- (Object) roles



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

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



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

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 = @person.levenshtein_similar(2).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