Filter projects on dashboard

This commit is contained in:
Dmitriy Zaporozhets 2012-11-30 06:14:05 +03:00
parent a03f318964
commit c38b9a2f80
5 changed files with 46 additions and 0 deletions

View file

@ -100,3 +100,17 @@ input[type='search'].search-text-input {
}
fieldset legend { font-size: 17px; }
ul.nav.nav-projects-tabs {
@extend .nav-tabs;
padding-left: 8px;
li {
a {
padding: 4px 20px;
margin-top: 2px;
border-color: #DDD;
}
}
}

View file

@ -7,6 +7,15 @@ class DashboardController < ApplicationController
def index
@groups = current_user.authorized_groups
@projects = case params[:scope]
when 'personal' then
@projects.personal(current_user)
when 'joined' then
@projects.joined(current_user)
else
@projects
end
@projects = @projects.page(params[:page]).per(30)
@events = Event.in_projects(current_user.project_ids)

View file

@ -84,4 +84,17 @@ module TabHelper
'active'
end
end
# Use nav_tab for save controller/action but different params
def nav_tab key, value, &block
o = {}
o[:class] = ""
o[:class] << " active" if params[key] == value
if block_given?
content_tag(:li, capture(&block), o)
else
content_tag(:li, nil, o)
end
end
end

View file

@ -74,6 +74,8 @@ class Project < ActiveRecord::Base
scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.projects.map(&:id) ) }
scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) }
scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") }
scope :personal, ->(user) { where(namespace_id: user.namespace_id) }
scope :joined, ->(user) { where("namespace_id != ?", user.namespace_id) }
class << self
def authorized_for user

View file

@ -8,6 +8,14 @@
= link_to new_project_path, class: "btn very_small info" do
%i.icon-plus
New Project
%ul.nav.nav-projects-tabs
= nav_tab :scope, nil do
= link_to "All", dashboard_path
= nav_tab :scope, 'personal' do
= link_to "Personal", dashboard_path(scope: 'personal')
= nav_tab :scope, 'joined' do
= link_to "Joined", dashboard_path(scope: 'joined')
%ul.unstyled
- projects.each do |project|
%li.wll