From f6e6818e5b822fc5a37e666652e1c10b4e3c4427 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 14 Feb 2020 20:27:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=94=AF=E6=8C=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 14 +++++------ .../weapps/challenges_controller.rb | 23 +++++++++++++++++++ app/models/mirror_repository.rb | 1 + app/models/shixun.rb | 3 ++- config/routes.rb | 3 +++ 5 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 app/controllers/weapps/challenges_controller.rb diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index d3744fb6e..c40010be2 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -25,7 +25,7 @@ class ShixunsController < ApplicationController before_action :special_allowed, only: [:send_to_course, :search_user_courses] before_action :shixun_marker, only: [:new, :create] - before_action :validate_wachat_support, only: [:shixun_exec] + #before_action :validate_wachat_support, only: [:shixun_exec] skip_before_action :check_sign, only: [:download_file] ## 获取课程列表 @@ -1186,11 +1186,11 @@ private md5.hexdigest end - def validate_wachat_support - - if (params[:wechat].present? && !@shixun.is_wechat_support?) - tip_exception(-5, "..") - end - end + # def validate_wachat_support + # + # if (params[:wechat].present? && !@shixun.is_wechat_support?) + # tip_exception(-5, "..") + # end + # end end diff --git a/app/controllers/weapps/challenges_controller.rb b/app/controllers/weapps/challenges_controller.rb new file mode 100644 index 000000000..49d065f03 --- /dev/null +++ b/app/controllers/weapps/challenges_controller.rb @@ -0,0 +1,23 @@ +class Weapps::ChallengesController < Weapps::BaseController + before_action :require_login + before_action :set_challenge + + def is_play + # 关卡有展示效果 || 选择题 || jupyter实训 || 隐藏代码窗口 || html+css实训 + play = @challenge.show_type != -1 || @challenge.st == 1 || @shixun.is_jupyter? || + @shixun.hide_code? || (@shixun.small_mirror_name & ["Css", "Html", "Web"]).present? + if play + normal_status(-5, "该关卡暂不支持小程序") + else + render_ok + end + end + + + private + def set_challenge + @challenge = Challenge.find_by!(id: params[:id]) + @shixun = @challenge.shixun + end + +end diff --git a/app/models/mirror_repository.rb b/app/models/mirror_repository.rb index 96a92e5e7..315813e51 100644 --- a/app/models/mirror_repository.rb +++ b/app/models/mirror_repository.rb @@ -8,6 +8,7 @@ class MirrorRepository < ApplicationRecord scope :published_mirror, -> { where(status: [1,2,3,5]) } scope :published_main_mirror, -> { published_mirror.where(main_type: 1) } scope :published_small_mirror, -> { published_mirror.where(main_type: 0) } + scope :small_mirror, -> { where(main_type: 0) } def deletable? status != 1 && !shixun_mirror_repositories.exists? diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 30c27ba94..c3c5cec78 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -171,7 +171,8 @@ class Shixun < ApplicationRecord # 实训对应的镜像小类别名(已选) def small_mirror_name - mirror_repositories.published_small_mirror.map(&:type_name) + names = mirror_repositories.small_mirror.map(&:type_name) + names.blank? ? [] : names end def small_mirror_id diff --git a/config/routes.rb b/config/routes.rb index 971c1859f..d01403bc3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1027,6 +1027,9 @@ Rails.application.routes.draw do resources :shixun_lists, only: [:index] resources :subjects, path: :paths, only: [:index, :create, :update, :edit, :show] + resources :challenges do + get :is_play, on: :member + end resources :courses, only: [:create, :update, :edit, :show] do member do