Browse Source

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

tags/v3.1.5^2^2
jasder 4 years ago
parent
commit
cb1d77ee6d
37 changed files with 546 additions and 5 deletions
  1. +2
    -2
      app/assets/javascripts/admins/courses/index.js
  2. +76
    -0
      app/assets/javascripts/admins/reversed_keywords/index.js
  3. +10
    -2
      app/assets/javascripts/admins/shixun_settings/index.js
  4. +1
    -0
      app/controllers/accounts_controller.rb
  5. +84
    -0
      app/controllers/admins/reversed_keywords_controller.rb
  6. +1
    -0
      app/controllers/organizations/organizations_controller.rb
  7. +2
    -0
      app/controllers/projects_controller.rb
  8. +26
    -0
      app/models/reversed_keyword.rb
  9. +32
    -0
      app/views/admins/reversed_keywords/_form_modal.html.erb
  10. +37
    -0
      app/views/admins/reversed_keywords/_list.html.erb
  11. +2
    -0
      app/views/admins/reversed_keywords/edit.js.erb
  12. +18
    -0
      app/views/admins/reversed_keywords/index.html.erb
  13. +1
    -0
      app/views/admins/reversed_keywords/index.js.erb
  14. +2
    -0
      app/views/admins/reversed_keywords/new.js.erb
  15. +1
    -0
      app/views/admins/shared/_sidebar.html.erb
  16. +1
    -0
      config/routes.rb
  17. +11
    -0
      db/migrate/20210831014412_create_reversed_keywords.rb
  18. +1
    -1
      public/assets/.sprockets-manifest-7657344e1d61e579de6a996a4498d7a2.json
  19. +36
    -0
      public/assets/admin-719988f975840fa3b187ef2594aecb8494218f82342377a1f3c71731f68fbf61.css
  20. BIN
      public/assets/admin-719988f975840fa3b187ef2594aecb8494218f82342377a1f3c71731f68fbf61.css.gz
  21. +49
    -0
      public/assets/admin-b2526c7eefd8212cde88c53131e8a7dd02f4d96e6d9e262d31dbca516addc979.js
  22. BIN
      public/assets/admin-b2526c7eefd8212cde88c53131e8a7dd02f4d96e6d9e262d31dbca516addc979.js.gz
  23. +6
    -0
      public/assets/application-346b678500708f3f4e9cd72c46d1e9e54aaf76e0478b766519ac083bf93fbcff.css
  24. BIN
      public/assets/application-346b678500708f3f4e9cd72c46d1e9e54aaf76e0478b766519ac083bf93fbcff.css.gz
  25. +16
    -0
      public/assets/application-860dba70259cdc6c5c72c499f8be717c050d517f1fd6a1543c0b6863af987000.js
  26. BIN
      public/assets/application-860dba70259cdc6c5c72c499f8be717c050d517f1fd6a1543c0b6863af987000.js.gz
  27. +34
    -0
      public/assets/college-bd7fb1ab1da64733a0172f89c8b9d5cfe4db736bb3ee51e0ca0701b40e2e49cc.js
  28. BIN
      public/assets/college-bd7fb1ab1da64733a0172f89c8b9d5cfe4db736bb3ee51e0ca0701b40e2e49cc.js.gz
  29. +9
    -0
      public/assets/college-fe5b44c2d2fe8fcd24143a2cb9df8254be9104d3fe4e3da0f3e3317838a16ebc.css
  30. BIN
      public/assets/college-fe5b44c2d2fe8fcd24143a2cb9df8254be9104d3fe4e3da0f3e3317838a16ebc.css.gz
  31. +46
    -0
      public/assets/cooperative-1f8e268f2c629e3453e71d3ad4bc2c043e73989a8804598ad807c4050ee3c346.js
  32. BIN
      public/assets/cooperative-1f8e268f2c629e3453e71d3ad4bc2c043e73989a8804598ad807c4050ee3c346.js.gz
  33. +36
    -0
      public/assets/cooperative-cf4adc259ee46508f0fba0ccaa4f2c3beb33dbb715cc354ec30fbb7db729ca77.css
  34. BIN
      public/assets/cooperative-cf4adc259ee46508f0fba0ccaa4f2c3beb33dbb715cc354ec30fbb7db729ca77.css.gz
  35. +1
    -0
      public/assets/oauth-79ad9eb7fd1c8cc81aed569f2c933d0bbd5a823dc450a1038c034eef2a7b6b9c.css
  36. BIN
      public/assets/oauth-79ad9eb7fd1c8cc81aed569f2c933d0bbd5a823dc450a1038c034eef2a7b6b9c.css.gz
  37. +5
    -0
      spec/models/reversed_keyword_spec.rb

+ 2
- 2
app/assets/javascripts/admins/courses/index.js 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');


