From 9be978eb686d4bd4f2316a99c581223bddff40f7 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Mon, 24 Sep 2012 22:04:53 +0400 Subject: [PATCH] #648: updated models, JS, controller according to comments and discussions --- app/assets/javascripts/extra/filter_labels.js | 6 +-- app/assets/stylesheets/design/custom.scss | 49 +++---------------- .../projects/projects_controller.rb | 26 +++++----- app/helpers/projects_helper.rb | 15 ++++++ app/models/project.rb | 5 +- .../projects/projects/_filters.html.haml | 24 ++------- app/views/projects/projects/index.html.haml | 13 ++--- config/locales/models/relation.en.yml | 2 +- config/locales/models/relation.ru.yml | 6 +-- 9 files changed, 53 insertions(+), 93 deletions(-) diff --git a/app/assets/javascripts/extra/filter_labels.js b/app/assets/javascripts/extra/filter_labels.js index c10c97659..5dd23a47e 100644 --- a/app/assets/javascripts/extra/filter_labels.js +++ b/app/assets/javascripts/extra/filter_labels.js @@ -6,12 +6,10 @@ $(document).ready(function() { var bg = $("#"+flag).css("background-color"); var checkbox = $(this).find(':checkbox'); if ($(this).css("background-color") != bg) { - $(this).css("background-color",bg); - $(this).css("color","#FFFFFF"); + $(this).css("background-color",bg).css("color","#FFFFFF"); checkbox.attr('checked', 'checked'); } else { - $(this).css("background-color","rgb(247, 247, 247)"); - $(this).css("color","#565657"); + $(this).css("background-color","rgb(247, 247, 247)").css("color","#565657"); checkbox.removeAttr('checked'); } }); diff --git a/app/assets/stylesheets/design/custom.scss b/app/assets/stylesheets/design/custom.scss index 7dd03070a..7ba727fe8 100644 --- a/app/assets/stylesheets/design/custom.scss +++ b/app/assets/stylesheets/design/custom.scss @@ -698,48 +698,13 @@ div.toolbar a.button { float: left; } -div.toolbar div.legend { - float: left; - margin-left: 50px; - padding: 4px 0 6px; -} - -table.dataTable tr td.rights span.group, -div.toolbar div.legend.rights span.group { - background: image-url('group16.png') no-repeat 0 0 transparent; -} - -table.dataTable tr td.rights span.user, -div.toolbar div.legend.rights span.user { - background: image-url('user16.png') no-repeat 0 0 transparent; -} - -table.dataTable tr td.rights span.group_owner, -div.toolbar div.legend.rights span.group_owner { - background: image-url('group16g.png') no-repeat 0 0 transparent; -} - -table.dataTable tr td.rights span.user_owner, -div.toolbar div.legend.rights span.user_owner { - background: image-url('user16g.png') no-repeat 0 0 transparent; -} - -table.dataTable tr td.rights span.group_owner, -div.toolbar div.legend.rights span.group_owner, -table.dataTable tr td.rights span.user_owner, -div.toolbar div.legend.rights span.user_owner, -table.dataTable tr td.rights span.group, -div.toolbar div.legend.rights span.group, -table.dataTable tr td.rights span.user, -div.toolbar div.legend.rights span.user { - padding-left: 20px; -} - -div.toolbar div.legend.rights span.group_owner, -div.toolbar div.legend.rights span.user_owner, -div.toolbar div.legend.rights span.group, -div.toolbar div.legend.rights span.user { - margin: 0 10px; +div.toolbar, table.dataTable { + > .group_owner, > .user_owner, > .group, > .user { margin-right: 15px; } + .group_owner, .user_owner, .group, .user { padding-left: 20px; } + .user_owner { background: image-url('user16g.png') no-repeat 0 0 transparent; } + .group_owner { background: image-url('group16g.png') no-repeat 0 0 transparent; } + .user { background: image-url('user16.png') no-repeat 0 0 transparent; } + .group { background: image-url('group16.png') no-repeat 0 0 transparent; } } .root { diff --git a/app/controllers/projects/projects_controller.rb b/app/controllers/projects/projects_controller.rb index 4ad644e01..d9fa0d6af 100644 --- a/app/controllers/projects/projects_controller.rb +++ b/app/controllers/projects/projects_controller.rb @@ -1,16 +1,24 @@ # -*- encoding : utf-8 -*- class Projects::ProjectsController < Projects::BaseController + include ProjectsHelper before_filter :authenticate_user! load_and_authorize_resource :id_param => :project_name # to force member actions load def index - @groups = params[:groups] || [] - @user_owner = params[:user_owner] ? true : false @projects = Project.accessible_by(current_ability, :membered) respond_to do |format| - format.html { @projects = @projects.recent.paginate(:page => params[:page], :per_page => 25) } - format.json { @projects = prepare_list(@projects, @groups, @user_owner) } + format.html { + @all_projects = @projects + @groups = current_user.groups + @owners = User.where(:id => @projects.select(:owner_id).where(:owner_type => 'User').group(:owner_id).map(&:owner_id)) + @projects = @projects.recent.paginate(:page => params[:page], :per_page => 25) + } + format.json { + selected_groups = params[:groups] || [] + selected_owners = params[:owners] || [] + @projects = prepare_list(@projects, selected_groups, selected_owners) + } end end @@ -97,7 +105,7 @@ class Projects::ProjectsController < Projects::BaseController protected - def prepare_list(projects, groups, user_owner) + def prepare_list(projects, groups, owners) res = {} colName = ['name'] @@ -107,12 +115,8 @@ class Projects::ProjectsController < Projects::BaseController res[:total_count] = projects.count - if user_owner && groups.present? - projects = projects.by_groups_or_owner(groups, current_user) - elsif groups.present? - projects = projects.where(:groups => {:id => groups}).joins(:groups) - elsif user_owner - projects = projects.where(:owner_id => current_user, :owner_type => 'User') + if groups.present? || owners.present? + projects = projects.by_owners(groups, owners) end projects = projects.search(params[:sSearch]).search_order if params[:sSearch].present? diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 40ddb89a2..904e15ad3 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -1,5 +1,20 @@ # -*- encoding : utf-8 -*- module ProjectsHelper + def options_for_filters(all_projects, groups, owners) + (groups + owners).map do |o| + class_name = o.class.name + { + :id => "#{class_name.downcase}-#{o.id}", + :color => '464646', + :selected => false, + :check_box_name => class_name.downcase.pluralize, + :check_box_value => o.id, + :name => o.uname, + :count => all_projects.where(:owner_id => o, :owner_type => class_name).count + } + end.sort_by{ |f| f[:name] } + end + def git_repo_url(name) if current_user "#{request.protocol}#{current_user.uname}@#{request.host_with_port}/#{name}.git" diff --git a/app/models/project.rb b/app/models/project.rb index f47128b52..f5bbcc31c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -49,9 +49,8 @@ class Project < ActiveRecord::Base WHERE (ptr.repository_id = #{ repository_id }) ) ) } - scope :by_groups_or_owner, lambda { |group_ids, owner_id| - where("(relations.actor_id IN (?) AND relations.actor_type = 'Group') OR (projects.owner_id = ? AND projects.owner_type = 'User')", group_ids, owner_id). - joins(:relations) + scope :by_owners, lambda { |group_owner_ids, user_owner_ids| + where("(projects.owner_id in (?) AND projects.owner_type = 'Group') OR (projects.owner_id in (?) AND projects.owner_type = 'User')", group_owner_ids, user_owner_ids) } diff --git a/app/views/projects/projects/_filters.html.haml b/app/views/projects/projects/_filters.html.haml index 1fddd37fb..437dbec65 100644 --- a/app/views/projects/projects/_filters.html.haml +++ b/app/views/projects/projects/_filters.html.haml @@ -3,25 +3,9 @@ =form_tag projects_path, :id => 'filter_projects', :method => :get do .bordered.bpadding20 =tracker_search_field(:search, t('layout.find_project')) + = link_to t('layout.projects.new'), new_project_path, :class => 'button' if can?(:create, Project) .bordered.bpadding20 - =render 'projects/shared/filter_label', - :id => 'user-owner', - :selected => @user_owner, - :color => '00a651', - :check_box_name => 'user_owner', - :check_box_value => 'true', - :name => t("layout.relations.my"), - :count => current_user.own_projects.count - - .bordered.bpadding20 - %h3=t('layout.groups.list_header') - - current_user.groups.each do |group| - =render 'projects/shared/filter_label', - :id => "group-#{group.id}", - :selected => @groups.include?(group.id.to_s), - :color => '00a651', - :check_box_name => 'groups', - :check_box_value => group.id, - :name => group.uname, - :count => group.projects.count + %h3=t('layout.relations.filters') + - options_for_filters(@all_projects, @groups, @owners).each do |options| + =render 'projects/shared/filter_label', options diff --git a/app/views/projects/projects/index.html.haml b/app/views/projects/projects/index.html.haml index c88a9292b..15305fe39 100644 --- a/app/views/projects/projects/index.html.haml +++ b/app/views/projects/projects/index.html.haml @@ -1,15 +1,10 @@ -set_meta_tags :title => t('layout.projects.list_header') -render 'filters' .toolbar - = link_to t('layout.projects.new'), new_project_path, :class => 'button' if can?(:create, Project) - - .legend.rights - %div - %span.user_owner= t("layout.relations.user_owner") - %span.group_owner= t("layout.relations.group_owner") - %div - %span.user= t("layout.relations.user") - %span.group= t("layout.relations.group") + %span.user_owner= t("layout.relations.user_owner") + %span.group_owner= t("layout.relations.group_owner") + %span.user= t("layout.relations.user") + %span.group= t("layout.relations.group") .both - columns = [{:type => 'html'}, {:type => 'html', :sortable => false, :searchable => false}, diff --git a/config/locales/models/relation.en.yml b/config/locales/models/relation.en.yml index 1dc1fb3bb..8a5af138e 100644 --- a/config/locales/models/relation.en.yml +++ b/config/locales/models/relation.en.yml @@ -1,7 +1,7 @@ en: layout: relations: - my: My + filters: Filters user_owner: I'm owner group_owner: I'm member of owner group user: I'm collaborator diff --git a/config/locales/models/relation.ru.yml b/config/locales/models/relation.ru.yml index 857d6df7c..8160c72b5 100644 --- a/config/locales/models/relation.ru.yml +++ b/config/locales/models/relation.ru.yml @@ -1,8 +1,8 @@ ru: layout: relations: - my: Мои + filters: Фильтры user_owner: Я - владелец - group_owner: Я состою в группе-владельцев + group_owner: Я состою в группе-владельце user: Я - участник - group: Я состою в группе-участников + group: Я состою в группе-участнике