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

This commit is contained in:
daiao 2017-03-30 16:35:59 +08:00
commit ec82d16bbc
7 changed files with 43 additions and 18 deletions

View File

@ -22,22 +22,17 @@ class GamesController < ApplicationController
# path"" && path: @game.path
def show
@game_challenge = @game.challenge
logger.info("*** ###############")
game_path = (@game_challenge.path.blank? ? @path : @game_challenge.path.strip)
@rev = @rev.nil? ? "master" : @rev
@git_url = git_repository_url(@myshixun, "Myshixun")
logger.info("*** git_url is###{@git_url}")
@type = params[:type]
logger.info("*** ###{@rev}#######{@path}")
# 默认打开文件
if @path == "" && !game_path.nil? && !@repository.cat(game_path, @rev).blank? && @type != "root"
@path = game_path
@file_open = true
@content = @repository.cat(@path, @rev)
logger.info("content result is ###############{@content}")
else
@entries = @repository.entries(@path, @rev)
logger.info("result is ###############{@entries.first.try(:path)}")
end
@latest_output = @game.latest_output.try(:out_put)
@ -204,7 +199,7 @@ class GamesController < ApplicationController
end
def allowd_manager
render_403 unless (User.current.manager_of_myshixun?(@myshixun) || User.current.admin?)
render_403 unless (User.current.manager_of_myshixun?(@myshixun) || User.current.admin? || User.current.id == @myshixun.shixun.try(:user_id))
end
# Find myshixun of id params[:id]

View File

@ -37,22 +37,22 @@ module ApplicationHelper
# 定义实训相关方法
# myshixun 最高分
def top_score shixun, position
Game.find_by_sql("SELECT max(final_score) as score FROM `games` where stage=#{position} and myshixun_id in (SELECT id FROM `myshixuns` where parent_id=#{shixun.id})").first
Game.find_by_sql("SELECT max(final_score) as top_score FROM `games` g, `challenges` c where g.challenge_id = c.id and c.position=#{position} and g.myshixun_id in (SELECT id FROM `myshixuns` ms where ms.shixun_id=#{shixun.id})").first.try(:top_score)
end
# 实训平均分
def shixun_avg_score shixun, position
Game.find_by_sql("SELECT avg(final_score) as avg_score FROM `games` where stage=#{position} and myshixun_id in (SELECT id FROM `myshixuns` where parent_id=#{shixun.id})")
Game.find_by_sql("SELECT avg(g.final_score) as avg_score FROM `games` g, `challenges` c where g.challenge_id=c.id and c.position=#{position} and g.myshixun_id in (SELECT id FROM `myshixuns` ms where ms.shixun_id=#{shixun.id})").first.try(:avg_score)
end
# 正在进行中任务
def shixun_running shixun, position
Myshixun.find_by_sql("SELECT * FROM `myshixuns` ms, `games` g where g.myshixun_id = ms.id and shixun_id =#{shixun.id} and g.stage=#{position} and (g.status=0 or g.status=1);").count
Shixun.find_by_sql("SELECT count(*) as count FROM `myshixuns` ms, `games` g, `challenges` c where g.myshixun_id = ms.id and ms.shixun_id =#{shixun.id} and g.challenge_id=c.id and c.position=#{position} and g.status in ('0','1');").first.try(:count)
end
# 已完成任务
def shixun_done shixun, position
Myshixun.find_by_sql("SELECT * FROM `myshixuns` ms, `games` g where g.myshixun_id = ms.id and shixun_id =#{shixun.id} and g.stage=#{position} and g.status=2;").count
Shixun.find_by_sql("SELECT count(*) as count FROM `myshixuns` ms, `games` g, `challenges` c where g.myshixun_id = ms.id and ms.shixun_id =#{shixun.id} and g.challenge_id=c.id and c.position=#{position} and g.status=2;").first.try(:count)
end
# 测评次数
@ -85,6 +85,25 @@ module ApplicationHelper
min = time % (24*60*60) % (60*60) / 60
end
# 耗时:天、小时、分
# 小于1分钟则不显示
def game_spend_time start_time, end_time
time = (end_time - start_time).to_i
day = time / 86400
hour = time % (24*60*60) / (60*60)
min = time % (24*60*60) % (60*60) / 60
if day < 1
if hour < 1
time = "#{min} 分钟"
else
time = "#{hour}小时 : #{min}"
end
else
time = "#{day}天 : #{hour}小时 : #{min}"
end
return time
end
# 已闯关
def had_pass myshixun
Game.find_by_sql("SELECT * FROM `games` where status =2 and myshixun_id in (SELECT id FROM `myshixuns` where parent_id=#{myshixun.parent_id});").count
@ -96,7 +115,7 @@ module ApplicationHelper
end
def shixun_final_score myshixun
Game.find_by_sql("SELECT sum(final_score) as score FROM `games` where myshixun_id='#{myshixun.id}';")
Game.find_by_sql("SELECT sum(final_score) as final_score FROM `games` where myshixun_id='#{myshixun.id}';").first.try(:final_score)
end
# def user_blogs_path(resource,parameters={})

