Commit c38b9a2f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Filter projects on dashboard

parent 00a30420fa37
...@@ -100,3 +100,17 @@ input[type='search'].search-text-input { ...@@ -100,3 +100,17 @@ input[type='search'].search-text-input {
} }
fieldset legend { font-size: 17px; } 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;
}
}
}
...@@ -7,6 +7,15 @@ class DashboardController < ApplicationController ...@@ -7,6 +7,15 @@ class DashboardController < ApplicationController
def index def index
@groups = current_user.authorized_groups @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) @projects = @projects.page(params[:page]).per(30)
@events = Event.in_projects(current_user.project_ids) @events = Event.in_projects(current_user.project_ids)
......
...@@ -84,4 +84,17 @@ def branches_tab_class ...@@ -84,4 +84,17 @@ def branches_tab_class
'active' 'active'
end end
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 end
...@@ -74,6 +74,8 @@ class Project < ActiveRecord::Base ...@@ -74,6 +74,8 @@ class Project < ActiveRecord::Base
scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.projects.map(&:id) ) } 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 :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 :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 class << self
def authorized_for user def authorized_for user
......
...@@ -8,6 +8,14 @@ ...@@ -8,6 +8,14 @@
= link_to new_project_path, class: "btn very_small info" do = link_to new_project_path, class: "btn very_small info" do
%i.icon-plus %i.icon-plus
New Project 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 %ul.unstyled
- projects.each do |project| - projects.each do |project|
%li.wll %li.wll
......
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