diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 9b5f0b869..fdaa30305 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -230,11 +230,16 @@ class ChallengesController < ApplicationController def crud_answer raise '参考答案不能为空' if params[:challenge_answer].empty? raise '占比之和必须为100%' if params[:challenge_answer].map{|a| a[:score]}.sum != 100 - @challenge.challenge_answers.destroy_all if @challenge.challenge_answers - params[:challenge_answer].each_with_index do |answer, index| - ChallengeAnswer.create(name: answer[:name], contents: answer[:contents], - level: index+1, score: answer[:score], challenge_id: @challenge.id) + ActiveRecord::Base.transaction do + @challenge.challenge_answers.destroy_all if @challenge.challenge_answers + params[:challenge_answer].each_with_index do |answer, index| + # 内容为空不保存 + next if answer[:contents].blank? + ChallengeAnswer.create(name: answer[:name], contents: answer[:contents], + level: index+1, score: answer[:score], challenge_id: @challenge.id) + end end + end # 查看参考答案接口 diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 6042fbc9a..973e73dac 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -315,7 +315,7 @@ class CoursesController < ApplicationController # @users = User.where.not(id: user_ids_of_course_members) @users = User.where(status: User::STATUS_ACTIVE) - @users = @users.where("concat(users.firstname, users.lastname) like '%#{name}%'") if name.present? + @users = @users.where("concat(users.lastname, users.firstname) like '%#{name}%'") if name.present? # REDO:Extension @users = @users.joins(user_extension: :school).where("schools.name like '%#{school_name}%'") if school_name.present? diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 84ee9daf2..cfc1c4ba5 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1597,7 +1597,7 @@ class HomeworkCommonsController < ApplicationController att = attachment.copy att.author_id = homework_bank.user_id att.copy_from = attachment.id - att.attachtype = attachment.attachtype + att.attachtype = attachment.attachtype || 1 homework_bank.attachments << att end homework_bank diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index 5ff247729..098c07d1b 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -154,7 +154,7 @@ class QuestionBanksController < ApplicationController att.container_id = nil att.container_type = nil att.author_id = homework.user_id - att.attachtype = attachment.attachtype + att.attachtype = attachment.attachtype || 1 # att.attachtype = 1 att.copy_from = attachment.id att.save! diff --git a/app/controllers/users/project_packages_controller.rb b/app/controllers/users/project_packages_controller.rb new file mode 100644 index 000000000..edd6bd29b --- /dev/null +++ b/app/controllers/users/project_packages_controller.rb @@ -0,0 +1,17 @@ +class Users::ProjectPackagesController < Users::BaseController + + def index + packages = Users::ProjectPackageService.call(observed_user, query_params) + + @count = packages.count + @packages = paginate(packages.includes(:project_package_category)) + + bidding_users = BiddingUser.where(project_package_id: @packages.map(&:id), user_id: observed_user.id) + bidding_users = bidding_users.group(:project_package_id).select(:project_package_id, :status) + @bidding_status_map = bidding_users.each_with_object({}) { |u, h| h[u.project_package_id] = u.status } + end + + def query_params + params.permit(:category, :status, :sort_by, :sort_direction) + end +end \ No newline at end of file diff --git a/app/models/game.rb b/app/models/game.rb index ae056a702..d81b794a5 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -31,7 +31,7 @@ class Game < ApplicationRecord # 根据得分比例来算实际得分(试卷、实训作业) def real_score score - (final_score.to_f / challenge.all_score) * score + ((final_score < 0 ? 0 : final_score).to_f / challenge.all_score) * score end # 判断实训是否全部通关 diff --git a/app/models/project_package.rb b/app/models/project_package.rb index fc541097a..219f60ca4 100644 --- a/app/models/project_package.rb +++ b/app/models/project_package.rb @@ -13,6 +13,9 @@ class ProjectPackage < ApplicationRecord has_many :attachments, as: :container, dependent: :destroy + scope :visible, -> { where(status: %i[published bidding_ended bidding_finished]) } + scope :invisible, -> { where(status: %i[pending applying refused]) } + aasm(:status) do state :pending, initiali: true state :applying diff --git a/app/models/user.rb b/app/models/user.rb index 73036c73e..03c97b9f3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -123,6 +123,11 @@ class User < ApplicationRecord has_many :user_interests, dependent: :delete_all has_many :interests, through: :user_interests, source: :repertoire + # 众包 + has_many :project_packages, foreign_key: :creator_id, dependent: :destroy + has_many :bidding_users, dependent: :destroy + has_many :bidden_project_packages, through: :bidding_users, source: :project_package + # Groups and active users scope :active, lambda { where(status: STATUS_ACTIVE) } @@ -572,6 +577,10 @@ class User < ApplicationRecord Attendance.find_by(user_id: id)&.next_gold || 60 # 基础50,连续签到+10 end + def admin_or_business? + admin? || business? + end + protected def validate_password_length # 管理员的初始密码是5位 diff --git a/app/services/users/project_package_service.rb b/app/services/users/project_package_service.rb new file mode 100644 index 000000000..870cdc98e --- /dev/null +++ b/app/services/users/project_package_service.rb @@ -0,0 +1,76 @@ +class Users::ProjectPackageService < ApplicationService + include CustomSortable + + sort_columns :published_at, default_by: :published_at, default_direction: :desc + + attr_reader :user, :params + + def initialize(user, params) + @user = user + @params = params + end + + def call + packages = category_scope_filter + + packages = user_policy_filter(packages) + + custom_sort(packages, :published_at, params[:sort_direction]) + end + + private + + def category_scope_filter + case params[:category] + when 'bidden' then + user.bidden_project_packages + when 'manage' then + user.project_packages + else + ids = user.bidding_users.pluck(:project_package_id) + user.project_packages.pluck(:id) + ProjectPackage.where(id: ids) + end + end + + def user_policy_filter(relations) + if self_or_admin? + status_filter(relations) + else + relations.visible + end + end + + def status_filter(relations) + return relations unless self_or_admin? + + case params[:category] + when 'bidden' then bidding_status_filter(relations) + when 'manage' then package_status_filter(relations) + else relations + end + end + + def bidding_status_filter(relations) + case params[:status] + when 'bidding_lost' then + relations.where(bidding_users: { status: :bidding_lost }) + when 'bidding_won' then + relations.where(bidding_users: { status: :bidding_won }) + else + relations + end + end + + def package_status_filter(relations) + case params[:status] + when 'unpublished' then relations.invisible + when 'bidding' then relations.where(status: :published) + when 'finished' then relations.where(status: %w[bidding_ended bidding_finished]) + else relations + end + end + + def self_or_admin? + User.current&.id == user.id || User.current&.admin_or_business? + end +end \ No newline at end of file diff --git a/app/views/courses/search_teacher_candidate.json.jbuilder b/app/views/courses/search_teacher_candidate.json.jbuilder index 33bed4100..49109b729 100644 --- a/app/views/courses/search_teacher_candidate.json.jbuilder +++ b/app/views/courses/search_teacher_candidate.json.jbuilder @@ -1,7 +1,7 @@ json.candidates do json.array! @users do |user| json.id user.id - json.name user.firstname + user.lastname + json.name user.real_name json.nickname user.nickname json.school_name user.user_extension.school.try(:name) json.school_id user.user_extension.school.try(:id) diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index b9565535e..51c30ad92 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -21,7 +21,8 @@ if question.question_type <= 2 #当为选择题或判断题时,只显示选 user_answer_b = user_answer.include?(a.id) json.c_position (index+1) if ex_choice_random_boolean #当选项随机时,选项位置以此为准,否则不出现 json.choice_id a.id - json.choice_text (edit_type.present? || question.question_type == 2) ? a.choice_text : "#{(index+65).chr}.#{a.choice_text}" + # json.choice_text (edit_type.present? || question.question_type == 2) ? a.choice_text : "#{(index+65).chr}.#{a.choice_text}" + json.choice_text a.choice_text json.choice_position a.choice_position if exercise_type == 1 || exercise_type == 4 #1为教师编辑/预览 试卷或问题,2为空白试卷,即标准答案和用户答案都不显示,3为用户开始答题的显示,4为老师评阅试卷或学生在截止后查看试卷 json.standard_boolean standard_answer_b diff --git a/app/views/exercises/exercise_result.json.jbuilder b/app/views/exercises/exercise_result.json.jbuilder index 2c4b3ded7..1ceb8209d 100644 --- a/app/views/exercises/exercise_result.json.jbuilder +++ b/app/views/exercises/exercise_result.json.jbuilder @@ -35,15 +35,16 @@ json.commit_results do if q[:type] != Exercise::PRACTICAL json.ques_details do json.array! q[:ques_details].each_with_index.to_a do |d,index| - if q[:type] <= Exercise::MULTIPLE - ques_index = (index+65).chr - elsif q[:type] == Exercise::JUDGMENT - ques_index = (index+1).to_s - else - ques_index = nil - end + # if q[:type] <= Exercise::MULTIPLE + # ques_index = (index+65).chr + # elsif q[:type] == Exercise::JUDGMENT + # ques_index = (index+1).to_s + # else + # ques_index = nil + # end json.choice_position d[:choice_position] - json.choice_text ques_index.present? ? "#{ques_index}.#{d[:choice_text]}" : d[:choice_text] + # json.choice_text ques_index.present? ? "#{ques_index}.#{d[:choice_text]}" : d[:choice_text] + json.choice_text d[:choice_text] json.choice_users_count d[:choice_users_count] json.choice_percent d[:choice_percent] json.choice_right_boolean d[:right_answer] diff --git a/app/views/users/project_packages/index.json.jbuilder b/app/views/users/project_packages/index.json.jbuilder new file mode 100644 index 000000000..a2574d558 --- /dev/null +++ b/app/views/users/project_packages/index.json.jbuilder @@ -0,0 +1,20 @@ +user = observed_user + +json.count @count +json.project_packages do + json.array! @packages.each do |package| + json.extract! package, :id, :title, :status, :min_price, :max_price, :visit_count, :bidding_users_count + + is_creator = user.id == package.creator_id + json.type is_creator ? 'manage' : 'bidden' + json.category_id package.project_package_category_id + json.category_name package.category_name + + unless is_creator + json.bidden_status @bidding_status_map[package.id] + end + + json.deadline_at package.display_deadline_at + json.published_at package.display_published_at + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 16140e99c..bb5bc49cc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -50,6 +50,7 @@ Rails.application.routes.draw do resource :experience_records, only: [:show] resource :grade_records, only: [:show] resource :watch, only: [:create, :destroy] + resources :project_packages, only: [:index] end diff --git a/db/migrate/20190723152256_delete_contents_is_null_for_challenge_answers.rb b/db/migrate/20190723152256_delete_contents_is_null_for_challenge_answers.rb new file mode 100644 index 000000000..a85152894 --- /dev/null +++ b/db/migrate/20190723152256_delete_contents_is_null_for_challenge_answers.rb @@ -0,0 +1,6 @@ +class DeleteContentsIsNullForChallengeAnswers < ActiveRecord::Migration[5.2] + def change + contents = ChallengeAnswer.where("contents = ''") + contents.delete_all + end +end diff --git a/public/images/educoder/nodata.png b/public/images/educoder/nodata.png index 15a9e522f..ad4c76b97 100644 Binary files a/public/images/educoder/nodata.png and b/public/images/educoder/nodata.png differ diff --git a/public/react/src/AppConfig.js b/public/react/src/AppConfig.js index 554cb5bcb..003ef5a9b 100644 --- a/public/react/src/AppConfig.js +++ b/public/react/src/AppConfig.js @@ -2,7 +2,7 @@ import React from "react"; import axios from 'axios'; import { requestProxy } from "./indexEduplus2RequestProxy"; -import { broadcastChannelOnmessage ,SetAppModel} from 'educoder'; +import { broadcastChannelOnmessage ,SetAppModel, isDev, queryString} from 'educoder'; import { notification } from 'antd'; import './index.css' broadcastChannelOnmessage('refreshPage', () => { @@ -18,10 +18,19 @@ function locationurl(list){ } // TODO 开发期多个身份切换 -const debugType ="" -// window.location.search.indexOf('debug=t') != -1 ? 'teacher' : -// window.location.search.indexOf('debug=s') != -1 ? 'student' : 'admin' -// window._debugType = debugType; +let debugType = "" +if (isDev) { + const _search = window.location.search; + let parsed = {}; + if (_search) { + parsed = queryString.parse(_search); + } + debugType = window.location.search.indexOf('debug=t') != -1 ? 'teacher' : + window.location.search.indexOf('debug=s') != -1 ? 'student' : + window.location.search.indexOf('debug=a') != -1 ? 'admin' : parsed.debug || '' +} + +window._debugType = debugType; export function initAxiosInterceptors(props) { // TODO 避免重复的请求 https://github.com/axios/axios#cancellation diff --git a/public/react/src/modules/comment/Comments.js b/public/react/src/modules/comment/Comments.js index 1b2e2b45a..ce5cc8017 100644 --- a/public/react/src/modules/comment/Comments.js +++ b/public/react/src/modules/comment/Comments.js @@ -574,7 +574,7 @@ class Comments extends Component {
-

