From feacad4948cdff5e6cb2528af4da05c9a4959371 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 29 Oct 2019 15:09:56 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/student_works_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/student_works_helper.rb b/app/helpers/student_works_helper.rb index ebe0ce52d..73d12aa2f 100644 --- a/app/helpers/student_works_helper.rb +++ b/app/helpers/student_works_helper.rb @@ -126,7 +126,7 @@ module StudentWorksHelper if game.status == 2 "评测通过" else - "共有#{game.challenge.challenge_chooses.count}组测试集,其中有#{game.challenge.challenge_chooses.count-game.choose_correct_num}组测试结果不匹配" + "共有#{game.challenge.challenge_chooses.count}组测试集,其中有#{game.challenge.challenge_chooses.count-game.choose_correct_num(output.query_index)}组测试结果不匹配" end end end From 9e7e920c4f91b8413c7508adfa9f4889a3813e6c Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Tue, 29 Oct 2019 15:10:59 +0800 Subject: [PATCH 2/4] ADD sync some data to trusti platform --- app/jobs/sync_trustie_job.rb | 19 ++++++++++--------- app/models/application_record.rb | 4 ++++ app/models/project.rb | 7 +++---- app/models/school.rb | 8 +++----- app/models/shixun.rb | 10 +++++----- app/models/user.rb | 8 +++----- .../20191029065244_init_trustie_config.rb | 8 ++++++++ 7 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 db/migrate/20191029065244_init_trustie_config.rb diff --git a/app/jobs/sync_trustie_job.rb b/app/jobs/sync_trustie_job.rb index 89c0b8375..33df5b529 100644 --- a/app/jobs/sync_trustie_job.rb +++ b/app/jobs/sync_trustie_job.rb @@ -6,20 +6,21 @@ class SyncTrustieJob < ApplicationJob def perform(type, count) Rails.logger.info("#######_________response__sync__start__#########") - configs_content = Rails.application.config_for(:configuration) - token = configs_content["sync_token"] - token_url = configs_content["sync_url"] - url = "#{token_url}/api/v1/homes/sync_count" + token = EduSetting.get('trustie_api_token') + api_host = EduSetting.get('trustie_api_url') + + url = "#{api_host}/api/v1/homes/sync_count" sync_json = { "token": token, "type": type, "number": count } uri = URI.parse(url) - - http = Net::HTTP.new(uri.hostname, uri.port) - http.send_request('PUT', uri.path, sync_json.to_json, {'Content-Type' => 'application/json'}) - Rails.logger.info("#######_________response__sync__end_____#########") + if api_host + http = Net::HTTP.new(uri.hostname, uri.port) + http.send_request('PUT', uri.path, sync_json.to_json, {'Content-Type' => 'application/json'}) + Rails.logger.info("#######_________response__sync__end_____#########") + end end -end \ No newline at end of file +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb index ded4119cd..b3807faa0 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -12,4 +12,8 @@ class ApplicationRecord < ActiveRecord::Base def display_extra_data(key) _extra_data&.[](key) end + + def allow_sync_to_trustie? + Rails.env.production? && EduSetting.get('host_name') == 'https://www.educoder.net/' + end end diff --git a/app/models/project.rb b/app/models/project.rb index c884935d8..2e0a8be64 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -8,7 +8,9 @@ class Project < ApplicationRecord has_many :issues has_many :user_grades, dependent: :destroy - after_create :sync_project_trustie #同步到trustie + after_create do + SyncTrustieJob.perform_later("project", 1) if allow_sync_to_trustie? + end #同步到trustie # 创建者 def creator @@ -23,7 +25,4 @@ class Project < ApplicationRecord members.exists?(user_id: user.id) end - def sync_project_trustie - SyncTrustieJob.perform_later("project", 1) - end end diff --git a/app/models/school.rb b/app/models/school.rb index 1608377a6..10bbd4e76 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -19,7 +19,9 @@ class School < ApplicationRecord has_many :apply_add_departments, dependent: :destroy has_many :user_extensions, dependent: :nullify - after_create :sync_school_trustie #同步到trustie + after_create do + SyncTrustieJob.perform_later("school", 1) if allow_sync_to_trustie? #同步到trustie + end # 学校管理员 def manager?(user) @@ -41,8 +43,4 @@ class School < ApplicationRecord def manage_permission?(user) manager?(user) || major_manager?(user) || course_manager?(user) end - - def sync_school_trustie - SyncTrustieJob.perform_later("school", 1) - end end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 744d486e3..103c8b68f 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -75,7 +75,11 @@ class Shixun < ApplicationRecord scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) } scope :find_by_ids,lambda{|k| where(id:k)} - after_create :send_tiding, :sync_shixun_trustie #同步到trustie + after_create :send_tiding + #同步到trustie + after_create do + SyncTrustieJob.perform_later("practical_training_project", 1) if allow_sync_to_trustie? + end # REDO:  def propaedeutics @@ -290,10 +294,6 @@ class Shixun < ApplicationRecord subjects.where(hidden: 0).uniq end - def sync_shixun_trustie - SyncTrustieJob.perform_later("practical_training_project", 1) - end - private def send_tiding diff --git a/app/models/user.rb b/app/models/user.rb index 6b5fc62ee..6c9af3099 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -156,7 +156,9 @@ class User < ApplicationRecord delegate :gender, :department_id, :school_id, :location, :location_city, :technical_title, to: :user_extension, allow_nil: true before_save :update_hashed_password - after_create :sync_user_trustie #同步到trustie + after_create do + SyncTrustieJob.perform_later("user", 1) if allow_sync_to_trustie? + end # # validations @@ -314,10 +316,6 @@ class User < ApplicationRecord shixun.shixun_members.exists?(role: 2, user_id: id) end - def sync_user_trustie - SyncTrustieJob.perform_later("user", 1) - end - # TPI的创建者 def creator_of_game?(game) id == game.user_id diff --git a/db/migrate/20191029065244_init_trustie_config.rb b/db/migrate/20191029065244_init_trustie_config.rb new file mode 100644 index 000000000..24ec7a245 --- /dev/null +++ b/db/migrate/20191029065244_init_trustie_config.rb @@ -0,0 +1,8 @@ +class InitTrustieConfig < ActiveRecord::Migration[5.2] + def change + hash = {"trustie_api_token" => "", "trustie_api_url" => ""} + hash.each { |key, value| + EduSetting.find_or_create_by(name: key, value: value) + } + end +end From bd2018263bdb2751fc241cb03f8322e01bfd930f Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Tue, 29 Oct 2019 15:14:35 +0800 Subject: [PATCH 3/4] FIX . --- app/models/application_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/application_record.rb b/app/models/application_record.rb index b3807faa0..888c65423 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -14,6 +14,6 @@ class ApplicationRecord < ActiveRecord::Base end def allow_sync_to_trustie? - Rails.env.production? && EduSetting.get('host_name') == 'https://www.educoder.net/' + Rails.env.production? && EduSetting.get('host_name') == 'https://www.educoder.net' end end From f51b6a7f772b07ac71b7bc1b91bab785ff3d0877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Tue, 29 Oct 2019 15:23:36 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=EF=BC=8C=E7=AB=9E=E8=B5=9B=E6=9D=83=E9=99=90=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Competitimain/CompetitionsIndex.js | 19 +- .../modules/courses/statistics/Statistics.js | 226 ++++++++++++------ 2 files changed, 160 insertions(+), 85 deletions(-) diff --git a/public/react/src/modules/competitions/Competitimain/CompetitionsIndex.js b/public/react/src/modules/competitions/Competitimain/CompetitionsIndex.js index e72926fcd..39eb647de 100644 --- a/public/react/src/modules/competitions/Competitimain/CompetitionsIndex.js +++ b/public/react/src/modules/competitions/Competitimain/CompetitionsIndex.js @@ -53,14 +53,6 @@ class CompetitionsIndex extends Component{ this.getdata(e.key,page) }; - setcompetitonurl=(url)=>{ - - if(url!=null){ - // this.props.history.push(url); - window.location.href=url; - } - } - PaginationCourse=(pageNumber)=>{ let {category}=this.state; this.setState({ @@ -68,6 +60,7 @@ class CompetitionsIndex extends Component{ }) this.getdata(category,pageNumber); } + render() { let {datas,page,count}=this.state; @@ -124,14 +117,14 @@ class CompetitionsIndex extends Component{ size="large" dataSource={datas&&datas} renderItem={(item,key) => ( -
{item.competition_status==="nearly_published"? - this.props.current_user&&this.props.current_user.admin===true?"":this.props.current_user&&this.props.current_user.business===true?"":
即将发布 敬请期待
:""} + item.permission.editable==true?"":
即将发布 敬请期待
:""} {/*
即将发布 敬请期待
*/} {/*{item.description===null||item.description===undefined||item.description===""?