diff --git a/Gemfile b/Gemfile index e40c468aa..758ef59dd 100644 --- a/Gemfile +++ b/Gemfile @@ -4,9 +4,9 @@ unless RUBY_PLATFORM =~ /w32/ # unix-like only gem 'iconv' if RUBY_PLATFORM =~ /darwin/ - gem "rmagick", "= 2.15.4" ## osx must be this version + # gem "rmagick", "= 2.15.4" ## osx must be this version elsif RUBY_PLATFORM =~ /linux/ - gem "rmagick", "~> 2.13.1" ## centos yum install ImageMagick-devel + # gem "rmagick", "~> 2.13.1" ## centos yum install ImageMagick-devel end gem 'certified' gem 'net-ssh', '2.9.1' diff --git a/app/assets/javascripts/training_tasks.js.coffee b/app/assets/javascripts/training_tasks.js.coffee new file mode 100644 index 000000000..b3f5f376b --- /dev/null +++ b/app/assets/javascripts/training_tasks.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/training_tasks.css.scss b/app/assets/stylesheets/training_tasks.css.scss new file mode 100644 index 000000000..5a071ec72 --- /dev/null +++ b/app/assets/stylesheets/training_tasks.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the training_tasks 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/account_controller.rb b/app/controllers/account_controller.rb index 9d8a5ecc5..4c7d578ba 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -279,6 +279,14 @@ class AccountController < ApplicationController render :json => result end + def change_email + user = User.find params[:user_id].to_i + user.update_attributes(:mail => params[:value]) + result = {:email => user.mail} + + render :json => result + end + def email_activation diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index c2499e824..9d51e5839 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -978,7 +978,11 @@ class AdminController < ApplicationController #作业 def homework #@homework = HomeworkCommon.order('end_time desc') - @homework = HomeworkCommon.order( 'created_at desc ') + if params[:type] == "2" + @homework = HomeworkCommon.where(:homework_type => 2).order( 'created_at desc ') + else + @homework = HomeworkCommon.order( 'created_at desc ') + end @homework = paginateHelper @homework,30 @page = (params['page'] || 1).to_i - 1 respond_to do |format| diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cd989ef2d..8a3445494 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -312,7 +312,11 @@ class ApplicationController < ActionController::Base def authorize_allowed(ctrl = params[:controller], action = params[:action], global = false) #modify by NWB if @project - allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global) + if ctrl == "repositories" && action == "show" && @project.hidden_repo + allowed = User.current.admin? || (User.current.member_of?(@project) && !(role_of_members_in_project(@project.id, User.current.id) == "Reporter")) + else + allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global) + end elsif @course allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @course || @courses, :global => global) else diff --git a/app/controllers/at_controller.rb b/app/controllers/at_controller.rb index 66cbf27b8..81d678261 100644 --- a/app/controllers/at_controller.rb +++ b/app/controllers/at_controller.rb @@ -29,6 +29,8 @@ class AtController < ApplicationController case type when "Issue" find_issue(id) + whne 'TrainingTask' + find_training_task(id) when 'Project' find_project(id) when 'Course' @@ -69,6 +71,13 @@ class AtController < ApplicationController at_persons.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id } end + def find_training_task(id) + training_task = TrainingTask.find(id) + journals = training_task.journals + at_persons = journals.map(&:user) + training_task.project.users + at_persons.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id } + end + def find_project(id) return [] if id.to_i<0 at_persons = Project.find(id).users diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 8eff74041..0f5a55ab9 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -143,7 +143,7 @@ class ForumsController < ApplicationController reorder(order). preload(:author, {:last_reply => :author}). all - @forums = Forum.reorder("topic_count desc,updated_at desc") + @forums = Forum.find_by_sql("SELECT *,topic_count + memo_count tm FROM `forums` order by tm desc;") @my_forums_count = Memo.where("author_id =? and parent_id is null", User.current.id).count @my_memos_count = Memo.where("author_id =? and parent_id is not null", User.current.id).count @errors = params[:errors] diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index 3e3c338b4..a60b85b90 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -1,166 +1,168 @@ -class PraiseTreadController < ApplicationController - - accept_api_auth :tread_plus,:praise_plus - # before_filter :require_login,:only => [:praise_plus,:tread_plus] - before_filter :user_unlogged_check,:only => [:praise_plus,:tread_plus,:praise_minus] - - def praise_plus - @obj = nil - @activity = false - if request.get? - @obj_id = params[:obj_id] - @obj_type = params[:obj_type] - if !params[:user_activity_id].nil? && !params[:type].nil? - @user_activity_id = params[:user_activity_id] - @type = params[:type] - @activity = true - end - # @is_in_list = nil - @obj = find_object_by_type_and_id(@obj_type,@obj_id) - pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id) - unless pts.empty? - respond_to do |format| - format.js - end - return - end - @horizontal = params[:horizontal].downcase == "false" ? false:true if params[:horizontal] - # if @obj.respond_to?("author_id") - # author_id = @obj.author_id - # elsif @obj.respond_to?("user_id") - # author_id = @obj.user_id - # end - # unless author_id == User.current.id - praise_tread_plus(@obj_type,@obj_id,1) - # end - respond_to do |format| - format.js - end - end - end - - def praise_minus - @obj = nil - @activity = false - if request.get? - #@obj = params[:obj] # 传的是对象,最后变成id了 - #首先更新praise_tread 表 删除关注记录 - #@pt = PraiseTread.find_by_user_id_and_praise_tread_object_id_and_praise_tread_object_type(User.current.id,@obj,"user") - @obj_id = params[:obj_id] - @obj_type = params[:obj_type] - if !params[:user_activity_id].nil? && !params[:type].nil? - @user_activity_id = params[:user_activity_id] - @type = params[:type] - @activity = true - end - @obj = find_object_by_type_and_id(@obj_type,@obj_id) - @pt = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id).first - if @pt.nil? - respond_to do |format| - format.js - end - return - end - @pt.delete if !@pt.nil? - #再更新praise_tread_cache表 使相应的记录减1 当为0时删除 - @ptc = PraiseTreadCache.where("object_id=? and object_type=?",@obj_id,@obj_type.to_s).first - @ptc.minus(1) if !@ptc.nil? - if @ptc.praise_num == 0 - @ptc.delete - end - - end - #@obj = User.find_by_id(@obj) - respond_to do |format| - format.js - end - end - - def tread_plus - @obj = nil - # @is_in_list = nil - if request.get? - @obj_id = params[:obj_id] - @obj_type = params[:obj_type] - #@horizontal = params[:horizontal].downcase == "false" ? false:true - @obj = find_object_by_type_and_id(@obj_type,@obj_id) - unless @obj.author_id == User.current.id - praise_tread_plus(@obj_type,@obj_id,0) - end - - end - end - - def tread_minus - respond_to do |format| - format.html - format.js - end - end - - private - - def find_object_by_type_and_id(type,id) - @obj = nil - case type - when 'Memo' - @obj = Memo.find_by_id(id) - when 'Message' - @obj = Message.find_by_id(id) - when 'HomeworkCommon' - @obj = HomeworkCommon.find_by_id(id) - when 'JournalsForMessage' - @obj = JournalsForMessage.find_by_id(id) - when 'News' - @obj = News.find_by_id(id) - when 'Comment' - @obj = Comment.find_by_id(id) - when 'Journal' - @obj = Journal.find_by_id(id) - when 'BlogComment' - @obj = BlogComment.find_by_id(id) - when 'OrgDocumentComment' - @obj = OrgDocumentComment.find_by_id(id) - when 'User' - @obj = User.find_by_id(id) - when 'Issue' - @obj = Issue.find_by_id(id) - when 'Project' - @obj = Project.find_by_id(id) - when 'Bid' - @obj = Bid.find_by_id(id) - when 'Contest' - @obj = Contest.find_by_id(id) - when 'Syllabus' - @obj = Syllabus.find_by_id(id) - when 'Work' - @obj = Work.find_by_id(id) - else - @obj = nil - end - return @obj - end - - def praise_tread_plus(type,id,flag) - unless id.nil? and type.nil? - #首先创建或更新praise_tread 表 - @pt = PraiseTread.new - @pt.user_id = User.current.id - @pt.praise_tread_object_id = id.to_i - @pt.praise_tread_object_type = type - @pt.praise_or_tread = flag - @pt.save - # end - - #再创建或更新praise_tread_cache表 - #@ptc = PraiseTreadCache.find_by_object_id_and_object_type(id,type) - @ptc = PraiseTreadCache.where("object_id = ? and object_type = ?",id.to_i,type).first - @ptc = @ptc.nil? ? PraiseTreadCache.new : @ptc - @ptc.object_id = id.to_i - @ptc.object_type = type - @ptc.save - @ptc.plus(flag,1) - end - end - -end +class PraiseTreadController < ApplicationController + + accept_api_auth :tread_plus,:praise_plus + # before_filter :require_login,:only => [:praise_plus,:tread_plus] + before_filter :user_unlogged_check,:only => [:praise_plus,:tread_plus,:praise_minus] + + def praise_plus + @obj = nil + @activity = false + if request.get? + @obj_id = params[:obj_id] + @obj_type = params[:obj_type] + if !params[:user_activity_id].nil? && !params[:type].nil? + @user_activity_id = params[:user_activity_id] + @type = params[:type] + @activity = true + end + # @is_in_list = nil + @obj = find_object_by_type_and_id(@obj_type,@obj_id) + pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id) + unless pts.empty? + respond_to do |format| + format.js + end + return + end + @horizontal = params[:horizontal].downcase == "false" ? false:true if params[:horizontal] + # if @obj.respond_to?("author_id") + # author_id = @obj.author_id + # elsif @obj.respond_to?("user_id") + # author_id = @obj.user_id + # end + # unless author_id == User.current.id + praise_tread_plus(@obj_type,@obj_id,1) + # end + respond_to do |format| + format.js + end + end + end + + def praise_minus + @obj = nil + @activity = false + if request.get? + #@obj = params[:obj] # 传的是对象,最后变成id了 + #首先更新praise_tread 表 删除关注记录 + #@pt = PraiseTread.find_by_user_id_and_praise_tread_object_id_and_praise_tread_object_type(User.current.id,@obj,"user") + @obj_id = params[:obj_id] + @obj_type = params[:obj_type] + if !params[:user_activity_id].nil? && !params[:type].nil? + @user_activity_id = params[:user_activity_id] + @type = params[:type] + @activity = true + end + @obj = find_object_by_type_and_id(@obj_type,@obj_id) + @pt = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",@obj_id,@obj_type.to_s,User.current.id).first + if @pt.nil? + respond_to do |format| + format.js + end + return + end + @pt.delete if !@pt.nil? + #再更新praise_tread_cache表 使相应的记录减1 当为0时删除 + @ptc = PraiseTreadCache.where("object_id=? and object_type=?",@obj_id,@obj_type.to_s).first + @ptc.minus(1) if !@ptc.nil? + if @ptc.praise_num == 0 + @ptc.delete + end + + end + #@obj = User.find_by_id(@obj) + respond_to do |format| + format.js + end + end + + def tread_plus + @obj = nil + # @is_in_list = nil + if request.get? + @obj_id = params[:obj_id] + @obj_type = params[:obj_type] + #@horizontal = params[:horizontal].downcase == "false" ? false:true + @obj = find_object_by_type_and_id(@obj_type,@obj_id) + unless @obj.author_id == User.current.id + praise_tread_plus(@obj_type,@obj_id,0) + end + + end + end + + def tread_minus + respond_to do |format| + format.html + format.js + end + end + + private + + def find_object_by_type_and_id(type,id) + @obj = nil + case type + when 'Memo' + @obj = Memo.find_by_id(id) + when 'Message' + @obj = Message.find_by_id(id) + when 'HomeworkCommon' + @obj = HomeworkCommon.find_by_id(id) + when 'JournalsForMessage' + @obj = JournalsForMessage.find_by_id(id) + when 'News' + @obj = News.find_by_id(id) + when 'Comment' + @obj = Comment.find_by_id(id) + when 'Journal' + @obj = Journal.find_by_id(id) + when 'BlogComment' + @obj = BlogComment.find_by_id(id) + when 'OrgDocumentComment' + @obj = OrgDocumentComment.find_by_id(id) + when 'User' + @obj = User.find_by_id(id) + when 'Issue' + @obj = Issue.find_by_id(id) + when 'TrainingTask' + @obj = TrainingTask.find_by_id(id) + when 'Project' + @obj = Project.find_by_id(id) + when 'Bid' + @obj = Bid.find_by_id(id) + when 'Contest' + @obj = Contest.find_by_id(id) + when 'Syllabus' + @obj = Syllabus.find_by_id(id) + when 'Work' + @obj = Work.find_by_id(id) + else + @obj = nil + end + return @obj + end + + def praise_tread_plus(type,id,flag) + unless id.nil? and type.nil? + #首先创建或更新praise_tread 表 + @pt = PraiseTread.new + @pt.user_id = User.current.id + @pt.praise_tread_object_id = id.to_i + @pt.praise_tread_object_type = type + @pt.praise_or_tread = flag + @pt.save + # end + + #再创建或更新praise_tread_cache表 + #@ptc = PraiseTreadCache.find_by_object_id_and_object_type(id,type) + @ptc = PraiseTreadCache.where("object_id = ? and object_type = ?",id.to_i,type).first + @ptc = @ptc.nil? ? PraiseTreadCache.new : @ptc + @ptc.object_id = id.to_i + @ptc.object_type = type + @ptc.save + @ptc.plus(flag,1) + end + end + +end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 43923f6bb..cf1a71424 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -29,7 +29,7 @@ class ProjectsController < ApplicationController menu_item :share, :only => :share before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise, - :view_homework_attaches,:join_project, :project_home] + :view_homework_attaches,:join_project, :project_home, :training_execute, :training_task_status] before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course] before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches] before_filter :require_admin, :only => [ :copy, :unarchive, :destroy, :calendar] @@ -332,9 +332,11 @@ class ProjectsController < ApplicationController if User.current.member_of?(@project) || User.current.admin? case params[:type] when nil - @events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'Project', 'Attachment','Commit')", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) + @events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'TrainingTask','Message','News', 'Project', 'Attachment','Commit')", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) when 'issue' @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Issue'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) + when 'training_task' + @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'TrainingTask'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) when 'news' @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'News'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) when 'message' @@ -379,7 +381,9 @@ class ProjectsController < ApplicationController def settings # 顶部导航 @project_menu_type = 10 - + if @project.is_child_training_project? + return render_404 + end # 修改查看消息状态 applied_messages = ForgeMessage.where("user_id =? and project_id =? and forge_message_type =? and viewed =?", User.current.id, @project, "AppliedProject", 0) applied_messages.update_all(:viewed => true) @@ -765,6 +769,18 @@ class ProjectsController < ApplicationController end end + def add_script + if User.current.admin? || User.current.member_of?(@project) + if @project.update_attribute(:script, params[:project_script]) + @notice = "脚本添加成功" + else + @notice = "脚本添加失败" + end + else + return render_403 + end + end + def modules @project.enabled_module_names = params[:enabled_module_names] flash[:notice] = l(:notice_successful_update) @@ -805,6 +821,231 @@ class ProjectsController < ApplicationController redirect_to admin_projects_url(:status => params[:status]) end + # 弹框提醒: + # 自己不能参加自己的实训项目 + # 没有建立版本库的项目不能开启实训 + # 已经实训过直接跳入 + # + def training_chiled_project_exec + respond_to do |format| + format.js + end + end + + # training_status: 默认为0; 1代表实训项目; 2:代表实训子项目 + def training_project_execute + if @project.training_tasks.count == 0 + @notice = "实训开启失败:请先发布实训任务" + return + elsif Repository.where(:project_id => @project.id, :type => "Repository::Gitlab").count == 0 + @notice = "实训开启失败:请先创建版本库" + return + end + jobName = "#{@project.id}" + pipeLine = "#{Base64.encode64(@project.script)}" + uri = URI("http://123.59.135.74:9999/jenkins-exec/api/createJob") + params = {jobName: jobName, pipeLine: pipeLine} + res = uri_exec uri, params + training_project_notice res + @project.update_attribute(:training_status, 1) + end + + def training_project_update + jobName = "#{@project.id}" + pipeLine = "#{Base64.encode64(@project.script)}" + uri = URI("http://123.59.135.74:9999/jenkins-exec/api/updateJob") + params = {jobName: jobName, pipeLine: pipeLine} + res = uri_exec uri, params + training_project_notice res + @project.update_attribute(:training_status, 1) + end + + def training_project_notice res + if res['code'] == 0 + @notice = "实训开启成功" + elsif res['code'] == -2 + @notice = "Job已存在" + else + @notice = res['msg'].nil? ? "实训开启失败" : res['msg'] + end + end + + # TrainintTask.status 0:评测中 1:评测成功 2:评测惊醒中 + # 非项目成员、非实训子项目不允许执行该方法 + def task_execute + if !@project.is_child_training_project? || !User.current.member_of?(@project) + return render_403 + end + taskId = params[:training_task_id] + jobName = @project.forked_from_project_id + @training_task = TrainingTask.find(taskId) + if @training_task.status == 0 + params = {:jobName => "#{jobName}", :taskId => "#{taskId}"} + uri = URI.parse("http://123.59.135.74:9999/jenkins-exec/api/buildJob") + begin + res = uri_exec uri, params + # 任务开启成功后创建一条留言提示,并发布 + @training_task.update_attribute(:status, 2) + return + rescue Exception => e + puts e + end + end + end + + def uri_exec uri, params + res = Net::HTTP.post_form(uri, params).body + res = JSON.parse(res) + end + + # 开启实训项目,学生会fork一个项目并自动发送任务 + def training_project_extend + @project = Project.find(params[:id]) + @repository = Repository.where("project_id =? and type =?", @project.id, "Repository::Gitlab") + # 如果当前用户已经fork过该项目,不会新fork项目,则跳至已fork的项 + unless has_forked?(@project, User.current) + project = project_from_current_project(@project.id, User.current.id) + redirect_to project_path(project) + else + ActiveRecord::Base.transaction do + g = Gitlab.client + if User.current.gid.nil? + s = Trustie::Gitlab::Sync.new + s.sync_user(User.current) + end + gproject = g.fork(@project.gpid, User.current.gid) + if gproject + new_training_project = copy_project_and_module(@project, gproject) + forked_count = @project.forked_count.to_i + 1 + @project.update_attributes(:forked_count => forked_count) + # 发布实训任务,只发布实训任务的第一个 + publish_training_tasks(@project.id, new_training_project.id, 1) + end + end + end + end + + # 需要传Task ID + # 判断任务是否完成 + # 如果完成则发送下一个任务直到任务结束 + # TrainingTask.status 1 成功,其它失败 + def training_task_status + status = params[:status].to_i + task_id = params[:taskId] + message = params[:msg].to_i + begin + @training_task = TrainingTask.find(task_id) + # 如果已经执行成功过,则不重复执行 + return if @training_task.status == 1 + original_project_id = Project.find(@training_task.project_id).try(:forked_from_project_id) + original_project = Project.find(original_project_id) + rescue + return + end + original_tasks_count = original_project.training_tasks.count + position = @training_task.try(:position) + 1 + # 测试,默认成功 + if status == 0 + ActiveRecord::Base.transaction do + if position <= original_tasks_count + # 继续发布下一个任务 + publish_training_tasks original_project_id, @training_task.project_id, position + @training_task.update_attribute(:status, 1) + end + # 创建一条回复提醒 + content = "恭喜您通过测评" + add_training_task_journal(content, original_project.user_id) + end + else + content = "很遗憾,您没有通过该步" + add_training_task_journal(content, original_project.user_id) + end + end + + # 创建一条回复 + def add_training_task_journal content, user_id + jour = Journal.new + jour.user_id = user_id + jour.notes = content + jour.journalized = @training_task + jour.save + update_user_activity(@training_task.class, @training_task.id) + update_forge_activity(@training_task.class, @training_task.id) + end + + # 实训开启成功后,发布第一个任务 + # REDO:失败后提醒用户,及相关处理 + def publish_training_tasks original_project_id, new_training_project_id, position + original_task = TrainingTask.where(:project_id => original_project_id, :position => position).first + training_task = TrainingTask.new + training_task.save_attachments(params[:attachments] || (params[:training_task] && params[:training_task][:uploads])) + training_task.subject = original_task.subject + training_task.description = original_task.description + training_task.position = original_task.position + training_task.project_id = new_training_project_id + training_task.author_id = User.current.id + if training_task.save + respond_to do |format| + format.html{redirect_to project_url(new_training_project_id)} + end + else + raise "create task failed" + end + end + + # 复制项目 + def copy_project_and_module tproject, gproject + project = Project.new + project.name = tproject.name + project.is_public = tproject.is_public + project.status = tproject.status + project.description = tproject.description + project.hidden_repo = tproject.hidden_repo + project.user_id = User.current.id + project.project_type = 0 + project.project_new_type = tproject.project_new_type + project.gpid = gproject.id + project.forked_from_project_id = tproject.id + project.enabled_module_names = tproject.enabled_module_names + if project.save + project.update_attribute(:training_status,2) + r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first + m = Member.new(:user => User.current, :roles => [r]) + if ProjectScore.where("project_id=?", project.id).first.nil? + ProjectScore.create(:project_id => project.id, :score => false) + end + project_info = ProjectInfo.new(:user_id => User.current.id, :project_id => project.id) + user_grades = UserGrade.create(:user_id => User.current.id, :project_id => project.id) + Rails.logger.debug "UserGrade created: #{user_grades.to_json}" + project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @project.project_type,:grade => 0) + Rails.logger.debug "ProjectStatus created: #{project_status.to_json}" + project.members << m + project.project_infos << project_info + copy_repository(project, gproject) + return project + else + respond_to do |format| + format.html { render :action => 'forked', :layout => 'base_projects'} + format.api { render_validation_errors(@project) } + end + end + end + + # 判断用户是否已经fork过该项目 + def has_forked?(project, user) + projects = Project.where("user_id =?", user) + projects.map(&:forked_from_project_id).detect{|s| s == @project.id}.nil? ? true : false + end + + def copy_repository(project, gproject) + repository = Repository.factory('Git') + repository.project_id = project.id + repository.type = 'Repository::Gitlab' + repository.url = gproject.name + repository.identifier = gproject.name + repository = repository.save + end + # 资源库fork弹框 def forked_pop respond_to do |format| diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index a955fa88b..35fde54ac 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -35,12 +35,13 @@ class RepositoriesController < ApplicationController before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo, :stats, :quality_analysis] before_filter :find_repository, :only => [:edit, :update, :destroy, :committers] - before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked, :export_rep_static] + before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo, :to_gitlab, :forked, :export_rep_static, :training_project_extend] # 连接gitlab # before_filter :connect_gitlab, :only => [:quality_analysis, :commit_diff] before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue] - before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff] + # before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff] + before_filter :authorize_visible , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff] # 版本库新增权限 # before_filter :show_rep, :only => [:show, :stats, :revisions, :revision, :diff, :commit_diff ] accept_rss_auth :revisions @@ -132,6 +133,94 @@ class RepositoriesController < ApplicationController # send_file "/path/to/file.zip" end + # 开启实训项目,学生会fork一个项目并自动发送任务 + def training_project_extend + @project = Project.find(params[:id]) + @repository = Repository.where("project_id =? and type =?", @project.id, "Repository::Gitlab") + # 如果当前用户已经fork过该项目,不会新fork项目,则跳至已fork的项 + unless has_forked?(@project, User.current) + project = project_from_current_project(@project.id, User.current.id) + redirect_to project_path(project) + else + ActiveRecord::Base.transaction do + g = Gitlab.client + if User.current.gid.nil? + begin + s = Trustie::Gitlab::Sync.new + s.sync_user(User.current) + ensure + logger.error "Syn user failed ==>#{User.current.id}" + end + end + gproject = g.fork(@project.gpid, User.current.gid) + if gproject + new_training_project = copu_project_and_module(@project, gproject) + forked_count = @project.forked_count.to_i + 1 + @project.update_attributes(:forked_count => forked_count) + # 发布实训任务,只发布实训任务的第一个 + publish_training_tasks(@project, new_training_project) + end + end + end + end + + def copu_project_and_module tproject, gproject + project = Project.new + project.name = tproject.name + project.is_public = tproject.is_public + project.status = tproject.status + project.description = tproject.description + project.hidden_repo = tproject.hidden_repo + project.user_id = User.current.id + project.project_type = 0 + project.project_new_type = tproject.project_new_type + project.gpid = gproject.id + project.forked_from_project_id = tproject.id + project.enabled_module_names = tproject.enabled_module_names + if project.save + project.update_attribute(:training_status,1) + r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first + m = Member.new(:user => User.current, :roles => [r]) + if ProjectScore.where("project_id=?", project.id).first.nil? + ProjectScore.create(:project_id => project.id, :score => false) + end + project_info = ProjectInfo.new(:user_id => User.current.id, :project_id => project.id) + user_grades = UserGrade.create(:user_id => User.current.id, :project_id => project.id) + Rails.logger.debug "UserGrade created: #{user_grades.to_json}" + project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @project.project_type,:grade => 0) + Rails.logger.debug "ProjectStatus created: #{project_status.to_json}" + project.members << m + project.project_infos << project_info + copy_repository(project, gproject) + return project + else + respond_to do |format| + format.html { render :action => 'forked', :layout => 'base_projects'} + format.api { render_validation_errors(@project) } + end + end + end + + # REDO: 如果实训项目还没有创建任务的时候应该跳出 + def publish_training_tasks original_project, new_training_project + original_task = TrainingTask.where(:project_id => original_project.id, :position => 1).first + training_task = TrainingTask.new + training_task.save_attachments(params[:attachments] || (params[:training_task] && params[:training_task][:uploads])) + training_task.subject = original_task.subject + training_task.description = original_task.description + training_task.position = original_task.position + training_task.project_id = new_training_project.id + training_task.author_id = User.current.id + if training_task.save + respond_to do |format| + format.html{redirect_to project_training_tasks_url(:project_id => new_training_project.id)} + end + else + raise "create task failed" + end + end + + # 判断用户是否已经fork过该项目 def has_forked?(project, user) projects = Project.where("user_id =?", user) @@ -183,6 +272,7 @@ class RepositoriesController < ApplicationController format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => project.id) } format.js end + return project else respond_to do |format| format.html { render :action => 'forked', :layout => 'base_projects'} @@ -396,11 +486,12 @@ update redirect_to :controller => 'repositories', :action => 'show', :id => @project.id, to: 'gitlab' end + # 权限: + # 如果项目隐藏了版本库,则非项目成员及项目报告人员不能够访问版本库 + # 如果没有隐藏版本库,只要项目公开,其它成员都可以看到版本库 + # 项目关联了课程,课程的老师是可以看到版本库的 + # 超级管理员可以看到项目版本库 def show - if !User.current.admin? && (@project.hidden_repo && (role_of_members_in_project(@project.id, User.current.id) == "Reporter" || !is_project_member?(User.current.id, @project.id))) - render_403 - return - else # 顶部导航 @project_menu_type = 5 @@ -410,7 +501,6 @@ update if request.xhr? @entries ? render(:partial => 'dir_list_content') : render(:nothing => true) else - unless @entries.blank? @changesets_latest_coimmit = @g.rep_last_changes(@project.gpid, :rev => @rev, :path => @path) # @g.rep_last_changes(@project.gpid, :rev => @rev, :path => @path) # 总的提交数 @@ -426,7 +516,6 @@ update # token值解密 # gitlab_token = aes_dicrypt("priEn3UwXfJs3Pmy", token) @zip_path = Gitlab.endpoint.to_s + "/projects/" + @project.gpid.to_s + "/repository/archive?&private_token=" + token - end @creator = @project.owner.to_s gitlab_address = Redmine::Configuration['gitlab_address'] @@ -448,7 +537,6 @@ update render :layout => 'base_projects' end end - end alias_method :browse, :show @@ -698,6 +786,19 @@ update end end + def authorize_visible + allowed = authorize_allowed(params[:controller], params[:action], global = false) + if allowed || User.current.admin? || (@project.hidden_repo && User.current.member_of?(@project) && !role_of_members_in_project(@project.id, User.current.id) == "Reporter") + true + else + if @project && @project.archived? + render_403 :message => :notice_not_authorized_archived_project + else + deny_access + end + end + end + private # 更新项目统计数 def update_commits_count project, count diff --git a/app/controllers/training_tasks_controller.rb b/app/controllers/training_tasks_controller.rb new file mode 100644 index 000000000..115754ff2 --- /dev/null +++ b/app/controllers/training_tasks_controller.rb @@ -0,0 +1,388 @@ +# encoding: utf-8 +class TrainingTasksController < ApplicationController + + layout 'base_projects' + before_filter :find_project, :only => [:index, :new, :create, :update_form, :issue_commits, :commit_for_issue, :issue_commit_delete, :destroy] + before_filter :allow_manager, :only => [:index, :show] + before_filter :allow_members, :only => [:new, :create] + before_filter :build_new_task_from_params, :only => [:new, :create, :update_form] + before_filter :find_training_task, :only => [:show, :edit, :update, :add_journal, :complete_training_task] + + # before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy] + + # before_filter :authorize, :except => [:index, :show] + # before_filter :authorize, :except => [:new, :index,:add_journal, :add_journal_in_org,:delete_journal,:reply,:add_reply, :issue_commits, :commit_for_issue, :issue_commit_delete] + + before_filter :check_for_default_issue_status, :only => [:new, :create] + before_filter :build_new_task_from_params, :only => [:new, :create, :update_form] + accept_rss_auth :index, :show + accept_api_auth :index, :show, :create, :update, :destroy + + rescue_from Query::StatementInvalid, :with => :query_statement_invalid + + helper :journals + helper :projects + include ProjectsHelper + helper :custom_fields + include CustomFieldsHelper + helper :issue_relations + include IssueRelationsHelper + helper :watchers + include WatchersHelper + helper :attachments + include AttachmentsHelper + helper :queries + include QueriesHelper + helper :repositories + include RepositoriesHelper + helper :sort + include SortHelper + include IssuesHelper + helper :timelog + include Redmine::Export::PDF + helper :project_score + include ApplicationHelper + + def issue_commit_delete + commit_id = params[:commit_id].split(",") + issue_commit_ids = params[:issue_commit_ids] + # issue_id存在则为issue详情或者编辑的时候,否则为新建Issue + # 编辑和详情的时候需要在数据库中删除记录,新建的时候在内存中删除 + if params[:issue_id] + commit_issue = CommitIssues.where(:commit_id => commit_id, :issue_id => params[:issue_id], :project_id => @project.id).first + commit_issue.delete if commit_issue + end + @issue_commit_ids = issue_commit_ids - commit_id + end + # over + + def index + # 顶部导航 + @project_menu_type = 11 + @training_tasks = TrainingTask.where(:project_id => @project.id).order('position desc') + @training_tasks_count = @training_tasks.count + @limit = 10 + @is_remote = true + @training_tasks_pages = Paginator.new @training_tasks_count, @limit, params['page'] || 1 + @offset ||= @training_tasks_pages.offset + @training_tasks = paginateHelper @training_tasks, @limit + respond_to do |format| + format.js + format.html + end + rescue ActiveRecord::RecordNotFound + render_404 + end + + def show + # 顶部导航 + @project_menu_type = 11 + # 打开编辑内容 + @is_edit = true unless params[:edit].nil? + @jour_reply = Journal.new + @journals = @training_task.journals.includes(:user, :details).reorder("#{Journal.table_name}.id desc").all + @journals = get_no_children_comments_all @journals + @journals.each_with_index {|j,i| j.indice = i+1} + @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @training_task.project) + @journals.reverse! if User.current.wants_comments_in_reverse_order? + @journal = Journal.new(:journalized => @training_task) + respond_to do |format| + format.html + format.js + end + end + + # Add a new issue + # The new issue will be created from an existing one if copy_from parameter is given + def new + # 顶部导航 + @project_menu_type = 11 + respond_to do |format| + format.html { render :action => 'new', :layout => 'base_projects' } + end + end + + # 用户发布新任务 + def create + @training_task.save_attachments(params[:attachments] || (params[:training_task] && params[:training_task][:uploads])) + @training_task.subject = params[:training_task][:subject] + @training_task.description = params[:training_task][:description] + @training_task.tracker_id = params[:training_task][:tracker_id] + @training_task.position = params[:training_task][:position].to_i + if @training_task.save + respond_to do |format| + format.html { + render_attachment_warning_if_needed(@training_task) + redirect_to training_task_url(@training_task) + } + end + return + else + respond_to do |format| + format.html { render :action => 'new' } + end + end + end + + def complete_training_task + taskId = @training_task.position + end + + def edit + @project_menu_type = 11 + # 修改实例变量的值 + return unless build_new_task_from_params + respond_to do |format| + format.html {render :layout => 'base_projects' } + format.xml { } + end + end + + # 用户编辑更改issue + def update + return unless build_new_task_from_params + @training_task.save_attachments(params[:attachments] || (params[:training_task] && params[:training_task][:uploads])) + if @training_task.update_attributes(params[:training_task]) + respond_to do |format| + format.js + format.html{redirect_to training_task_url(@training_task)} + end + end + end + + def update_user_issue_detail(issue, params) + case params[:type] + when "status" + issue.update_attribute(:status_id, params[:status_id]) + when "assigned" + issue.update_attribute(:assigned_to_id, params[:assigned_to_id]) + when "ratio" + issue.update_attribute(:done_ratio, params[:done_ratio]) + when "prior" + issue.update_attribute(:priority_id, params[:priority_id]) + end + end + + # Updates the issue form when changing the project, status or tracker + # on issue creation/update + def update_form + end + + def destroy + return unless build_new_task_from_params + @training_task.destroy + respond_to do |format| + if params[:type] == "project_show" + format.html {redirect_to project_path(@project)} + else + format.html {redirect_to project_training_tasks_path(@project)} + end + end + end + + def add_journal + if User.current.logged? + jour = Journal.new + jour.user_id = User.current.id + jour.notes = params[:notes] + jour.journalized = @training_task + jour.save_attachments(params[:attachments]) + jour.save + update_user_activity(@training_task.class, @training_task.id) + update_forge_activity(@training_task.class, @training_task.id) + # @allowed_statuses = @training_task.new_statuses_allowed_to(User.current) + @user_activity_id = params[:user_activity_id] + @priorities = IssuePriority.active + + respond_to do |format| + # Issue详情单独处理 + if params[:is_issue_show] + format.js{ redirect_to training_task_path(@training_task) } + else + format.js + end + end + end + end + + def add_journal_in_org + if User.current.logged? + jour = Journal.new + jour.user_id = User.current.id + jour.notes = params[:notes] + jour.journalized = @issue + jour.save + org_activity = OrgActivity.where("org_act_type='Issue' and org_act_id =#{@issue.id}").first + org_activity.updated_at = jour.created_on + org_activity.save + @user_activity_id = params[:user_activity_id] + respond_to do |format| + format.js + end + end + end + + #对某个journ回复,显示回复框 + def reply + @training_task = TrainingTask.find(params[:id]) + @jour = Journal.find(params[:journal_id]) + respond_to do |format| + format.js + end + end + + #给issue添加journ。回复内容包含 对某个被回复的journ的内容 + def add_reply + if User.current.logged? + jour = Journal.find(params[:journal_id]) + @training_task = TrainingTask.find params[:id] + @project = @training_task.project + # @allowed_statuses = @training_task.new_statuses_allowed_to(User.current) + @priorities = IssuePriority.active + new_jour = Journal.new + new_jour.user_id = User.current.id + new_jour.reply_id = params[:journal_id] + new_jour.parent_id = jour.id + new_jour.notes = params[:content] + new_jour.journalized = @training_task + new_jour.save_attachments(params[:attachments]) + # new_jour = @issue.journals.build(:user_id => User.current.id, :reply_id => params[:journal_id], :notes => params[:content], :parent_id => jour.id) + @user_activity_id = params[:user_activity_id] + if new_jour.save + update_user_activity(@training_task.class, @training_task.id) + update_forge_activity(@training_task.class, @training_task.id) + respond_to do |format| + if params[:is_issue_show] + format.js{ redirect_to training_task_path(@training_task) } + else + format.js + end + end + end +=begin + @journals = @training_task.journals.includes(:user, :details).reorder("#{Journal.table_name}.id desc").all + @journals = get_no_children_comments_all @journals + @journals.each_with_index {|j,i| j.indice = i+1} + @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @training_task.project) + @journals.reverse! if User.current.wants_comments_in_reverse_order? + @journal = Journal.new(:journalized => @training_task) + respond_to do |format| + #if params[:is_issue_show] + # format.js{ redirect_to training_task_path(@training_task) } + #else + format.js + #end + end +=end + end + end + + # 需要刷新详情页面,代码同步一致 + # 获取project和issue状态是为了刷新页面 + # 值所以用delete是因为issue和journal在act_as_attachment中是同一个类型 + # 非动态页面直接刷新,动态页面手动刷新 + def delete_journal + @is_project = params[:is_project] + @training_task = TrainingTask.find(params[:id]) + begin + forge_acts = ForgeMessage.where(:forge_message_type => "Journal", :forge_message_id => params[:journal_id]) + forge_acts.destroy_all unless forge_acts.empty? + at_message = AtMessage.where(:at_message_type => "Journal", :at_message_id => params[:journal_id]) + at_message.destroy_all unless at_message.empty? + Journal.delete(params[:journal_id]) + rescue Exception => e + puts e + end + @user_activity_id = params[:user_activity_id] + respond_to do |format| + if @user_activity_id + format.js + else + format.js{ redirect_to training_task_path(@training_task)} + end + end + end + + private + + def find_project + project_id = params[:project_id] || (params[:issue] && params[:issue][:project_id]) + @project = Project.find(project_id) + rescue ActiveRecord::RecordNotFound + render_404 + end + + def allow_members + if !(User.current.member_of?(@project) || User.current.admin?) + render_403 + end + end + + def allow_manager + if !(User.current.admin? || is_project_member?(User.current.id, @project.id)) + return render_403 + end + end + + def retrieve_previous_and_next_issue_ids + retrieve_query_from_session + if @query + sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) + sort_update(@query.sortable_columns, 'issues_index_sort') + limit = 500 + issue_ids = @query.issue_ids(:order => sort_clause, :limit => (limit + 1), :include => [:assigned_to, :tracker, :priority, :category, :fixed_version]) + if (idx = issue_ids.index(@issue.id)) && idx < limit + if issue_ids.size < 500 + @issue_position = idx + 1 + @issue_count = issue_ids.size + end + @prev_issue_id = issue_ids[idx - 1] if idx > 0 + @next_issue_id = issue_ids[idx + 1] if idx < (issue_ids.size - 1) + end + end + end + + def build_new_task_from_params + if params[:id].blank? + @training_task = TrainingTask.new + @training_task.project = @project + else + @training_task = @project.training_tasks.find(params[:id]) + end + + @training_task.project = @project + @training_task.author ||= User.current + end + + def check_for_default_issue_status + if IssueStatus.default.nil? + render_error l(:error_no_default_issue_status) + return false + end + end + + def parse_params_for_bulk_issue_attributes(params) + attributes = (params[:issue] || {}).reject {|k,v| v.blank?} + attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'} + if custom = attributes[:custom_field_values] + custom.reject! {|k,v| v.blank?} + custom.keys.each do |k| + if custom[k].is_a?(Array) + custom[k] << '' if custom[k].delete('__none__') + else + custom[k] = '' if custom[k] == '__none__' + end + end + end + attributes + end + + # Find the issue whose id is the :id parameter + # Raises a Unauthorized exception if the issue is not visible + def find_training_task + @training_task = TrainingTask.find(params[:id]) + @project = @training_task.project + rescue ActiveRecord::RecordNotFound + render_404 + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f54b5ba3b..7113d0c98 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -310,6 +310,11 @@ class UsersController < ApplicationController @user_activity_id = params[:user_activity_id] @activity_id = params[:activity_id] @type = 'Issue' + when 'Training_task' + @reply = Journal.find params[:reply_id] + @user_activity_id = params[:user_activity_id] + @activity_id = params[:activity_id] + @type = 'Training_task' when 'Syllabus' @reply = JournalsForMessage.find params[:reply_id] @type = 'Syllabus' @@ -417,6 +422,11 @@ class UsersController < ApplicationController comment = @root.journals.build(:user_id => User.current.id, :reply_id => params[:reply_id], :notes => params[:reply_message], :parent_id => reply.id) comment.save @is_project = params[:is_project] if params[:is_project] + when 'TrainingTask' + @root = reply.training_task + comment = @root.journals.build(:user_id => User.current.id, :reply_id => params[:reply_id], :notes => params[:reply_message], :parent_id => reply.id) + comment.save + @is_project = params[:is_project] if params[:is_project] when 'Syllabus' @root = Syllabus.find reply.jour_id options = {:notes => params[:reply_message], :reply_id => reply.user_id,:user_id => User.current.id,:m_parent_id => params[:reply_id].to_i,:m_reply_id => params[:reply_id].to_i, :root_id => reply.root_id} @@ -4402,6 +4412,11 @@ class UsersController < ApplicationController @journals = @activity.journals.reorder("created_on desc") @user_activity_id = params[:div_id].to_i if params[:div_id] @user_activity = ForgeActivity.where(params[:div_id].to_i).first if params[:div_id] + when 'is_project_training_task' + @activity = TrainingTask.where('id = ?', params[:id].to_i).first + @journals = @activity.journals.reorder("created_on desc") + @user_activity_id = params[:div_id].to_i if params[:div_id] + @user_activity = ForgeActivity.where(params[:div_id].to_i).first if params[:div_id] when 'BlogComment' obj = BlogComment.where('id = ?', params[:id].to_i).first @user_activity_id = params[:div_id].to_i if params[:div_id] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 545062bca..a8c3d2de4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3697,7 +3697,7 @@ def get_reply_by_type type, reply_id reply = OrgDocumentComment.find reply_id when 'News','Comment' reply = Comment.find reply_id - when 'Issue' + when 'Issue', 'TrainingTask' reply = Journal.find reply_id when 'Journal' reply = Journal.find reply_id diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 653afef62..f9b185ba4 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -544,6 +544,8 @@ module ProjectsHelper result = "manage_versions" elsif user.allowed_to?(:manage_repository, @project) result = "manage_repository" + elsif @project.is_training_project? + result = "training_task" end result end diff --git a/app/helpers/training_tasks_helper.rb b/app/helpers/training_tasks_helper.rb new file mode 100644 index 000000000..bb52e8a79 --- /dev/null +++ b/app/helpers/training_tasks_helper.rb @@ -0,0 +1,44 @@ +module TrainingTasksHelper + include ApplicationHelper + include TagsHelper + require 'iconv' + + # Returns the textual representation of a journal details + # as an array of strings + def details_to_strings(details, no_html=false, options={}) + options[:only_path] = (options[:only_path] == false ? false : true) + options[:token] = options[:token] if options[:token] + strings = [] + values_by_field = {} + details.each do |detail| + + if detail.property == 'cf' + field_id = detail.prop_key + field = CustomField.find_by_id(field_id) + if field && field.multiple? + values_by_field[field_id] ||= {:added => [], :deleted => []} + if detail.old_value + values_by_field[field_id][:deleted] << detail.old_value + end + if detail.value + values_by_field[field_id][:added] << detail.value + end + next + end + end + strings << show_detail(detail, no_html, options) + + end + values_by_field.each do |field_id, changes| + detail = JournalDetail.new(:property => 'cf', :prop_key => field_id) + if changes[:added].any? + detail.value = changes[:added] + strings << show_detail(detail, no_html, options) + elsif changes[:deleted].any? + detail.old_value = changes[:deleted] + strings << show_detail(detail, no_html, options) + end + end + strings + end +end diff --git a/app/models/journal.rb b/app/models/journal.rb index f14484a31..822d7beca 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -23,7 +23,8 @@ class Journal < ActiveRecord::Base belongs_to :journalized, :polymorphic => true,:touch => true # added as a quick fix to allow eager loading of the polymorphic association # since always associated to an issue, for now - belongs_to :issue, :foreign_key => :journalized_id,:touch => true + belongs_to :issue, :foreign_key => :journalized_id, :touch => true + belongs_to :training_task, :foreign_key => :journalized_id, :touch => true belongs_to :user has_many :details, :class_name => "JournalDetail", :dependent => :delete_all @@ -192,27 +193,44 @@ class Journal < ActiveRecord::Base def act_as_forge_message receivers = [] # 直接回复 - if self.user_id != self.issue.author_id - receivers << self.issue.author_id - end - if self.user_id != self.issue.assigned_to_id && self.issue.assigned_to_id != self.issue.author_id # 指派人不是自己的话,则给指派人发送 - receivers << self.issue.assigned_to_id - end - receivers.each do |r| - self.forge_messages << ForgeMessage.new(:user_id => r, :project_id => self.issue.project_id, :viewed => false) + if self.journalized_type == 'Issue' + if self.user_id != self.issue.author_id + receivers << self.issue.author_id + end + if self.user_id != self.issue.assigned_to_id && self.issue.assigned_to_id != self.issue.author_id # 指派人不是自己的话,则给指派人发送 + receivers << self.issue.assigned_to_id + end + receivers.each do |r| + self.forge_messages << ForgeMessage.new(:user_id => r, :project_id => self.issue.project_id, :viewed => false) + end + elsif self.journalized_type == 'TrainingTask' + if self.user_id != self.training_task.author_id + receivers << self.training_task.author_id + end + receivers.each do |r| + self.forge_messages << ForgeMessage.new(:user_id => r, :project_id => self.training_task.project, :viewed => false) + end end end # 更新用户分数 -by zjc def be_user_score + if (self.journalized_type == 'Issue') #新建了缺陷留言且留言不为空,不为空白 - if !self.notes.nil? && self.notes.gsub(' ','') != '' - #协同得分加分 - UserScore.joint(:post_issue_message, self.user,self.issue.author,self, { message_id: self.id }) - update_messges_for_issue(self.user,1) - update_messges_for_issue(self.user,2,self.issue.project) + if !self.notes.nil? && self.notes.gsub(' ','') != '' + #协同得分加分 + UserScore.joint(:post_issue_message, self.user,self.issue.author,self, { message_id: self.id }) + update_messges_for_issue(self.user,1) + update_messges_for_issue(self.user,2,self.issue.project) + end + elsif( self.journalized_type == 'TrainingTask') + if !self.notes.nil? && self.notes.gsub(' ','') != '' + #协同得分加分 + UserScore.joint(:post_issue_message, self.user, self.training_task.author, self, { message_id: self.id }) + update_messges_for_issue(self.user, 1) + update_messges_for_issue(self.user, 2, self.training_task.project) + end end - end # 减少用户分数 -by zjc def down_user_score @@ -237,12 +255,18 @@ class Journal < ActiveRecord::Base # issue留言总数更新 def add_journals_count - if !self.issue.project.nil? && self.journalized_type == "Issue" && !self.issue.project.project_score.nil? - project = self.issue.project - project.project_score.update_attribute(:issue_journal_num, project.project_score.issue_journal_num + 1) + if self.journalized_type == 'Issue' + if !self.issue.project.nil? && self.journalized_type == "Issue" && !self.issue.project.project_score.nil? + project = self.issue.project + project.project_score.update_attribute(:issue_journal_num, project.project_score.issue_journal_num + 1) + end + elsif self.journalized_type == 'TrainingTask' + if !self.training_task.project.nil? && self.journalized_type == "TrainingTask" && !self.training_task.project.project_score.nil? + project = self.training_task.project + project.project_score.update_attribute(:issue_journal_num, project.project_score.issue_journal_num + 1) + end end end - # 回复issue的时候,更新issue的时候 def update_issue_time if self.journalized_type == "Issue" diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb index 63ba89b18..d0c067437 100644 --- a/app/models/praise_tread.rb +++ b/app/models/praise_tread.rb @@ -1,98 +1,100 @@ -class PraiseTread < ActiveRecord::Base - attr_accessible :user_id,:praise_tread_object_id,:praise_tread_object_type,:praise_or_tread - belongs_to :user - belongs_to :praise_tread_object, polymorphic: true - #after_create :be_user_score - #after_destroy :down_user_score - include UserScoreHelper - def self.find_object_by_type_and_id(type,id) - @obj = nil - case type - when 'User' - @obj = User.find_by_id(id) - when 'Issue' - @obj = Issue.find_by_id(id) - when 'Project' - @obj = Project.find_by_id(id) - when 'Bid' - @obj = Bid.find_by_id(id) - when 'Contest' - @obj = Contest.find_by_id(id) - when 'Memo' - @obj = Memo.find_by_id(id) - when 'Message' - @obj = Message.find_by_id(id) - end - return @obj - end - - # 获取裁定对象为Message时Message所属的项目或课程 - def project - project = nil - if self.praise_tread_object_type == 'Message' || self.praise_tread_object_type == 'Issues' - obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) - project = obj.project - end - project - end - - #更新用户分数 - by zjc - def be_user_score - #踩贴吧或讨论区帖子 - if self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') - obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) - target_user = obj.author - UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id }) - update_tread(self.user,1) - update_tread(target_user,1) - unless self.project.nil? - update_tread(self.user,2,self.project) - update_tread(target_user,2,self.project) - end - #顶贴吧或讨论区帖子 - elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') - obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) - target_user = obj.author - UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id }) - update_praise(target_user,1) - unless self.project.nil? - update_praise(target_user,2,self.project) - end - #更新用户等级 - UserLevels.update_user_level(target_user) - end - end - - def down_user_score - #踩贴吧或讨论区帖子 - if self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') - obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) - target_user = obj.author - #UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id }) - update_tread(self.user,1) - update_tread(target_user,1) - unless self.project.nil? - update_tread(self.user,2,self.project) - update_tread(target_user,2,self.project) - end - #顶贴吧或讨论区帖子 - elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') - obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) - target_user = obj.author - #UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id }) - update_praise(target_user,1) - unless self.project.nil? - update_praise(target_user,2,self.project) - end - #更新用户等级 - UserLevels.update_user_level(target_user) - end - end - - def self.praised(activity) - self.where(praise_tread_object_id: activity.id, - praise_tread_object_type: activity.class.to_s, - user_id: User.current.id).empty? - end - -end +class PraiseTread < ActiveRecord::Base + attr_accessible :user_id,:praise_tread_object_id,:praise_tread_object_type,:praise_or_tread + belongs_to :user + belongs_to :praise_tread_object, polymorphic: true + #after_create :be_user_score + #after_destroy :down_user_score + include UserScoreHelper + def self.find_object_by_type_and_id(type,id) + @obj = nil + case type + when 'User' + @obj = User.find_by_id(id) + when 'Issue' + @obj = Issue.find_by_id(id) + when 'TrainingTask' + @obj = TrainingTask.find_by_id(id) + when 'Project' + @obj = Project.find_by_id(id) + when 'Bid' + @obj = Bid.find_by_id(id) + when 'Contest' + @obj = Contest.find_by_id(id) + when 'Memo' + @obj = Memo.find_by_id(id) + when 'Message' + @obj = Message.find_by_id(id) + end + return @obj + end + + # 获取裁定对象为Message时Message所属的项目或课程 + def project + project = nil + if self.praise_tread_object_type == 'Message' || self.praise_tread_object_type == 'Issues' + obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) + project = obj.project + end + project + end + + #更新用户分数 - by zjc + def be_user_score + #踩贴吧或讨论区帖子 + if self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') + obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) + target_user = obj.author + UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id }) + update_tread(self.user,1) + update_tread(target_user,1) + unless self.project.nil? + update_tread(self.user,2,self.project) + update_tread(target_user,2,self.project) + end + #顶贴吧或讨论区帖子 + elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') + obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) + target_user = obj.author + UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id }) + update_praise(target_user,1) + unless self.project.nil? + update_praise(target_user,2,self.project) + end + #更新用户等级 + UserLevels.update_user_level(target_user) + end + end + + def down_user_score + #踩贴吧或讨论区帖子 + if self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') + obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) + target_user = obj.author + #UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id }) + update_tread(self.user,1) + update_tread(target_user,1) + unless self.project.nil? + update_tread(self.user,2,self.project) + update_tread(target_user,2,self.project) + end + #顶贴吧或讨论区帖子 + elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') + obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) + target_user = obj.author + #UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id }) + update_praise(target_user,1) + unless self.project.nil? + update_praise(target_user,2,self.project) + end + #更新用户等级 + UserLevels.update_user_level(target_user) + end + end + + def self.praised(activity) + self.where(praise_tread_object_id: activity.id, + praise_tread_object_type: activity.class.to_s, + user_id: User.current.id).empty? + end + +end diff --git a/app/models/project.rb b/app/models/project.rb index e48a5296c..d5d2da038 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -57,6 +57,7 @@ class Project < ActiveRecord::Base has_many :enabled_modules, :dependent => :delete_all has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position" has_many :issues, :dependent => :destroy, :include => [:status, :tracker],:order => "issues.id ASC" + has_many :training_tasks, :dependent => :destroy, :order => "training_tasks.id ASC" has_many :issue_changes, :through => :issues, :source => :journals has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC" has_many :time_entries, :dependent => :delete_all @@ -159,6 +160,7 @@ class Project < ActiveRecord::Base after_create :create_board_sync,:acts_as_forge_activities, :create_project_ealasticsearch_index before_destroy :delete_all_members,:delete_project_ealasticsearch_index after_update :update_project_ealasticsearch_index + def remove_references_before_destroy return if self.id.nil? Watcher.delete_all ['watchable_id = ?', id] @@ -193,6 +195,7 @@ class Project < ActiveRecord::Base scope :project_entities, -> { where(project_type: ProjectType_project) } scope :course_entities, -> { where(project_type: ProjectType_course) } scope :indexable,lambda { where('is_public = 1')} #用于elastic建索引的scope + def self.search(query) __elasticsearch__.search( { @@ -219,6 +222,17 @@ class Project < ActiveRecord::Base } ) end + + # 判断项目是否为实训项目 + def is_training_project? + (!self.enabled_modules.where("name = 'training_tasks'").empty? && self.training_status == 1) ? true : false + end + + # 判断项目是否为开启实训的项目(eg:学生开启实训) + def is_child_training_project? + self.training_status == 2 ? true :false + end + def new_course self.where('project_type = ?', 1) end diff --git a/app/models/training_task.rb b/app/models/training_task.rb new file mode 100644 index 000000000..3ddf99286 --- /dev/null +++ b/app/models/training_task.rb @@ -0,0 +1,28 @@ +class TrainingTask < ActiveRecord::Base + attr_accessible :description, :project_id, :subject, :tracker_id + belongs_to :project,:touch=> true + belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' + belongs_to :tracker + has_many :journals, :as => :journalized, :dependent => :destroy + has_many :visible_journals, + :class_name => 'Journal', + :as => :journalized, + :conditions => Proc.new { + ["(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(User.current, :view_private_notes)}))", false] + }, + :readonly => true + has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy + has_many :forge_acts, :class_name => 'ForgeActivity', :as => :forge_act, :dependent => :destroy + + acts_as_attachable + + validates_presence_of :subject, :author + validates_length_of :subject, :maximum => 255 + after_create :act_as_forge_activity + + def act_as_forge_activity + self.forge_acts << ForgeActivity.new(:user_id => self.author_id, :project_id => self.project_id) + end + +end diff --git a/app/models/user.rb b/app/models/user.rb index 72e89020e..0d2295ee8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1239,6 +1239,16 @@ class User < Principal Thread.current[:current_user] ||= User.anonymous end + def user_real_extension + ue = self.user_extensions + if ue.nil? + ue = UserExtensions.new + ue.user_id = self.id + ue.save + end + ue + end + # Returns the anonymous user. If the anonymous user does not exist, it is created. There can be only # one anonymous user per database. def self.anonymous diff --git a/app/views/account/_change_user_email.html.erb b/app/views/account/_change_user_email.html.erb new file mode 100644 index 000000000..20eae1374 --- /dev/null +++ b/app/views/account/_change_user_email.html.erb @@ -0,0 +1,72 @@ +
+
+

