Commit 6eb045fc authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Prevent Project.all & User.all in selectboxes

parent 52f312a8
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
.ajax-users-select { .ajax-users-select {
width: 400px; width: 400px;
&.input-large {
width: 210px;
}
} }
.user-result { .user-result {
......
...@@ -2,8 +2,10 @@ class Admin::ProjectsController < Admin::ApplicationController ...@@ -2,8 +2,10 @@ class Admin::ProjectsController < Admin::ApplicationController
before_filter :project, only: [:edit, :show, :update, :destroy, :team_update] before_filter :project, only: [:edit, :show, :update, :destroy, :team_update]
def index def index
@projects = Project.scoped owner_id = params[:owner_id]
@projects = @projects.where(namespace_id: params[:namespace_id]) if params[:namespace_id].present? user = User.find_by_id(owner_id)
@projects = user ? user.owned_projects : Project.scoped
@projects = @projects.where(public: true) if params[:public_only].present? @projects = @projects.where(public: true) if params[:public_only].present?
@projects = @projects.with_push if params[:with_push].present? @projects = @projects.with_push if params[:with_push].present?
@projects = @projects.abandoned if params[:abandoned].present? @projects = @projects.abandoned if params[:abandoned].present?
......
...@@ -192,9 +192,12 @@ module ApplicationHelper ...@@ -192,9 +192,12 @@ module ApplicationHelper
alias_method :url_to_image, :image_url alias_method :url_to_image, :image_url
def users_select_tag(id, opts = {}) def users_select_tag(id, opts = {})
css_class = "ajax-users-select" css_class = "ajax-users-select "
css_class << " multiselect" if opts[:multiple] css_class << "multiselect " if opts[:multiple]
hidden_field_tag(id, '', class: css_class) css_class << opts[:class] || ''
value = opts[:selected] || ''
hidden_field_tag(id, value, class: css_class)
end end
def body_data_page def body_data_page
......
module NamespacesHelper module NamespacesHelper
def namespaces_options(selected = :current_user, scope = :default) def namespaces_options(selected = :current_user, scope = :default)
if current_user.admin groups = current_user.owned_groups.select {|n| n.type == 'Group'}
groups = Group.all users = current_user.namespaces.reject {|n| n.type == 'Group'}
users = Namespace.root
else
groups = current_user.owned_groups.select {|n| n.type == 'Group'}
users = current_user.namespaces.reject {|n| n.type == 'Group'}
end
global_opts = ["Global", [['/', Namespace.global_id]] ] global_opts = ["Global", [['/', Namespace.global_id]] ]
group_opts = ["Groups", groups.sort_by(&:human_name).map {|g| [g.human_name, g.id]} ] group_opts = ["Groups", groups.sort_by(&:human_name).map {|g| [g.human_name, g.id]} ]
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
= text_field_tag :name, params[:name], class: "span2" = text_field_tag :name, params[:name], class: "span2"
.control-group .control-group
= label_tag :namespace_id, 'Namespace:', class: 'control-label' = label_tag :owner_id, 'Owner:', class: 'control-label'
.controls .controls
= select_tag :namespace_id, namespaces_options(params[:namespace_id], :all), class: "chosen span2", prompt: "Any" = users_select_tag :owner_id, selected: params[:owner_id], class: 'input-large'
.control-group .control-group
= label_tag :public_only, 'Public Only', class: 'control-label' = label_tag :public_only, 'Public Only', class: 'control-label'
.controls .controls
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment