提交 f17ddeb3 编写于 作者: D Dmitriy Zaporozhets

Make admin project list more useful

上级 552b3105
......@@ -77,3 +77,7 @@ a {
a:focus {
outline: none;
}
.monospace {
font-family: 'Menlo', 'Liberation Mono', 'Consolas', 'Courier New', 'andale mono','lucida console',monospace;
}
......@@ -3,8 +3,9 @@ class Admin::ProjectsController < AdminController
def index
@projects = Project.scoped
@projects = @projects.where(namespace_id: params[:namespace_id]) if params[:namespace_id].present?
@projects = @projects.search(params[:name]) if params[:name].present?
@projects = @projects.order("name ASC").page(params[:page]).per(20)
@projects = @projects.includes(:namespace).order("namespaces.code, projects.name ASC").page(params[:page]).per(20)
end
def show
......
......@@ -74,16 +74,25 @@ module ApplicationHelper
grouped_options_for_select(options, @ref || @project.default_branch)
end
def namespaces_options
def namespaces_options(selected = :current_user, scope = :default)
groups = current_user.namespaces.select {|n| n.type == 'Group'}
users = current_user.namespaces.reject {|n| n.type == 'Group'}
users = if scope == :all
Namespace.root
else
current_user.namespaces.reject {|n| n.type == 'Group'}
end
options = [
["Groups", groups.map {|g| [g.human_name, g.id]} ],
[ "Users", users.map {|u| [u.human_name, u.id]} ]
]
grouped_options_for_select(options, current_user.namespace.id)
if selected == :current_user
selected = current_user.namespace.id
end
grouped_options_for_select(options, selected)
end
def search_autocomplete_source
......
......@@ -10,6 +10,8 @@ class Namespace < ActiveRecord::Base
delegate :name, to: :owner, allow_nil: true, prefix: true
scope :root, where('type IS NULL')
def self.search query
where("name LIKE :query OR code LIKE :query", query: "%#{query}%")
end
......
......@@ -80,7 +80,7 @@ class Project < ActiveRecord::Base
end
def search query
where("name LIKE :query OR code LIKE :query OR path LIKE :query", query: "%#{query}%")
where("projects.name LIKE :query OR projects.code LIKE :query OR projects.path LIKE :query", query: "%#{query}%")
end
def create_by_user(params, user)
......
......@@ -4,13 +4,14 @@
= link_to 'New Project', new_project_path, class: "btn small right"
%br
= form_tag admin_projects_path, method: :get, class: 'form-inline' do
= select_tag :namespace_id, namespaces_options(params[:namespace_id], :all), class: "chosen xlarge", include_blank: true
= text_field_tag :name, params[:name], class: "xlarge"
= submit_tag "Search", class: "btn submit primary"
%table
%thead
%th Name
%th Path
%th Project
%th Team Members
%th Last Commit
%th Edit
......@@ -18,8 +19,13 @@
- @projects.each do |project|
%tr
%td= link_to project.name, [:admin, project]
%td= project.path
%td
- if project.namespace
= link_to project.namespace.human_name, [:admin, project]
&rarr;
= link_to project.name, [:admin, project]
%td
%span.monospace= project.path_with_namespace + ".git"
%td= project.users_projects.count
%td= last_commit(project)
%td= link_to 'Edit', edit_admin_project_path(project), id: "edit_#{dom_id(project)}", class: "btn small"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册