Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into courseware
	
		
	
				
					
				
			
						commit
						486cb8a25c
					
				| @ -0,0 +1,82 @@ | |||||||
|  | $(document).on('turbolinks:load', function() { | ||||||
|  |   if ($('body.admins-upgrade-notices-index-page').length > 0) { | ||||||
|  |     window.upgradeNoticeForm = function(clazz) { | ||||||
|  |       var $modal = $('.modal.admin-' + clazz + '-upgrade-notice-modal'); | ||||||
|  |       var $form = $modal.find('form.admin-' + clazz + '-upgrade-notice-form'); | ||||||
|  | 
 | ||||||
|  |       $form.validate({ | ||||||
|  |         errorElement: 'span', | ||||||
|  |         errorClass: 'danger text-danger', | ||||||
|  |         rules: { | ||||||
|  |           'upgrade_notice[title]': { | ||||||
|  |             required: true | ||||||
|  |           }, | ||||||
|  |           'upgrade_notice[content]': { | ||||||
|  |             required: true | ||||||
|  |           }, | ||||||
|  |           'upgrade_notice[start_at]': { | ||||||
|  |             required: true | ||||||
|  |           }, | ||||||
|  |           'upgrade_notice[end_at]': { | ||||||
|  |             required: true | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       }); | ||||||
|  | 
 | ||||||
|  |       $modal.on('click', '.submit-btn', function() { | ||||||
|  |         $form.find('.error').html(''); | ||||||
|  |         console.log('url', $form.data('url'), $form) | ||||||
|  | 
 | ||||||
|  |         if ($form.valid()) { | ||||||
|  |           var url = $form.attr('action'); | ||||||
|  |           var newDate = new Date(); | ||||||
|  |           var begin_time = Date.parse($('.' + clazz +'_start_at').val()); | ||||||
|  |           var end_time = Date.parse($('.' + clazz +'_end_at').val()); | ||||||
|  |           if (begin_time < newDate) { | ||||||
|  |             $('.' + clazz +'_end_at').addClass('danger text-danger'); | ||||||
|  |             $form.find('.error').html('开始时间应大于当前时间'); | ||||||
|  |             return false | ||||||
|  |           } else if (end_time < newDate) { | ||||||
|  |             $form.find('.error').html('结束时间应大于当前时间'); | ||||||
|  |             $('.' + clazz +'_end_at').addClass('danger text-danger'); | ||||||
|  |             return false | ||||||
|  |           } else if (end_time < begin_time) { | ||||||
|  |             $form.find('.error').html('结束时间应大于开始时间'); | ||||||
|  |             $('.' + clazz +'_end_at').addClass('danger text-danger'); | ||||||
|  |             return false | ||||||
|  |           } | ||||||
|  | 
 | ||||||
|  |           $.ajax({ | ||||||
|  |             method: clazz == 'create' ? 'POST' : 'PUT', | ||||||
|  |             dataType: 'json', | ||||||
|  |             url: url, | ||||||
|  |             data: $form.serialize(), | ||||||
|  |             success: function() { | ||||||
|  |               $.notify({ message: '创建成功' }); | ||||||
|  |               $modal.modal('hide'); | ||||||
|  | 
 | ||||||
|  |               setTimeout(function() { | ||||||
|  |                 window.location.reload(); | ||||||
|  |               }, 500); | ||||||
|  |             }, | ||||||
|  |             error: function(res) { | ||||||
|  |               var data = res.responseJSON; | ||||||
|  |               $form.find('.error').html(data.message); | ||||||
|  |             } | ||||||
|  |           }); | ||||||
|  |         } | ||||||
|  |       }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     var timeOptions = { | ||||||
|  |       autoclose: 1, | ||||||
|  |       language: 'zh-CN', | ||||||
|  |       format: 'yyyy-mm-dd hh:ii', | ||||||
|  |       minuteStep: 10 | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     $(".create_start_at").datetimepicker(timeOptions) | ||||||
|  |     $(".create_end_at").datetimepicker(timeOptions) | ||||||
|  |     upgradeNoticeForm("create"); | ||||||
|  |   } | ||||||
|  | }); | ||||||
| @ -0,0 +1,2 @@ | |||||||
|  | class UpgradeNotice < ApplicationRecord | ||||||
|  | end | ||||||
| @ -0,0 +1,2 @@ | |||||||
|  | $.notify({ message: '删除成功' }); | ||||||
|  | $(".upgrade-notice-item-<%= @upgrade_notice.id %>").remove(); | ||||||
| @ -0,0 +1,14 @@ | |||||||
|  | $('.admin-modal-container').html("<%= j( render partial: 'admins/upgrade_notices/shared/edit_upgrade_notice_modal', locals: { upgrade_notice: @upgrade_notice } ) %>"); | ||||||
|  | $('.modal.admin-edit-upgrade-notice-modal').modal('show'); | ||||||
|  | 
 | ||||||
|  | var timeOptions = { | ||||||
|  |   autoclose: 1, | ||||||
|  |   language: 'zh-CN', | ||||||
|  |   format: 'yyyy-mm-dd hh:ii', | ||||||
|  |   minuteStep: 10 | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | $(".edit_start_at").datetimepicker(timeOptions) | ||||||
|  | $(".edit_end_at").datetimepicker(timeOptions) | ||||||
|  | 
 | ||||||
|  | upgradeNoticeForm("edit"); | ||||||
| @ -0,0 +1,15 @@ | |||||||
|  | <% define_admin_breadcrumbs do %> | ||||||
|  |   <% add_admin_breadcrumb('系统升级提醒', admins_upgrade_notices_path) %> | ||||||
|  | <% end %> | ||||||
|  | 
 | ||||||
|  | <div class="box search-form-container upgrade-notice-list-form rig"> | ||||||
|  |   <div class="flex-1"> | ||||||
|  |     <%= javascript_void_link '新增', class: 'btn btn-primary', data: { toggle: 'modal', target: '.admin-create-upgrade-notice-modal' } %> | ||||||
|  |   </div> | ||||||
|  | </div> | ||||||
|  | 
 | ||||||
|  | <div class="box admin-list-container admin-upgrade-notices-list-container"> | ||||||
|  |   <%= render(partial: 'admins/upgrade_notices/shared/list') %> | ||||||
|  | </div> | ||||||
|  | 
 | ||||||
|  | <%= render partial: 'admins/upgrade_notices/shared/create_upgrade_notice_modal', locals: {upgrade_notice: @upgrade_notice} %> | ||||||
| @ -0,0 +1 @@ | |||||||
|  | $(".admin-upgrade-notices-list-container").html("<%= j render partial: "admins/upgrade_notices/shared/list",locals: {upgrade_notices: @upgrade_notices} %>") | ||||||
| @ -0,0 +1,26 @@ | |||||||
|  | <div class="modal fade admin-create-upgrade-notice-modal" tabindex="-1" role="dialog" aria-hidden="true"> | ||||||
|  |   <div class="modal-dialog modal-dialog-centered" role="document"> | ||||||
|  |     <div class="modal-content"> | ||||||
|  |       <div class="modal-header"> | ||||||
|  |         <h5 class="modal-title">新增系统升级提醒</h5> | ||||||
|  |         <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||||||
|  |           <span aria-hidden="true">×</span> | ||||||
|  |         </button> | ||||||
|  |       </div> | ||||||
|  |       <div class="modal-body"> | ||||||
|  |         <%= simple_form_for(upgrade_notice, url: admins_upgrade_notices_path, html: { class: 'admin-create-upgrade-notice-form' }, defaults: { wrapper_html: { class: 'offset-md-1 col-md-10' } }) do |f| %> | ||||||
|  |           <%= f.input :title, as: :string, label: '标题' %> | ||||||
|  |           <%= f.input :content, label: '详情', input_html: {rows: 10} %> | ||||||
|  |           <%= f.input :start_at,as: :string, label: '开始时间', input_html: { class: 'create_start_at' } %> | ||||||
|  |           <%= f.input :end_at, as: :string, label: '结束时间', input_html: { class: 'create_end_at' } %> | ||||||
|  | 
 | ||||||
|  |           <div class="error text-danger"></div> | ||||||
|  |         <% end %> | ||||||
|  |       </div> | ||||||
|  |       <div class="modal-footer"> | ||||||
|  |         <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button> | ||||||
|  |         <button type="button" class="btn btn-primary submit-btn">确认</button> | ||||||
|  |       </div> | ||||||
|  |     </div> | ||||||
|  |   </div> | ||||||
|  | </div> | ||||||
| @ -0,0 +1,25 @@ | |||||||
|  | <div class="modal fade admin-edit-upgrade-notice-modal" tabindex="-1" role="dialog" aria-hidden="true"> | ||||||
|  |   <div class="modal-dialog modal-dialog-centered" role="document"> | ||||||
|  |     <div class="modal-content"> | ||||||
|  |       <div class="modal-header"> | ||||||
|  |         <h5 class="modal-title">编辑系统升级提醒</h5> | ||||||
|  |         <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||||||
|  |           <span aria-hidden="true">×</span> | ||||||
|  |         </button> | ||||||
|  |       </div> | ||||||
|  |       <div class="modal-body"> | ||||||
|  |         <%= simple_form_for(upgrade_notice, url: admins_upgrade_notice_path(upgrade_notice), html: { class: 'admin-edit-upgrade-notice-form' }, defaults: { wrapper_html: { class: 'offset-md-1 col-md-10' } }) do |f| %> | ||||||
|  |           <%= f.input :title, as: :string, label: '标题' %> | ||||||
|  |           <%= f.input :content, label: '详情', input_html: {rows: 10} %> | ||||||
|  |           <%= f.input :start_at,as: :string, label: '开始时间', input_html: { class: 'edit_start_at' } %> | ||||||
|  |           <%= f.input :end_at, as: :string, label: '结束时间', input_html: { class: 'edit_end_at' } %> | ||||||
|  |           <div class="error text-danger"></div> | ||||||
|  |         <% end %> | ||||||
|  |       </div> | ||||||
|  |       <div class="modal-footer"> | ||||||
|  |         <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button> | ||||||
|  |         <button type="button" class="btn btn-primary submit-btn">确认</button> | ||||||
|  |       </div> | ||||||
|  |     </div> | ||||||
|  |   </div> | ||||||
|  | </div> | ||||||
| @ -0,0 +1,49 @@ | |||||||
|  | <table class="table table-hover text-center admin-upgrade-notices-list-table"> | ||||||
|  |   <thead class="thead-light"> | ||||||
|  |   <tr> | ||||||
|  |     <th width="6%">序号</th> | ||||||
|  |     <th width="10%" class="text-left">标题</th> | ||||||
|  |     <th width="30%" class="text-left">详情</th> | ||||||
|  |     <th width="10%" class="text-left">开始时间</th> | ||||||
|  |     <th width="10%" class="text-left">结束时间</th> | ||||||
|  |     <th width="10%" class="text-left"><%= sort_tag('创建时间', name: 'created_at', path: admins_upgrade_notices_path) %></th> | ||||||
|  |     <th width="10%" class="text-left">更新时间</th> | ||||||
|  |     <th width="16%">操作</th> | ||||||
|  |   </tr> | ||||||
|  |   </thead> | ||||||
|  |   <tbody> | ||||||
|  |   <% if @upgrade_notices.present? %> | ||||||
|  |     <% @upgrade_notices.each_with_index do |notice, index| %> | ||||||
|  |       <tr class="upgrade-notice-item-<%= notice.id %>"> | ||||||
|  |         <td><%= index + 1 %></td> | ||||||
|  |         <td class="text-left"> | ||||||
|  |           <%= notice.title %> | ||||||
|  |         </td> | ||||||
|  |         <td class="text-left"> | ||||||
|  |           <%= notice.content %> | ||||||
|  |         </td> | ||||||
|  |         <td class="text-left"> | ||||||
|  |           <%= notice.start_at.to_s %> | ||||||
|  |         </td> | ||||||
|  |         <td class="text-left"> | ||||||
|  |           <%= notice.end_at.to_s %> | ||||||
|  |         </td> | ||||||
|  |         <td class="text-left"> | ||||||
|  |           <%= notice.created_at.to_s %> | ||||||
|  |         </td> | ||||||
|  |         <td class="text-left"> | ||||||
|  |           <%= notice.updated_at.to_s %> | ||||||
|  |         </td> | ||||||
|  |         <td> | ||||||
|  |           <%= link_to '编辑', edit_admins_upgrade_notice_path(notice), remote: true, class: 'edit-action' %> | ||||||
|  |           <%= delete_link '删除', admins_upgrade_notice_path(notice, element: ".upgrade-notice-item-#{notice.id}"), class: 'delete-upgrade-notice-action' %> | ||||||
|  |         </td> | ||||||
|  |       </tr> | ||||||
|  |     <% end %> | ||||||
|  |   <% else %> | ||||||
|  |     <%= render 'admins/shared/no_data_for_table' %> | ||||||
|  |   <% end %> | ||||||
|  |   </tbody> | ||||||
|  | </table> | ||||||
|  | 
 | ||||||
|  | <%= render partial: 'admins/shared/paginate', locals: { objects: @upgrade_notices } %> | ||||||
| @ -1,6 +1,6 @@ | |||||||
| json.course_groups @course_groups do |group| | json.course_groups @course_groups do |group| | ||||||
|   json.id group.id |   json.id group.id | ||||||
|   json.name group.name |   json.name group.name | ||||||
|   json.end_time @group_settings.select{|group_setting| group_setting.course_group_id == group.id}.first&.end_time |   json.end_time @exercise.unified_setting ? @exercise.end_time : @group_settings.select{|group_setting| group_setting.course_group_id == group.id}.first&.end_time | ||||||
| end | end | ||||||
| json.end_time @exercise.end_time | json.end_time @exercise.end_time | ||||||
| @ -1,6 +1,6 @@ | |||||||
| json.course_groups @course_groups do |group| | json.course_groups @course_groups do |group| | ||||||
|   json.id group.id |   json.id group.id | ||||||
|   json.name group.name |   json.name group.name | ||||||
|   json.end_time @group_settings.select{|group_setting| group_setting.course_group_id == group.id}.first&.end_time |   json.end_time @poll.unified_setting ? @poll.end_time : @group_settings.select{|group_setting| group_setting.course_group_id == group.id}.first&.end_time | ||||||
| end | end | ||||||
| json.end_time @poll.end_time | json.end_time @poll.end_time | ||||||
| @ -0,0 +1,28 @@ | |||||||
|  | Time::DATE_FORMATS[:db2] = '%Y-%m-%d %H:%M:%S' | ||||||
|  | 
 | ||||||
|  | Time::DATE_FORMATS[:default] = ->(time){ | ||||||
|  |   Time.zone = 'Beijing' | ||||||
|  |   t = Time.zone.at time | ||||||
|  |   t.strftime '%Y-%m-%d %H:%M:%S' | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | Time::DATE_FORMATS[:sh] = ->(time){ | ||||||
|  |   t = Time.zone.at time | ||||||
|  |   t.strftime '%y-%m-%d %H:%M:%S' | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | Time::DATE_FORMATS[:date] = ->(time){ | ||||||
|  |   t = Time.zone.at time | ||||||
|  |   t.strftime '%Y-%m-%d' | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | Time::DATE_FORMATS[:h] = ->(time){ | ||||||
|  |   t = Time.zone.at time | ||||||
|  |   t.strftime '%H:%M' | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | Time::DATE_FORMATS[:datetime] = '%Y-%m-%d %H:%M' | ||||||
|  | 
 | ||||||
|  | Date::DATE_FORMATS[:date] = ->(date){ | ||||||
|  |   date.strftime '%Y-%m-%d' | ||||||
|  | } | ||||||
| @ -0,0 +1,12 @@ | |||||||
|  | class CreateUpgradeNotices < ActiveRecord::Migration[5.2] | ||||||
|  |   def change | ||||||
|  |     create_table :upgrade_notices do |t| | ||||||
|  |       t.string :title | ||||||
|  |       t.text :content | ||||||
|  |       t.datetime :start_at | ||||||
|  |       t.datetime :end_at | ||||||
|  | 
 | ||||||
|  |       t.timestamps | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  | end | ||||||
					Loading…
					
					
				
		Reference in new issue