#648: updated models, JS, controller according to comments and discussions

This commit is contained in:
Vokhmin Alexey V 2012-09-24 22:04:53 +04:00
parent cee1ee6cb6
commit 9be978eb68
9 changed files with 53 additions and 93 deletions

View File

@ -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');
}
});

View File

@ -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 {

View File

@ -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?

View File

@ -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"

View File

@ -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)
}

View File

@ -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

View File

@ -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},

View File

@ -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

View File

@ -1,8 +1,8 @@
ru:
layout:
relations:
my: Мои
filters: Фильтры
user_owner: Я - владелец
group_owner: Я состою в группе-владельцев
group_owner: Я состою в группе-владельце
user: Я - участник
group: Я состою в группе-участников
group: Я состою в группе-участнике