From 508eee45f25aec91ed2c439655bd41528b47a5c3 Mon Sep 17 00:00:00 2001 From: huangjingquan Date: Fri, 11 Oct 2013 09:27:07 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E8=AF=BE=E7=A8=8B=E5=BC=B9=E6=A1=86=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/projects/_new_join.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/_new_join.html.erb b/app/views/projects/_new_join.html.erb index e26caeab3..82cc61b4d 100644 --- a/app/views/projects/_new_join.html.erb +++ b/app/views/projects/_new_join.html.erb @@ -47,7 +47,7 @@ + <%= text_field_tag 'course_password', nil, :size => 45 %> From c49209cbfbd8d35978fd6ccb5319cd60a12f0334 Mon Sep 17 00:00:00 2001 From: huangjingquan Date: Fri, 11 Oct 2013 20:25:24 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=B0=86=E8=AF=BE=E7=A8=8B=E5=92=8C?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E5=88=86=E5=BC=80=20=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E5=8D=95=E7=8B=AC=E4=B8=80=E4=B8=AAtabs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 43 +++++++++++++++++-------- app/views/users/_my_course.html.erb | 2 +- app/views/users/user_courses.html.erb | 11 ------- app/views/users/user_homeworks.html.erb | 9 ++++++ app/views/users/watch_bids.html.erb | 2 +- config/locales/zh.yml | 2 ++ config/routes.rb | 1 + lib/redmine.rb | 4 +-- 8 files changed, 45 insertions(+), 29 deletions(-) create mode 100644 app/views/users/user_homeworks.html.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 14dad38b7..d49d5e245 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -23,12 +23,14 @@ class UsersController < ApplicationController menu_item :requirement_focus, :only => :watch_bids menu_item :user_newfeedback, :only => :user_newfeedback menu_item :user_course, :only => :user_courses + menu_item :user_homework, :only => :user_homeworks #Ended by young - before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info, :user_watchlist, :user_fanslist,:update, :user_courses] + before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info, :user_watchlist, :user_fanslist,:update, + :user_courses, :user_homeworks] #edit has been deleted by huang, 2013-9-23 - before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, + before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, :user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info] accept_api_auth :index, :show, :create, :update, :destroy,:tag_save @@ -79,7 +81,7 @@ class UsersController < ApplicationController def watch_bids cond = 'bids.reward_type <> 1' @bids = Bid.watched_by(@user) - @bids = Bid.visible.where('reward_type = ?', 1) # modified by huang + @bids = Bid.visible.where('reward_type = ?', 1) # added by huang @offset, @limit = api_offset_and_limit({:limit => 10}) @bid_count = @bids.count @bid_pages = Paginator.new @bid_count, @limit, params['page'] @@ -123,19 +125,32 @@ class UsersController < ApplicationController end # end - # added by fq - def user_courses - case params[:type] - when "2" + # added by huang + def user_homeworks @membership = @user.memberships.all(:conditions => Project.visible_condition(User.current)) @memberships = [] @membership.each do |membership| - if membership.project.project_type == 1 - @membership << membership - end - end - @state = 2 - + if membership.project.project_type == 1 + @memberships << membership + end + end + @bid = [] + @memberships.each do |membership| + @bid += membership.project.homeworks + end + @bid = @bid.group_by {|bid| bid.courses.first.id} + #add by huang + unless User.current.admin? + if !@user.active? + render_404 + return + end + end + end + + # added by fq + def user_courses + case params[:type] when "1" @membership = @user.memberships.all(:conditions => Project.visible_condition(User.current)) @memberships = [] @@ -214,7 +229,7 @@ class UsersController < ApplicationController when 'xml', 'json' @offset, @limit = api_offset_and_limit({:limit => 15}) else - @limit = 15#per_page_option + @limit = 15 #per_page_option end @status = params[:status] || 1 diff --git a/app/views/users/_my_course.html.erb b/app/views/users/_my_course.html.erb index 5e0a47994..417864cb7 100644 --- a/app/views/users/_my_course.html.erb +++ b/app/views/users/_my_course.html.erb @@ -18,7 +18,7 @@ <% else %> <% unless @user != User.current %> <% if @user.user_extensions.identity == 0 %> - <%= link_to"#{l(:label_course_new)}",{:controller=>'projects',:action=>'new', :course => 1}, :class => 'icon icon-add' %> +