View File

@ -4,6 +4,7 @@ class Myshixun < ActiveRecord::Base
has_many :myshixun_members
has_one :repository
has_many :games, :dependent => :destroy, :order => "games.id ASC"
belongs_to :shixun
# 当前任务:一个实训中只可能一个未完成任务(status 0或1只会存在一条记录)
# status:0 可以测评的,正在测评的

View File

@ -6,6 +6,7 @@ class Shixun < ActiveRecord::Base
has_many :shixun_members
has_one :repository
has_many :challenges, :dependent => :destroy, :order => "challenges.id ASC"
has_many :myshixuns
def owner
User.find(self.user_id)

View File

@ -21,14 +21,16 @@
<a href="<%= index_down_shixun_challenge_path(challenge, :shixun_id => @shixun) %>" title="下移" data-remote="true"><i class="fa fa-long-arrow-down color-grey font-16 mr5" ></i></a>
<% end %>
<a href="<%= edit_shixun_challenge_path(challenge, :shixun_id => @shixun) %>" title="编辑" ><i class="fa fa-pencil-square-o color-grey font-16 mr5" ></i></a>
<!-- <a href="#" title="删除" ><i class="fa fa-trash-o color-grey font-16 mr5" ></i></a>-->
<!-- <a href="#" title="删除" ><i class="fa fa-trash-o color-grey font-16 mr5" ></i></a>-->
<!--<a href="#" title="排名" ><i class="fa fa-signal color-grey font-16 mr5 " ></i></a>-->
</p>
<% end %>
<div class="cl"></div>
<p class="ml15 mt15 color-grey">
<!--<span class=" mr10">平均表现:<%#= shixun_avg_score(@shixun, challenge.position).avg_score.to_i %>分 </span>-->
<span class=" mr10">正在挑战:<%= shixun_running(@shixun, challenge.position) %></span>
<span class=" mr10">完成挑战:<%= shixun_done(@shixun, challenge.position) %></span>
<span class=" mr10">最佳表现:<%= top_score(@shixun, challenge.position) %>分</span>
<span class=" mr10">平均表现:<%= shixun_avg_score(@shixun, challenge.position).to_i %>分 </span>
</p>
</div>
<script>

View File

@ -13,8 +13,13 @@
link_path << '/' unless link_path.empty?
link_path << "#{dir}"
%>
<span class="c_grey">/</span> <%= link_to h(dir), {:action => 'show', :id => @game, :myshixun_id => @myshixun, :path => to_path_param(link_path), :rev => @rev},
:remote => true, :class => "f14 fb" %>
<% if dir.include?(".") %>
<span class="c_grey">/</span> <%= link_to h(dir), {:action => 'entry', :id => @game, :myshixun_id => @myshixun, :path => to_path_param(link_path), :rev => @rev},
:remote => true, :class => "f14 fb" %>
<% else %>
<span class="c_grey">/</span> <%= link_to h(dir), {:action => 'show', :id => @game, :myshixun_id => @myshixun, :path => to_path_param(link_path), :rev => @rev},
:remote => true, :class => "f14 fb" %>
<% end %>
<% end %>
<% end %>

View File

@ -3,8 +3,10 @@
<a href="javascript:void(0)" class="fr rightbar-pause" id="leave_shixun_page"><i class="fa fa-power-off font-20 mt5"></i><span class="ml10">暂时离开</span></a>
<ul class="rightbar-score fr" >
<!--<li><i class="fa fa-signal font-14 mr5"></i>排名:<a href="#" class="">123</a></li>-->
<li><i class="fa fa-trophy font-14 mr5"></i>积分:<a class=""><%= shixun_final_score(@myshixun).first.try(:score) %></a></li>
<!--<li><i class="fa fa-clock-o font-14 mr5"></i>耗时:<a class=""><%#= game_avg_hour(@game.created_at, @game.updated_at) %><%#= game_avg_min(@game.created_at, @game.updated_at) %></a></li>-->
<li><i class="fa fa-trophy font-14 mr5"></i>积分:<%= shixun_final_score(@myshixun) %></li>
<% if (Time.now - @game.created_at) > 60 %>
<li><i class="fa fa-clock-o font-14 mr5"></i>耗时:<%= @game.status == 2 ? game_spend_time(@game.created_at, Time.now) : game_spend_time(@game.created_at, @game.updated_at) %></li>
<% end %>
</ul>
</div>
<script>