diff --git a/app/assets/javascripts/admins/competition_settings/index.js b/app/assets/javascripts/admins/competition_settings/index.js
index bd84123f5..81fbf7519 100644
--- a/app/assets/javascripts/admins/competition_settings/index.js
+++ b/app/assets/javascripts/admins/competition_settings/index.js
@@ -154,7 +154,7 @@ $(document).on('turbolinks:load', function(){
},
templateResult: function (item) {
if(!item.id || item.id === '') return item.text;
- return $("" + item.real_name + " " + item.school_name + ' ' + item.hidden_phone + "");
+ return $("
" + item.real_name + "" + item.school_name + "" + item.hidden_phone + "
");
},
templateSelection: function(item){
if (item.id) {
diff --git a/app/assets/javascripts/admins/subjects/index.js b/app/assets/javascripts/admins/subjects/index.js
new file mode 100644
index 000000000..0d63ae4cd
--- /dev/null
+++ b/app/assets/javascripts/admins/subjects/index.js
@@ -0,0 +1,50 @@
+$(document).on('turbolinks:load', function() {
+ if ($('body.admins-subjects-index-page').length > 0) {
+ var $form = $('.subject-list-form');
+
+ // ************** 学校选择 *************
+ $form.find('.school-select').select2({
+ theme: 'bootstrap4',
+ placeholder: '请选择创建者单位',
+ minimumInputLength: 1,
+ ajax: {
+ delay: 500,
+ url: '/api/schools/for_option.json',
+ dataType: 'json',
+ data: function(params){
+ return { keyword: params.term };
+ },
+ processResults: function(data){
+ return { results: data.schools }
+ }
+ },
+ templateResult: function (item) {
+ if(!item.id || item.id === '') return item.text;
+ return item.name;
+ },
+ templateSelection: function(item){
+ if (item.id) {
+ }
+ return item.name || item.text;
+ }
+ });
+
+ // 清空
+ $form.on('click', '.clear-btn', function(){
+ $form.find('select[name="status"]').val('');
+ $form.find('.school-select').val('').trigger('change');
+ $form.find('input[name="keyword"]').val('');
+ $form.find('#homepage_show').attr('checked', false);
+ $form.find('#excellent').attr('checked', false);
+ $form.find('input[type="submit"]').trigger('click');
+ })
+
+ // 上传图片
+ $('.modal.admin-upload-file-modal').on('upload:success', function(e, data){
+ var $imageElement = $('.subject-image-' + data.source_id);
+ $imageElement.attr('src', data.url);
+ $imageElement.show();
+ $imageElement.next().html('重新上传');
+ })
+ }
+});
\ No newline at end of file
diff --git a/app/assets/stylesheets/admins/sidebar.scss b/app/assets/stylesheets/admins/sidebar.scss
index be7da93ac..db71591ef 100644
--- a/app/assets/stylesheets/admins/sidebar.scss
+++ b/app/assets/stylesheets/admins/sidebar.scss
@@ -21,9 +21,12 @@
flex-direction: column;
&-logo {
- padding-left: 5px;
overflow: hidden;
margin-bottom: 10px;
+
+ & > .logo-label {
+ display: none;
+ }
}
}
@@ -54,7 +57,7 @@
-ms-transform: translateX(50%);
transform: translateX(50%);
}
-
+
ul ul a {
padding: 10px !important;
@@ -76,6 +79,23 @@
display: flex;
flex-direction: row;
justify-content: space-between;
+
+ &-logo {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+
+ & > img {
+ width: 40px;
+ height: auto;
+ }
+
+ & > .logo-label {
+ font-size: 18px;
+ color: darkgrey;
+ margin-left: 10px;
+ }
+ }
}
#sidebarCollapse {
@@ -183,7 +203,7 @@
ul li a {
padding: 10px;
font-size: 0.85em;
-
+
i {
margin-right: 0;
display: block;
@@ -194,7 +214,7 @@
& > ul > li > a > i {
font-size: 1.8em;
}
-
+
ul ul a {
padding: 10px !important;
}
diff --git a/app/controllers/admins/subjects_controller.rb b/app/controllers/admins/subjects_controller.rb
new file mode 100644
index 000000000..6795440ac
--- /dev/null
+++ b/app/controllers/admins/subjects_controller.rb
@@ -0,0 +1,8 @@
+class Admins::SubjectsController < Admins::BaseController
+ def index
+ default_sort('created_at', 'desc')
+
+ subjects = Admins::SubjectQuery.call(params)
+ @subjects = paginate subjects.includes(:repertoire, :subject_level_system, user: { user_extension: :school })
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/competitions/competitions_controller.rb b/app/controllers/competitions/competitions_controller.rb
index 63d0942cc..1a80dc7e6 100644
--- a/app/controllers/competitions/competitions_controller.rb
+++ b/app/controllers/competitions/competitions_controller.rb
@@ -145,7 +145,10 @@ class Competitions::CompetitionsController < Competitions::BaseController
end
def allow_visit
- render_forbidden unless current_competition.published? || admin_or_business?
+ return if current_competition.published? || admin_or_business?
+ return if current_competition.nearly_published? && current_competition.manager?(current_user)
+
+ render_forbidden
end
def chart_visible
diff --git a/app/helpers/admins/subjects_helper.rb b/app/helpers/admins/subjects_helper.rb
new file mode 100644
index 000000000..56738fd86
--- /dev/null
+++ b/app/helpers/admins/subjects_helper.rb
@@ -0,0 +1,11 @@
+module Admins::SubjectsHelper
+ def display_subject_status(subject)
+ style =
+ case subject.status
+ when 0 then 'text-secondary'
+ when 1 then 'text-warning'
+ when 2 then 'text-success'
+ end
+ raw content_tag(:span, t("subject.status.#{subject.status}"), class: style)
+ end
+end
\ No newline at end of file
diff --git a/app/libs/custom_sortable.rb b/app/libs/custom_sortable.rb
index 21ead8a4e..3b22bb016 100644
--- a/app/libs/custom_sortable.rb
+++ b/app/libs/custom_sortable.rb
@@ -14,7 +14,13 @@ module CustomSortable
return relations unless self.class.check_sort_parameter_validate(sort_by.to_s, sort_direction.to_s)
order_method = self.class.sort_options[:reorder] ? :reorder : :order
- relations.send(order_method, "#{sort_by} #{sort_direction}")
+
+ default_table = self.class.sort_options[:default_table]
+ if default_table.present?
+ relations.send(order_method, "#{default_table}.#{sort_by} #{sort_direction}")
+ else
+ relations.send(order_method, "#{sort_by} #{sort_direction}")
+ end
end
module ClassMethods
@@ -23,6 +29,7 @@ module CustomSortable
@_sort_options[:default_by] = opts[:default_by].to_s
@_sort_options[:default_direction] = opts[:default_direction].to_s
@_sort_options[:reorder] = opts[:reorder]
+ @_sort_options[:default_table] = opts[:default_table]
@_sort_columns = columns.map(&:to_s)
end
diff --git a/app/models/subject.rb b/app/models/subject.rb
index d29a97d0c..d96b6b06c 100644
--- a/app/models/subject.rb
+++ b/app/models/subject.rb
@@ -7,6 +7,7 @@ class Subject < ApplicationRecord
#status :0 编辑中 1 审核中 2 发布
belongs_to :repertoire
belongs_to :user
+ belongs_to :subject_level_system, optional: true
has_many :stages, -> { order("stages.position ASC") }, dependent: :destroy
diff --git a/app/models/subject_level_system.rb b/app/models/subject_level_system.rb
new file mode 100644
index 000000000..f8cc2b53e
--- /dev/null
+++ b/app/models/subject_level_system.rb
@@ -0,0 +1,5 @@
+class SubjectLevelSystem < ApplicationRecord
+ default_scope { order(level: :asc) }
+
+ has_many :subjects, dependent: :nullify
+end
\ No newline at end of file
diff --git a/app/queries/admins/subject_query.rb b/app/queries/admins/subject_query.rb
new file mode 100644
index 000000000..d5b60b8b6
--- /dev/null
+++ b/app/queries/admins/subject_query.rb
@@ -0,0 +1,45 @@
+class Admins::SubjectQuery < ApplicationQuery
+ include CustomSortable
+
+ attr_reader :params
+
+ sort_columns :created_at, default_by: :created_at, default_direction: :desc, default_table: 'subjects'
+
+ def initialize(params)
+ @params = params
+ end
+
+ def call
+ subjects = Subject.all
+
+ # 状态过滤
+ status =
+ case params[:status].to_s.strip
+ when 'pending' then 0
+ when 'applying' then 1
+ when 'published' then 2
+ end
+ subjects = subjects.where(status: status) if status
+
+ # 创建者单位
+ if params[:school_id].present?
+ subjects = subjects.joins(user: :user_extension).where(user_extensions: { school_id: params[:school_id] })
+ end
+
+ # 首页展示、金课
+ %i[homepage_show excellent].each do |column|
+ if params[column].present? && params[column].to_s == 'true'
+ subjects = subjects.where(column => true)
+ end
+ end
+
+ # 关键字
+ keyword = params[:keyword].to_s.strip
+ if keyword
+ sql = 'CONCAT(lastname, firstname) LIKE :keyword OR subjects.name LIKE :keyword'
+ subjects = subjects.joins(:user).where(sql, keyword: "%#{keyword}%")
+ end
+
+ custom_sort(subjects, params[:sort_by], params[:sort_direction])
+ end
+end
\ No newline at end of file
diff --git a/app/views/admins/laboratories/shared/_laboratory_item.html.erb b/app/views/admins/laboratories/shared/_laboratory_item.html.erb
index 4262d2aee..92b8ef9a9 100644
--- a/app/views/admins/laboratories/shared/_laboratory_item.html.erb
+++ b/app/views/admins/laboratories/shared/_laboratory_item.html.erb
@@ -36,12 +36,14 @@
<%= javascript_void_link '添加管理员', class: 'action', data: { laboratory_id: laboratory.id, toggle: 'modal', target: '.admin-add-laboratory-user-modal' } %>
<% end %>
- <%= javascript_void_link('更多', class: 'action dropdown-toggle', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false) %>
-