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

Instance Method Details

- (Object) autocomplete



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

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

- (Object) autocomplete_params (private)



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

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

- (Object) create

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

- (Object) destroy

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



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

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



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

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

- (Object) download

GET /people/download



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

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

- (Object) edit

GET /people/1/edit



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

def edit
end

- (Object) filter_params (private)



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

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

- (Object) index

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

- (Object) list



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

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

- (Object) merge



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

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)



161
162
163
164
165
166
# File 'app/controllers/people_controller.rb', line 161

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

- (Object) new

GET /people/new



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

def new
  @person = Person.new
end

- (Object) person_params (private)



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

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



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

def role_types
  render json: ROLES
end

- (Object) roles

GET /people/123/roles



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

def roles
end

- (Object) search

TODO: deprecate!



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

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

GET /people/select_options



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

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

- (Object) set_person (private)



147
148
149
150
# File 'app/controllers/people_controller.rb', line 147

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

- (Object) show

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



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

def show
end

- (Object) similar



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

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



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

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