diff --git a/Gemfile b/Gemfile index 3784e60d..9dae2827 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ gem "i18n", "~> 0.6.0" gem "coderay", "~> 1.0.6" gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby] gem "builder", "3.0.0" -gem 'acts-as-taggable-on' +gem 'acts-as-taggable-on', '2.4.1' group :development do gem 'better_errors', path: 'lib/better_errors' diff --git a/Gemfile.lock b/Gemfile.lock index 6680070a..e6ee7da7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -134,7 +134,7 @@ PLATFORMS DEPENDENCIES activerecord-jdbc-adapter (= 1.2.5) activerecord-jdbcmysql-adapter - acts-as-taggable-on + acts-as-taggable-on (= 2.4.1) better_errors! builder (= 3.0.0) coderay (~> 1.0.6) diff --git a/ReadMe.txt b/ReadMe.txt index 9d223259..0fcba47c 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -44,4 +44,10 @@ app\controller\welcome_controller.rb return 0 end end -================================================================================ \ No newline at end of file +================================================================================ + +================================================================================ +0606:新坑 +user_scores表结构有问题,需要运行 +bundle exec rake db:migrate:down VERSION=20140410021724 +bundle exec rake db:migrate:up VERSION=20140410021724 \ No newline at end of file diff --git a/app/assets/javascripts/contestnotifications.js b/app/assets/javascripts/contestnotifications.js new file mode 100644 index 00000000..dee720fa --- /dev/null +++ b/app/assets/javascripts/contestnotifications.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/javascripts/notificationcomments.js.coffee b/app/assets/javascripts/notificationcomments.js.coffee new file mode 100644 index 00000000..76156794 --- /dev/null +++ b/app/assets/javascripts/notificationcomments.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/contestnotifications.css b/app/assets/stylesheets/contestnotifications.css new file mode 100644 index 00000000..afad32db --- /dev/null +++ b/app/assets/stylesheets/contestnotifications.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/app/assets/stylesheets/notificationcomments.css.scss b/app/assets/stylesheets/notificationcomments.css.scss new file mode 100644 index 00000000..aea714e4 --- /dev/null +++ b/app/assets/stylesheets/notificationcomments.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the notificationcomments controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5c42db5c..af6fbd63 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -294,6 +294,20 @@ class ApplicationController < ActionController::Base render_404 end + def find_contest_by_contest_id + @contest = Contest.find(params[:contest_id]) + rescue ActiveRecord::RecordNotFound + render_404 + end + + #course_idproject + def find_project_by_course_id + @bid = Bid.find params[:course_id] + @project = @bid.courses[0] + rescue ActiveRecord::RecordNotFound + render_404 + end + # Find a project based on params[:project_id] # TODO: some subclasses override this, see about merging their logic def find_optional_project @@ -304,6 +318,14 @@ class ApplicationController < ActionController::Base render_404 end + def find_optional_contest + @contest = Contest.find(params[:contest_id]) unless params[:contest_id].blank? + allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @contest, :global => true) + allowed ? true : deny_access + rescue ActiveRecord::RecordNotFound + render_404 + end + # Finds and sets @project based on @object.project def find_project_from_association render_404 unless @object.present? @@ -314,6 +336,12 @@ class ApplicationController < ActionController::Base end end + + def find_contest_from_association + render_404 unless @object.present? + + @contest =@object.contest + end def find_model_object model = self.class.model_object @@ -326,13 +354,23 @@ class ApplicationController < ActionController::Base end #added by nwb - #获取课程 + #ȡγ def find_course @course= Course.find(params[:id]) rescue ActiveRecord::RecordNotFound render_404 end + # def find_model_object_contest + # model = self.class.model_object + # if model + # @object = model.find(params[:id]) + # self.instance_variable_set('@' + controller_name.singularize, @object) if @object + # end + # rescue ActiveRecord::RecordNotFound + # render_404 + # end + def self.model_object(model) self.model_object = model end diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index ab392789..a0c85689 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -25,7 +25,14 @@ class BidsController < ApplicationController helper :projects helper :words helper :welcome - + + def find_project_by_bid_id + @bid = Bid.find(params[:id]) + @project = @bid.courses[0] + rescue ActiveRecord::RecordNotFound + render_404 + end + def homework_ajax_modal @bid = Bid.find_by_id(params[:id]) # find_bid @@ -176,7 +183,8 @@ class BidsController < ApplicationController @homework.budget = 0 @homework.author_id = User.current.id @homework.commit = 0 - @homework.homework_type = params[:bid][:homework_type] + @homework.homework_type = 1 + @homework.is_evaluation = params[:bid][:is_evaluation] @homework.parent_id = @bid.id @homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads])) # @bid. @@ -405,7 +413,9 @@ class BidsController < ApplicationController if @bid.homework_type == 1 @homework = HomeworkAttach.new - @homework_list = @bid.homeworks + #@homework_list = @bid.homeworks + #增加作业按评分排序, + @homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC") if params[:student_id].present? @temp = [] @homework_list.each do |pro| @@ -521,6 +531,7 @@ class BidsController < ApplicationController message = params[:bid_message][:message] + "\n" + params[:reference_content] else message = params[:bid_message][:message] + @m = message end refer_user_id = params[:bid_message][:reference_user_id].to_i @bid.add_jour(User.current, message, refer_user_id) @@ -687,6 +698,7 @@ class BidsController < ApplicationController @bid = Bid.new @bid.name = params[:bid][:name] @bid.description = params[:bid][:description] + @bid.is_evaluation = params[:bid][:is_evaluation] @bid.reward_type = 3 # @bid.budget = params[:bid][:budget] @bid.deadline = params[:bid][:deadline] @@ -870,7 +882,7 @@ class BidsController < ApplicationController def find_bid if params[:id] - @bid = Bid.find(params[:id]) + @bid = Bid.find(params[:id], :include => [{:homeworks => :user}]) @user = @bid.author end rescue diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index b2689d0c..90c034fd 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -18,7 +18,7 @@ class CommentsController < ApplicationController default_search_scope :news model_object News - before_filter :find_model_object + before_filter :find_model_object before_filter :find_project_from_association before_filter :authorize @@ -50,4 +50,6 @@ class CommentsController < ApplicationController @comment = nil @news end + + end diff --git a/app/controllers/contestnotifications_controller.rb b/app/controllers/contestnotifications_controller.rb new file mode 100644 index 00000000..6b05e8e4 --- /dev/null +++ b/app/controllers/contestnotifications_controller.rb @@ -0,0 +1,187 @@ +class ContestnotificationsController < ApplicationController + # GET /contestnotifications + # GET /contestnotifications.json + layout 'base_newcontest' + default_search_scope :contestnotifications + model_object Contestnotification + # before_filter :find_model_object, :except => [:new, :create, :index] + # before_filter :find_contest_from_association, :except => [:new, :create, :index] + before_filter :find_contest_by_contest_id, :only => [:new, :create] + before_filter :find_contest + before_filter :find_author + # before_filter :authorize, :except => [:index] + before_filter :find_optional_contest, :only => [:index] + accept_rss_auth :index + accept_api_auth :index + + before_filter :access_edit_destroy, only: [:edit ,:update, :destroy] + + def find_author + @user = @contest.author + render_404 if @user.nil? + end + def find_contest + @contest = Contest.find(params[:contest_id]) + render_404 if @contest.nil? + end + + + def index + + # @contestnotifications = Contestnotification.all + # + # respond_to do |format| + # format.html # index.html.erb + # format.json { render json: @contestnotifications } + # end + + ### begin ### + case params[:format] + when 'xml', 'json' + @offset, @limit = api_offset_and_limit + else + @limit = 10 + end + + scope = @contest ? @contest.contestnotifications.visible : Contestnotifications.visible + + @contestnotifications_count = scope.count + @contestnotifications_pages = Paginator.new @contestnotifications_count, @limit, params['page'] + @offset ||= @contestnotifications_pages.offset + @contestnotificationss = scope.all(:include => [:author, :contest], + :order => "#{Contestnotification.table_name}.created_at DESC", + :offset => @offset, + :limit => @limit) + + respond_to do |format| + format.html { + @contestnotification = Contestnotification.new # for adding news inline + render :layout => 'base_newcontest' + } + format.api + format.atom { render_feed(@contestnotificationss, :title => (@contest ? @contest.name : Setting.app_title) + ": #{l(:label_contest_notification)}") } + end + ### end ### + end + + # GET /contestnotifications/1 + # GET /contestnotifications/1.json + def show + @contestnotification = Contestnotification.find(params[:id]) + + # + # respond_to do |format| + # format.html # show.html.erb + # format.json { render json: @contestnotification } + # end + @notificationcomments = @contestnotification.notificationcomments + @notificationcomments.reverse! if User.current.wants_notificationcomments_in_reverse_order? + render :layout => 'base_newcontest' + + end + + # GET /contestnotifications/new + # GET /contestnotifications/new.json + def new + # @contestnotification = Contestnotification.new +# + # respond_to do |format| + # format.html # new.html.erb + # format.json { render json: @contestnotification } + # end + @contestnotification = Contestnotification.new(:contest => @contest, :author => User.current) + render :layout => 'base_newcontest' + end + + # GET /contestnotifications/1/edit + def edit + @contestnotification = Contestnotification.find(params[:id]) + end + + # POST /contestnotifications + # POST /contestnotifications.json + def create + # @contestnotification = Contestnotification.new(params[:contestnotification]) + # + # respond_to do |format| + # if @contestnotification.save + # format.html { redirect_to @contestnotification, notice: 'Contestnotification was successfully created.' } + # format.json { render json: @contestnotification, status: :created, location: @contestnotification } + # else + # format.html { render action: "new" } + # format.json { render json: @contestnotification.errors, status: :unprocessable_entity } + # end + # end + @contestnotification = Contestnotification.new(:contest => @contest, :author => User.current) + @contestnotification.safe_attributes = params[:contestnotification] + @contestnotification.save_attachments(params[:attachments]) + if @contestnotification.save + render_attachment_warning_if_needed(@contestnotification) + flash[:notice] = l(:notice_successful_create) + redirect_to contest_contestnotifications_path(@contest) + else + layout_file = 'base_newcontest' + render :action => 'new', :layout => layout_file + end + end + + # PUT /contestnotifications/1 + # PUT /contestnotifications/1.json + def update + # @contestnotification = Contestnotification.find(params[:id]) + # + # respond_to do |format| + # if @contestnotification.update_attributes(params[:contestnotification]) + # format.html { redirect_to @contestnotification, notice: 'Contestnotification was successfully updated.' } + # format.json { head :no_content } + # else + # format.html { render action: "edit" } + # format.json { render json: @contestnotification.errors, status: :unprocessable_entity } + # end + # end + @contestnotification = Contestnotification.find(params[:id]) + @contestnotification.safe_attributes = params[:contestnotification] + @contestnotification.save_attachments(params[:attachments]) + if @contestnotification.save + render_attachment_warning_if_needed(@contestnotification) + flash[:notice] = l(:notice_successful_update) + redirect_to contest_contestnotification_path(@contestnotification.contest, @contestnotification) + else + render :action => 'edit' + end + end + + # DELETE /contestnotifications/1 + # DELETE /contestnotifications/1.json + def destroy + # @contestnotification = Contestnotification.find(params[:id]) + # @contestnotification.destroy + # + # respond_to do |format| + # format.html { redirect_to contestnotifications_url } + # format.json { head :no_content } + # end + @contestnotification = Contestnotification.find(params[:id]) + @contestnotification.destroy + redirect_to contest_contestnotifications_path(@contest) + end + + private + + def find_optional_contest + return true unless params[:id] + @contest = Contest.find(params[:id]) + # authorize + rescue ActiveRecord::RecordNotFound + render_404 + end + + def access_edit_destroy + if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?) + return true + else + render_403 + end + end + +end diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index b83040ef..f50fe191 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -4,9 +4,9 @@ class ContestsController < ApplicationController menu_item :respond menu_item :project, :only => :show_project menu_item :application, :only => :show_softapplication - menu_item :attendingcontest, :only => :show_attendingcontest - menu_item :contestnotification, :only => :show_notification - before_filter :find_contest, :only => [:show_contest, :show_project, :show_softapplication, :show_attendingcontest, :show_notification, :set_reward_project, :set_reward_softapplication, :create,:destroy,:more,:back,:add,:add_softapplication,:new,:show_results, :set_reward, + menu_item :attendingcontests, :only => :show_attendingcontest + menu_item :contestnotifications, :only => :index + before_filter :find_contest, :only => [:show_contest, :show_project, :show_softapplication, :show_attendingcontest, :index, :set_reward_project, :set_reward_softapplication, :create,:destroy,:more,:back,:add,:add_softapplication,:new,:show_results, :set_reward, :show_contest_project, :show_contest_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings] # added by fq @@ -210,11 +210,14 @@ class ContestsController < ApplicationController # @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page'] @membership.each do |membership| unless(membership.project.project_type==1) - membership.member_roles.each{|role| - if(role.role_id == 3) - @option << membership.project - end - } + #membership.member_roles.each{|role| + # if(role.role_id == 3) + # @option << membership.project + # end + #} + if User.current.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false) + @option << membership.project + end end end @user = @contest.author @@ -301,11 +304,15 @@ class ContestsController < ApplicationController # @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page'] @membership.each do |membership| unless(membership.project.project_type==1) - membership.member_roles.each{|role| - if(role.role_id == 3) + #membership.member_roles.each{|role| + #if(role.role_id == 3) + #@option << membership.project + #end + #} + #拥有编辑项目权限的可将该项目参赛 + if User.current.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false) @option << membership.project - end - } + end end end @user = @contest.author diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 51486f25..464c4a2b 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -62,6 +62,7 @@ class DocumentsController < ApplicationController def create @document = @project.documents.build @document.safe_attributes = params[:document] + @document.user = User.current @document.save_attachments(params[:attachments]) if @document.save render_attachment_warning_if_needed(@document) diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 24e1a86e..d10f09ff 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -1,5 +1,30 @@ class HomeworkAttachController < ApplicationController ############################### + #判断当前角色权限时需先找到当前操作的project + before_filter :find_project_by_bid_id, :only => [:new] + before_filter :find_project_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users] + #判断当前角色是否有操作权限 + #勿删 before_filter :authorize, :only => [:new,:edit,:update,:destroy] + + def find_project_by_bid_id + @bid = Bid.find(params[:id]) + @project = @bid.courses[0] + rescue ActiveRecord::RecordNotFound + render_404 + end + + def find_project_by_hoemwork_id + @homework = HomeworkAttach.find(params[:id]) + @project = @homework.bid.courses[0] + end + + #获取作业的成员 + def get_homework_member homework + @hoemwork_users = users_for_homework(@homework) + @members = members_for_homework(@homework,@hoemwork_users,params[:q]) + @members = paginateHelper @members,10 + end + def index @homeworks = HomeworkAttach.all respond_to do |format| @@ -8,114 +33,213 @@ class HomeworkAttachController < ApplicationController end end - def add_users users - if users != nil && users.count > 0 - users.each do |user| - @homework.homework_users.build(:user_id => user.id) - @homework.save + #作业添加成员(参与人员) + def add_homework_users + if User.current.admin? || User.current.member_of?(@homework.bid.courses.first) + #@homework = HomeworkAttach.find(params[:id]) + if params[:membership] + if params[:membership][:user_ids] + attrs = params[:membership].dup + user_ids = attrs.delete(:user_ids) + user_ids.each do |user_id| + @homework.homework_users.build(:user_id => user_id) + end + end end + @homework.save + get_homework_member @homework + respond_to do |format| + format.js + end + else + render_403 :message => :notice_not_authorized + end + end + + #作业删除成员(参与人员) + def destory_homework_users + #@homework = HomeworkAttach.find(params[:id]) + if User.current.admin? || User.current.member_of?(@homework.bid.courses.first) + homework_user = @homework.homework_users.where("user_id = #{params[:user_id]}").first + homework_user.destroy + get_homework_member @homework + respond_to do |format| + format.js + end + else + render_403 :message => :notice_not_authorized end end def create - #if User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0) - user_id = params[:user_id] - bid_id = params[:bid_id] - sta = 0 - name = params[:new_form][:name] - description = params[:new_form][:description] - options = { - :user_id => user_id, - :state => sta, - :name => name, - :description => description, - :bid_id => bid_id - } + bid = Bid.find params[:bid_id] + if User.current.admin? || User.current.member_of?(bid.courses.first) + if bid.homeworks.where("user_id = ?",User.current).count == 0 + user_id = params[:user_id] + bid_id = params[:bid_id] + sta = 0 + name = params[:new_form][:name] + description = params[:new_form][:description] + options = { + :user_id => user_id, + :state => sta, + :name => name, + :description => description, + :bid_id => bid_id + } - #@bid = Bid.find bid_id - #@homework_list = @bid.homeworks - @homework = HomeworkAttach.new(options) - @homework.save_attachments(params[:attachments]) - render_attachment_warning_if_needed(@homework) + #@homework_list = @bid.homeworks + @homework = HomeworkAttach.new(options) + @homework.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(@homework) + + if @homework.save + respond_to do |format| + format.html { redirect_to project_for_bid_path @homework.bid } + format.json { head :no_content } + end + else + render_403 :message => :notice_not_authorized + end + else + render_403 :message => :notice_has_homework + end + else + render_403 :message => :notice_not_authorized + end + end + + def new + @bid = Bid.find(params[:id]) + if User.current.admin? || User.current.member_of?(@bid.courses.first) + #该课程的学生的集合(新建不实现功能:添加成员) + #@members = @bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id <> #{User.current.id}", {:role_id => [5, 10]}) + + #@members = paginateHelper @members,10 + #@all_user = [] + #@bid.courses.first.members.each do |member| + # @all_user << member.user + #end + @homework = HomeworkAttach.new + #@homework_user = members_for_homework(@homework) + User.current + #@members = @all_user - @homework_user + respond_to do |format| + format.html # new.html.erb + format.json { render json: @homework } + end + else + render_403 :message => :notice_not_authorized + end + end + + #获取作业成员的集合 + def get_homework_member_list + @homework = HomeworkAttach.find(params[:bid_id]) + course = @homework.bid.courses.first + if User.current.admin? || User.current.member_of?(course) + get_homework_member @homework + else + raise "error" + end + respond_to do |format| + format.js + end + end + + #获取指定作业的所有成员 + def users_for_homework homework + homework.nil? ? [] : (homework.users + [homework.user]) + end + + #获取可选成员列表 + #homework:作业 + #users:该作业所有成员 + #q:模糊匹配的用户的昵称 + def members_for_homework homework,users,q + homework.bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id not in (:users)", {:role_id => [5, 10],:users => users}).joins(:user).where("users.login like '%#{q}%'") + end + + def edit + #@homework = HomeworkAttach.find(params[:id]) + if User.current.admin? || User.current.member_of?(@homework.bid.courses.first) + #@members = @homework.bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id)", {:role_id => [5, 10]}) + get_homework_member @homework + else + render_403 :message => :notice_not_authorized + end + end + + def update + #@homework = HomeworkAttach.find(params[:id]) + course = @homework.bid.courses.first + if User.current.admin? || User.current.member_of?(course) + name = params[:homework_name] + description = params[:homework_description] + @homework.name = name + @homework.description = description + if params[:attachments] + @homework.save_attachments(params[:attachments]) + end if @homework.save respond_to do |format| format.html { redirect_to project_for_bid_path @homework.bid } format.json { head :no_content } end else - - end - #end - end - - def new - @homework = HomeworkAttach.new - @bid = Bid.find(params[:id]) - - respond_to do |format| - format.html # new.html.erb - format.json { render json: @homework } - end - end - - def edit - @homework = HomeworkAttach.find(params[:id]) - end - - def update - @homework = HomeworkAttach.find(params[:id]) - name = params[:homework_name] - description = params[:homework_description] - @homework.name = name - @homework.description = description - if params[:attachments] - @homework.save_attachments(params[:attachments]) - end - if @homework.save - respond_to do |format| - format.html { redirect_to project_for_bid_path @homework.bid } - format.json { head :no_content } end else + render_403 :message => :notice_not_authorized end end def destroy - @homework = HomeworkAttach.find(params[:id]) - if @homework.destroy - respond_to do |format| - format.html { redirect_to project_for_bid_path @homework.bid } - format.json { head :no_content } + #@homework = HomeworkAttach.find(params[:id]) + if User.current.admin? || User.current == @homework + if @homework.destroy + respond_to do |format| + format.html { redirect_to project_for_bid_path @homework.bid } + format.json { head :no_content } + end + else end else + render_403 :message => :notice_not_authorized end end #显示作业信息 def show - @homework = HomeworkAttach.find(params[:id]) - # 打分统计 - stars_reates = @homework. - rates(:quality) - stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count - stars_status = stars_reates.select("stars, count(*) as scount"). - group("stars") - @stars_status_map = Hash.new(0.0) - stars_status.each do |star_status| - percent = (star_status.scount * 1.0/ stars_reates_count) * 100.to_f - percent_m = format("%.2f", percent) - @stars_status_map["star#{star_status.stars.to_i}".to_sym] = - percent_m.to_s + "%" + #@homework = HomeworkAttach.find(params[:id]) + if User.current.admin? || User.current.member_of?(@homework.bid.courses.first) + # 打分统计 + stars_reates = @homework. + rates(:quality) + stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count + stars_status = stars_reates.select("stars, count(*) as scount"). + group("stars") + @stars_status_map = Hash.new(0.0) + stars_status.each do |star_status| + percent = (star_status.scount * 1.0/ stars_reates_count) * 100.to_f + percent_m = format("%.2f", percent) + @stars_status_map["star#{star_status.stars.to_i}".to_sym] = + percent_m.to_s + "%" + end + #是否已经进行过评价 + @has_evaluation = stars_reates.where("rater_id = ?",User.current).count > 0 + #是否开启互评功能 + @is_evaluation = @homework.bid.is_evaluation == 1 || @homework.bid.is_evaluation == nil + @limit = 10 + @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC") + @feedback_count = @jours.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + @jour = @jours[@offset, @limit] + @comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC") + else + render_403 :message => :notice_not_authorized end - @limit = 10 - @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC") - @feedback_count = @jours.count - @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - @offset ||= @feedback_pages.offset - @jour = @jours[@offset, @limit] - @comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC") end #删除留言 diff --git a/app/controllers/homework_users_controller.rb b/app/controllers/homework_users_controller.rb index cb55d965..5f473b42 100644 --- a/app/controllers/homework_users_controller.rb +++ b/app/controllers/homework_users_controller.rb @@ -1,3 +1,14 @@ class HomeworkUsersController < ApplicationController - + #新增数据 + def create option + user = HomeworkUser.new option + user.save + user + end + #删除数据 + def destory homework_user + user = HomeworkUser.find homework_user + user.destroy + user + end end diff --git a/app/controllers/issue_categories_controller.rb b/app/controllers/issue_categories_controller.rb index a716653a..9803eb78 100644 --- a/app/controllers/issue_categories_controller.rb +++ b/app/controllers/issue_categories_controller.rb @@ -19,6 +19,7 @@ class IssueCategoriesController < ApplicationController menu_item :settings model_object IssueCategory before_filter :find_model_object, :except => [:index, :new, :create] + #before_filter :find_model_object_contest, :except => [:index, :new, :create] before_filter :find_project_from_association, :except => [:index, :new, :create] before_filter :find_project_by_project_id, :only => [:index, :new, :create] before_filter :authorize @@ -119,4 +120,10 @@ class IssueCategoriesController < ApplicationController super @category = @object end + + def find_model_object_contest + super + @category = @object + end + end diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 53dd903e..76be0240 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -17,6 +17,7 @@ class MembersController < ApplicationController model_object Member before_filter :find_model_object, :except => [:index, :create, :autocomplete] + #before_filter :find_model_object_contest, :except => [:index, :create, :autocomplete] before_filter :find_project_from_association, :except => [:index, :create, :autocomplete] before_filter :find_project_by_project_id, :only => [:index, :create, :autocomplete] before_filter :authorize diff --git a/app/controllers/notificationcomments_controller.rb b/app/controllers/notificationcomments_controller.rb new file mode 100644 index 00000000..80500ab1 --- /dev/null +++ b/app/controllers/notificationcomments_controller.rb @@ -0,0 +1,27 @@ +class NotificationcommentsController < ApplicationController + # default_search_scope :contestnotifications + # model_object Contestnotifications + # before_filter :authorize + + def create + #raise Unauthorized unless @contestnotifications.notificationcommentable? + @contest = Contest.find(params[:contest_id]) + @contestnotification = Contestnotification.find(params[:contestnotification_id]) + + # @notificaioncomment = Notificationcomment.new + # @notificaioncomment.safe_attributes = params[:notificationcomment] + # @notificaioncomment.author = User.current + comment = @contestnotification.notificationcomments.new(params[:notificationcomment].merge(author_id: User.current.id)) + if comment.save + flash[:notice] = l(:label_comment_added) + end + + redirect_to contest_contestnotification_path(@contest, @contestnotification) + end + + def destroy + @contestnotifications.notificaioncomments.find(params[:notificaioncomment_id]).destroy + redirect_to contest_contestnotification_path(@contestnotifications) + end + +end diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index 53df54e9..97cf3cda 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -9,6 +9,7 @@ class PraiseTreadController < ApplicationController if request.get? @obj_id = params[:obj_id] @obj_type = params[:obj_type] + @horizontal = params[:horizontal] @obj = find_object_by_type_and_id(@obj_type,@obj_id) praise_tread_plus(@obj_type,@obj_id,1) end @@ -44,6 +45,7 @@ class PraiseTreadController < ApplicationController if request.get? @obj_id = params[:obj_id] @obj_type = params[:obj_type] + @horizontal = params[:horizontal] @obj = find_object_by_type_and_id(@obj_type,@obj_id) praise_tread_plus(@obj_type,@obj_id,0) end @@ -71,6 +73,10 @@ class PraiseTreadController < ApplicationController @obj = Bid.find_by_id(id) when 'Contest' @obj = Contest.find_by_id(id) + when 'Memo' + @obj = Memo.find_by_id(id) + when 'Message' + @obj = Message.find_by_id(id) end return @obj end diff --git a/app/controllers/previews_controller.rb b/app/controllers/previews_controller.rb index 0083116d..579f8caa 100644 --- a/app/controllers/previews_controller.rb +++ b/app/controllers/previews_controller.rb @@ -16,10 +16,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class PreviewsController < ApplicationController - before_filter :find_project, :find_attachments + before_filter :find_project, :find_attachments, :find_contest, except: [:contestnotification] def issue @issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank? + @issue = @contest.issues.find_by_id(params[:id]) unless params[:id].blank? if @issue @description = params[:issue] && params[:issue][:description] if @description && @description.gsub(/(\r?\n|\n\r?)/, "\n") == @issue.description.to_s.gsub(/(\r?\n|\n\r?)/, "\n") @@ -41,6 +42,12 @@ class PreviewsController < ApplicationController render :partial => 'common/preview' end + def contestnotification + @previewed = Contestnotification.find(params[:id]) + @text = (params[:contestnotification] ? params[:contestnotification][:description] : nil) + render :partial => 'common/preview' + end + private def find_project @@ -50,4 +57,20 @@ class PreviewsController < ApplicationController render_404 end + def contestnotifications + if params[:id].present? && contestnotifications = Contestnotifications.visible.find_by_id(params[:id]) + @previewed = contestnotifications + end + @text = (params[:contestnotifications] ? params[:contestnotifications][:description] : nil) + render :partial => 'common/preview' + end + + private + def find_contest + contest_id = (params[:issue] && params[:issue][:contest_id]) || params[:contest_id] + @contest = Contest.find(contest_id) + rescue ActiveRecord::RecordNotFound + render_404 + end + end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 032e2f00..b7824c7e 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -37,6 +37,7 @@ class ProjectsController < ApplicationController # before_filter :authorize, :except => [:new_join, :new_homework, :homework, :statistics, :search, :watcherlist, :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy, :member, :focus, :file, # :statistics, :feedback, :course, :enterprise_course, :course_enterprise, :project_respond, :share, # :show_projects_score, :issue_score_index, :news_score_index, :file_score_index, :code_submit_score_index, :projects_topic_score_index] + #此条勿删 课程相关权限 ,:new_homework,:homework,:feedback,,:member before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course] before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches] before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] @@ -716,6 +717,9 @@ class ProjectsController < ApplicationController @teachers= searchTeacherAndAssistant(@project) @canShowRealName = isCourseTeacher(User.current.id) end + + #勿删 real_name action为虚拟的该方法并不存在,用来辅助判断真名权限 + #勿删 @canShowRealName = User.current.allowed_to?({:controller => "projects", :action => "real_name"}, @project || @projects, :global => false) respond_to do |format| format.html{render :layout => 'base_courses' if @base_courses_tag==1} format.api diff --git a/app/controllers/softapplications_controller.rb b/app/controllers/softapplications_controller.rb index b8d81b10..362a04f5 100644 --- a/app/controllers/softapplications_controller.rb +++ b/app/controllers/softapplications_controller.rb @@ -108,11 +108,16 @@ class SoftapplicationsController < ApplicationController # @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page'] @membership.each do |membership| unless(membership.project.project_type==1) - membership.member_roles.each{|role| - if(role.role_id == 3) + #membership.member_roles.each{|role| + # if(role.role_id == 3) + # @option << membership.project + # end + #} + + #拥有编辑项目权限的可操作该项目 + if User.current.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false) @option << membership.project - end - } + end end end diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index 49e32ba1..0bbbd1bd 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -20,6 +20,7 @@ class VersionsController < ApplicationController menu_item :roadmap model_object Version before_filter :find_model_object, :except => [:index, :new, :create, :close_completed] + #before_filter :find_model_object_contest, :except => [:index, :new, :create] before_filter :find_project_from_association, :except => [:index, :new, :create, :close_completed] before_filter :find_project_by_project_id, :only => [:index, :new, :create, :close_completed] before_filter :authorize @@ -154,6 +155,13 @@ class VersionsController < ApplicationController redirect_to settings_project_path(@project, :tab => 'versions') end + def close_completed_contest + if request.put? + @contest.close_completed_versions + end + redirect_to settings_contest_path(@contest, :tab => 'versions') + end + def destroy if @version.fixed_issues.empty? @version.destroy diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index b1fbfb8e..50bb2ccd 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -122,7 +122,9 @@ class WatchersController < ApplicationController end def find_watchables + #根据参数获取关注对象的类型(user、project) klass = Object.const_get(params[:object_type].camelcase) rescue nil + #判断获取的对象类型能否响应‘watched_by’方法 if klass && klass.respond_to?('watched_by') @watchables = klass.find_all_by_id(Array.wrap(params[:object_id])) raise Unauthorized if @watchables.any? {|w| w.respond_to?(:visible?) && !w.visible?} diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index c92f39d3..6105b22b 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -18,7 +18,7 @@ class WelcomeController < ApplicationController caches_action :robots # before_filter :fake, :only => [:index, :course] - before_filter :entry_select_course, :entry_select_contest, :entry_select_user, :only => [:index] + before_filter :entry_select, :only => [:index] def index @@ -92,9 +92,28 @@ class WelcomeController < ApplicationController private + def entry_select + url = request.original_url + if url.include?("course.trustie.net") + course + render :course + return 0 + elsif url.include?("contest.trustie.net") + contest + render :contest + return 0 + elsif url.include?("user.trustie.net") + redirect_to(:controller => "users", :action => "index") + end + + + end + # 判断网站的入口,是课程 course 则跳过index去渲染 course 方法 def entry_select_course - (course() and render :course and return 0) if request.original_url.match(/course\.trustie\.net/) + if request.original_url.match(/course\.trustie\.net/) + (course() and render :course and return 0) + end end def entry_select_contest diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 5f5a2227..808df65d 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -1,7 +1,21 @@ class ZipdownController < ApplicationController + #查找项目(课程) + before_filter :find_project_by_bid_id, :only => [:assort] + #检查权限 + #勿删 before_filter :authorize, :only => [:assort,:download_user_homework] SAVE_FOLDER = "#{Rails.root}/files" OUTPUT_FOLDER = "#{Rails.root}/tmp/archiveZip" + #通过作业Id找到项目(课程) + def find_project_by_bid_id + obj_class = params[:obj_class] + obj_id = params[:obj_id] + obj = obj_class.constantize.find(obj_id) + case obj.class.to_s.to_sym + when :Bid + @project = obj.courses[0] + end + end def assort obj_class = params[:obj_class] obj_id = params[:obj_id] @@ -22,18 +36,13 @@ class ZipdownController < ApplicationController #下载某一学生的作业的所有文件 def download_user_homework - obj_class = params[:obj_class] - obj_id = params[:obj_id] - user_id = params[:user_id] - obj = obj_class.constantize.find(obj_id) - zipfile = nil - case obj.class.to_s.to_sym - when :Bid - zipfile = zip_user_bid obj,user_id - else - logger.error "[ZipDown#assort] ===> #{obj.class.to_s.to_sym} unKown !!" + homework = HomeworkAttach.find params[:homework] + if homework != nil && (User.current.admin? || User.current.member_of?(homework.bid.courses.first)) + zipfile = zip_homework_by_user homework + send_file zipfile, :filename => homework.name, :type => detect_content_type(zipfile) if zipfile + else + render_403 :message => :notice_not_authorized end - send_file zipfile, :filename => obj.name, :type => detect_content_type(zipfile) if zipfile end private @@ -47,7 +56,8 @@ class ZipdownController < ApplicationController user_zip_paths = homeattaches.map do |homeattach| zip_homework_by_user homeattach end - zipping "#{Time.now.to_i}_#{bid.name}.zip", user_zip_paths, OUTPUT_FOLDER + #zipping "#{Time.now.to_i}_#{bid.name}.zip", user_zip_paths, OUTPUT_FOLDER + user_zip_paths end def zip_bid(bid) @@ -78,7 +88,8 @@ class ZipdownController < ApplicationController #length = attach.storage_path.length homeworks_attach_path << attach.diskfile#.to_s.slice((length+1)..-1) end - zipping "#{Time.now.to_i}_#{homeattach.user.name.to_s}.zip", homeworks_attach_path, OUTPUT_FOLDER, true + zipping "#{homeattach.user.name.to_s}.zip", homeworks_attach_path, OUTPUT_FOLDER, true + #user_attaches_paths end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 400a1232..f7b94587 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -46,6 +46,10 @@ module ApplicationHelper def authorize_for(controller, action) User.current.allowed_to?({:controller => controller, :action => action}, @project) end + + def authorize_for_contest(controller, action) + User.current.allowed_to?({:controller => controller, :action => action}, @contest) + end # Display a link if user is authorized # @@ -57,6 +61,9 @@ module ApplicationHelper link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action]) end + def link_to_if_authorized_contest(name, options = {}, html_options = nil, *parameters_for_method_reference) + link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for_contest(options[:controller] || params[:controller], options[:action]) + end # Displays a link to user's account page if active def link_to_user(user, canShowRealName = false, options={}) if user.is_a?(User) @@ -198,9 +205,8 @@ module ApplicationHelper end def thumbnail_tag(attachment) - imagepath = named_attachment_path(attachment, attachment.filename) - link_to image_tag(imagepath), - imagepath , + link_to image_tag(thumbnail_path(attachment)), + named_attachment_path(attachment, attachment.filename), :title => attachment.filename end diff --git a/app/helpers/bids_helper.rb b/app/helpers/bids_helper.rb index 8b03d74c..a5c25ecb 100644 --- a/app/helpers/bids_helper.rb +++ b/app/helpers/bids_helper.rb @@ -155,16 +155,6 @@ module BidsHelper end people.include?(User.current) end - #当前用户是不是指定课程的学生 - def is_cur_course_student? course - people = [] - course.members.each do |member| - if [5,10].include? member.roles.first.id - people << member.user - end - end - people.include?(User.current) - end # def select_option_helper option # tmp = Hash.new diff --git a/app/helpers/contestnotifications_helper.rb b/app/helpers/contestnotifications_helper.rb new file mode 100644 index 00000000..ab17149d --- /dev/null +++ b/app/helpers/contestnotifications_helper.rb @@ -0,0 +1,2 @@ +module ContestnotificationsHelper +end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 7f204102..2475121e 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -245,29 +245,49 @@ module CoursesHelper Course.find_by_extra(try(extra)) end #判断制定用户是不是当前课程的老师 - def is_course_teacher user,course - people = [] - course.members.each do |member| - role_id = member.roles.first.id - if TeacherRoles.include? role_id - people << member.user - end - end - people.include?(user) + def is_course_teacher (user,course) + course.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and members.user_id = #{user.id}", {:role_id => TeacherRoles}).count != 0 + #修改为根据用户是否有发布任务的权限来判断用户是否是课程的老师 + #is_teacher = false + #@membership = user.memberships.all(:conditions => Project.visible_condition(User.current)) + #@membership.each do |membership| + # unless(membership.project.project_type==0) + # if user.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) + # is_teacher = true + # end + # end + #end + #is_teacher end #当前用户是不是指定课程的学生 - def is_cur_course_student? course - people = [] - course.members.each do |member| - if StudentRoles.include? member.roles.first.id - people << member.user - end - end - people.include?(User.current) + def is_cur_course_student course + course.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and members.user_id = #{User.current.id}", {:role_id => StudentRoles}).count != 0 + #修改:能新建占位且不能新建任务的角色判定为学生 + #is_student = false + #@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) + #@membership.each do |membership| + # unless(membership.project.project_type==0) + # if !User.current.allowed_to?({:controller => "projects", :action => "new_homework"}, membership.project, :global => false) && User.current.allowed_to?({:controller => "homework_attach", :action => "new"}, membership.project, :global => false) + # is_student = true + # end + # end + #end + #is_student end #获取当前用户在指定作业下提交的作业的集合 def cur_user_homework_for_bid bid - cur_user_homework = HomeworkAttach.where("user_id = ? and bid_id = ?",User.current,params[:id]) + cur_user_homework = HomeworkAttach.where("user_id = ? and bid_id = ?",User.current,bid.id) cur_user_homework end + + #判断当前用户对指定作业是否已经评价过 + def has_evaluation? homework + seem_count = homework.rates(:quality).where("rater_id = ?",User.current).count + seem_count > 0 + end + + #获取指定作业的所有成员 + def users_for_homework homework + homework.nil? ? [] : (homework.users + [homework.user]) + end end diff --git a/app/helpers/homework_attach_helper.rb b/app/helpers/homework_attach_helper.rb index 1abac35d..28bb48d3 100644 --- a/app/helpers/homework_attach_helper.rb +++ b/app/helpers/homework_attach_helper.rb @@ -1,10 +1,57 @@ module HomeworkAttachHelper + #判断是否具有删除的权限 def attach_delete(project) if User.current.logged? && (User.current.admin? || (!Member.where('user_id = ? and project_id = ?', User.current.id, project.bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, project.bid.courses.first.id).first.roles&Role.where('id = ? or id = ?', 3, 7)).size >0) || project.user_id == User.current.id) true else false end + end + #作业添加、编辑界面的tab页 + def homework_settings_tabs f + @f = f + tabs = [{:name => 'info', :partial => 'homework_attach/edit_homework', :label => :label_information_plural}, + {:name => 'members', :partial => 'homework_attach/homework_member', :label => :label_member_plural} + ] + end + #作业可选成员列表分页 + def render_new_members_for_homework members + #scope = Principal.active.sorted.not_member_of(project).like(params[:q]) + #scope = project.members + #principals = paginateHelper members,10 + #principals = members + #principal_count = members.count + #limit = 10 + #principal_pages = Redmine::Pagination::Paginator.new principal_count, limit, params['page'] #by young + #offset ||= principal_pages.offset + #principals = members[offset, limit] + users = members.map(&:user) + s = content_tag('div', member_check_box_tags_ex('membership[user_ids][]', users), :id => 'principals') + links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false) {|text, parameters, options| + link_to text, get_homework_member_list_homework_attach_index_path( parameters.merge(:q => params[:q], bid_id: params[:id]||@homework)), :remote => true } + return s + content_tag('div', content_tag('ul', links), :class => 'pagination_new') + end + + #扩展的checkbox生成 + def member_check_box_tags_ex(name, principals) + s = '' + principals.each do |member| + s << "
" + end + s.html_safe + end + + def paginateHelper obj, pre_size=20 + @obj_count = obj.count + @obj_pages = Redmine::Pagination::Paginator.new @obj_count, pre_size, params['page'] + if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation + obj.limit(@obj_pages.per_page).offset(@obj_pages.offset) + elsif obj.kind_of? Array + obj[@obj_pages.offset, @obj_pages.per_page] + else + logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}" + raise RuntimeError, 'unknow type, Please input you type into this helper.' + end end end \ No newline at end of file diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb index d1292260..134b7c00 100644 --- a/app/helpers/members_helper.rb +++ b/app/helpers/members_helper.rb @@ -54,7 +54,7 @@ module MembersHelper # 当前申请加入的成员名单 def render_principals_for_applied_members(project) scope = Principal.active.sorted.applied_members(project).like(params[:q]) - principal_count = scope.count + principal_count = scope.count principal_pages = Redmine::Pagination::Paginator.new principal_count, 10, params['page'] principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all diff --git a/app/helpers/notificationcomments_helper.rb b/app/helpers/notificationcomments_helper.rb new file mode 100644 index 00000000..2d90bfe3 --- /dev/null +++ b/app/helpers/notificationcomments_helper.rb @@ -0,0 +1,2 @@ +module NotificationcommentsHelper +end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index a42a626d..c859fec2 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -150,7 +150,6 @@ module ProjectsHelper {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural} ] tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)} - end #Ended by young @@ -227,6 +226,19 @@ module ProjectsHelper type << option2 end + #是否启动互评下拉框 + def is_evaluation_option + type = [] + option1 = [] + option2 = [] + option1 << l(:lable_start_mutual_evaluation) + option1 << 1 + option2 << l(:lable_close_mutual_evaluation) + option2 << 2 + type << option1 + type << option2 + end + # 用来判断用户是否是项目的管理员 # added by william def is_manager?(user_id,project_id) diff --git a/app/helpers/shares_helper.rb b/app/helpers/shares_helper.rb index f2cbc6ab..9e082813 100644 --- a/app/helpers/shares_helper.rb +++ b/app/helpers/shares_helper.rb @@ -4,11 +4,15 @@ def options_from_select_project(user) @option = [] @membership.each do |membership| unless(membership.project.project_type==1) - membership.member_roles.each{|role| - if(role.role_id == 3) + #membership.member_roles.each{|role| + # if(role.role_id == 3) + # @option << membership.project + # end + #} + #拥有编辑项目权限的可操作该项目 + if user.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false) @option << membership.project - end - } + end end end options_for_select(@option) diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index d9ab8730..3101b823 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -228,12 +228,21 @@ module UserScoreHelper isManager = 0 members = Member.where('user_id = ?', user.id) members.each do |m| - roles = m.member_roles - roles.each do |r| - if r.role_id == 3 + #roles = m.member_roles + #roles.each do |r| + # if r.role_id == 3 + # isManager = 1 + # end + #end + @membership = m.memberships.all(:conditions => Project.visible_condition(User.current)) + @membership.each do |membership| + #拥有编辑项目权限的可操作该项目 + if m.allowed_to?({:controller => "projects", :action => "edit"}, membership.project, :global => false) isManager = 1 end end + + end level = 0 diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index c00f629d..62cb451c 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -22,6 +22,33 @@ module WelcomeHelper include CoursesHelper include ProjectsHelper + def get_timestamp(obj) + if obj.respond_to? :updated_on + :updated_on + elsif obj.respond_to? :updated_at + :updated_at + elsif obj.respond_to? :created_on + :created_on + elsif obj.respond_to? :created_at + :created_at + else + Time.now.to_i.to_s.to_sym + end + end + + def cache_key_for_project(obj) + timestamp = get_timestamp(obj) + "welcome_index_project_ul_#{obj.class}_li_#{obj.id}_#{obj.__send__ timestamp}" + end + def cache_key_for_event(obj) + timestamp = get_timestamp(obj) + "welcome_index_event_ul_#{obj.class}_li_#{obj.id}_#{obj.__send__ timestamp}" + end + def cache_key_for_topic(obj) + timestamp = get_timestamp(obj) + "welcome_index_topic_ul_#{obj.class}_li_#{obj.id}_#{obj.__send__ timestamp}" + end + def welcome_join_in_course(project, user) if(user.logged? && !(course_endTime_timeout? project) && @@ -319,9 +346,10 @@ module WelcomeHelper "show_documents" => true, "show_messages" => true, "show_news" => true, - "show_bids" => true + "show_bids" => true, + "show_contest" => true } - activity.scope_select{|t| ['changesets', 'documents', 'memos', 'messages', 'journals_for_messages', 'bids', 'news'].include?(t) ? nil : 'You may think you know what the following code does, may be. but why don"t you close this file and go play with something else, Now?' } + activity.scope_select{|t| ['changesets', 'documents', 'memos', 'messages', 'journals_for_messages', 'bids', 'news', 'contestnotification'].include?(t) ? nil : 'You may think you know what the following code does, may be. but why don"t you close this file and go play with something else, Now?' } activity.events_welcome(nil, nil, {:limit => limit, :types => 'welcome'}) end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 175a649c..2da139da 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -65,6 +65,7 @@ class Attachment < ActiveRecord::Base @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") before_save :files_to_final_location + before_save :be_user_score # user_score after_destroy :delete_from_disk # Returns an unsaved copy of the attachment @@ -374,4 +375,17 @@ class Attachment < ActiveRecord::Base end "#{timestamp}_#{ascii}" end + + + # update user score + def be_user_score + if self.container_id_changed? + type = self.container_type + types = %w|Document News Version Project Issue Message WikiPage| + if types.include?(type) + UserScore.project(:push_file, User.current, { attachment_id: self.id }) + end + end + end + end diff --git a/app/models/changeset.rb b/app/models/changeset.rb index e3e7ac70..36f78d32 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -18,6 +18,9 @@ class Changeset < ActiveRecord::Base belongs_to :repository belongs_to :user + + after_save :be_user_score # user_score + has_many :filechanges, :class_name => 'Change', :dependent => :delete_all # fq has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy @@ -292,4 +295,16 @@ class Changeset < ActiveRecord::Base def self.to_utf8(str, encoding) Redmine::CodesetUtil.to_utf8(str, encoding) end + + private + + # update user score + def be_user_score + if self.new_record? + UserScore.project(:push_code, self.user, { changeset_id: self.id }) + #更新用户等级 + self.user.update_user_level + end + end + end diff --git a/app/models/contest.rb b/app/models/contest.rb index 9a326865..d41506b8 100644 --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -13,6 +13,7 @@ class Contest < ActiveRecord::Base has_many :join_in_competitions, foreign_key: 'competition_id', :dependent => :destroy has_many :join_in_contests, class_name: 'JoinInCompetition', foreign_key: 'competition_id', :dependent => :destroy has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_many :contestnotifications, :dependent => :destroy, :include => :author @@ -93,6 +94,17 @@ class Contest < ActiveRecord::Base end end + # Closes open and locked project versions that are completed + def close_completed_versions_contest + Version.transaction do + versions.where(:status => %w(open locked)).all.each do |version| + if version.completed? + version.update_attribute(:status, 'closed') + end + end + end + end + def set_commit(commit) self.update_attribute(:commit, commit) end diff --git a/app/models/contestnotification.rb b/app/models/contestnotification.rb new file mode 100644 index 00000000..0bda4954 --- /dev/null +++ b/app/models/contestnotification.rb @@ -0,0 +1,63 @@ +class Contestnotification < ActiveRecord::Base + #attr_accessible :author_id, :notificationcomments_count, :contest_id, :description, :summary, :title + + include Redmine::SafeAttributes + #Contestnotification::Notificationcomment + belongs_to :contest + belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' + has_many :notificationcomments, as: :notificationcommented, :dependent => :delete_all, :order => "created_at" + # fq + has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy + + validates_presence_of :title, :description + validates_length_of :title, :maximum => 60 + validates_length_of :summary, :maximum => 255 + + acts_as_attachable :delete_permission => :manage_contestnotifications + acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"], :include => :contest + acts_as_event :url => Proc.new {|o| {:controller => 'contestnotifications', :action => 'show', :id => o.id}} + acts_as_activity_provider :find_options => {:include => [:contest, :author]}, + :author_key => :author_id + acts_as_watchable + + after_create :add_author_as_watcher + + after_create :act_as_activity + + + scope :visible, lambda {|*args| + nil + #includes(:contest).where(Contest.allowed_to_condition(args.shift || User.current, :view_contestnotifications, *args)) + } + + safe_attributes 'title', 'summary', 'description' + + def visible?(user=User.current) + !user.nil? && user.allowed_to?(:view_contestnotifications, contest) + end + + # Returns true if the news can be commented by user + def notificationcommentable?(user=User.current) + user.allowed_to?(:notificationcomment_contestnotifications, contest) + end + + def recipients + #contest.users.select {|user| user.notify_about?(self)}.map(&:mail) + end + + # returns latest news for contests visible by user + def self.latest(user = User.current, count = 5) + visible(user).includes([:author, :contest]).order("#{Contestnotification.table_name}.created_at DESC").limit(count).all + end + + private + + def add_author_as_watcher + #Watcher.create(:watchable => self, :user => author) + end + ## fq + def act_as_activity + self.acts << Activity.new(:user_id => self.author_id) + end + +end diff --git a/app/models/document.rb b/app/models/document.rb index 0c2ce173..3710e6eb 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -18,7 +18,12 @@ class Document < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :project + belongs_to :user belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id" + + before_save :be_user_score # user_score + + acts_as_attachable :delete_permission => :delete_documents acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project @@ -54,4 +59,11 @@ class Document < ActiveRecord::Base end @updated_on end + + # update user score + def be_user_score + if self.new_record? + UserScore.project(:push_document, self.user, { document_id: self.id }) + end + end end diff --git a/app/models/homework_attach.rb b/app/models/homework_attach.rb index ad59d107..e60d4230 100644 --- a/app/models/homework_attach.rb +++ b/app/models/homework_attach.rb @@ -7,14 +7,15 @@ class HomeworkAttach < ActiveRecord::Base belongs_to :bid has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :homework_users, :dependent => :destroy + has_many :users, :through => :homework_users seems_rateable :allow_update => true, :dimensions => :quality safe_attributes "bid_id", "user_id" acts_as_attachable - def addjours user_id,message,status = 0,is_comprehensive_evaluation = 0 - jfm = self.journals_for_messages.build(:user_id => user_id,:notes =>message,:status => status,:is_comprehensive_evaluation => is_comprehensive_evaluation) + def addjours user_id,message,status = 0,is_comprehensive_evaluation = 0,reply_id = 0 + jfm = self.journals_for_messages.build(:user_id => user_id,:notes =>message,:status => status,:is_comprehensive_evaluation => is_comprehensive_evaluation,:reply_id => reply_id) jfm.save jfm end diff --git a/app/models/homework_user.rb b/app/models/homework_user.rb index 0adef62c..df75ef82 100644 --- a/app/models/homework_user.rb +++ b/app/models/homework_user.rb @@ -1,6 +1,6 @@ class HomeworkUser < ActiveRecord::Base attr_accessible :homework_attach_id, :user_id - belongs_to :homework_attach + belongs_to :homework_attach, :foreign_key => :homework_attach_id belongs_to :user end diff --git a/app/models/issue.rb b/app/models/issue.rb index 7e899eaf..6cfa9b7e 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -77,6 +77,8 @@ class Issue < ActiveRecord::Base # fq after_create :act_as_activity + before_save :be_user_score + # after_create :be_user_score # end delegate :notes, :notes=, :private_notes, :private_notes=, :to => :current_journal, :allow_nil => true @@ -1484,4 +1486,17 @@ class Issue < ActiveRecord::Base and #{visible_condition(User.current, :project => project)} group by s.id, s.is_closed, j.id") end + + # update user score + def be_user_score + if self.new_record? + UserScore.project(:post_issue, User.current, { issue_id: self.id }) + elsif self.done_ratio_changed? + UserScore.project(:update_issue_ratio, User.current, { issue_id: self.id }) + #缺陷状态更改 + elsif self.status_id_changed? + #协同得分 + UserScore.joint(:change_issue_status, User.current,nil, {issue_id: self.id}) + end + end end diff --git a/app/models/journal.rb b/app/models/journal.rb index 0997640d..c82db5a1 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -48,6 +48,9 @@ class Journal < ActiveRecord::Base after_create :act_as_activity # end + before_save :be_user_score + #before_destroy :down_user_score + scope :visible, lambda {|*args| user = args.shift || User.current @@ -151,4 +154,21 @@ class Journal < ActiveRecord::Base self.acts << Activity.new(:user_id => self.user_id) end # end + + # 更新用户分数 -by zjc + def be_user_score + #新建了缺陷留言且留言不为空,不为空白 + if self.new_record? && !self.notes.nil? && self.notes.gsub(' ','') != '' + #协同得分加分 + UserScore.joint(:post_issue, User.current,self.issue.author, { message_id: self.id }) + end + end + # 减少用户分数 -by zjc + def down_user_score + #删除有效缺陷留言 + if !self.notes.nil? && self.notes.gsub(' ','') != '' + #协同得分减分 + UserScore.joint(:delete_issue, User.current,self.issue.author, { message_id: self.id }) + end + end end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 082165f1..f59fe4b2 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -51,6 +51,8 @@ class JournalsForMessage < ActiveRecord::Base after_create :act_as_activity #huang after_create :reset_counters! after_destroy :reset_counters! + before_save :be_user_score + #before_destroy :down_user_score # default_scope { where('m_parent_id IS NULL') } @@ -110,4 +112,21 @@ class JournalsForMessage < ActiveRecord::Base count = find_all_by_m_parent_id(journals_for_messages.m_parent_id).count #(SELECT COUNT(*) FROM #{JournalsForMessage.table_name} WHERE m_parent_id = #{jfm_id} ) update_all("m_reply_count = #{count.to_i}", ["id = ?", journals_for_messages.m_parent_id]) end + + # 更新用户分数 -by zjc + def be_user_score + #新建了留言回复 + if self.new_record? && self.reply_id != 0 + #协同得分加分 + UserScore.joint(:reply_message, User.current,User.find(self.reply_id), { journals_for_messages_id: self.id }) + end + end + # 更新用户分数 -by zjc + def down_user_score + #删除了留言回复 + if self.reply_id != 0 + #协同得分减分 + UserScore.joint(:reply_message_delete, User.current,User.find(self.reply_id), { journals_for_messages_id: self.id }) + end + end end diff --git a/app/models/mailer.rb b/app/models/mailer.rb index bb7a2424..e954f03c 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -51,7 +51,7 @@ class Mailer < ActionMailer::Base when :User user_newfeedback_user_url(journals_for_message.jour, anchor: "word_li_#{journals_for_message.id}") else - logger.error "[Builds a Mail::Message ERROR] journalsForMessage's jour is unkown type, journalsForMessage.id = #{journals_for_message.id}" + Rails.logger.error "[Builds a Mail::Message ERROR] journalsForMessage's jour is unkown type, journalsForMessage.id = #{journals_for_message.id}" return -1 end #如果是直接留言并且留言对象是Project并且Project类型是课程 @@ -70,7 +70,12 @@ class Mailer < ActionMailer::Base end mail :to => @recipients, :subject => "#{l(:label_your_course)}#{journals_for_message.jour.name}#{l(:label_have_message)} " - else + elsif journals_for_message.jour.class.to_s.to_sym == :Bid + if !journals_for_message.jour.author.notify_about? journals_for_message + return -1 + end + mail :to => journals_for_message.jour.author.mail, :subject => @title + else mail :to => @mail.mail, :subject => @title end diff --git a/app/models/memo.rb b/app/models/memo.rb index a0581d94..d706f814 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -46,7 +46,7 @@ class Memo < ActiveRecord::Base # after_create :send_notification # after_save :plusParentAndForum # after_destroy :minusParentAndForum - + before_save :be_user_score # scope :visible, lambda { |*args| # includes(:forum => ).where() # } @@ -140,5 +140,17 @@ class Memo < ActiveRecord::Base @forum.topic_count = 0 if @forum.topic_count.to_int < 0 end @forum.save - end + end + + #更新用户分数 -by zjc + def be_user_score + #新建memo且无parent的为发帖 + if self.new_record? && self.parent_id.nil? + UserScore.joint(:post_message, User.current,nil, { memo_id: self.id }) + #新建memo且有parent的为回帖 + elsif self.new_record? && !self.parent_id.nil? + UserScore.joint(:reply_posting, User.current,self.parent.author, { memo_id: self.id }) + end + end + end diff --git a/app/models/message.rb b/app/models/message.rb index 80b515a0..9e71eddc 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -61,6 +61,8 @@ class Message < ActiveRecord::Base # fq after_create :act_as_activity + before_save :be_user_score + #before_destroy :down_user_score # end scope :visible, lambda {|*args| @@ -141,4 +143,25 @@ class Message < ActiveRecord::Base self.acts << Activity.new(:user_id => self.author_id) end # end + + #更新用户分数 -by zjc + def be_user_score + #新建message且无parent的为发帖 + if self.new_record? && self.parent_id.nil? + UserScore.joint(:post_message, User.current,nil, { message_id: self.id }) + #新建message且有parent的为回帖 + elsif self.new_record? && !self.parent_id.nil? + UserScore.joint(:reply_posting, User.current,self.parent.author, { message_id: self.id }) + end + end + #减少用户分数 + def down_user_score + #删除发帖 + if self.parent_id.nil? + UserScore.joint(:delete_message, User.current,nil, { message_id: self.id }) + #删除留言 + else + UserScore.joint(:reply_deleting, User.current,self.parent.author, { message_id: self.id }) + end + end end diff --git a/app/models/notificationcomment.rb b/app/models/notificationcomment.rb new file mode 100644 index 00000000..9cc658f2 --- /dev/null +++ b/app/models/notificationcomment.rb @@ -0,0 +1,11 @@ +class Notificationcomment < ActiveRecord::Base + attr_accessible :author_id, :notificationcommented_id, :notificationcommented_type, :notificationcomments + + include Redmine::SafeAttributes + belongs_to :notificationcommented, :polymorphic => true#, :counter_cache => true + belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' + + validates_presence_of :notificationcommented, :author, :notificationcomments + + # safe_attributes 'notificationcomments' +end diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb index c27e1fc9..11d68157 100644 --- a/app/models/praise_tread.rb +++ b/app/models/praise_tread.rb @@ -2,5 +2,43 @@ class PraiseTread < ActiveRecord::Base attr_accessible :user_id,:praise_tread_object_id,:praise_tread_object_type,:praise_or_tread belongs_to :user belongs_to :praise_tread_object, polymorphic: true - + before_save :be_user_score + + def self.find_object_by_type_and_id(type,id) + @obj = nil + case type + when 'User' + @obj = User.find_by_id(id) + when 'Issue' + @obj = Issue.find_by_id(id) + when 'Project' + @obj = Project.find_by_id(id) + when 'Bid' + @obj = Bid.find_by_id(id) + when 'Contest' + @obj = Contest.find_by_id(id) + when 'Memo' + @obj = Memo.find_by_id(id) + when 'Message' + @obj = Message.find_by_id(id) + end + return @obj + end + + #更新用户分数 - by zjc + def be_user_score + #踩贴吧或讨论区帖子 + if self.new_record? && self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Memo' || self.praise_tread_object_type == 'Message') + obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) + target_user = obj.author + UserScore.skill(:treaded_by_user, User.current,target_user, { praise_tread_id: self.id }) + #顶贴吧或讨论区帖子 + elsif self.new_record? && self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Memo' || self.praise_tread_object_type == 'Message') + obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) + target_user = obj.author + UserScore.skill(:praised_by_user, User.current,target_user,{ praise_tread_id: self.id }) + #更新用户等级 + target_user.update_user_level + end + end end diff --git a/app/models/project_info.rb b/app/models/project_info.rb index c6edab81..4cb984b0 100644 --- a/app/models/project_info.rb +++ b/app/models/project_info.rb @@ -5,7 +5,7 @@ class ProjectInfo < ActiveRecord::Base belongs_to :user validates_presence_of :project_id, :user_id validates_uniqueness_of :project_id, :scope => :user_id - + after_save :update_user_level def self.manager? (user_id, project) for project_info in project.project_infos if project_info.user_id == user_id @@ -14,4 +14,9 @@ class ProjectInfo < ActiveRecord::Base end return false end + + #更新用户等级 + def update_user_level + self.user.update_user_level + end end diff --git a/app/models/user.rb b/app/models/user.rb index 0c798eea..d4e71009 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -73,7 +73,8 @@ class User < Principal ['none', :label_user_mail_option_none] ] - belongs_to :homework_user + has_many :homework_users + has_many :homework_attaches, :through => :homework_users has_and_belongs_to_many :groups, :after_add => Proc.new {|user, group| group.user_added(user)}, :after_remove => Proc.new {|user, group| group.user_removed(user)} @@ -107,11 +108,14 @@ class User < Principal # added by bai has_many :join_in_contests, :dependent => :destroy has_many :news, :foreign_key => 'author_id' + has_many :contestnotification, :foreign_key => 'author_id' has_many :comments, :foreign_key => 'author_id' + has_many :notificationcomments, :foreign_key => 'author_id' has_many :wiki_contents, :foreign_key => 'author_id' has_many :journals has_many :messages, :foreign_key => 'author_id' has_one :user_score, :dependent => :destroy + has_many :documents # 项目中关联的文档再次与人关联 # end ######added by nie @@ -120,6 +124,10 @@ class User < Principal ##### has_many :shares ,:dependent => :destroy + # add by zjc + has_one :level, :class_name => 'UserLevels', :dependent => :destroy + has_many :memos , :foreign_key => 'author_id' + ##### scope :logged, lambda { where("#{User.table_name}.status <> #{STATUS_ANONYMOUS}") } scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) } scope :visible, lambda {|*args| @@ -137,6 +145,7 @@ class User < Principal has_one :user_extensions,:dependent => :destroy ## end + # default_scope -> { includes(:user_extensions, :user_score) } scope :teacher, -> { joins(:user_extensions).where('user_extensions.identity = ?', UserExtensions::TEACHER) } @@ -200,6 +209,7 @@ class User < Principal # ====================================================================== # 集中处理 User 扩展表为空的问题 + # 合并 user_score 属性 validate :valid_user_extensions after_save :save_user_extensions @@ -207,21 +217,32 @@ class User < Principal self.user_extensions ||= UserExtensions.new end + def user_score_attr + self.user_score ||= UserScore.new + end + + alias_method :ori_respond_to?, :respond_to? def respond_to?(m, include_private = false) - flag = UserExtensions.instance_methods.include? m.to_sym - if flag - flag - else - super - end + flag = false + flag = ori_respond_to? m.to_sym unless flag + flag = UserExtensions.new.respond_to? m.to_sym unless flag + flag = UserScore.new.respond_to? m.to_sym unless flag + + flag end def method_missing m, *args, &block if extensions.respond_to? m.to_sym - self.class.send :define_method, m.to_sym, *args do + self.class.send(:define_method, "_meta_#{m}".to_sym) do |*args, &block| self.extensions.__send__ m.to_sym, *args end - __send__ m.to_sym, *args, &block + __send__ "_meta_#{m}".to_sym, *args, &block + + elsif user_score_attr.respond_to? m.to_sym + self.class.send(:define_method, "_meta_#{m}".to_sym) do |*args, &block| + self.user_score_attr.__send__ m.to_sym, *args + end + __send__ "_meta_#{m}".to_sym, *args, &block else super @@ -240,6 +261,7 @@ class User < Principal def save_user_extensions self.extensions.save + self.user_score_attr.save end # 集中处理 User 扩展表为空的问题 < end # ====================================================================== @@ -505,6 +527,9 @@ class User < Principal self.pref[:comments_sorting] == 'desc' end + def wants_notificationcomments_in_reverse_order? + self.pref[:notificationcomments_sorting] == 'desc' + end # Return user's RSS key (a 40 chars long string), used to access feeds def rss_key if rss_token.nil? @@ -927,6 +952,63 @@ class User < Principal end end + #获取user的等级 -by zjc + def get_level + if self.level.nil? + update_user_level + end + self.level.level + end + + #更新用户等级 - by zjc + def update_user_level + user_level = self.level.nil? ? UserLevels.new : self.level + user_level.user = self + + #判断user的等级 + pis = self.project_infos #ProjectInfo.find_all_by_user_id(self.id) + isManager = false; + pis.each do |pi| + #判断是否为项目管理员 + if self.allowed_to?({:controller => "projects", :action => "edit"}, pi.project) + isManager = true; + end + end + has_effective_praise_count = false; + self.messages.each do |message| + if message.parent_id.nil? + ptcs = PraiseTreadCache.find_all_by_object_id(message.id) + ptcs.each do |ptc| + if ptc.object_type == 'Message' && ptc.praise_num.to_i > 5 + has_effective_praise_count = true + end + end + end + end + if !has_effective_praise_count + self.memos do |memo| + if memo.parent_id.nil? + ptcs = PraiseTreadCache.find_all_by_object_id(memo.id) + ptcs.each do |ptc| + if ptc.object_type == 'Memo' && ptc.praise_num > 5 + has_effective_praise_count = true + end + end + end + end + end + + if isManager || self.changesets.count > 100 + user_level.level = 3 + elsif (self.changesets.count > 1 && self.changesets.count <= 100) || has_effective_praise_count + user_level.level = 2 + else + user_level.level = 1 + end + user_level.save + self.reload + end + protected def validate_password_length @@ -935,7 +1017,6 @@ class User < Principal errors.add(:password, :too_short, :count => Setting.password_min_length.to_i) end end - private def act_as_activity @@ -950,6 +1031,7 @@ class User < Principal substitute = User.anonymous Attachment.update_all ['author_id = ?', substitute.id], ['author_id = ?', id] Comment.update_all ['author_id = ?', substitute.id], ['author_id = ?', id] + Notificationcomment.update_all ['author_id = ?', substitute.id], ['author_id = ?', id] Issue.update_all ['author_id = ?', substitute.id], ['author_id = ?', id] Issue.update_all 'assigned_to_id = NULL', ['assigned_to_id = ?', id] Journal.update_all ['user_id = ?', substitute.id], ['user_id = ?', id] @@ -977,6 +1059,8 @@ class User < Principal Redmine::Utils.random_hex(16) end + + end class AnonymousUser < User diff --git a/app/models/user_levels.rb b/app/models/user_levels.rb new file mode 100644 index 00000000..eb8dd37e --- /dev/null +++ b/app/models/user_levels.rb @@ -0,0 +1,5 @@ +#用户等级类 - by zjc +class UserLevels < ActiveRecord::Base + attr_accessible :user_id, :level + belongs_to :user +end \ No newline at end of file diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 5b95386b..e0a54180 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -54,6 +54,9 @@ class UserPreference < ActiveRecord::Base def comments_sorting; self[:comments_sorting] end def comments_sorting=(order); self[:comments_sorting]=order end + def notificationcomments_sorting; self[:notificationcomments_sorting] end + def notificationcomments_sorting=(order); self[:notificationcomments_sorting]=order end + def warn_on_leaving_unsaved; self[:warn_on_leaving_unsaved] || '1'; end def warn_on_leaving_unsaved=(value); self[:warn_on_leaving_unsaved]=value; end end diff --git a/app/models/user_score.rb b/app/models/user_score.rb index f383d667..bf6f9798 100644 --- a/app/models/user_score.rb +++ b/app/models/user_score.rb @@ -18,6 +18,8 @@ class UserScore < ActiveRecord::Base belongs_to :user + before_save :correct_score + def self.find_max_file self.maximum(:file) end @@ -33,4 +35,223 @@ class UserScore < ActiveRecord::Base def self.find_min_issue self.minimum(:file) end + # 以上类方法目测没用,反正也报错 + # =============================================================================== + + # 前略·协同得分 + # operate - 更新操作 类型 symbol + # user - 计分用户 + # + # Examples + # + # UserScore.joint(:post_message, User.current, nil) + # # => true #当前用户发帖计分操作成功 + # + # Returns boolean. 返回积分保存结果 + def self.joint(operate, current_user, target_user, options={}) + current_user, target_user = get_users(current_user, target_user) + user_score = current_user.user_score_attr + case operate + when :post_message # current_user 发帖了 Add Message + user_score.collaboration = user_score.collaboration.to_i + 2 + user_score.save + Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a message. options => (#{options.to_s})" + when :delete_message # current_user 发帖了 Delete Message + user_score.collaboration = user_score.collaboration.to_i - 2 + user_score.save + Rails.logger.info "[UserScore#joint] ===> User: #{current_user} deleting a message. options => (#{options.to_s})" + when :post_issue # current_user 对 target_user 的缺陷留言了 Add Journal + user_score.collaboration = user_score.collaboration.to_i + 1 + user_score.save + Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a issue. options => (#{options.to_s})" + when :delete_issue # current_user 删除了 对 target_user 的缺陷留言了 Delete Journal + user_score.collaboration = user_score.collaboration.to_i - 1 + user_score.save + Rails.logger.info "[UserScore#joint] ===> User: #{current_user} deleting a issue. options => (#{options.to_s})" + when :change_issue_status # current_user 更改了缺陷的状态 Changed Issue + user_score.collaboration = user_score.collaboration.to_i + 1 + user_score.save + Rails.logger.info "[UserScore#joint] ===> User: #{current_user} change issue status. options => (#{options.to_s})" + when :reply_message # current_user 对 target_user 留言的回复 Add Journals_for_messages + user_score.collaboration = user_score.collaboration.to_i + 1 + user_score.save + Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply message. options => (#{options.to_s})" + when :reply_message_delete # current_user 删除了对 target_user 留言的回复 delete Journals_for_messages + user_score.collaboration = user_score.collaboration.to_i - 1 + user_score.save + Rails.logger.info "[UserScore#joint] ===> User: #{current_user} delete reply message. options => (#{options.to_s})" + when :reply_posting # current_user 对 target_user 帖子的回复 Add Message + user_score.collaboration = user_score.collaboration.to_i + 1 + user_score.save + Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply posting. options => (#{options.to_s})" + when :reply_deleting # current_user 删除了 对 target_user 帖子的回复 Delete Message + user_score.collaboration = user_score.collaboration.to_i - 1 + user_score.save + Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply deleting. options => (#{options.to_s})" + else + Rails.logger.error "[UserScore#joint] ===> #{operate} is not define." + return false + end + rescue => e + Rails.logger.error "[UserScore#joint] ===> Exception: #{e}." + end + + # 前略·影响力得分 + # operate - 更新操作 类型 symbol + # user - 计分用户 + # + # Examples + # + # UserScore.influence(:followed_by, user) + # # => true #当前被关注用户记分成功 + # + # Returns boolean. 返回积分保存结果 + def self.influence(operate, current_user, target_user, options={}) + current_user, target_user = get_users(current_user, target_user) + user_score = target_user.user_score_attr + case operate + when :followed_by # current_user 关注了target_user Add watcher + user_score.influence = user_score.influence.to_i + 2 + user_score.save + Rails.logger.info "[UserScore#influence] ===> User: #{current_user} be followed. options => (#{options.to_s})" + when :cancel_followed # current_uer 取消了对 target_user的关注 delete watcher + user_score.influence = user_score.influence.to_i - 2 + user_score.save + Rails.logger.info "[UserScore#influence] ===> User: #{current_user} canceled followed. options => (#{options.to_s})" + else + Rails.logger.error "[UserScore#influence] ===> #{operate} is not define." + return false + end + rescue => e + Rails.logger.error "[UserScore#influence] ===> Exception: #{e}." + end + + # 前略·技术得分 + # operate - 更新操作 类型 symbol + # user - 计分用户 + # + # Examples + # + # UserScore.skill(:followed_by, current_user, target_user) + # # => true #当前current_user对target_user用户帖子的记分成功 + # + # Returns boolean. 返回积分保存结果 + def self.skill(operate, current_user, target_user, options={}) + current_user, target_user = get_users(current_user, target_user) + current_user_score = current_user.user_score_attr + target_user_score = target_user.user_score_attr + case operate + # when :treading # current_user 踩了 target_user 的帖子 + # Rails.logger.info "[UserScore#skill] ===> User: #{current_user} treading #{target_user}'s posting. options => (#{options.to_s})" + when :treaded_by_user # current_user 踩了 target_user 的帖子 + current_user_score.skill = current_user_score.skill.to_i - 2 #踩别人的帖子减2分 add praise_tread + current_user_score.save + if current_user.id == target_user.id + target_user.reload + target_user_score = target_user.user_score_attr + end + level = current_user.get_level + if level == 1 + target_user_score.skill = target_user_score.skill.to_i - 2 #帖子被一级会员踩-2分 add praise_tread + target_user_score.save + elsif level == 2 + target_user_score.skill = target_user_score.skill.to_i - 4 #帖子被二级会员踩-4分 add praise_tread + target_user_score.save + elsif level == 3 + target_user_score.skill = target_user_score.skill.to_i - 6 #帖子被三级会员踩-6分 add praise_tread + target_user_score.save + end + + Rails.logger.info "[UserScore#skill] ===> User: #{current_user} treaded_by #{target_user}. options => (#{options.to_s})" + when :praised_by_user # current_user 顶了 target_user 的帖子 + level = current_user.get_level + if level == 1 + target_user_score.skill = target_user_score.skill.to_i + 4 #帖子被一级会员顶+4分 add praise_tread + target_user_score.save + elsif level == 2 + target_user_score.skill = target_user_score.skill.to_i + 6 #帖子被二级会员顶+6分 add praise_tread + target_user_score.save + elsif level == 3 + target_user_score.skill = target_user_score.skill.to_i + 8 #帖子被三级会员顶+8分 add praise_tread + target_user_score.save + end + + Rails.logger.info "[UserScore#skill] ===> User: #{current_user} praised_by #{target_user}. options => (#{options.to_s})" + else + Rails.logger.error "[UserScore#skill] ===> #{operate} is not define." + return false + end + rescue => e + Rails.logger.error "[UserScore#skill] ===> Exception: #{e}." + end + + # 前略·项目得分 + # operate - 更新操作 类型 symbol + # user - 计分用户 + # + # Examples + # + # UserScore.project(:pull_code, current_user) + # # => true #当前current_user对项目贡献积分成功 + # + # Returns boolean. 返回积分保存结果 + def self.project(operate, current_user, options={}) + current_user, target_user = get_users(current_user, nil) + user_score = current_user.try(:user_score_attr) + return false if current_user.nil? + case operate + when :push_code # current_user 提交了代码 changeset + user_score = user_score.active.to_i + 4 + user_score.save + Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed code one time. options => (#{options.to_s})" + when :push_document # current_user + user_score.active = user_score.active.to_i + 4 + user_score.save + Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed a document. options => (#{options.to_s})" + when :push_file # current_user + user_score.active = user_score.active.to_i + 4 + user_score.save + Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed a file. options => (#{options.to_s})" + when :update_issue_ratio # current_user + user_score.active = user_score.active.to_i + 2 + user_score.save + Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] updated issue ratio. options => (#{options.to_s})" + when :post_issue # current_user + user_score.active = user_score.active.to_i + 4 + user_score.save + Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] posting issue. options => (#{options.to_s})" + else + Rails.logger.error "[UserScore#project] ===> #{operate} is not define." + return false + end + rescue => e + Rails.logger.error "[UserScore#project] ===> Exception: #{e}." + end + + private + + def self.get_users(current_user, target_user) + cUser = (current_user.kind_of?User) ? current_user : User.find_by_id(current_user) + tUser = (target_user.kind_of?User) ? target_user : User.find_by_id(target_user) + + [cUser, tUser] + end + + #修正分数 + #分数小于0时修正为0 + #分数大于等于0时不修正 -by zjc + def correct_score + if !self.collaboration.nil? && self.collaboration < 0 + self.collaboration = 0 + end + if !self.influence.nil? && self.influence < 0 + self.influence = 0 + end + if !self.skill.nil? && self.skill < 0 + self.skill = 0 + end + if !self.active.nil? && self.active < 0 + self.active = 0 + end + end end diff --git a/app/models/watcher.rb b/app/models/watcher.rb index f700e62a..88f23900 100644 --- a/app/models/watcher.rb +++ b/app/models/watcher.rb @@ -22,6 +22,8 @@ class Watcher < ActiveRecord::Base has_one :project_status has_one :users_status #end + before_save :be_user_score + before_destroy :down_user_score validates_presence_of :user validates_uniqueness_of :user_id, :scope => [:watchable_type, :watchable_id] @@ -70,4 +72,22 @@ class Watcher < ActiveRecord::Base end pruned end + + # 更新用户分数 -by zjc + def be_user_score + #添加了关注 + if self.new_record? && self.watchable_type == 'Principal' + #影响力得分 + UserScore.influence(:followed_by, self.user,self.watchable, { watcher_id: self.id }) + end + + end + #减分操作 -by zjc + def down_user_score + #取消关注 + if self.watchable_type == 'Principal' + UserScore.influence(:cancel_followed, self.user,self.watchable, { watcher_id: self.id }) + end + + end end diff --git a/app/views/account/register.html.erb b/app/views/account/register.html.erb index cc7a26ad..fac05e6d 100644 --- a/app/views/account/register.html.erb +++ b/app/views/account/register.html.erb @@ -1,409 +1,447 @@ -

