Merge branch 'dev_cxt' into dev_aliyun

chromesetting
cxt 5 years ago
commit 92c79c59b0

@ -8,6 +8,9 @@ class Admins::ShixunsController < Admins::BaseController
@pending_shixuns = shixuns.where(status:1).size
@processed_shixuns = shixuns.where(status:2).size
@closed_shixuns = shixuns.where(status:3).size
@none_public_shixuns = shixuns.where(public:0).size
@pending_public_shixuns = shixuns.where(public:1).size
@processed_pubic_shixuns = shixuns.where(public:2).size
@shixuns_type_check = MirrorRepository.pluck(:type_name,:id)
@params_page = params[:page] || 1
@shixuns = paginate shixuns.preload(:user,:challenges)

@ -29,7 +29,7 @@ class CoursesController < ApplicationController
:informs, :update_informs, :online_learning, :update_task_position, :tasks_list,
:join_excellent_course, :export_couser_info, :export_member_act_score, :new_informs,
:delete_informs, :change_member_role, :course_groups, :join_course_group, :statistics,
:work_score, :act_score]
:work_score, :act_score, :calculate_all_shixun_scores]
before_action :user_course_identity, except: [:join_excellent_course, :index, :create, :new, :apply_to_join_course,
:search_course_list, :get_historical_course_students, :mine, :search_slim, :board_list]
before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate,
@ -48,7 +48,7 @@ class CoursesController < ApplicationController
before_action :validate_page_size, only: :mine
before_action :course_tasks, only: [:tasks_list, :update_task_position]
before_action :validate_inform_params, only: [:update_informs, :new_informs]
before_action :course_member_allowed, only: [:statistics, :work_score, :act_score]
before_action :course_member_allowed, only: [:statistics, :work_score, :act_score, :calculate_all_shixun_scores]
if RUBY_PLATFORM =~ /linux/
require 'simple_xlsx_reader'
@ -1334,6 +1334,16 @@ class CoursesController < ApplicationController
end
end
# 计算课堂所有已发布的实训作业成绩
def calculate_all_shixun_scores
tip_exception(-1, "课堂已结束") if @course.is_end
shixun_homeworks = @course.homework_commons.homework_published.where(homework_type: 4)
shixun_homeworks.includes(:homework_challenge_settings, :published_settings, :homework_commons_shixun).each do |homework|
homework.update_homework_work_score
end
normal_status(0, "更新成功")
end
def search_slim
courses = current_user.manage_courses.not_deleted.processing

@ -19,14 +19,14 @@ class ShixunsController < ApplicationController
before_action :allowed, only: [:update, :close, :update_propaedeutics, :settings, :publish,
:shixun_members_added, :change_manager, :collaborators_delete,
:cancel_publish, :add_collaborators, :add_file]
:cancel_apply_public, :cancel_publish, :add_collaborators, :add_file]
before_action :portion_allowed, only: [:copy]
before_action :special_allowed, only: [:send_to_course, :search_user_courses]
## 获取课程列表
def index
@shixuns = current_laboratory.shixuns.unhidden
@shixuns = current_laboratory.shixuns.unhidden.publiced
## 方向
if params[:tag_level].present? && params[:tag_id].present?
@ -818,6 +818,7 @@ class ShixunsController < ApplicationController
@status = 0
@position = []
begin
unless @shixun.is_jupyter?
if @shixun.challenges.count == 0
@status = 4
else
@ -836,8 +837,10 @@ class ShixunsController < ApplicationController
end
end
end
end
if @status == 0
@shixun.update_attributes!(:status => 1)
ActiveRecord::Base.transaction do
@shixun.update_attributes!(:status => 2)
apply = ApplyAction.where(:container_type => "ApplyShixun", :container_id => @shixun.id).order("created_at desc").first
if apply && apply.status == 0
@status = 0
@ -851,6 +854,7 @@ class ShixunsController < ApplicationController
@status = 1
end
end
end
rescue Exception => e
logger.error("pushlish game #{e}")
end
@ -993,14 +997,24 @@ class ShixunsController < ApplicationController
:disposition => 'attachment' #inline can open in browser
end
# 撤销发布
def cancel_publish
tip_exception("实训已经发布,无法撤销") if @shixun.status == 2
# 撤销申请公开
def cancel_apply_public
tip_exception("实训已经公开,无法撤销") if @shixun.public == 2
ActiveRecord::Base.transaction do
apply = ApplyAction.where(:container_type => "ApplyShixun", :container_id => @shixun.id).order("created_at desc").first
if apply && apply.status == 0
apply.update_attribute(:status, 3)
apply.tidings.destroy_all
apply.update_attributes!(status: 3)
apply.tidings&.destroy_all
end
@shixun.update_column(:public, 0)
end
normal_status(0, "成功撤销申请")
end
# 撤销发布
def cancel_publish
tip_exception("请先撤销申请公开,再撤销发布") if @shixun.public == 1
tip_exception("实训已经公开,无法撤销") if @shixun.public == 2
@shixun.update_column(:status, 0)
end

