Class: ProjectsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/projects_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 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



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/controllers/projects_controller.rb', line 104

def autocomplete
  @projects = Project.find_for_autocomplete(params)

  data = @projects.collect do |t|
    {id: t.id,
     label: ApplicationController.helpers.project_tag(t),
     response_values: {
         params[:method] => t.id
     },
     label_html: ApplicationController.helpers.project_tag(t)
    }
  end

  render json: data
end

- (Object) create

POST /projects POST /projects.json



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

def create
  @project = Project.new(project_params)

  respond_to do |format|
    if @project.save
      format.html { redirect_to @project, notice: 'Project was successfully created.' }
      format.json { render action: 'show', status: :created, location: @project }
    else
      format.html { render action: 'new' }
      format.json { render json: @project.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy

DELETE /projects/1 DELETE /projects/1.json



61
62
63
# File 'app/controllers/projects_controller.rb', line 61

def destroy
  redirect_to projects_url, notice: 'Nice try, not this time.'
end

- (Object) edit

GET /projects/1/edit



26
27
# File 'app/controllers/projects_controller.rb', line 26

def edit
end

- (Object) go_to (private)



137
138
139
# File 'app/controllers/projects_controller.rb', line 137

def go_to
  @project.workbench_starting_path
end

- (Object) index

GET /projects GET /projects.json



11
12
13
# File 'app/controllers/projects_controller.rb', line 11

def index
  @projects = Project.all
end

- (Object) list



92
93
94
# File 'app/controllers/projects_controller.rb', line 92

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

- (Object) new

GET /projects/new



21
22
23
# File 'app/controllers/projects_controller.rb', line 21

def new
  @project = Project.new
end

- (Object) per_relationship_recent_stats



87
88
89
90
# File 'app/controllers/projects_controller.rb', line 87

def per_relationship_recent_stats
  Rails.application.eager_load!
  @relationship = params.require(:relationship) # params.permit(:relationship)[:relationship]
end

- (Object) preferences



65
66
67
# File 'app/controllers/projects_controller.rb', line 65

def preferences
  @project = sessions_current_project
end

- (Object) project_params (private)

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



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

def project_params
  params.require(:project).permit(:name, Project.key_value_preferences, Project.array_preferences, Project.hash_preferences)
end

- (Object) recently_created_stats



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

def recently_created_stats
  redirect_to hub_path, notice: 'Select a project first.' if @project.nil?
  render json: @project.data_breakdown_for_chartkick_recent
end

- (Object) search



96
97
98
99
100
101
102
# File 'app/controllers/projects_controller.rb', line 96

def search
  if params[:id].blank?
    redirect_to projects_path, notice: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    redirect_to project_path(params[:id])
  end
end

- (Object) select



69
70
71
72
73
74
75
76
77
# File 'app/controllers/projects_controller.rb', line 69

def select
  set_project
  if authorize_project_selection(sessions_current_user, @project)
    sessions_select_project(@project)
    redirect_to go_to # see def go_to for unprotected redirect mitigation
  else
    redirect_to root_path, notice: 'You are not a member of that project!'
  end
end

- (Object) set_project (private)

Use callbacks to share common setup or constraints between actions.



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

def set_project
  @project = Project.find(params[:id])
  @recent_object = @project
end

- (Object) settings_for



79
80
81
# File 'app/controllers/projects_controller.rb', line 79

def settings_for
  redirect_to edit_project_path(sessions_current_project)
end

- (Object) show

GET /projects/1 GET /projects/1.json



17
18
# File 'app/controllers/projects_controller.rb', line 17

def show
end

- (Object) stats



83
84
85
# File 'app/controllers/projects_controller.rb', line 83

def stats
  Rails.application.eager_load!
end

- (Object) update

PATCH/PUT /projects/1 PATCH/PUT /projects/1.json



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

def update
  respond_to do |format|
    if @project.update(project_params)
      format.html { redirect_to @project, notice: 'Project was successfully updated.' }
      format.json { render :show, status: :ok, location: @project }
    else
      format.html { render action: 'edit' }
      format.json { render json: @project.errors, status: :unprocessable_entity }
    end
  end
end