更换邮箱

+ +
+
+
+ +
+
+ \ No newline at end of file diff --git a/app/views/account/email_activation.html.erb b/app/views/account/email_activation.html.erb index d02715e43..253867447 100644 --- a/app/views/account/email_activation.html.erb +++ b/app/views/account/email_activation.html.erb @@ -1,22 +1,31 @@
- + <%#= link_to l(:label_mail_resend), { :controller => 'account', :action => 'resendmail',:user => @user}, :class=>"email_verify_btn mt30 ml30", :remote => true, :method => 'get' %> -
diff --git a/app/views/account/email_valid.html.erb b/app/views/account/email_valid.html.erb index 84da6d04d..21ab2e270 100644 --- a/app/views/account/email_valid.html.erb +++ b/app/views/account/email_valid.html.erb @@ -5,7 +5,7 @@

注册成功! 请在24小时内点击邮件中的链接来激活您的账号。

-

请登录邮箱(<%= @user.mail %>)收取账号激活邮件。
点击邮件中的激活链接,方可使用该账号 +

请登录邮箱(<%= @user.mail %>)收取账号激活邮件。
点击邮件中的激活链接,方可使用该账号

<%= l(:label_check_email)%> @@ -14,14 +14,15 @@

--> - +
\ No newline at end of file diff --git a/app/views/layouts/_footer_show.html.erb b/app/views/layouts/_footer_show.html.erb index 99e71762d..d9c0eeeda 100644 --- a/app/views/layouts/_footer_show.html.erb +++ b/app/views/layouts/_footer_show.html.erb @@ -38,8 +38,7 @@
  • web小蜜蜂
  • - + \ No newline at end of file diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb index f99160f75..4cade508c 100644 --- a/app/views/layouts/_logined_header.html.erb +++ b/app/views/layouts/_logined_header.html.erb @@ -116,6 +116,7 @@ $("#navHomepageSearchType").hide(); }); + <% unless @force %> $("#user_messages").mouseenter(function(){ onNotice = true; $("#user_messages_list").show(); @@ -134,6 +135,7 @@ obj.html("<%=escape_javascript(render :partial => 'layouts/message_loading') %>"); } }, 500); }); + <% end %> $("#message_list_detail").mouseenter(function(event){ event.stopPropagation(); onUserMessages = true; diff --git a/app/views/layouts/_show_messages_list.html.erb b/app/views/layouts/_show_messages_list.html.erb index 6292db7d6..d51f5e9e1 100644 --- a/app/views/layouts/_show_messages_list.html.erb +++ b/app/views/layouts/_show_messages_list.html.erb @@ -132,7 +132,7 @@ role_str = "参赛者" end end %> -
  • <%= user.show_name%> <%= user.user_extensions.school_id.blank? ? "" : "来自"+user.user_extensions.school.name+"," %>申请以"<%= role_str%>"的身份加入竞赛:<%=Contest.find(ma.contest_id).name %> <%= User.find(ma.contest_message_id).show_name %><%= ma.status == 1 ? "已同意" : "已拒绝"%>
  • +
  • <%= user.show_name%> <%= user.user_extensions.school_id.blank? || user.user_extensions.school.nil? ? "" : "来自"+user.user_extensions.school.name+"," %>申请以"<%= role_str%>"的身份加入竞赛:<%=Contest.find(ma.contest_id).name %> <%= User.find(ma.contest_message_id).show_name %><%= ma.status == 1 ? "已同意" : "已拒绝"%>
  • <% elsif ma.contest_message_type == "JoinContest" and ma.status == 0 %>
  • <%=User.find(ma.contest_message_id).show_name %> 将您加入了竞赛:<%= ma.contest.name%>
  • <% elsif ma.contest_message_type == "JoinContest" and ma.status == 1 %> @@ -177,8 +177,8 @@ <% applied_contest = ma.applied %> <% contest = Contest.find applied_contest.contest_id %> <% message_user = User.find(applied_contest.user_id) %> - <% content = ''+message_user.show_name+' '+(message_user.user_extensions.school_id.blank? ? "" : "来自")+message_user.user_extensions.school.name+","+'申请以"'+ get_role_str(ma.role) + '"的身份加入竞赛:' + contest.name%> - <%= link_to content.html_safe, contest_path(contest.id), :title => "#{message_user.show_name} #{message_user.user_extensions.school_id.blank? ? '' : '来自'+message_user.user_extensions.school.name},申请以'#{get_role_str(ma.role)}'的身份加入竞赛:#{contest.name}", :target => '_blank' %> + <% content = ''+message_user.show_name+' '+(message_user.user_extensions.school_id.blank? || message_user.user_extensions.school.nil? ? "" : "来自"+message_user.user_extensions.school.name+",")+'申请以"'+ get_role_str(ma.role) + '"的身份加入竞赛:' + contest.name%> + <%= link_to content.html_safe, contest_path(contest.id), :title => "#{message_user.show_name} #{message_user.user_extensions.school_id.blank? || message_user.user_extensions.school.nil? ? '' : '来自'+message_user.user_extensions.school.name+","}申请以'#{get_role_str(ma.role)}'的身份加入竞赛:#{contest.name}", :target => '_blank' %> <% end %> <% elsif ma.class == ForgeMessage %> diff --git a/app/views/layouts/base_contest_community.html.erb b/app/views/layouts/base_contest_community.html.erb index 26c5f4f1f..d92df3bc3 100644 --- a/app/views/layouts/base_contest_community.html.erb +++ b/app/views/layouts/base_contest_community.html.erb @@ -7,7 +7,7 @@ <%= 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 'jquery/jquery-ui-1.9.2','css/common', 'css/structure','css/public', 'prettify','css/project','css/courses','css/popup','css/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','contest'%> diff --git a/app/views/layouts/base_contests.html.erb b/app/views/layouts/base_contests.html.erb index da1a83b16..4b826482b 100644 --- a/app/views/layouts/base_contests.html.erb +++ b/app/views/layouts/base_contests.html.erb @@ -12,7 +12,7 @@ <%= javascript_heads %> <%= heads_for_theme %> <%= call_hook :view_layouts_base_html_head %> - <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/common','css/public', 'css/structure','prettify', 'css/courses','css/popup','sy_public','syllabus', 'css/moduel','css/contest'%> + <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/common','css/public', 'css/structure','prettify', 'css/courses','css/popup','css/sy_public','css/syllabus', 'css/moduel','css/contest'%> <%= javascript_include_tag "course","avatars","header","attachments",'prettify','contest' %> <%= yield :header_tags -%> diff --git a/app/views/layouts/base_course_community.html.erb b/app/views/layouts/base_course_community.html.erb index 4897482c6..44fa0cea7 100644 --- a/app/views/layouts/base_course_community.html.erb +++ b/app/views/layouts/base_course_community.html.erb @@ -7,7 +7,7 @@ <%= 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 'jquery/jquery-ui-1.9.2','css/common', 'css/structure','css/public', 'prettify','css/project','css/courses','css/popup','css/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'%> diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index e662d9fa0..479f9f1cd 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -19,7 +19,7 @@ <%= javascript_heads %> <%= heads_for_theme %> <%= call_hook :view_layouts_base_html_head %> - <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/common','css/public', 'css/structure','prettify', 'css/courses','css/popup','sy_public','syllabus', 'css/moduel','css/contest'%> + <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/common','css/public', 'css/structure','prettify', 'css/courses','css/popup','css/syllabus', 'css/moduel','css/contest'%> <%= javascript_include_tag "course","avatars","header","attachments",'prettify' %> <%= yield :header_tags -%> diff --git a/app/views/layouts/base_org.html.erb b/app/views/layouts/base_org.html.erb index a422dd780..3ee47af2c 100644 --- a/app/views/layouts/base_org.html.erb +++ b/app/views/layouts/base_org.html.erb @@ -162,8 +162,7 @@
    diff --git a/app/views/layouts/base_project_community.html.erb b/app/views/layouts/base_project_community.html.erb index a9caebcdb..6161e424b 100644 --- a/app/views/layouts/base_project_community.html.erb +++ b/app/views/layouts/base_project_community.html.erb @@ -7,7 +7,7 @@ <%= 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 'jquery/jquery-ui-1.9.2','css/common', 'css/structure','css/public', 'prettify','css/project','css/courses','css/popup','csws/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'%> diff --git a/app/views/layouts/base_syllabus.html.erb b/app/views/layouts/base_syllabus.html.erb index 0b9b47c55..3e75e1739 100644 --- a/app/views/layouts/base_syllabus.html.erb +++ b/app/views/layouts/base_syllabus.html.erb @@ -7,7 +7,7 @@ <%= csrf_meta_tag %> <%= favicon %> - <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/common','css/public','css/structure','css/courses','css/popup','prettify','syllabus','sy_public','css/moduel',:media => 'all'%> + <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/common','css/public','css/structure','css/courses','css/popup','prettify','css/syllabus','css/sy_public','css/moduel',:media => 'all'%> <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> <%= javascript_heads %> <%= javascript_include_tag "bootstrap","avatars","course",'attachments','prettify','syllabus','cookie'%> diff --git a/app/views/layouts/new_base.html.erb b/app/views/layouts/new_base.html.erb index cc6da3581..ba5c84ca2 100644 --- a/app/views/layouts/new_base.html.erb +++ b/app/views/layouts/new_base.html.erb @@ -13,7 +13,7 @@ <%= javascript_heads %> <%= 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'%> + <%= stylesheet_link_tag 'css/common','css/structure', 'css/public', 'css/courses','prettify', 'css/org', 'css/syllabus'%> <%= 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 acfdf4728..1d08ab7da 100644 --- a/app/views/layouts/new_base_user.html.erb +++ b/app/views/layouts/new_base_user.html.erb @@ -7,7 +7,7 @@ <%= 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 'jquery/jquery-ui-1.9.2','css/common', 'css/structure','css/public', 'prettify','css/project','css/courses','css/popup','css/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'%> diff --git a/app/views/layouts/new_base_user_show.html.erb b/app/views/layouts/new_base_user_show.html.erb index 94c5c8a30..2a3d503b7 100644 --- a/app/views/layouts/new_base_user_show.html.erb +++ b/app/views/layouts/new_base_user_show.html.erb @@ -7,7 +7,7 @@ <%= 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',:media => 'all' %> + <%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2','css/common', 'css/structure','css/public', 'prettify','css/project','css/courses','css/popup','css/syllabus',:media => 'all' %> <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> <%= javascript_heads %> <%= javascript_include_tag "bootstrap","avatars","new_user",'attachments','prettify'%> diff --git a/app/views/layouts/static_base.html.erb b/app/views/layouts/static_base.html.erb index ff0e30414..9f0bbaa37 100644 --- a/app/views/layouts/static_base.html.erb +++ b/app/views/layouts/static_base.html.erb @@ -16,7 +16,7 @@ <%= call_hook :view_layouts_base_html_head %> <%= yield :header_tags -%> - <%= stylesheet_link_tag 'css/common','css/structure','css/public','css/popup','syllabus','sy_public', :media => 'all'%> + <%= stylesheet_link_tag 'css/common','css/structure','css/public','css/popup','css/syllabus','css/sy_public', :media => 'all'%> +<% end %> + diff --git a/app/views/projects/_applied_status.html.erb b/app/views/projects/_applied_status.html.erb index 59d339b9d..06bd2bf0b 100644 --- a/app/views/projects/_applied_status.html.erb +++ b/app/views/projects/_applied_status.html.erb @@ -1,43 +1,49 @@ -<% if !User.current.member_of?(@project) %> - <% if User.current.login? && !User.current.admin %> - -
  • - <%= watcher_link_for_project(@project, User.current) %> - <%= link_to "#{@project.watcher_users.count}", {:controller => "projects", :action => "project_watcherlist", - :id => @project.id}, :id => "fans_num", :class => 'pro_new_topbtn fl', :title => "关注成员列表" %> -
  • - -
  • - <% if AppliedProject.where(:user_id => User.current, :project_id => @project_id).first.nil? %> - <%= join_in_project_link(@project, User.current) %> - <% else %> - 等待审批 - <% end %> - <%= link_to "#{Member.where(:project_id => @project.id).count}", project_member_path(@project), :class => 'pro_new_topbtn fl', :title => "项目成员列表" %> -
  • - <% end %> -<% else %> - - <% if User.current.login? %> -
  • - <%= watcher_link_for_project(@project, User.current) %> - <%= link_to "#{@project.watcher_users.count}", {:controller => "projects", :action => "project_watcherlist", - :id => @project.id}, :id => "fans_num", :class => 'pro_new_topbtn fl', :title => "关注成员列表" %> -
  • -
  • - 已加入 - - <%= link_to "#{Member.where(:project_id => @project.id).count}", project_member_path(@project), :class => 'pro_new_topbtn fl', :title => "项目成员列表" %> -
  • - <%#= link_to "#{Member.where(:project_id => @project.id).count}", project_member_path(@project), :class => 'pro_new_topbtn fl', :title => "项目成员" %> - <% end %> -<% end %> - - -
  • - <%= link_to "".html_safe+"Fork", forked_pop_project_path(@project), - :class=>"pro_new_topbtn_left fl", :remote => true %> - <%= project_fork_count %> -
  • - - +<% if !User.current.member_of?(@project) %> + <% if User.current.login? && !User.current.admin %> + +
  • + <%= watcher_link_for_project(@project, User.current) %> + <%= link_to "#{@project.watcher_users.count}", {:controller => "projects", :action => "project_watcherlist", + :id => @project.id}, :id => "fans_num", :class => 'pro_new_topbtn fl', :title => "关注成员列表" %> +
  • + +
  • + <% if AppliedProject.where(:user_id => User.current, :project_id => @project_id).first.nil? %> + <%= join_in_project_link(@project, User.current) %> + <% else %> + 等待审批 + <% end %> + <%= link_to "#{Member.where(:project_id => @project.id).count}", project_member_path(@project), :class => 'pro_new_topbtn fl', :title => "项目成员列表" %> +
  • + <% end %> +<% else %> + + <% if User.current.login? %> +
  • + <%= watcher_link_for_project(@project, User.current) %> + <%= link_to "#{@project.watcher_users.count}", {:controller => "projects", :action => "project_watcherlist", + :id => @project.id}, :id => "fans_num", :class => 'pro_new_topbtn fl', :title => "关注成员列表" %> +
  • +
  • + 已加入 + + <%= link_to "#{Member.where(:project_id => @project.id).count}", project_member_path(@project), :class => 'pro_new_topbtn fl', :title => "项目成员列表" %> +
  • + <%#= link_to "#{Member.where(:project_id => @project.id).count}", project_member_path(@project), :class => 'pro_new_topbtn fl', :title => "项目成员" %> + <% end %> +<% end %> + + +
  • + + <% if @project.is_training_project? && User.current.id != @project.user_id %> + <%= link_to "开始实训", training_chiled_project_exec_project_path(@project), :class => "sy_btn_green fr", :remote => true %> + <% else %> + <%= link_to "".html_safe+"Fork", forked_pop_project_path(@project), + :class=>"pro_new_topbtn_left fl", :remote => true %> + <%= project_fork_count %> + <% end %> + +
  • + + diff --git a/app/views/projects/_invite_code.html.erb b/app/views/projects/_invite_code.html.erb index 94a2d1ea5..03591034a 100644 --- a/app/views/projects/_invite_code.html.erb +++ b/app/views/projects/_invite_code.html.erb @@ -1,5 +1,5 @@

    项目简介 -<% if User.current.member_of?(@project) %> +<% if User.current.member_of?(@project) && !@project.is_child_training_project? %> 邀请码:<%= @project.invite_code %> <% end %>

    \ No newline at end of file diff --git a/app/views/projects/_project_activities.html.erb b/app/views/projects/_project_activities.html.erb index 07363a0a5..fe504145a 100644 --- a/app/views/projects/_project_activities.html.erb +++ b/app/views/projects/_project_activities.html.erb @@ -40,7 +40,11 @@ <% when "Issue" %> <%= render :partial => 'projects/act_issues', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :project_id => activity.project_id} %> - + <% when "TrainingTask" %> + <% if User.current.admin? || is_project_member?(User.current.id, @project.id) %> + <%= render :partial => 'projects/act_training_tasks', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :project_id => activity.project_id} %> + <% end %> + <% when "Message" %> <%= render :partial => 'projects/act_messages', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :is_course => 1, :is_board => 0} %> diff --git a/app/views/projects/_project_issue_expand_show.html.erb b/app/views/projects/_project_issue_expand_show.html.erb index 2debb7789..4d147a85d 100644 --- a/app/views/projects/_project_issue_expand_show.html.erb +++ b/app/views/projects/_project_issue_expand_show.html.erb @@ -32,27 +32,64 @@ <%= render :partial => "praise_tread/praise", :locals => {:activity => comment, :user_activity_id => comment.id, :type => "reply"} %> - - <%= link_to( - l(:button_reply), - {:controller => 'users', :action => 'reply_to', :reply_id => comment.id, :type => 'Issue', :user_activity_id => user_activity_id, :activity_id => activity.id, :is_project => true}, - :remote => true, - :method => 'get', - :title => l(:button_reply)) %> + <% if activity.class.to_s == 'TrainingTask' %> + <%= link_to(l(:button_reply), + {:controller => 'users', + :action => 'reply_to', + :reply_id => comment.id, + :type => 'Training_task', + :user_activity_id => user_activity_id, + :activity_id => activity.id, + :is_project => true}, + :remote => true, + :method => 'get', + :title => l(:button_reply)) %> + <% else %> + <%= link_to(l(:button_reply), + {:controller => 'users', + :action => 'reply_to', + :reply_id => comment.id, + :type => 'Issue', + :user_activity_id => user_activity_id, + :activity_id => activity.id, :is_project => true}, + :remote => true, + :method => 'get', + :title => l(:button_reply)) %> + + <% end %> - <%= link_to( - l(:button_delete), - {:controller => 'issues',:action => 'delete_journal', :id => activity.id,:journal_id=>comment.id, :user_activity_id => user_activity_id, :is_project => true}, - :method => 'get', - :confirm => l(:text_are_you_sure), - :remote=>true, - :id => "delete_reply_#{activity.id}_#{comment.id}", - :class => 'fr mr20 undis', - :title => l(:button_delete) - ) if comment.user_id == User.current.id %> - + <% if activity.class.to_s == 'TrainingTask' %> + <%= link_to(l(:button_delete), + {:controller => 'training_tasks', + :action => 'delete_journal', + :id => activity.id, + :journal_id=>comment.id, + :user_activity_id => user_activity_id, + :is_project => true}, + :method => 'get', + :confirm => l(:text_are_you_sure), + :remote=>true, + :id => "delete_reply_#{activity.id}_#{comment.id}", + :class => 'fr mr20 undis', + :title => l(:button_delete)) if comment.user_id == User.current.id %> + <% else %> + <%= link_to( + l(:button_delete), + {:controller => 'issues', + :action => 'delete_journal', + :id => activity.id, + :journal_id=>comment.id, + :user_activity_id => user_activity_id, + :is_project => true}, + :method => 'get', + :confirm => l(:text_are_you_sure), + :remote=>true, + :id => "delete_reply_#{activity.id}_#{comment.id}", + :class => 'fr mr20 undis', + :title => l(:button_delete)) if comment.user_id == User.current.id %> + <% end %>
    @@ -70,13 +107,13 @@
    <% if User.current.logged? %>
    - <%= form_for('new_form',:url => add_journal_issue_path(activity.id, :user_activity_id => user_activity_id, :is_project => true),:method => "post", :remote => true) do |f| %> - -
    - - + <%= form_for('new_form', :url => (activity.class.to_s == 'TrainingTask' ? add_journal_training_task_path(activity.id, :user_activity_id => user_activity_id, :is_project => true) : add_journal_issue_path(activity.id, :user_activity_id => user_activity_id, :is_project => true) ), :method => "post", :remote => true) do |f| %> + +
    + +
    -

    +

    <% end%>
    <% else %> diff --git a/app/views/projects/_project_issue_reply.html.erb b/app/views/projects/_project_issue_reply.html.erb index 95ffc1962..d67d4aabc 100644 --- a/app/views/projects/_project_issue_reply.html.erb +++ b/app/views/projects/_project_issue_reply.html.erb @@ -4,6 +4,6 @@
    <%= render :partial => 'projects/project_reply_banner', :locals => {:count => count, :activity => activity, :user_activity_id => user_activity_id, :expand_more =>no_children_comments[:three_more]} %>
    - <%= render :partial => "projects/project_issue_expand_show", :locals => {:comments => no_children_comments[:no_children_comments], :activity => activity, :user_activity_id => user_activity_id} %> + <%= render :partial => "projects/project_issue_expand_show", :locals => { :comments => no_children_comments[:no_children_comments], :activity => activity, :user_activity_id => user_activity_id} %>
    \ No newline at end of file diff --git a/app/views/projects/_project_reply_banner.html.erb b/app/views/projects/_project_reply_banner.html.erb index a1bbcdcbf..b9acfbb82 100644 --- a/app/views/projects/_project_reply_banner.html.erb +++ b/app/views/projects/_project_reply_banner.html.erb @@ -3,7 +3,7 @@ 回复 ︿ <%= count>0 ? "(#{count})" : "" %> - + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%>
    @@ -11,15 +11,19 @@ <% if expand_more %>
    <% if activity.class.to_s == 'Issue' %> - + 展开更多 <% elsif activity.class.to_s == 'Message' %> - + + 展开更多 + + <% elsif activity.class.to_s == 'TrainingTask' %> + 展开更多 <% else %> - + 展开更多 <% end %> diff --git a/app/views/projects/_reply_to.html.erb b/app/views/projects/_reply_to.html.erb index 943d0addf..482334738 100644 --- a/app/views/projects/_reply_to.html.erb +++ b/app/views/projects/_reply_to.html.erb @@ -26,6 +26,16 @@

    <% end %> + <% elsif @type == 'Training_task' %> + <%= form_for('new_form', :url => add_reply_training_task_path(reply.training_task.id, :is_project => true),:method => "post", :remote => true) do |f|%> + <%= hidden_field_tag 'journal_id',params[:journal_id],:value =>reply.id %> + <%= hidden_field_tag 'user_activity_id',params[:user_activity_id],:value =>@user_activity_id %> +
    + + +
    +

    + <% end %> <% end %>
    diff --git a/app/views/projects/_training_child_project_exec.html.erb b/app/views/projects/_training_child_project_exec.html.erb new file mode 100644 index 000000000..e8747a384 --- /dev/null +++ b/app/views/projects/_training_child_project_exec.html.erb @@ -0,0 +1,39 @@ +
    +
    +

    提示

    + +
    +
    +
    + +
    +
    \ No newline at end of file diff --git a/app/views/projects/add_script.js.erb b/app/views/projects/add_script.js.erb new file mode 100644 index 000000000..5e1b2630c --- /dev/null +++ b/app/views/projects/add_script.js.erb @@ -0,0 +1,2 @@ +$("#training_project_exec_tip").html('<%= escape_javascript(render :partial => 'projects/settings/training_project_exec_tip') %>'); +$("#training_project_filter_tip").html('<%= escape_javascript(render :partial => 'projects/settings/training_projects_filter_tip') %>'); \ No newline at end of file diff --git a/app/views/projects/settings.html.erb b/app/views/projects/settings.html.erb index 5ca0820ed..a5578284c 100644 --- a/app/views/projects/settings.html.erb +++ b/app/views/projects/settings.html.erb @@ -19,6 +19,9 @@ <% if User.current.allowed_to?(:manage_repository, @project) %>
  • 版本库
  • <% end %> + <% if !@project.enabled_modules.where("name = 'training_tasks'").empty? %> +
  • 实训任务
  • + <% end %> @@ -27,7 +30,6 @@
    <%= render :partial=>"projects/settings/new_edit" if User.current.allowed_to?(:edit_project, @project)%>
    -
    <%= render :partial=>"projects/settings/new_modules" if User.current.allowed_to?(:select_project_modules, @project)%>
    @@ -51,6 +53,10 @@
    <%= render :partial=>"projects/settings/new_repositories" if User.current.allowed_to?(:manage_repository, @project)%>
    + +
    + <%= render :partial=>"projects/settings/new_trainig_task" if is_project_manager?(User.current.id, @project.id) %> +
    diff --git a/app/views/projects/settings/_new_modules.html.erb b/app/views/projects/settings/_new_modules.html.erb index 6413823c5..196287449 100644 --- a/app/views/projects/settings/_new_modules.html.erb +++ b/app/views/projects/settings/_new_modules.html.erb @@ -1,42 +1,42 @@ - - - - - +

    问题跟踪模块与实训模块不能同时选择

    一旦选定并保存后,将不能修改

    + + + \ No newline at end of file diff --git a/app/views/projects/settings/_new_trainig_task.html.erb b/app/views/projects/settings/_new_trainig_task.html.erb new file mode 100644 index 000000000..4990544ce --- /dev/null +++ b/app/views/projects/settings/_new_trainig_task.html.erb @@ -0,0 +1,44 @@ +
    + <%= render :partial => "projects/settings/training_project_exec_tip" %> +
    + +
    +
    + <%= render :partial => "projects/settings/training_projects_filter_tip" %> +
    +
    +
    + <%= form_tag(url_for(:controller => 'projects', :action => 'add_script', :project_id => @project.id), :id => 'project_script_form', :method => "post", :remote => true) do %> + + + 取消 + 确定 + <% end %> +
    +
    + + diff --git a/app/views/projects/settings/_training_project_exec_tip.html.erb b/app/views/projects/settings/_training_project_exec_tip.html.erb new file mode 100644 index 000000000..3445f4c9b --- /dev/null +++ b/app/views/projects/settings/_training_project_exec_tip.html.erb @@ -0,0 +1,3 @@ +<% if @notice %> +

    <%= @notice %>

    +<% end %> diff --git a/app/views/projects/settings/_training_projects_filter_tip.html.erb b/app/views/projects/settings/_training_projects_filter_tip.html.erb new file mode 100644 index 000000000..28e936960 --- /dev/null +++ b/app/views/projects/settings/_training_projects_filter_tip.html.erb @@ -0,0 +1,7 @@ +<% unless @project.script.blank? %> + <% if @project.training_status == 1 %> + <%= link_to "重启实训", training_project_update_project_path, :class => "fr sy_btn_green mb10", :remote => true %> + <% else %> + <%= link_to "开启实训", training_project_execute_project_path, :class => "fr sy_btn_green mb10", :remote => true %> + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index 85dda34af..7b3976619 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -1,6 +1,6 @@
    -
    <%= render :partial => 'projects/invite_code' %>
    +
    <%= render :partial => 'projects/invite_code' %>
    <% if @project.description.blank? %>

    <%= @project.name %>

    @@ -24,15 +24,15 @@
  • <%= link_to "资源库动态", {:controller => "projects", :action => "show", :type => "attachment"}, :class => "homepagePostTypeResource resourcesGrey" %>
  • <%= link_to "讨论区动态", {:controller => "projects", :action => "show", :type => "message"}, :class => "homepagePostTypeForum postTypeGrey" %>
  • - + <% if @project.is_training_project? && is_project_member?(User.current.id, @project.id) %> +
  • <%= link_to "实训任务动态", {:controller => "projects", :action => "show", :type => "training_task"}, :class => "homepagePostTypeForum postTypeGrey" %>
  • + <% end %>
    - -
    <%= render :partial => "project_activities", :locals => {:forge_acts => @events_pages, :page => 0, :type => @type} %> diff --git a/app/views/projects/task_execute.js.erb b/app/views/projects/task_execute.js.erb new file mode 100644 index 000000000..e6528db39 --- /dev/null +++ b/app/views/projects/task_execute.js.erb @@ -0,0 +1,2 @@ +$("#training_project_task_status_<%= @training_task.id %>").html('<%= escape_javascript( render :partial => 'training_tasks/action_status', :locals => {:activity => @training_task}) %>'); +$("#training_task_details").html('<%= escape_javascript( render :partial => 'training_tasks/training_task_details', :locals => {:activity => @training_task, :project_id => @project.id}) %>'); \ No newline at end of file diff --git a/app/views/projects/training_chiled_project_exec.js.erb b/app/views/projects/training_chiled_project_exec.js.erb new file mode 100644 index 000000000..91b7651ea --- /dev/null +++ b/app/views/projects/training_chiled_project_exec.js.erb @@ -0,0 +1,3 @@ +var htmlvalue = "<%= escape_javascript(render :partial => 'projects/training_child_project_exec') %>"; +pop_box_new(htmlvalue,460,316); + diff --git a/app/views/projects/training_project_execute.js.erb b/app/views/projects/training_project_execute.js.erb new file mode 100644 index 000000000..5e1b2630c --- /dev/null +++ b/app/views/projects/training_project_execute.js.erb @@ -0,0 +1,2 @@ +$("#training_project_exec_tip").html('<%= escape_javascript(render :partial => 'projects/settings/training_project_exec_tip') %>'); +$("#training_project_filter_tip").html('<%= escape_javascript(render :partial => 'projects/settings/training_projects_filter_tip') %>'); \ No newline at end of file diff --git a/app/views/projects/training_project_update.js.erb b/app/views/projects/training_project_update.js.erb new file mode 100644 index 000000000..5e1b2630c --- /dev/null +++ b/app/views/projects/training_project_update.js.erb @@ -0,0 +1,2 @@ +$("#training_project_exec_tip").html('<%= escape_javascript(render :partial => 'projects/settings/training_project_exec_tip') %>'); +$("#training_project_filter_tip").html('<%= escape_javascript(render :partial => 'projects/settings/training_projects_filter_tip') %>'); \ No newline at end of file diff --git a/app/views/projects/training_task_status.js.erb b/app/views/projects/training_task_status.js.erb new file mode 100644 index 000000000..1dd2affac --- /dev/null +++ b/app/views/projects/training_task_status.js.erb @@ -0,0 +1 @@ +$("#task_action_status_<%= @training_task.id %>").html('<%= escape_javascript( render :partial => 'training_tasks/action_status', :locals => {:activity => @training_task}) %>'); \ No newline at end of file diff --git a/app/views/quality_analysis/_result_list.html.erb b/app/views/quality_analysis/_result_list.html.erb index 62837663e..135e59621 100644 --- a/app/views/quality_analysis/_result_list.html.erb +++ b/app/views/quality_analysis/_result_list.html.erb @@ -8,7 +8,7 @@ - + @@ -20,7 +20,7 @@ <% if @quality_analyses && @quality_analyses.count > 0 %> <% @quality_analyses.each do |qa| %> - + diff --git a/app/views/repositories/_forked_popbox.html.erb b/app/views/repositories/_forked_popbox.html.erb index c28bef2d6..eca24ea24 100644 --- a/app/views/repositories/_forked_popbox.html.erb +++ b/app/views/repositories/_forked_popbox.html.erb @@ -6,16 +6,17 @@
    +
    \ No newline at end of file diff --git a/app/views/repositories/_latest_commit.html.erb b/app/views/repositories/_latest_commit.html.erb index 204196442..acce15cd8 100644 --- a/app/views/repositories/_latest_commit.html.erb +++ b/app/views/repositories/_latest_commit.html.erb @@ -1,11 +1,11 @@ -
    - <% if @changesets_latest_coimmit %> +<% if @changesets_latest_coimmit && @changesets_latest_coimmit.try(:time) %> +
    <%= image_tag(url_to_avatar(user_commit_rep(@changesets_latest_coimmit.try(:author_email))), :width => "25", :height => "25", :class => "fl portraitRadius mt2 ml4 mr5") %> <%= link_to_user_mail(@changesets_latest_coimmit.try(:author_email), "fb fontGrey3 mr5 fl hidden maxwidth150 ml5") %>
    提交于 <%= time_tag(@changesets_latest_coimmit.try(:time)) %> 前:
    <%= @changesets_latest_coimmit.message %>
    - <% end %> - <% if @entry && @entry.kind == 'file' %> - <%= render :partial => 'link_to_functions' %> - <% end %> -
    \ No newline at end of file + <% if @entry && @entry.kind == 'file' %> + <%= render :partial => 'link_to_functions' %> + <% end %> +
    +<% end %> \ No newline at end of file diff --git a/app/views/repositories/forked.html.erb b/app/views/repositories/forked.html.erb index 2860b9898..8b1378917 100644 --- a/app/views/repositories/forked.html.erb +++ b/app/views/repositories/forked.html.erb @@ -1,10 +1 @@ -
    -

    <%= render :partial => 'breadcrumbs', :locals => {:path => @path, :kind => 'dir', :revision => @rev} %>

    -
    -<%= form_for('forked',:url => {:controller => 'repositories', :action => 'forked'},:method => "post") do |f| %> - - -<% end %> -<%= @project.id %> -<%= @repository.id %> -<%= User.current %> + diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index d8afa6a4c..bd8d48e9a 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -1,86 +1,70 @@ -<%#= call_hook(:view_repositories_show_contextual, {:repository => @repository, :project => @project}) %>
    -
    - <% if @entries.nil? %> - <%# 未提交代码提示 %> -
    - <% if @entries.nil? && authorize_for('repositories', 'browse') %> -
    - 该版本库还没有上传代码! -
    - <% end %> - <% if @repository.type.to_s == "Repository::Gitlab" %> - 版本库地址:<%= @repos_url %> - <% else %> - 版本库地址:<%= h @repository.url %> - <% end %> -
    -
    - <% else %> -
      -
    • - <%=link_to "#{choise_commit_count(@changesets_all_count, @g_project.commit_count.to_i)}", - {:action => 'changes', :path => to_path_param(@path), :id => @project, :repository_id => @repository.identifier_param, - :rev => @rev, :page => 1 ,:commit_count =>"#{@changesets_all_count}"}, :class => "linkBlue fb" %> 提交 -
    • -
    • - <%= @repository.branches.count %>分支 -
    • -
    • - <%=link_to "贡献统计", stats_repository_project_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, - :creator => @creator, :default_branch => @g_default_branch ) %> -
    • -
    -
    -
    - <%= render :partial => 'navigation' %> -
    - ZIP下载 - <% if User.current.member_of?(@project) && @project.is_public? %> - <% if quality_analysis(User.current.try(:login), @repository.id).nil? %> - <%= link_to "质量分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "1"), :remote => true, :class => "btn_zipdown fl ml10" %> - <% else %> - <%= link_to "重新分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "2"), :remote => true, :class => "btn_zipdown fl ml10" %> - <% end %> - <% end %> - <% unless QualityAnalysis.where(:project_id => @project.id).first.nil? %> - <%= link_to "代码分析结果", project_quality_analysis_path(:project_id => @project.id), :class => "btn_zipdown fl ml10" %> - <% end %> - -
    - - - -
    -
    - -
    - <%= render :partial => 'latest_commit' %> -
    +
    +
      +
    • + <%=link_to "#{choise_commit_count(@changesets_all_count, @g_project.commit_count.to_i)}", + {:action => 'changes', :path => to_path_param(@path), :id => @project, :repository_id => @repository.identifier_param, + :rev => @rev, :page => 1 ,:commit_count =>"#{@changesets_all_count}"}, :class => "linkBlue fb" %> 提交 +
    • +
    • + <%= @repository.branches.count %>分支 +
    • +
    • + <%=link_to "贡献统计", stats_repository_project_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, + :creator => @creator, :default_branch => @g_default_branch ) %> +
    • +
    +
    +
    + <%= render :partial => 'navigation' %> +
    + ZIP下载 + <% if !@entries.blank? && User.current.member_of?(@project) && @project.is_public? %> + <% if quality_analysis(User.current.try(:login), @repository.id).nil? %> + <%= link_to "质量分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "1"), :remote => true, :class => "btn_zipdown fl ml10" %> + <% else %> + <%= link_to "重新分析", quality_analysis_path(:id => @project.id, :repository_id => @repository.identifier, :rev => @rev, :default_branch => @g_default_branch, :type => "2"), :remote => true, :class => "btn_zipdown fl ml10" %> + <% end %> + <% end %> + <% unless QualityAnalysis.where(:project_id => @project.id).first.nil? %> + <%= link_to "代码分析结果", project_quality_analysis_path(:project_id => @project.id), :class => "btn_zipdown fl ml10" %> <% end %> - <% if !@entries.nil? && authorize_for('repositories', 'browse') %> +
    + + + +
    +
    + +
    + <%= render :partial => 'latest_commit' %> +
    + + <% if !@entries.blank? && authorize_for('repositories', 'browse') %> <%= render :partial => 'dir_list' %> + <% else %> + <%= render :partial => "projects/no_data" %> <% end %> <% memo = Memo.where(:id => 1232).first %> <% unless memo.nil? %> - <%=Setting.host_name %>/forums/1/memos/1232" class="linkBlue2" target="_blank">如何提交代码 + <%=Setting.host_name %>/forums/1/memos/1232" class="linkBlue2" target="_blank">如何提交代码 <% end %> <% unless @entries.blank? %> -
    - 导出统计结果: - <%= link_to "最近一周", {:controller => 'repositories', :action => 'export_rep_static', :format => 'xls', :rev => @rev, :cycle => "week" }, :class => "linkBlue2" %> | - <%= link_to "最近一月", {:controller => 'repositories', :action => 'export_rep_static', :format => 'xls', :rev => @rev, :cycle => "month" }, :class => "linkBlue2" %> -
    -
    +
    + 导出统计结果: + <%= link_to "最近一周", {:controller => 'repositories', :action => 'export_rep_static', :format => 'xls', :rev => @rev, :cycle => "week" }, :class => "linkBlue2" %> | + <%= link_to "最近一月", {:controller => 'repositories', :action => 'export_rep_static', :format => 'xls', :rev => @rev, :cycle => "month" }, :class => "linkBlue2" %> +
    +
    <% end %> - <%#= link_to "导出excel", {:controller => 'repositories', :action => 'export_rep_static', :rev => @rev}, :format => 'xls' %> - -
    + <%#= link_to "导出excel", {:controller => 'repositories', :action => 'export_rep_static', :rev => @rev}, :format => 'xls' %> + +
    <%# content_for :header_tags do %> - <%#= stylesheet_link_tag "scm" %> +<%#= stylesheet_link_tag "scm" %> <%# end %> <% html_title(l(:label_repository)) -%> diff --git a/app/views/training_tasks/_action_status.html.erb b/app/views/training_tasks/_action_status.html.erb new file mode 100644 index 000000000..ed5a48dca --- /dev/null +++ b/app/views/training_tasks/_action_status.html.erb @@ -0,0 +1,16 @@ +<%# activity = activity.nil? ? local_assigns[:activity] : activity %> +
    + <% if activity.status == 1 %> + 本任务已通过测评,处于关闭状态。 + <% elsif activity.status == 2 %> + 当前任务正在后台测评中,稍后将显示您的任务完成情况...... + <% else %> + <% if User.current.member_of?(@project) && @project.is_child_training_project? %> + <%= link_to "提交评测", task_execute_project_path(@project, :training_task_id => activity.id), :class => "task-display-span bBlue mt10", :remote => true %> + <% end %> + <% end %> +
    + + + + diff --git a/app/views/training_tasks/_all_list.html.erb b/app/views/training_tasks/_all_list.html.erb new file mode 100644 index 000000000..59549283d --- /dev/null +++ b/app/views/training_tasks/_all_list.html.erb @@ -0,0 +1,3 @@ +<% tasks.each do |task| -%> + <%= render :partial => 'content_list', :locals => {:activity => task, :user_activity_id => task.id} %> +<% end %> \ No newline at end of file diff --git a/app/views/training_tasks/_content_list.html.erb b/app/views/training_tasks/_content_list.html.erb new file mode 100644 index 000000000..b98e44afe --- /dev/null +++ b/app/views/training_tasks/_content_list.html.erb @@ -0,0 +1,66 @@ +<% unless activity.author.nil? %> + + + + <% if @project.is_child_training_project? %> + + <% end %> + +<% end %> + + + diff --git a/app/views/training_tasks/_detail.html.erb b/app/views/training_tasks/_detail.html.erb new file mode 100644 index 000000000..7c272e1cb --- /dev/null +++ b/app/views/training_tasks/_detail.html.erb @@ -0,0 +1,45 @@ +
    +
    + <%= link_to image_tag(url_to_avatar(@training_task.author), :width => 46, :height => 46), user_path(@training_task.author), :class => "ping_dispic" %> +
    +
    +
    + <%= render :partial => "training_tasks/training_task_details", :locals => {:activity => @training_task, :project_id => @project.id} %> +
    +
    +
    + 由<%=link_to @training_task.author.show_name, user_path(@training_task.author), :class => "link-blue" %>添加于 <%= format_time(@training_task.created_at).html_safe %> +
    + + + + <% if User.current.logged? && is_project_manager?(User.current.id, @project.id) || @training_task.author_id == User.current.id %> + <%= link_to l(:button_delete), training_task_path(@training_task.id, :project_id => @project.id), :data => {:confirm => l(:text_trainig_task_destroy_confirmation)}, :method => :delete, :class => 'talk_edit fr' %> + <%= link_to l(:button_edit), edit_training_task_path(@training_task), :class => 'talk_edit fr', :accesskey => accesskey(:edit) %> + <% end %> + +
    + <% if @training_task.description? || @training_task.attachments.any? -%> +
    + <% if @training_task.description? %> + <%= textAreailizable @training_task, :description, :attachments => @training_task.attachments %> + <% end %> +
    + <% end -%> + + <%# 附件局部刷新 %> +
    + <%= render :partial => 'task_attachments', :locals => {:training_task => @training_task} %> +
    +
    +
    + <%= render :partial => "training_tasks/action_status", :locals => {:activity => @training_task} %> +
    +
    + + \ No newline at end of file diff --git a/app/views/training_tasks/_edit.html.erb b/app/views/training_tasks/_edit.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/training_tasks/_form.html.erb b/app/views/training_tasks/_form.html.erb new file mode 100644 index 000000000..a7dcee893 --- /dev/null +++ b/app/views/training_tasks/_form.html.erb @@ -0,0 +1,49 @@ + + diff --git a/app/views/training_tasks/_issue_replies.html.erb b/app/views/training_tasks/_issue_replies.html.erb new file mode 100644 index 000000000..ee31a78ab --- /dev/null +++ b/app/views/training_tasks/_issue_replies.html.erb @@ -0,0 +1,94 @@ + +
    + +
    + <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(@training_task.author_id), :alt => "用户头像" %> +
    + +
    + <% if User.current.logged? %> +
    + <%= form_for('new_form', :url => add_journal_project_training_task_path(@training_task.id, :is_issue_show => true), :method => "post", :remote => true) do |f| %> + +
    +
    + +
    +
    + <%= render :partial => 'attachments/issue_reply', :locals => {:container => @training_task} %> +
    + + +
    + <% end %> +
    + <% else %> + <%= render :partial => "users/show_unlogged" %> + <% end %> +
    + +
    +
    +
    \ No newline at end of file diff --git a/app/views/training_tasks/_reply_banner.html.erb b/app/views/training_tasks/_reply_banner.html.erb new file mode 100644 index 000000000..0cd357b65 --- /dev/null +++ b/app/views/training_tasks/_reply_banner.html.erb @@ -0,0 +1,6 @@ +<% count = @training_task.journals.count %> +回复<%= count > 0 ? "(#{count})" : "" %> + + + <%=render :partial => "praise_tread/praise", :locals => {:activity => @training_task, :user_activity_id => @training_task.id, :type => "activity"}%> + \ No newline at end of file diff --git a/app/views/training_tasks/_task_attachments.html.erb b/app/views/training_tasks/_task_attachments.html.erb new file mode 100644 index 000000000..3036a625a --- /dev/null +++ b/app/views/training_tasks/_task_attachments.html.erb @@ -0,0 +1,10 @@ +<% if training_task.attachments.any? %> +
    + + + <%= link_to_attachment_project training_task, :thumbnails => true %> +
    + <%#= call_hook(:view_issues_show_description_bottom, :training_task => training_task) %> +
    +
    +<% end %> \ No newline at end of file diff --git a/app/views/training_tasks/_training_task_details.html.erb b/app/views/training_tasks/_training_task_details.html.erb new file mode 100644 index 000000000..4c1bc19dc --- /dev/null +++ b/app/views/training_tasks/_training_task_details.html.erb @@ -0,0 +1,16 @@ +
    + <% if activity.status == 1 %> +
    + <% else %> +
    + <% end %> + step<%= activity.position %> + + <%= link_to activity.subject.to_s, training_task_url(activity), :class => "postGrey ml5 ", :target => "_blank", :style => "" %> +
    + + + + + +
    \ No newline at end of file diff --git a/app/views/training_tasks/_training_tasks_reply_ke_form.html.erb b/app/views/training_tasks/_training_tasks_reply_ke_form.html.erb new file mode 100644 index 000000000..b01adf0e6 --- /dev/null +++ b/app/views/training_tasks/_training_tasks_reply_ke_form.html.erb @@ -0,0 +1,27 @@ +
    + +
    + <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(@training_task.author_id), :alt => "用户头像" %> +
    + +
    + <% if User.current.logged? %> +
    + <%= form_for('new_form', :url => add_reply_training_task_path(@training_task, :is_issue_show => true), :method => "post", :remote => true) do |f|%> + +
    +
    + +
    + + +
    + <% end %> +
    + <% else %> + <%= render :partial => "users/show_unlogged" %> + <% end %> +
    + +
    +
    \ No newline at end of file diff --git a/app/views/training_tasks/add_journal.js.erb b/app/views/training_tasks/add_journal.js.erb new file mode 100644 index 000000000..b76e03c68 --- /dev/null +++ b/app/views/training_tasks/add_journal.js.erb @@ -0,0 +1,6 @@ +<% if params[:is_project] %> + $("#div_user_issue_reply_<%= @user_activity_id %>").html("<%= escape_javascript(render :partial => 'projects/project_issue_reply', :locals => {:activity => @training_task, :user_activity_id => @user_activity_id}) %>"); +<% else %> + $("#div_user_issue_reply_<%= @user_activity_id %>").html("<%= escape_javascript(render :partial => 'users/project_issue_reply', :locals => {:activity => @training_task, :user_activity_id => @user_activity_id}) %>"); +<% end %> +sd_create_editor_from_data(<%= @user_activity_id %>, null, "100%", "UserActivity"); \ No newline at end of file diff --git a/app/views/training_tasks/add_reply.js.erb b/app/views/training_tasks/add_reply.js.erb new file mode 100644 index 000000000..016e13176 --- /dev/null +++ b/app/views/training_tasks/add_reply.js.erb @@ -0,0 +1,13 @@ +<% if @user_activity_id %> +<%# 动态中 %> +<% if params[:is_project] %> +$("#div_user_issue_reply_<%= @user_activity_id %>").html("<%= escape_javascript(render :partial => 'projects/project_issue_reply', :locals => {:activity => @training_task, :user_activity_id => @user_activity_id}) %>"); +<% else %> +$("#div_user_issue_reply_<%= @user_activity_id %>").html("<%= escape_javascript(render :partial => 'users/project_issue_reply', :locals => {:activity => @training_task, :user_activity_id => @user_activity_id}) %>"); +<% end %> + +sd_create_editor_from_data(<%= @user_activity_id %>, null, "100%","<%= @training_task.class.name %>"); +<% else %> +<%# issue详情 %> +<%= render "jounal_refresh" %> +<% end %> \ No newline at end of file diff --git a/app/views/training_tasks/delete_journal.js.erb b/app/views/training_tasks/delete_journal.js.erb new file mode 100644 index 000000000..1a11d3488 --- /dev/null +++ b/app/views/training_tasks/delete_journal.js.erb @@ -0,0 +1,14 @@ +<% if @user_activity_id %> + <% if @is_project %> + $("#div_user_issue_reply_<%= @user_activity_id %>").html("<%= escape_javascript(render :partial => 'projects/project_issue_reply', + :locals => {:activity => @training_task, + :user_activity_id => @user_activity_id}) %>"); + <% else %> + $("#div_user_issue_reply_<%= @user_activity_id %>").html("<%= escape_javascript(render :partial => 'users/project_issue_reply', + :locals => {:activity => @training_task, + :user_activity_id => @user_activity_id}) %>"); + <% end %> + sd_create_editor_from_data(<%= @user_activity_id %>, null, "100%","<%= @training_task.class.name %>"); +<% else %> + <%= render "jounal_refresh" %> +<% end %> \ No newline at end of file diff --git a/app/views/training_tasks/edit.html.erb b/app/views/training_tasks/edit.html.erb new file mode 100644 index 000000000..14732824b --- /dev/null +++ b/app/views/training_tasks/edit.html.erb @@ -0,0 +1,15 @@ +
    + <%= content_for(:header_tags) do %> + <%= import_ke(enable_at: true, prettify: false, init_activity: false) %> + <% end %> + +
    +
    + <%= labelled_form_for @training_task, :html => {:id => 'project_training_form', :multipart => true} do |f| %> +
    + <%= render :partial => 'training_tasks/form', :locals => {:f => f} %> +
    + <% end %> +
    +
    +
    diff --git a/app/views/training_tasks/index.html.erb b/app/views/training_tasks/index.html.erb new file mode 100644 index 000000000..7cf63aea5 --- /dev/null +++ b/app/views/training_tasks/index.html.erb @@ -0,0 +1,251 @@ +<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: true,init_activity: true) %> +<% end %> + + + + +
    + <% if !@project.is_child_training_project? || User.current.admin? %> + 新建 +
    + <% else %> +
    +

    完成任务后,请点击“提交评测”按钮,若通过系统测试,将为你发送下一个任务,祝你早日通关,加油!

    +
    + <% end %> + <% if @training_tasks.empty? %> + <%= render :partial => "projects/no_data" %> + <% else %> +
    +
    +
    名称名称 分支 语言 路径
    <%=link_to qa.sonar_name, project_quality_analysis_path(:resource_id => qa.sonar_name, :branch => (qa.branch.nil? ? "master" : qa.branch)), :class => "analysis-result-name fl fontBlue2 hidden" %><%=link_to qa.sonar_name, project_quality_analysis_path(:resource_id => qa.sonar_name, :branch => (qa.branch.nil? ? "master" : qa.branch)), :class => "analysis-result-name fl fontBlue2 hidden" %> <%= qa.branch %> <%= qa.language %> <%= qa.path %>
    + <% if activity.status == 1 %> +
    + <% else %> +
    + <% end %> +
    +
    + + step<%= activity.position %> + <%= activity.subject.to_s %> + + <% if activity.status == 1 %> + 已解决 + <% else %> + 正在解决中 + <% end %> +
    +
    +
    +

    <%= format_time(activity.created_at) %>发布

    +

    <%= format_time(activity.updated_at) %>更新

    +
    +
    +
    + <% if activity.journals.count != 0 %> + + <%= activity.journals.count %> + <% end %> + +
    + <%= render :partial => 'action_status', :locals => {:activity => activity} %> +
    +
    + + + + + <% if @project.is_child_training_project? %> + + <% end %> + + + + <%= render :partial => 'all_list', :locals => {:tasks => @training_tasks} %> + +

    所有<%= @training_tasks_count %>

      
    +
    +
    +
      + +
    +
    +
    +
      + <%= pagination_links_full @training_tasks_pages, @training_tasks_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true %> +
    +
    +
    +
    +
    + + <% end %> + + \ No newline at end of file diff --git a/app/views/training_tasks/index.js.erb b/app/views/training_tasks/index.js.erb new file mode 100644 index 000000000..d0ac3f0a6 --- /dev/null +++ b/app/views/training_tasks/index.js.erb @@ -0,0 +1,3 @@ +$("#issue_list").html("<%= escape_javascript(render :partial => 'training_tasks/all_list',:locals => {:tasks => @training_tasks, :project=> @project})%>"); +$("#issue_list_pagination").html('<%= pagination_links_full @training_tasks_pages, @training_tasks_count, :training_tasks => @training_tasks, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true %>'); + diff --git a/app/views/training_tasks/new.html.erb b/app/views/training_tasks/new.html.erb new file mode 100644 index 000000000..ab85e68a4 --- /dev/null +++ b/app/views/training_tasks/new.html.erb @@ -0,0 +1,27 @@ +<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: true, prettify: false, init_activity: false) %> +<% end %> + + + +
    +
    + <%#= call_hook(:view_issues_new_top, {:training_task => @training_task}) %> + <%= labelled_form_for @training_task, :url => project_training_tasks_url(@project), + :html => {:id => 'project_training_form', :multipart => true} do |f| %> + <%= error_messages_for 'training_task' %> + <%= hidden_field_tag 'copy_from', params[:copy_from] if params[:copy_from] %> +
    + <%= render :partial => 'training_tasks/form', :locals => {:f => f} %> +
    + <% end %> +
    +
    + + + diff --git a/app/views/training_tasks/reply.js.erb b/app/views/training_tasks/reply.js.erb new file mode 100644 index 000000000..d53160573 --- /dev/null +++ b/app/views/training_tasks/reply.js.erb @@ -0,0 +1,12 @@ +<% if params[:is_project]%> +$("#reply_message_<%= @jour.id %>"). +<% else %> +if($("#reply_message_<%= @jour.id %>").length > 0) { + $("#reply_message_<%= @jour.id %>").replaceWith("<%= escape_javascript(render :partial => 'training_tasks/training_tasks_reply_ke_form') %>"); + $(function(){ + sd_create_editor_from_data(<%= @jour.id %>, null, "100%", "<%= @jour.class.name %>"); + }); +}else if($("#reply_to_message_<%= @jour.id %>").length >0) { + $("#reply_to_message_<%= @jour.id %>").replaceWith("

    "); +} +<% end %> \ No newline at end of file diff --git a/app/views/training_tasks/show.html.erb b/app/views/training_tasks/show.html.erb new file mode 100644 index 000000000..f125717b1 --- /dev/null +++ b/app/views/training_tasks/show.html.erb @@ -0,0 +1,42 @@ +<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: true) %> + <%= javascript_include_tag 'create_kindeditor'%> +<% end %> + + +
    + + +
    +
    +
    +
    + <%= render :partial => 'detail'%> +
    +
    + + +
    +
    +
    +
    +
    + <%= render :partial => 'reply_banner' %> +
    +
    +
    +
    + <%= render :partial => 'issue_replies',:locals => {:issue => @training_task, :replies_all_i => 0 } %> +
    +
    +
    +
    + +
    +
    + diff --git a/app/views/training_tasks/show.js.erb b/app/views/training_tasks/show.js.erb new file mode 100644 index 000000000..9db0abd72 --- /dev/null +++ b/app/views/training_tasks/show.js.erb @@ -0,0 +1,19 @@ +// $("#div_user_issue_reply_<%#= @user_activity_id %>").html("<%#= escape_javascript(render :partial => 'projects/project_issue_reply', :locals => {:activity => @issue, :user_activity_id => @user_activity_id}) %>"); + +$("#reply_div_<%= @training_task.id %>").html("<%= escape_javascript(render :partial => 'training_tasks/issue_replies', :locals => {:issue => @training_task}) %>"); +$("#div_issue_attachment_<%=@training_task.id %>").html("<%= escape_javascript(render :partial => 'issues/issue_attachments', :locals => {:issue => @training_task}) %>"); +issue_desc_editor = KindEditor.create('#issue_description', + {"width":"85%", + "resizeType":0, + "no_label":true, + "at_id":<%= @training_task.project_id %>, + "at_type":"Project", + "autoHeightMode":true, + "afterCreate":"eval(function(){ if(typeof enablePasteImg ==='function'){enablePasteImg(self);};if(typeof enableAt ==='function'){enableAt(self, \"<%= @training_task.project_id %>\", 'Project');}; this.loadPlugin('autoheight')})", + "emotionsBasePath":'<%= Setting.host_name%>', + "height":300, + "allowFileManager":true, + "uploadJson":"/kindeditor/upload", + "fileManagerJson":"/kindeditor/filemanager"}); +$(".homepagePostReplyBannerCount").html('<%= escape_javascript(render :partial => 'reply_banner') %>'); +sd_create_editor_from_data(<%= @training_task.id %>, null, "100%", "<%= @training_task.class.name %>"); \ No newline at end of file diff --git a/app/views/users/_comment_reply.html.erb b/app/views/users/_comment_reply.html.erb index 0720d2e25..c405b1ff0 100644 --- a/app/views/users/_comment_reply.html.erb +++ b/app/views/users/_comment_reply.html.erb @@ -1,8 +1,8 @@
    <% unless comment.parent.nil? %>
    - <%=render :partial => 'users/comment_reply', :locals => {:comment => comment.parent, :type => type, :user_activity_id => user_activity_id, :parent_id => parent_id} %> + <%= render :partial => 'users/comment_reply', :locals => {:comment => comment.parent, :type => type, :user_activity_id => user_activity_id, :parent_id => parent_id} %>
    <% end %> - <%=render :partial => 'users/comment_reply_detail', :locals => {:comment => comment, :type => type, :user_activity_id => user_activity_id, :parent_id => parent_id} %> + <%= render :partial => 'users/comment_reply_detail', :locals => {:comment => comment, :type => type, :user_activity_id => user_activity_id, :parent_id => parent_id} %>
    \ No newline at end of file diff --git a/app/views/users/_comment_reply_detail.html.erb b/app/views/users/_comment_reply_detail.html.erb index 12cd6874a..587704075 100644 --- a/app/views/users/_comment_reply_detail.html.erb +++ b/app/views/users/_comment_reply_detail.html.erb @@ -1,7 +1,7 @@
    <%= link_to image_tag(url_to_avatar(comment.creator_user), :width => "33", :height => "33"), user_path(comment.creator_user), :alt => "用户头像" %>
    -
    +
    <%= link_to comment.creator_user.show_name, user_path(comment.creator_user), :class => "content-username" %> <%= time_from_now(comment.respond_to?(:created_on) ? comment.created_on : comment.created_at) %>
    @@ -26,23 +26,31 @@ <% topic = comment.root %> <% if !topic.locked? && authorize_for('messages', 'reply') %> - <%= link_to( - l(:button_reply), - {:controller => 'users' ,:action => 'reply_to_comment', :reply_id => comment.id, :type => type, :user_activity_id => user_activity_id, :parent_id => parent_id}, - :remote => true, - :method => 'get', - :title => l(:button_reply)) %> + <%= link_to(l(:button_reply), + {:controller => 'users' , + :action => 'reply_to_comment', + :reply_id => comment.id, + :type => type, + :user_activity_id => user_activity_id, + :parent_id => parent_id}, + :remote => true, + :method => 'get', + :title => l(:button_reply)) %> <% end %> <% else %> - <%= link_to( - l(:button_reply), - {:controller => 'users' ,:action => 'reply_to_comment', :reply_id => comment.id, :type => type, :user_activity_id => user_activity_id, :parent_id => parent_id}, - :remote => true, - :method => 'get', - :title => l(:button_reply)) %> + <%= link_to(l(:button_reply), + {:controller => 'users', + :action => 'reply_to_comment', + :reply_id => comment.id, + :type => type, + :user_activity_id => user_activity_id, + :parent_id => parent_id}, + :remote => true, + :method => 'get', + :title => l(:button_reply)) %> <% end %> diff --git a/app/views/users/_join_contest_applied_message.html.erb b/app/views/users/_join_contest_applied_message.html.erb index 6ec2ab642..6ee35b1af 100644 --- a/app/views/users/_join_contest_applied_message.html.erb +++ b/app/views/users/_join_contest_applied_message.html.erb @@ -13,7 +13,7 @@ :class => "newsBlue homepageNewsPublisher", :target => '_blank' %> - <%= message_user.user_extensions.school_id.blank? ? "" : "来自"+message_user.user_extensions.school.name+"," %> + <%= message_user.user_extensions.school_id.blank? || message_user.user_extensions.school.nil? ? "" : "来自"+message_user.user_extensions.school.name+"," %> 申请以"<%= get_role_str ma.role %>"的身份加入竞赛: diff --git a/app/views/users/_news_contents.html.erb b/app/views/users/_news_contents.html.erb index e421fd442..e46901d46 100644 --- a/app/views/users/_news_contents.html.erb +++ b/app/views/users/_news_contents.html.erb @@ -6,7 +6,7 @@ <% parents_rely = [] %> <% parents_rely = get_reply_parents parents_rely, comment %> <% length = parents_rely.length %> -
    +
    <% if length <= 5 %> <%=render :partial => 'users/comment_reply', :locals => {:comment => comment.parent, :type => type, :user_activity_id => user_activity_id, :parent_id => comment.id} %> <% else %> diff --git a/app/views/users/_user_journalsformessage.html.erb b/app/views/users/_user_journalsformessage.html.erb index cd79b9052..340b4ab78 100644 --- a/app/views/users/_user_journalsformessage.html.erb +++ b/app/views/users/_user_journalsformessage.html.erb @@ -1,4 +1,4 @@ -
    +
    <%= link_to image_tag(url_to_avatar(activity.user), :width => "50", :height => "50"), user_path(activity.user), :alt => "用户头像" %> diff --git a/app/views/users/_user_message_contest.html.erb b/app/views/users/_user_message_contest.html.erb index 12292620f..04b83d09c 100644 --- a/app/views/users/_user_message_contest.html.erb +++ b/app/views/users/_user_message_contest.html.erb @@ -25,7 +25,7 @@ <%=link_to user.show_name, user_path(user), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %> - <%= user.user_extensions.school_id.blank? ? "" : "来自"+user.user_extensions.school.name+"," %> + <%= user.user_extensions.school_id.blank? || user.user_extensions.school.nil? ? "" : "来自"+user.user_extensions.school.name+"," %> 申请以"<%= role_str%>"的身份加入竞赛: diff --git a/app/views/users/all_journals.js.erb b/app/views/users/all_journals.js.erb index bcba9b5fb..05467dd7f 100644 --- a/app/views/users/all_journals.js.erb +++ b/app/views/users/all_journals.js.erb @@ -1,17 +1,55 @@ <% if params[:type] == 'HomeworkCommon' || params[:type] == 'Work' %> -$('#reply_div_<%= @user_activity_id %>').html('<%=escape_javascript(render :partial => 'users/news_replies', :locals => {:comments => @journals, :type => @type, :is_teacher => @is_teacher, :user_activity_id => @user_activity_id, :activity_id => params[:id].to_i}) %>'); + $('#reply_div_<%= @user_activity_id %>').html('<%= escape_javascript(render :partial => 'users/news_replies', + :locals => {:comments => @journals, + :type => @type, + :is_teacher => @is_teacher, + :user_activity_id => @user_activity_id, + :activity_id => params[:id].to_i}) %>'); <% elsif params[:type] == 'JournalsForMessage' %> -$('#reply_div_<%= @user_activity_id %>').html('<%=escape_javascript(render :partial => 'users/message_replies', :locals => {:comments => @journals,:user_activity_id => @user_activity_id, :type => @type, :activity_id =>params[:id].to_i}) %>'); + $('#reply_div_<%= @user_activity_id %>').html('<%= escape_javascript(render :partial => 'users/message_replies', + :locals => {:comments => @journals, + :user_activity_id => @user_activity_id, + :type => @type, + :activity_id =>params[:id].to_i}) %>'); <% elsif params[:type] == 'Message' %> -$('#reply_div_<%= params[:div_id].to_i %>').html('<%=escape_javascript(render :partial => 'users/message_replies', :locals => {:comments => @journals,:user_activity_id => @user_activity_id, :type => @type, :activity_id => params[:id].to_i}) %>'); + $('#reply_div_<%= params[:div_id].to_i %>').html('<%= escape_javascript(render :partial => 'users/message_replies', + :locals => {:comments => @journals, + :user_activity_id => @user_activity_id, + :type => @type, + :activity_id => params[:id].to_i}) %>'); <% elsif params[:type] == 'BlogComment' %> -$('#reply_div_<%= params[:div_id].to_i %>').html('<%=escape_javascript(render :partial => 'users/message_replies', :locals => {:comments => @journals,:user_activity_id => @user_activity_id, :type => @type, :activity_id => params[:id].to_i}) %>'); + $('#reply_div_<%= params[:div_id].to_i %>').html('<%=escape_javascript(render :partial => 'users/message_replies', + :locals => {:comments => @journals, + :user_activity_id => @user_activity_id, + :type => @type, + :activity_id => params[:id].to_i}) %>'); <% elsif params[:type] == 'OrgDocumentComment' %> -$('#reply_div_<%= params[:div_id].to_i %>').html('<%=escape_javascript(render :partial => 'users/message_replies', :locals => {:comments => @journals, :user_activity_id => @user_activity_id, :type => @type, :activity_id => params[:id].to_i}) %>'); + $('#reply_div_<%= params[:div_id].to_i %>').html('<%= escape_javascript(render :partial => 'users/message_replies', + :locals => {:comments => @journals, + :user_activity_id => @user_activity_id, + :type => @type, + :activity_id => params[:id].to_i}) %>'); <% elsif params[:type] == 'News' || params[:type] == 'Issue' || params[:type] == 'Syllabus' %> -$('#reply_div_<%= params[:div_id].to_i %>').html('<%=escape_javascript(render :partial => 'users/news_replies', :locals => {:comments => @journals, :user_activity_id => @user_activity_id, :type => @type, :activity_id => params[:id].to_i}) %>'); + $('#reply_div_<%= params[:div_id].to_i %>').html('<%= escape_javascript(render :partial => 'users/news_replies', + :locals => {:comments => @journals, + :user_activity_id => @user_activity_id, + :type => @type, + :activity_id => params[:id].to_i}) %>'); <% elsif params[:type] == 'is_project_issue' %> -$('#reply_div_<%= params[:div_id].to_i %>').html('<%=escape_javascript(render :partial => 'projects/project_issue_expand_show', :locals => {:comments => @journals, :user_activity_id => @user_activity_id, :activity => @activity}) %>'); + $('#reply_div_<%= params[:div_id].to_i %>').html('<%= escape_javascript(render :partial => 'projects/project_issue_expand_show', + :locals => {:comments => @journals, + :user_activity_id => @user_activity_id, + :activity => @activity}) %>'); +<% elsif params[:type] == 'is_project_training_task' %> +$('#reply_div_<%= params[:div_id].to_i %>').html('<%= escape_javascript(render :partial => 'projects/project_issue_expand_show', + :locals => {:comments => @journals, + :user_activity_id => @user_activity_id, + :activity => @activity}) %>'); +sd_create_editor_from_data(<%= @user_activity_id %>, null, "100%", "UserActivity"); <% elsif params[:type] == 'is_project_message' %> -$('#reply_div_<%= params[:div_id].to_i %>').html('<%=escape_javascript(render :partial => 'projects/project_message_replies', :locals => {:comments => @journals,:user_activity_id => @user_activity_id, :type => @type, :activity_id => params[:id].to_i}) %>'); + $('#reply_div_<%= params[:div_id].to_i %>').html('<%= escape_javascript(render :partial => 'projects/project_message_replies', + :locals => {:comments => @journals, + :user_activity_id => @user_activity_id, + :type => @type, + :activity_id => params[:id].to_i}) %>'); <% end %> diff --git a/app/views/users/reply_detail.js.erb b/app/views/users/reply_detail.js.erb index 91828ef0f..e7e69507d 100644 --- a/app/views/users/reply_detail.js.erb +++ b/app/views/users/reply_detail.js.erb @@ -38,6 +38,8 @@ $("#activity_post_reply_<%= @user_activity_id%>").html("<%= escape_javascript(re <% else %> window.location.href = "<%=issue_path(@root) %>"; <% end %> +<% elsif @type == 'TrainingTask' %> + window.location.href = "<%= training_task_path(@root) %>"; <% elsif @type == 'OrgDocumentComment' %> <% if @user_activity_id.to_i != @root.id %> $("#activity_post_reply_<%= @user_activity_id %>").html("<%= escape_javascript(render :partial => 'organizations/org_document_post_reply', :locals => {:activity => @root, :user_activity_id => @user_activity_id}) %>"); diff --git a/app/views/users/reply_to_comment.js.erb b/app/views/users/reply_to_comment.js.erb index 22ae8e3fd..49a624e28 100644 --- a/app/views/users/reply_to_comment.js.erb +++ b/app/views/users/reply_to_comment.js.erb @@ -1,10 +1,10 @@ -if($("#comment_reply_<%=@parent_id %> #reply_message_<%= @reply.id%>").length > 0) { - $("#comment_reply_<%=@parent_id %> #reply_message_<%= @reply.id%>").replaceWith("<%= escape_javascript(render :partial => 'users/reply_to_comment', :locals => {:reply => @reply}) %>"); +if($("#comment_reply_<%=@parent_id %> #reply_message_<%= @reply.id %>").length > 0) { + $("#comment_reply_<%=@parent_id %> #reply_message_<%= @reply.id %>").replaceWith("<%= escape_javascript(render :partial => 'users/reply_to_comment', :locals => {:reply => @reply}) %>"); $("#comment_reply_<%=@parent_id %> #reply_iconup_<%=@reply.id %>").show(); $(function(){ - sd_create_editor_from_data(<%= @reply.id%>,null,"100%", "<%= @reply.class.to_s %>"); + sd_create_editor_from_data(<%= @reply.id %>,null,"100%", "<%= @reply.class.to_s %>"); }); -}else if($("#comment_reply_<%=@parent_id %> #reply_to_message_<%= @reply.id%>").length >0) { - $("#comment_reply_<%=@parent_id %> #reply_to_message_<%= @reply.id%>").replaceWith("

    "); - $("#comment_reply_<%=@parent_id %> #reply_iconup_<%=@reply.id %>").hide(); +}else if($("#comment_reply_<%= @parent_id %> #reply_to_message_<%= @reply.id %>").length >0) { + $("#comment_reply_<%= @parent_id %> #reply_to_message_<%= @reply.id %>").replaceWith("

    "); + $("#comment_reply_<%= @parent_id %> #reply_iconup_<%= @reply.id %>").hide(); } \ No newline at end of file diff --git a/app/views/users/user_manage_homeworks.html.erb b/app/views/users/user_manage_homeworks.html.erb index 850f4a85e..95712dcc6 100644 --- a/app/views/users/user_manage_homeworks.html.erb +++ b/app/views/users/user_manage_homeworks.html.erb @@ -3,7 +3,7 @@ window.location.href = url; } -
    +