Class: ProjectsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ProjectsController
- Defined in:
- app/controllers/projects_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
- #autocomplete ⇒ Object
-
#create ⇒ Object
POST /projects POST /projects.json.
-
#destroy ⇒ Object
DELETE /projects/1 DELETE /projects/1.json.
-
#edit ⇒ Object
GET /projects/1/edit.
- #go_to ⇒ Object private
-
#index ⇒ Object
GET /projects GET /projects.json.
- #list ⇒ Object
-
#new ⇒ Object
GET /projects/new.
- #preferences ⇒ Object
- #project_params ⇒ Object private
- #recently_created_stats ⇒ Object
- #search ⇒ Object
- #select ⇒ Object
- #set_project ⇒ Object private
- #settings_for ⇒ Object
-
#show ⇒ Object
GET /projects/1 GET /projects/1.json.
-
#update ⇒ Object
PATCH/PUT /projects/1 PATCH/PUT /projects/1.json.
Methods included from RedirectHelper
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
Methods included from ProjectsHelper
#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification
Methods included from Api::Intercept
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#autocomplete ⇒ Object
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 |
#create ⇒ Object
POST /projects POST /projects.json
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/projects_controller.rb', line 31 def create # can't use project_params here because :create_with_current_user param will be rejected # (as it should, it's a one off that shouldn't be accepted anywhere else) create_with_current_user = params.dig(:project, :create_with_current_user) @project = Project.new(project_params) respond_to do |format| if @project.save if create_with_current_user ProjectMember.create(project_id: @project.id, user_id: Current.user_id) end 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 |
#destroy ⇒ Object
DELETE /projects/1 DELETE /projects/1.json
70 71 72 |
# File 'app/controllers/projects_controller.rb', line 70 def destroy redirect_to projects_url, notice: 'Nice try, not this time.' end |
#edit ⇒ Object
GET /projects/1/edit
26 27 |
# File 'app/controllers/projects_controller.rb', line 26 def edit end |
#go_to ⇒ Object (private)
139 140 141 |
# File 'app/controllers/projects_controller.rb', line 139 def go_to @project.workbench_starting_path end |
#index ⇒ Object
GET /projects GET /projects.json
11 12 13 |
# File 'app/controllers/projects_controller.rb', line 11 def index @projects = Project.all end |
#list ⇒ Object
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 |
#new ⇒ Object
GET /projects/new
21 22 23 |
# File 'app/controllers/projects_controller.rb', line 21 def new @project = Project.new end |
#preferences ⇒ Object
74 75 76 77 78 79 |
# File 'app/controllers/projects_controller.rb', line 74 def preferences @project = sessions_current_project if @project.nil? render json: {success: false}, status: :not_found and return end end |
#project_params ⇒ Object (private)
135 136 137 |
# File 'app/controllers/projects_controller.rb', line 135 def project_params params.require(:project).permit(:name, :set_new_api_access_token, :clear_api_access_token, Project.key_value_preferences, Project.array_preferences, Project.hash_preferences) end |
#recently_created_stats ⇒ Object
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 |
#search ⇒ Object
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, alert: '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 |
#select ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/projects_controller.rb', line 81 def select set_project if (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 |
#set_project ⇒ Object (private)
130 131 132 133 |
# File 'app/controllers/projects_controller.rb', line 130 def set_project @project = Project.find(params[:id]) @recent_object = @project end |
#settings_for ⇒ Object
91 92 93 |
# File 'app/controllers/projects_controller.rb', line 91 def settings_for redirect_to edit_project_path(sessions_current_project) end |
#show ⇒ Object
GET /projects/1 GET /projects/1.json
17 18 |
# File 'app/controllers/projects_controller.rb', line 17 def show end |
#update ⇒ Object
PATCH/PUT /projects/1 PATCH/PUT /projects/1.json
56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/projects_controller.rb', line 56 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 |