games模块相关功能

This commit is contained in:
huang 2017-03-13 09:00:13 +08:00
parent 6183db782a
commit fbc52a7892
9 changed files with 70 additions and 20 deletions

View File

@ -2,6 +2,7 @@ class GamesController < ApplicationController
layout "base_myshixun"
before_filter :find_myshixun, :only => [:index, :game_build]
before_filter :find_game, :only => [:show, :game_build]
before_filter :find_repository, :only => [:show]
before_filter :allowd_manager, :only => [:game_build]
include ApplicationHelper
@ -9,8 +10,13 @@ class GamesController < ApplicationController
end
# mushixun的版本库必须创建时就创建
def show
@git_url = git_repository_url(@myshixun, "Myshixun")
@entries = @repository.entries(@path, @rev)
if request.xhr?
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
end
end
# REDO:回复状态更新
@ -33,6 +39,10 @@ class GamesController < ApplicationController
end
private
def find_repository
@repository = @myshixun.repository
end
def allowd_manager
render_403 unless User.current.manager_of_myshixun?(@myshixun)
end

View File

@ -12,7 +12,7 @@ class ShixunsController < ApplicationController
def shixun_monitor
monitor_filter
if @had_exec
@tpm = Shixun.where(:forked_form => @shixun.id, :user_id => User.current.id).first
@tpm = Myshixun.where(:user_id => User.current, :parent_id => @shixun).first
end
respond_to do |format|
@ -176,7 +176,7 @@ class ShixunsController < ApplicationController
def publish_games original_shixun_id, new_shixun_id, position
original_challenge = Challenge.where(:shixun_id => original_shixun_id, :position => position).first
challenge = Game.create(:subject => original_challenge.subject, :description => original_challenge.description,
:stage => position, :myshixun_id => new_shixun_id, :user_id => User.current.id)
:stage => position, :myshixun_id => new_shixun_id, :user_id => User.current.id)
end
# 复制项目

View File

@ -40,8 +40,8 @@ module ApplicationHelper
def git_repository_url project, type
if type == "Shixun"
rep_identify = Repository.where(:shixun_id => project.id, :type => "Repository::Gitlab").first.try(:identifier)
eleif type == "Myshixun"
rep_identify = Repository.where(:my_shixun_id => project.id, :type => "Repository::Gitlab").first.try(:identifier)
elsif type == "Myshixun"
rep_identify = Repository.where(:myshixun_id => project.id, :type => "Repository::Gitlab").first.try(:identifier)
else
rep_identify = Repository.where(:project_id => project.id, :type => "Repository::Gitlab").first.try(:identifier)
end
@ -141,17 +141,11 @@ module ApplicationHelper
# 判断当前用户是否已经实训过当前项目
# project: current_project
def has_exec_cur_shixun shixun
cur_user_shixuns = Shixun.where(:user_id => User.current.id)
if cur_user_shixuns.count == 0
false
else
has_forked = cur_user_shixuns.select{|cur_user_shixun| cur_user_shixun.forked_form == shixun.id}
has_forked.length > 0 ? true : false
end
Myshixun.where(:user_id => User.current.id, :parent_id => shixun.id).count > 0 ? true : false
end
def tpi_allow_show shixun
(shixun.tpm? && User.current.logged? && User.current.id != shixun.user_id)
(User.current.logged? && User.current.id != shixun.user_id)
end
# 通过系统外部邮箱查找用户,如果用户不存在则用邮箱替换

View File

@ -108,7 +108,7 @@ class Repository < ActiveRecord::Base
def scm
unless @scm
@scm = self.scm_adapter.new(url, root_url, login, password, path_encoding, project_id, shixun_id)
@scm = self.scm_adapter.new(url, root_url, login, password, path_encoding, project_id, shixun_id, myshixun_id)
if root_url.blank? && @scm.root_url.present?
update_attribute(:root_url, @scm.root_url)
end

View File