<%=l(:label_register)%> <%=link_to l(:label_login_with_open_id_option), signin_url if Setting.openid? %>

+

<%= l(:label_register) %> <%= link_to l(:label_login_with_open_id_option), signin_url if Setting.openid? %>

<%= labelled_form_for @user, :url => register_path do |f| %> -<%= error_messages_for 'user' %> + <%= error_messages_for 'user' %> -
-

- - + +
<%= l(:label_identity) %> * - -
+

+ <% if @user.auth_source_id.nil? %> +

<%= f.text_field :login, :size => 25, :required => true %> + <%= l(:label_max_number) %>

-<% if @user.auth_source_id.nil? %> -

<%= f.text_field :login, :size => 25, :required => true %> - <%= l(:label_max_number) %>

-

<%= f.password_field :password, :size => 25, :required => true %> - <%= l(:text_caracters_minimum, :count => Setting.password_min_length) %>

+

<%= f.password_field :password, :size => 25, :required => true %> + <%= l(:text_caracters_minimum, :count => Setting.password_min_length) %>

-

<%= f.password_field :password_confirmation, :size => 25, :required => true %>

-<% end %> -
+

+ + + + + + +
+ <%= l(:label_location) %> * + + + + +
+

+ + -

<%= submit_tag l(:button_submit) %>

