Merge pull request '系统保留关键词模块' (#137) from yystopf/forgeplus:hh_reversed_keyword into develop

This commit is contained in:
jasder 2021-09-03 17:52:48 +08:00
commit cb1d77ee6d
37 changed files with 546 additions and 5 deletions

View File

@ -1,7 +1,7 @@
$(document).on('turbolinks:load', function() {
if ($('body.admins-courses-index-page').length > 0) {
let searchContainer = $(".course-list-form");
let searchForm = $("form.search-form",searchContainer);
var searchContainer = $(".course-list-form");
var searchForm = $("form.search-form",searchContainer);
searchContainer.on('change', '.course-homepage-show', function(){
searchForm.find('input[type="submit"]').trigger('click');

View File

@ -0,0 +1,76 @@
/*
* @Description: Do not edit
* @Date: 2021-08-31 11:16:45
* @LastEditors: viletyy
* @Author: viletyy
* @LastEditTime: 2021-08-31 14:19:46
* @FilePath: /forgeplus/app/assets/javascripts/admins/reversed_keywords/index.js
*/
$(document).on('turbolinks:load', function(){
var showSuccessNotify = function() {
$.notify({
message: '操作成功'
},{
type: 'success'
});
}
// close user
$('.reversed-keyword-list-container').on('click', '.close-action', function(){
var $closeAction = $(this);
var $uncloseAction = $closeAction.siblings('.unclose-action');
var keywordID = $closeAction.data('id');
customConfirm({
content: '确认关闭限制吗?',
ok: function(){
$.ajax({
url: '/admins/reversed_keywords/' + keywordID,
method: 'PUT',
dataType: 'json',
data: {
reversed_keyword: {
closed: true
}
},
success: function() {
showSuccessNotify();
$closeAction.hide();
$uncloseAction.show();
$(".reversed-keyword-item-"+keywordID).children('td').eq(3).text("")
}
});
}
});
});
// unclose user
$('.reversed-keyword-list-container').on('click', '.unclose-action', function(){
var $uncloseAction = $(this);
var $closeAction = $uncloseAction.siblings('.close-action');
var keywordID = $uncloseAction.data('id');
customConfirm({
content: '确认开启限制吗?',
ok: function () {
$.ajax({
url: '/admins/reversed_keywords/' + keywordID,
method: 'PUT',
dataType: 'json',
data: {
reversed_keyword: {
closed: false
}
},
success: function() {
showSuccessNotify();
$closeAction.show();
$uncloseAction.hide();
$(".reversed-keyword-item-"+keywordID).children('td').eq(3).text("√")
}
});
}
})
});
})

View File

@ -1,7 +1,15 @@
/*
* @Description: Do not edit
* @Date: 2021-07-16 11:58:16
* @LastEditors: viletyy
* @Author: viletyy
* @LastEditTime: 2021-08-31 14:48:59
* @FilePath: /forgeplus/app/assets/javascripts/admins/shixun_settings/index.js
*/
$(document).on('turbolinks:load', function() {
if ($('body.admins-shixun-settings-index-page').length > 0) {
let searchContainer = $(".shixun-settings-list-form");
let searchForm = $("form.search-form",searchContainer);
var searchContainer = $(".shixun-settings-list-form");
var searchForm = $("form.search-form",searchContainer);
searchContainer.on('change', '.shixun-settings-select', function(){
searchForm.find('input[type="submit"]').trigger('click');

View File

@ -9,6 +9,7 @@ class AccountsController < ApplicationController
# 其他平台同步注册的用户
def remote_register
username = params[:username]&.gsub(/\s+/, "")
tip_exception("无法使用以下关键词:#{username},请重新命名") if ReversedKeyword.is_reversed(username).present?
email = params[:email]&.gsub(/\s+/, "")
password = params[:password]
platform = (params[:platform] || 'forge')&.gsub(/\s+/, "")

View File

@ -0,0 +1,84 @@
class Admins::ReversedKeywordsController < Admins::BaseController
before_action :get_keyword, only: [:edit,:update, :destroy]
# before_action :validate_identifer, only: [:create, :update]
def index
sort_by = ReversedKeyword.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
q = ReversedKeyword.ransack(identifier_cont: params[:search])
keywords = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
@keywords = paginate(keywords)
end
def new
@keyword = ReversedKeyword.new
end
def edit
end
def create
@keyword = ReversedKeyword.new(keyword_params)
if @keyword.save
redirect_to admins_reversed_keywords_path
flash[:success] = '系统保留关键词创建成功'
else
redirect_to admins_reversed_keywords_path
flash[:danger] = @keyword.errors.full_messages.join(",")
end
end
def update
respond_to do |format|
if @keyword.update_attributes(keyword_params)
format.html do
redirect_to admins_reversed_keywords_path
flash[:success] = '系统保留关键词更新成功'
end
format.js {render_ok}
else
format.html do
redirect_to admins_reversed_keywords_path
flash[:danger] = @keyword.errors.full_messages.join(",")
end
format.js {render_js_error}
end
end
end
def destroy
if @keyword.destroy
redirect_to admins_reversed_keywords_path
flash[:success] = "系统保留关键词删除成功"
else
redirect_to admins_reversed_keywords_path
flash[:danger] = "系统保留关键词删除失败"
end
end
private
def keyword_params
params.require(:reversed_keyword).permit!
end
def get_keyword
@keyword = ReversedKeyword.find_by(id: params[:id])
unless @keyword.present?
redirect_to admins_reversed_keywords_path
flash[:danger] = "系统保留关键词不存在"
end
end
def validate_identifer
identifer = keyword_params[:identifier].to_s.downcase
if identifer.blank?
redirect_to admins_reversed_keywords_path
flash[:danger] = '系统保留关键词标识不能为空'
elsif ProjectLanguage.exists?(name: identifer)
redirect_to admins_reversed_keywords_path
flash[:danger] = '系统保留关键词已存在'
end
end
end

View File

@ -26,6 +26,7 @@ class Organizations::OrganizationsController < Organizations::BaseController
def create
ActiveRecord::Base.transaction do
tip_exception("无法使用以下关键词:#{organization_params[:name]},请重新命名") if ReversedKeyword.is_reversed(organization_params[:name]).present?
Organizations::CreateForm.new(organization_params).validate!
@organization = Organizations::CreateService.call(current_user, organization_params)
Util.write_file(@image, avatar_path(@organization)) if params[:image].present?

View File

@ -46,6 +46,7 @@ class ProjectsController < ApplicationController
def create
ActiveRecord::Base.transaction do
tip_exception("无法使用以下关键词:#{project_params[:repository_name]},请重新命名") if ReversedKeyword.is_reversed(project_params[:repository_name]).present?
Projects::CreateForm.new(project_params).validate!
@project = Projects::CreateService.new(current_user, project_params).call
@ -56,6 +57,7 @@ class ProjectsController < ApplicationController
end
def migrate
tip_exception("无法使用以下关键词:#{mirror_params[:repository_name]},请重新命名") if ReversedKeyword.is_reversed(mirror_params[:repository_name]).present?
Projects::MigrateForm.new(mirror_params).validate!
@project =

View File

@ -0,0 +1,26 @@
# == Schema Information
#
# Table name: reversed_keywords
#
# id :integer not null, primary key
# identifier :string(255)
# description :text(65535)
# closed :boolean default("0")
# created_at :datetime not null
# updated_at :datetime not null
#
class ReversedKeyword < ApplicationRecord
scope :is_reversed, -> (identifier){where(identifier: identifier.downcase, closed: false) if identifier.present?}
validates :identifier, presence: true, uniqueness: true
before_validation :set_identifier
private
def set_identifier
self.identifier = self.identifier.downcase
end
end

View File

@ -0,0 +1,32 @@
<div class="modal fade reversed-keyword-change-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"><%= type == "create" ? "新增" : "编辑" %></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<%= form_for @keyword, url: {controller: "reversed_keywords", action: "#{type}"} do |p| %>
<div class="modal-body">
<div class="form-group">
<label>
系统保留关键词标识 <span class="ml10 color-orange mr20">*</span>
</label>
<%= p.text_field :identifier,class: "form-control input-lg",required: true%>
</div>
<div class="form-group">
<label>
系统保留关键词描述
</label>
<%= p.text_area :description,class: "form-control",placeholder: ""%>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
</div>
<% end %>
</div>
</div>
</div>

View File

@ -0,0 +1,37 @@
<table class="table table-hover text-center subject-list-table">
<thead class="thead-light">
<tr>
<th width="5%">序号</th>
<th width="30%"><%= sort_tag('标识', name: 'identifier', path: admins_reversed_keywords_path) %></th>
<th width="20%">描述</th>
<th width="20%"><%= sort_tag('限制是否开启', name: 'closed', path: admins_reversed_keywords_path) %></th>
<th width="20%"><%= sort_tag('创建时间', name: 'created_at', path: admins_reversed_keywords_path) %></th>
<th width="25%">操作</th>
</tr>
</thead>
<tbody>
<% if keywords.present? %>
<% keywords.each_with_index do |keyword, index| %>
<tr class="reversed-keyword-item-<%= keyword.id %>">
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
<td>
<%= link_to(keyword.identifier, "javascript:void(0)") %>
</td>
<td><%= keyword.description %></td>
<td class="keyword_closed"><%= !keyword.closed ? '√' : '' %></td>
<td><%= keyword.created_at&.strftime('%Y-%m-%d %H:%M') %></td>
<td class="action-container">
<%= javascript_void_link '开启限制', class: 'action unclose-action', data: { id: keyword.id }, style: keyword.closed? ? '' : 'display: none;' %>
<%= javascript_void_link '关闭限制', class: 'action close-action', data: { id: keyword.id }, style: keyword.closed? ? 'display: none;' : '' %>
<%= link_to "编辑", edit_admins_reversed_keyword_path(keyword), remote: true, class: "action" %>
<%= link_to "删除", admins_reversed_keyword_path(keyword), method: :delete, data:{confirm: "确认删除的吗?"}, class: "action" %>
</td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: keywords } %>

View File

@ -0,0 +1,2 @@
$("#reversed-keyword-modals").html("<%= j render(partial: 'admins/reversed_keywords/form_modal', locals: {type: 'update'}) %>")
$(".reversed-keyword-change-modal").modal('show');

View File

@ -0,0 +1,18 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('系统保留关键词') %>
<% end %>
<div class="box search-form-container project-list-form">
<%= form_tag(admins_reversed_keywords_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '标识检索') %>
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
<% end %>
<%= link_to "新增", new_admins_reversed_keyword_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %>
</div>
<div class="box admin-list-container reversed-keyword-list-container">
<%= render partial: 'admins/reversed_keywords/list', locals: { keywords: @keywords } %>
</div>
<div id="reversed-keyword-modals">
</div>

View File

@ -0,0 +1 @@
$('.reversed-keyword-list-container').html("<%= j( render partial: 'admins/reversed_keywords/list', locals: { keywords: @keywords } ) %>");

View File

@ -0,0 +1,2 @@
$("#reversed-keyword-modals").html("<%= j render(partial: 'admins/reversed_keywords/form_modal', locals: {type: 'create'}) %>")
$(".reversed-keyword-change-modal").modal('show');

View File

@ -26,6 +26,7 @@
<li><%= sidebar_item(admins_project_categories_path, '分类列表', icon: 'sitemap', controller: 'admins-project_categories') %></li>
<li><%= sidebar_item(admins_project_licenses_path, '开源许可证', icon: 'file-text-o', controller: 'admins-project_licenses') %></li>
<li><%= sidebar_item(admins_project_ignores_path, '忽略文件', icon: 'git', controller: 'admins-project_ignores') %></li>
<li><%= sidebar_item(admins_reversed_keywords_path, '系统保留关键词', icon: 'key', controller: 'admins-reversed_keywords') %></li>
<% end %>
</li>

View File

@ -655,6 +655,7 @@ Rails.application.routes.draw do
resources :project_categories
resources :project_licenses
resources :project_ignores
resources :reversed_keywords
resources :major_informations, only: [:index]
resources :ec_templates, only: [:index, :destroy] do
collection do

View File

@ -0,0 +1,11 @@
class CreateReversedKeywords < ActiveRecord::Migration[5.2]
def change
create_table :reversed_keywords do |t|
t.string :identifier, comment: '保留关键字'
t.text :description, comment: '描述'
t.boolean :closed, default: false, comment: '是否关闭'
t.timestamps
end
end
end

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
html{margin:0px;padding:0px;font-size:14px;font-family:"微软雅黑","宋体"}body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{margin:0;padding:0}.IndexContent{height:100vh;width:100%;position:relative;background-image:url("/images/oauth/backImg.png");background-repeat:no-repeat;background-size:cover;display:-webkit-box;display:flex;-webkit-box-align:center;align-items:center;-webkit-box-pack:center;justify-content:center;-webkit-box-orient:vertical;-webkit-box-direction:normal;flex-direction:column}.indexLogo{width:80px;margin-bottom:35px}.indexPanel{width:580px;min-height:400px;background-color:#fff;box-shadow:0px 2px 10px 5px rgba(0,0,0,0.05);border-radius:5px;box-sizing:border-box}.indexTitle{height:75px;line-height:75px;font-size:18px;color:#333;text-align:center;border-bottom:1px solid #eee}.indexInfo{display:-webkit-box;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;flex-direction:column;-webkit-box-align:start;align-items:flex-start}.indexInfos{padding:40px 60px}.indexInfo>span{color:#333;font-size:16px;margin-top:5px}.indexInfo input{width:100%;height:40px;border-radius:2px;border:1px solid #eee;margin-top:5px;padding:0px 0px 0px 8px;outline:none}.indexInfo .checkInfo{height:15px;color:red}.indexBtn{text-align:center;margin-top:20px}.indexSubmit{width:50%;height:32px;line-height:32px;background-color:#1890FF;border:none;color:#fff;border-radius:2px;cursor:pointer;outline:none}

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ReversedKeyword, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end