Class: ProjectMembersController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ProjectMembersController
- Defined in:
- app/controllers/project_members_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
- #clipboard ⇒ Object
-
#create ⇒ Object
POST /otus.
-
#create_many ⇒ Object
POST /project_members/create_many.
-
#destroy ⇒ Object
DELETE /project_members/1 DELETE /project_members/1.json.
-
#edit ⇒ Object
GET /project_members/1/edit.
-
#index ⇒ Object
GET /project_members.json.
- #many_new ⇒ Object
-
#new ⇒ Object
GET /project_members/new.
- #project_id_param ⇒ Object private
- #project_member_params ⇒ Object private
- #project_members_params ⇒ Object private
- #set_available_users ⇒ Object private
- #set_form_variables ⇒ Object private
- #set_member_project ⇒ Object private
- #set_project_member ⇒ Object private
-
#update ⇒ Object
PATCH/PUT /project_members/1 PATCH/PUT /project_members/1.json.
-
#update_clipboard ⇒ Object
PATCH /project_members/1/update_clipboard.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, #week_in_review_graphs
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
#clipboard ⇒ Object
87 88 89 90 91 92 93 |
# File 'app/controllers/project_members_controller.rb', line 87 def clipboard if @project_member = sessions_current_user.project_members.where(project_id: sessions_current_project_id).first render :show else render json: {} end end |
#create ⇒ Object
POST /otus
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/project_members_controller.rb', line 27 def create @project_member = ProjectMember.new(project_member_params) respond_to do |format| if @project_member.save format.html { redirect_to project_path(@project_member.project), notice: "User #{@project_member.user.name}' was successfully added to #{@project_member.project.name}." } else set_available_users format.html { render action: 'new' } end end end |
#create_many ⇒ Object
POST /project_members/create_many
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/project_members_controller.rb', line 42 def create_many begin ApplicationRecord.transaction do project_members_params.each do |user_id| @member_project.project_members.create!(project_member_params.merge(user_id:)) end end @project_member = ProjectMember.new(project_member_params) redirect_to project_path(@member_project), notice: "Project members were #{project_members_params.empty? ? 'not selected.' : 'added to project.'}" rescue ActiveRecord::RecordInvalid redirect_to many_new_project_members_path, notice: 'There was a problem adding project members, none were added.' end end |
#destroy ⇒ Object
DELETE /project_members/1 DELETE /project_members/1.json
97 98 99 100 101 102 103 |
# File 'app/controllers/project_members_controller.rb', line 97 def destroy @project_member.destroy respond_to do |format| format.html { redirect_to project_path(@project_member.project), notice: 'Project member was successfully destroyed.' } format.json { head :no_content } end end |
#edit ⇒ Object
GET /project_members/1/edit
23 24 |
# File 'app/controllers/project_members_controller.rb', line 23 def edit end |
#index ⇒ Object
GET /project_members.json
12 13 14 |
# File 'app/controllers/project_members_controller.rb', line 12 def index @project_members = ProjectMember.joins(:user).where(project_id: sessions_current_project_id).order('users.name ASC').eager_load(:user, :project) end |
#many_new ⇒ Object
58 59 60 61 |
# File 'app/controllers/project_members_controller.rb', line 58 def many_new @project_member = ProjectMember.new(project_member_params) redirect_to project_path(@project_member.project), alert: 'There are no additional users available to add to this project.' if !@available_users.any? end |
#new ⇒ Object
GET /project_members/new
17 18 19 20 |
# File 'app/controllers/project_members_controller.rb', line 17 def new @project_member = ProjectMember.new(project_member_params) redirect_to project_path(@project_member.project), alert: 'There are no additional users available to add to this project.' if !@available_users.any? end |
#project_id_param ⇒ Object (private)
131 132 133 |
# File 'app/controllers/project_members_controller.rb', line 131 def project_id_param params.require(:project_member).permit(:project_id)[:project_id] end |
#project_member_params ⇒ Object (private)
123 124 125 |
# File 'app/controllers/project_members_controller.rb', line 123 def project_member_params params.require(:project_member).permit(:project_id, :is_project_administrator, :user_id) end |
#project_members_params ⇒ Object (private)
127 128 129 |
# File 'app/controllers/project_members_controller.rb', line 127 def project_members_params params.require(:project_member).permit(user_ids: [])[:user_ids] || [] end |
#set_available_users ⇒ Object (private)
107 108 109 |
# File 'app/controllers/project_members_controller.rb', line 107 def set_available_users @available_users = User.all.not_in_project(@member_project).order(:name) end |
#set_form_variables ⇒ Object (private)
111 112 113 |
# File 'app/controllers/project_members_controller.rb', line 111 def set_form_variables @target_letters = @available_users.collect {|u| u.name[0].upcase}.uniq end |
#set_member_project ⇒ Object (private)
119 120 121 |
# File 'app/controllers/project_members_controller.rb', line 119 def set_member_project @member_project = Project.find(project_id_param) end |
#set_project_member ⇒ Object (private)
115 116 117 |
# File 'app/controllers/project_members_controller.rb', line 115 def set_project_member @project_member = ProjectMember.find(params[:id]) end |
#update ⇒ Object
PATCH/PUT /project_members/1 PATCH/PUT /project_members/1.json
65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/project_members_controller.rb', line 65 def update respond_to do |format| if @project_member.update(project_member_params) format.html { redirect_to project_path(@project_member.project), notice: 'Project member was successfully updated.' } format.json { render :show, status: :ok, location: @project_member } else format.html { render :edit } format.json { render json: @project_member.errors, status: :unprocessable_entity } end end end |
#update_clipboard ⇒ Object
PATCH /project_members/1/update_clipboard.json
78 79 80 81 82 83 84 85 |
# File 'app/controllers/project_members_controller.rb', line 78 def update_clipboard @project_member = sessions_current_user.project_members.where(project_id: sessions_current_project_id).first if @project_member.update( params.require(:project_member).permit(clipboard: {}) ) render :show, status: :ok, location: @project_member else render json: @project_member.errors, status: :unprocessable_entity end end |