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

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/people_controller.rb', line 80

def autocomplete
  @people = Person.find_for_autocomplete(params).limit(50)
  data = @people.collect do |t|
    {id:              t.id,
     label:           t.name,
     response_values: {
         params[:method] => t.id
     },
     label_html:     t.name 
    }
  end

  render :json => data
end

- (Object) create

POST /people POST /people.json



30
31
32
33
34
35
36
37
38
39
40
41
42
# 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 @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



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

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



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

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

- (Object) download

GET /people/download



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

def download
  send_data Person.generate_download( Person.all ), type: 'text', filename: "people_#{DateTime.now.to_s}.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.all.includes(:creator, :updater)
  @recent_objects = Person.order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



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

def list
  @people =  Person.order(:id).page(params[:page]) #.per(10) #.per(3)
end

- (Object) lookup_person



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

def lookup_person
  @people = Person.find_for_autocomplete(params)
  render :json => @people.collect{|p|
    {
      label: p.bibtex_name,
      object_id: p.id}
  }
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)

Never trust parameters from the scary internet, only allow the white list through.



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

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

- (Object) role_types

GET /people/role_types.json



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

def role_types
  render :json => ROLES 
end

- (Object) roles



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

def roles
end

- (Object) search



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

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)

Use callbacks to share common setup or constraints between actions.



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

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



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

def update
  respond_to do |format|
    if @person.update(person_params)
      format.html { redirect_to @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