mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +01:00
Add a Sidebar class to represent the side bar
Start using it throughout the rest of the app instead of the various instance variables
This commit is contained in:
parent
2883d1b7f4
commit
8d24f5105a
5 changed files with 66 additions and 17 deletions
|
|
@ -212,12 +212,7 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def init_data_for_sidebar
|
def init_data_for_sidebar
|
||||||
@completed_projects = current_user.projects.completed
|
@sidebar = Sidebar.new(current_user)
|
||||||
@hidden_projects = current_user.projects.hidden
|
|
||||||
@active_projects = current_user.projects.active
|
|
||||||
|
|
||||||
@active_contexts = current_user.contexts.active
|
|
||||||
@hidden_contexts = current_user.contexts.hidden
|
|
||||||
|
|
||||||
init_not_done_counts
|
init_not_done_counts
|
||||||
if prefs.show_hidden_projects_in_sidebar
|
if prefs.show_hidden_projects_in_sidebar
|
||||||
|
|
|
||||||
|
|
@ -562,11 +562,7 @@ class TodosController < ApplicationController
|
||||||
format.html do
|
format.html do
|
||||||
init_not_done_counts
|
init_not_done_counts
|
||||||
init_project_hidden_todo_counts
|
init_project_hidden_todo_counts
|
||||||
@active_projects = current_user.projects.active
|
init_data_for_sidebar unless mobile?
|
||||||
@active_contexts = current_user.contexts.active
|
|
||||||
@hidden_projects = current_user.projects.hidden
|
|
||||||
@hidden_contexts = current_user.contexts.hidden
|
|
||||||
@completed_projects = current_user.projects.completed
|
|
||||||
end
|
end
|
||||||
format.m
|
format.m
|
||||||
format.xml { render :xml => @not_done_todos.to_xml( *todo_xml_params ) }
|
format.xml { render :xml => @not_done_todos.to_xml( *todo_xml_params ) }
|
||||||
|
|
|
||||||
29
app/models/sidebar.rb
Normal file
29
app/models/sidebar.rb
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
class Sidebar
|
||||||
|
attr_reader :contexts, :projects
|
||||||
|
|
||||||
|
def initialize(user)
|
||||||
|
user = user
|
||||||
|
@contexts = user.contexts
|
||||||
|
@projects = user.projects
|
||||||
|
end
|
||||||
|
|
||||||
|
def active_contexts
|
||||||
|
@active_contexts ||= contexts.active
|
||||||
|
end
|
||||||
|
|
||||||
|
def hidden_contexts
|
||||||
|
@hidden_contexts ||= contexts.hidden
|
||||||
|
end
|
||||||
|
|
||||||
|
def active_projects
|
||||||
|
@active_projects ||= projects.active
|
||||||
|
end
|
||||||
|
|
||||||
|
def hidden_projects
|
||||||
|
@hidden_projects ||= projects.hidden
|
||||||
|
end
|
||||||
|
|
||||||
|
def completed_projects
|
||||||
|
@completed_projects ||= projects.completed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<div id="sidebar">
|
<div id="sidebar">
|
||||||
<%= sidebar_html_for_titled_list(@active_projects, t('sidebar.list_name_active_projects'))%>
|
<%= sidebar_html_for_titled_list(@sidebar.active_projects, t('sidebar.list_name_active_projects'))%>
|
||||||
<%= sidebar_html_for_titled_list(@active_contexts, t('sidebar.list_name_active_contexts'))%>
|
<%= sidebar_html_for_titled_list(@sidebar.active_contexts, t('sidebar.list_name_active_contexts'))%>
|
||||||
<%= sidebar_html_for_titled_list(@hidden_projects, t('sidebar.list_name_hidden_projects')) if prefs.show_hidden_projects_in_sidebar %>
|
<%= sidebar_html_for_titled_list(@sidebar.hidden_projects, t('sidebar.list_name_hidden_projects')) if prefs.show_hidden_projects_in_sidebar %>
|
||||||
<%= sidebar_html_for_titled_list(@completed_projects, t('sidebar.list_name_completed_projects')) if prefs.show_completed_projects_in_sidebar %>
|
<%= sidebar_html_for_titled_list(@sidebar.completed_projects, t('sidebar.list_name_completed_projects')) if prefs.show_completed_projects_in_sidebar %>
|
||||||
<%= sidebar_html_for_titled_list(@hidden_contexts, t('sidebar.list_name_hidden_contexts')) if prefs.show_hidden_contexts_in_sidebar %>
|
<%= sidebar_html_for_titled_list(@sidebar.hidden_contexts, t('sidebar.list_name_hidden_contexts')) if prefs.show_hidden_contexts_in_sidebar %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
29
test/models/sidebar_test.rb
Normal file
29
test/models/sidebar_test.rb
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class SidebarTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@sidebar = Sidebar.new(users(:admin_user))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_it_gets_the_active_contexts
|
||||||
|
assert @sidebar.active_contexts == users(:admin_user).contexts.active
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_it_gets_the_hidden_contexts
|
||||||
|
assert @sidebar.hidden_contexts == users(:admin_user).contexts.hidden
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_it_gets_the_active_projects
|
||||||
|
assert @sidebar.active_projects == users(:admin_user).projects.active
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_it_gets_the_hidden_projects
|
||||||
|
assert @sidebar.hidden_projects == users(:admin_user).projects.hidden
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_it_gets_the_completed_projects
|
||||||
|
assert @sidebar.completed_projects == users(:admin_user).projects.completed
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue