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

#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



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/controllers/projects_controller.rb', line 107

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
64
65
66
67
68
69
70
# File 'app/controllers/projects_controller.rb', line 61

def destroy

  redirect_to projects_url, notice: 'Nice try, not this time.'
  #  @project.destroy
  #  respond_to do |format|
  #    format.html { redirect_to projects_url }
  #    format.json { head :no_content }
  #  end

end

- (Object) edit

GET /projects/1/edit



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

def edit
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



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

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



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

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

- (Object) project_params (private)

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



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

def project_params
  params.require(:project).permit(:name)
end

- (Object) recently_created_stats



123
124
125
126
# File 'app/controllers/projects_controller.rb', line 123

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



99
100
101
102
103
104
105
# File 'app/controllers/projects_controller.rb', line 99

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



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

def select
  set_project
  if authorize_project_selection(sessions_current_user, @project)
    sessions_select_project(@project)
    redirect_to @project.workbench_starting_path
  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.



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

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

- (Object) settings_for



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

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



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

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 { head :no_content }
    else
      format.html { render action: 'edit' }
      format.json { render json: @project.errors, status: :unprocessable_entity }
    end
  end
end