forked from Gitlink/forgeplus
add: project explore management
This commit is contained in:
parent
0970a402c8
commit
91852d7957
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* @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/system_notifications/index.js
|
||||
*/
|
||||
$(document).on('turbolinks:load', function(){
|
||||
|
||||
var showSuccessNotify = function() {
|
||||
$.notify({
|
||||
message: '操作成功'
|
||||
},{
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
|
||||
// close user
|
||||
$('.project-list-container').on('click', '.recommend-action', function(){
|
||||
var $closeAction = $(this);
|
||||
var $uncloseAction = $closeAction.siblings('.unrecommend-action');
|
||||
|
||||
var keywordID = $closeAction.data('id');
|
||||
customConfirm({
|
||||
content: '确认将该项目设置为推荐项目吗?',
|
||||
ok: function(){
|
||||
$.ajax({
|
||||
url: '/admins/projects/' + keywordID,
|
||||
method: 'PUT',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
project: {
|
||||
recommend: true,
|
||||
recommend_index: 1
|
||||
}
|
||||
},
|
||||
success: function() {
|
||||
showSuccessNotify();
|
||||
$closeAction.hide();
|
||||
$uncloseAction.show();
|
||||
$(".project-item-"+keywordID).children('td').eq(5).text("√")
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// unclose user
|
||||
$('.project-list-container').on('click', '.unrecommend-action', function(){
|
||||
var $uncloseAction = $(this);
|
||||
var $closeAction = $uncloseAction.siblings('.recommend-action');
|
||||
|
||||
var keywordID = $uncloseAction.data('id');
|
||||
customConfirm({
|
||||
content: '确认取消该推荐项目吗?',
|
||||
ok: function () {
|
||||
$.ajax({
|
||||
url: '/admins/projects/' + keywordID,
|
||||
method: 'PUT',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
project: {
|
||||
recommend: false,
|
||||
recommend: 1
|
||||
}
|
||||
},
|
||||
success: function() {
|
||||
showSuccessNotify();
|
||||
$closeAction.show();
|
||||
$uncloseAction.hide();
|
||||
$(".project-item-"+keywordID).children('td').eq(5).text("")
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
// close user
|
||||
$('.project-list-container').on('click', '.pinned-action', function(){
|
||||
var $closeAction = $(this);
|
||||
var $uncloseAction = $closeAction.siblings('.unpinned-action');
|
||||
|
||||
var keywordID = $closeAction.data('id');
|
||||
customConfirm({
|
||||
content: '确认将该项目设置为精选项目吗?',
|
||||
ok: function(){
|
||||
$.ajax({
|
||||
url: '/admins/projects/' + keywordID,
|
||||
method: 'PUT',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
project: {
|
||||
is_pinned: true,
|
||||
}
|
||||
},
|
||||
success: function() {
|
||||
showSuccessNotify();
|
||||
$closeAction.hide();
|
||||
$uncloseAction.show();
|
||||
$(".project-item-"+keywordID).children('td').eq(4).text("√")
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// unclose user
|
||||
$('.project-list-container').on('click', '.unpinned-action', function(){
|
||||
var $uncloseAction = $(this);
|
||||
var $closeAction = $uncloseAction.siblings('.pinned-action');
|
||||
|
||||
var keywordID = $uncloseAction.data('id');
|
||||
customConfirm({
|
||||
content: '确认取消该精选项目吗?',
|
||||
ok: function () {
|
||||
$.ajax({
|
||||
url: '/admins/projects/' + keywordID,
|
||||
method: 'PUT',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
project: {
|
||||
is_pinned: false,
|
||||
}
|
||||
},
|
||||
success: function() {
|
||||
showSuccessNotify();
|
||||
$closeAction.show();
|
||||
$uncloseAction.hide();
|
||||
$(".project-item-"+keywordID).children('td').eq(4).text("")
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
})
|
|
@ -22,7 +22,7 @@ class Admins::ProjectCategoriesController < Admins::BaseController
|
|||
max_position_items = ProjectCategory.select(:id, :position).pluck(:position).reject!(&:blank?)
|
||||
max_position = max_position_items.present? ? max_position_items.max.to_i : 0
|
||||
|
||||
@project_category = ProjectCategory.new(name: @name,position: max_position)
|
||||
@project_category = ProjectCategory.new(name: @name,position: max_position, pinned_index: params[:project_category][:pinned_index].to_i)
|
||||
if @project_category.save
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:success] = '创建成功'
|
||||
|
@ -33,7 +33,7 @@ class Admins::ProjectCategoriesController < Admins::BaseController
|
|||
end
|
||||
|
||||
def update
|
||||
if @project_category.update_attribute(:name, @name)
|
||||
if @project_category.update_attributes({name: @name, pinned_index: params[:project_category][:pinned_index].to_i})
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:success] = '更新成功'
|
||||
else
|
||||
|
@ -43,7 +43,7 @@ class Admins::ProjectCategoriesController < Admins::BaseController
|
|||
end
|
||||
|
||||
def destroy
|
||||
if @project_language.destroy
|
||||
if @project_category.destroy
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:success] = "删除成功"
|
||||
else
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Admins::ProjectsController < Admins::BaseController
|
||||
before_action :find_project, only: [:edit, :update]
|
||||
|
||||
def index
|
||||
sort_by = Project.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_on'
|
||||
|
@ -8,6 +9,26 @@ class Admins::ProjectsController < Admins::BaseController
|
|||
@projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score)
|
||||
end
|
||||
|
||||
def edit ;end
|
||||
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @project.update_attributes(project_update_params)
|
||||
format.html do
|
||||
redirect_to admins_projects_path
|
||||
flash[:sucess] = "更新成功"
|
||||
end
|
||||
format.js {render_ok}
|
||||
else
|
||||
format.html do
|
||||
redirect_to admins_projects_path
|
||||
flash[:danger] = "更新失败"
|
||||
end
|
||||
format.js {render_js_error}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
project = Project.find_by!(id: params[:id])
|
||||
ActiveRecord::Base.transaction do
|
||||
|
@ -21,4 +42,13 @@ class Admins::ProjectsController < Admins::BaseController
|
|||
redirect_to admins_projects_path
|
||||
flash[:danger] = "删除失败"
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
@project = Project.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def project_update_params
|
||||
params.require(:project).permit(:is_pinned, :recommend, :recommend_index)
|
||||
end
|
||||
end
|
|
@ -130,7 +130,7 @@ class Project < ApplicationRecord
|
|||
has_many :webhooks, class_name: "Gitea::Webhook", primary_key: :gpid, foreign_key: :repo_id
|
||||
after_create :init_project_common, :incre_user_statistic, :incre_platform_statistic
|
||||
after_save :check_project_members, :reset_cache_data
|
||||
before_save :set_invite_code, :reset_unmember_followed
|
||||
before_save :set_invite_code, :reset_unmember_followed, :set_recommend_and_is_pinned
|
||||
before_destroy :decre_project_common
|
||||
after_destroy :decre_user_statistic, :decre_platform_statistic
|
||||
scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :user_id, :forked_count, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)}
|
||||
|
@ -214,6 +214,16 @@ class Project < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def set_recommend_and_is_pinned
|
||||
self.recommend = self.recommend_index.zero? ? false : true
|
||||
# 私有项目不允许设置精选和推荐
|
||||
unless self.is_public
|
||||
self.recommend = false
|
||||
self.recommend_index = 0
|
||||
self.is_pinned = false
|
||||
end
|
||||
end
|
||||
|
||||
def self.search_project(search)
|
||||
ransack(name_or_identifier_cont: search)
|
||||
end
|
||||
|
|
|
@ -9,7 +9,18 @@
|
|||
</div>
|
||||
<%= form_for @project_category, url: {controller: "project_categories", action: "#{type}"} do |p| %>
|
||||
<div class="modal-body">
|
||||
<%= p.text_field :name,class: "form-control input-lg",placeholder: "分类名称",required: true, maxlength: 64%>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
分类名称 <span class="ml10 color-orange mr20">*</span>
|
||||
</label>
|
||||
<%= p.text_field :name,class: "form-control input-lg",placeholder: "分类名称",required: true, maxlength: 64%>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>
|
||||
精选级别
|
||||
</label>
|
||||
<%= p.number_field :pinned_index,class: "form-control input-lg",placeholder: "精选级别",required: true%>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<tr>
|
||||
<th width="5%">序号</th>
|
||||
<th width="30%">名称</th>
|
||||
<th width="20%"><%= sort_tag('精选', name: 'pinned_index', path: admins_project_categories_path) %></th>
|
||||
<th width="20%"><%= sort_tag('项目数', name: 'projects_count', path: admins_project_categories_path) %></th>
|
||||
<th width="20%"><%= sort_tag('创建时间', name: 'created_at', path: admins_project_categories_path) %></th>
|
||||
<th width="25%">操作</th>
|
||||
|
@ -16,6 +17,7 @@
|
|||
<td>
|
||||
<%= link_to(project_category.name, "/projects?category_id=#{project_category.id}", target: '_blank') %>
|
||||
</td>
|
||||
<td><%= project_category.pinned_index == 0 ? "" : "√" %></td>
|
||||
<td><%= project_category.projects_count %></td>
|
||||
<td><%= project_category.created_at&.strftime('%Y-%m-%d %H:%M') %></td>
|
||||
<td class="action-container">
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
$("#projects-modals").html("<%= j render(partial: 'admins/projects/shared/form_modal', locals: {type: 'update'}) %>")
|
||||
$(".project-change-modal").modal('show');
|
|
@ -12,4 +12,7 @@
|
|||
|
||||
<div class="box admin-list-container project-list-container">
|
||||
<%= render partial: 'admins/projects/shared/list', locals: { projects: @projects } %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="projects-modals">
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<div class="modal fade project-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">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<%= form_for @project, url: {controller: "projects", action: "#{type}"} do |p| %>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>
|
||||
推荐等级
|
||||
</label>
|
||||
<%= p.number_field :recommend_index,class: "form-control input-lg"%>
|
||||
</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>
|
|
@ -5,6 +5,8 @@
|
|||
<th width="4%">ID</th>
|
||||
<th width="15%" class="text-left">项目名称</th>
|
||||
<th width="6%">公开</th>
|
||||
<th width="6%">精选</th>
|
||||
<th width="6%">推荐</th>
|
||||
<th width="5%">issue</th>
|
||||
<th width="5%">资源</th>
|
||||
<th width="6%">版本库</th>
|
||||
|
@ -12,8 +14,8 @@
|
|||
<th width="6%">里程碑</th>
|
||||
<th width="10%">成员</th>
|
||||
<th width="10%">管理员</th>
|
||||
<th width="11%"><%= sort_tag('创建时间', name: 'created_on', path: admins_projects_path) %></th>
|
||||
<th width="10%">操作</th>
|
||||
<th width="15%"><%= sort_tag('创建时间', name: 'created_on', path: admins_projects_path) %></th>
|
||||
<th width="25%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -26,6 +28,8 @@
|
|||
<%= link_to(project.name, "/projects/#{project&.owner&.login}/#{project.identifier}", target: '_blank') %>
|
||||
</td>
|
||||
<td><%= project.is_public ? '√' : '' %></td>
|
||||
<td><%= project.is_pinned ? '√' : '' %></td>
|
||||
<td><%= project.recommend ? '√' : '' %></td>
|
||||
<td><%= project.issues.size %></td>
|
||||
<td><%= project.attachments.size %></td>
|
||||
<td><%= project&.project_score.try(:changeset_num).to_i %></td>
|
||||
|
@ -37,8 +41,15 @@
|
|||
</td>
|
||||
<td><%= project.created_on&.strftime('%Y-%m-%d %H:%M') %></td>
|
||||
<td class="action-container">
|
||||
<% if project.is_public %>
|
||||
<%= javascript_void_link '精选', class: 'action pinned-action', data: { id: project.id }, style: project.is_pinned ? 'display: none;' : '' %>
|
||||
<%= javascript_void_link '取消精选', class: 'action unpinned-action', data: { id: project.id }, style: project.is_pinned ? '' : 'display: none;' %>
|
||||
<%= javascript_void_link '推荐', class: 'action recommend-action', data: { id: project.id }, style: project.recommend ? 'display: none;' : '' %>
|
||||
<%= javascript_void_link '取消推荐', class: 'action unrecommend-action', data: { id: project.id }, style: project.recommend ? '' : 'display: none;' %>
|
||||
<%= link_to "设置推荐等级", edit_admins_project_path(project.id), remote: true, class: "action", style: project.recommend ? '' : 'display: none;' %>
|
||||
<% end %>
|
||||
<%= link_to "删除", admins_project_path(project.id), method: :delete, data:{confirm: "确认删除的吗?"}, class: "delete-project-action" %>
|
||||
</td>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% else %>
|
||||
|
|
|
@ -909,7 +909,7 @@ Rails.application.routes.draw do
|
|||
|
||||
resources :courses, only: [:index, :destroy, :update]
|
||||
|
||||
resources :projects, only: [:index, :destroy]
|
||||
resources :projects, only: [:index, :edit, :update, :destroy]
|
||||
|
||||
resources :disciplines, only: [:index, :create, :edit, :update, :destroy] do
|
||||
post :adjust_position, on: :member
|
||||
|
|
Loading…
Reference in New Issue