+

+ + + + +
<%= submit_tag l(:button_submit) %>
+

<% end %> <% if Setting.openid? %> -

<%= f.text_field :identity_url %>

+

<%= f.text_field :identity_url %>

<% end %> -<% @user.custom_field_values.select {|v| v.editable? || v.required?}.each do |value| %> -

<%= custom_field_tag_with_label :user, value %>

+<% @user.custom_field_values.select { |v| v.editable? || v.required? }.each do |value| %> +

<%= custom_field_tag_with_label :user, value %>

<% end %> \ No newline at end of file diff --git a/app/views/attachments/_links.html.erb b/app/views/attachments/_links.html.erb index f73df8fb..c135ee21 100644 --- a/app/views/attachments/_links.html.erb +++ b/app/views/attachments/_links.html.erb @@ -33,7 +33,7 @@ <% if images.any? %>
<% images.each do |attachment| %> -
<%= thumbnail_small_tag(attachment) %>
+
<%= thumbnail_tag(attachment) %>
<% end %>
<% end %> diff --git a/app/views/bids/_bid_homework_show.html.erb b/app/views/bids/_bid_homework_show.html.erb index 3ef55c56..c4eb875a 100644 --- a/app/views/bids/_bid_homework_show.html.erb +++ b/app/views/bids/_bid_homework_show.html.erb @@ -15,7 +15,13 @@ <% if(User.current.logged? && (!Member.where('user_id = ? and project_id = ?', User.current.id, bid.courses.first.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',5, 10, 7)).size >0)) %> <%# 提交作业按钮 %> - <%= link_to l(:label_commit_homework), '#OpenWindow', rel: 'leanModal', onclick: "showSubH(#{bid.id}, '#{bid.name}');" if User.current.member_of?(@project) %> + + <% cur_user_homework = cur_user_homework_for_bid(bid) %> + <% if cur_user_homework!= nil && cur_user_homework.count == 0 %> + <%= link_to l(:label_commit_homework),new_homework_attach_path(bid) %> + <% else %> + <%= l(:lable_has_commit_homework)%> + <% end %> <% end %> <% if (User.current.admin?||User.current.id==bid.author_id) %> <%= link_to( diff --git a/app/views/bids/_fork_form.html.erb b/app/views/bids/_fork_form.html.erb index 1bfb4550..3fcf0f02 100644 --- a/app/views/bids/_fork_form.html.erb +++ b/app/views/bids/_fork_form.html.erb @@ -19,6 +19,7 @@

<%= f.select :homework_type, homework_type_option %>

--> +

<%= f.select :is_evaluation, is_evaluation_option %>

<%= l(:label_attachment_plural) %>

<%= render :partial => 'attachments/form', :locals => {:container => @homework} %>

\ No newline at end of file diff --git a/app/views/bids/_homework_form.html.erb b/app/views/bids/_homework_form.html.erb index f726c038..92b16203 100644 --- a/app/views/bids/_homework_form.html.erb +++ b/app/views/bids/_homework_form.html.erb @@ -36,6 +36,7 @@

<%= f.select :homework_type, homework_type_option %>

--> +

<%= f.select :is_evaluation, is_evaluation_option %>

<%= hidden_field_tag 'course_id', @project_id %>

<%= l(:label_attachment_plural) %> diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index fd4b0a93..18778f5e 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -1,7 +1,8 @@ -<% is_student = is_cur_course_student? @bid.courses.first %> +<% is_student = is_cur_course_student(@bid.courses.first) %> <% is_teacher = is_course_teacher User.current,@bid.courses.first %> - + +<% is_evaluation = @bid.is_evaluation == 1 || @bid.is_evaluation == nil %> <%= form_tag(:controller => 'bids', :action => "show_project", :method => :get) do %>
@@ -41,23 +42,25 @@ <% else %> <% homework_filename = attachment.filename %> <% end %> - <% end %> <% else %> <% homework_filename = homework.name %> <% end %> - <%= link_to homework_filename, :controller => "zipdown", :action => "download_user_homework",:obj_class => @bid.class,:obj_id => @bid, :user_id =>homework.user%> + + <% if is_evaluation || is_teacher%> + <%= link_to homework_filename, :controller => "zipdown", :action => "download_user_homework",:homework => homework%> + <% else %> + <%= homework_filename %> + <% end %> + - -
<% if is_student %> - <%= link_to "互评>>" , homework_attach_path(homework)%> + <% if is_evaluation %> + <%= link_to "互评>>" , homework_attach_path(homework)%> + <% else %> + <%= link_to "查看详细" , homework_attach_path(homework)%> + <% end %> <% else %> <% if is_teacher %> <%= link_to "综评>>" , homework_attach_path(homework)%> @@ -71,13 +74,8 @@ 作业评分: - <% stars_reates = homework.rates(:quality) %> - <% sum = 0 %> - <% stars_reates.each do |star_reates| %> - <% sum = sum + star_reates.stars %> - <% end %> - <% stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count %> - <%= format("%.2f", sum * 1.0 / stars_reates_count) %> + + <%= format("%.2f", homework.rate_averages.first.try(:avg).to_f ) %> <% if Time.parse(@bid.deadline.to_s) < Time.parse(homework.created_at.to_s) %> @@ -87,36 +85,23 @@
  - <% if is_cur_course_user? @bid %> - <%= l(:label_bidding_user_studentcode) %>  : <%= homework.user.user_extensions.student_id%> + <% if User.current.member_of?(@bid.courses.first) %> + <%= l(:label_bidding_user_studentcode) %>  : <%= homework.user.student_id%> <% end %> - <% if (User.current == homework.user) || (!Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.nil? && - (Member.where('user_id = ? and project_id = ?', User.current.id, @bid.courses.first.id).first.roles&Role.where('id = ? or id = ? or id =?',3,7, 9)).size >0) %> + <% if (users_for_homework(homework).include?(User.current) || is_teacher) %> <%= link_to l(:button_edit), edit_homework_attach_path(homework) %> - <%= link_to(l(:label_bid_respond_delete), homework, - method: :delete, :confirm => l(:text_are_you_sure)) %> + <% if homework.user == User.current || is_teacher %> + <%= link_to(l(:label_bid_respond_delete), homework, + method: :delete, :confirm => l(:text_are_you_sure)) %> + <% end %> <% end %>
-<% end %> +<% end %> \ No newline at end of file diff --git a/app/views/bids/show_project.html.erb b/app/views/bids/show_project.html.erb index c14d2e14..039de6b7 100644 --- a/app/views/bids/show_project.html.erb +++ b/app/views/bids/show_project.html.erb @@ -1,8 +1,9 @@ <% if @bid.homework_type == Bid::HomeworkFile %> + <%= render :partial => 'homework' %> <% else %> - + + + \ No newline at end of file diff --git a/app/views/contestnotifications/new.html.erb b/app/views/contestnotifications/new.html.erb new file mode 100644 index 00000000..30d5f010 --- /dev/null +++ b/app/views/contestnotifications/new.html.erb @@ -0,0 +1,9 @@ + +<%= labelled_form_for @contestnotification, :url => contest_contestnotifications_path(@contest), :html => { :id => 'contestnotifications-form', :multipart => true } do |f| %> + <%= render :partial => 'contestnotifications/form', :locals => { :f => f } %> + <%= submit_tag l(:button_create), :class => "whiteButton m3p10 h30" %> + <%= submit_tag l(:button_cancel), :class => "whiteButton m3p10 h30",:onclick => "cancel();" %> + + +<% end %> +
diff --git a/app/views/contestnotifications/show.html.erb b/app/views/contestnotifications/show.html.erb new file mode 100644 index 00000000..eea4cc20 --- /dev/null +++ b/app/views/contestnotifications/show.html.erb @@ -0,0 +1,91 @@ + +
+ <%= link_to(l(:button_edit), + edit_contest_contestnotification_path(@contest, @contestnotification), + :class => 'icon icon-edit', + :accesskey => accesskey(:edit), + :onclick => '$("#edit-contestnotifications").show(); return true;') if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?)%> + <%= delete_link contest_contestnotification_path(@contest, @contestnotification) if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?) %> +
+ +

<%=h @contestnotification.title %>

+ + + +
+ +
+ <%= textilizable(@contestnotification, :description) %> +
+ <%#= link_to_attachments @contestnotification %> +
+ + + <% if User.current.logged? %> +

+ <%= toggle_link l(:label_comment_add), "add_notificationcomment_form", :focus => "notificationcomment_notificationcomments" %> +

+ <% else %> + <%= l(:label_user_login_notificationcomment) %> + <%= link_to l(:label_user_login_new), signin_path %> + <% end %> + + <%= form_tag( contest_contestnotification_notificationcomments_path(@contest, @contestnotification) , :id => "add_notificationcomment_form", :style => "display:none;") do %> +
+ <%= text_area 'notificationcomment', 'notificationcomments', :cols => 80, :rows => 15, :class => 'wiki-edit' %> + <%= wikitoolbar_for 'notificationcomment_notificationcomments' %> +
+

+ <%= submit_tag l(:button_add) %> + <%= submit_tag l(:button_cancel), :onclick => "cancel();" %> +

+ <% end %> + + + <% html_title @contestnotification.title -%> + + <% content_for :header_tags do %> + <%= stylesheet_link_tag 'scm' %> + <% end %> + + +
+
+

<%= l(:label_comment_plural) %>

+ <% notificationcomments = @notificationcomments.reverse %> + <% notificationcomments.each do |notificationcomment| %> + <% next if notificationcomment.new_record? %> + + + + + +
<%= image_tag(url_to_avatar(notificationcomment.author), :class => "avatar")%> + + + + + + + + + + + +
<%= link_to_user(notificationcomment.author) if notificationcomment.respond_to?(:author) %> <%= l(:label_project_newadd) %><%= l(:label_comment_plural) %>
+

+ <%= textilizable(notificationcomment.notificationcomments) %> +

<%= format_time(notificationcomment.created_at) %><%#= link_to_if_authorized_contest image_tag('delete.png'), {:controller => 'notificationcomments', :action => 'destroy', :id => @contestnotifications, :notificationcomment_id => notificationcomment}, + :data => {:confirm => l(:text_are_you_sure)}, :method => :delete, :title => l(:button_delete) %>
+ <% end if @notificationcomments.any? %> +
+ + diff --git a/app/views/contests/show_contest.html.erb b/app/views/contests/show_contest.html.erb index 67414b0c..c379bc66 100644 --- a/app/views/contests/show_contest.html.erb +++ b/app/views/contests/show_contest.html.erb @@ -15,7 +15,7 @@
<%= render :partial => "/praise_tread/praise_tread", - :locals => {:obj => @contest,:show_flag => true,:user_id =>User.current.id}%> + :locals => {:obj => @contest,:show_flag => true,:user_id =>User.current.id,:horizontal => false}%> diff --git a/app/views/courses/_homework_form.html.erb b/app/views/courses/_homework_form.html.erb index dc1550a3..442ebbeb 100644 --- a/app/views/courses/_homework_form.html.erb +++ b/app/views/courses/_homework_form.html.erb @@ -32,10 +32,8 @@

-->

<%= f.text_field :deadline, :required => true, :size => 60, :style => "width:150px;" %><%= calendar_for('bid_deadline')%>

-

<%= hidden_field_tag 'course_id', @course.id %>

<%= l(:label_attachment_plural) %> diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb index 38ed8819..d626fe30 100644 --- a/app/views/documents/show.html.erb +++ b/app/views/documents/show.html.erb @@ -1,3 +1,5 @@ +
+
<% if User.current.allowed_to?(:edit_documents, @project) %> <%= link_to l(:button_edit), edit_document_path(@document), :class => 'icon icon-edit', :accesskey => accesskey(:edit) %> @@ -7,26 +9,15 @@ <% end %>
- - - - - - - -

<%=h @document.title %>

-
- <%= textilizable @document.description, :attachments => @document.attachments %> -
-

<%= format_date @document.created_on %>

- +<%= textilizable @document, :description, :attachments => @document.attachments %> +
+

<%= l(:label_attachment_plural) %>

<%= link_to_attachments @document %> @@ -42,3 +33,4 @@ <% end %> <% html_title @document.title -%> + diff --git a/app/views/homework_attach/_comprehensive_evaluation.html.erb b/app/views/homework_attach/_comprehensive_evaluation.html.erb index e6ebacff..08db3054 100644 --- a/app/views/homework_attach/_comprehensive_evaluation.html.erb +++ b/app/views/homework_attach/_comprehensive_evaluation.html.erb @@ -22,12 +22,6 @@
<%= comprehensive_evaluation.first.notes%>
- <% if is_teacher %> -
评分: - <%= rating_for homework, dimension: :quality, class: 'rateable div_inline' %> - (您可以重新打分,打分结果以最后一次打分为主!) -
- <% end %> <% else %> <% if is_teacher %> @@ -35,10 +29,7 @@
作业综评:
-
评分: - <%= rating_for homework, dimension: :quality, class: 'rateable div_inline' %> - (您可以重新打分,打分结果以最后一次打分为主!) -
+ <%= render :partial => 'evaluation', :locals => {:homework => homework} %>
<%= render :partial => 'addjour', :locals => {:homework_attach => homework, :sta => 0,:is_comprehensive_evaluation => 1} %>
diff --git a/app/views/homework_attach/_evaluation.html.erb b/app/views/homework_attach/_evaluation.html.erb new file mode 100644 index 00000000..bd8677fb --- /dev/null +++ b/app/views/homework_attach/_evaluation.html.erb @@ -0,0 +1,4 @@ +
评分: + <%= rating_for homework, dimension: :quality, class: 'rateable div_inline' %> + (每个用户对每份作业只能进行一次评价!) +
\ No newline at end of file diff --git a/app/views/homework_attach/_homework_member.html.erb b/app/views/homework_attach/_homework_member.html.erb new file mode 100644 index 00000000..9dfe170b --- /dev/null +++ b/app/views/homework_attach/_homework_member.html.erb @@ -0,0 +1,44 @@ +<%= error_messages_for 'member' %> +
+ + + + + + + + + + + + + + + + <% hoemwork_users.each do |user| %> + + <% if homework.user != user %> + + + + <% end %> + + <% end %> + +
<%= l(:label_user) %><%= l(:label_role_plural) %>
<%= link_to_user homework.user %> 发布人员
<%= link_to_user user %> 参与人员 <%= link_to l(:button_delete),destory_homework_users_homework_attach_path(:user_id=>user),:remote => true, :method => :post %>
+
+ +
+ <%= form_for(hoemwork_users, {:url => add_homework_users_homework_attach_path(homework), :remote => true, :method => :post}) do |f| %> +
+ <%= l(:label_member_new) %> +

<%= label_tag "principal_search", l(:label_principal_search) %><%= text_field_tag 'principal_search', nil %>

+ <%= javascript_tag "observeSearchfield('principal_search', null, '#{ escape_javascript get_homework_member_list_homework_attach_index_path(:q => params[:q], :bid_id => params[:id]||homework, :format => 'js') }')" %> +
+ <%= render_new_members_for_homework(members) %> +
+

<%= submit_tag l(:button_add), :id => 'member-add-submit' %>

+
+ <% end %> +
diff --git a/app/views/homework_attach/_member_list_partial.html.erb b/app/views/homework_attach/_member_list_partial.html.erb new file mode 100644 index 00000000..ca422f0d --- /dev/null +++ b/app/views/homework_attach/_member_list_partial.html.erb @@ -0,0 +1,3 @@ +
+ <%= render_new_members_for_homework(members) %> +
\ No newline at end of file diff --git a/app/views/homework_attach/_new_homework.html.erb b/app/views/homework_attach/_new_homework.html.erb new file mode 100644 index 00000000..de749d18 --- /dev/null +++ b/app/views/homework_attach/_new_homework.html.erb @@ -0,0 +1,22 @@ +
+

+ 标 题: + <%= f.text_field "name", :required => true, :size => 60, :style => "width:490px;" %> +

+

+ 描 述: + + <%= f.text_area "description", :rows => 8, :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %> + +

+

+

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

+ <%= render :partial => 'attachments/form' %> +

+
+

+
\ No newline at end of file diff --git a/app/views/homework_attach/add_homework_users.js.erb b/app/views/homework_attach/add_homework_users.js.erb new file mode 100644 index 00000000..dc4b0cc5 --- /dev/null +++ b/app/views/homework_attach/add_homework_users.js.erb @@ -0,0 +1 @@ +$('#content2').html('<%= escape_javascript(render(:partial => 'homework_member', :locals => {:members => @members,:hoemwork_users =>@hoemwork_users,:homework => @homework} )) %>'); \ No newline at end of file diff --git a/app/views/homework_attach/destory_homework_users.js.erb b/app/views/homework_attach/destory_homework_users.js.erb new file mode 100644 index 00000000..dc4b0cc5 --- /dev/null +++ b/app/views/homework_attach/destory_homework_users.js.erb @@ -0,0 +1 @@ +$('#content2').html('<%= escape_javascript(render(:partial => 'homework_member', :locals => {:members => @members,:hoemwork_users =>@hoemwork_users,:homework => @homework} )) %>'); \ No newline at end of file diff --git a/app/views/homework_attach/edit.html.erb b/app/views/homework_attach/edit.html.erb index 80292340..f7104840 100644 --- a/app/views/homework_attach/edit.html.erb +++ b/app/views/homework_attach/edit.html.erb @@ -1,35 +1,79 @@ -

<%=raw l(:label_new_homework)%>

-
+ + +
+ + + + + + + + + + +
高校课程实践社区<%= l(:label_user_location) %> :
<%= link_to request.host()+"/courses", :controller => 'projects', :action => 'course'%>

<%=link_to "主页", home_path %> > <%=link_to l(:label_course_practice), :controller => 'projects', :action => 'course' %> > + <%= link_to(@homework.bid.courses.first.name.to_s, homework_project_path(@homework.bid.courses.first)) if @homework.bid.courses.first%> > + <%=link_to(@homework.bid.name, respond_path(@homework.bid)) %> > <%= link_to "修改作业",edit_homework_attach_path(@homework)%>

+
+ +

<%=raw l(:label_edit_homework)%>

+ +
<%= form_for(@homework) do |f|%> -

- 标 题: - <%= f.text_field :name, :required => true, :name => "homework_name", :size => 60, :style => "width:490px;"%> -

-

- 描 述: - - <%= f.text_area :description, :rows => 8, :name => "homework_description", :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %> - -

-

-

-

- <% options = {:author => true, :deletable => attach_delete(@homework)} %> - <%= render :partial => 'attachments/links', - :locals => {:attachments => @homework.attachments, :options => options} %> -

- - <%= l(:label_attachment_plural) %> - -

- <%= render :partial => 'attachments/form' %> -

-
-

-

- - <%= submit_tag t(:label_button_ok), :sta => 0, :class => "enterprise"%> - -

+

+ 标 题: + <%= f.text_field :name, :required => true, :name => "homework_name", :size => 60, :style => "width:490px;"%> +

+

+ 描 述: + + <%= f.text_area :description, :rows => 8, :name => "homework_description", :class => 'wiki-edit', :style => "font-size:small;width:490px;margin-left:10px;" %> + +

+

+

+

+ <% options = {:author => true, :deletable => attach_delete(@homework)} %> + <%= render :partial => 'attachments/links', + :locals => {:attachments => @homework.attachments, :options => options} %> +

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

+ <%= render :partial => 'attachments/form' %> +

+
+

+

+ + <%= submit_tag t(:label_button_ok), :sta => 0, :class => "enterprise"%> + +

<% end %> -
\ No newline at end of file +
+ + diff --git a/app/views/homework_attach/get_homework_member_list.js.erb b/app/views/homework_attach/get_homework_member_list.js.erb new file mode 100644 index 00000000..64fa22cb --- /dev/null +++ b/app/views/homework_attach/get_homework_member_list.js.erb @@ -0,0 +1,2 @@ +$('#principals_for_new_member').replaceWith('<%= j(render :partial => "member_list_partial", locals:{members: @members})%>'); + diff --git a/app/views/homework_attach/new.html.erb b/app/views/homework_attach/new.html.erb index 966176a1..618fc15a 100644 --- a/app/views/homework_attach/new.html.erb +++ b/app/views/homework_attach/new.html.erb @@ -1,3 +1,19 @@ +
+ + + + + + + + + + +
高校课程实践社区<%= l(:label_user_location) %> :
<%= link_to request.host()+"/courses", :controller => 'projects', :action => 'course'%>

<%=link_to "主页", home_path %> > <%=link_to l(:label_course_practice), :controller => 'projects', :action => 'course' %> > + <%= link_to(@bid.courses.first.name.to_s, homework_project_path(@bid.courses.first)) if @bid.courses.first%> > + <%=link_to(@bid.name, respond_path(@bid)) %> > <%= link_to "创建作业", new_homework_attach_path(@bid)%>

+
+

<%=h l(:label_new_homework)%>

<%= form_for('new_form', :method => :post, @@ -26,10 +42,11 @@

-

+ +

<%= submit_tag t(:label_button_ok), :sta => 0, :class => "enterprise"%>

<% end %> - \ No newline at end of file + diff --git a/app/views/homework_attach/show.html.erb b/app/views/homework_attach/show.html.erb index 2b2ec5cc..4ab6141d 100644 --- a/app/views/homework_attach/show.html.erb +++ b/app/views/homework_attach/show.html.erb @@ -1,4 +1,4 @@ - +<%= render :partial => 'layouts/base_homework_attach', :locals => {:homework_attach => @homework} %> -<% is_student = is_cur_course_student? @homework.bid.courses.first %> +<% is_student = is_cur_course_student @homework.bid.courses.first %> <% is_teacher = is_course_teacher User.current,@homework.bid.courses.first %> -

<%= notice %>

@@ -24,23 +23,35 @@ 发布人员:<%= link_to @homework.user, user_path(@homework.user)%> - 发布时间:<%=format_time @homework.created_at %> + + 所属任务:<%= link_to(@homework.bid.name, project_for_bid_path(@homework.bid))%> + 作业下载: - <% options = {:author => true } %> - <%= render :partial => 'app_link', :locals => {:attachments => @homework.attachments, :options => options} %> + <% if @is_evaluation || is_teacher%> + <% options = {:author => true } %> + <%= render :partial => 'app_link', :locals => {:attachments => @homework.attachments, :options => options} %> + <% else %> + <%= l(:label_cant_download) %> + <% end %> - - 所属任务:<%= link_to(@homework.bid.name, project_for_bid_path(@homework.bid))%> + + 参与人员: + <% @homework.users.each do |homework_user| %> + <%= link_to homework_user, user_path(homework_user)%> + <% if @homework.users.count > 1 && homework_user != @homework.users.last %> +
                 + <% end %> + <% end %> - - 平均评分: + 平均评分: <%= rating_for @homework, :static => true, dimension: :quality, class: 'rateable div_inline' %> + 发布时间:<%=format_time @homework.created_at %> @@ -94,7 +105,7 @@
<%= @stars_status_map["star#{(star/20).to_s}".to_sym] %> -
+
<% end %> @@ -130,23 +141,37 @@
-
-
作业评论:
- <% if is_student %> -
评分: - <%= rating_for @homework, dimension: :quality, class: 'rateable div_inline' %> - (您可以重新打分,打分结果以最后一次打分为主!) -
- <% end %> -
+ + +<% if !users_for_homework(@homework).include?(User.current) %> +
+
作业评论:
+ <% if is_student %> + <% if @is_evaluation %> + <% if @has_evaluation %> +
+ <%= l(:lable_has_evaluation)%> +
+ <% else %> + <%= render :partial => 'evaluation', :locals => {:homework => @homework} %> + <% end %> + <% else %> +
+ <%= l(:lable_close_evaluation)%> +
+ <% end %> + <% end %> +
+<% end %> <% if !is_teacher %> - -
- <%= render :partial => 'addjour', :locals => {:homework_attach => @homework, :sta => 0, :is_comprehensive_evaluation => nil} %> -
+ +
+ <%= render :partial => 'addjour', :locals => {:homework_attach => @homework, :sta => 0, :is_comprehensive_evaluation => nil} %> +
<% end %> +
<%= render :partial => 'showjour', :locals => {:jour => @jour,:homework => @homework} %> diff --git a/app/views/issues/_list.html.erb b/app/views/issues/_list.html.erb index 2b17b4fb..dd348725 100644 --- a/app/views/issues/_list.html.erb +++ b/app/views/issues/_list.html.erb @@ -10,7 +10,7 @@ <% column_content = ( query.inline_columns.map {|column| "#{column_content_new(column, issue)}"}) %> - <%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => issue,:show_flag => true,:user_id =>User.current.id}%> + <%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => issue,:show_flag => true,:user_id =>User.current.id,:horizontal => false}%> <% if issue.tracker_id == 1 %> <%= image_tag("/images/task.png", :class => "img-tag-issues") %> diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index d261957c..8e6ad803 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -33,7 +33,7 @@ - <%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => @issue,:show_flag => true,:user_id =>User.current.id}%> + <%= render :partial => "/praise_tread/praise_tread",:locals => {:obj => @issue,:show_flag => true,:user_id =>User.current.id,:horizontal => false}%>

diff --git a/app/views/layouts/_base_footer.html.erb b/app/views/layouts/_base_footer.html.erb index baf438cb..c62a974d 100644 --- a/app/views/layouts/_base_footer.html.erb +++ b/app/views/layouts/_base_footer.html.erb @@ -1,4 +1,5 @@ +<% cache "footer" do %>