Merge branch 'master' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_forum
杨树林 5 years ago
commit c696207ac3

@ -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

@ -13,6 +13,9 @@ class ProjectPackage < ApplicationRecord
has_many :attachments, as: :container, dependent: :destroy 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 aasm(:status) do
state :pending, initiali: true state :pending, initiali: true
state :applying state :applying

@ -123,6 +123,11 @@ class User < ApplicationRecord
has_many :user_interests, dependent: :delete_all has_many :user_interests, dependent: :delete_all
has_many :interests, through: :user_interests, source: :repertoire 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 # Groups and active users
scope :active, lambda { where(status: STATUS_ACTIVE) } 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 Attendance.find_by(user_id: id)&.next_gold || 60 # 基础50连续签到+10
end end
def admin_or_business?
admin? || business?
end
protected protected
def validate_password_length def validate_password_length
# 管理员的初始密码是5位 # 管理员的初始密码是5位

@ -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

@ -21,7 +21,8 @@ if question.question_type <= 2 #当为选择题或判断题时,只显示选
user_answer_b = user_answer.include?(a.id) user_answer_b = user_answer.include?(a.id)
json.c_position (index+1) if ex_choice_random_boolean #当选项随机时,选项位置以此为准,否则不出现 json.c_position (index+1) if ex_choice_random_boolean #当选项随机时,选项位置以此为准,否则不出现
json.choice_id a.id 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 json.choice_position a.choice_position
if exercise_type == 1 || exercise_type == 4 #1为教师编辑/预览 试卷或问题2为空白试卷即标准答案和用户答案都不显示3为用户开始答题的显示4为老师评阅试卷或学生在截止后查看试卷 if exercise_type == 1 || exercise_type == 4 #1为教师编辑/预览 试卷或问题2为空白试卷即标准答案和用户答案都不显示3为用户开始答题的显示4为老师评阅试卷或学生在截止后查看试卷
json.standard_boolean standard_answer_b json.standard_boolean standard_answer_b

@ -35,15 +35,16 @@ json.commit_results do
if q[:type] != Exercise::PRACTICAL if q[:type] != Exercise::PRACTICAL
json.ques_details do json.ques_details do
json.array! q[:ques_details].each_with_index.to_a do |d,index| json.array! q[:ques_details].each_with_index.to_a do |d,index|
if q[:type] <= Exercise::MULTIPLE # if q[:type] <= Exercise::MULTIPLE
ques_index = (index+65).chr # ques_index = (index+65).chr
elsif q[:type] == Exercise::JUDGMENT # elsif q[:type] == Exercise::JUDGMENT
ques_index = (index+1).to_s # ques_index = (index+1).to_s
else # else
ques_index = nil # ques_index = nil
end # end
json.choice_position d[:choice_position] 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_users_count d[:choice_users_count]
json.choice_percent d[:choice_percent] json.choice_percent d[:choice_percent]
json.choice_right_boolean d[:right_answer] json.choice_right_boolean d[:right_answer]

@ -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

@ -50,6 +50,7 @@ Rails.application.routes.draw do
resource :experience_records, only: [:show] resource :experience_records, only: [:show]
resource :grade_records, only: [:show] resource :grade_records, only: [:show]
resource :watch, only: [:create, :destroy] resource :watch, only: [:create, :destroy]
resources :project_packages, only: [:index]
end end

@ -25,9 +25,7 @@ if (isDev) {
if (_search) { if (_search) {
parsed = queryString.parse(_search); parsed = queryString.parse(_search);
} }
debugType = window.location.search.indexOf('debug=t') != -1 ? 'teacher' : debugType = window.location.search.indexOf('debug=t') != -1 ? "cxt" : ''
window.location.search.indexOf('debug=s') != -1 ? 'student' :
window.location.search.indexOf('debug=a') != -1 ? 'admin' : parsed.debug || ''
} }
window._debugType = debugType; window._debugType = debugType;
@ -144,6 +142,7 @@ export function initAxiosInterceptors(props) {
// } // }
if (response.data.status === 403) { if (response.data.status === 403) {
// props.history.replace('/403') // props.history.replace('/403')
debugger
// 这里会分2个情况1、刚进入页面发请求返回的4032、进入页面后其他用户操作触发请求返回的403 // 这里会分2个情况1、刚进入页面发请求返回的4032、进入页面后其他用户操作触发请求返回的403
// TODO 这里做一个403弹框比较好 // TODO 这里做一个403弹框比较好
locationurl('/403'); locationurl('/403');

@ -147,6 +147,8 @@ class Addcourses extends Component{
if(Addcoursestype===true){ if(Addcoursestype===true){
this.props.hideAddcoursestype(); this.props.hideAddcoursestype();
}else{
window.location.href = "/";
} }
} }

@ -382,7 +382,7 @@ class ShixunhomeWorkItem extends Component{
<a className="btn colorblue font-16" href={"/shixuns/"+discussMessage.shixun_identifier+"/challenges"} target={"_blank"}>实训详情</a> <a className="btn colorblue font-16" href={"/shixuns/"+discussMessage.shixun_identifier+"/challenges"} target={"_blank"}>实训详情</a>
{this.props.isAdminOrCreator()?<a onClick={()=>this.editname(discussMessage.name,discussMessage.homework_id)} className={"btn colorblue ml20 font-16"}>重命名</a>:""} {this.props.isAdminOrCreator()?<a onClick={()=>this.editname(discussMessage.name,discussMessage.homework_id)} className={"btn colorblue ml20 font-16"}>重命名</a>:""}
{/*<WordsBtn className="btn colorblue ml20 font-16" to={`/courses/${this.props.match.params.coursesId}/${this.state.shixuntypes}/${discussMessage.homework_id}/settings?tab=3`} > 设置</WordsBtn>*/} {/*<WordsBtn className="btn colorblue ml20 font-16" to={`/courses/${this.props.match.params.coursesId}/${this.state.shixuntypes}/${discussMessage.homework_id}/settings?tab=3`} > 设置</WordsBtn>*/}
<WordsBtn className="btn colorblue font-16" to={`/courses/${this.props.match.params.coursesId}/${this.state.shixuntypes}/${discussMessage.homework_id}/settings?tab=3`} > 设置</WordsBtn> <WordsBtn className="btn colorblue font-16 ml20" to={`/courses/${this.props.match.params.coursesId}/${this.state.shixuntypes}/${discussMessage.homework_id}/settings?tab=3`} > 设置</WordsBtn>
</div>:""} </div>:""}

@ -487,10 +487,11 @@ submittojoinclass=(value)=>{
} }
showSearchOpen=(e)=>{ showSearchOpen=(e)=>{
debugger
this.setState({ this.setState({
showSearchOpentype:true showSearchOpentype:true
}) })
e.stopPropagation(e);//阻止冒泡
} }
hideshowSearchOpen=(e)=>{ hideshowSearchOpen=(e)=>{
@ -500,7 +501,7 @@ submittojoinclass=(value)=>{
showSearchOpentype:false, showSearchOpentype:false,
setevaluatinghides:false setevaluatinghides:false
}) })
e.stopPropagation(e);//阻止冒泡
} }
} }

Loading…
Cancel
Save