#648: added filters to Projects page
This commit is contained in:
parent
3c70adba9a
commit
2406423483
|
@ -0,0 +1,19 @@
|
|||
$(document).ready(function() {
|
||||
|
||||
$(".div-filter-labels").live('click', function() {
|
||||
var flag = this.id;
|
||||
flag = flag.replace("label-","flag-");
|
||||
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");
|
||||
checkbox.attr('checked', 'checked');
|
||||
} else {
|
||||
$(this).css("background-color","rgb(247, 247, 247)");
|
||||
$(this).css("color","#565657");
|
||||
checkbox.removeAttr('checked');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
|
@ -30,19 +30,6 @@ $(document).ready(function() {
|
|||
});
|
||||
|
||||
$("div.div-tracker-labels").live('click', function() {
|
||||
var flag = this.id;
|
||||
flag = flag.replace("label-","flag-");
|
||||
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");
|
||||
checkbox.attr('checked', 'checked');
|
||||
} else {
|
||||
$(this).css("background-color","rgb(247, 247, 247)");
|
||||
$(this).css("color","#565657");
|
||||
checkbox.removeAttr('checked');
|
||||
}
|
||||
return send_index_tracker_request('GET');
|
||||
});
|
||||
|
||||
|
@ -89,7 +76,7 @@ $(document).ready(function() {
|
|||
data = data || '';
|
||||
var filter_form = $('#filter_issues');
|
||||
url = url || filter_form.attr("action");
|
||||
var label_form = $('#filter_labels');
|
||||
var label_form = $('#filter_labels, #filter_projects');
|
||||
var status = 'status=' + $('#issues_status').attr('value');
|
||||
$.ajax({
|
||||
type: type_request,
|
||||
|
|
|
@ -1931,7 +1931,7 @@ a.button.width100 {
|
|||
width: 100px;
|
||||
}
|
||||
|
||||
.div-tracker-labels {
|
||||
.div-filter-labels {
|
||||
margin: 2px 13px 2px 0px;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
|
|
|
@ -4,11 +4,13 @@ class Projects::ProjectsController < Projects::BaseController
|
|||
load_and_authorize_resource :id_param => :project_name # to force member actions load
|
||||
|
||||
def index
|
||||
@groups = params[:groups] || []
|
||||
@user_owner = params[:user_owner] == ['true'] ? 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) }
|
||||
format.json { @projects = prepare_list(@projects, @groups, @user_owner) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -95,7 +97,7 @@ class Projects::ProjectsController < Projects::BaseController
|
|||
|
||||
protected
|
||||
|
||||
def prepare_list(projects)
|
||||
def prepare_list(projects, groups, user_owner)
|
||||
res = {}
|
||||
|
||||
colName = ['name']
|
||||
|
@ -104,7 +106,21 @@ class Projects::ProjectsController < Projects::BaseController
|
|||
order = "#{colName[sort_col.to_i]} #{sort_dir}"
|
||||
|
||||
res[:total_count] = projects.count
|
||||
|
||||
if user_owner
|
||||
project_ids = current_user.own_projects.map(&:id)
|
||||
if groups.present?
|
||||
projects = projects.where("groups.id in (?) OR projects.id in (?)", groups, project_ids).
|
||||
joins(:relations).
|
||||
joins('RIGHT OUTER JOIN "groups" ON "groups"."id" = "relations"."actor_id"')
|
||||
else
|
||||
projects = projects.where(:id => project_ids)
|
||||
end
|
||||
else
|
||||
projects = projects.where(:groups => {:id => groups}).joins(:groups) if groups.present?
|
||||
end
|
||||
projects = projects.search(params[:sSearch]).search_order if params[:sSearch].present?
|
||||
|
||||
res[:filtered_count] = projects.count
|
||||
|
||||
projects = projects.order(order)
|
||||
|
|
|
@ -3,16 +3,15 @@
|
|||
#labels-stock
|
||||
=form_tag project_issues_path(@project), :id => 'filter_labels', :method => :get do
|
||||
- @project.labels.each_with_index do |label, index|
|
||||
.div-tracker-labels{:id => "label-#{label.name.parameterize}", :style => @labels.include?(label.name) ? "background-color:##{label.color};color:#FFF" : ''}
|
||||
.div-label-left
|
||||
.label
|
||||
.flag{:id => "flag-#{label.name.parameterize}", :style => "background-color: ##{label.color};"}
|
||||
.labeltext=label.name
|
||||
=check_box_tag 'labels[]', label.name, @labels.include?(label.name), :style => 'display:none'
|
||||
.both
|
||||
.div-label-right=Labeling.joins(:label).where(:labels => {:name => label.name, :project_id => @project.id}).count
|
||||
.both
|
||||
.both
|
||||
=render 'projects/shared/filter_label',
|
||||
:id => label.name.parameterize,
|
||||
:selected => @labels.include?(label.name),
|
||||
:extra_classes => 'div-tracker-labels',
|
||||
:color => label.color,
|
||||
:check_box_name => 'labels',
|
||||
:check_box_value => label.name,
|
||||
:name => label.name,
|
||||
:count => Labeling.joins(:label).where(:labels => {:name => label.name, :project_id => @project.id}).count
|
||||
- if can? :write, @project
|
||||
%a#manage-labels.button.tmargin10{:href => "#labels-stock"}=t('layout.issues.label_manage')
|
||||
#labels-edit{:style => "display: none;"}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
-content_for :sidebar do
|
||||
- if current_user
|
||||
=form_tag projects_path, :id => 'filter_projects', :method => :get do
|
||||
.bordered.bpadding20
|
||||
=tracker_search_field(:search, t('layout.find_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
|
|
@ -1,10 +1,13 @@
|
|||
-set_meta_tags :title => t('layout.projects.list_header')
|
||||
-render 'filter'
|
||||
.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")
|
||||
.both
|
||||
|
@ -29,15 +32,11 @@
|
|||
%th.th2= t("activerecord.attributes.project.description")
|
||||
%th.th3= t("layout.projects.role")
|
||||
%th.th4= t("layout.projects.remove_user")
|
||||
%tr.search
|
||||
%th{:colspan => 4}
|
||||
<input class="gray" type="text" value="#{ t('layout.find_project') }">
|
||||
|
||||
%tbody= render :partial => 'projects/projects/project', :collection => @projects
|
||||
|
||||
:javascript
|
||||
$(document).ready(function() {
|
||||
|
||||
var isUpdateDataTable = null;
|
||||
var JsonParser = function (json) {
|
||||
|
||||
var firstColumn = function(row) {
|
||||
|
@ -99,16 +98,17 @@
|
|||
#{ format_columns_for_datatable(columns) }
|
||||
],
|
||||
"fnServerData": function ( sSource, aoData, fnCallback ) {
|
||||
$.getJSON( sSource, aoData, function (json) {
|
||||
if (isUpdateDataTable != null) { isUpdateDataTable.abort(); }
|
||||
_.each($('#filter_projects').serializeArray(), function(dv) { aoData.push(dv); });
|
||||
isUpdateDataTable = $.getJSON( sSource, aoData, function (json) {
|
||||
json.aaData = JsonParser(json);
|
||||
fnCallback(json);
|
||||
} );
|
||||
}
|
||||
|
||||
});
|
||||
$('#datatable_wrapper').append("<div class='both'></div>");
|
||||
|
||||
var $search = $('tr.search input[type="text"]');
|
||||
var $search = $('#search');
|
||||
$search.live('blur', function() {
|
||||
$this = $(this);
|
||||
if ($this.val() == '') {
|
||||
|
@ -128,6 +128,9 @@
|
|||
$search.live('keyup', function() {
|
||||
oTable.fnFilter(this.value);
|
||||
});
|
||||
$(".div-filter-labels").live('click', function() {
|
||||
oTable.dataTable().fnDraw();
|
||||
});
|
||||
});
|
||||
|
||||
=# will_paginate
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
- extra_classes ||= ''
|
||||
.div-filter-labels{:id => "label-#{id}", :class => extra_classes, :style => selected ? "background-color:##{color};color:#FFF" : ''}
|
||||
.div-label-left
|
||||
.label
|
||||
.flag{:id => "flag-#{id}", :style => "background-color: ##{color};"}
|
||||
.labeltext=name
|
||||
=check_box_tag "#{check_box_name}[]", check_box_value, selected, :style => 'display:none'
|
||||
.both
|
||||
.div-label-right=count
|
||||
.both
|
||||
.both
|
|
@ -1,6 +1,7 @@
|
|||
en:
|
||||
layout:
|
||||
relations:
|
||||
list_header: Relations of projects
|
||||
user_owner: I'm owner
|
||||
group_owner: I'm member of owner group
|
||||
user: I'm collaborator
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
ru:
|
||||
layout:
|
||||
relations:
|
||||
list_header: Принадлежность проектов
|
||||
user_owner: Я - владелец
|
||||
group_owner: Я состою в группе-владельце
|
||||
group_owner: Я состою в группе-владельцев
|
||||
user: Я - участник
|
||||
group: Я состою в группе-участнике
|
||||
group: Я состою в группе-участников
|
||||
|
|
Loading…
Reference in New Issue