@ -27,6 +27,17 @@ module ShixunsHelper
end
end
def shixun_public_status shixun
case shixun.try(:public)
when 0,nil
"未公开"
when 1
"待审核"
when 2
"已公开"
end
end
# 已完成实训所获得的经验值
def myshixun_exp myshixun
score = 0

@ -119,6 +119,12 @@ class Game < ApplicationRecord
# self.outputs.pluck(:query_index).first
#end
# 是否查看了答案(通关的是否在通关前看的答案)
def view_answer
answer_exists = Grade.exists?("container_type = 'Answer' and container_id = #{id} and created_at < '#{end_time}'")
answer_open != 0 ? (status == 2 ? answer_exists : true) : false
end
# 用户关卡得分
def get_user_final_score

@ -83,9 +83,10 @@ class Myshixun < ApplicationRecord
self.games.select{|game| game.status == 2}.size
end
# 查看答案的关卡数
# 查看答案的关卡数,只统计通关前看的关卡
def view_answer_count
self.games.select{|game| game.status == 2 && game.answer_open != 0}.size
answer_ids = user.grades.joins("join games on grades.container_id = games.id").where("container_type = 'Answer' and games.status=2 and games.end_time > grades.created_at").pluck(:container_id)
self.games.select{|game| game.status == 2 && game.answer_open != 0 && answer_ids.include?(game.id)}.size
end
# 通关时间

@ -3,6 +3,7 @@ class Shixun < ApplicationRecord
attr_accessor :page_no #管理员页面 实训配置更新状态时需要接受page_no参数
# status: 0编辑 1申请发布 2正式发布 3关闭 -1软删除
# public: 0未公开 1申请公开 2公开
# hide_code 隐藏代码窗口
# code_hidden: 隐藏代码目录
# task_pass: 跳关
@ -76,6 +77,7 @@ class Shixun < ApplicationRecord
scope :published_closed, lambda{ where(status: [2, 3]) }
scope :none_closed, lambda{ where(status: [0, 1, 2]) }
scope :unhidden, lambda{ where(hidden: 0, status: 2) }
scope :publiced, lambda{ where(public: 2) }
scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) }
scope :find_by_ids,lambda{|k| where(id:k)}

@ -21,7 +21,17 @@ class Admins::ShixunQuery < ApplicationQuery
[0,1,2,3]
end
public =
case params[:public]
when "editing" then [0]
when "pending" then [1]
when "processed" then [2]
else
[0,1,2]
end
all_shixuns = all_shixuns.where(status: status) if status.present?
all_shixuns = all_shixuns.where(public: public) if public.present?
if params[:tag].present?
all_shixuns = all_shixuns.joins(:mirror_repositories).where("mirror_repositories.id = ?",params[:tag].to_i)

@ -10,7 +10,7 @@ class Admins::ShixunAuths::AgreeApplyService < ApplicationService
def call
ActiveRecord::Base.transaction do
apply.update!(status: 1, dealer_id: user.id)
shixun.update!(status: 2, publish_time: Time.now)
shixun.update!(public: 2, publish_time: Time.now)
# 奖励金币、经验
reward_grade_and_experience!

@ -10,7 +10,7 @@ class Admins::ShixunAuths::RefuseApplyService < ApplicationService
def call
ActiveRecord::Base.transaction do
shixun.update!(status: 0)
shixun.update!(public: 0)
apply.update!(status: 2, reason: reason, dealer_id: user.id)
deal_tiding!

@ -30,7 +30,6 @@ class SearchService < ApplicationService
model_options = {
includes: modal_name.searchable_includes
}
model_options.deep_merge!(where: { status: 2 }) if modal_name == Shixun
model_options.deep_merge!(extra_options)
model_options.deep_merge!(default_options)
@ -40,7 +39,7 @@ class SearchService < ApplicationService
def extra_options
case params[:type].to_s.strip
when 'shixun' then
{ where: { id: Laboratory.current.shixuns.pluck(:id) } }
{ where: { id: Laboratory.current.shixuns.where(public: 2, status: 2, fork_from: nil).or(Laboratory.current.shixuns.where(status: 2, id: User.current.shixuns)).pluck(:id) } }
when 'subject' then
{ where: { id: Laboratory.current.subjects.pluck(:id) } }
when 'course' then

@ -25,7 +25,7 @@ class ShixunSearchService < ApplicationService
else
none_shixun_ids = ShixunSchool.where("school_id != #{User.current.school_id}").pluck(:shixun_id)
@shixuns = @shixuns.where.not(id: none_shixun_ids).where(hidden: 0)
@shixuns = @shixuns.where.not(id: none_shixun_ids).where(hidden: 0, status: 2, public: 2).or(@shixuns.where(id: current_user.shixuns))
end
end

