From 602e3dc3fa686bb545450c5f33732abcbf1f6211 Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Thu, 12 Sep 2013 17:19:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=AA=E4=BA=BA=E4=B8=BB?= =?UTF-8?q?=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 +- app/controllers/projects_controller.rb | 7 ++-- app/controllers/users_controller.rb | 55 ++++++++++++++++++++++++- app/helpers/users_helper.rb | 16 ++++++++ app/models/bid.rb | 2 +- app/models/project.rb | 2 +- app/views/courses/_set_join.js.erb | 3 ++ app/views/projects/_new_join.html.erb | 2 +- app/views/projects/settings.html.erb | 2 +- app/views/users/_my_course.html.erb | 42 +++++++++++++++++++ app/views/users/_my_homework.html.erb | 56 ++++++++++++++++++++++++++ app/views/users/user_courses.html.erb | 10 +++++ config/routes.rb | 1 + lib/redmine.rb | 1 + 14 files changed, 191 insertions(+), 10 deletions(-) create mode 100644 app/views/courses/_set_join.js.erb create mode 100644 app/views/users/_my_course.html.erb create mode 100644 app/views/users/_my_homework.html.erb create mode 100644 app/views/users/user_courses.html.erb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 8011b238b..8d5ef1a67 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1,4 +1,4 @@ -class CourseController < ApplicationController +class CoursesController < ApplicationController before_filter :require_login, :only => [:join, :unjoin] diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 5908c5940..2769b4736 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -355,7 +355,7 @@ class ProjectsController < ApplicationController redirect_to new_project_path(:course => '1') #Ended by young else - redirect_to settings_project_path(@project, :course => @course_tag) + redirect_to settings_project_path(@project) end } format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } @@ -430,7 +430,8 @@ class ProjectsController < ApplicationController "show_issues" => true, "show_files" => true, "show_documents" => true, - "show_messages" => true + "show_messages" => true, + "show_bids" => true } @date_to ||= Date.today + 1 @date_from = @date_to - @days @@ -483,7 +484,7 @@ class ProjectsController < ApplicationController #Added by young # @course_tag = params[:course] # if @course_tag == '1' - if @project.project_type + if @project.project_type == 1 render :layout => 'base_courses' end #Ended by young diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index fa8879921..20246bc45 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -22,11 +22,12 @@ class UsersController < ApplicationController menu_item :user_project, :only => :user_projects menu_item :requirement_focus, :only => :watch_bids menu_item :user_newfeedback, :only => :user_newfeedback + menu_item :user_course, :only => :user_courses #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,:edit,:update] - before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, + before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info, :user_watchlist, :user_fanslist,:edit,:update, :user_courses] + before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info] accept_api_auth :index, :show, :create, :update, :destroy,:tag_save @@ -117,6 +118,56 @@ class UsersController < ApplicationController 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 = [] + @membership.each do |membership| + if membership.project.project_type == 1 + @memberships << membership + end + end + @bid = [] + @memberships.each do |membership| + @bid += membership.project.homeworks + end + @state = 1 + else + @membership = @user.memberships.all(:conditions => Project.visible_condition(User.current)) + + @memberships = [] + @membership.each do |membership| + if membership.project.project_type == 1 + @memberships << membership + end + end + @state = 0 + end + + # events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 20) + # @events_by_day = events.group_by(&:event_date) + + # @state = 0 + + #add by huang + unless User.current.admin? + if !@user.active? #|| (@user != User.current && @memberships.empty? && events.empty?) + render_404 + return + end + end + #end + + # respond_to do |format| + # format.html + # format.api + # end + end + # end # modified by fq def user_newfeedback diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 32c4b6142..3e4700cff 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -90,6 +90,22 @@ module UsersHelper end content_tag('div', content, :class => "pagination") end + + def user_course(state) + content = ''.html_safe + case state + when 0 + s = content_tag('span', '我的课程', :class => "current-page") + content << content_tag('li', s) + content << content_tag('li', link_to('我的作业', {:controller => 'users', :action => 'user_courses', :type => 1})) + when 1 + s = content_tag('span', '我的作业', :class => "current-page") + content << content_tag('li', link_to('我的课程', {:controller => 'users', :action => 'user_courses'})) + content << content_tag('li', s, :class => "current-page") + end + content_tag('div', content, :class => "pagination") + + end # added by huang def sort_user(state) diff --git a/app/models/bid.rb b/app/models/bid.rb index c79f8fd10..a017cb48b 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -48,7 +48,7 @@ class Bid < ActiveRecord::Base :author => :author, :url => Proc.new {|o| {:controller => 'bids', :action => 'show', :id => o.id}} - acts_as_activity_provider :find_options => {:include => [:author]}, + acts_as_activity_provider :find_options => {:include => [:project, :author]}, :author_key => :author_id diff --git a/app/models/project.rb b/app/models/project.rb index 4e0e4549c..dfdca8a03 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -54,7 +54,7 @@ class Project < ActiveRecord::Base # added by fq has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :homework_for_courses, :dependent => :destroy - has_many :homeworks, :through => :homework_for_courses, :source => :bid + has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy has_many :students_for_courses, :dependent => :destroy has_many :student, :through => :students_for_courses, :source => :user diff --git a/app/views/courses/_set_join.js.erb b/app/views/courses/_set_join.js.erb new file mode 100644 index 000000000..cd6ca1b59 --- /dev/null +++ b/app/views/courses/_set_join.js.erb @@ -0,0 +1,3 @@ + + +$('#join').html('<%= escape_javascript join_in_course(course, user) %>'); diff --git a/app/views/projects/_new_join.html.erb b/app/views/projects/_new_join.html.erb index 244bb95cb..b96ce346c 100644 --- a/app/views/projects/_new_join.html.erb +++ b/app/views/projects/_new_join.html.erb @@ -1,6 +1,6 @@
<%= link_to image_tag(url_to_avatar(membership.project), :class => 'avatar'), project_path(membership.project) %> | +
+
|
+
<%= l(:label_project_un) %>
+<% else %> +<%= l(:label_project_unadd) %><%= link_to"#{l(:label_new)}",:controller=>'projects',:action=>'new'%>
+<% end %> + +<% end %> +<%= call_hook :view_account_left_bottom, :user => @user %> +<%= link_to image_tag(url_to_avatar(bid.author), :class => 'avatar'),user_path(bid.author), :class => "avatar" %> | +
+
|
+
暂无任何作业
+<% end %> \ No newline at end of file diff --git a/app/views/users/user_courses.html.erb b/app/views/users/user_courses.html.erb new file mode 100644 index 000000000..8124468da --- /dev/null +++ b/app/views/users/user_courses.html.erb @@ -0,0 +1,10 @@ + + +<%= user_course @state%> + +<% if @state == 0%> +<%= render :partial => 'my_course' %> +<% else %> +<%= render :partial => 'my_homework' %> +<% end %> + diff --git a/config/routes.rb b/config/routes.rb index 282a36ddc..b79a490db 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -89,6 +89,7 @@ RedmineApp::Application.routes.draw do match 'info', :to => 'users#info', :via => [:get , :post], :as => 'user_info' 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 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 59c6e6d94..1f6cacd2d 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -279,6 +279,7 @@ end Redmine::MenuManager.map :user_menu do |menu| menu.push :activity, {:controller => 'users', :action => 'show' } menu.push :user_project, {:controller => 'users', :action => 'user_projects'} + menu.push :user_course, {:controller => 'users', :action => 'user_courses'} menu.push :requirement_focus, {:controller => 'users', :action => 'watch_bids'} menu.push :user_newfeedback, {:controller => 'users', :action => 'user_newfeedback'}