暂时还没有评论~

+

暂时还没有相关数据哦!

: '' } diff --git a/public/react/src/modules/courses/Resource/index.js b/public/react/src/modules/courses/Resource/index.js index 34fe53e4f..f83b525ee 100644 --- a/public/react/src/modules/courses/Resource/index.js +++ b/public/react/src/modules/courses/Resource/index.js @@ -956,7 +956,7 @@ class Fileslists extends Component{ >
-

暂无数据哦~

+

暂时还没有相关数据哦!

diff --git a/public/react/src/modules/courses/coursesHome/CoursesHome.js b/public/react/src/modules/courses/coursesHome/CoursesHome.js index 3f4b4ad12..962413e54 100644 --- a/public/react/src/modules/courses/coursesHome/CoursesHome.js +++ b/public/react/src/modules/courses/coursesHome/CoursesHome.js @@ -145,7 +145,7 @@ class CoursesHome extends Component{ {coursesHomelist===undefined?"":coursesHomelist.courses.length===0?
-

暂无数据哦~

+

暂时还没有相关数据哦!

:""} { diff --git a/public/react/src/modules/courses/coursesPublic/NoneData.js b/public/react/src/modules/courses/coursesPublic/NoneData.js index 9e23cbe2e..8c280b6c5 100644 --- a/public/react/src/modules/courses/coursesPublic/NoneData.js +++ b/public/react/src/modules/courses/coursesPublic/NoneData.js @@ -9,7 +9,7 @@ class NoneData extends Component{ return(
-

暂无数据哦~

+

暂时还没有相关数据哦!

) } diff --git a/public/react/src/modules/courses/graduation/tasks/index.js b/public/react/src/modules/courses/graduation/tasks/index.js index ac2a226bd..08639b521 100644 --- a/public/react/src/modules/courses/graduation/tasks/index.js +++ b/public/react/src/modules/courses/graduation/tasks/index.js @@ -773,7 +773,7 @@ class GraduationTasks extends Component{ >
-

暂无数据哦~

+

暂时还没有相关数据哦!

diff --git a/public/react/src/modules/courses/shixunHomework/ShixunStudentWork.js b/public/react/src/modules/courses/shixunHomework/ShixunStudentWork.js index 8dd33bcd3..0c808e01d 100644 --- a/public/react/src/modules/courses/shixunHomework/ShixunStudentWork.js +++ b/public/react/src/modules/courses/shixunHomework/ShixunStudentWork.js @@ -838,7 +838,7 @@ class ShixunStudentWork extends Component { {datalist === undefined ? "" : datalist.length===0?
-

暂无数据哦~

+

暂时还没有相关数据哦!

:
-

暂无数据哦~

+

暂时还没有相关数据哦!

diff --git a/public/react/src/modules/paths/ShixunPathCard.js b/public/react/src/modules/paths/ShixunPathCard.js index d538ad255..9260b9f46 100644 --- a/public/react/src/modules/paths/ShixunPathCard.js +++ b/public/react/src/modules/paths/ShixunPathCard.js @@ -68,7 +68,7 @@ class ShixunPathCard extends Component{ ):(
-

暂无数据哦~

+

暂时还没有相关数据哦!

) } diff --git a/public/react/src/modules/tpm/shixunchild/Challenges/Challenges.js b/public/react/src/modules/tpm/shixunchild/Challenges/Challenges.js index 85b0920e0..f5d57ae21 100644 --- a/public/react/src/modules/tpm/shixunchild/Challenges/Challenges.js +++ b/public/react/src/modules/tpm/shixunchild/Challenges/Challenges.js @@ -348,14 +348,14 @@ class Challenges extends Component {
-

暂无数据哦~

+

暂时还没有相关数据哦!

: ChallengesDataList.challenge_list === undefined ?
-

暂无数据哦~

+

暂时还没有相关数据哦!

: ChallengesDataList.challenge_list.length === 0 ? @@ -363,7 +363,7 @@ class Challenges extends Component {
-

暂无数据哦~

+

暂时还没有相关数据哦!

: ChallengesDataList.challenge_list.map((item, key) => { diff --git a/public/react/src/modules/tpm/shixunchild/Propaedeutics/Propaedeu_tics.js b/public/react/src/modules/tpm/shixunchild/Propaedeutics/Propaedeu_tics.js index 7582f52e4..a2b20415d 100644 --- a/public/react/src/modules/tpm/shixunchild/Propaedeutics/Propaedeu_tics.js +++ b/public/react/src/modules/tpm/shixunchild/Propaedeutics/Propaedeu_tics.js @@ -92,7 +92,7 @@ class Propaedeutics extends Component {
-

暂无数据哦~

+

暂时还没有相关数据哦!

diff --git a/public/react/src/modules/tpm/shixunchild/Repository/Repository.js b/public/react/src/modules/tpm/shixunchild/Repository/Repository.js index acdeb616b..c888ba6d8 100644 --- a/public/react/src/modules/tpm/shixunchild/Repository/Repository.js +++ b/public/react/src/modules/tpm/shixunchild/Repository/Repository.js @@ -164,7 +164,7 @@ class Repository extends Component { trees === undefined || trees === null ?
-

暂无数据哦~

+

暂时还没有相关数据哦!

:
diff --git a/public/react/src/modules/tpm/shixuns/ShixunCard.js b/public/react/src/modules/tpm/shixuns/ShixunCard.js index 18e261bb5..ae6aa696d 100644 --- a/public/react/src/modules/tpm/shixuns/ShixunCard.js +++ b/public/react/src/modules/tpm/shixuns/ShixunCard.js @@ -64,7 +64,7 @@ class ShixunCard extends Component {
-

暂无数据哦~

+

暂时还没有相关数据哦!

diff --git a/public/stylesheets/educoder/edu-main.css b/public/stylesheets/educoder/edu-main.css index 3777201b4..af2725447 100644 --- a/public/stylesheets/educoder/edu-main.css +++ b/public/stylesheets/educoder/edu-main.css @@ -444,8 +444,9 @@ ul.abouttable li .minh-label{min-width: 150px;height: 28px;line-height: 28px;tex .allNone tr{height: 30px!important;} /*数据为空公共页面*/ -img.edu-nodata-img{ width:300px; margin:50px auto 20px; display: block;} -.edu-nodata-p{ font-size: 20px; text-align: center; color:#999;border-bottom:none!important;padding-left: 18px;box-sizing: border-box;} +img.edu-nodata-img{ width:300px; margin:50px auto 20px; display: block; width: 128px;} +/* 不能加 padding-left: 18px; 会影响其他地方的居中 */ +.edu-nodata-p{ font-size: 20px; text-align: center; color:#999;border-bottom:none!important;box-sizing: border-box;} /*输入为空或者错误的提示*/ .input-none{box-shadow: 0px 0px 2px rgba(0,0,0,0.1);}