<%= link_to"#{l(:label_course_new)}",{:controller=>'projects',:action=>'new', :course => 1}, :class => 'icon icon-add' %>

<% end %> <% end %>
- <%= text_field_tag 'course_password', nil, :style => 'width:200px'%>
diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 984b8b445..fefbebcce 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1489,6 +1489,7 @@ zh: label_welcome_trustie_description: 面向有创意和激情的高校大学生与创业者,提供社交化的项目管理、协同研究、软件开发和众包平台。 label_user_project: 项目 label_user_course: 课程 + label_user_homework: 作业 label_bid_respond_quote: 回复 label_bid_if_agreement: 如果喜欢我,请点击我 label_bid_respond_delete: 删除 @@ -1497,6 +1498,7 @@ zh: label_newfeedback_delete: 删除 label_user_all_activity: 所有动态 label_user_activity_myself: 只看自己 + label_my_honework_no_homework: 暂无任何作业! label_user_all_respond: 所有反馈 label_layouts_feedback: 留言 label_welcome_participate: 参与了 diff --git a/config/routes.rb b/config/routes.rb index 3df494b5b..7b929afcb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -92,6 +92,7 @@ RedmineApp::Application.routes.draw do match 'user_watchlist', :to => 'users#user_watchlist', :via => :get, :as => "user_watchlist" #add by huang match 'user_fanslist', :to => 'users#user_fanslist', :via => :get, :as => "user_fanslist" #add by huang match 'user_courses', :to => 'users#user_courses', :via => :get + match 'user_homeworks', :to => 'users#user_homeworks', :via => :get end end match 'users/:id/user_newfeedback', :to => 'users#user_newfeedback', :via => :get, :as => "feedback" diff --git a/lib/redmine.rb b/lib/redmine.rb index ee9a9386c..0ec9a772f 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -330,8 +330,8 @@ end Redmine::MenuManager.map :user_menu do |menu| menu.push :activity, {:controller => 'users', :action => 'show' } menu.push :user_course, {:controller => 'users', :action => 'user_courses'} - menu.push :user_project, {:controller => 'users', :action => 'user_projects'} - + menu.push :user_homework, {:controller => 'users', :action => 'user_homeworks'} + menu.push :user_project, {:controller => 'users', :action => 'user_projects'} menu.push :requirement_focus, {:controller => 'users', :action => 'watch_bids'} menu.push :user_newfeedback, {:controller => 'users', :action => 'user_newfeedback'} From 8ce8de09cbe5451a55d964a47ad7285d55b35c11 Mon Sep 17 00:00:00 2001 From: huangjingquan Date: Sat, 12 Oct 2013 08:53:45 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E4=B8=BB=E9=A1=B5=E8=AF=BE=E7=A8=8B=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/_my_course.html.erb | 6 +++--- app/views/users/_my_joinedcourse.html.erb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/users/_my_course.html.erb b/app/views/users/_my_course.html.erb index 417864cb7..6a461c6ce 100644 --- a/app/views/users/_my_course.html.erb +++ b/app/views/users/_my_course.html.erb @@ -49,11 +49,11 @@ diff --git a/app/views/users/_my_joinedcourse.html.erb b/app/views/users/_my_joinedcourse.html.erb index 4b8107440..ae5735b0c 100644 --- a/app/views/users/_my_joinedcourse.html.erb +++ b/app/views/users/_my_joinedcourse.html.erb @@ -48,11 +48,11 @@ From d7f7ff5fa94f8a544cca2216e0ae37ab02d41336 Mon Sep 17 00:00:00 2001 From: xianbo Date: Fri, 11 Oct 2013 20:32:44 +0800 Subject: [PATCH 4/6] delete homework --- app/controllers/bids_controller.rb | 185 ++++++++++--------- app/models/bid.rb | 35 ++-- app/views/users/_my_create_homework.html.erb | 65 ++++--- app/views/users/_my_homework.html.erb | 17 +- config/routes.rb | 1 + 5 files changed, 158 insertions(+), 145 deletions(-) diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 8d66bf1af..0c39ee5c6 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -7,13 +7,12 @@ class BidsController < ApplicationController menu_item :homework_statistics, :only => :homework_statistics #Ended by young before_filter :find_bid, :only => [:show, :show_project, :create,:destroy,:more,:back,:add,:new,:show_results,:set_reward, :add_homework, :fork, :create_fork, :show_course] - before_filter :require_login,:only => [:set_reward] - + before_filter :require_login,:only => [:set_reward] + helper :watchers helper :attachments include AttachmentsHelper helper :projects - def index @project_type = params[:project_type] # Modified by nie @@ -22,11 +21,11 @@ class BidsController < ApplicationController if @project_type == '1' @bids = Bid.visible.where('reward_type = ?', 3) # elsif - # @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4) + # @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4) else @bids = Bid.visible.where('reward_type = ?', 1) end - + @bids = @bids.like(params[:name]) if params[:name].present? @bid_count = @bids.count @bid_pages = Paginator.new @bid_count, @limit, params['page'] @@ -65,28 +64,28 @@ class BidsController < ApplicationController end else unless @offset == 0 - @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse - else - limit = @bid_count % @limit - limit = @limit if limit == 0 - @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse - end - @s_state = 1 + @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse + else + limit = @bid_count % @limit + limit = @limit if limit == 0 + @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse + end + @s_state = 1 end #end end - + #huang def contest - + # Modified by nie # @requirement_title = "4" - @offset, @limit = api_offset_and_limit({:limit => 10}) - + @offset, @limit = api_offset_and_limit({:limit => 10}) + @bids = Bid.visible.where('reward_type = ?', 2) - + # elsif - # @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4) + # @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4) @bids = @bids.like(params[:name]) if params[:name].present? @bid_count = @bids.count @bid_pages = Paginator.new @bid_count, @limit, params['page'] @@ -125,27 +124,27 @@ class BidsController < ApplicationController end else unless @offset == 0 - @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse - else - limit = @bid_count % @limit - limit = @limit if limit == 0 - @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse - end - @s_state = 1 + @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse + else + limit = @bid_count % @limit + limit = @limit if limit == 0 + @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse + end + @s_state = 1 end #end end - + def fork @courses = [] - @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) + @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) @membership.each do |membership| if membership.project.project_type == 1 - @courses << membership.project + @courses << membership.project end end end - + def create_fork @homework = Bid.new @homework.name = params[:bid][:name] @@ -171,10 +170,10 @@ class BidsController < ApplicationController else @bid.safe_attributes = params[:bid] @courses = [] - @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) + @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) @membership.each do |membership| if membership.project.project_type == 1 - @courses << membership.project + @courses << membership.project end end render :action => 'fork' @@ -192,39 +191,39 @@ class BidsController < ApplicationController @state = false respond_to do |format| - if @bid.reward_type == 3 - format.html { - render :layout => 'base_homework' - } + if @bid.reward_type == 3 + format.html { + render :layout => 'base_homework' + } else format.html { - render :layout => 'base_bids' - } - end + render :layout => 'base_bids' + } + end format.api - + end end - + def show_course bids = Bid.where('parent_id = ?', @bid.id) @courses = [] for bid in bids @courses << bid.courses.first end - + respond_to do |format| - if @bid.reward_type == 3 - format.html { - render :layout => 'base_homework' - } + if @bid.reward_type == 3 + format.html { + render :layout => 'base_homework' + } else format.html { - render :layout => 'base_bids' - } - end + render :layout => 'base_bids' + } + end format.api - + end end @@ -233,10 +232,10 @@ class BidsController < ApplicationController @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) @option = [] @membership.each do |membership| - unless(membership.project.project_type==1) + unless(membership.project.project_type==1) membership.member_roles.each{|role| if(role.role_id == 3) - @option << membership.project + @option << membership.project end } end @@ -251,23 +250,22 @@ class BidsController < ApplicationController @homework_list = @bid.homeworks end respond_to do |format| - if @bid.reward_type == 3 - format.html { - render :layout => 'base_homework' - } + if @bid.reward_type == 3 + format.html { + render :layout => 'base_homework' + } else format.html { - render :layout => 'base_bids' - } - end + render :layout => 'base_bids' + } + end format.api end end - ##### by huang def show_project_homework - # flash[:notice] = "" + # flash[:notice] = "" @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) @option = [] @membership.each do |membership| @@ -277,19 +275,19 @@ class BidsController < ApplicationController @user = @bid.author @bidding_project = @bid.biding_projects respond_to do |format| - if @bid.reward_type == 3 - format.html { - render :layout => 'base_homework' - } + if @bid.reward_type == 3 + format.html { + render :layout => 'base_homework' + } else format.html { - render :layout => 'base_bids' - } - end + render :layout => 'base_bids' + } + end format.api - end + end end - + ###添加应标项目 def add project = Project.where('name = ?', params[:bid]).first @@ -299,10 +297,10 @@ class BidsController < ApplicationController flash[:notice] = l(:label_bidding_succeed) end else - if @bid.reward_type == 3 - flash[:error] = l(:label_bidding_homework_fail) + if @bid.reward_type == 3 + flash[:error] = l(:label_bidding_homework_fail) else - flash[:error] = l(:label_bidding_fail) + flash[:error] = l(:label_bidding_fail) end end @bidding_project = @bid.biding_projects @@ -371,6 +369,19 @@ class BidsController < ApplicationController end end + #删除作业 + #by xianbo + def homework_destroy + @bid_to_destroy = Bid.find params[:course_id] + @bid_to_destroy.destroy + respond_to do |format| + format.html { redirect_to :back } + format.js + #format.api { render_api_ok } + end + end + + #end by xianbo ##引用 def new @jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id] @@ -395,8 +406,9 @@ class BidsController < ApplicationController @bid = Bid.new @bid.safe_attributes = params[:bid] end - #huang - def create_contest + + #huang + def create_contest @bid = Bid.new @bid.name = params[:bid][:name] @bid.description = params[:bid][:description] @@ -417,8 +429,7 @@ class BidsController < ApplicationController render :action => 'new_bid' end end - - + #huang def new_contest @bid = Bid.new @@ -446,7 +457,7 @@ class BidsController < ApplicationController render :action => 'new_bid' end end - + def create_homework @bid = Bid.new @bid.name = params[:bid][:name] @@ -473,7 +484,7 @@ class BidsController < ApplicationController render :action => 'new_bid' end end - + def add_homework # homework = HomeworkAttach.create(:bid_id => @bid.id, :user_id => User.current.id) # homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads])) @@ -483,29 +494,29 @@ class BidsController < ApplicationController @homework.save_attachments(params[:attachments]) @homework.save @homework_list = @bid.homeworks - + end - + # 作业统计 def homework_statistics @course = @bid.courses.first @member = [] @course.memberships.each do |member| unless (member.roles && Role.where('id = ? ', 3)).empty? - @member.push member + @member.push member end end - if @bid.homework_type = 1 + if @bid.homework_type = 1 @student = User.where("id in (select DISTINCT user_id from #{HomeworkAttach.table_name} where bid_id = ? )", @bid.id) @homework_type = true else - + @homework_type = false end @user = @bid.author render :layout => 'base_homework' end - + def homework_respond @user = @bid.author render :layout => 'base_homework' @@ -522,7 +533,6 @@ class BidsController < ApplicationController #format.api { render_api_ok } end end - def back @jour = @bid.journals_for_messages @@ -541,12 +551,12 @@ class BidsController < ApplicationController def set_reward @b_p = nil @biding_project_id = nil - + if params[:set_reward][:reward] # @bid_id = params[:id] @biding_project_id = params[:set_reward][:b_id] @b_p = BidingProject.find_by_id(@biding_project_id) - + # 把字段存进表中 @b_p.update_reward(params[:set_reward][:reward].to_s) end @@ -556,7 +566,6 @@ class BidsController < ApplicationController end end - # added by william # used to manage the bid and end the bid def manage diff --git a/app/models/bid.rb b/app/models/bid.rb index e6b8511c3..0c8a4d371 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -12,7 +12,7 @@ class Bid < ActiveRecord::Base has_many :homework_for_courses, :dependent => :destroy has_many :courses, :through => :homework_for_courses, :source => :project has_many :homeworks, :class_name => 'HomeworkAttach', :dependent => :destroy - + acts_as_attachable NAME_LENGTH_LIMIT = 60 @@ -30,11 +30,11 @@ class Bid < ActiveRecord::Base validate :validate_user validate :validate_reward_type after_create :act_as_activity - + scope :visible, lambda {|*args| nil } - + scope :like, lambda {|arg| if arg.blank? where(nil) @@ -54,17 +54,15 @@ class Bid < ActiveRecord::Base acts_as_activity_provider :find_options => {:include => [:projects, :author]}, :author_key => :author_id - - + safe_attributes 'name', 'description', 'budget', 'deadline' - + # safe_attributes 'name', - # 'description', - # 'deadline' - + # 'description', + # 'deadline' def add_jour(user, notes, reference_user_id = 0) self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id) end @@ -72,7 +70,7 @@ class Bid < ActiveRecord::Base def self.creat_bids(budget, deadline, name, description=nil, reward_type) self.create(:author_id => User.current.id, :budget => budget, :deadline => deadline, :name => name, :description => description, :commit => 0, :reward_type => reward_type) - # self.acts << Activity.new(:user_id => self.author_id) + # self.acts << Activity.new(:user_id => self.author_id) end def update_bids(budget, deadline, name, description=nil) @@ -102,25 +100,24 @@ class Bid < ActiveRecord::Base def validate_user errors.add :author_id, :invalid if author.nil? || !author.active? end - + def validate_reward_type errors.add :reward_type, :invalid if self.reward_type == 0 end - + def act_as_activity self.acts << Activity.new(:user_id => self.author_id) end - + # used to validate weather the user is the creater of the bid # added by william def validate_bid_manager(user_id) unless user_id.nil? - if self.author_id == user_id - return true - else - return false - end + if self.author_id == user_id + return true + else + return false + end end end - end diff --git a/app/views/users/_my_create_homework.html.erb b/app/views/users/_my_create_homework.html.erb index 1fd948605..845fb093e 100644 --- a/app/views/users/_my_create_homework.html.erb +++ b/app/views/users/_my_create_homework.html.erb @@ -4,7 +4,7 @@ <% @bid.each do |bids|%> <% for bid in bids[1] %> -<% if @user == bid.author %> +<% if @user == bid.author %>
<% if membership.roles.sort.collect(&:to_s).join(', ') =='Manager' %> - Teacher + 老师 <% elsif membership.roles.sort.collect(&:to_s).join(', ') =='Reporter' %> - Student + 学生 <% elsif membership.roles.sort.collect(&:to_s).join(', ') =='TA' %> - TA + 助教 <% end %>
<% if membership.roles.sort.collect(&:to_s).join(', ') =='Manager' %> - Teacher + 老师 <% elsif membership.roles.sort.collect(&:to_s).join(', ') =='Reporter' %> - Student + 学生 <% elsif membership.roles.sort.collect(&:to_s).join(', ') =='TA' %> - TA + 助教 <% end %>
@@ -12,43 +12,50 @@
<%= link_to(image_tag(url_to_avatar(bid.author), :class => 'avatar'), user_path(bid.author), :class => "avatar") %>
+ <%= link_to(bid.name, respond_path(bid), :class => 'bid_path') %>    + <%= l(:label_course_homework) %> : <%= link_to(bid.courses.first.name, project_path(bid.courses.first)) %> <%= link_to( + l(:button_delete), + {:action => 'homework_destroy', :controller=>'bids', :course_id => bid.id}, + :method => :post, + :data => {:confirm => l(:text_are_you_sure)}, + :class => 'icon icon-del' + ) %> + + + + + + + + +
<%= link_to(bid.author.lastname+bid.author.firstname, user_path(bid.author), :class => 'bid_user') %>:   - <%= link_to(bid.name, respond_path(bid), :class => 'bid_path') %>    - <%= l(:label_course_homework) %> : <%= link_to(bid.courses.first.name, project_path(bid.courses.first)) %>
+ + + + - - - - - +
<% if bid.reward_type.nil? or bid.reward_type == 1 %> <%= l(:label_bids_reward_method) %><%= l(:label_call_bonus) %> <%= l(:label_RMB_sign) %><%= bid.budget%> <% elsif bid.reward_type == 2 %> <%= l(:label_bids_reward_method) %><%= bid.budget%> <% else %> <% end %>
- - - - - - - -
<% if bid.reward_type.nil? or bid.reward_type == 1 %> <%= l(:label_bids_reward_method) %><%= l(:label_call_bonus) %> <%= l(:label_RMB_sign) %><%= bid.budget%> <% elsif bid.reward_type == 2 %> <%= l(:label_bids_reward_method) %><%= bid.budget%> <% else %> <% end %>
- <% if bid.homework_type == 1%> - <%= l(:label_x_homework_project, :count => bid.homeworks.count) %>(<%= link_to bid.homeworks.count, project_for_bid_path(bid.id) %>) - <% else %><%= l(:label_x_homework_project, :count => bid.biding_projects.count) %>(<%= link_to bid.biding_projects.count, project_for_bid_path(bid.id) %>)<% end %> - - <%= l(:label_x_responses, :count => bid.commit) %>(<%= link_to bid.commit, respond_path(bid) %>)
<%= format_time bid.created_on %>
-
- - - - -
<%= bid.description%>
-
<% if bid.homework_type == 1%> + <%= l(:label_x_homework_project, :count => bid.homeworks.count) %>(<%= link_to bid.homeworks.count, project_for_bid_path(bid.id) %>) + <% else %><%= l(:label_x_homework_project, :count => bid.biding_projects.count) %>(<%= link_to bid.biding_projects.count, project_for_bid_path(bid.id) %>)<% end %> <%= l(:label_x_responses, :count => bid.commit) %>(<%= link_to bid.commit, respond_path(bid) %>)
<%= format_time bid.created_on %>
+
+ + + + +
<%= bid.description%>
+
+ <% end %> <% end %> <% end %> <% else %> -

