diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 1cee38816..12f56146f 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -11,7 +11,8 @@ class CoursesController < ApplicationController render_error(ex.model.errors.full_messages.join(',')) end - before_action :require_login, :check_auth, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, :left_banner, :top_banner] + before_action :require_login, :check_auth, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, + :left_banner, :top_banner, :apply_to_join_course] before_action :set_course, :user_course_identity, only: [:show, :update, :destroy, :settings, :set_invite_code_halt, :set_public_or_private, :search_teacher_candidate, :teachers, :apply_teachers, :top_banner, :left_banner, :add_teacher_popup, :add_teacher, diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index afaa3a1b6..b372eb2c0 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -7,6 +7,7 @@ class SubjectsController < ApplicationController :up_member_position, :down_member_position] include ApplicationHelper + include SubjectsHelper def index @tech_system = Repertoire.where(nil).order("updated_at desc") @@ -81,11 +82,13 @@ class SubjectsController < ApplicationController @is_creator = current_user.creator_of_subject?(@subject) # 合作团队 @members = @subject.subject_members.includes(:user) - challenge_ids = Challenge.where(shixun_id: @subject.shixuns.published.pluck(:id)).pluck(:id) + shixun_ids = @subject.shixuns.published.pluck(:id) + challenge_ids = Challenge.where(shixun_id: shixun_ids).pluck(:id) # 实训路径中的所有实训标签 @tags = ChallengeTag.where(challenge_id: challenge_ids).pluck(:name).uniq # 用户获取的实训标签 - @user_tags = @subject.shixuns.map(&:user_tags_name).flatten.uniq + # @user_tags = @subject.shixuns.map(&:user_tags_name).flatten.uniq + @user_tags = user_shixun_tags challenge_ids, @user.id # 访问数变更 @subject.increment!(:visits) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index e9fe4ed94..23f6870c8 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3,6 +3,12 @@ class UsersController < ApplicationController before_action :load_user, only: [:show, :homepage_info] before_action :check_user_exist, only: [:show, :homepage_info] + # 检查是否更新 + def system_update + @notice = SystemUpdateNotice.last + end + + def show;end def update diff --git a/app/helpers/subjects_helper.rb b/app/helpers/subjects_helper.rb index 21fb3bb0d..f0ecd1174 100644 --- a/app/helpers/subjects_helper.rb +++ b/app/helpers/subjects_helper.rb @@ -10,4 +10,9 @@ module SubjectsHelper end status end + + # 实训路径的所有用户获得的标签 + def user_shixun_tags challenge_ids, user_id + ChallengeTag.joins(challenge: [:games]).where(games: {status: 2, user_id: user_id}, challenges: {id:challenge_ids}).pluck("challenge_tags.name").uniq + end end diff --git a/app/models/challenge_choose.rb b/app/models/challenge_choose.rb index 07b0813bb..2463d3317 100644 --- a/app/models/challenge_choose.rb +++ b/app/models/challenge_choose.rb @@ -1,5 +1,5 @@ class ChallengeChoose < ApplicationRecord - default_scope {order("position asc")} + default_scope {order("challenge_chooses.position asc")} belongs_to :challenge, optional: true has_many :challenge_tags, :dependent => :destroy has_many :challenge_questions, dependent: :destroy diff --git a/app/models/shixun.rb b/app/models/shixun.rb index d274f0a6d..e35f9f1a6 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -56,6 +56,7 @@ class Shixun < ApplicationRecord scope :visible, -> { where.not(status: -1) } scope :published, lambda{ where(status: 2) } + scope :published_closed, lambda{ where(status: [2, 3]) } scope :unhidden, lambda{ where(hidden: 0, status: 2) } scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) } scope :find_by_ids,lambda{|k| where(id:k)} diff --git a/app/models/subject.rb b/app/models/subject.rb index 064efb7a6..d68360fd0 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -53,11 +53,13 @@ class Subject < ApplicationRecord end def my_subject_score - shixuns_id = self.stage_shixuns.map(&:shixun_id) - shixuns_id = Shixun.where(:id => shixuns_id, :status =>[2, 3]).map(&:id) - shixuns_id = shixuns_id.present? ? shixuns_id.join(",") : -1 - my_shixun_score = Challenge.find_by_sql("select sum(c.score) as score FROM challenges c join games g on g.challenge_id = c.id where g.status = 2 and g.user_id = #{User.current.id} and c.shixun_id in(#{shixuns_id})").first.try(:score) - my_choose_score = ChallengeChoose.find_by_sql("SELECT sum(g.final_score) score FROM (`challenge_chooses` cc join challenges c on cc.challenge_id = c.id) join games g on g.challenge_id = c.id where g.status = 2 and g.user_id = #{User.current.id} and c.shixun_id in(#{shixuns_id})").first.try(:score) + # shixuns_id = @subject.shixuns.published_closed.pluck(:id) + # shixuns_id = shixuns_id.present? ? shixuns_id.join(",") : -1 + shixuns_id = shixuns.published_closed.pluck(:id) + my_shixun_score = Challenge.joins(:games).where(games: {status: 2, user_id: User.current.id}, shixun_id: shixuns_id).pluck(:score).sum + # my_shixun_score = Challenge.find_by_sql("select sum(c.score) as score FROM challenges c join games g on g.challenge_id = c.id where g.status = 2 and g.user_id = #{User.current.id} and c.shixun_id in(#{shixuns_id})").first.try(:score) + my_choose_score = ChallengeChoose.joins(challenge: :games).where(games: {status: 2, user_id: User.current.id}, challenges: {shixun_id: shixuns_id}).pluck(:score).sum + # my_choose_score = ChallengeChoose.find_by_sql("SELECT sum(g.final_score) score FROM (`challenge_chooses` cc join challenges c on cc.challenge_id = c.id) join games g on g.challenge_id = c.id where g.status = 2 and g.user_id = #{User.current.id} and c.shixun_id in(#{shixuns_id})").first.try(:score) return my_shixun_score.to_i + my_choose_score.to_i end diff --git a/app/models/system_update_notice.rb b/app/models/system_update_notice.rb new file mode 100644 index 000000000..44589a405 --- /dev/null +++ b/app/models/system_update_notice.rb @@ -0,0 +1,2 @@ +class SystemUpdateNotice < ApplicationRecord +end diff --git a/app/views/users/system_update.json.jbuilder b/app/views/users/system_update.json.jbuilder new file mode 100644 index 000000000..2cf2a4527 --- /dev/null +++ b/app/views/users/system_update.json.jbuilder @@ -0,0 +1,7 @@ +if @notice && @notice.end_time > Time.now + json.system_update true + json.system_score @notice.notes.rstrip + json.(@notice, :subject, :start_time, :end_time) +else + json.system_update false +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 210071b97..9da4d4a7e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -64,6 +64,7 @@ Rails.application.routes.draw do get :search_user_projects post :brief_introduction post :attendance + get :system_update resource :trial_apply, only: [:create] resources :projects, only: [] do diff --git a/db/migrate/20190720025309_add_ts_mem_for_outputs.rb b/db/migrate/20190720025309_add_ts_mem_for_outputs.rb index 1cf3f3e6f..fac886fda 100644 --- a/db/migrate/20190720025309_add_ts_mem_for_outputs.rb +++ b/db/migrate/20190720025309_add_ts_mem_for_outputs.rb @@ -1,5 +1,5 @@ class AddTsMemForOutputs < ActiveRecord::Migration[5.2] def change - add_column :outputs, :ts_mem, :float + #add_column :outputs, :ts_mem, :float end end diff --git a/db/migrate/20190720025341_add_ts_time_for_outputs.rb b/db/migrate/20190720025341_add_ts_time_for_outputs.rb index a5366fbd0..9c5f8a23f 100644 --- a/db/migrate/20190720025341_add_ts_time_for_outputs.rb +++ b/db/migrate/20190720025341_add_ts_time_for_outputs.rb @@ -1,5 +1,5 @@ class AddTsTimeForOutputs < ActiveRecord::Migration[5.2] def change - add_column :outputs, :ts_time, :float + #add_column :outputs, :ts_time, :float end end diff --git a/db/migrate/20190722062801_modify_answer_for_challenges.rb b/db/migrate/20190722062801_modify_answer_for_challenges.rb new file mode 100644 index 000000000..747564d68 --- /dev/null +++ b/db/migrate/20190722062801_modify_answer_for_challenges.rb @@ -0,0 +1,11 @@ +class ModifyAnswerForChallenges < ActiveRecord::Migration[5.2] + def change + challenges = Challenge.where("answer is not null or answer != ''") + .includes(:challenge_answers).unscoped + challenges.find_each do |c| + next if c.challenge_answers.present? + puts("############challenge_id:##{c.id}") + ChallengeAnswer.create(name: "解题代码", contents: "#{c.answer}", level: 1, score: 100, challenge_id: c.id) + end + end +end diff --git a/public/500.html b/public/500.html index 4837570ad..f885d05a0 100644 --- a/public/500.html +++ b/public/500.html @@ -1,66 +1,62 @@ - +
-If you are the application owner check the logs for more information.
+ + + diff --git a/spec/models/system_update_notice_spec.rb b/spec/models/system_update_notice_spec.rb new file mode 100644 index 000000000..aceabc264 --- /dev/null +++ b/spec/models/system_update_notice_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe SystemUpdateNotice, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/warn/pic_403.jpg b/warn/pic_403.jpg new file mode 100644 index 000000000..5db2f3236 Binary files /dev/null and b/warn/pic_403.jpg differ diff --git a/warn/pic_404.jpg b/warn/pic_404.jpg new file mode 100644 index 000000000..b85751094 Binary files /dev/null and b/warn/pic_404.jpg differ diff --git a/warn/pic_500.jpg b/warn/pic_500.jpg new file mode 100644 index 000000000..f46c1c370 Binary files /dev/null and b/warn/pic_500.jpg differ diff --git a/warn/update.jpeg b/warn/update.jpeg new file mode 100644 index 000000000..ad546b37b Binary files /dev/null and b/warn/update.jpeg differ