Merge branch 'dev_raining' of https://git.trustie.net/jacknudt/trustieforge into dev_raining

This commit is contained in:
daiao 2017-02-20 15:19:44 +08:00
commit e4b582fbb7
11 changed files with 85 additions and 35 deletions

View File

@ -379,7 +379,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)
@ -843,7 +845,6 @@ class ProjectsController < ApplicationController
# 资源库fork弹框
def forked_pop
@task = params[:task]
respond_to do |format|
format.js
end

View File

@ -148,12 +148,12 @@ class RepositoriesController < ApplicationController
s = Trustie::Gitlab::Sync.new
s.sync_user(User.current)
ensure
logger.error "Synv user failed ==>#{User.current.id}"
logger.error "Syn user failed ==>#{User.current.id}"
end
end
gproject = g.fork(@project.gpid, User.current.gid)
if gproject
new_training_project = copy_project(@project, 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)
# 发布实训任务,只发布实训任务的第一个
@ -163,6 +163,43 @@ class RepositoriesController < ApplicationController
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
@ -221,19 +258,19 @@ class RepositoriesController < ApplicationController
project.members << m
project.project_infos << project_info
copy_repository(project, gproject)
# respond_to do |format|
# format.html {
# flash[:notice] = l(:notice_successful_create)
# if params[:continue]
# attrs = {:parent_id => project.parent_id}.reject {|k,v| v.nil?}
# redirect_to new_project_url(attrs, :course => '0')
# else
# redirect_to project_path(project)
# end
# }
# format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => project.id) }
# format.js
# end
respond_to do |format|
format.html {
flash[:notice] = l(:notice_successful_create)
if params[:continue]
attrs = {:parent_id => project.parent_id}.reject {|k,v| v.nil?}
redirect_to new_project_url(attrs, :course => '0')
else
redirect_to project_path(project)
end
}
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|

View File

@ -544,7 +544,7 @@ module ProjectsHelper
result = "manage_versions"
elsif user.allowed_to?(:manage_repository, @project)
result = "manage_repository"
elsif user.admin?
elsif is_project_manager?(user.id, @project.id)
result = "training_task"
end
result

View File

@ -160,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]
@ -194,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(
{
@ -220,6 +222,17 @@ class Project < ActiveRecord::Base
}
)
end
# 判断项目是否为实训项目
def is_training_project?
(self.enabled_modules.where("name = 'training_tasks'").empty? && self.training_status == 0) ? false : true
end
# 判断项目是否为开启实训的项目eg学生开启实训
def is_child_training_project?
self.training_status == 1 ? true :false
end
def new_course
self.where('project_type = ?', 1)
end

View File

@ -15,9 +15,12 @@
</div>
<!--加入、退出、关注项目-->
<div class="fr clear mr15">
<ul><span id="join_in_project_applied"><%= render :partial => "projects/applied_status" %></span></ul>
</div>
<% if !@project.is_child_training_project? %>
<div class="fr clear mr15">
<ul><span id="join_in_project_applied"><%= render :partial => "projects/applied_status" %></span></ul>
</div>
<% end %>
<div class="cl"></div>
<% unless @project.forked_from_project_id.nil? %>
<div class="fl pro_new_name ml15 clear mt5">
@ -40,8 +43,8 @@
<% end %>
<!--实训任务-->
<% unless @project.enabled_modules.where("name = 'training_tasks'").empty? %>
<li id="project_menu_11">
<%= link_to training_tasks_count > 0 ? "#{l(:project_module_training_tasks)}<span class='issues_nav_tag ml5'>#{switch_integer_into_k training_tasks_count}</span>".html_safe : "#{l(:project_module_training_tasks)}", project_training_tasks_url(@project, :remote => true), :class => "pro_new_proname", :title => "#{training_tasks_count}" %>
<li id="project_menu_011">
<%= link_to training_tasks_count > 0 ? "#{l(:project_module_training_tasks)}<span class='issues_nav_tag ml5'>#{switch_integer_into_k training_tasks_count}</span>".html_safe : "#{l(:project_module_training_tasks)}", project_training_tasks_url(@project), :class => "pro_new_proname", :title => "#{training_tasks_count}" %>
</li>
<% end %>
<!--讨论区-->
@ -87,7 +90,7 @@
</li>
<% end %>
<% if User.current.admin? || User.current.allowed_to?({:controller => 'projects', :action => 'settings'}, @project) %>
<% if (User.current.admin? || User.current.allowed_to?({:controller => 'projects', :action => 'settings'}, @project)) && !@project.is_child_training_project? %>
<li id="project_menu_010">
<%= link_to "#{l(:button_configure)}", settings_project_path(@project), :class => "pro_new_proname" %>
</li>