<%= l(:label_my_create_honework_no_homework) %>

+

+ <%= l(:label_my_create_honework_no_homework) %> +

<% end %> \ No newline at end of file diff --git a/app/views/users/_my_homework.html.erb b/app/views/users/_my_homework.html.erb index 1d39bb21c..b471e3dfe 100644 --- a/app/views/users/_my_homework.html.erb +++ b/app/views/users/_my_homework.html.erb @@ -3,7 +3,7 @@ <% @bid.each do |bids|%> -<% for bid in bids[1]%> +<% for bid in bids[1]%> <% unless @user == bid.author %> @@ -12,9 +12,8 @@
+     + <%= l(:label_course_homework) %> : <%= link_to(bid.courses.first.name, project_path(bid.courses.first)) %> - + <% else %><%= l(:label_x_homework_project, :count => bid.biding_projects.count) %>(<%= link_to bid.biding_projects.count, project_for_bid_path(bid.id) %>)<% end %> <%= l(:label_x_responses, :count => bid.commit) %>(<%= link_to bid.commit, respond_path(bid) %>)
<%= link_to(bid.author.lastname+bid.author.firstname, user_path(bid.author), :class => 'bid_user') %>:  <%= link_to(bid.name, respond_path(bid), :class => 'bid_path') %> -     - <%= l(:label_course_homework) %> : <%= link_to(bid.courses.first.name, project_path(bid.courses.first)) %> -
@@ -23,11 +22,9 @@ <% if bid.reward_type.nil? or bid.reward_type == 1 %> <%= l(:label_bids_reward_method) %><%= l(:label_call_bonus) %> <%= l(:label_RMB_sign) %><%= bid.budget%> <% elsif bid.reward_type == 2 %> <%= l(:label_bids_reward_method) %><%= bid.budget%> <% else %> <% end %>
- <% if bid.homework_type == 1%> + <% if bid.homework_type == 1%> <%= l(:label_x_homework_project, :count => bid.homeworks.count) %>(<%= link_to bid.homeworks.count, project_for_bid_path(bid.id) %>) - <% else %><%= l(:label_x_homework_project, :count => bid.biding_projects.count) %>(<%= link_to bid.biding_projects.count, project_for_bid_path(bid.id) %>)<% end %> - <%= l(:label_x_responses, :count => bid.commit) %>(<%= link_to bid.commit, respond_path(bid) %>)
<%= format_time bid.created_on %> @@ -50,5 +47,7 @@ <% end %> <% else %> -

