diff --git a/app/assets/javascripts/contest_members.js.coffee b/app/assets/javascripts/contest_members.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/contest_members.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/javascripts/contestant_works.js.coffee b/app/assets/javascripts/contestant_works.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/contestant_works.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/javascripts/contestnotifications.js b/app/assets/javascripts/contestnotifications.js deleted file mode 100644 index dee720fac..000000000 --- a/app/assets/javascripts/contestnotifications.js +++ /dev/null @@ -1,2 +0,0 @@ -// 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/contests.js.coffee b/app/assets/javascripts/contests.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/contests.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/javascripts/works.js.coffee b/app/assets/javascripts/works.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/works.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/contest_members.css.scss b/app/assets/stylesheets/contest_members.css.scss new file mode 100644 index 000000000..ca038cd20 --- /dev/null +++ b/app/assets/stylesheets/contest_members.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the contest_members controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/contestant_works.css.scss b/app/assets/stylesheets/contestant_works.css.scss new file mode 100644 index 000000000..3c6e458c8 --- /dev/null +++ b/app/assets/stylesheets/contestant_works.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the contestant_works controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/contestnotifications.css b/app/assets/stylesheets/contestnotifications.css deleted file mode 100644 index afad32db0..000000000 --- a/app/assets/stylesheets/contestnotifications.css +++ /dev/null @@ -1,4 +0,0 @@ -/* - Place all the styles related to the matching controller here. - They will automatically be included in application.css. -*/ diff --git a/app/assets/stylesheets/contests.css.scss b/app/assets/stylesheets/contests.css.scss new file mode 100644 index 000000000..f799aa9d3 --- /dev/null +++ b/app/assets/stylesheets/contests.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the contests controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/works.css.scss b/app/assets/stylesheets/works.css.scss new file mode 100644 index 000000000..8c84be8c4 --- /dev/null +++ b/app/assets/stylesheets/works.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the works 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/contest_members_controller.rb b/app/controllers/contest_members_controller.rb new file mode 100644 index 000000000..a5954d2c3 --- /dev/null +++ b/app/controllers/contest_members_controller.rb @@ -0,0 +1,2 @@ +class ContestMembersController < ApplicationController +end diff --git a/app/controllers/contest_notification_controller.rb b/app/controllers/contest_notification_controller.rb deleted file mode 100644 index 2ae841ed0..000000000 --- a/app/controllers/contest_notification_controller.rb +++ /dev/null @@ -1,6 +0,0 @@ -class ContestNotificationController < ApplicationController - layout 'contest_base' - def show - @notification = ContestNotification.find(params[:id]) - end -end diff --git a/app/controllers/contestant_works_controller.rb b/app/controllers/contestant_works_controller.rb new file mode 100644 index 000000000..50adc24b1 --- /dev/null +++ b/app/controllers/contestant_works_controller.rb @@ -0,0 +1,119 @@ +#encoding: utf-8 +class ContestantWorksController < ApplicationController + include ContestantWorksHelper + include ApplicationHelper + require 'bigdecimal' + require "base64" + before_filter :find_contestwork, :only => [:new, :index, :create, :new_student_work_project,:student_work_project,:cancel_relate_project, + :search_course_students,:work_canrepeat,:add_group_member,:change_project] + before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment] + before_filter :member_of_contest, :only => [:new, :create, :show] + before_filter :author_of_work, :only => [:edit, :update, :destroy] + before_filter :admin_of_contest, :only => [] + before_filter :is_logged, :only => [:index] + + def new + + end + + def index + + end + + def show + + end + + def create + + end + + def edit + + end + + def update + + end + + def destroy + + end + + def new_student_work_project + @user_activity_id = params[:user_activity_id].to_i + @hw_status = params[:hw_status].to_i + respond_to do |format| + format.js + end + end + + #创建作业的关联项目 + def student_work_project + @project = ContestantWorkProject.new + @project.work_id = @contestwork.id + @project.project_id = params[:projectName].to_i + @project.user_id = User.current.id + @project.is_leader = 1 + @project.contest_id = @contestwork.contest_id + if @project.save + @user_activity_id = params[:user_activity_id].to_i + @hw_status = params[:hw_status].to_i + @is_teacher = User.current.admin_of_contest?(@contestwork.contest) || User.current.admin? + respond_to do |format| + format.js + end + end + end + + # 取消关联项目 + def cancel_relate_project + relate_pro = ContestantWorkProject.where("user_id = #{User.current.id} and work_id = #{@contestwork.id}").first + if relate_pro.destroy + @user_activity_id = params[:user_activity_id].to_i + @hw_status = params[:hw_status].to_i + @is_teacher = User.current.admin_of_contest?(@contestwork.contest) || User.current.admin? + respond_to do |format| + format.js + end + end + end + + private + #获取题目 + def find_contestwork + @contestwork = Work.find params[:work] + @contest = @contestwork.contest + rescue + render_404 + end + + #获取作品 + def find_work + @work = ContestantWork.find params[:id] + @contestwork = @work.work + @contest = @contestwork.contest + rescue + render_404 + end + + #是不是当前竞赛的成员 + #当前竞赛成员才可以看到作品列表 + def member_of_contest + render_403 unless User.current.member_of_contest?(@contest) || User.current.admin? + end + + #判断是不是当前作品的提交者 + #提交者 && (非匿评作业 || 未开启匿评) 可以编辑作品 + def author_of_work + render_403 unless User.current.admin? || User.current.id == @work.user_id + end + + def admin_of_contest + render_403 unless User.current.admin_of_contest?(@contest) || User.current.admin? + end + + def is_logged + redirect_to signin_path unless User.current.logged? + end +end diff --git a/app/controllers/contestnotifications_controller.rb b/app/controllers/contestnotifications_controller.rb deleted file mode 100644 index 54ba33262..000000000 --- a/app/controllers/contestnotifications_controller.rb +++ /dev/null @@ -1,187 +0,0 @@ -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_url(@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_url(@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_url(@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 d3edde756..4f711a124 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -1,736 +1,51 @@ -# fq -# class BidsController < ApplicationController -class ContestsController < ApplicationController - layout "contest_base" - - menu_item :respond - menu_item :project, :only => :show_project - menu_item :application, :only => :show_softapplication - menu_item :attendingcontests, :only => :show_attendingcontest - menu_item :contestnotifications, :only => :index - - before_filter :can_show_contest, :except => [] # modified by alan - - # modified by longjun - 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, :watcherlist, - :join_in_contest, :unjoin_in_contest, :new_join, :settings - ] - # end longjun - - # added by fq - before_filter :require_login, :only => [:join_in_contest, :unjoin_in_contest] - # end - before_filter :require_login,:only => [:set_reward, :destroy, :add, :new ] - - helper :watchers - helper :attachments - helper :projects - helper :words - - include AttachmentsHelper - include ApplicationHelper - - - def index - render_404 unless params[:name] - # @contests = Contest.visible - # @contests ||= [] - @offset, @limit = api_offset_and_limit(:limit => 10) - #@contests = Contest.visible - #@contests = @contests.like(params[:name]) if params[:name].present? - @is_search = params[:name] ? true:false - @contests = Contest.visible.where("name like '%#{params[:name]}%'") - if params[:contests_search] - (redirect_to contests_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank? - end - @contest_count = @contests.count - @contest_pages = Paginator.new @contest_count, @limit, params['page'] - - @offset ||= @contest_pages.reverse_offset - if params[:contest_sort_type].present? - case params[:contest_sort_type] - when '0' - # modified by longjun - # never use unless and else, 将下面重复操作模块化,放在private下 - # unless @offset == 0 - # if @offset != 0 - # @contests = @contests.reorder('contests.commit').offset(@offset).limit(@limit).all.reverse - # else - # limit = @contest_count % @limit - # limit = @limit if limit == 0 - # @contests = @contests.reorder('contests.commit').offset(@offset).limit(limit).all.reverse - - @contests = index_page_sort(@offset, @limit, @contest_count, @contests, 'contests.commit') - # end - @s_state = 0 - when '1' - - @contests = index_page_sort(@offset, @limit, @contest_count, @contests, 'contests.created_on') - @s_state = 1 - # modified by longjun - # 目前只有 0, 1 两个sort_type - # when '2' - else - # end longjun - - @contests = index_page_sort(@offset, @limit, @contest_count, @contests, '') - @s_state = 0 - end - else - # modified by longjun - # never use unless and else - # unless @offset == 0 - if @offset != 0 - @contests = @contests.reorder('contests.created_on').offset(@offset).limit(@limit).all.reverse - else - limit = @contest_count % @limit - limit = @limit if limit == 0 - @contests = @contests.reorder('contests.created_on').offset(@offset).limit(limit).all.reverse - end - @s_state = 1 - end - end - - def search - redirect_to action: 'index',name:params[:name] - end - - def homework - @offset, @limit = api_offset_and_limit({:limit => 10}) - @bids = @course.homeworks.order('deadline DESC') - @bids = @bids.like(params[:name]) if params[:name].present? - @bid_count = @bids.count - @bid_pages = Paginator.new @bid_count, @limit, params['page'] - - @offset ||= @bid_pages.reverse_offset - # modified by longjun - # never use unless and else - # unless @offset == 0 - if @offset != 0 - @bids = @bids.offset(@offset).limit(@limit).all.reverse - else - limit = @bid_count % @limit - @bids = @bids.offset(@offset).limit(limit).all.reverse - end - render :layout => 'base_courses' - - end - - - def show_contest - @user = @contest.author - @jours = @contest.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') - #@limit = 10 - #@feedback_count = @jours.count - #@feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - #@offset ||= @feedback_pages.offset - #@jour = @jours[@offset, @limit] - @jour = paginateHelper @jours,10 - @state = false - - respond_to do |format| - format.html { - render :layout => 'base_newcontest' - } - format.api - end - end - - def join_in_contest - if params[:contest_password] == @contest.password - JoinInCompetition.create(:user_id => User.current.id, :competition_id => @contest.id) - @state = 0 - else - @state = 1 - end - - respond_to do |format| - format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} } - end - end - - def unjoin_in_contest - - joined = JoinInCompetition.where('competition_id = ? and user_id = ?', @contest.id, User.current.id) - - joined.each do |join| - join.delete - end - - respond_to do |format| - format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} } - end - end - - - - def show_participator - render :layout => 'base_newcontest' - - end - - - def settings - if @contest.author.id == User.current.id - @contest = Contest.find(params[:id]) - render :layout => 'base_newcontest' - else - render_403 :message => :notice_not_contest_setting_authorized - end - end - - # Added by Longjun - def destroy_contest - @contest = Contest.find(params[:id]) - if @contest.author_id == User.current.id || User.current.admin? - - @contest.destroy - redirect_to welcome_contest_url - else - render_403 :message => :notice_not_contest_delete_authorized - end - - end - # end - - def show_contest_project - contests = Contest.where('parent_id = ?', @contest.id) - @projects = [] - - # Modified by longjun - # 用 arr.each 替换 for [ according to the style guide ] - - # for contest in contests - # @projects += contest.contesting_projects - # end - - contests.each do |contest| - @projects += contest.contesting_projects - end - - # end - - respond_to do |format| - format.html { - render :layout => 'base_newcontest' - } - format.api - end - end - - def show_contest_softapplication - contests = Contest.where('parent_id = ?', @contest.id) - @softapplications = [] - - # Modified by Longjun - # for contest in contests - # @softapplications += contest.contesting_softapplications - - - contests.each do |contest| - @softapplications += contest.contesting_softapplications - end - - # end - - respond_to do |format| - format.html { - render :layout => 'base_newcontest' - } - format.api - - end - end - - def show_contest_user - contests = Contest.find(:all) - @users = [] - - # Modified by Longjun - # for contest in contests - # for project in contest.projects - # @users += project.users - # end - - - contests.each do |contest| - contest.projects.each do |project| - @users += project.users - end - end - # end - - respond_to do |format| - format.html { - render :layout => 'base_newcontest' - } - format.api - - end - end - #显示参赛的项目 - def show_project - @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) - @option = [] - # @contesting_project_count = @contesting_project_all.count - # @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page'] - @membership.each do |membership| - - # Modified by Longjun - # 将两个判断语句合并 - # unless membership.project.project_type==1 - # if User.current.allowed_to?(:quote_project, membership.project) - # @option << membership.project - # end - # end - if membership.project.project_type != 1 && User.current.allowed_to?(:quote_project, membership.project) - @option << membership.project - - end - # end - - end - @user = @contest.author - @contesting_project = @contest.contesting_projects.all - if params[:student_id].present? - @temp = [] - @contesting_project.each do |pro| - if pro.project && pro.project.project_status - if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id - @temp << pro - end - end - @temp - end - @contesting_project = @temp - else - - @temp = [] - @contesting_project.each do |pro| - # modified by longjun - # if pro.project && pro.project.project_status - # @temp << pro - # end - @temp << pro if pro.project && pro.project.project_status - # end longjun - @temp - end - if @temp.size > 0 - @contesting_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade} - end - end - @contesting_project = paginateHelper(@contesting_project) - respond_to do |format| - format.html { - render :layout => 'base_newcontest' - } - format.api - end - end - ############ - ##显示参赛的应用 - def show_softapplication - - # @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) - # @option = [] - - # @user = @contest.user - @softapplication = Softapplication.all - @contesting_softapplication = @contest.contesting_softapplications - - @contesting_softapplication = paginateHelper(@contesting_softapplication, 10) - - # @temp = [] - # @softapplicationt.each do |pro| - # if pro.project && pro.project.project_status - # @temp << pro - # end - # @temp - - # if @temp.size > 0 - # @contesting_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade} - # end - # end - # respond_to do |format| - # format.html { - # render :layout => 'base_newcontest' - # } - # format.api - # end -########################## - @contest = Contest.find_by_id(params[:id]) - respond_to do |format| - format.html { - render :layout => 'base_newcontest' - } - format.api - end - end - - - ###我要参赛 - def show_attendingcontest -##取出参赛项目--项目列表 - @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current)) - @option = [] - # @contesting_project_count = @contesting_project_all.count - # @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page'] - @membership.each do |membership| - unless membership.project.project_type==1 - #拥有编辑项目权限的可将该项目参赛 - if User.current.allowed_to?(:quote_project, membership.project) - @option << membership.project - end - end - end - @user = @contest.author - @contesting_project = @contest.contesting_projects.all - if params[:student_id].present? - @temp = [] - @contesting_project.each do |pro| - if pro.project && pro.project.project_status - if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id - @temp << pro - end - end - @temp - end - @contesting_project = @temp - else - - @temp = [] - @contesting_project.each do |pro| - # modified by longjun - # if pro.project && pro.project.project_status - # @temp << pro - # end - @temp << pro if pro.project && pro.project.project_status - # end longjun - @temp - end - if @temp.size > 0 - @contesting_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade} - end - end - # 取出参赛应用 --应用列表 - @softapplication = Softapplication.all - @contesting_softapplication = @contest.contesting_softapplications. - joins("LEFT JOIN softapplications ON contesting_softapplications.softapplication_id=softapplications.id"). - joins("LEFT JOIN ( - SELECT * FROM seems_rateable_cached_ratings - WHERE cacheable_type='Softapplication' AND DIMENSION = 'quality') AS cached - ON cached.cacheable_id=softapplications.id"). - order("cached.avg").reverse_order - @contesting_softapplication = paginateHelper @contesting_softapplication, 10 - - - #引用base_newcontest整体样式 - @contest = Contest.find_by_id(params[:id]) - respond_to do |format| - format.html { - render :layout => 'base_newcontest' - } - format.api - end - end - - ###end - - def show_notification - @contest = Contest.find_by_id(params[:id]) - respond_to do |format| - format.html { - render :layout => 'base_newcontest' - } - format.api - end - end - - - def set_reward_project - @c_p = nil - @contesting_project_id = nil - - if params[:set_reward_project][:reward]&&((User.current.id==@contest.author_id)||User.current.admin) - # @bid_id = params[:id] - @contesting_project_id = params[:set_reward_project][:c_id] - @c_p = ContestingProject.find_by_id(@contesting_project_id) - - # 把字段存进表中 - @c_p.update_reward(params[:set_reward_project][:reward].to_s) - end - - respond_to do |format| - format.js - end - end - - def set_reward_softapplication - @c_sa = nil - @contesting_softapplication_id = nil - - if params[:set_reward_softapplication][:reward]&&((User.current.id==@contest.author_id)||User.current.admin) - # @bid_id = params[:id] - @contesting_softapplication_id = params[:set_reward_softapplication][:c_id] - @c_sa = ContestingSoftapplication.find_by_id(@contesting_softapplication_id) - - # 把字段存进表中 - @c_sa.update_reward(params[:set_reward_softapplication][:reward].to_s) - end - - respond_to do |format| - format.js - end - end - - - ###添加已创建的参赛项目 - def add - project = Project.find(params[:contest]) - contest_message = params[:contest_for_save][:contest_message] - if ContestingProject.where("project_id = ? and contest_id = ?", project.id, @contest.id).size == 0 - # modified by longjun, create 写错了 - # if ContestingProject.cerate_contesting(@contest.id, project.id, contest_message) - if ContestingProject.create_contesting(@contest.id, project.id, contest_message) - # end longjun - - flash.now[:notice] = l(:label_bidding_contest_succeed) - end - else - flash.now[:error] = l(:label_bidding_fail) - end - - @contesting_project = paginateHelper @contest.contesting_projects - - respond_to do |format| - - format.html { redirect_to :back } - format.js - end - end - ###添加已发布的参赛应用 - def add_softapplication - softapplication = Softapplication.find(params[:contest]) - contest_message = params[:contest_for_save][:contest_message] - if ContestingSoftapplication.where("softapplication_id = ? and contest_id = ?", softapplication.id, @contest.id).size == 0 - if ContestingSoftapplication.create_softapplication_contesting(@contest.id, softapplication.id, contest_message) - flash.now[:notice] = l(:label_release_add_contest_succeed) - end - else - flash.now[:error] = l(:label_add_contest_succeed_fail) - end - - @contesting_softapplication = paginateHelper @contest.contesting_softapplications - - respond_to do |format| - - format.html { redirect_to :back } - format.js - end - end - ## 新建留言 - def create - - if params[:contest_message][:message].size>0 - if params[:reference_content] - message = params[:contest_message][:message] + "\n" + params[:reference_content] - else - message = params[:contest_message][:message] - end - refer_user_id = params[:contest_message][:reference_user_id].to_i - @contest.add_jour(User.current, message, refer_user_id) - end - @user = @contest.author - @jours = @contest.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') - @limit = 10 - @feedback_count = @jours.count - @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - @offset ||= @feedback_pages.offset - @jour = @jours[@offset, @limit] - @contest.set_commit(@feedback_count) - - respond_to do |format| - format.js - end - - end - - ##删除留言 - def destroy - @user = @contest.author - if User.current.admin? || User.current.id == @user.id - JournalsForMessage.delete_message(params[:object_id]) - end - @jours = @contest.journals_for_messages.reverse - @limit = 10 - @feedback_count = @jours.count - @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - @offset ||= @feedback_pages.offset - @jour = @jours[@offset, @limit] - - @contest.set_commit(@feedback_count) - respond_to do |format| - format.js - end - end - - ##引用留言 - def new - @jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id] - if @jour - user = @jour.user - text = @jour.notes - else - user = @contest.author - text = @contest.description - end - text = text.to_s.strip.gsub(%r{
((.|\s)*?)
}m, '[...]') - @content = "> #{ll(User.current.language, :text_user_wrote, user)}\n> " - @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" - @id = user.id - rescue ActiveRecord::RecordNotFound - render_404 - end - - ##新建竞赛 - def new_contest - @contest = Contest.new - @contest.safe_attributes = params[:contest] - end - - ##提交创建的竞赛 - def create_contest - @contest = Contest.new - @contest.name = params[:contest][:name] - @contest.description = params[:contest][:description] - @contest.budget = params[:contest][:budget] - @contest.deadline = params[:contest][:deadline] - @contest.password = params[:contest][:password] - @contest.author_id = User.current.id - @contest.commit = 0 - if @contest.save - unless @contest.watched_by?(User.current) - if @contest.add_watcher(User.current) - flash[:notice] = l(:label_contesting_created_succeed) - end - end - redirect_to show_contest_contest_url(@contest) - else - @contest.safe_attributes = params[:contest] - render :action => 'new_contest' - end - end - - ##更新竞赛配置信息 - def update_contest - @contest = Contest.find(params[:id]) - @contest.name = params[:contest][:name] - @contest.description = params[:contest][:description] - - @contest.budget = params[:contest][:budget] - @contest.deadline = params[:contest][:deadline] - @contest.password = params[:contest][:password] - @contest.author_id = User.current.id - @contest.commit = 0 - if @contest.save - unless @contest.watched_by?(User.current) - if @contest.add_watcher(User.current) - flash[:notice] = l(:label_contesting_updated_succeed) - end - end - redirect_to show_contest_contest_url(@contest) - - else - @contest.safe_attributes = params[:contest] - render :action => 'new_contest' - end - end - - def more - @jour = @contest.journals_for_messages - @jour.each_with_index {|j,i| j.indice = i+1} - @state = true - - respond_to do |format| - format.html { redirect_to :back } - format.js - #format.api { render_api_ok } - end - end - - def back - @jour = @contest.journals_for_messages - @jour.each_with_index {|j,i| j.indice = i+1} - @state = false - - respond_to do |format| - format.html { redirect_to :back } - format.js - #format.api { render_api_ok } - end - end - - def set_reward - @b_p = nil - @contesting_project_id = nil - - if params[:set_reward][:reward]&&((User.current.id==@contest.author_id)||User.current.admin) - # @contest_id = params[:id] - @contesting_project_id = params[:set_reward][:b_id] #[:b_id]??? - @b_p = ContestingProject.find_by_id(@contesting_project_id) - - # 把字段存进表中 - @b_p.update_reward(params[:set_reward][:reward].to_s) - end - - respond_to do |format| - format.js - end - end - def watcherlist - render :layout => 'base_newcontest' - end - - - - private - - def find_contest - if params[:id] - @contest = Contest.find(params[:id]) - @user = @contest.author - end - rescue - render_404 - end - - #验证是否显示竞赛 - def can_show_contest - @first_page = FirstPage.find_by_page_type('project') - if @first_page.show_contest == 2 - render_404 - end - end - - # added by longjun - # 将index页面中分页排序的方法抽离出来 - def index_page_sort(offset, limit, contest_count, contests, contest_sort_by) - # modified by longjun - # never use unless and else - # unless @offset == 0 - if offset != 0 - contests = contests.reorder(contest_sort_by).offset(offset).limit(limit).all.reverse - else - limit = contest_count % limit - limit = limit if limit == 0 - contests = contests.reorder(contest_sort_by).offset(offset).limit(limit).all.reverse - end - contests - end -end - +class ContestsController < ApplicationController + + before_filter :find_contest, :only => [:show] + before_filter :is_logged, :only => [:index, :new, :create] + + def show + + end + + def new + if User.current.login? + @contest = Contest.new + render :layout => 'new_base' + else + redirect_to signin_url + end + end + + def create + @contest = Contest.new + @contest.name = params[:contest][name] + params[:contest][:is_public] ? @contest.is_public = 1 : @contest.is_public = 0 + @contest.user_id = User.current.id + if @contest && @contest.save + #unless User.current.admin? + r = Role.givable.where(:name => 'ContestManager').first + m = ContestMember.new(:user => current_user, :roles => [r]) + @contest.contest_members << m + end + respond_to do |format| + format.html {redirect_to contest_url(@contest)} + end + end + + private + + def find_contest + if params[:id].to_i < 780 + render_403 + return + end + @contest = Contest.find(params[:id]) + rescue ActiveRecord::RecordNotFound + render_404 + end + + def is_logged + redirect_to signin_path unless User.current.logged? + end + +end diff --git a/app/controllers/shield_activities_controller.rb b/app/controllers/shield_activities_controller.rb index b2d5191b3..633fe4e93 100644 --- a/app/controllers/shield_activities_controller.rb +++ b/app/controllers/shield_activities_controller.rb @@ -11,6 +11,8 @@ class ShieldActivitiesController < ApplicationController ShieldActivity.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Project', :shield_id => params[:project_id].to_i) elsif params[:course_id] ShieldActivity.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Course', :shield_id => params[:course_id].to_i) + elsif params[:contest_id] + ShieldActivity.create(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Contest', :shield_id => params[:contest_id].to_i) end end end @@ -37,6 +39,10 @@ class ShieldActivitiesController < ApplicationController ShieldActivity.where("container_type='User' and container_id=#{params[:user_id].to_i} and shield_type='Course' and shield_id=#{params[:course_id]}").each do |act| act.destroy end + elsif params[:contest_id] + ShieldActivity.where(:container_type => 'User', :container_id => params[:user_id].to_i, :shield_type => 'Contest', :shield_id => params[:contest_id].to_i).each do |act| + act.destroy + end end end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 314f63069..8d8b8069b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -40,9 +40,9 @@ class UsersController < ApplicationController :anonymous_evaluation_list,:unfinished_test_list, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index, :unapproval_applied_list, :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index, :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource, - :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction, + :user_courses4show,:user_projects4show,:user_contests4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction, :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list, - :sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses,:homepage, :user_issues, :course_community, :project_community] + :sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses,:homepage, :user_issues, :course_community, :project_community, :contest_community] before_filter :auth_user_extension, only: :show #before_filter :rest_user_score, only: :show #before_filter :select_entry, only: :user_projects @@ -1641,6 +1641,13 @@ class UsersController < ApplicationController @all_count = @user.favorite_projects.visible.count end + # 竞赛社区左侧列表展开 + def user_contests4show + @page = params[:page].to_i + 1 + @courses = @user.favorite_contests.visible.where("is_delete =?", 0).select("contests.*,(SELECT MAX(updated_at) FROM `contest_activities` WHERE contest_activities.contest_id = contests.id) AS a").order("a desc").limit(10).offset(@page * 10) + @all_count = @user.favorite_contests.visible.where("is_delete =?", 0).count + end + def user_course_activities lastid = nil if params[:lastid]!=nil && !params[:lastid].empty? @@ -2224,6 +2231,61 @@ class UsersController < ApplicationController end end + # 竞赛社区 + def contest_community + shield_contest_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{@user.id} and shield_type='Contest'").map(&:shield_id) + @page = params[:page] ? params[:page].to_i + 1 : 0 + user_contest_ids = (@user.favorite_contests.visible.where("is_delete = 0").map{|contest| contest.id}-shield_contest_ids).empty? ? "(-1)" : "(" + (@user.favorite_contests.visible.map{|contest| contest.id}-shield_contest_ids).join(",") + ")" + contest_types = "('Message','News','Work','Contest','JournalsForMessage')" + container_type = '' + act_type = '' + + if params[:type].present? + case params[:type] + when "contest_work" + container_type = 'Contest' + act_type = 'HomeworkCommon' + when "contest_news" + container_type = 'Contest' + act_type = 'News' + when "contest_message" + container_type = 'Contest' + act_type = 'Message' + when "contest_journals" + container_type = 'Contest' + act_type = 'JournalsForMessage' + when "current_user" + container_type = 'Principal' + act_type = 'Principal' + when "all" + container_type = 'all' + act_type = 'all' + end + end + if container_type != '' && container_type != 'all' + if container_type == 'Contest' + sql = "container_type = '#{container_type}' and container_id in #{user_contest_ids} and act_type = '#{act_type}'" + elsif container_type == 'Principal' && act_type == 'Principal' + sql = "user_id = #{@user.id} and (container_type = 'Contest' and container_id in #{user_contest_ids} and act_type in #{contest_types})" + end + if User.current != @user + sql += " and user_id = #{@user.id}" + end + else + sql = "(container_type = 'Contest' and container_id in #{user_contest_ids} and act_type in #{contest_types})" + if container_type != 'all' && User.current != @user + sql = "user_id = #{@user.id} and(" + sql + ")" + end + end + @user_activities_count = UserActivity.where("#{sql}").order('updated_at desc').count + @user_activities = UserActivity.where("#{sql}").order('updated_at desc').limit(10).offset(@page * 10) + @type = params[:type] + respond_to do |format| + format.js + format.html {render :layout => 'base_contest_community'} + end + end + def show_old pre_count = 10 #limit # Time 2015-02-04 11:46:34 @@ -3987,6 +4049,9 @@ class UsersController < ApplicationController elsif params[:course] @course = Course.find params[:course] member = Member.where("user_id = #{@user.id} and course_id = #{@course.id}") + elsif params[:contest] + @contest = Contest.find params[:contest] + member = ContestMember.where("user_id = #{@user.id} and contest_id = #{@contest.id}") end unless member.empty? member.first.update_attribute(:is_collect, member.first.is_collect == 0 ? 1 : 0) @@ -3995,6 +4060,8 @@ class UsersController < ApplicationController @projects = @user.favorite_projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10) elsif @course @courses = @user.favorite_courses.visible.where("is_delete =?", 0).select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a").order("a desc").limit(10) + elsif @contest + @contests = @user.favorite_contests.visible.where("is_delete =?", 0).select("contests.*,(SELECT MAX(updated_at) FROM `contest_activities` WHERE contest_activities.contest_id = contests.id) AS a").order("a desc").limit(10) end respond_to do |format| format.js diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index 2ce505e15..953848d84 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -362,6 +362,70 @@ class WordsController < ApplicationController end end + #题目的回复 + def leave_contest_work_message + if User.current.logged? + @user = User.current + @contestwork = Work.find(params[:id]) + if params[:homework_message].size>0 && User.current.logged? && @user + feedback = Work.add_work_jour(@user, params[:homework_message], params[:id], @contestwork.id) + if (feedback.errors.empty?) + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE + end + @contestwork.update_column('updated_at', Time.now) + update_contest_activity(@contestwork.class,@contestwork.id) + update_user_activity(@contestwork.class,@contestwork.id) + respond_to do |format| + format.js{ + @user_activity_id = params[:user_activity_id].to_i + @hw_status = params[:hw_status].to_i if params[:hw_status] + @is_teacher = User.current.admin_of_contest?(@contestwork.contest) || User.current.admin? + } + end + else + flash[:error] = feedback.errors.full_messages[0] + end + end + else + render_403 + end + end + + #题目的二级回复 + def reply_to_contest_work + if User.current.logged? + @user = User.current + reply = JournalsForMessage.find params[:id].to_i + @contestwork = Work.find reply.jour_id + if params[:reply_message].size>0 && User.current.logged? && @user + options = {:notes => params[:reply_message], :reply_id => reply.user_id,:user_id => @user.id,:m_parent_id => params[:id].to_i,:m_reply_id => params[:id].to_i, :root_id => reply.root_id} + feedback = Work.add_work_jour(@user, params[:reply_message], reply.jour_id, reply.root_id, options) + if (feedback.errors.empty?) + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE + end + @contestwork.update_column('updated_at', Time.now) + update_contest_activity(@contestwork.class,@contestwork.id) + update_user_activity(@contestwork.class,@contestwork.id) + respond_to do |format| + format.js{ + @user_activity_id = params[:user_activity_id].to_i + @hw_status = params[:hw_status].to_i if params[:hw_status] + @is_teacher = User.current.admin_of_contest?(@contestwork.contest) || User.current.admin? + } + end + else + flash[:error] = feedback.errors.full_messages[0] + end + end + else + render_403 + end + end + #课程大纲的二级回复 def reply_to_syllabus if User.current.logged? diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb new file mode 100644 index 000000000..cfc87d169 --- /dev/null +++ b/app/controllers/works_controller.rb @@ -0,0 +1,6 @@ +class WorksController < ApplicationController + + def index + + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index aef32f714..99fa08dd4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2826,9 +2826,16 @@ module ApplicationHelper end technical_title end + + # 用户竞赛总数 + def user_contest_count + count = @user.contests.where(:is_delete => false).count + return count + end + # 用户项目总数 def user_project_count - @my_projects = @user.projects.select("projects.*,(SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS updatetime").order("updatetime DESC") + @my_projects = @user.projects.visible.where("status != 9") @my_project_total = @my_projects.count end @@ -3024,6 +3031,40 @@ module ApplicationHelper end end + #根据传入作业确定显示为编辑作品还是新建作品,或者显示作品数量 + def user_for_contest_work homework,is_teacher,work + count = homework.contestant_works.count + if User.current.member_of_contest?(homework.contest) + if is_teacher #老师显示作品数量 + link_to "作品(#{count})", contestant_work_index_url_in_org(homework.id, 2), :class => "c_blue" + else #学生显示提交作品、修改作品等按钮 + work = cur_user_works_for_work homework + project = cur_user_projects_for_work homework + if work.nil? && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") + if homework.work_type ==3 && project.nil? && homework.work_detail_group.base_on_project + link_to "提交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再提交作品' + else + link_to "提交作品(#{count})", new_contestant_works_index_path(:work => homework.id),:class => 'c_blue' + end + elsif work.nil? && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") + if homework.work_type ==3 && project.nil? && homework.work_detail_group.base_on_project + link_to "补交作品(#{count})","javascript:void(0)", :class => 'c_grey',:style=>"cursor:not-allowed",:title => '请先关联项目再补交作品' + else + link_to "补交作品(#{count})", new_contestant_works_index_path(:work => homework.id),:class => 'c_red' + end + else + if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d") && work.user_id == User.current.id + link_to "修改作品(#{count})", edit_contestant_works_path(work.id),:class => 'c_blue' + else + link_to "查看作品(#{count})", contestant_work_index_url_in_org(homework.id, 2), :class => 'c_blue', :title => "作业截止后不可修改作品" + end + end + end + else + link_to "作品(#{count})",contestant_work_index_url_in_org(homework.id, 2),:class => "c_blue" + end + end + #根据传入作业确定显示为提交作品、补交作品、查看作品等 def student_for_homework_common homework if User.current.allowed_to?(:as_teacher, homework.course) @@ -3108,6 +3149,24 @@ module ApplicationHelper homework.student_work_projects.where("user_id = ?",User.current).first end + #获取当前用户在指定题目下提交的作业的集合 + def cur_user_works_for_work work + work = work.contestant_works.where("user_id = ? && work_status != 0",User.current).first + if work.work_type == 3 + pro = work.contestant_work_projects.where("user_id = #{User.current.id}").first + if pro.nil? || pro.contestant_work_id == "" || pro.contestant_work_id.nil? + work = nil + else + work = ContestantWork.find pro.contestant_work_id + end + end + work + end + #获取当前用户在指定题目下关联的项目的集合 + def cur_user_projects_for_work work + work.contestant_work_projects.where("user_id = ?",User.current).first + end + #获取当前作业的提交截止时间/互评截止时间 def cur_homework_end_time homework str = "" @@ -3294,6 +3353,14 @@ int main(int argc, char** argv){ ss.html_safe end + #竞赛动态的更新 + def update_contest_activity type, id + contest_activity = ContestActivity.where("contest_act_type=? and contest_act_id =?", type.to_s, id).first + if contest_activity + contest_activity.updated_at = Time.now + contest_activity.save + end + end #课程动态的更新 def update_course_activity type, id course_activity = CourseActivity.where("course_act_type=? and course_act_id =?", type.to_s, id).first @@ -3392,6 +3459,17 @@ def student_work_index_url_in_org(homework_id, tab = 1, is_focus = '', show_work end end + +def contestant_work_index_url_in_org(work_id, tab = 1, is_focus = '', show_work_id = '') + if is_focus != '' + Setting.protocol + "://" + Setting.host_name + "/contestant_work?work=" + work_id.to_s + "&tab=" + tab.to_s + "&is_focus=" + is_focus.to_s + elsif show_work_id != '' + Setting.protocol + "://" + Setting.host_name + "/contestant_work?work=" + work_id.to_s + "&tab=" + tab.to_s + "&show_work_id=" + show_work_id.to_s + else + Setting.protocol + "://" + Setting.host_name + "/contestant_work?work=" + work_id.to_s + "&tab=" + tab.to_s + end +end + def course_url_in_org(course_id) Setting.protocol + "://" + Setting.host_name + "/courses/" + course_id.to_s end @@ -3750,6 +3828,17 @@ def message_content content content end +def get_work_index(hw,is_teacher) + if is_teacher + works = hw.contest.works.order("created_at asc") + else + works = hw.contest.works.where("publish_time <= '#{Date.today}'").order("created_at asc") + end + hw_ids = works.map{|hw| hw.id} if !works.empty? + index = hw_ids.index(hw.id) + return index +end + def get_hw_index(hw,is_teacher) if is_teacher homeworks = hw.course.homework_commons.order("created_at asc") diff --git a/app/helpers/contest_members_helper.rb b/app/helpers/contest_members_helper.rb new file mode 100644 index 000000000..f036537b3 --- /dev/null +++ b/app/helpers/contest_members_helper.rb @@ -0,0 +1,2 @@ +module ContestMembersHelper +end diff --git a/app/helpers/contestant_works_helper.rb b/app/helpers/contestant_works_helper.rb new file mode 100644 index 000000000..255aced00 --- /dev/null +++ b/app/helpers/contestant_works_helper.rb @@ -0,0 +1,2 @@ +module ContestantWorksHelper +end diff --git a/app/helpers/contestnotifications_helper.rb b/app/helpers/contestnotifications_helper.rb deleted file mode 100644 index ab17149d7..000000000 --- a/app/helpers/contestnotifications_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ContestnotificationsHelper -end diff --git a/app/helpers/contests_helper.rb b/app/helpers/contests_helper.rb index 0bc3e5e73..1bec615dd 100644 --- a/app/helpers/contests_helper.rb +++ b/app/helpers/contests_helper.rb @@ -1,206 +1,2 @@ -#enconding:utf-8 -# fq module ContestsHelper - - def render_notes(contest, journal, options={}) - content = '' - removable = User.current == journal.user || User.current == contest.author - links = [] - if !journal.notes.blank? - links << link_to(image_tag('comment.png'), - {:controller => 'contests', :action => 'new', :id => contest, :journal_id => journal}, - :remote => true, - :method => 'post', - :title => l(:button_quote)) if options[:reply_links] - if removable - url = {:controller => 'contests', - :action => 'destroy', - :object_id => journal, - :id => contest} - links << ' ' - links << link_to(image_tag('delete.png'), url, - :remote => true, :method => 'delete', :class => "delete", :title => l(:button_delete)) - end - end - content << content_tag('div', links.join(' ').html_safe, :class => 'contextual') unless links.empty? - content << textilizable(journal.notes) - css_classes = "wiki" - content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes) - end - - def link_to_in_place_notes_editor(text, field_id, url, options={}) - onclick = "$.ajax({url: '#{url_for(url)}', type: 'get'}); return false;" - link_to text, '#', options.merge(:onclick => onclick) - end - - # this method is used to get all projects that tagged one tag - # added by william - def get_contests_by_tag(tag_name) - Contest.tagged_with(tag_name).order('updated_on desc') - end - - #added by huang - def sort_contest_enterprise(state, project_type) - content = ''.html_safe - case state - when 0 - content << content_tag('li', link_to(l(:label_sort_by_active), calls_path(:contest_sort_type => '1', :project_type => project_type))) - content << content_tag('li', link_to(l(:label_sort_by_time), calls_path(:contest_sort_type => '0', :project_type => project_type), :class=>"selected"), :class=>"selected") - - when 1 - content << content_tag('li', link_to(l(:label_sort_by_active), calls_path(:contest_sort_type => '1', :project_type => project_type), :class=>"selected"), :class=>"selected") - content << content_tag('li', link_to(l(:label_sort_by_time), calls_path(:contest_sort_type => '0', :project_type => project_type))) - end - content = content_tag('ul', content) - content_tag('div', content, :class => "tabs_enterprise") - end - #end - - - - #huang - def sort_contest(state) - content = ''.html_safe - case state - when 0 - content << content_tag('li', link_to(l(:label_sort_by_time), {controller: 'contests', action: 'index' ,:contest_sort_type => '1'})) - content << content_tag('li', link_to(l(:label_sort_by_active), {controller: 'contests', action: 'index' ,:contest_sort_type => '0'}, :class=>"selected"), :class=>"selected") - - when 1 - content << content_tag('li', link_to(l(:label_sort_by_time), {controller: 'contests', action: 'index' ,:contest_sort_type => '1'}, :class=>"selected"), :class=>"selected") - content << content_tag('li', link_to(l(:label_sort_by_active), {controller: 'contests', action: 'index' ,:contest_sort_type => '0'})) - end - content = content_tag('ul', content) - content_tag('div', content, :class => "tabs") - end - #end - - # def course_options_for_select(courses) - # # - # html = '' - # courses.each do |course| - # html << "" - # end - # html.html_safe - # end - - - # used to get the reward and handle the value which can be used to display in views - # added by william - def get_prize(c_project) - c_project.get_reward - end - - def get_prize(c_softapplication) - c_softapplication.get_reward - end - - def count_contest_project - contests = Contest.find(:id) - @projects = [] - # Modified by longjun - # for contest in contests - contests.each do |contest| - # end longjun - @projects += contest.contesting_projects - end - @projects.count - end - - def count_contest_softapplication - contests = Contest.find(:id) - @softapplications = [] - # Modified by alan - # for contest in contests - contests.each do |contest| - # end alan - @softapplications += contest.contesting_softapplications - end - @projects.count - end - - - def count_contest_user - contests = Contest.find(:id) - @users = [] - # Modified by alan - # for contest in contests - contests.each do |contest| - - contest.projects.each do |project| - - @users += project.users - end - end - # end alan - - @users.count - end - - def count_contest_softapplication_user - contests = Contest.find(:id) - @users = [] - # Modified by alan - # for contest in contests - contests.each do |contest| - - contest.projects.each do |softapplications| - # for project in contest.softapplications - @users += softapplication.users - end - end - @users.count - end - def im_watching_student_id? contest - people = [] - people << contest.author - # case bid.reward_type # 天煞的bid分了三用途,里面各种hasmany还不定能用! - # when 1 - # when 2 - # bid.join_in_contests.each do |jic| - # people << jic.user - # end - # when 3 - # people += bid.courses.first.users.to_a - # else - # raise 'bids_helper: unknow bid type' # 出了错看这里!不知道的抛异常,省的找不到出错的地方! - # end - - contest.join_in_contests.each do |jic| - people << jic.user - end - people.include?(User.current) - end - - # def select_option_helper option - # tmp = Hash.new - # tmp={"" => ""} - # option.each do |project| - # tmp[project.name] = project.identifier - # end - # tmp - # end - def select_option_app_helper options - tmp = Hash.new - options.each do |option| - tmp[option.name] = option.id - end - tmp - end - - #作品分类下拉框 - def work_type_opttion - type = [] - #work_types = WorksCategory.all - WorksCategory.all.each do |work_type| - option = [] - option << work_type.category - option << work_type.category - type << option - end - type - end - -end \ No newline at end of file +end diff --git a/app/helpers/works_helper.rb b/app/helpers/works_helper.rb new file mode 100644 index 000000000..ccb78c2b7 --- /dev/null +++ b/app/helpers/works_helper.rb @@ -0,0 +1,2 @@ +module WorksHelper +end diff --git a/app/models/contest.rb b/app/models/contest.rb index 4fbd5441e..c540de4d6 100644 --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -1,136 +1,87 @@ -class Contest < ActiveRecord::Base - attr_accessible :author_id, :budget, :commit, :deadline, :description, :name, :password - include Redmine::SafeAttributes - - belongs_to :author, :class_name => 'User', :foreign_key => :author_id - has_many :contesting_projects, :dependent => :destroy - has_many :projects, :through => :contesting_projects - has_many :contesting_softapplications, :dependent => :destroy - has_many :softapplications, :through => :contesting_softapplications, :dependent => :destroy - has_many :projects_member, :class_name => 'User', :through => :projects - has_many :journals_for_messages, :as => :jour, :dependent => :destroy - has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy - 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_one :praise_tread_cache, as: :object, dependent: :destroy - has_many :contestnotifications, :dependent => :destroy, :include => :author - - - - - acts_as_attachable - - NAME_LENGTH_LIMIT = 60 - DESCRIPTION_LENGTH_LIMIT = 250 - validates :name, length: {maximum: NAME_LENGTH_LIMIT}, presence: true - validates :description, length: {maximum: DESCRIPTION_LENGTH_LIMIT} - validates :author_id, presence: true - validates :budget, presence: true - validates :deadline, format: {:with =>/^[1-9][0-9]{3}\-0?[1-9]|1[12]\-0?[1-9]|[12]\d|3[01]$/} - validate :validate_user - after_create :act_as_activity - - scope :visible, lambda {|*args| - nil - } - - scope :like, lambda {|arg| - if arg.blank? - where(nil) - else - pattern = "%#{arg.to_s.strip.downcase}%" - where("LOWER(id) LIKE :p OR LOWER(name) LIKE :p OR LOWER(description) LIKE :p", :p => pattern) - end - } - - acts_as_watchable - acts_as_taggable - - acts_as_event :title => Proc.new {|o| "#{l(:label_requirement)} ##{o.id}: #{o.name}" }, - :description => :description, - :author => :author, - :url => Proc.new {|o| {:controller => 'contests', :action => 'show_contest', :id => o.id}} - - acts_as_activity_provider :find_options => {:include => [:projects, :author]}, - :author_key => :author_id - - safe_attributes 'name', - 'description', - 'budget', - 'deadline', - 'password' - - - def add_jour(user, notes, reference_user_id = 0, options = {}) - if options.count == 0 - self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id) - else - jfm = self.journals_for_messages.build(options) - jfm.save - jfm - end - end - - # modified by longjun - # 这个函数没有用到 - # def self.creat_contests(budget, deadline, name, description=nil) - # self.create(:author_id => User.current.id, :budget => budget, - # :deadline => deadline, :name => name, :description => description, :commit => 0) - # end - # end longjun - - def update_contests(budget, deadline, name, description=nil) - if(User.current.id == self.author_id) - self.name = name - self.budget = budget - self.deadline = deadline - self.description = description - self.save - end - end - - def delete_contests - unless self.nil? - if User.current.id == self.author_id - self.destroy - end - 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 - - private - - def validate_user - errors.add :author_id, :invalid if author.nil? || !author.active? - end - - - def act_as_activity - self.acts << Activity.new(:user_id => self.author_id) - end - - def validate_contest_manager(user_id) - unless user_id.nil? - if self.author_id == user_id - return true - else - return false - end - end - end -end +class Contest < ActiveRecord::Base + attr_accessible :description, :invite_code, :invite_code_halt, :is_delete, :is_public, :name, :user_id, :visits + + belongs_to :user + has_many :contest_members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}" + has_many :memberships, :class_name => 'ContestMember' + has_many :member_principals, :class_name => 'ContestMember', + :include => :principal, + :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})" + has_many :principals, :through => :member_principals, :source => :principal + has_many :users, :through => :members + has_many :contestants, :class_name => 'ContestantForContest', :source => :user + + has_many :contest_acts, :class_name => 'ContestActivity',:as =>:contest_act ,:dependent => :destroy + has_many :contest_activities + has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy + + validates_format_of :name,:with =>/^[^ ]+[a-zA-Z0-9_\u4e00-\u9fa5\s\S]*$/ + + before_destroy :delete_all_members + after_create :act_as_course_activity + + scope :visible, lambda {|*args| where(Contest.where("is_delete =?", 0).visible_condition(args.shift || User.current, *args)) } + + # 删除竞赛所有成员 + def delete_all_members + if self.contest_members && self.contest_members.count > 0 + me, mr = ContestMember.table_name, ContestMemberRole.table_name + connection.delete("DELETE FROM #{mr} WHERE #{mr}.contest_member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.contest_id = #{id})") + ContestMember.delete_all(['contest_id = ?', id]) + end + end + + def self.visible_condition(user, options={}) + allowed_to_condition(user, :view_course, options) + end + + def self.allowed_to_condition(user, permission, options={}) + perm = Redmine::AccessControl.permission(permission) + base_statement = ("#{Contest.table_name}.is_delete <> 1") + if perm && perm.contest_module + base_statement << " AND #{Contest.table_name}.id IN (SELECT em.contest_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.contest_module}')" + end + + if options[:contest] + contest_statement = "#{Contest.table_name}.id = #{options[:contest].id}" + contest_statement << " OR (#{Contest.table_name}.lft > #{options[:contest].lft} AND #{Contest.table_name}.rgt < #{options[:contest].rgt})" if options[:with_subcontests] + base_statement = "(#{contest_statement}) AND (#{base_statement})" + end + + if user.admin? + base_statement + else + statement_by_role = {} + unless options[:contest_member] + role = user.logged? ? Role.non_member : Role.anonymous + if role.allowed_to?(permission) + statement_by_role[role] = "#{Contest.table_name}.is_public = #{connection.quoted_true}" + end + end + if user.logged? + user.contests_by_role.each do |role, contests| + if role.allowed_to?(permission) && contests.any? + statement_by_role[role] = "#{Contest.table_name}.id IN (#{contests.collect(&:id).join(',')})" + end + end + end + if statement_by_role.empty? + "1=0" + else + if block_given? + statement_by_role.each do |role, statement| + if s = yield(role, user) + statement_by_role[role] = "(#{statement} AND (#{s}))" + end + end + end + "((#{base_statement}) AND (#{statement_by_role.values.join(' OR ')}))" + end + end + end + + # 竞赛动态公共表记录 + def act_as_contest_activity + self.contest_acts << ContestActivity.new(:user_id => self.user_id,:contest_id => self.id) + end +end diff --git a/app/models/contest_activity.rb b/app/models/contest_activity.rb new file mode 100644 index 000000000..07a8f2a0e --- /dev/null +++ b/app/models/contest_activity.rb @@ -0,0 +1,37 @@ +class ContestActivity < ActiveRecord::Base + attr_accessible :contest_act_id, :contest_act_type + + belongs_to :user + belongs_to :contest + belongs_to :contest_act ,:polymorphic => true + has_many :user_acts, :class_name => 'UserAcivity',:as =>:act + after_create :add_user_activity + before_destroy :destroy_user_activity + + #在个人动态里面增加当前动态 + def add_user_activity + user_activity = UserActivity.where("act_type = '#{self.contest_act_type.to_s}' and act_id = '#{self.contest_act_id}'").first + if user_activity + user_activity.save + else + if self.contest_act_type == 'Message' && !self.contest_act.parent_id.nil? + user_activity = UserActivity.where("act_type = 'Message' and act_id = #{self.contest_act.parent.id}").first + user_activity.created_at = self.created_at + user_activity.save + else + user_activity = UserActivity.new + user_activity.act_id = self.contest_act_id + user_activity.act_type = self.contest_act_type + user_activity.container_type = "Contest" + user_activity.container_id = self.contest_id + user_activity.user_id = self.user_id + user_activity.save + end + end + end + + def destroy_user_activity + user_activity = UserActivity.where("act_type = '#{self.contest_act_type.to_s}' and act_id = '#{self.contest_act_id}'") + user_activity.destroy_all + end +end diff --git a/app/models/contest_member.rb b/app/models/contest_member.rb new file mode 100644 index 000000000..269a308ed --- /dev/null +++ b/app/models/contest_member.rb @@ -0,0 +1,19 @@ +class ContestMember < ActiveRecord::Base + belongs_to :user + belongs_to :contest + attr_accessible :is_collect, :is_current + + belongs_to :principal, :foreign_key => 'user_id' + has_many :contest_member_roles, :dependent => :destroy + has_many :roles, :through => :contest_member_roles + + validates_presence_of :principal + validates_uniqueness_of :user_id, :scope => [:contest_id] + validate :validate_role + + protected + + def validate_role + errors.add_on_empty :role if contest_member_roles.empty? && roles.empty? + end +end diff --git a/app/models/contest_member_role.rb b/app/models/contest_member_role.rb new file mode 100644 index 000000000..f8d4b5b39 --- /dev/null +++ b/app/models/contest_member_role.rb @@ -0,0 +1,22 @@ +class ContestMemberRole < ActiveRecord::Base + belongs_to :contest_member + belongs_to :role + # attr_accessible :title, :body + + after_destroy :remove_member_if_empty + + validates_presence_of :role + validate :validate_role_member + + def validate_role_member + errors.add :role_id, :invalid if role && !role.member? + end + + private + + def remove_member_if_empty + if contest_member.roles.empty? + contest_member.destroy + end + end +end diff --git a/app/models/contest_message.rb b/app/models/contest_message.rb new file mode 100644 index 000000000..82fa17050 --- /dev/null +++ b/app/models/contest_message.rb @@ -0,0 +1,20 @@ +class ContestMessage < ActiveRecord::Base + attr_accessible :content, :contest_message_id, :course_message_type, :status, :viewed + + belongs_to :contest_message ,:polymorphic => true + belongs_to :user + belongs_to :contest + has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy + + validates :user_id, presence: true + validates :contest_id, presence: true + validates :contest_message_id, presence: true + validates :contest_message_type, presence: true + after_create :add_user_message + + def add_user_message + if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil? && self.status != 9 + self.message_alls << MessageAll.new(:user_id => self.user_id) + end + end +end diff --git a/app/models/contest_notification.rb b/app/models/contest_notification.rb deleted file mode 100644 index 71c448f65..000000000 --- a/app/models/contest_notification.rb +++ /dev/null @@ -1,6 +0,0 @@ -class ContestNotification < ActiveRecord::Base - attr_accessible :content, :title - validates :title, length: {maximum: 30} - - -end diff --git a/app/models/contestant_for_contest.rb b/app/models/contestant_for_contest.rb new file mode 100644 index 000000000..f2cbcfbc0 --- /dev/null +++ b/app/models/contestant_for_contest.rb @@ -0,0 +1,8 @@ +class ContestantForContest < ActiveRecord::Base + belongs_to :contest + attr_accessible :student_id, :contest_id + + belongs_to :contestants, :class_name => 'User', :foreign_key => :student_id + validates_presence_of :contest_id, :student_id + validates_uniqueness_of :student_id, :scope => :course_id +end diff --git a/app/models/contestant_work.rb b/app/models/contestant_work.rb new file mode 100644 index 000000000..1922391b9 --- /dev/null +++ b/app/models/contestant_work.rb @@ -0,0 +1,20 @@ +class ContestantWork < ActiveRecord::Base + belongs_to :work + belongs_to :user + belongs_to :project + attr_accessible :commit_time, :description, :is_delete, :name, :work_score, :work_status + + has_many :contestant_work_projects, :dependent => :destroy + has_many :contestant_work_scores, :dependent => :destroy + has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy + has_many :attachments, :dependent => :destroy + + after_create :act_as_message + acts_as_attachable + + def act_as_message + if self.work_status != 0 && self.created_at > self.work.end_time + 1 + self.contest_messages << ContestMessage.new(:user_id => self.user_id, :contest_id => self.work.contest_id, :viewed => false, :status => false) + end + end +end diff --git a/app/models/contestant_work_project.rb b/app/models/contestant_work_project.rb new file mode 100644 index 000000000..5142ddaad --- /dev/null +++ b/app/models/contestant_work_project.rb @@ -0,0 +1,8 @@ +class ContestantWorkProject < ActiveRecord::Base + belongs_to :contest + belongs_to :work + belongs_to :contestant_work + belongs_to :project + belongs_to :user + attr_accessible :is_leader +end diff --git a/app/models/contestant_work_score.rb b/app/models/contestant_work_score.rb new file mode 100644 index 000000000..8b1d2aefd --- /dev/null +++ b/app/models/contestant_work_score.rb @@ -0,0 +1,5 @@ +class ContestantWorkScore < ActiveRecord::Base + belongs_to :contestant_work + belongs_to :user + attr_accessible :comment, :reviewer_role, :score +end diff --git a/app/models/contesting_project.rb b/app/models/contesting_project.rb deleted file mode 100644 index ced787cbd..000000000 --- a/app/models/contesting_project.rb +++ /dev/null @@ -1,53 +0,0 @@ -class ContestingProject < ActiveRecord::Base - attr_accessible :contest_id, :description, :project_id, :user_id, :reward - - belongs_to :contest - belongs_to :project - belongs_to :user - - DESCRIPTION_LENGTH_LIMIT = 500 - validates :description, length: {maximum:DESCRIPTION_LENGTH_LIMIT } - validates :user_id, presence: true - validates :contest_id, presence: true, uniqueness: {scope: :project_id} - validates :project_id, presence: true - - validate :validate_user - validate :validate_contest - validate :validate_project - - def self.create_contesting(contest_id, project_id, description = nil) - self.create(:user_id => User.current.id, :contest_id => contest_id, - :project_id => project_id, :description => description) - end - - - def update_reward(which) - self.update_attribute(:reward,which) - end - - def get_reward - self.reward - end - - def cancel_contesting - unless self.nil? - if User.current.id == self.user_id - self.destroy - end - end - end - - private - - def validate_user - errors.add :user_id, :invalid if user.nil? || !user.active? - end - - def validate_contest - errors.add :contest_id, :invalid if contest.nil? - end - - def validate_project - errors.add :project_id, :invalid if project.nil? - end -end diff --git a/app/models/contesting_softapplication.rb b/app/models/contesting_softapplication.rb deleted file mode 100644 index f91c16f69..000000000 --- a/app/models/contesting_softapplication.rb +++ /dev/null @@ -1,28 +0,0 @@ - -class ContestingSoftapplication < ActiveRecord::Base - attr_accessible :contest_id, :description, :softapplication_id, :user_id - - belongs_to :contest - belongs_to :softapplication, :dependent => :destroy - belongs_to :user - - - def self.create_softapplication_contesting(contest_id, softapplication_id, description = nil) - self.create(:user_id => User.current.id, :contest_id => contest_id, - :softapplication_id => softapplication_id, :description => description) - end - - def self.create_work_contesting(contest_id, softapplication_id) - self.create(:user_id => User.current.id, :contest_id => contest_id, - :softapplication_id => softapplication_id) - end - - def update_reward(which) - self.update_attribute(:reward,which) - end - - def get_reward - self.reward - end - -end diff --git a/app/models/contestnotification.rb b/app/models/contestnotification.rb deleted file mode 100644 index fff861ab4..000000000 --- a/app/models/contestnotification.rb +++ /dev/null @@ -1,59 +0,0 @@ -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 :title, length: {maximum: 60}, presence: true - validates :description, presence: true - validates :summary, length: {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/journals_for_message.rb b/app/models/journals_for_message.rb index 58c597061..a80d9b425 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -64,8 +64,11 @@ class JournalsForMessage < ActiveRecord::Base has_many :principal_acts, :class_name => 'PrincipalActivity',:as =>:principal_act ,:dependent => :destroy # 课程动态 has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy + # 竞赛动态 + has_many :contest_acts, :class_name => 'ContestActivity',:as =>:contest_act ,:dependent => :destroy # 消息关联 has_many :course_messages, :class_name => 'CourseMessage',:as =>:course_message ,:dependent => :destroy + has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy has_many :user_feedback_messages, :class_name => 'UserFeedbackMessage', :as =>:journals_for_message, :dependent => :destroy has_many :at_messages, as: :at_message, dependent: :destroy diff --git a/app/models/message.rb b/app/models/message.rb index 5366724eb..7a43836a8 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -40,11 +40,13 @@ class Message < ActiveRecord::Base has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy # 课程动态 has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy - + # 竞赛动态 + has_many :contest_acts, :class_name => 'ContestActivity',:as =>:contest_act ,:dependent => :destroy # end # 课程/项目 消息 has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy + has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy has_many :at_messages, as: :at_message, dependent: :destroy has_many :ActivityNotifies,:as => :activity, :dependent => :destroy diff --git a/app/models/news.rb b/app/models/news.rb index c436724fd..d42565980 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -34,10 +34,13 @@ class News < ActiveRecord::Base has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy # 课程动态 has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy + # 竞赛动态 + has_many :contest_acts, :class_name => 'ContestActivity',:as =>:contest_act ,:dependent => :destroy # end - # 课程/项目消息关联 + # 课程/项目/竞赛消息关联 has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy + has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy #end has_many :praise_tread, as: :praise_tread_object, dependent: :destroy diff --git a/app/models/principal.rb b/app/models/principal.rb index 7c2b24587..155e2144b 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -34,6 +34,10 @@ class Principal < ActiveRecord::Base has_many :course_groups, :through => :members has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify + has_many :contest_members, :foreign_key => 'user_id', :dependent => :destroy + has_many :contestmemberships, :class_name => 'ContestMember', :foreign_key => 'user_id', :include => [:contest, :roles], :conditions => "#{Contest.table_name}.is_delete != 0", :order => "#{Contest.table_name}.name" + has_many :contests, :through => :contestmemberships + # Groups and active users scope :active, lambda { where(:status => STATUS_ACTIVE) } @@ -157,6 +161,14 @@ class Principal < ActiveRecord::Base return projects end + #收藏的竞赛 + def favorite_contests + members = ContestMember.where(:user_id => self.id, :is_collect => true) + contest_ids = members.empty? ? "(-1)" : "(" + members.map{|member| member.contest_id}.join(",") + ")" + contests = Contest.where("id in #{contest_ids}") + return contests + end + protected # Make sure we don't try to insert NULL values (see #4632) diff --git a/app/models/role.rb b/app/models/role.rb index f6a24a27f..233a54531 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -57,6 +57,8 @@ class Role < ActiveRecord::Base has_many :members, :through => :member_roles has_many :org_member_roles, :dependent => :destroy has_many :org_members,:through => :org_member_roles + has_many :contest_member_roles, :dependent => :destroy + has_many :contest_members, :through => :contest_member_roles acts_as_list serialize :permissions, ::Role::PermissionsAttributeCoder diff --git a/app/models/user.rb b/app/models/user.rb index 6cf58be14..d7631bf07 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -130,7 +130,6 @@ class User < Principal belongs_to :ucourse, :class_name => 'Course', :foreign_key => :id #huang ## added by xianbo for delete # has_many :biding_projects, :dependent => :destroy - has_many :contesting_projects, :dependent => :destroy belongs_to :softapplication, :foreign_key => 'id', :dependent => :destroy ##ended by xianbo @@ -138,12 +137,12 @@ class User < Principal has_many :jours, :class_name => 'JournalsForMessage', :dependent => :destroy has_many :journals_messages, :class_name => 'JournalsForMessage', :foreign_key => "user_id", :dependent => :destroy # has_many :bids, :foreign_key => 'author_id', :dependent => :destroy - has_many :contests, :foreign_key => 'author_id', :dependent => :destroy has_many :softapplications, :foreign_key => 'user_id', :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :journal_replies, :dependent => :destroy has_many :activities, :dependent => :destroy has_many :students_for_courses + has_many :contestant_for_contests #has_many :courses, :through => :students_for_courses, :source => :project has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy has_many :principal_acts, :class_name => 'PrincipalActivity',:as =>:principal_act ,:dependent => :destroy @@ -151,11 +150,8 @@ class User < Principal has_many :course_attachments , :class_name => 'Attachment', :foreign_key => 'author_id', :conditions => "container_type = 'Course'" #### # 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' @@ -501,6 +497,7 @@ class User < Principal @name = nil @projects_by_role = nil @courses_by_role = nil + @contests_by_role = nil @membership_by_project_id = nil base_reload(*args) end @@ -884,6 +881,10 @@ class User < Principal courses.to_a.include?(course) end + def member_of_contest?(contest) + contests.to_a.include?(contest) + end + def member_of_org?(org) if !self.logged? return false @@ -912,6 +913,49 @@ class User < Principal false end end + + # 判断是否是竞赛的主办人 + def admin_of_contest?(contest) + if self.admin? + return true + end + if ContestMember.where("user_id =? and contest_id =?", self.id, contest.id).count == 0 + return false + end + role = ContestMember.where("user_id =? and contest_id =?", self.id, contest.id)[0].roles[0] + unless role.nil? + role.name == 'ContestManager' ? true : false + else + false + end + end + + # 判断是否是竞赛的评委 + def judge_of_contest?(contest) + if ContestMember.where("user_id =? and contest_id =?", self.id, contest.id).count == 0 + return false + end + role = ContestMember.where("user_id =? and contest_id =?", self.id, contest.id)[0].roles[0] + unless role.nil? + role.name == 'Judge' ? true : false + else + false + end + end + + # 判断是否是竞赛的参赛者 + def judge_of_contest?(contest) + if ContestMember.where("user_id =? and contest_id =?", self.id, contest.id).count == 0 + return false + end + role = ContestMember.where("user_id =? and contest_id =?", self.id, contest.id)[0].roles[0] + unless role.nil? + role.name == 'Contestant' ? true : false + else + false + end + end + def member_of_course_group?(course_group) course_groups.to_a.include?(course_group) end @@ -954,6 +998,26 @@ class User < Principal @courses_by_role end + + # 竞赛的角色权限 + def contests_by_role + return @contests_by_role if @contests_by_role + + @contests_by_role = Hash.new([]) + contestmemberships.each do |membership| + if membership.contest + membership.roles.each do |role| + @contests_by_role[role] = [] unless @contests_by_role.key?(role) + @contests_by_role[role] << membership.contest + end + end + end + @contests_by_role.each do |role, contests| + contests.uniq! + end + + @contests_by_role + end # Returns true if user is arg or belongs to arg def is_or_belongs_to?(arg) if arg.is_a?(User) diff --git a/app/models/work.rb b/app/models/work.rb new file mode 100644 index 000000000..2dd007d6c --- /dev/null +++ b/app/models/work.rb @@ -0,0 +1,66 @@ +class Work < ActiveRecord::Base + belongs_to :user + belongs_to :contest + attr_accessible :description, :end_time, :is_delete, :is_open, :name, :publish_time, :score_open, :work_status, :work_type + + has_one :work_detail_group, :dependent => :destroy + has_many :contestant_work_projects, :dependent => :destroy + has_many :contestant_works, :dependent => :destroy, :conditions => "is_delete != 1" + has_many :journals_for_messages, :as => :jour, :dependent => :destroy + has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy + # 竞赛动态 + has_many :contest_acts, :class_name => 'ContestActivity',:as =>:contest_act ,:dependent => :destroy + # 竞赛消息 + has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy + acts_as_attachable + + after_create :act_as_contest_message + after_update :update_activity + after_save :act_as_contest_activity + #after_destroy :delete_kindeditor_assets + + ###添加回复 + def self.add_work_jour(user, notes, id, root_id, options = {}) + homework = Work.find(id) + if options.count == 0 + jfm = homework.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0, :root_id => root_id) + else + jfm = homework.journals_for_messages.build(options) + end + jfm.save + jfm + end + + def act_as_contest_activity + if self.contest + if self.work_status == 0 + self.contest_acts.destroy_all + else + if self.contest_acts.size == 0 + self.contest_acts << ContestActivity.new(:user_id => self.user_id,:contest_id => self.contest_id) + end + end + end + end + + #动态的更新 + def update_activity + update_contest_activity(self.class, self.id) + update_user_activity(self.class, self.id) + end + + def act_as_contest_message + if self.contest + if self.work_status == 0 + self.contest_messages.destroy_all + else + self.contest.contest_members.each do |m| + if m.user_id != self.user_id + self.contest_messages << ContestMessage.new(:user_id => m.user_id, :contest_id => self.contest_id, :viewed => false) + end + end + end + end + end +end diff --git a/app/models/work_detail_group.rb b/app/models/work_detail_group.rb new file mode 100644 index 000000000..b51103790 --- /dev/null +++ b/app/models/work_detail_group.rb @@ -0,0 +1,4 @@ +class WorkDetailGroup < ActiveRecord::Base + belongs_to :work + attr_accessible :base_on_project, :max_num, :min_num +end diff --git a/app/views/contestant_works/_relate_project.html.erb b/app/views/contestant_works/_relate_project.html.erb new file mode 100644 index 000000000..75298a62d --- /dev/null +++ b/app/views/contestant_works/_relate_project.html.erb @@ -0,0 +1,63 @@ +
+
+

