tpm权限控制

及index一些统计
This commit is contained in:
huang 2017-03-23 17:41:32 +08:00
parent 1eb0cf06e5
commit 62ab862516
5 changed files with 19 additions and 13 deletions

View File

@ -5,8 +5,9 @@ class ChallengesController < ApplicationController
before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy] before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy]
before_filter :authorize_tpi, :only => [:new, :create] before_filter :authorize_tpi, :only => [:new, :create]
before_filter :build_challege_from_params, :only => [:new, :create] before_filter :build_challege_from_params, :only => [:new, :create]
before_filter :tpi_manager_allowed, :only => [:challenge_build] before_filter :tpi_manager_allowed, :only => [:challenge_build, :destroy, :show, :edit, :new]
before_filter :query_challeges, :only => [:show, :edit, :update] before_filter :query_challeges, :only => [:show, :edit, :update]
# before_filter :is_members, :only => [:show, :edit]
include ApplicationHelper include ApplicationHelper
@ -197,6 +198,10 @@ class ChallengesController < ApplicationController
end end
private private
def is_members
render_403 unless User.current.manager_of_shixun?(@shixun)
end
def count_input input, output def count_input input, output
if input.length == 0 && output.length == 0 if input.length == 0 && output.length == 0
result = 0 result = 0
@ -208,7 +213,7 @@ class ChallengesController < ApplicationController
end end
def tpi_manager_allowed def tpi_manager_allowed
unless (@shixun.tpi? && User.current.manager_of_shixun?(@shixun)) unless (User.current.manager_of_shixun?(@shixun))
render_403 render_403
end end
end end

View File

@ -37,8 +37,12 @@ module ApplicationHelper
# 定义实训相关方法 # 定义实训相关方法
# myshixun 最高分 # myshixun 最高分
def top_score shixun, position def top_score shixun, position
Game.find_by_sql("SELECT max(final_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 score FROM `games` where stage=#{position} and myshixun_id in (SELECT id FROM `myshixuns` where parent_id=#{shixun.id})").first
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})")
end end
# 正在进行中任务 # 正在进行中任务
@ -52,14 +56,11 @@ module ApplicationHelper
end end
# 测评次数 # 测评次数
def shixun_exec_total_count shixun def shixun_exec_total_count shixun, position
Game.find_by_sql("SELECT * FROM `outputs` op, `games` g, `myshixuns` m where op.game_id = g.id and m.parent_id = '#{shixun.id}';") Game.find_by_sql("SELECT * FROM `outputs` op, `games` g, `myshixuns` m where op.game_id = g.id and g.stage='#{position}' and m.parent_id = '#{shixun.id}';")
end end
# 实训平均分
def shixun_avg
end
# 平均耗时 # 平均耗时
def shixun_avg def shixun_avg

View File

@ -24,9 +24,9 @@
<p class="ml15 mt15 color-grey"> <p class="ml15 mt15 color-grey">
<span class=" mr10">正在挑战:<%= shixun_running @shixun %></span> <span class=" mr10">正在挑战:<%= shixun_running @shixun %></span>
<span class=" mr10">完成挑战:<%= shixun_done @shixun %></span> <span class=" mr10">完成挑战:<%= shixun_done @shixun %></span>
<span class=" mr10">最佳表现:98分</span> <span class=" mr10">最佳表现:<%= top_score(@shixun, challenge.position).score.to_i %>分</span>
<span class=" mr10">测评次数:3次</span> <span class=" mr10">测评次数:<%= shixun_exec_total_count(@shixun, challenge.position).count %>次</span>
<span class=" mr10">平均表现80分 </span> <!--<span class=" mr10">平均表现:<%#= shixun_avg_score(@shixun, challenge.position).avg_score.to_i %>分 </span>-->
</p> </p>
</div> </div>
<script> <script>

View File

@ -84,7 +84,7 @@ module Trustie
snippets_enabled: false, snippets_enabled: false,
public: false, public: false,
user_id: gid, user_id: gid,
visibility_level: UserLevel::PUBLIC visibility_level: UserLevel::PUBLIC
) )
shixun.gpid = gshixun.id shixun.gpid = gshixun.id
shixun.save! shixun.save!

View File

@ -127,7 +127,7 @@ a.rightbar-pause{ color:#29bd8b; font-size: 18px; margin-right:245px; margin-top
.content-submit{width:10%; min-width:135px;} .content-submit{width:10%; min-width:135px;}
.content-submitbox{ height: 80px; width:120px; margin: 15px auto;} .content-submitbox{ height: 80px; width:120px; margin: 15px auto;}
.panel-inner{ background:#EFF2F7; margin:15px; padding:15px;} .panel-inner{ background:#EFF2F7; margin:15px; padding:15px;}
.panel-inner-title{ font-size: 14px; color: #666;} .panel-inner-title{ font-size: 14px; color: #666; max-width: 85%; line-height: 30px; word-wrap: break-word;}
/* 弹框 */ /* 弹框 */
.task-popup{ width: 30%;background: #fff; border:1px solid #e8e8e8; border-radius:3px; -webkit-box-shadow:0 0 10px #ccc; -moz-box-shadow:0 0 10px #ccc; box-shadow:0 0 10px #ccc; margin: 50px auto;} .task-popup{ width: 30%;background: #fff; border:1px solid #e8e8e8; border-radius:3px; -webkit-box-shadow:0 0 10px #ccc; -moz-box-shadow:0 0 10px #ccc; box-shadow:0 0 10px #ccc; margin: 50px auto;}
.task-popup-text-center{ text-align: center; color: #666;} .task-popup-text-center{ text-align: center; color: #666;}