<%= l(:label_my_honework_no_homework) %>

+

+ <%= l(:label_my_honework_no_homework) %> +

<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 7b929afcb..bf98b2858 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -60,6 +60,7 @@ RedmineApp::Application.routes.draw do post 'boards/:board_id/topics/:id/replies', :to => 'messages#reply' post 'boards/:board_id/topics/:id/edit', :to => 'messages#edit' post 'boards/:board_id/topics/:id/destroy', :to => 'messages#destroy' + post 'bids/homework_destroy', :to => 'bids#homework_destroy' # Misc issue routes. TODO: move into resources match '/issues/auto_complete', :to => 'auto_completes#issues', :via => :get, :as => 'auto_complete_issues' From fd144574462f2fd70fc7b5ed925c39756cb0b8a5 Mon Sep 17 00:00:00 2001 From: xianbo Date: Sat, 12 Oct 2013 10:05:05 +0800 Subject: [PATCH 5/6] add delete homework in course --- app/controllers/bids_controller.rb | 1 + app/views/bids/_bid_homework_show.html.erb | 18 +++++++++++++++--- app/views/messages/show.html.erb | 2 +- app/views/users/_my_create_homework.html.erb | 15 ++++++++------- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 0c39ee5c6..f61ed35f6 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -373,6 +373,7 @@ class BidsController < ApplicationController #by xianbo def homework_destroy @bid_to_destroy = Bid.find params[:course_id] + (render_403; return false) unless User.current.admin?||User.current.id==bid.author_id @bid_to_destroy.destroy respond_to do |format| format.html { redirect_to :back } diff --git a/app/views/bids/_bid_homework_show.html.erb b/app/views/bids/_bid_homework_show.html.erb index 840a661cc..78a4d6f40 100644 --- a/app/views/bids/_bid_homework_show.html.erb +++ b/app/views/bids/_bid_homework_show.html.erb @@ -7,22 +7,34 @@ - + +
<%= link_to(bid.author.lastname+bid.author.firstname, user_path(bid.author), :class => 'bid_user') %>:  <%= link_to(bid.name, respond_path(bid), :class => 'bid_path') %><%= link_to(bid.author.lastname+bid.author.firstname, user_path(bid.author), :class => 'bid_user') %>:  <%= link_to(bid.name, respond_path(bid), :class => 'bid_path') %> + + <%= link_to( + l(:button_delete), + {:action => 'homework_destroy', :controller=>'bids', :course_id => bid.id}, + :method => :post, + :data => {:confirm => l(:text_are_you_sure)}, + :class => 'icon icon-del' + ) if (User.current.admin?||User.current.id==bid.author_id)&&(bid.homework_type == 1)%>
diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb index 0529de844..3787efe4a 100644 --- a/app/views/messages/show.html.erb +++ b/app/views/messages/show.html.erb @@ -20,7 +20,7 @@ :method => :post, :data => {:confirm => l(:text_are_you_sure)}, :class => 'icon icon-del' - ) if @message.destroyable_by?(User.current) %> + ) if @bid.destroyable_by?(User.current) %>