关联项目

+ +
+
+
+ <%= form_for('new_form',:url =>{:controller => 'contestant_work',:action => 'student_work_project',:work => @contestantwork.id,:user_activity_id=>@user_activity_id,:hw_status =>@hw_status},:method => "post", :remote => true) do |f|%> + +
+ + +

+ 确定 + 取消 +
+ <% end %> +
+
+ \ No newline at end of file diff --git a/app/views/contestant_works/cancel_relate_project.js.erb b/app/views/contestant_works/cancel_relate_project.js.erb new file mode 100644 index 000000000..c65034689 --- /dev/null +++ b/app/views/contestant_works/cancel_relate_project.js.erb @@ -0,0 +1,10 @@ +<% if @hw_status == 5 %> +$("#homework_post_brief").html("<%= escape_javascript(render :partial => 'student_work/homework_post_brief', :locals => {:homework => @homework, :is_teacher => @is_teacher}) %>"); +<% else %> +$("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/course_homework', :locals => {:activity => @homework,:user_activity_id =>@user_activity_id,:hw_status=>@hw_status}) %>"); +<% end %> +<% if @user_activity_id != @homework.id %> +sd_create_editor_from_data(<%= @user_activity_id%>,"","100%", "UserActivity"); +<% else %> +sd_create_editor_from_data(<%= @homework.id%>,"","100%", "<%=@homework.class.to_s%>"); +<% end %> \ No newline at end of file diff --git a/app/views/contestant_works/new_student_work_project.js.erb b/app/views/contestant_works/new_student_work_project.js.erb new file mode 100644 index 000000000..83ef3d89a --- /dev/null +++ b/app/views/contestant_works/new_student_work_project.js.erb @@ -0,0 +1,2 @@ +var htmlvalue = "<%= escape_javascript(render :partial => 'student_work/relate_project') %>"; +pop_box_new(htmlvalue, 400, 285); \ No newline at end of file diff --git a/app/views/contestant_works/student_work_project.js.erb b/app/views/contestant_works/student_work_project.js.erb new file mode 100644 index 000000000..80a508612 --- /dev/null +++ b/app/views/contestant_works/student_work_project.js.erb @@ -0,0 +1,11 @@ +hideModal("#popbox02"); +<% if @hw_status == 5 %> +$("#homework_post_brief").html("<%= escape_javascript(render :partial => 'student_work/homework_post_brief', :locals => {:homework => @homework, :is_teacher => @is_teacher}) %>"); +<% else %> +$("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/course_homework', :locals => {:activity => @homework,:user_activity_id =>@user_activity_id,:hw_status=>@hw_status}) %>"); +<% end %> +<% if @user_activity_id != @homework.id %> +sd_create_editor_from_data(<%= @user_activity_id%>,"","100%", "UserActivity"); +<% else %> +sd_create_editor_from_data(<%= @homework.id%>,"","100%", "<%=@homework.class.to_s%>"); +<% end %> \ No newline at end of file diff --git a/app/views/contestnotifications/_form.html.erb b/app/views/contestnotifications/_form.html.erb deleted file mode 100644 index 680ab93d1..000000000 --- a/app/views/contestnotifications/_form.html.erb +++ /dev/null @@ -1,77 +0,0 @@ -<%= error_messages_for @contestnotifications %> - -
-