+ 76
- 0
app/assets/javascripts/admins/reversed_keywords/index.js 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("√")
}
});
}
})
});
})

+ 10
- 2
app/assets/javascripts/admins/shixun_settings/index.js 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');


+ 1
- 0
app/controllers/accounts_controller.rb 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+/, "")


+ 84
- 0
app/controllers/admins/reversed_keywords_controller.rb 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

+ 1
- 0
app/controllers/organizations/organizations_controller.rb 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?


+ 2
- 0
app/controllers/projects_controller.rb 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 =


+ 26
- 0
app/models/reversed_keyword.rb 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

+ 32
- 0
app/views/admins/reversed_keywords/_form_modal.html.erb 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>

+ 37
- 0
app/views/admins/reversed_keywords/_list.html.erb 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 } %>

+ 2
- 0
app/views/admins/reversed_keywords/edit.js.erb 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');

+ 18
- 0
app/views/admins/reversed_keywords/index.html.erb 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>

+ 1
- 0
app/views/admins/reversed_keywords/index.js.erb View File

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

+ 2
- 0
app/views/admins/reversed_keywords/new.js.erb 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');

+ 1
- 0
app/views/admins/shared/_sidebar.html.erb 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>



+ 1
- 0
config/routes.rb 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


+ 11
- 0
db/migrate/20210831014412_create_reversed_keywords.rb 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

+ 1
- 1
public/assets/.sprockets-manifest-7657344e1d61e579de6a996a4498d7a2.json
File diff suppressed because it is too large
View File


+ 36
- 0
public/assets/admin-719988f975840fa3b187ef2594aecb8494218f82342377a1f3c71731f68fbf61.css
File diff suppressed because it is too large
View File


BIN
public/assets/admin-719988f975840fa3b187ef2594aecb8494218f82342377a1f3c71731f68fbf61.css.gz View File


+ 49
- 0
public/assets/admin-b2526c7eefd8212cde88c53131e8a7dd02f4d96e6d9e262d31dbca516addc979.js
File diff suppressed because it is too large
View File


BIN
public/assets/admin-b2526c7eefd8212cde88c53131e8a7dd02f4d96e6d9e262d31dbca516addc979.js.gz View File


+ 6
- 0
public/assets/application-346b678500708f3f4e9cd72c46d1e9e54aaf76e0478b766519ac083bf93fbcff.css
File diff suppressed because it is too large
View File


BIN
public/assets/application-346b678500708f3f4e9cd72c46d1e9e54aaf76e0478b766519ac083bf93fbcff.css.gz View File


+ 16
- 0
public/assets/application-860dba70259cdc6c5c72c499f8be717c050d517f1fd6a1543c0b6863af987000.js
File diff suppressed because it is too large
View File


BIN
public/assets/application-860dba70259cdc6c5c72c499f8be717c050d517f1fd6a1543c0b6863af987000.js.gz View File


+ 34
- 0
public/assets/college-bd7fb1ab1da64733a0172f89c8b9d5cfe4db736bb3ee51e0ca0701b40e2e49cc.js
File diff suppressed because it is too large
View File


BIN
public/assets/college-bd7fb1ab1da64733a0172f89c8b9d5cfe4db736bb3ee51e0ca0701b40e2e49cc.js.gz View File


+ 9
- 0
public/assets/college-fe5b44c2d2fe8fcd24143a2cb9df8254be9104d3fe4e3da0f3e3317838a16ebc.css
File diff suppressed because it is too large
View File


BIN
public/assets/college-fe5b44c2d2fe8fcd24143a2cb9df8254be9104d3fe4e3da0f3e3317838a16ebc.css.gz View File


+ 46
- 0
public/assets/cooperative-1f8e268f2c629e3453e71d3ad4bc2c043e73989a8804598ad807c4050ee3c346.js
File diff suppressed because it is too large
View File


BIN
public/assets/cooperative-1f8e268f2c629e3453e71d3ad4bc2c043e73989a8804598ad807c4050ee3c346.js.gz View File


+ 36
- 0
public/assets/cooperative-cf4adc259ee46508f0fba0ccaa4f2c3beb33dbb715cc354ec30fbb7db729ca77.css
File diff suppressed because it is too large
View File


BIN
public/assets/cooperative-cf4adc259ee46508f0fba0ccaa4f2c3beb33dbb715cc354ec30fbb7db729ca77.css.gz View File


+ 1
- 0
public/assets/oauth-79ad9eb7fd1c8cc81aed569f2c933d0bbd5a823dc450a1038c034eef2a7b6b9c.css 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}

BIN
public/assets/oauth-79ad9eb7fd1c8cc81aed569f2c933d0bbd5a823dc450a1038c034eef2a7b6b9c.css.gz View File


+ 5
- 0
spec/models/reversed_keyword_spec.rb View File

@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe ReversedKeyword, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

Loading…
Cancel
Save