diff --git a/app/controllers/admins/competitions_controller.rb b/app/controllers/admins/competitions_controller.rb new file mode 100644 index 000000000..3d6bef819 --- /dev/null +++ b/app/controllers/admins/competitions_controller.rb @@ -0,0 +1,15 @@ +class Admins::CompetitionsController < Admins::BaseController + + def index + params[:sort_by] = params[:sort_by].presence || 'created_on' + params[:sort_direction] = params[:sort_direction].presence || 'desc' + @competitions = custom_sort Competition.all, params[:sort_by], params[:sort_direction] + @params_page = params[:page] || 1 + @competitions = paginate @competitions + + respond_to do |format| + format.js + format.html + end + end +end \ No newline at end of file diff --git a/app/controllers/course_modules_controller.rb b/app/controllers/course_modules_controller.rb index fccc28f6d..0bef519fd 100644 --- a/app/controllers/course_modules_controller.rb +++ b/app/controllers/course_modules_controller.rb @@ -2,7 +2,8 @@ class CourseModulesController < ApplicationController before_action :require_login, :check_auth before_action :set_module, except: [:unhidden_modules] before_action :find_course, only: [:unhidden_modules] - before_action :teacher_or_admin_allowed + before_action :teacher_or_admin_allowed, except: [:add_second_category] + before_action :teacher_allowed, only: [:add_second_category] # 模块置顶 def sticky_module diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 9c60317bd..8b7034ab9 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -98,7 +98,7 @@ class Attachment < ApplicationRecord def become_history history = self.attachment_histories.first - new_attachment_history = AttachmentHistory.new(self.attributes.except("id", "resource_bank_id", "unified_setting", "course_second_category_id").merge( + new_attachment_history = AttachmentHistory.new(self.attributes.except("id", "resource_bank_id", "unified_setting", "course_second_category_id", "delay_publish").merge( attachment_id: self.id, version: history.nil? ? 1 : history.version + 1, )) @@ -106,7 +106,7 @@ class Attachment < ApplicationRecord end def copy_attributes_from_new_attachment(new_attachment) - self.attributes = new_attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads", "quotes",'is_publish','publish_time') + self.attributes = new_attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads", "quotes",'is_publish','publish_time', "delay_publish") end def set_public(is_public) diff --git a/app/models/competition_mode_setting.rb b/app/models/competition_mode_setting.rb new file mode 100644 index 000000000..b6bafa7c3 --- /dev/null +++ b/app/models/competition_mode_setting.rb @@ -0,0 +1,3 @@ +class CompetitionModeSetting < ApplicationRecord + belongs_to :course +end diff --git a/app/views/admins/competitions/index.html.erb b/app/views/admins/competitions/index.html.erb new file mode 100644 index 000000000..8fa238181 --- /dev/null +++ b/app/views/admins/competitions/index.html.erb @@ -0,0 +1,7 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('竞赛列表', admins_competitions_path) %> +<% end %> + +
+ <%= render partial: 'admins/shixuns/shared/list', locals: { shixuns: @shixuns } %> +
diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index 145910928..ca6fb2a46 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -66,6 +66,8 @@ <% end %> +
  • <%= sidebar_item(admins_competitions_path, '竞赛', icon: 'trophy', controller: 'admins-competitions') %>
  • +
  • <%= sidebar_item_group('#setting-submenu', '网站建设', icon: 'cogs') do %>
  • <%= sidebar_item(admins_carousels_path, '轮播图', icon: 'image', controller: 'admins-carousels') %>
  • diff --git a/app/views/competitions/competitions/index.json.jbuilder b/app/views/competitions/competitions/index.json.jbuilder index f0d70f69e..400f17379 100644 --- a/app/views/competitions/competitions/index.json.jbuilder +++ b/app/views/competitions/competitions/index.json.jbuilder @@ -20,7 +20,7 @@ json.competitions do if section json.current_stage do - json.name = section.competition_stage.name + json.name section.competition_stage.name json.start_time section.display_start_time json.end_time section.display_end_time end diff --git a/app/views/courses/mine.json.jbuilder b/app/views/courses/mine.json.jbuilder index 41368d883..fc6a5becc 100644 --- a/app/views/courses/mine.json.jbuilder +++ b/app/views/courses/mine.json.jbuilder @@ -1,5 +1,6 @@ json.partial! "commons/success" -json.data do - json.array! @courses, :id, :name, :updated_at, :created_at, :end_date +json.data @courses do |course| + json.(course, :id, :name, :updated_at, :end_date) + json.created_at course.created_at.strftime("%Y-%m-%d") end diff --git a/config/routes.rb b/config/routes.rb index 32725e8e9..f6f8db066 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -980,6 +980,8 @@ Rails.application.routes.draw do resource :laboratory_setting, only: [:show, :update] resource :laboratory_user, only: [:create, :destroy] end + + resources :competitions, only: [:index, :destroy] end resources :colleges, only: [] do diff --git a/db/migrate/20191015013924_add_new_column_to_competitions.rb b/db/migrate/20191015013924_add_new_column_to_competitions.rb new file mode 100644 index 000000000..616a46059 --- /dev/null +++ b/db/migrate/20191015013924_add_new_column_to_competitions.rb @@ -0,0 +1,6 @@ +class AddNewColumnToCompetitions < ActiveRecord::Migration[5.2] + def change + add_column :competitions, :bonus, :integer, default: 0 + add_column :competitions, :mode, :integer, default: 0 + end +end diff --git a/db/migrate/20191015015723_create_competition_mode_settings.rb b/db/migrate/20191015015723_create_competition_mode_settings.rb new file mode 100644 index 000000000..5d170eeab --- /dev/null +++ b/db/migrate/20191015015723_create_competition_mode_settings.rb @@ -0,0 +1,11 @@ +class CreateCompetitionModeSettings < ActiveRecord::Migration[5.2] + def change + create_table :competition_mode_settings do |t| + t.references :course + t.datetime :start_time + t.datetime :end_time + + t.timestamps + end + end +end diff --git a/spec/models/competition_mode_setting_spec.rb b/spec/models/competition_mode_setting_spec.rb new file mode 100644 index 000000000..535767880 --- /dev/null +++ b/spec/models/competition_mode_setting_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CompetitionModeSetting, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end