- <%= f.text_field :title, - :required => true, - :size => 60, - :maxlength => 60, - :style => "width:488px;", - :onkeyup => "regexTitle();" - %> -

- -

- <%= f.text_area :description, - :required => true, - :cols => 60, - :rows => 11, - :class => 'wiki-edit', - :style => "width:490px;", - :onkeyup => "regexDescription();" - %> -

- -
- -<%= wikitoolbar_for 'news_description' %> diff --git a/app/views/contestnotifications/_news.html.erb b/app/views/contestnotifications/_news.html.erb deleted file mode 100644 index c8af85cf4..000000000 --- a/app/views/contestnotifications/_news.html.erb +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - -
- - - - - - - - - - - - -
- - <%=link_to contestnotifications.author, - contest_contestnotification_path(contestnotifications) - %> - - - <%= l(:label_project_newshare) %> - - <%= link_to h(contestnotifications.title), - contest_contestnotification_path(contestnotifications) - %> -
-

- <%=h contestnotifications.description%> -

-
- - <%= contestnotifications.created_at %> - - - <%= link_to l(:label_project_newother), - contest_contestnotification_path(contestnotifications) - %> - <%= "(#{l(:label_x_comments, :count => contestnotifications.notificationcomments_count)})" if contestnotifications.notificationcomments_count > 0 %> -
diff --git a/app/views/contestnotifications/edit.html.erb b/app/views/contestnotifications/edit.html.erb deleted file mode 100644 index 53536aaaf..000000000 --- a/app/views/contestnotifications/edit.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -

<%=l(:label_edit_contest_notice)%>

- -<%= labelled_form_for @contestnotification, - :url => contest_contestnotification_path, - :html => { :id => 'contestnotifications-form', - :multipart => true, - :method => :put } do |f| %> -<%= render :partial => 'form', :locals => { :f => f } %> -<%= submit_tag l(:button_save) %> -<%#= preview_link preview_contestnotifications_path(id: @contestnotification), - 'contestnotifications-form' -%> -<% end %> -
- -<% content_for :header_tags do %> - <%= stylesheet_link_tag 'scm' %> -<% end %> \ No newline at end of file diff --git a/app/views/contestnotifications/index.api.rsb b/app/views/contestnotifications/index.api.rsb deleted file mode 100644 index 6509d2915..000000000 --- a/app/views/contestnotifications/index.api.rsb +++ /dev/null @@ -1,14 +0,0 @@ -api.array :contestnotifications, api_meta(:total_count => @contestnotifications_count, :offset => @offset, :limit => @limit) do - @contestnotificationss.each do |contestnotifications| - api.contestnotifications do - api.id contestnotifications.id - api.contest(:id => contestnotifications.contest_id, :name => contestnotifications.contest.name) unless contestnotifications.contest.nil? - api.author(:id => contestnotifications.author_id, :name => contestnotifications.author.name) unless contestnotifications.author.nil? - - api.title contestnotifications.title - api.summary contestnotifications.summary - api.description contestnotifications.description - api.created_at contestnotifications.created_at - end - end -end diff --git a/app/views/contestnotifications/index.html.erb b/app/views/contestnotifications/index.html.erb deleted file mode 100644 index cf7ebe508..000000000 --- a/app/views/contestnotifications/index.html.erb +++ /dev/null @@ -1,151 +0,0 @@ - - - - <%= l(:label_notification) %> - -<% if User.current.logged? && (User.current.admin? ||User.current == @contest.author) %> - <%= link_to(l(:bale_news_notice), - new_contest_contestnotification_path(@contest), - :class => 'icon icon-add', - :onclick => 'showAndScrollTo("add-contestnotifications", "contestnotifications_title"); return false;') %> -<% end %> -<% if @contest %> - -
-<% end %> -
- -
- - <%= image_tag(url_to_avatar(@contest.author), :class => "avatar")%> - - - - <%= render :partial => "/praise_tread/praise_tread", - :locals => {:obj => @contest, - :show_flag => true, - :user_id =>User.current.id, - :horizontal => false} - %> - -

- <%= link_to(@contest.author.lastname+@contest.author.firstname, - user_path(@contest.author))%> - :<%= @contest.name %> -

-

- - <%= l(:label_bids_reward_method) %> - - <%= @contest.budget%> - - -

-
- <%= @contest.description %> -
-
-
- -
- -

- <% @contestnotificationss.each do |contestnotifications| %> - - - - - -
- <%= link_to image_tag(url_to_avatar(contestnotifications.author), :class => "avatar"), user_path(contestnotifications.author) %> - - - - - - - - - - - - - -
- - <%= link_to_user(contestnotifications.author) if contestnotifications.respond_to?(:author) %> - - - <%= l(:label_project_notice) %> - - - <%= link_to h(contestnotifications.title), contest_contestnotification_path(@contest, contestnotifications) %> - - - <%= link_to l(:button_edit), edit_contest_contestnotification_path(@contest, contestnotifications) if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?) %> - <%= delete_link contest_contestnotification_path(@contest, contestnotifications) if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?) %> - -
- - <%= textilizable(contestnotifications, :description) %> - -
- <%= l :label_update_time %> -   - <%= format_time(contestnotifications.created_at) %> - - - <%= link_to l(:label_check_comment), contest_contestnotification_path(@contest, contestnotifications) %> -
-
- <% end %> - -
- -
- - - <% content_for :header_tags do %> - <%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :page => nil, :key => User.current.rss_key})) %> - <%= stylesheet_link_tag 'scm' %> - <% end %> - - <% html_title(l(:label_contest_notification)) -%> -
- - - - \ No newline at end of file diff --git a/app/views/contestnotifications/new.html.erb b/app/views/contestnotifications/new.html.erb deleted file mode 100644 index 310a68d77..000000000 --- a/app/views/contestnotifications/new.html.erb +++ /dev/null @@ -1,17 +0,0 @@ - -<%= labelled_form_for @contestnotification, - :url => contest_contestnotifications_path(@contest), - :html => { :id => 'contestnotifications-form', :multipart => true } do |f| %> - <%= render :partial => 'contestnotifications/form', :locals => { :f => f } %> - - <%= link_to l(:button_cancel), contest_contestnotifications_path(@contest.id) %> -<% end %> -
diff --git a/app/views/contestnotifications/show.html.erb b/app/views/contestnotifications/show.html.erb deleted file mode 100644 index 47cdd3a86..000000000 --- a/app/views/contestnotifications/show.html.erb +++ /dev/null @@ -1,144 +0,0 @@ - -
- <%= 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), - :name => nil, - :onclick => "cancel();", - :type => 'button', - :class => "enterprise", - :onmouseout => "this.style.backgroundPosition = 'left top'", - :onmouseover => "this.style.backgroundPosition = 'left -30px'" - %> -

- <% 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) %> - - <% if notificationcomment.author==User.current|| User.current.admin? %> - <%= link_to(l(:label_bid_respond_delete), - contest_contestnotification_notificationcomment_path(@contest, @contestnotification,notificationcomment), - :method => :delete,:confirm => l(:text_are_you_sure), :title => l(:button_delete)) %> - <% end %> -
-

- <%= 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/_contest_jours.html.erb b/app/views/contests/_contest_jours.html.erb deleted file mode 100644 index 54a7f14a7..000000000 --- a/app/views/contests/_contest_jours.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -
-
-

留言内容

- <%= render :partial => 'new', :locals => {:contest => @contest, :sta => @state} %> - - - -
-
- <%= render :partial => 'history',:locals => { :contest => @contest, :journals => @jour, :state => false} %> -
- - -
\ No newline at end of file diff --git a/app/views/contests/_contest_list.html.erb b/app/views/contests/_contest_list.html.erb deleted file mode 100644 index 26035aa29..000000000 --- a/app/views/contests/_contest_list.html.erb +++ /dev/null @@ -1,118 +0,0 @@ - -<% contests.each do |contest|%> - - - - - -
- <% unless contest.author.nil? %> - <%= link_to(image_tag(url_to_avatar(contest.author), :class => 'avatar'), - user_path(contest.author), - :class => "avatar") - %> - <% end %> - - - - - - - - - - - - -
- <% unless contest.author.nil? %> - <%= link_to(contest.author, - user_path(contest.author), - :class => 'bid_user') - %>: - <% end %> -  <%= link_to(contest.name, - contest_contestnotifications_path(contest), - :class => 'bid_path', - :target => "_blank") %>
- - - - - - - - - -
- <%= l(:label_contests_reward_method) %>:   - - <%= contest.budget%> - - -
- - - <% if contest.id == 2 || contest.id == 3 || contest.id == 6 %> - <%= l(:label_contest_work, - :count => contest.contesting_projects.count) - %> - ( - - <%= link_to(contest.projects.where('is_public=1').count, - show_attendingcontest_contest_path(contest), - :target => "_blank") - %> - - ) - <% else %> - <%= l(:label_contest_work, - :count => contest.contesting_softapplications.count) - %> - ( - - <%= link_to(contest.contesting_softapplications.count, - show_attendingcontest_contest_path(contest), - :target => "_blank") %> - - ) - <% end %> -
- - <%= l :label_create_time %>: <%= format_time contest.created_on %> - -
-
- - - - -
-
-
-<% end %> - - diff --git a/app/views/contests/_form_contest.html.erb b/app/views/contests/_form_contest.html.erb deleted file mode 100644 index 0b9f1469d..000000000 --- a/app/views/contests/_form_contest.html.erb +++ /dev/null @@ -1,76 +0,0 @@ - - -<%= error_messages_for 'contest' %> - -

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

-

- <%= f.text_field :name, - :required => true, - :size => 60, - :style => "width:490px;", - :maxlength => Contest::NAME_LENGTH_LIMIT, - :placeholder => "#{l(:label_contest_name)}" - %> -

- -

- <%= f.text_area :description, - :size => 60, - :rows => 4, - :style => "width:490px;", - :maxlength => Contest::DESCRIPTION_LENGTH_LIMIT, - :placeholder => "#{l(:label_contest_description)}" - %> -

- -

- <%= f.text_field :password, - :size => 60, - :rows => 4, - :style => "width:490px;" - %> -

- -

- <%= f.text_area :budget, - :required => true, - :size => 60, - :rows => 4, - :maxlength => Contest::DESCRIPTION_LENGTH_LIMIT, - :style => "width:490px;", - :placeholder => l(:label_bids_reward_what) - %> - - -

- -

- <%= f.text_field :deadline, - :required => true, - :size => 60, - :style => "width:150px;float:left;", - :readonly => true, - :placeholder => "#{l(:label_deadline)}" - %> - <%= calendar_for('contest_deadline')%> -

diff --git a/app/views/contests/_history.html.erb b/app/views/contests/_history.html.erb deleted file mode 100644 index 1115b81b0..000000000 --- a/app/views/contests/_history.html.erb +++ /dev/null @@ -1,63 +0,0 @@ -<% reply_allow = JournalsForMessage.create_by_user? User.current %> - -
-
- <% if journals.size > 0 %> - <% for journal in journals %> -
- -
-
- - <%= link_to journal.user, user_path(journal.user),:style => " font-weight:bold; color:#15bccf; margin-right:30px; background:none;", :target => "_blank"%><%= format_time(journal.created_on) %> -
-

<%= textilizable journal.notes%>

