diff --git a/app/assets/javascripts/admins/competition_settings/index.js b/app/assets/javascripts/admins/competition_settings/index.js new file mode 100644 index 000000000..f02f845c4 --- /dev/null +++ b/app/assets/javascripts/admins/competition_settings/index.js @@ -0,0 +1,23 @@ +$(document).on('turbolinks:load', function(){ + if ($('body.admins-competition-settings-index-page').length > 0) { + + var baseOptions = { + autoclose: true, + language: 'zh-CN', + format: 'yyyy-mm-dd', + startDate: '2017-04-01', + endDate: '-1d' + }; + + var defineDateRangeSelect = function(element){ + var options = $.extend({inputs: $(element).find('.start-date, .end-date')}, baseOptions); + $(element).datepicker(options); + + $(element).find('.start-date').datepicker().on('changeDate', function(e){ + $(element).find('.end-date').datepicker('setStartDate', e.date); + }); + }; + + defineDateRangeSelect('.teaching-mode-date'); + } +}); \ No newline at end of file diff --git a/app/assets/stylesheets/admins/competition_settings.scss b/app/assets/stylesheets/admins/competition_settings.scss new file mode 100644 index 000000000..20468aaed --- /dev/null +++ b/app/assets/stylesheets/admins/competition_settings.scss @@ -0,0 +1,21 @@ +.admins-competition-settings-index-page { + .competition-mode-container { + .row { + height: 35px; + } + + .des-row { + height: auto; + } + + .form-control { + font-size: 14px; + } + + //.mode-input { + // input { + // width: 40%; + // } + //} + } +} \ No newline at end of file diff --git a/app/models/competition.rb b/app/models/competition.rb index 8b9d59ed2..708af2556 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -28,9 +28,9 @@ class Competition < ApplicationRecord def mode_type case mode when 1 - "课堂" - when 2 "实训" + when 2 + "课堂" when 3 "教学" when 4 @@ -94,9 +94,9 @@ class Competition < ApplicationRecord GROUP BY competition_stage_id order by competition_stage_id") end - def awards_count - competition_awards.pluck(:num)&.sum > 0 ? competition_awards.pluck(:num)&.sum : 20 - end + # def awards_count + # competition_awards.pluck(:num)&.sum > 0 ? competition_awards.pluck(:num)&.sum : 20 + # end private diff --git a/app/views/admins/competition_settings/index.html.erb b/app/views/admins/competition_settings/index.html.erb index 4f53cb5d3..4c73609e4 100644 --- a/app/views/admins/competition_settings/index.html.erb +++ b/app/views/admins/competition_settings/index.html.erb @@ -10,9 +10,110 @@ 基础设置
-
+ <%= form_tag(admins_competition_competition_settings_path(unsafe_params), method: :post, class: 'basic-setting-form flex-1', remote: true) do %> +
+
+
+ 竞赛模式 +
+
+ <%= radio_button_tag(:mode, 1, @competition.mode == 1, class: 'form-radio-input') %> + +
+
-
+
+
+
+
+ <%= radio_button_tag(:mode, 2, @competition.mode == 2, class: 'form-radio-input') %> + +
+
+ <%= text_field_tag(:course_id, @competition.competition_mode_setting&.course_id, autocomplete: 'off', class: 'form-control', placeholder: '课堂id') %> +
+
+ +
+
+
+
+ <%= radio_button_tag(:mode, 3, @competition.mode == 3, class: 'form-radio-input') %> + +
+
+ <%= text_field_tag :start_time, @competition.competition_mode_setting&.start_time, autocomplete: 'off', class: 'form-control start-date mx-0 mr-2', placeholder: '统计数据的开始时间' %> + <%= text_field_tag :end_time, @competition.competition_mode_setting&.end_time, autocomplete: 'off', class: 'form-control end-date mx-0', placeholder: '统计数据的结束时间' %> +
+
+ +
+
+
+
+ <%= radio_button_tag(:mode, 4, @competition.mode == 4, class: 'form-radio-input') %> + +
+
+ +
+
+ URL +
+
+ <%= text_field_tag(:identifier, @competition.identifier, autocomplete: 'off', class: 'form-control', placeholder: '请输入url赛事网址') %> +
+
+ +
+
+ 主办方 +
+
+ +
+
+ +
+
+ 奖金 +
+
+
+
¥
+
+ <%= number_field_tag(:bonus, @competition.bonus, autocomplete: 'off', step: 1, min: 0, class: 'form-control', placeholder: '请输入总奖金额') %> +
+
+ +
+
+ 获奖人数 +
+
+ <%= number_field_tag(:bonus, @competition.bonus, autocomplete: 'off', step: 1, min: 0, class: 'form-control', placeholder: '请输入总奖金额') %> +
+
+ +
+
+ 描述 +
+
+ <%= text_area_tag(:description, @competition.description, class: 'form-control', placeholder: '请输入赛事简介') %> +
+
+ +
+
+
+
+ <%= javascript_void_link '保存', class: 'btn btn-primary submit-btn' %> +
+
+
+ + <% end %>
diff --git a/db/migrate/20191022075223_migrate_competition_mode_default.rb b/db/migrate/20191022075223_migrate_competition_mode_default.rb new file mode 100644 index 000000000..d61d4aa68 --- /dev/null +++ b/db/migrate/20191022075223_migrate_competition_mode_default.rb @@ -0,0 +1,6 @@ +class MigrateCompetitionModeDefault < ActiveRecord::Migration[5.2] + def change + change_column_default :competitions, :mode, from: 0, to: 1 + Competition.all.update_all(mode: 1) + end +end diff --git a/db/migrate/20191022100044_add_awards_count_to_competition.rb b/db/migrate/20191022100044_add_awards_count_to_competition.rb new file mode 100644 index 000000000..ef6657ae6 --- /dev/null +++ b/db/migrate/20191022100044_add_awards_count_to_competition.rb @@ -0,0 +1,5 @@ +class AddAwardsCountToCompetition < ActiveRecord::Migration[5.2] + def change + add_column :competitions, :awards_count, :integer, default: 0 + end +end