@ -12,6 +12,10 @@ class Shixun < ActiveRecord::Base
# raise ActiveRecord::RecordNotFound, "Couldn't find Shixun with parent_id=#{self.parent_id}" if shixun.nil?
end
def children
Myshixun.where(:parent_id => self.id)
end
def tpi?
(!self.parent_id.nil? && !self.forked_form.nil? && self.status == 2) ? true : false
end

View File

@ -0,0 +1,27 @@
<% @entries.each do |entry| %>
<% tr_id = Digest::MD5.hexdigest(entry.path)
depth = params[:depth].to_i %>
<% sub_path = entry.path[0] == "/" ? entry.path.sub("/", "") : entry.path %>
<% ent_path = Redmine::CodesetUtil.replace_invalid_utf8(sub_path) %>
<% ent_name = Redmine::CodesetUtil.replace_invalid_utf8(entry.name) %>
<%# latest_changes = get_trees_last_changes(@project.gpid, @rev, ent_path, @g) %>
<tr id="<%= tr_id %>" class="<%= h params[:parent_id] %> entry <%= entry.kind %>">
<td style="padding-left: <%=18 * depth%>px;" class="filename_no_report hidden">
<% if entry.is_dir? %>
<%# 展开文件目录 %>
<span class="expander" onclick="scmEntryClick('<%= tr_id %>', '<%= escape_javascript(url_for(
:action => 'show',
:id => @myshixun,
:repository_id => @repository.identifier_param,
:path => to_path_param(ent_path),
:rev => @rev,
:depth => (depth + 1),
:parent_id => tr_id)) %>');">&nbsp;</span>
<% end %>
<%= link_to h(ent_name),
{:action => (entry.is_dir? ? 'show' : 'entry'), :id => @myshixun, :repository_id => @repository.identifier_param, :path => to_path_param(ent_path), :rev => @rev},
:class => (entry.is_dir? ? 'old-icon old-icon-folder' : "old-icon old-icon-file #{Redmine::MimeType.css_class_of(ent_name)}")%>
</td>
</tr>
<% end %>

View File

@ -1,2 +1,10 @@
<%= link_to "提交评测", {:controller => 'games', :action => "game_build", :id => @game, :myshixun_id => @myshixun}, :class => "task-display-span bBlue mt10", :onclick => "training_task_submmit();", :remote => true %>
tpi
tpi
</br>
<%= @git_url %>
<% if @entries.blank? %>
<%= render :partial => "projects/no_data" %>
<% else %>
<%= render :partial => "repository" %>
<% end %>

View File

@ -80,7 +80,7 @@ module Redmine
end
def initialize(url, root_url=nil, login=nil, password=nil,
path_encoding=nil, project_id, shixun_id)
path_encoding=nil, project_id, shixun_id, myshixun_id)
@url = url
@login = login if login && !login.empty?
@password = (password || "") if @login

View File

@ -13,13 +13,18 @@ module Redmine
attr_accessor :is_default
end
def initialize(url, root_url=nil, login=nil, password=nil, path_encoding=nil, project_id, shixun_id)
def initialize(url, root_url=nil, login=nil, password=nil, path_encoding=nil, project_id, shixun_id, myshixun_id)
super
@g = Gitlab.client
# shixun project
if project_id == -1
r = Repository.where("url =? and shixun_id =?", url, shixun_id).first
@shixun = r.shixun.gpid
if shixun_id == -2
r = Repository.where("url =? and myshixun_id =?", url, myshixun_id).first
@myshixun = r.myshixun.gpid
else
r = Repository.where("url =? and shixun_id =?", url, shixun_id).first
@shixun = r.shixun.gpid
end
else
r = Repository.where("url =? and project_id =?", url, project_id).first
@project = r.project.gpid
@ -97,8 +102,10 @@ module Redmine
entries = Entries.new
if @project
trees = @g.trees(@project, path: path, ref_name: identifier)
else
elsif @shixun
trees = @g.trees(@shixun, path: path, ref_name: identifier)
else
trees = @g.trees(@myshixun, path: path, ref_name: identifier)
end
trees.each do |tree|
entries << Entry.new({