@ -4,25 +4,31 @@
<div class="box search-form-container shixuns-list-form">
<%= form_tag(admins_shixuns_path, method: :get, class: 'form-inline search-form',id:"shixuns-search-form",remote:true) do %>
<div class="form-group mr-2">
<div class="form-group">
<label for="status">状态:</label>
<% status_options = [['全部', ''], ["编辑中(#{@editing_shixuns})", "editing"], ["待审核(#{@pending_shixuns})", 'pending'], ["已发布(#{@processed_shixuns})", 'processed'],["已关闭(#{@closed_shixuns})",'closed']] %>
<%= select_tag(:status, options_for_select(status_options), class: 'form-control') %>
</div>
<div class="form-group">
<label for="status">公开:</label>
<% public_options = [['全部', ''], ["未公开(#{@none_public_shixuns})", "editing"], ["待审核(#{@pending_public_shixuns})", 'pending'], ["已公开(#{@processed_pubic_shixuns})", 'processed']] %>
<%= select_tag(:public, options_for_select(public_options), class: 'form-control') %>
</div>
<div class="form-group mr-2">
<label for="tag-choosed">技术平台:</label>
<%= select_tag(:tag, options_for_select(@shixuns_type_check.unshift(["",nil])), class: 'form-control',id:"tag-choosed") %>
</div>
<div class="form-group ml-3">
<div class="form-group">
<label>搜索类型:</label>
<% auto_trial_options = [['创建者姓名', 0], ['实训名称', 1], ['学校名称', 2]] %>
<%= select_tag(:search_type, options_for_select(auto_trial_options), class: 'form-control') %>
</div>
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: '输入关键字搜索') %>
<%= submit_tag('搜索', class: 'btn btn-primary ml-3','data-disable-with': '搜索中...') %>
<%= link_to "清除",admins_shixuns_path,class: "btn btn-default",id:"shixuns-clear-search",'data-disable-with': '清除中...' %>
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2', placeholder: '输入关键字搜索') %>
<%= submit_tag('搜索', class: 'btn btn-primary','data-disable-with': '搜索中...') %>
<%= link_to "清除", admins_shixuns_path,class: "btn btn-default",id:"shixuns-clear-search",'data-disable-with': '清除中...' %>
<% end %>
<a href="javascript:void(0)" class="btn btn-primary" id="shixuns-export" data-disable-with = '导出中...'>导出</a>
</div>

@ -2,14 +2,15 @@
<thead class="thead-light">
<th width="4%">序号</th>
<th width="8%">ID</th>
<th width="28%" class="text-left">实训名称</th>
<th width="24%" class="text-left">实训名称</th>
<th width="8%">技术平台</th>
<th width="5%">Fork源</th>
<th width="5%">实践</th>
<th width="5%">选择</th>
<th width="6%">状态</th>
<th width="6%">公开</th>
<th width="7%">创建者</th>
<th width="13%"><%= sort_tag('创建于', name: 'created_at', path: admins_shixuns_path) %></th>
<th width="11%"><%= sort_tag('创建于', name: 'created_at', path: admins_shixuns_path) %></th>
<th width="5%">单测</th>
<th width="6%">操作</th>
</thead>
@ -33,6 +34,7 @@
<td><%= shixun.challenges.where(:st => 0).size %></td>
<td><%= shixun.challenges.where(:st => 1).size %></td>
<td class="shixuns-status-<%= shixun.status %>"><%= shixun_authentication_status shixun %></td>
<td class="shixuns-status-<%= shixun.public %>"><%= shixun_public_status shixun %></td>
<td><%= link_to shixun.user.try(:real_name),"/users/#{shixun.user.try(:login)}",target:'_blank' %></td>
<td><%= format_time shixun.created_at %></td>
<td class="homepage_teacher">

@ -16,3 +16,5 @@ json.diffcult diff_to_s(shixun.trainee)
json.score_info shixun.shixun_preference_info # todo: 这块可以改成只显示实训的平均分,不用每次都去取每种星的分数了。
# 用于是否显示导航栏中的'背景知识'
json.propaedeutics shixun.propaedeutics.present?
json.public shixun.public

@ -42,7 +42,7 @@ if @shixun
json.challenge_comment challenge_comment&.comment
json.challenge_comment_hidden @user_course_identity < Course::STUDENT ? challenge_comment&.hidden_comment : nil
json.comment_id challenge_comment&.id
json.view_answer game ? game.answer_open != 0 : 0
json.view_answer game ? game.view_answer : false
end
end

@ -257,6 +257,7 @@ Rails.application.routes.draw do
post :send_to_course
delete :collaborators_delete
get :cancel_publish
get :cancel_apply_public
get :publish
get :shixun_exec
post :review_shixun
@ -420,6 +421,7 @@ Rails.application.routes.draw do
get 'statistics'
post :inform_up
post :inform_down
get :calculate_all_shixun_scores
end
collection do

@ -0,0 +1,5 @@
class AddPublicStatusToShixun < ActiveRecord::Migration[5.2]
def change
add_column :shixuns, :public, :integer, default: 0
end
end

@ -0,0 +1,9 @@
class MigrateShixunStatus < ActiveRecord::Migration[5.2]
def change
# 平台上所有已发布且未隐藏的实训都设为公开
Shixun.unhidden.update_all(public: 2)
# 所有已申请发布的实训状态都改为已发布,申请发布改为申请公开
Shixun.where(status: 1, id: ApplyAction.where(container_type: 'ApplyShixun', status: 0).pluck(:container_id)).update_all(status: 2, public: 1)
end
end
Loading…
Cancel
Save