<%= avatar(@topic.author, :size => "24") %><%=h @topic.subject %>

diff --git a/app/views/users/_my_create_homework.html.erb b/app/views/users/_my_create_homework.html.erb index 845fb093e..6f17ab265 100644 --- a/app/views/users/_my_create_homework.html.erb +++ b/app/views/users/_my_create_homework.html.erb @@ -13,13 +13,14 @@ + <%= l(:label_course_homework) %> : <%= link_to(bid.courses.first.name, project_path(bid.courses.first)) %> + <%= link_to( + l(:button_delete), + {:action => 'homework_destroy', :controller=>'bids', :course_id => bid.id}, + :method => :post, + :data => {:confirm => l(:text_are_you_sure)}, + :class => 'icon icon-del' + ) if User.current.admin?||User.current.id==bid.author_id%> From d3f46adc34a18f072f52958eb9682ddc23f2e65d Mon Sep 17 00:00:00 2001 From: xianbo Date: Sat, 12 Oct 2013 10:08:45 +0800 Subject: [PATCH 6/6] fix --- app/controllers/bids_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index f61ed35f6..499d90a92 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -373,7 +373,7 @@ class BidsController < ApplicationController #by xianbo def homework_destroy @bid_to_destroy = Bid.find params[:course_id] - (render_403; return false) unless User.current.admin?||User.current.id==bid.author_id + (render_403; return false) unless User.current.admin?||User.current.id==@bid_to_destroy.author_id @bid_to_destroy.destroy respond_to do |format| format.html { redirect_to :back }
<% if bid.reward_type.nil? or bid.reward_type == 1 %> <%= l(:label_bids_reward_method) %><%= l(:label_call_bonus) %> <%= l(:label_RMB_sign) %> - <%= bid.budget%> <% elsif bid.reward_type == 2 %> <%= l(:label_bids_reward_method) %><%= bid.budget%> <% else %> + <%= bid.budget%> <% elsif bid.reward_type == 2 %> <%= l(:label_bids_reward_method) %><%= bid.budget%> + <% else %> <% end %>
<% if bid.homework_type == 1%> + <%= l(:label_x_homework_project, :count => bid.homeworks.count) %>(<%= link_to bid.homeworks.count, project_for_bid_path(bid.id) %>) - <% else %><%= l(:label_x_homework_project, :count => bid.biding_projects.count) %>(<%= link_to bid.biding_projects.count, project_for_bid_path(bid.id) %>)<% end %> + <% else %><%= l(:label_x_homework_project, :count => bid.biding_projects.count) %>(<%= link_to bid.biding_projects.count, project_for_bid_path(bid.id) %> + )<% end %> <%= l(:label_x_responses, :count => bid.commit) %>(<%= link_to bid.commit, respond_path(bid) %>)
<%= link_to(bid.author.lastname+bid.author.firstname, user_path(bid.author), :class => 'bid_user') %>:   <%= link_to(bid.name, respond_path(bid), :class => 'bid_path') %>    - <%= l(:label_course_homework) %> : <%= link_to(bid.courses.first.name, project_path(bid.courses.first)) %> <%= link_to( - l(:button_delete), - {:action => 'homework_destroy', :controller=>'bids', :course_id => bid.id}, - :method => :post, - :data => {:confirm => l(:text_are_you_sure)}, - :class => 'icon icon-del' - ) %>