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



83
84
85
86
87
88
# File 'app/controllers/people_controller.rb', line 83

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

- (Object) autocomplete_params (private)



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

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

- (Object) create

POST /people POST /people.json



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/people_controller.rb', line 30

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



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

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



104
105
106
107
# File 'app/controllers/people_controller.rb', line 104

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

- (Object) download

GET /people/download



91
92
93
# File 'app/controllers/people_controller.rb', line 91

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

- (Object) edit

GET /people/1/edit



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

def edit
end

- (Object) index

GET /people GET /people.json



8
9
10
11
12
# File 'app/controllers/people_controller.rb', line 8

def index
  @people         = Person.order(updated_at: :desc).limit(10)
  @recent_objects = @people
  render '/shared/data/all/index'
end

- (Object) list



69
70
71
# File 'app/controllers/people_controller.rb', line 69

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

- (Object) new

GET /people/new



20
21
22
# File 'app/controllers/people_controller.rb', line 20

def new
  @person = Person.new
end

- (Object) person_params (private)



120
121
122
123
124
125
126
127
# File 'app/controllers/people_controller.rb', line 120

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



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

def role_types
  render json: ROLES
end

- (Object) roles



95
96
# File 'app/controllers/people_controller.rb', line 95

def roles
end

- (Object) search

TODO: deprecate!



74
75
76
77
78
79
80
81
# File 'app/controllers/people_controller.rb', line 74

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)



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

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

- (Object) show

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



16
17
# File 'app/controllers/people_controller.rb', line 16

def show
end

- (Object) update

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



47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/people_controller.rb', line 47

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