添加后台系统升级提醒

dev_aliyun2
anke1460 5 years ago
parent a2cafe7bda
commit f21af5046e

@ -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,54 @@
class Admins::UpgradeNoticesController < Admins::BaseController
def index
params[:sort_by] ||= 'created_at'
params[:sort_direction] ||= 'desc'
@upgrade_notice = UpgradeNotice.new(
content: '201852200:00
201852210:00
便',
title: 'educoder系统升级暂停服务通知')
@upgrade_notices = UpgradeNotice.order("created_at #{params[:sort_direction]}")
@upgrade_notices = paginate @upgrade_notices
end
def create
upgrade_notice = UpgradeNotice.new(upgrade_notice_params)
if upgrade_notice.save
render_ok
else
render_error upgrade_notice.error.full_messages.join(",")
end
end
def destroy
check_upgrade_notice
@upgrade_notice.destroy
end
def edit
check_upgrade_notice
end
def update
check_upgrade_notice
if @upgrade_notice.update(upgrade_notice_params)
render_ok
else
render_error @upgrade_notice.error.full_messages.join(",")
end
end
private
def upgrade_notice_params
params.require(:upgrade_notice).permit(:title, :content, :start_at, :end_at)
end
def check_upgrade_notice
@upgrade_notice = UpgradeNotice.find(params[:id])
end
end

@ -0,0 +1,2 @@
class UpgradeNotice < ApplicationRecord
end

@ -86,7 +86,8 @@
<li>
<%= sidebar_item_group('#comments-submenu', '消息', icon: 'comments') do %>
<li><%= sidebar_item(admins_shixun_feedback_messages_path, '实训反馈', icon: 'comment', controller: 'admins-shixun_feedback_messages') %></li>
<% end %>
<li><%= sidebar_item(admins_upgrade_notices_path, '系统升级提醒', icon: 'envelope-open', controller: 'admins-upgrade_notices') %></li>
<% end %>
</li>
<li>

@ -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">&times;</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">&times;</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 } %>

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

@ -31,6 +31,7 @@ Rails.application.routes.draw do
resources :watch_video_histories, only: [:create]
resources :jupyters do
collection do
get :save_with_tpi
@ -1136,6 +1137,7 @@ Rails.application.routes.draw do
namespace :admins do
get '/', to: 'dashboards#index'
resources :upgrade_notices
resources :major_informations, only: [:index]
resources :ec_templates, only: [:index, :destroy] do
collection do

@ -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…
Cancel
Save