diff --git a/app/controllers/applied_project_controller.rb b/app/controllers/applied_project_controller.rb new file mode 100644 index 000000000..2f8879636 --- /dev/null +++ b/app/controllers/applied_project_controller.rb @@ -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 diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index b06b8cbb3..b1fbfb8ea 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -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 diff --git a/app/helpers/applied_project_helper.rb b/app/helpers/applied_project_helper.rb new file mode 100644 index 000000000..a766976a4 --- /dev/null +++ b/app/helpers/applied_project_helper.rb @@ -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 diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index fcaf63604..1d7e2bcf9 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -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 diff --git a/app/models/applied_project.rb b/app/models/applied_project.rb new file mode 100644 index 000000000..04056cadc --- /dev/null +++ b/app/models/applied_project.rb @@ -0,0 +1,6 @@ +class AppliedProject < ActiveRecord::Base + attr_accessible :project_id, :user_id + + belongs_to :user + belongs_to :project +end diff --git a/app/models/project.rb b/app/models/project.rb index 3c2956a94..5da9f674e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 diff --git a/app/views/layouts/base_projects.html.erb b/app/views/layouts/base_projects.html.erb index 7504e5755..8d4de3a7c 100644 --- a/app/views/layouts/base_projects.html.erb +++ b/app/views/layouts/base_projects.html.erb @@ -103,6 +103,14 @@ <%= watcher_link(@project, User.current) %> <% end %> + +
+ + <% if ( !(User.current.member_of? @project) && User.current.login?) %> + <%= applied_link(@project, User.current) %> + <% end %> +
+ diff --git a/config/locales/en.yml b/config/locales/en.yml index 58ce0dd29..e7d24c329 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 4ff4b0c55..b5d9639db 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -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: 留言 diff --git a/config/routes.rb b/config/routes.rb index f9aa041d7..6a4b1d7a3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/db/migrate/20140521072851_create_applied_projects.rb b/db/migrate/20140521072851_create_applied_projects.rb new file mode 100644 index 000000000..3b0efbd97 --- /dev/null +++ b/db/migrate/20140521072851_create_applied_projects.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 4c60942a3..e2afdaae2 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 => 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|