新增:后台管理项目列表项目类别筛选

This commit is contained in:
yystopf 2024-07-18 15:32:34 +08:00
parent d109859149
commit c362315ea5
2 changed files with 22 additions and 1 deletions

View File

@ -7,6 +7,16 @@ class Admins::ProjectsController < Admins::BaseController
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
search = params[:search].to_s.strip
projects = Project.where("name like ? OR identifier LIKE ?", "%#{search}%", "%#{search}%").order("#{sort_by} #{sort_direction}")
case params[:category]
when 'public'
projects = projects.where(is_public: true)
when 'private'
projects = projects.where(is_public: false)
when 'fork'
projects = projects.where.not(forked_from_project_id: nil)
when 'original'
projects = projects.where(forked_from_project_id: nil, project_type: 'common')
end
@projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score)
end

View File

@ -3,10 +3,15 @@
<% end %>
<div class="box search-form-container project-list-form">
<%= form_tag(admins_projects_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
<%= form_tag(admins_projects_path, method: :get, class: 'form-inline search-form flex-1', id: 'project-list-form', 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="清空"/>
<div class="form-group mr-2 pull-right" style='margin-left:auto'>
<label for="status">项目类别:</label>
<% type_options = [['全部项目', ''], ['公开项目', 'public'], ['私有项目', 'private'], ['Fork项目', 'fork'], ['原创项目', 'original']] %>
<%= select_tag(:category, options_for_select(type_options, params[:category]), class: 'form-control', id: 'project-category') %>
</div>
<% end %>
</div>
@ -16,3 +21,9 @@
<div id="projects-modals">
</div>
<script>
$("#project-category").on('change', function() {
$("#project-list-form").submit()
});
</script>