-
-
- <% ids = 'project_respond_form_'+ journal.id.to_s%> - - <% if journal.user == User.current|| User.current.admin? %> - <%= link_to(l(:label_bid_respond_delete), - {:controller => 'words', :action => 'destroy', :object_id => journal, :user_id => @user}, - :remote => true, :confirm => l(:text_are_you_sure), :method => 'delete', - :class => "delete", :title => l(:button_delete)) %> - <% end %> - <% if reply_allow %> - <%= link_to l(:label_bid_respond_quote),'', - {:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea')); $('##{ids} textarea') ;return false;"} %> - <%= link_to(l(:button_quote), contests_path(:id => contest, - :journal_id => journal), - :remote => true, - :method => 'post', - :title => l(:button_quote))%> - <% end %> - - - <%= l(:label_bids_published) %>  - <%= time_tag(journal.created_on).html_safe %>  - <%= l(:label_bids_published_ago) %> - -
-
- <% ids = 'project_respond_form_'+ journal.id.to_s%> - <% if reply_allow %> -
- <%= render :partial => 'words/new_respond', :locals => {:journal => journal, :m_reply_id => journal,:show_name => true} %> -
- <% end %> -
-
- <%= render :partial => "words/journal_reply", :locals => {:journal => journal, :show_name => true} %> -
-
-
-
- <% end %> - <% end %> -
-
- - - - - diff --git a/app/views/contests/_list_projects.html.erb b/app/views/contests/_list_projects.html.erb deleted file mode 100644 index 2ffecff12..000000000 --- a/app/views/contests/_list_projects.html.erb +++ /dev/null @@ -1,109 +0,0 @@ - -<% contesting_project.each do |c_project|%> - <% if c_project.project %> - - - - -
- - - - - - - -
-
- <%= image_tag(url_to_avatar(c_project.project), :class => 'avatar3') %> - -
- - - - - - - - - - - - - - - - - -
- - <%= link_to(c_project.project.name, project_path(c_project.project)) %> - - <%= l(:label_joined_contest)%> - - - - <%= l(:label_system_grade) %>: - <%= (c_project.project.project_status.nil? ? 0.0 : c_project.project.project_status.grade) unless (c_project.project.project_status.nil? && c_project.project.nil?) %> - <% if get_prize(c_project).nil? || get_prize(c_project) == "" %> - <% if @contest.deadline < Date.today %> - <%= l(:label_noawards)%> - <% end %> - <% else %> - - <% case get_prize(c_project) %> - <% when '-1' %> - <%= image_tag("/images/bid/special_reward.png")%> - <% when '0' %> - <%= image_tag("/images/bid/first_reward.png")%> - <% when '1' %> - <%= image_tag("/images/bid/second_reward.png")%> - <% when '2' %> - <%= image_tag("/images/bid/third_reward.png")%> - <% when '3' %> - <%= image_tag("/images/bid/forth_reward.png")%> - <% when '4' %> - <%= image_tag("/images/bid/fifth_reward.png")%> - <% when '5' %> - <%= image_tag("/images/bid/qualified.png")%> - <% end %> - <% end %> - - -
<%= c_project.project.description %>
- <%= format_time c_project.created_at%> -
-
-
- - - - - - - - -
- - <%= l(:label_contest_user) %> - <% unless c_project.user.nil? %> - - <%= link_to c_project.user.lastname + c_project.user.firstname, - user_path(c_project.user) - %> - <% end %> - - -
- <%= l(:label_contest_reason) %> - <%= c_project.description %> -
-
-
-
- <% end %> -<% end %> - - diff --git a/app/views/contests/_list_softapplications.html.erb b/app/views/contests/_list_softapplications.html.erb deleted file mode 100644 index 40a6f1cb2..000000000 --- a/app/views/contests/_list_softapplications.html.erb +++ /dev/null @@ -1,40 +0,0 @@ - -<% contesting_softapplication.each do |c_softapplication|%> - <% if c_softapplication.softapplication %> -
-
- - <%=l(:label_softapplication)%>: - - <%= link_to(c_softapplication.softapplication.name, - softapplication_path(c_softapplication.softapplication), - :target => '_blank') - %> - -
-
-
- - <%=l(:label_profile)%>: - - <%= c_softapplication.softapplication.description.truncate(90, omission: '...') %> - -
-
-
- - <%=l(:label_activity_time)%>: - - <%=format_time c_softapplication.created_at %> - - - -
-
- <% end %> -
-<% end %> - - diff --git a/app/views/contests/_new.html.erb b/app/views/contests/_new.html.erb deleted file mode 100644 index 2a88a7f46..000000000 --- a/app/views/contests/_new.html.erb +++ /dev/null @@ -1,36 +0,0 @@ - -
- <%= form_for('contest_message', - :remote => true, :method => :post, - :url => {:controller => 'contests', - :action => 'create', - :id => contest, - :sta => sta} - ) do |f|%> - -
- <%= render :partial => 'pre_show', :locals => {:content => @content} %> -
- - <% if User.current.logged? %> - - <%= f.text_area 'message', - :rows => 3, - :cols => 65, - :placeholder => l(:label_my_respond), - :style => "resize: none; width: 98%", - :class => 'noline', - :maxlength => 250 - %> - - <%= f.text_field :reference_user_id, :style=>"display:none"%> - <%= submit_tag l(:button_leave_meassge), :name => nil , :class => "enterprise" , :style => "display: block; float: right; margin-right: 1%; margin-top: 1px;"%> - <% else %> -
- <%= l(:label_user_login_tips) %> - <%= link_to l(:label_user_login_new), signin_path %> -
- <% end %> - <% end %> -
-
\ No newline at end of file diff --git a/app/views/contests/_new_join.html.erb b/app/views/contests/_new_join.html.erb deleted file mode 100644 index fc638d218..000000000 --- a/app/views/contests/_new_join.html.erb +++ /dev/null @@ -1,66 +0,0 @@ - - - -

<%=l(:label_please_input_password)%>

- -<%= form_tag( join_in_contest_contests_path(id: contest.id), - :remote => true, - :method => :post, - :id => 'new-watcher-form') do %> - - - - - <%= text_field_tag 'contest_password', nil, :size => 45 %> - -

- <%= submit_tag l(:label_new_join), - :name => nil, :class => "contest_btn", - :onclick => "hideModal(this);" - %> - <%= submit_tag l(:button_cancel), - :name => nil, - :class => "contest_btn", - :onclick => "hideModal(this);", - :type => 'button' - %> -

- -
-
-<% end %> diff --git a/app/views/contests/_new_softapplication.html.erb b/app/views/contests/_new_softapplication.html.erb deleted file mode 100644 index 3bba3db41..000000000 --- a/app/views/contests/_new_softapplication.html.erb +++ /dev/null @@ -1,228 +0,0 @@ -<%#= error_messages_for 'softapplication' %> - - - -<%= form_for Softapplication.new, :url => softapplications_path do |f| %> -
- <%= hidden_field_tag 'contest_id', @contest.id %> - - <%= l(:label_work_name) %> - * : - - <%= f.text_field :name, - :required => true, - :size => 60, - :style => "width:320px;", - :onkeyup => "regexName();" - %> - - (<%= l(:label_workname_lengthlimit) %>) - -
-
-
- - - - - - <%= l(:label_work_description) %>  - * -  :  - - - <%= f.text_area :description, - :required => true, - :size => 60, - :rows => 3, - :onkeyup => 'regexDescription();', - :style => "width:320px; " - %> - (<%= l(:label_work_description_lengthlimit) %>) - - - -
-
-
- - - <%= l(:label_softapplication_developers) %> - * : - - <%= f.text_field :application_developers, - :required => true, - :size => 60, - :style => "width:320px;", - :onkeyup => 'regexDevelopers();' - %> - - - (<%= l(:label_workdescription_lengthlimit) %>) - - -
-
-
- - - <%= l(:label_work_deposit_project) %>: - - <%= select_tag 'project', - options_for_select(select_option_helper(@option)), - :name => 'project', - :class => 'grayline2', - :style => "width:328px;" - %> - - - - - <%= link_to l(:label_create_new_projects), - new_project_path(:course => 0, :project_type => 0, :host => Setting.host_name), - :target => '_blank' - %> - - - -
-
-
- -
- - <%= l(:label_upload_softworkpacket_photo) %> - - <%#= render_flash_messages %> -

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

- -

- 1、<%= l(:label_upload_softapplication_packets_mustpacketed) %>
-
- 2、<%= l(:label_upload_softapplication_photo_condition) %> -

- -
-

-
- - <%#= submit_tag l(:button_create) %> - <%= submit_tag l(:button_cancel), - :name => nil, - :onclick => "cancel();", - :type => 'button', - :class => "enterprise", - :onmouseout => "this.style.backgroundPosition = 'left top'", - :onmouseover => "this.style.backgroundPosition = 'left -30px'" %> -
-<% end %> \ No newline at end of file diff --git a/app/views/contests/_pre_show.html.erb b/app/views/contests/_pre_show.html.erb deleted file mode 100644 index 67ceeb356..000000000 --- a/app/views/contests/_pre_show.html.erb +++ /dev/null @@ -1,18 +0,0 @@ - -<% unless content.nil?%> - - - - - - - -
<%= textilizable content %>
- <%= hidden_field_tag 'reference_content', - params[:reference_content], - :value => content - %> -
-<% end %> - - diff --git a/app/views/contests/_project_list.html.erb b/app/views/contests/_project_list.html.erb deleted file mode 100644 index 33e884020..000000000 --- a/app/views/contests/_project_list.html.erb +++ /dev/null @@ -1,19 +0,0 @@ - -<%= render_flash_messages %> - - - - <% if User.current.logged? %> - - <% end %> -
- <%= l(:label_bidding_project) %>(<%= contesting_project.count%>) - -
- <%= toggle_link l(:button_contesting_as_project), 'put-bid-form' %> -
-
- -<%= render :partial=> "list_projects", - :locals => {:contesting_project => contesting_project,:contest => @contest } -%> diff --git a/app/views/contests/_set_join.js.erb b/app/views/contests/_set_join.js.erb deleted file mode 100644 index d06f773d1..000000000 --- a/app/views/contests/_set_join.js.erb +++ /dev/null @@ -1,9 +0,0 @@ -$("#<%=object_id%>").replaceWith('<%= escape_javascript join_in_competition(@contest, user) %>'); -<% if @state %> -// modified by longjun 去掉中文,引用zh.yml中的标签 - <% if @state == 0 %> - alert(<%= l(:notice_successful_join) %>) - <% else %> - alert(<%= l(:notice_account_wrong_password) %>) - <% end %> -<% end %> \ No newline at end of file diff --git a/app/views/contests/_softapplication_list.html.erb b/app/views/contests/_softapplication_list.html.erb deleted file mode 100644 index d93923d72..000000000 --- a/app/views/contests/_softapplication_list.html.erb +++ /dev/null @@ -1,24 +0,0 @@ - -<%= render_flash_messages %> - - - - <% if User.current.logged? %> - - <% end %> -
- <%= l(:label_contest_softapplication) %> - (<%= @contest.contesting_softapplications.count%>) - -
- - <%= link_to l(:button_contesting_as_application), - "javascript:void(0);", - onclick: "$('#put-bid-form').toggle();" - %> -
-
-<%= render :partial=> "list_softapplications", - :locals => {:contesting_softapplication => contesting_softapplication, - :contest => @contest } -%> diff --git a/app/views/contests/add.js.erb b/app/views/contests/add.js.erb deleted file mode 100644 index 0706d0c56..000000000 --- a/app/views/contests/add.js.erb +++ /dev/null @@ -1,4 +0,0 @@ -$('#contesting_project_list').html('<%= escape_javascript(render(:partial => 'project_list', :locals => {:contesting_project => @contesting_project})) %>'); -$("#project_id").val("<%= l(:label_please_select_project) %>"); -$("#contest_message").val( "<%= l(:label_bid_reason) %>" ); -$("#put-bid-form").hide(); \ No newline at end of file diff --git a/app/views/contests/add_softapplication.js.erb b/app/views/contests/add_softapplication.js.erb deleted file mode 100644 index dfe774100..000000000 --- a/app/views/contests/add_softapplication.js.erb +++ /dev/null @@ -1,4 +0,0 @@ -$('#contesting_softapplication_list').html('<%= escape_javascript(render(:partial => 'softapplication_list', :locals => {:contesting_softapplication => @contesting_softapplication})) %>'); -$("#softapplication_id").val("<%= l(:label_please_select_contestingsoftapplication) %>"); -$("#contest_message").val( "<%= l(:label_bid_reason) %>" ); -$("#put-bid-form").hide(); \ No newline at end of file diff --git a/app/views/contests/back.js.erb b/app/views/contests/back.js.erb deleted file mode 100644 index d806c1481..000000000 --- a/app/views/contests/back.js.erb +++ /dev/null @@ -1,2 +0,0 @@ -$('#history').html('<%= escape_javascript(render(:partial => 'history', :locals => {:contest => @contest, :journals => @jour, :state => @state})) %>'); -$('#contest_message_reference_user_id').val(""); \ No newline at end of file diff --git a/app/views/contests/create.js.erb b/app/views/contests/create.js.erb deleted file mode 100644 index 9246d939c..000000000 --- a/app/views/contests/create.js.erb +++ /dev/null @@ -1,4 +0,0 @@ -$('#history').html('<%= escape_javascript(render(:partial => 'contests/history', :locals => {:contest => @contest, :journals => @jour, :state => true})) %>'); -$('#pre_show').html('<%= escape_javascript(render(:partial => 'pre_show', :locals => {:content => nil})) %>'); -$('#contest_message_message').val(""); -$('#contest_message_reference_user_id').val(""); diff --git a/app/views/contests/destroy.js.erb b/app/views/contests/destroy.js.erb deleted file mode 100644 index a2f0fb2da..000000000 --- a/app/views/contests/destroy.js.erb +++ /dev/null @@ -1,2 +0,0 @@ -$('#history').html('<%= escape_javascript(render(:partial => 'history', :locals => {:contest => @contest, :journals => @jour, :state => false})) %>'); -$('#contest_message_reference_user_id').val(""); \ No newline at end of file diff --git a/app/views/contests/index.html.erb b/app/views/contests/index.html.erb deleted file mode 100644 index 26e9e2114..000000000 --- a/app/views/contests/index.html.erb +++ /dev/null @@ -1,79 +0,0 @@ -
- <%= form_tag({:controller => 'contests', :action => 'index'}, :method => :get, :id => 'contests_serch') do %> - - - - - - - - - - -
- - <%=l(:label_contest_innovate_community)%> - - - <%= l(:label_user_location) %> : - - <% if User.current.logged? %> - <% unless User.current.user_extensions.identity == 1 %> - <%= link_to(l(:label_newtype_contest), new_contest_contests_path, :class => 'icon icon-add', :target => "_blank") %> - - <% end %> - <% end %> - - -
- <%=link_to l(:field_homepage), home_path %> > - <%= l(:label_contest_innovate) %> - -
- <% end %> -
-<% if @contests.size > 0%> - <%#= sort_contest(@s_state)%> -
- <%= render :partial => 'contest_list', :locals => {:contests => @contests, :contest_pages => @contest_pages} %> -
-<% elsif @is_search%> - <%= render :partial => "layouts/no_content"%> -<% else %> - <%#= sort_contest(@s_state)%> -
- <%= render :partial => 'contest_list', :locals => {:contests => @contests, :contest_pages => @contest_pages} %> -
-<% end %> - -<% html_title l(:label_contest_list)%> diff --git a/app/views/contests/more.js.erb b/app/views/contests/more.js.erb deleted file mode 100644 index d806c1481..000000000 --- a/app/views/contests/more.js.erb +++ /dev/null @@ -1,2 +0,0 @@ -$('#history').html('<%= escape_javascript(render(:partial => 'history', :locals => {:contest => @contest, :journals => @jour, :state => @state})) %>'); -$('#contest_message_reference_user_id').val(""); \ No newline at end of file diff --git a/app/views/contests/new.html.erb b/app/views/contests/new.html.erb new file mode 100644 index 000000000..7950ad990 --- /dev/null +++ b/app/views/contests/new.html.erb @@ -0,0 +1,31 @@ +
+

<%= l(:permission_new_contest)%>

+
+
+ +
+
+ \ No newline at end of file diff --git a/app/views/contests/new.js.erb b/app/views/contests/new.js.erb deleted file mode 100644 index a251b3d69..000000000 --- a/app/views/contests/new.js.erb +++ /dev/null @@ -1,5 +0,0 @@ -$('#pre_show').html('<%= escape_javascript(render(:partial => 'pre_show', :locals => {:content => @content})) %>'); -$('#contest_message_reference_user_id').val("<%= @id%>"); -showAndScrollTo("pre_show", "contest_message_reference_user_id"); - - diff --git a/app/views/contests/new_contest.html.erb b/app/views/contests/new_contest.html.erb deleted file mode 100644 index 0e1b83602..000000000 --- a/app/views/contests/new_contest.html.erb +++ /dev/null @@ -1,13 +0,0 @@ - -

<%=l(:label_newtype_contest)%>

- -<%= labelled_form_for @contest, - :url => {:controller => 'contests', :action => 'create_contest'}, - method: :post do |f| %> -
- <%= render :partial => 'form_contest', :locals => { :f => f } %> - <%= submit_tag l(:button_create), :style=> "margin-left: 100px;margin-top: 10px;" %> - <%= javascript_tag "$('#bid_name').focus();" %> - <% end %> -
-<% html_title(l(:label_newtype_contest)) -%> \ No newline at end of file diff --git a/app/views/contests/new_join.js.erb b/app/views/contests/new_join.js.erb deleted file mode 100644 index 5ec9356d7..000000000 --- a/app/views/contests/new_join.js.erb +++ /dev/null @@ -1,3 +0,0 @@ -$('#ajax-modal').html('<%= escape_javascript(render :partial => 'contests/new_join', :locals => {:contest => @contest}) %>'); -showModal('ajax-modal', '400px'); -$('#ajax-modal').addClass('new-watcher'); diff --git a/app/views/contests/set_reward_project.js.erb b/app/views/contests/set_reward_project.js.erb deleted file mode 100644 index 2ea06abb1..000000000 --- a/app/views/contests/set_reward_project.js.erb +++ /dev/null @@ -1,31 +0,0 @@ - -$('#reward_result_<%= @contesting_project_id %>').html('<%= j( - -if get_prize(@c_p).nil? || get_prize(@c_p) == "" - if @contest.deadline < Date.today - puts '未评奖' - end -else - - case get_prize(@c_p) - when '-1' - image_tag("/images/bid/special_reward.png") - when '0' - image_tag("/images/bid/first_reward.png") - when '1' - image_tag("/images/bid/second_reward.png") - when '2' - image_tag("/images/bid/third_reward.png") - when '3' - image_tag("/images/bid/forth_reward.png") - when '4' - image_tag("/images/bid/fifth_reward.png") - when '5' - image_tag("/images/bid/qualified.png") - end - -end -) -%>') - -$('#<%= @contesting_project_id %>').hide() diff --git a/app/views/contests/set_reward_softapplication.js.erb b/app/views/contests/set_reward_softapplication.js.erb deleted file mode 100644 index 2906d95d3..000000000 --- a/app/views/contests/set_reward_softapplication.js.erb +++ /dev/null @@ -1,32 +0,0 @@ - -$('#reward_result_<%= @contesting_softapplication_id %>').html('<%= j( - - -if get_prize(@c_sa).nil? || get_prize(@c_sa) == "" - if @contest.deadline < Date.today - puts '未评奖' - end -else - - case get_prize(@c_sa) - when '-1' - image_tag("/images/bid/special_reward.png") - when '0' - image_tag("/images/bid/first_reward.png") - when '1' - image_tag("/images/bid/second_reward.png") - when '2' - image_tag("/images/bid/third_reward.png") - when '3' - image_tag("/images/bid/forth_reward.png") - when '4' - image_tag("/images/bid/fifth_reward.png") - when '5' - image_tag("/images/bid/qualified.png") - end - -end -) -%>') - -$('#<%= @contesting_softapplication_id %>').hide() diff --git a/app/views/contests/settings.html.erb b/app/views/contests/settings.html.erb deleted file mode 100644 index 4f8b8b0f2..000000000 --- a/app/views/contests/settings.html.erb +++ /dev/null @@ -1,35 +0,0 @@ - -

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

- - -<%= error_messages_for 'contest' %> - -<%= labelled_form_for @contest, :url => update_contest_contest_path(@contest) do |f| %> -
- <%= render :partial => 'form_contest', :locals => { :f => f } %> -
- <%= submit_tag l(:button_create) %> - <%= javascript_tag "$('#bid_name').focus();" %> -<% end %> \ No newline at end of file diff --git a/app/views/contests/show_notification.html.erb b/app/views/contests/show.html.erb similarity index 100% rename from app/views/contests/show_notification.html.erb rename to app/views/contests/show.html.erb diff --git a/app/views/contests/show_attendingcontest.html.erb b/app/views/contests/show_attendingcontest.html.erb deleted file mode 100644 index 3f8ef4264..000000000 --- a/app/views/contests/show_attendingcontest.html.erb +++ /dev/null @@ -1,318 +0,0 @@ - - - -<%= render_flash_messages %> - -
-
- <%= l(:label_wellmeaning_intimation_contentone) %> -
-
- 1) <%= l(:label_wellmeaning_intimation_contenttwo) %> -
-
- 2) <%= l(:label_wellmeaning_intimation_contentthree) %> -
-
- -<% if User.current.logged? %> -
-
- <%= l(:label_attending_contest) %>: - - <%= link_to l(:label_new_attendingcontest_work), - "javascript:void(0);", - onclick: "$('#put-project-form').slideToggle();" - %> - -
-
-
- <%= render "new_softapplication" %> -
- -<% else %> -
- <%= l(:label_user_login_attending_contest) %> - <%= link_to l(:label_user_login_new), signin_path %> -
-<% end %> -
- - - -<% if @contest.id == 2 or @contest.id == 3 or @contest.id == 6 %> - - <% @contesting_project.sort.reverse.each do |c_project| %> - <% if c_project.project %> -
-
-
-
<%= l(:label_contest_work) %> - : <%= link_to(c_project.project.name, project_path(c_project.project), :target => '_blank') %> - -
- - - - <% if get_prize(c_project).nil? or get_prize(c_project) == "" %> - <% if @contest.deadline < Date.today %> - <%= l(:label_noawards) %> - <% else %> - <%= l(:label_noawards_current) %> - <% end %> - <% else %> - <% case get_prize(c_project) %> - <% when '-1' %> - <%= image_tag("/images/bid/special_reward.png") %> - <% when '0' %> - <%= image_tag("/images/bid/first_reward.png") %> - <% when '1' %> - <%= image_tag("/images/bid/second_reward.png") %> - <% when '2' %> - <%= image_tag("/images/bid/third_reward.png") %> - <% when '3' %> - <%= image_tag("/images/bid/forth_reward.png") %> - <% when '4' %> - <%= image_tag("/images/bid/fifth_reward.png") %> - <% when '5' %> - <%= image_tag("/images/bid/qualified.png") %> - <% end %> - <% end %> - - - - - - <% if ((User.current.id == @contest.author_id) && (@contest.deadline >= Date.today))||User.current.admin %> - - - <%= toggle_link l(:label_reward), c_project.id.to_s %> - - - - - <% end %> -
-
-
-
-
-
- - <%= l(:label_profile) %>: - - <%#= c_project.project.description.truncate(90, omission: '...') %> - <%= c_project.project.description %> - - -
-
-
- <%= l(:label_attendingcontest_time) %> - :<%= format_time c_project.created_at %> - <%= l(:label_attendingcontest_spoksman) %> - - <% unless c_project.nil? || c_project.user.nil? %> - :<%= link_to c_project.user.name,user_path(c_project.user) %> - <% end %> -
- -
- -
-
- <% end %> -
- <% end %> -<% else %> - <% @contesting_softapplication.each do |c_softapplication| %> - <% if c_softapplication.softapplication %> -
-
- - <%= l(:label_contest_work) %>: - <%= link_to(c_softapplication.softapplication.name, softapplication_path(c_softapplication.softapplication), :target => '_blank') %> - -
-
- -
- - <%= l(:label_profile) %>: - - <%#= c_softapplication.softapplication.description.truncate(90, omission: '...') %> - <%= c_softapplication.softapplication.description %> - - -
-
- -
- <%= l(:label_attendingcontest_time) %> - :<%= format_time c_softapplication.created_at %> - <%= l(:label_attendingcontest_spoksman) %> - - <% unless c_softapplication.nil? || c_softapplication.softapplication.nil? || c_softapplication.softapplication.user.nil? %> - :<%= link_to c_softapplication.softapplication.user.name,user_path(c_softapplication.softapplication.user) %> - <% end %> -
- - -
- <% score = c_softapplication.softapplication.average(:quality).try(:avg).try(:round, 2).to_f %> - <%= l(:label_final_scores) %> - :<%= format("%.2f" , score) %> - 分 - - - - - <% if get_prize(c_softapplication).nil? or get_prize(c_softapplication) == "" %> - <% if @contest.deadline < Date.today %> - <%= l(:label_noawards) %> - <% else %> - <%= l(:label_noawards_current) %> - <% end %> - <% else %> - <% case get_prize(c_softapplication) %> - <% when '-1' %> - <%= image_tag("/images/bid/special_reward.png") %> - <% when '0' %> - <%= image_tag("/images/bid/first_reward.png") %> - <% when '1' %> - <%= image_tag("/images/bid/second_reward.png") %> - <% when '2' %> - <%= image_tag("/images/bid/third_reward.png") %> - <% when '3' %> - <%= image_tag("/images/bid/forth_reward.png") %> - <% when '4' %> - <%= image_tag("/images/bid/fifth_reward.png") %> - <% when '5' %> - <%= image_tag("/images/bid/qualified.png") %> - <% end %> - <% end %> - - - - - - <% if ((User.current.id == @contest.author_id) && (@contest.deadline >= Date.today))||User.current.admin %> -
- <%= toggle_link '评奖', c_softapplication.id.to_s %> - - -
- <% end %> -
-
-
- <% end %> -
- <% end %> -<% end %> - - -<% html_title(l(:label_contest_joincontest)) -%> - diff --git a/app/views/contests/show_contest.html.erb b/app/views/contests/show_contest.html.erb deleted file mode 100644 index bbda34b88..000000000 --- a/app/views/contests/show_contest.html.erb +++ /dev/null @@ -1,44 +0,0 @@ -<% reply_allow = JournalsForMessage.create_by_user? User.current %> -<%= stylesheet_link_tag 'css', :media => 'all' %> - - <%= render :partial => 'contest_jours', - :locals => { :contest => @contest, :journals => @jour, :state => false} - %> - -<% html_title(l(:label_user_response)) -%> diff --git a/app/views/contests/show_contest_user.html.erb b/app/views/contests/show_contest_user.html.erb deleted file mode 100644 index 1b8a27c1a..000000000 --- a/app/views/contests/show_contest_user.html.erb +++ /dev/null @@ -1,37 +0,0 @@ -
- <% for user in @contest.watcher_users %> - -<% end %> -
\ No newline at end of file diff --git a/app/views/contests/show_softapplication.html.erb b/app/views/contests/show_softapplication.html.erb deleted file mode 100644 index 86b20c09a..000000000 --- a/app/views/contests/show_softapplication.html.erb +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - <% if User.current.logged? %> - -
- - <% end %> - - - -
- <%= render :partial => 'softapplication_list', :locals => {:contesting_softapplication => @contesting_softapplication,:contest => @contest} %> -
- diff --git a/app/views/contests/watcherlist.html.erb b/app/views/contests/watcherlist.html.erb deleted file mode 100644 index 5628e5e95..000000000 --- a/app/views/contests/watcherlist.html.erb +++ /dev/null @@ -1,34 +0,0 @@ - -

