1.添加用户申请加入项目contrl、model及相关逻辑

2.项目界面添加申请加入按钮
This commit is contained in:
nwb 2014-05-21 16:45:11 +08:00
parent 5a5db45af2
commit 104ee13ac7
12 changed files with 107 additions and 6 deletions

View File

@ -0,0 +1,16 @@
class AppliedProjectController < ApplicationController
#申请加入项目
def applied_join_project
AppliedProject.create(:user_id => params[:user_id], :project_id => params[:project_id])
redirect_to_referer_or {render :text => ( 'applied success.'), :layout => true}
end
#取消申请
def unapplied_join_project
@applied = AppliedProject.find(params[:id])
@applied.destroy
redirect_to_referer_or {render :text => ( 'unsubscribe success.'), :layout => true}
end
end

View File

@ -158,6 +158,6 @@ class WatchersController < ApplicationController
respond_to do |format|
format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => watchables} }
end
end
end
end

View File

@ -0,0 +1,21 @@
module AppliedProjectHelper
def applied_link(project, user, options=[])
return '' unless user && user.logged?
applied = project.applied_projects.find_by_user_id(user.id)
text = applied ? l(:label_unapply_project) : l(:label_apply_project)
if applied
appliedid = applied.id
end
url = appliedproject_path(
:id=>appliedid,
:user_id => user.id,
:project_id => project.id
)
method = applied ? 'delete' : 'post'
link_to text, url, :remote => true, :method => method
end
end

View File

@ -187,4 +187,23 @@ module WatchersHelper
:class => "floating"
end.join.html_safe
end
def applied_link(project, user, options=[])
return '' unless user && user.logged?
applied = project.applied_projects.find_by_user_id(user.id)
text = applied ? l(:label_unapply_project) : l(:label_apply_project)
if applied
appliedid = applied.id
end
url = appliedproject_path(
:id=>appliedid,
:user_id => user.id,
:project_id => project.id
)
method = applied ? 'delete' : 'post'
link_to text, url, :remote => true, :method => method
end
end

View File

@ -0,0 +1,6 @@
class AppliedProject < ActiveRecord::Base
attr_accessible :project_id, :user_id
belongs_to :user
belongs_to :project
end

View File

@ -64,7 +64,8 @@ class Project < ActiveRecord::Base
# has_many :students_for_courses, :dependent => :destroy
has_many :student, :through => :students_for_courses, :source => :user
has_one :course_extra, :class_name => 'Course', :foreign_key => :extra,:primary_key => :identifier, :dependent => :destroy
has_many :applied_projects
# end
#ADDED BY NIE
has_many :project_infos, :dependent => :destroy

View File

@ -103,6 +103,14 @@
<span class="icon-fav icon"></span><%= watcher_link(@project, User.current) %>
<% end %>
</div>
<!--添加项目申请-->
<div style="margin-left: 20px;">
<% if ( !(User.current.member_of? @project) && User.current.login?) %> <!--added by linchun-->
<span class="icon-fav icon"></span><%= applied_link(@project, User.current) %>
<% end %>
</div>
</td>
</tr>
</table>

View File

@ -1165,6 +1165,8 @@ en:
label_tags_bid_description: call description
label_tags_issue_description: issue description
label_tags_all_objects: all objects
label_apply_project: Apply Project
label_unapply_project: Unsubscribe
#fq
button_leave_meassge: Submit

View File

@ -1326,7 +1326,8 @@ zh:
label_tags_bid_description: 需求描述
label_tags_issue_description: 问题描述
label_tags_all_objects: 所有
label_apply_project: 申请加入
label_unapply_project: 取消申请
#fq
button_leave_meassge: 留言

View File

@ -247,6 +247,9 @@ RedmineApp::Application.routes.draw do
post 'issues/:object_id/watchers', :to => 'watchers#create', :object_type => 'issue'
delete 'issues/:object_id/watchers/:user_id' => 'watchers#destroy', :object_type => 'issue'
post 'appliedproject/applied', :to => 'applied_project#applied_join_project', :as => 'appliedproject'
delete 'appliedproject/applied', :to => 'applied_project#unapplied_join_project'
resources :bids, :only=>[:edit,:update,:show] do
member do
match 'homework_ajax_modal'

View File

@ -0,0 +1,12 @@
class CreateAppliedProjects < ActiveRecord::Migration
def self.up
create_table :applied_projects do |t|
t.column :project_id, :integer, :null => false
t.column :user_id, :integer, :null => false
end
end
def self.down
drop_table :applied_projects
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140519070751) do
ActiveRecord::Schema.define(:version => 20140521072851) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -23,6 +23,11 @@ ActiveRecord::Schema.define(:version => 20140519070751) do
add_index "activities", ["user_id", "act_type"], :name => "index_activities_on_user_id_and_act_type"
add_index "activities", ["user_id"], :name => "index_activities_on_user_id"
create_table "applied_projects", :force => true do |t|
t.integer "project_id", :null => false
t.integer "user_id", :null => false
end
create_table "apply_project_masters", :force => true do |t|
t.integer "user_id"
t.string "apply_type"
@ -52,11 +57,14 @@ ActiveRecord::Schema.define(:version => 20140519070751) do
add_index "attachments", ["container_id", "container_type"], :name => "index_attachments_on_container_id_and_container_type"
add_index "attachments", ["created_on"], :name => "index_attachments_on_created_on"
create_table "attachmentstypes", :force => true do |t|
t.integer "typeId", :null => false
create_table "attachmentstypes", :id => false, :force => true do |t|
t.integer "id", :null => false
t.integer "typeId"
t.string "typeName", :limit => 50
end
add_index "attachmentstypes", ["id"], :name => "id"
create_table "auth_sources", :force => true do |t|
t.string "type", :limit => 30, :default => "", :null => false
t.string "name", :limit => 60, :default => "", :null => false
@ -675,6 +683,9 @@ ActiveRecord::Schema.define(:version => 20140519070751) do
t.integer "viewed_count_crawl", :default => 0
t.integer "viewed_count_local", :default => 0
t.string "url"
t.string "username"
t.string "userhomeurl"
t.date "date_collected"
end
create_table "repositories", :force => true do |t|
@ -763,6 +774,7 @@ ActiveRecord::Schema.define(:version => 20140519070751) do
t.integer "softapplication_id"
t.integer "is_public"
t.string "application_developers"
t.string "deposit_project_url"
end
create_table "students_for_courses", :force => true do |t|