Class: ProjectMembersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/project_members_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, #whitelist_constantize

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) clipboard



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

def clipboard
  @project_member = sessions_current_user.project_members.where(project_id: sessions_current_project_id).first  
  render :show
end

- (Object) create

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

- (Object) create_many

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: 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

- (Object) destroy

DELETE /project_members/1 DELETE /project_members/1.json



94
95
96
97
98
99
100
# File 'app/controllers/project_members_controller.rb', line 94

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

- (Object) edit

GET /project_members/1/edit



23
24
# File 'app/controllers/project_members_controller.rb', line 23

def edit
end

- (Object) index

GET /project_members.json



12
13
14
# File 'app/controllers/project_members_controller.rb', line 12

def index
  @project_members = ProjectMember.where(project_id: sessions_current_project_id)
end

- (Object) many_new



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

- (Object) new

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

- (Object) project_id_param (private)



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

def project_id_param
  params.require(:project_member).permit(:project_id)[:project_id]
end

- (Object) project_member_params (private)



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

def project_member_params
  params.require(:project_member).permit(:project_id, :is_project_administrator, :user_id)
end

- (Object) project_members_params (private)



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

def project_members_params
  params.require(:project_member).permit(user_ids: [])[:user_ids] || []
end

- (Object) set_available_users (private)



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

def set_available_users
  @available_users = User.all.not_in_project(@member_project).order(:name)
end

- (Object) set_form_variables (private)



108
109
110
# File 'app/controllers/project_members_controller.rb', line 108

def set_form_variables
  @target_letters = @available_users.collect {|u| u.name[0].upcase}.uniq
end

- (Object) set_member_project (private)



116
117
118
# File 'app/controllers/project_members_controller.rb', line 116

def set_member_project
  @member_project = Project.find(project_id_param)
end

- (Object) set_project_member (private)



112
113
114
# File 'app/controllers/project_members_controller.rb', line 112

def set_project_member
  @project_member = ProjectMember.find(params[:id])
end

- (Object) update

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

- (Object) update_clipboard

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