From a8fa4a55e301e0bb5d82db6f40cb8b0c3fba8199 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 28 Jul 2016 16:22:33 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=94=B3=E8=AF=B7=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/applied_project_controller.rb | 11 +++++------ app/helpers/users_helper.rb | 12 ++++++++++++ app/helpers/watchers_helper.rb | 2 +- app/models/applied_project.rb | 12 +++++------- .../applied_project/applied_project_info.js.erb | 1 + app/views/layouts/_join_exit_project.html.erb | 4 +++- app/views/users/_user_message_applied.html.erb | 17 +++++++++++++++++ ...0160728075947_add_role_to_applied_project.rb | 5 +++++ db/schema.rb | 7 ++++--- 9 files changed, 53 insertions(+), 18 deletions(-) create mode 100644 db/migrate/20160728075947_add_role_to_applied_project.rb diff --git a/app/controllers/applied_project_controller.rb b/app/controllers/applied_project_controller.rb index d8e6c5f12..117d022d6 100644 --- a/app/controllers/applied_project_controller.rb +++ b/app/controllers/applied_project_controller.rb @@ -42,7 +42,8 @@ class AppliedProjectController < ApplicationController # end end - # @flage:提示语标志(1 邀请码错误;2 已经是项目成员; 3 角色没有选择; 4 申请成功) + # @flage:提示语标志(1:邀请码错误;2:已经是项目成员; 3:角色没有选择; 4:申请成功) + # role:成员角色 => 0(1:管理人员;2:开发人员;3:报告人员) # 申请成功则发送消息 def applied_project_info @project = Project.find(params[:project_id]) @@ -54,12 +55,10 @@ class AppliedProjectController < ApplicationController @flag = 3 else @flag = 4 - applied_project = AppliedProject.create(:user_id => User.current.id, :project_id => params[:project_id]) + role = params[:member] == "member_manager" ? 1 : (params[:member] = "member_developer" ? 2 : 3) + applied_project = AppliedProject.create(:user_id => User.current.id, :project_id => params[:project_id], :role => role) # 申请成功则给项目管理员发送邮件及发送消息 - Mailer.run.applied_project(appliedproject) - @project.managers.each do |member| - AppliedMessage.create(:user_id => member.user_id, :status => true, :applied_id => applied_project.id, :applied_type => "AppliedProject", :viewed => true) - end + Mailer.run.applied_project(applied_project) end end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 98b993183..e9abe43a3 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -54,6 +54,18 @@ module UsersHelper end end + # 获取消息角色 + def applied_project_message_type role + case role + when 1 + "管理员" + when 2 + "开发人员" + when 3 + "报告人员" + end + end + def get_resource_origin attach type = attach.container_type content = attach.container diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index 254ce1ad7..d846071b5 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -372,7 +372,7 @@ module WatchersHelper method = 'post' @applied_flag = project.instance_of?(Project) if applied - link = "text" + link = "#{text}" else link = link_to(text, url, :remote => true, :method => method, :id => "#{project.id}", :class => "pr_join_a") end diff --git a/app/models/applied_project.rb b/app/models/applied_project.rb index fb8bf90af..8dbed9cda 100644 --- a/app/models/applied_project.rb +++ b/app/models/applied_project.rb @@ -1,18 +1,16 @@ class AppliedProject < ActiveRecord::Base - attr_accessible :project_id, :user_id + attr_accessible :project_id, :user_id, :role belongs_to :user belongs_to :project - has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy + has_many :applied_messages, :class_name => 'AppliedMessage', :as => :applied, :dependent => :destroy after_create :send_appliled_message + # 仅仅给项目管理人员发送消息 def send_appliled_message - # if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil? - self.project.members.each do |m| - if m.roles.first.to_s.include?("Manager") - self.forge_messages << ForgeMessage.new(:user_id => m.user_id, :project_id => self.project_id, :viewed => false) - end + self.project.managers.each do |member| + self.applied_messages << AppliedMessage.new(:user_id => member.user_id, :status => true, :viewed => false) end # end end diff --git a/app/views/applied_project/applied_project_info.js.erb b/app/views/applied_project/applied_project_info.js.erb index 9c5564f33..1ac627b3e 100644 --- a/app/views/applied_project/applied_project_info.js.erb +++ b/app/views/applied_project/applied_project_info.js.erb @@ -1,2 +1,3 @@ var htmlvalue = "<%= escape_javascript(render :partial => 'applied_project/applied_project_tip', locals: {:project_id => @project.id}) %>"; pop_box_new(htmlvalue,380,40,50); +//$("#join_in_project").attr('href','<%#= join_in_project_link(@project, User.current) %>'); diff --git a/app/views/layouts/_join_exit_project.html.erb b/app/views/layouts/_join_exit_project.html.erb index e893949f4..d39d3d67b 100644 --- a/app/views/layouts/_join_exit_project.html.erb +++ b/app/views/layouts/_join_exit_project.html.erb @@ -3,7 +3,9 @@ <% if !User.current.member_of?(@project) && User.current.login? && !User.current.admin %> <%= watcher_link_for_project(@project, User.current) %> - <%= join_in_project_link(@project, User.current) %> + + <%= join_in_project_link(@project, User.current) %> + <% end %> <% if User.current.admin? || User.current.allowed_to?({:controller => 'projects', :action => 'settings'}, @project) %> diff --git a/app/views/users/_user_message_applied.html.erb b/app/views/users/_user_message_applied.html.erb index dc3e51b4d..efd2bf8da 100644 --- a/app/views/users/_user_message_applied.html.erb +++ b/app/views/users/_user_message_applied.html.erb @@ -14,5 +14,22 @@
  • <%= time_tag(ma.created_at).html_safe %>
  • + <% elsif ma && ma.applied_type == "AppliedProject" %> + <% end %> <% end %> \ No newline at end of file diff --git a/db/migrate/20160728075947_add_role_to_applied_project.rb b/db/migrate/20160728075947_add_role_to_applied_project.rb new file mode 100644 index 000000000..964af6f19 --- /dev/null +++ b/db/migrate/20160728075947_add_role_to_applied_project.rb @@ -0,0 +1,5 @@ +class AddRoleToAppliedProject < ActiveRecord::Migration + def change + add_column :applied_projects, :role, :integer, :default => 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 123d474f4..4747a74e3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160728041943) do +ActiveRecord::Schema.define(:version => 20160728075947) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -85,8 +85,9 @@ ActiveRecord::Schema.define(:version => 20160728041943) do end create_table "applied_projects", :force => true do |t| - t.integer "project_id", :null => false - t.integer "user_id", :null => false + t.integer "project_id", :null => false + t.integer "user_id", :null => false + t.integer "role", :default => 0 end create_table "apply_add_schools", :force => true do |t|