<%= l(:label_user_watcher)%>

-
- <% @contest.watcher_users.each do |user| %> - - <% end %> -
-<% html_title(l(:label_followers)) -%> \ No newline at end of file diff --git a/app/views/layouts/_homepage_left_contest_list.html.erb b/app/views/layouts/_homepage_left_contest_list.html.erb new file mode 100644 index 000000000..7c96ac804 --- /dev/null +++ b/app/views/layouts/_homepage_left_contest_list.html.erb @@ -0,0 +1,17 @@ +<% all_count = @user.contests.visible.where("is_delete =?", 0).count%> +
+ +
+<% if !contests.empty? %> + + + +<% end %> + + \ No newline at end of file diff --git a/app/views/layouts/_user_contests.html.erb b/app/views/layouts/_user_contests.html.erb new file mode 100644 index 000000000..4e0b5aa94 --- /dev/null +++ b/app/views/layouts/_user_contests.html.erb @@ -0,0 +1,72 @@ +<% contests.each do |contest|%> +
  • + + <% is_teacher = User.current.logged? && (User.current.admin? || User.current.admin_of_contest?(contest)) %> +

    + <%= link_to contest.name, contest_path(contest.id), :target => '_blank', :class => 'hidden', :style => 'display:block;'%> +

    + + <% count = ShieldActivity.where("container_type='User' and container_id=#{user.id} and shield_type='Contest' and shield_id=#{contest.id}").count %> + +
    + +
    +
  • +<% end %> + +<% if all_count > (page.to_i+1) * 10%> + + + +<% end%> + + diff --git a/app/views/layouts/base_contest.html.erb b/app/views/layouts/base_contest.html.erb deleted file mode 100644 index 42a7eccd1..000000000 --- a/app/views/layouts/base_contest.html.erb +++ /dev/null @@ -1,289 +0,0 @@ -<% - @nav_dispaly_contest_label = 1 - @nav_dispaly_store_all_label = 1 -%> - - - - - <%= h html_title %> - - - <%= csrf_meta_tag %> - <%= favicon %> - <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'application', :media => 'all' %> - <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> - <%= javascript_heads %> - <%= heads_for_theme %> - <%= call_hook :view_layouts_base_html_head %> - - <%= yield :header_tags -%> - - -
    -
    -
    - <%=render :partial => 'layouts/base_header'%> -
    - -
    - - - - - - - - - -
    - - <%=l(:label_contest_innovate_community)%> - - - - <%= l(:label_user_location) %> : - - - -
    - <%=link_to l(:field_homepage), home_path %> > - <%= l(:label_contest_innovate)%> > - - <%= link_to @bid.name, bid_path %> - -
    -
    - - - -
    - <% if display_main_menu?(@bid) %> -
    - <%= render_menu :bid_menu %> -
    - <% end %> - - <%= yield %> - <%= call_hook :view_layouts_base_content %> -
    -
    - <%=render :partial => 'layouts/base_footer'%> -
    -
    -
    - - - - -
    - <%= call_hook :view_layouts_base_body_bottom %> - - diff --git a/app/views/layouts/base_contest_community.html.erb b/app/views/layouts/base_contest_community.html.erb new file mode 100644 index 000000000..b29779be6 --- /dev/null +++ b/app/views/layouts/base_contest_community.html.erb @@ -0,0 +1,103 @@ + + + + + <%= h html_title %> + + + <%= csrf_meta_tag %> + <%= favicon %> + <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/common', 'css/structure','css/public', 'prettify','css/project','css/courses','css/popup','syllabus','css/moduel', 'css/user', :media => 'all' %> + <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> + <%= javascript_heads %> + <%= javascript_include_tag "bootstrap","avatars","new_user",'attachments','prettify'%> + <%= heads_for_theme %> + <%= call_hook :view_layouts_base_html_head %> + <%= yield :header_tags -%> + + + + + + + + +
    +
    + +
    +
    +
    +
    + <% if hidden_unproject_infos %> +
      +
    • + <%= link_to '竞赛',{:controller => "users", :action => "user_contestlist", :id => @user}, :id => "user_contest_list" %> + <%= link_to '全部',{:controller => "users", :action => "user_contestlist", :id => @user}, :style => "color:#aaa;" %> + <% contests = @user.favorite_contests.visible.where("is_delete =?", 0).select("contests.*,(SELECT MAX(updated_at) FROM `contest_activities` WHERE contest_activities.contest_id = contests.id) AS a").order("a desc").limit(10) %> + <% unless contests.empty? %> +
      + <%= render :partial => 'layouts/homepage_left_contest_list', :locals => {:contests => contests} %> +
      + <% end %> +
    • + <% if is_current_user %> +
    • + <%= link_to "新建竞赛", new_contest_path(), :target => "_blank", :style => "font-size:14px;" %> +
    • +
    • + <%= link_to "加入竞赛",join_contest_contests_path(),:remote => true, :method => "post", :style => "font-size:14px;" %> +
    • + <% end %> +
    + <% end %> +
    + <%# 更新访问数,刷新的时候更新访问次数 %> + <%# update_visiti_count @user %> + +
    +
    + <%= yield %> +
    +
    +
    +
    +<%= render :partial => 'layouts/footer' %> +
    + + + + + + + + \ No newline at end of file diff --git a/app/views/layouts/base_contests.html.erb b/app/views/layouts/base_contests.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/layouts/new_base.html.erb b/app/views/layouts/new_base.html.erb index d28171f5f..cc6da3581 100644 --- a/app/views/layouts/new_base.html.erb +++ b/app/views/layouts/new_base.html.erb @@ -14,7 +14,7 @@ <%= heads_for_theme %> <%= call_hook :view_layouts_base_html_head %> <%= stylesheet_link_tag 'css/common','css/structure', 'css/public', 'css/courses','prettify', 'css/org', 'syllabus'%> - <%= javascript_include_tag "course","header",'prettify' %> + <%= javascript_include_tag "course","header",'prettify','contest' %> <%= yield :header_tags -%> diff --git a/app/views/layouts/new_base_user.html.erb b/app/views/layouts/new_base_user.html.erb index 24cad0bf8..785e2a235 100644 --- a/app/views/layouts/new_base_user.html.erb +++ b/app/views/layouts/new_base_user.html.erb @@ -238,6 +238,19 @@ + +
    +

    + <%= link_to "竞赛社区", user_contest_community_path(User.current), :class => "fl" , :target => "_blank"%> +

    + + <%# end %> +
    <% else %>

    Ta在确实 @@ -252,6 +265,10 @@ <%= link_to user_project_count > 0 ? "项目#{user_project_count}".html_safe : "项目", user_project_community_path(@user), :id => 'user_project_list', :class => "fl", :target => "_blank" %> +
  • + <%= link_to user_contest_count > 0 ? "竞赛#{user_contest_count}".html_safe : "竞赛", + user_contest_community_path(@user), :id => 'user_contest_list', :class => "fl", :target => "_blank" %> +
  • <% end %> diff --git a/app/views/users/_contest_create.html.erb b/app/views/users/_contest_create.html.erb new file mode 100644 index 000000000..017c57d58 --- /dev/null +++ b/app/views/users/_contest_create.html.erb @@ -0,0 +1,23 @@ +
    +
    +
    + <%= link_to image_tag(url_to_avatar(activity.user), :width => "50", :height => "50"), user_path(activity.user), :alt => "用户头像" %> + <%#= render :partial => 'users/show_detail_info', :locals => {:user => activity.user} %> +
    +
    +
    + <%= link_to activity.user.show_name, user_path(activity.user), :class => "newsBlue mr15" %> + TO + <% str = defined?(is_contest) && is_contest == 1 ? "竞赛" : "#{activity.name.to_s} | 竞赛" %> + <%= link_to str, contest_path(activity.id), :class => "newsBlue ml15" %> +
    +
    + <%= link_to activity.name, contest_path(activity.id), :class => "postGrey" %> +
    +
    + 创建时间:<%= format_time(activity.created_at) %> +
    +
    +
    +
    +
    diff --git a/app/views/users/_contest_work.html.erb b/app/views/users/_contest_work.html.erb new file mode 100644 index 000000000..fe976ab30 --- /dev/null +++ b/app/views/users/_contest_work.html.erb @@ -0,0 +1,61 @@ +<% is_teacher = User.current.admin_of_contest?(:as_teacher,activity.course) %> +
    +
    +
    + <%= link_to image_tag(url_to_avatar(activity.user), :width => "50", :height => "50"), user_path(activity.user), :alt => "用户头像" %> + <%#= render :partial => 'users/show_detail_info', :locals => {:user => activity.user} %> +
    +
    +
    + <%= link_to activity.user.show_name, user_path(activity.user,:host=>Setting.host_user), :class => "newsBlue mr15" %> + TO + <% if hw_status == 3 || hw_status == 2 %> + <%= link_to "竞赛作品", works_index_path(:contest => activity.contest.id), :class => "newsBlue ml15"%> + <% else %> + <%= link_to activity.contest.name.to_s+" | 竞赛作品", works_index_path(:contest => activity.contest.id), :class => "newsBlue ml15"%> + <% end %> +
    + + <%#=get_hw_status(activity).html_safe %> + +
    + <% if activity.work_type == 3 && activity.work_detail_group.base_on_project %> + 系统提示:该题目要求各组长<%=link_to "创建项目", new_project_path(:host=>Setting.host_name),:class=>"linkBlue",:title=>"新建项目",:style=>"text-decoration:underline;"%>,组成员加入项目,然后由组长关联项目。谢谢配合! + <% elsif activity.work_type == 3 && !activity.work_detail_group.base_on_project%> + 系统提示:该题目要求各组长提交作品,提交作品时请添加组成员。谢谢配合! + <% end %> +
    + <%= render :partial => 'users/work_opr', :locals => {:activity => activity, :is_teacher => is_teacher, :hw_status => hw_status, :user_activity_id => user_activity_id} %> + <% if !activity.end_time.nil? %> +
    提交截止时间:<%= activity.end_time.to_s %> 23:59
    + <% end %> + <% if activity.homework_detail_manual.comment_status == 0 && !activity.publish_time.nil? %> +
    + <%= l(:label_publish_time)%>:<%= activity.publish_time%> 00:00 +
    + <% end %> +
    + <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.description} %> + +
    + + +
    +
    + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
    + + <%= render :partial => "users/contest_work_base_info", :locals =>{:activity => activity, :user_activity_id =>user_activity_id, :is_teacher => is_teacher, :hw_status => hw_status} %> +
    +
    +
    + + <%= render :partial => 'users/homework_post_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id, :is_teacher => is_teacher} %> +
    diff --git a/app/views/users/_contest_work_base_info.html.erb b/app/views/users/_contest_work_base_info.html.erb new file mode 100644 index 000000000..071b08490 --- /dev/null +++ b/app/views/users/_contest_work_base_info.html.erb @@ -0,0 +1,58 @@ + + + + + + +<% if activity.contestant_works.count != 0 %> + <% sw = activity.contestant_works.reorder("commit_time desc").first %> +
    + # <%=time_from_now sw.commit_time %><%= link_to sw.user.show_name, user_activities_path(sw.user_id), :class => "newsBlue ml5 mr5"%>提交了作品 +
    +
    + <% sw_id = "("+activity.contestant_works.map{|sw| sw.id}.join(",")+")" %> + <% student_work_scores = ContestantWorkScore.where("contestant_work_id in #{sw_id} and score is not null").reorder("created_at desc") %> + <% unless student_work_scores.empty? %> + <% last_score = student_work_scores.first %> +
    +

    # <%=time_from_now last_score.created_at %> + <%= link_to last_score.reviewer_role == 3 && !is_teacher ? '学生匿名' : last_score.user.show_name, last_score.reviewer_role == 3 && !is_teacher ? "javascript:void(0)" : user_activities_path(last_score.user_id), :class => "newsBlue ml5 mr5"%>评阅了作品 +

    +
    + <% end %> +<% end %> +
    +<% if activity.work_type == 3 && activity.work_detail_group.base_on_project %> + <% projects = activity.contestant_work_projects.where(:is_leader => true) %> + <% unless projects.empty? %> + <% sort_projects = project_sort_update projects %> +
    +
    + <% first_pro_act = sort_projects.first %> + <% first_pro = Project.find first_pro_act.project_id %> + <% commit_time = first_pro.project_score.commit_time %> + <%# one_forge_time=ForgeActivity.where("project_id=?",first_pro.id).last.updated_at if ForgeActivity.where("project_id=?",first_pro.id).last %> + # <%=time_from_now !commit_time.nil? && format_time(commit_time) > format_time(first_pro_act.updated_at) ? commit_time : first_pro_act.updated_at %><%= link_to User.find(first_pro.user_id).show_name, user_activities_path(first_pro.user_id), :class => "newsBlue ml5 mr5"%>更新了项目 +
    +
    +
    + <% end %> +<% end %> +
    + +<% if is_teacher%> +
    + +
    +<% end%> \ No newline at end of file diff --git a/app/views/users/_contest_work_post_reply.html.erb b/app/views/users/_contest_work_post_reply.html.erb new file mode 100644 index 000000000..47358f06d --- /dev/null +++ b/app/views/users/_contest_work_post_reply.html.erb @@ -0,0 +1,34 @@ +<% count=activity.journals_for_messages.count %> +<% comments = activity.journals_for_messages.reorder("created_on desc") %> +<% no_children_comments = get_no_children_comments comments %> +
    + <%= render :partial => 'users/reply_banner', :locals => {:count => count, :activity => activity, :user_activity_id => user_activity_id, :expand_more =>no_children_comments[:three_more]} %> + + <% if count > 0 %> +
    + <%=render :partial => 'users/news_replies', :locals => {:comments => no_children_comments[:no_children_comments], :type => 'HomeworkCommon', :is_teacher => is_teacher, :user_activity_id => user_activity_id, :activity_id => activity.id} %> +
    + <% end %> + +
    +
    <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), :alt => "用户头像" %>
    +
    + <% if User.current.logged? %> +
    + <%= form_for('new_form',:url => {:controller => 'words', :action => 'leave_contest_work_message', :id => activity.id},:method => "post", :remote => true) do |f|%> + <%= hidden_field_tag 'user_activity_id',params[:user_activity_id],:value =>user_activity_id %> +
    + + +
    +

    + <% end%> +
    + <% else %> + <%= render :partial => "users/show_unlogged" %> + <% end %> +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/users/_user_activities.html.erb b/app/views/users/_user_activities.html.erb index 54eeffbd7..600adee5b 100644 --- a/app/views/users/_user_activities.html.erb +++ b/app/views/users/_user_activities.html.erb @@ -2,25 +2,25 @@ <%= import_ke(enable_at: true, prettify: false, init_activity: true) %> <% end %> <% if user_activity.act_type == "Project" %> - <%= render :partial => 'project_create', :locals => {:activity => user_activity,:user_activity_id =>user_activity.id} %> + <%= render :partial => 'project_create', :locals => {:activity => user_activity, :user_activity_id => user_activity.id} %> <% else %> - <% act= user_activity.act %> - <%if act %> - - <% case user_activity.container_type.to_s %> - <% when 'Course' %> - <% case user_activity.act_type.to_s %> - <% when 'HomeworkCommon' %> - <%# cache (act) do %> - <% hidden_courses = Setting.find_by_name("hidden_courses") %> - <% unvisiable = hidden_courses && hidden_courses.value == "1"%> - <% if !unvisiable %> - <%= render :partial => 'course_homework', :locals => {:activity => act,:user_activity_id =>user_activity.id,:hw_status => 1} %> - <% end %> - <%# end %> - <% when 'News' %> + <% act= user_activity.act %> + <% if act %> + <% case user_activity.container_type.to_s %> + <% when 'Course' %> + <% case user_activity.act_type.to_s %> + <% when 'HomeworkCommon' %> + <%# cache (act) do %> + <% hidden_courses = Setting.find_by_name("hidden_courses") %> + <% unvisiable = hidden_courses && hidden_courses.value == "1" %> + <% if !unvisiable %> + <%= render :partial => 'course_homework', :locals => {:activity => act, :user_activity_id => user_activity.id, :hw_status => 1} %> + <% end %> + <%# end %> + <% when 'News' %> <%# cache [act, act.comments.count] do %> - <%= render :partial => 'course_news', :locals => {:activity => act,:user_activity_id =>user_activity.id} %> + <%= render :partial => 'course_news', :locals => {:activity => act, :user_activity_id => user_activity.id} %> <%# end %> - <% when 'Message'%> - <%= render :partial => 'course_message', :locals => {:activity => act,:user_activity_id =>user_activity.id,:is_course=>0,:is_board=>0} %> - <% when 'Poll' %> - <%= render :partial => 'course_poll', :locals => {:activity => act, :user_activity_id => user_activity.id} %> - <% when 'Course'%> + <% when 'Message' %> + <%= render :partial => 'course_message', :locals => {:activity => act, :user_activity_id => user_activity.id, :is_course => 0, :is_board => 0} %> + <% when 'Poll' %> + <%= render :partial => 'course_poll', :locals => {:activity => act, :user_activity_id => user_activity.id} %> + <% when 'Course' %> <%# cache (act) do %> - <%= render :partial => 'users/course_create', :locals => {:activity => act, :user_activity_id => act.id} %> + <%= render :partial => 'users/course_create', :locals => {:activity => act, :user_activity_id => act.id} %> <%# end%> - <% when 'JournalsForMessage'%> + <% when 'JournalsForMessage' %> <%= render :partial => 'users/course_journalsformessage', :locals => {:activity => act, :user_activity_id => user_activity.id} %> - <% end %> - <% when 'Project' %> - <% case user_activity.act_type.to_s %> - <% when 'Issue' %> + <% end %> + <% when 'Project' %> + <% case user_activity.act_type.to_s %> + <% when 'Issue' %> <%# cache [act, act.journals.count, act.attachments.count] do%> - <%= render :partial => 'project_issue', :locals => {:activity => act,:user_activity_id =>user_activity.id, :user_id => user_id} %> + <%= render :partial => 'project_issue', :locals => {:activity => act, :user_activity_id => user_activity.id, :user_id => user_id} %> <%# end %> - <% when 'Message' %> - <%= render :partial => 'project_message', :locals => {:activity => act,:user_activity_id =>user_activity.id,:is_course=>0,:is_board=>0} %> - <% when 'Project'%> + <% when 'Message' %> + <%= render :partial => 'project_message', :locals => {:activity => act, :user_activity_id => user_activity.id, :is_course => 0, :is_board => 0} %> + <% when 'Project' %> <%# cache (act) do %> - <%= render :partial => 'project_create', :locals => {:activity => act,:user_activity_id =>user_activity.id} %> - <%# end %> - <% end %> - <% when 'Principal' %> - <% case user_activity.act_type.to_s %> - <% when 'JournalsForMessage' %> - <% unless act.private == 1 && (!User.current || (User.current && act.jour_id != User.current.id && act.user_id != User.current.id)) %> - <%= render :partial => 'user_journalsformessage', :locals => {:activity => act,:user_activity_id =>user_activity.id} %> - <% end %> - <% end %> - <% when 'Blog'%> - <%# cache (act) do %> - <% case user_activity.act_type.to_s %> - <% when 'BlogComment' %> - <%# if !(act.blog.homepage_id and act.id == act.blog.homepage_id) %> - <%= render :partial => 'user_blog', :locals => {:activity => act,:user_activity_id =>user_activity.id} %> - <%# end %> - <% end %> + <%= render :partial => 'project_create', :locals => {:activity => act, :user_activity_id => user_activity.id} %> <%# end %> <% end %> + <% when 'Contest' %> + <% case user_activity.act_type.to_s %> + <% when 'Work' %> + <%= render :partial => 'contest_work', :locals => {:activity => act, :user_activity_id => user_activity.id, :hw_status => 1} %> + <% when 'News' %> + <%#= render :partial => 'contest_news', :locals => {:activity => act, :user_activity_id => user_activity.id} %> + <% when 'Message' %> + <%#= render :partial => 'contest_message', :locals => {:activity => act, :user_activity_id => user_activity.id, :is_contest => 0, :is_board => 0} %> + <% when 'Contest' %> + <%= render :partial => 'users/contest_create', :locals => {:activity => act, :user_activity_id => act.id} %> + <% when 'JournalsForMessage' %> + <%#= render :partial => 'users/contest_journalsformessage', :locals => {:activity => act, :user_activity_id => user_activity.id} %> + <% end %> + <% when 'Principal' %> + <% case user_activity.act_type.to_s %> + <% when 'JournalsForMessage' %> + <% unless act.private == 1 && (!User.current || (User.current && act.jour_id != User.current.id && act.user_id != User.current.id)) %> + <%= render :partial => 'user_journalsformessage', :locals => {:activity => act, :user_activity_id => user_activity.id} %> + <% end %> + <% end %> + <% when 'Blog' %> + <%# cache (act) do %> + <% case user_activity.act_type.to_s %> + <% when 'BlogComment' %> + <%# if !(act.blog.homepage_id and act.id == act.blog.homepage_id) %> + <%= render :partial => 'user_blog', :locals => {:activity => act, :user_activity_id => user_activity.id} %> + <%# end %> + <% end %> + <%# end %> + <% end %> <% end %> - <% end %> <% end %> + <% end %> <% end %> -<% if user_activities.count == 10%> - - <%= link_to "点击展开更多", action == "project_community" ? user_project_community_path(@user.id, :type => type, :page => page) : (action == "course_community" ? user_course_community_path(@user.id, :type => type,:page => page) : user_activities_path(@user.id,:type => type,:page => page)), + <%= link_to "点击展开更多", action == "project_community" ? user_project_community_path(@user.id, :type => type, :page => page) : (action == "course_community" ? user_course_community_path(@user.id, :type => type, :page => page) : (action == "contest_community" ? user_contest_community_path(@user.id, :type => type, :page => page) : user_activities_path(@user.id, :type => type, :page => page))), :id => "show_more_activities", :remote => "true", :class => "loadMore mt10 f_grey" %> -<% end%> +<% end %> + + + + + + + <%# end %> +<%# end %> +<% if activity.homework_type == 2%> +
    + 语言: + <%= activity.language_name%> +
    +<% elsif activity.work_type == 3 && activity.work_detail_group%> + <% if activity.work_detail_group.base_on_project %> +
    + <%=link_to "项目(#{activity.contestant_work_projects.where(:is_leader => true).count})",contestant_work_index_url_in_org(activity.id, 3),:class => "c_blue" %> +
    + <% end %> +
    + 分组人数:<%=activity.work_detail_group.min_num %>-<%=activity.work_detail_group.max_num %> 人 +
    +<% end %> \ No newline at end of file diff --git a/app/views/users/cancel_or_collect.js.erb b/app/views/users/cancel_or_collect.js.erb index 833fa3260..ee0b3a04e 100644 --- a/app/views/users/cancel_or_collect.js.erb +++ b/app/views/users/cancel_or_collect.js.erb @@ -8,4 +8,9 @@ if($("#collect_project_icon_<%=@project.id %>").length > 0){ $("#collect_project_icon_<%=@project.id %>").html("<%= escape_javascript(render :partial => 'users/collect_project', :locals => {:project => @project}) %>"); } +<% elsif @contest %> + $("#homepage_left_contest_list").html("<%= escape_javascript(render :partial => 'layouts/homepage_left_contest_list', :locals => {:contests => @contests}) %>"); + if($("#collect_project_icon_<%=@contest.id %>").length > 0){ + $("#collect_project_icon_<%=@contest.id %>").html("<%= escape_javascript(render :partial => 'users/collect_contest', :locals => {:contest => @contest}) %>"); + } <% end %> \ No newline at end of file diff --git a/app/views/users/contest_community.html.erb b/app/views/users/contest_community.html.erb new file mode 100644 index 000000000..26cad6c32 --- /dev/null +++ b/app/views/users/contest_community.html.erb @@ -0,0 +1,32 @@ + + +
    +
    最新动态
    + +
    + +<% if @user_activities_count > 0 %> + <%= render :partial => 'users/user_activities', :locals => {:user_activities => @user_activities, :page => 0, :type => @type, + :user_id => (@user.type == "AnonymousUser" ? User.current.id : @user.id), :action => "contest_community" } %> +<% else %> +
    + <%= render :partial => 'users/no_data' %> +
    +<% end %> diff --git a/app/views/users/user_contests4show.html.erb b/app/views/users/user_contests4show.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/words/leave_contest_work_message.js.erb b/app/views/words/leave_contest_work_message.js.erb new file mode 100644 index 000000000..d3d4b2154 --- /dev/null +++ b/app/views/words/leave_contest_work_message.js.erb @@ -0,0 +1,6 @@ +$("#homework_post_reply_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/homework_post_reply', :locals => {:activity => @homework_common, :user_activity_id => @user_activity_id, :is_teacher => @is_teacher}) %>"); +<% if @user_activity_id != @homework_common.id %> +sd_create_editor_from_data(<%= @user_activity_id%>,"","100%", "UserActivity"); +<% else %> +sd_create_editor_from_data(<%= @homework_common.id%>,"","100%", "<%=@homework_common.class.to_s%>"); +<% end %> \ No newline at end of file diff --git a/app/views/words/reply_to_contest_work.js.erb b/app/views/words/reply_to_contest_work.js.erb new file mode 100644 index 000000000..d3d4b2154 --- /dev/null +++ b/app/views/words/reply_to_contest_work.js.erb @@ -0,0 +1,6 @@ +$("#homework_post_reply_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/homework_post_reply', :locals => {:activity => @homework_common, :user_activity_id => @user_activity_id, :is_teacher => @is_teacher}) %>"); +<% if @user_activity_id != @homework_common.id %> +sd_create_editor_from_data(<%= @user_activity_id%>,"","100%", "UserActivity"); +<% else %> +sd_create_editor_from_data(<%= @homework_common.id%>,"","100%", "<%=@homework_common.class.to_s%>"); +<% end %> \ No newline at end of file diff --git a/config/locales/zh.yml b/config/locales/zh.yml index ac18cda3e..789909de7 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -377,7 +377,8 @@ zh: label_user: 用户 label_user_plural: 用户列表 - + permission_new_contest: 新建竞赛 + label_tags_contest_name: 竞赛名称 label_user_new: 新建用户 label_user_anonymous: 匿名用户 diff --git a/config/routes.rb b/config/routes.rb index 14942ed28..067662cd1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -359,8 +359,6 @@ RedmineApp::Application.routes.draw do end end - resources :contest_notification - resources :open_source_projects do collection do match 'search', :via => [:get, :post] @@ -403,47 +401,46 @@ RedmineApp::Application.routes.draw do end end - ## new added by linchun #新竞赛相关 - resources :contests, only: [:index] do - resources :contestnotifications do - # get 'preview', on: :collection - resources :notificationcomments - end - - collection do - match 'new_contest' , :via => :get - match 'join_in_contest' , :via => :post - match 'unjoin_in_contest' , :via => :delete - match 'create_contest' , :via => :post - match 'new_join' , :via => :post - match 'new' , :via => :post - end - member do - delete 'destroy_contest' - match 'add_softapplication' - match 'update_contest' , :via => [:put] - match 'show_contest' , :via => [:get, :post] - match 'show_project' , :via => :get - match 'show_softapplication' , :via => :get - match 'show_attendingcontest' , :via => :get - #match 'show_notification' , :via => :get - match 'show_participator' , :via => :get - match 'set_reward_project' , :via => [:get, :post] - match 'set_reward_softapplication' , :via => [:get, :post] - match 'add' , :via => [:get, :post] - match 'add_softapplication' , :via => [:get, :post] - match 'create' , :via => :post - match 'settings' , :via => [:get, :post] - match 'show_contest_user' - get 'watcherlist', :action=> 'watcherlist' - end - end + # ## new added by linchun #新竞赛相关 + # resources :contests, only: [:index] do + # resources :contestnotifications do + # # get 'preview', on: :collection + # resources :notificationcomments + # end + # + # collection do + # match 'new_contest' , :via => :get + # match 'join_in_contest' , :via => :post + # match 'unjoin_in_contest' , :via => :delete + # match 'create_contest' , :via => :post + # match 'new_join' , :via => :post + # match 'new' , :via => :post + # end + # member do + # delete 'destroy_contest' + # match 'add_softapplication' + # match 'update_contest' , :via => [:put] + # match 'show_contest' , :via => [:get, :post] + # match 'show_project' , :via => :get + # match 'show_softapplication' , :via => :get + # match 'show_attendingcontest' , :via => :get + # #match 'show_notification' , :via => :get + # match 'show_participator' , :via => :get + # match 'set_reward_project' , :via => [:get, :post] + # match 'set_reward_softapplication' , :via => [:get, :post] + # match 'add' , :via => [:get, :post] + # match 'add_softapplication' , :via => [:get, :post] + # match 'create' , :via => :post + # match 'settings' , :via => [:get, :post] + # match 'show_contest_user' + # get 'watcherlist', :action=> 'watcherlist' + # end + # end match '/news/preview', :to => 'previews#news', :as => 'preview_news', :via => [:get, :post, :put] match '/issues/preview/new/:project_id', :to => 'previews#issue', :as => 'preview_new_issue', :via => [:get, :post, :put] match '/issues/preview/edit/:id', :to => 'previews#issue', :as => 'preview_edit_issue', :via => [:get, :post, :put] match '/issues/preview', :to => 'previews#issue', :as => 'preview_issue', :via => [:get, :post, :put] - match '/contestnotifications/preview', :to => 'previews#contestnotification', :as => 'preview_contestnotifications', :via => [:get, :post, :put] resources :stores do collection do @@ -570,11 +567,82 @@ RedmineApp::Application.routes.draw do match 'users/:id/courses', :to => 'users#course_community', :as => "user_course_community" match 'users/:id/projects', :to => 'users#project_community', :as => "user_project_community" + match 'users/:id/contests', :to => 'users#contest_community', :as => "user_contest_community" scope ":username" do resources :posts end +# added by cxt + resources :contest_members do + collection do + + end + + member do + + end + end + + # added by cxt + resources :contestant_works do + collection do + post 'student_work_project' + get 'new_student_work_project' + get 'cancel_relate_project' + end + + member do + + end + end + + # added by cxt + resources :works do + collection do + + end + + member do + + end + end + + # added by cxt + resources :contests do + collection do + get 'join_contest' + end + + member do + + end + + resources :boards + resources :files, :only => [:index, :new, :create] do + collection do + match "getattachtype", :via => [:get, :post] + match "search",:via => [:post,:get] + match "searchone4reload",:via => [:post,:get] + match "search_tag_attachment", :via => [:post,:get] + end + member do + match "quote_resource_show", :via => [:get] + get "file_hidden" + post "republish_file" + get "update_file_description" + post "edit_file_description" + end + end + resources :memberships, :shallow => true, :controller => 'contest_members', :only => [:index, :show, :new, :create, :update, :destroy] do + collection do + get 'autocomplete' + get 'appliedproject' + end + end + resources :news, :except => [:show, :edit, :update, :destroy] + end + #added by young resources :users do collection do @@ -604,6 +672,7 @@ RedmineApp::Application.routes.draw do match 'user_courses', :to => 'users#user_courses', :via => :get match 'user_courses4show', :to => 'users#user_courses4show', :via => :get match 'user_projects4show', :to => 'users#user_projects4show', :via => :get + match 'user_contests4show', :to => 'users#user_contests4show', :via => :get match 'user_course_activities', :to => 'users#user_course_activities', :via => :get match 'user_project_activities', :to => 'users#user_project_activities', :via => :get match 'user_feedback4show', :to => 'users#user_feedback4show', :via => :get @@ -647,6 +716,7 @@ RedmineApp::Application.routes.draw do #addby yk match 'user_courselist', :to => 'users#user_courselist', :via => :get, :as => "user_courselist" match 'user_projectlist', :to => 'users#user_projectlist', :via => :get, :as => "user_projectlist" + match 'user_contestlist', :to => 'users#user_contestlist', :via => :get, :as => "user_contestlist" match 'sort_syllabus_list', :to => 'users#sort_syllabus_list', :via => :get, :as => "sort_syllabus_list" match 'sort_project_list', :to => 'users#sort_project_list', :via => :get, :as => "sort_project_list" @@ -1357,6 +1427,8 @@ RedmineApp::Application.routes.draw do post 'words/:id/leave_syllabus_message', :to => 'words#leave_syllabus_message', :as => "leave_syllabus_message" post 'words/:id/leave_homework_message', :to => 'words#leave_homework_message', :as => "leave_homework_message" post 'words/:id/reply_to_homework', :to => 'words#reply_to_homework', :as => "reply_to_homework" + post 'words/:id/leave_contest_work_message', :to => 'words#leave_contest_work_message', :as => "leave_contest_work_message" + post 'words/:id/reply_to_contest_work', :to => 'words#reply_to_contest_work', :as => "reply_to_contest_work" post 'words/:id/reply_to_syllabus', :to => 'words#reply_to_syllabus', :as => "reply_to_syllabus" post 'join_in/join', :to => 'courses#join', :as => 'join' diff --git a/db/migrate/20140327071420_create_contests.rb b/db/migrate/20140327071420_create_contests.rb deleted file mode 100644 index 0ec04a6c5..000000000 --- a/db/migrate/20140327071420_create_contests.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CreateContests < ActiveRecord::Migration - def change - create_table :contests do |t| - t.string :name - t.integer :budget - t.integer :author_id - t.date :deadline - t.string :description - t.integer :commit - t.string :password - - t.timestamps - end - end -end diff --git a/db/migrate/20140327073052_create_contesting_projects.rb b/db/migrate/20140327073052_create_contesting_projects.rb deleted file mode 100644 index b9dc336b2..000000000 --- a/db/migrate/20140327073052_create_contesting_projects.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateContestingProjects < ActiveRecord::Migration - def change - create_table :contesting_projects do |t| - t.integer :project_id - t.string :contest_id - t.integer :user_id - t.string :description - - t.timestamps - end - end -end diff --git a/db/migrate/20140411003234_create_contesting_softapplications.rb b/db/migrate/20140411003234_create_contesting_softapplications.rb deleted file mode 100644 index 118b518f5..000000000 --- a/db/migrate/20140411003234_create_contesting_softapplications.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateContestingSoftapplications < ActiveRecord::Migration - def change - create_table :contesting_softapplications do |t| - t.integer :softapplication_id - t.integer :contest_id - t.integer :user_id - t.string :description - - t.timestamps - end - end -end diff --git a/db/migrate/20140530010015_create_contestnotifications.rb b/db/migrate/20140530010015_create_contestnotifications.rb deleted file mode 100644 index 5aa1e2f9f..000000000 --- a/db/migrate/20140530010015_create_contestnotifications.rb +++ /dev/null @@ -1,14 +0,0 @@ -class CreateContestnotifications < ActiveRecord::Migration - def change - create_table :contestnotifications do |t| - t.integer :contest_id - t.string :title - t.string :summary - t.string :description - t.integer :author_id - t.integer :notificationcomments_count - - t.timestamps - end - end -end diff --git a/db/migrate/20140722080529_create_contest_notifications.rb b/db/migrate/20140722080529_create_contest_notifications.rb deleted file mode 100644 index 0aff8d268..000000000 --- a/db/migrate/20140722080529_create_contest_notifications.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateContestNotifications < ActiveRecord::Migration - def change - create_table :contest_notifications do |t| - t.text :title - t.text :content - - t.timestamps - end - end -end diff --git a/db/migrate/20161220062249_create_contests.rb b/db/migrate/20161220062249_create_contests.rb new file mode 100644 index 000000000..decc45c55 --- /dev/null +++ b/db/migrate/20161220062249_create_contests.rb @@ -0,0 +1,26 @@ +class CreateContests < ActiveRecord::Migration + def change + #drop_table :contests + #drop_table :contest_notifications + #drop_table :contesting_projects + #drop_table :contesting_softapplications + #drop_table :contestnotifications + + create_table :contests do |t| + t.integer :user_id + t.string :name + t.text :description + t.boolean :is_public + t.boolean :is_delete, :default => false + t.integer :visits, :default => 0 + t.string :invite_code + t.integer :invite_code_halt, :default => 0 + + t.timestamps + end + + for i in 1 .. 779 + Contest.create(:user_id => 2, :is_public => false) + end + end +end diff --git a/db/migrate/20161220090638_create_contest_members.rb b/db/migrate/20161220090638_create_contest_members.rb new file mode 100644 index 000000000..e856024c4 --- /dev/null +++ b/db/migrate/20161220090638_create_contest_members.rb @@ -0,0 +1,14 @@ +class CreateContestMembers < ActiveRecord::Migration + def change + create_table :contest_members do |t| + t.references :user + t.references :contest + t.boolean :is_collect + t.boolean :is_current, :default => true + + t.timestamps + end + add_index :contest_members, :user_id + add_index :contest_members, :contest_id + end +end diff --git a/db/migrate/20161220090826_create_contest_member_roles.rb b/db/migrate/20161220090826_create_contest_member_roles.rb new file mode 100644 index 000000000..8b45b11cb --- /dev/null +++ b/db/migrate/20161220090826_create_contest_member_roles.rb @@ -0,0 +1,12 @@ +class CreateContestMemberRoles < ActiveRecord::Migration + def change + create_table :contest_member_roles do |t| + t.references :contest_member + t.references :role + + t.timestamps + end + add_index :contest_member_roles, :contest_member_id + add_index :contest_member_roles, :role_id + end +end diff --git a/db/migrate/20161220093609_create_contestant_for_contests.rb b/db/migrate/20161220093609_create_contestant_for_contests.rb new file mode 100644 index 000000000..8c5764e5a --- /dev/null +++ b/db/migrate/20161220093609_create_contestant_for_contests.rb @@ -0,0 +1,12 @@ +class CreateContestantForContests < ActiveRecord::Migration + def change + create_table :contestant_for_contests do |t| + t.integer :student_id + t.references :contest + + t.timestamps + end + add_index :contestant_for_contests, :contest_id + add_index :contestant_for_contests, :student_id + end +end diff --git a/db/migrate/20161221055334_create_works.rb b/db/migrate/20161221055334_create_works.rb new file mode 100644 index 000000000..d3c22de6b --- /dev/null +++ b/db/migrate/20161221055334_create_works.rb @@ -0,0 +1,21 @@ +class CreateWorks < ActiveRecord::Migration + def change + create_table :works do |t| + t.string :name + t.references :user + t.text :description + t.date :publish_time + t.date :end_time + t.integer :work_type + t.references :contest + t.boolean :is_delete, :default => false + t.boolean :score_open, :default => true + t.boolean :is_open, :default => false + t.integer :work_status + + t.timestamps + end + add_index :works, :user_id + add_index :works, :contest_id + end +end diff --git a/db/migrate/20161221060341_create_contest_activities.rb b/db/migrate/20161221060341_create_contest_activities.rb new file mode 100644 index 000000000..cbc601a91 --- /dev/null +++ b/db/migrate/20161221060341_create_contest_activities.rb @@ -0,0 +1,14 @@ +class CreateContestActivities < ActiveRecord::Migration + def change + create_table :contest_activities do |t| + t.references :user + t.references :contest + t.integer :contest_act_id + t.string :contest_act_type + + t.timestamps + end + add_index :contest_activities, :user_id + add_index :contest_activities, :contest_id + end +end diff --git a/db/migrate/20161221060853_create_contest_messages.rb b/db/migrate/20161221060853_create_contest_messages.rb new file mode 100644 index 000000000..90dff2111 --- /dev/null +++ b/db/migrate/20161221060853_create_contest_messages.rb @@ -0,0 +1,17 @@ +class CreateContestMessages < ActiveRecord::Migration + def change + create_table :contest_messages do |t| + t.references :user + t.references :contest + t.integer :contest_message_id + t.string :course_message_type + t.boolean :viewed, :default => false + t.text :content + t.integer :status + + t.timestamps + end + add_index :contest_messages, :user_id + add_index :contest_messages, :contest_id + end +end diff --git a/db/migrate/20161221065228_create_work_detail_groups.rb b/db/migrate/20161221065228_create_work_detail_groups.rb new file mode 100644 index 000000000..0479cfe06 --- /dev/null +++ b/db/migrate/20161221065228_create_work_detail_groups.rb @@ -0,0 +1,13 @@ +class CreateWorkDetailGroups < ActiveRecord::Migration + def change + create_table :work_detail_groups do |t| + t.references :work + t.integer :min_num + t.integer :max_num + t.boolean :base_on_project + + t.timestamps + end + add_index :work_detail_groups, :work_id + end +end diff --git a/db/migrate/20161221065841_create_contestant_works.rb b/db/migrate/20161221065841_create_contestant_works.rb new file mode 100644 index 000000000..f65bc15da --- /dev/null +++ b/db/migrate/20161221065841_create_contestant_works.rb @@ -0,0 +1,20 @@ +class CreateContestantWorks < ActiveRecord::Migration + def change + create_table :contestant_works do |t| + t.string :name + t.text :description + t.references :work + t.references :user + t.float :work_score + t.references :project + t.integer :work_status + t.timestamp :commit_time + t.boolean :is_delete, :default => false + + t.timestamps + end + add_index :contestant_works, :work_id + add_index :contestant_works, :user_id + add_index :contestant_works, :project_id + end +end diff --git a/db/migrate/20161221070253_create_contestant_work_projects.rb b/db/migrate/20161221070253_create_contestant_work_projects.rb new file mode 100644 index 000000000..aba5ab6ff --- /dev/null +++ b/db/migrate/20161221070253_create_contestant_work_projects.rb @@ -0,0 +1,18 @@ +class CreateContestantWorkProjects < ActiveRecord::Migration + def change + create_table :contestant_work_projects do |t| + t.references :contest + t.references :work + t.references :contestant_work + t.references :project + t.references :user + t.boolean :is_leader + + t.timestamps + end + add_index :contestant_work_projects, :contest_id + add_index :contestant_work_projects, :work_id + add_index :contestant_work_projects, :contestant_work_id + add_index :contestant_work_projects, :user_id + end +end diff --git a/db/migrate/20161221070623_create_contestant_work_scores.rb b/db/migrate/20161221070623_create_contestant_work_scores.rb new file mode 100644 index 000000000..770cd9dcf --- /dev/null +++ b/db/migrate/20161221070623_create_contestant_work_scores.rb @@ -0,0 +1,15 @@ +class CreateContestantWorkScores < ActiveRecord::Migration + def change + create_table :contestant_work_scores do |t| + t.references :contestant_work + t.references :user + t.integer :score + t.text :comment + t.integer :reviewer_role + + t.timestamps + end + add_index :contestant_work_scores, :contestant_work_id + add_index :contestant_work_scores, :user_id + end +end diff --git a/public/javascripts/contest.js b/public/javascripts/contest.js new file mode 100644 index 000000000..8633c9dbb --- /dev/null +++ b/public/javascripts/contest.js @@ -0,0 +1,28 @@ +/** + * Created by cxt on 2016/12/21. + */ + +//提交新建竞赛 +function submit_new_contest() +{ + if(regex_contest_name('new')) + { + $("#new_contest").submit(); + } +} + +//验证课程名称 +function regex_contest_name(str) +{ + var name = $.trim($("#"+str+"_course_name").val()); + if(name.length < 2) + { + $("#"+str+"_course_name_notice").show(); + return false; + } + else + { + $("#"+str+"_course_name_notice").hide(); + return true; + } +} diff --git a/spec/controllers/contest_members_controller_spec.rb b/spec/controllers/contest_members_controller_spec.rb new file mode 100644 index 000000000..abcbf4779 --- /dev/null +++ b/spec/controllers/contest_members_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ContestMembersController, :type => :controller do + +end diff --git a/spec/controllers/contestant_works_controller_spec.rb b/spec/controllers/contestant_works_controller_spec.rb new file mode 100644 index 000000000..f266cc1c8 --- /dev/null +++ b/spec/controllers/contestant_works_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ContestantWorksController, :type => :controller do + +end diff --git a/spec/controllers/contests_controller_spec.rb b/spec/controllers/contests_controller_spec.rb new file mode 100644 index 000000000..6e875cd5c --- /dev/null +++ b/spec/controllers/contests_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ContestsController, :type => :controller do + +end diff --git a/spec/controllers/works_controller_spec.rb b/spec/controllers/works_controller_spec.rb new file mode 100644 index 000000000..fddca1ab1 --- /dev/null +++ b/spec/controllers/works_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe WorksController, :type => :controller do + +end diff --git a/spec/factories/contest_activities.rb b/spec/factories/contest_activities.rb new file mode 100644 index 000000000..450ddd5bb --- /dev/null +++ b/spec/factories/contest_activities.rb @@ -0,0 +1,9 @@ +FactoryGirl.define do + factory :contest_activity do + user nil +contest nil +contest_act_id 1 +contest_act_type "MyString" + end + +end diff --git a/spec/factories/contest_member_roles.rb b/spec/factories/contest_member_roles.rb new file mode 100644 index 000000000..7c18d35ab --- /dev/null +++ b/spec/factories/contest_member_roles.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :contest_member_role do + contest_member nil +role nil + end + +end diff --git a/spec/factories/contest_members.rb b/spec/factories/contest_members.rb new file mode 100644 index 000000000..4222c915c --- /dev/null +++ b/spec/factories/contest_members.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :contest_member do + user nil +contest nil + end + +end diff --git a/spec/factories/contest_messages.rb b/spec/factories/contest_messages.rb new file mode 100644 index 000000000..156304087 --- /dev/null +++ b/spec/factories/contest_messages.rb @@ -0,0 +1,12 @@ +FactoryGirl.define do + factory :contest_message do + user nil +contest nil +contest_message_id 1 +course_message_type "MyString" +viewed false +content "MyText" +status 1 + end + +end diff --git a/spec/factories/contestant_for_contests.rb b/spec/factories/contestant_for_contests.rb new file mode 100644 index 000000000..61a889aab --- /dev/null +++ b/spec/factories/contestant_for_contests.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :contestant_for_contest do + student_id 1 +contest nil + end + +end diff --git a/spec/factories/contestant_work_projects.rb b/spec/factories/contestant_work_projects.rb new file mode 100644 index 000000000..4429d4ec5 --- /dev/null +++ b/spec/factories/contestant_work_projects.rb @@ -0,0 +1,11 @@ +FactoryGirl.define do + factory :contestant_work_project do + contest nil +work nil +contestant_work nil +project nil +user nil +is_leader false + end + +end diff --git a/spec/factories/contestant_work_scores.rb b/spec/factories/contestant_work_scores.rb new file mode 100644 index 000000000..d23fa8f3c --- /dev/null +++ b/spec/factories/contestant_work_scores.rb @@ -0,0 +1,10 @@ +FactoryGirl.define do + factory :contestant_work_score do + contestant_work nil +user nil +score 1 +comment "MyText" +reviewer_role 1 + end + +end diff --git a/spec/factories/contestant_works.rb b/spec/factories/contestant_works.rb new file mode 100644 index 000000000..6795be2c0 --- /dev/null +++ b/spec/factories/contestant_works.rb @@ -0,0 +1,14 @@ +FactoryGirl.define do + factory :contestant_work do + name "MyString" +description "MyText" +work nil +user nil +work_score 1.5 +project nil +work_status 1 +commit_time "2016-12-21 14:58:41" +is_delete false + end + +end diff --git a/spec/factories/contests.rb b/spec/factories/contests.rb new file mode 100644 index 000000000..b3a1c2e4e --- /dev/null +++ b/spec/factories/contests.rb @@ -0,0 +1,13 @@ +FactoryGirl.define do + factory :contest do + user_id 1 +name "MyString" +description "MyText" +is_public 1 +is_delete 1 +visits 1 +invite_code "MyString" +invite_code_halt 1 + end + +end diff --git a/spec/factories/work_detail_groups.rb b/spec/factories/work_detail_groups.rb new file mode 100644 index 000000000..7960c1f2b --- /dev/null +++ b/spec/factories/work_detail_groups.rb @@ -0,0 +1,9 @@ +FactoryGirl.define do + factory :work_detail_group do + work nil +min_num 1 +max_num 1 +base_on_project false + end + +end diff --git a/spec/factories/works.rb b/spec/factories/works.rb new file mode 100644 index 000000000..a2bccdd47 --- /dev/null +++ b/spec/factories/works.rb @@ -0,0 +1,16 @@ +FactoryGirl.define do + factory :work do + name "MyString" +user nil +description "MyText" +publish_time "2016-12-21" +end_time "2016-12-21" +work_type 1 +contest nil +is_delete false +score_open false +is_open false +work_status 1 + end + +end diff --git a/spec/models/contest_activity_spec.rb b/spec/models/contest_activity_spec.rb new file mode 100644 index 000000000..223d5ae49 --- /dev/null +++ b/spec/models/contest_activity_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ContestActivity, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/contest_member_role_spec.rb b/spec/models/contest_member_role_spec.rb new file mode 100644 index 000000000..d306f8a1c --- /dev/null +++ b/spec/models/contest_member_role_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ContestMemberRole, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/contest_member_spec.rb b/spec/models/contest_member_spec.rb new file mode 100644 index 000000000..b6867c64b --- /dev/null +++ b/spec/models/contest_member_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ContestMember, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/contest_message_spec.rb b/spec/models/contest_message_spec.rb new file mode 100644 index 000000000..3ea36df32 --- /dev/null +++ b/spec/models/contest_message_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ContestMessage, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/contest_spec.rb b/spec/models/contest_spec.rb new file mode 100644 index 000000000..16558959e --- /dev/null +++ b/spec/models/contest_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Contest, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/contestant_for_contest_spec.rb b/spec/models/contestant_for_contest_spec.rb new file mode 100644 index 000000000..8f428f8ba --- /dev/null +++ b/spec/models/contestant_for_contest_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ContestantForContest, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/contestant_work_project_spec.rb b/spec/models/contestant_work_project_spec.rb new file mode 100644 index 000000000..0a6522d65 --- /dev/null +++ b/spec/models/contestant_work_project_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ContestantWorkProject, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/contestant_work_score_spec.rb b/spec/models/contestant_work_score_spec.rb new file mode 100644 index 000000000..8c2d24166 --- /dev/null +++ b/spec/models/contestant_work_score_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ContestantWorkScore, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/contestant_work_spec.rb b/spec/models/contestant_work_spec.rb new file mode 100644 index 000000000..96ac28487 --- /dev/null +++ b/spec/models/contestant_work_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ContestantWork, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/work_detail_group_spec.rb b/spec/models/work_detail_group_spec.rb new file mode 100644 index 000000000..5d1fb345a --- /dev/null +++ b/spec/models/work_detail_group_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe WorkDetailGroup, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/work_spec.rb b/spec/models/work_spec.rb new file mode 100644 index 000000000..dcd60a5e7 --- /dev/null +++ b/spec/models/work_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Work, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/test/fixtures/contest_notifications.yml b/test/fixtures/contest_notifications.yml deleted file mode 100644 index 71f88b98c..000000000 --- a/test/fixtures/contest_notifications.yml +++ /dev/null @@ -1,9 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -one: - title: MyString - content: MyString - -two: - title: MyString - content: MyString diff --git a/test/fixtures/contesting_softapplications.yml b/test/fixtures/contesting_softapplications.yml deleted file mode 100644 index 8cdde9d08..000000000 --- a/test/fixtures/contesting_softapplications.yml +++ /dev/null @@ -1,13 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -one: - softapplication_id: 1 - contest_id: 1 - user_id: 1 - description: MyString - -two: - softapplication_id: 1 - contest_id: 1 - user_id: 1 - description: MyString diff --git a/test/fixtures/contestnotifications.yml b/test/fixtures/contestnotifications.yml deleted file mode 100644 index 1bffa73a2..000000000 --- a/test/fixtures/contestnotifications.yml +++ /dev/null @@ -1,17 +0,0 @@ -# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html - -one: - contest_id: 1 - title: MyString - summary: MyString - description: MyString - author_id: 1 - comments_count: 1 - -two: - contest_id: 1 - title: MyString - summary: MyString - description: MyString - author_id: 1 - comments_count: 1 diff --git a/test/functional/contestnotifications_controller_test.rb b/test/functional/contestnotifications_controller_test.rb deleted file mode 100644 index 2873cceeb..000000000 --- a/test/functional/contestnotifications_controller_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'test_helper' - -class ContestnotificationsControllerTest < ActionController::TestCase - setup do - @contestnotification = contestnotifications(:one) - end - - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:contestnotifications) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create contestnotification" do - assert_difference('Contestnotification.count') do - post :create, contestnotification: { author_id: @contestnotification.author_id, comments_count: @contestnotification.comments_count, contest_id: @contestnotification.contest_id, description: @contestnotification.description, summary: @contestnotification.summary, title: @contestnotification.title } - end - - assert_redirected_to contestnotification_path(assigns(:contestnotification)) - end - - test "should show contestnotification" do - get :show, id: @contestnotification - assert_response :success - end - - test "should get edit" do - get :edit, id: @contestnotification - assert_response :success - end - - test "should update contestnotification" do - put :update, id: @contestnotification, contestnotification: { author_id: @contestnotification.author_id, comments_count: @contestnotification.comments_count, contest_id: @contestnotification.contest_id, description: @contestnotification.description, summary: @contestnotification.summary, title: @contestnotification.title } - assert_redirected_to contestnotification_path(assigns(:contestnotification)) - end - - test "should destroy contestnotification" do - assert_difference('Contestnotification.count', -1) do - delete :destroy, id: @contestnotification - end - - assert_redirected_to contestnotifications_path - end -end diff --git a/test/unit/contest_notification_test.rb b/test/unit/contest_notification_test.rb deleted file mode 100644 index cf4ebf363..000000000 --- a/test/unit/contest_notification_test.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'test_helper' - -<<<<<<< HEAD:test/unit/applied_project_test.rb -class AppliedProjectTest < ActiveSupport::TestCase -======= -class ContestNotificationTest < ActiveSupport::TestCase ->>>>>>> a09a3dc378c45f43f5c4b090479fa292a846f4f0:test/unit/contest_notification_test.rb - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/contesting_softapplication_test.rb b/test/unit/contesting_softapplication_test.rb deleted file mode 100644 index a805392f0..000000000 --- a/test/unit/contesting_softapplication_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class ContestingSoftapplicationTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/contestnotification_test.rb b/test/unit/contestnotification_test.rb deleted file mode 100644 index efff724e9..000000000 --- a/test/unit/contestnotification_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class ContestnotificationTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/helpers/contestnotifications_helper_test.rb b/test/unit/helpers/contestnotifications_helper_test.rb deleted file mode 100644 index e4dc64783..000000000 --- a/test/unit/helpers/contestnotifications_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class ContestnotificationsHelperTest < ActionView::TestCase -end