View File

@ -1,5 +1,5 @@
<h2 style="background: #fff; font-size: 14px; color: #333; height: 40px; line-height: 40px; padding-left: 15px; border-bottom:1px solid #e5e5e5;">项目简介
<% if User.current.member_of?(@project) %>
<% if User.current.member_of?(@project) && !@project.is_child_training_project? %>
<span class="fr mr15" id="project_invite_code">邀请码:<span style="color: #333;"><%= @project.invite_code %></span></span>
<% end %>
</h2>

View File

@ -55,7 +55,7 @@
</div><!--tbc_06 end-->
<div class="<%= show_memu == 'training_task' ? 'pro_st_dis' : 'pro_st_undis'%>" id="pro_st_tbc_07">
<%= render :partial=>"projects/settings/new_trainig_task" if User.current.admin? %>
<%= render :partial=>"projects/settings/new_trainig_task" if is_project_manager?(User.current.id, @project.id) %>
</div><!--tbc_06 end-->
</div>
</div>

View File

@ -7,11 +7,8 @@
<a href="javascript:void(0)" class="fr btn btn-grey">取消</a>
<a href="javascript:void(0)" class="fr btn btn-blue mr5">确定</a>
</div>
</div>
<h3>请输入脚本</h3>
<p><%= link_to "开启实训", training_project_execute_project_path(@project) %></p>
<textarea id="pull_request_comment" name="pull_request_comment" class="pullreques_reply_textarea" style="padding-left: 0px;"></textarea>
<textarea>
node()

View File

@ -1,6 +1,6 @@
<!--新版项目头部结束-->
<div class="ke-block pro_description_new_info mb10 " style="padding-bottom: 5px;word-break: normal;word-wrap: break-word" >
<div id="project_invite_code"><%= render :partial => 'projects/invite_code' %></div>
<div id="project_invite_code"><%= render :partial => 'projects/invite_code' %></div>
<div id="project_description_code" style="padding: 0 15px 10px 15px;font-size: 14px;">
<% if @project.description.blank? %>
<p style="padding-top:5px"><%= @project.name %></p>

View File

@ -7,7 +7,7 @@
<div class="sy_popup_con" style="width:380px;">
<ul class="sy_popup_add" >
<%# 实训项目和非实训项目,@type为true的时候为实训 %>
<% if @task %>
<% if @project.is_training_project? %>
<% if User.current.id == @project.user_id %>
<li class="center mb30" style="line-height:20px">
很抱歉,您不能在自己的实训项目中启动训练

View File

@ -204,12 +204,12 @@
<!--实训任务列表开始-->
<div class="myissues_con mb10">
<% if is_project_manager?(User.current, @project) || User.current.admin? %>
<% if !@project.is_child_training_project? || User.current.admin? %>
<a href="<%= new_project_training_task_path(@project) %>" class="btn btn-green fr mb10">新建</a>
<div class="cl"></div>
<% else %>
<div class="pro_new_prompt mb10">
<p>完成任务后提交代码,若通过系统测试,将为你发送下一个任务,祝你早日通关,加油!</p>
<p>完成任务后,请点击“提交评测”按钮,若通过系统测试,将为你发送下一个任务,祝你早日通关,加油!</p>
</div>
<% end %>
<% if @training_tasks.empty? %>
@ -245,7 +245,6 @@
</div>
</div>
<% end %>
</div>
<!--实训任务结束-->