diff --git a/app/controllers/visits_controller.rb b/app/controllers/visits_controller.rb index 8e867ec4..51d33830 100644 --- a/app/controllers/visits_controller.rb +++ b/app/controllers/visits_controller.rb @@ -91,9 +91,7 @@ def destroy end def today - today = Date.today - params.merge! :year => today.year, :month => today.month, :day => today.day - day + redirect_to today_visits_path(:organization_key => @organization.key) end def day diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2050c84f..8a0bb38a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -30,8 +30,14 @@ def time_ago_in_words(from_time, include_seconds=false) distance_of_time_in_words(from_time, Time.zone.now, include_seconds) end - def tab_item(label, path) - "
  • #{label}
  • " + def tab_item(label, tab_path, request_path, params = { :select_children => false}) + selected = false + if params[:select_children] + selected = request_path.start_with?(tab_path) + else + selected = tab_path == request_path + end + "
  • #{label}
  • " end def today_visits_path(params={}) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index e132023a..e346ef52 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -46,15 +46,15 @@ %div#application_nav.flex-column %ul.tabs -if @organization && !@organization.new_record? - = tab_item('Home', organization_path(@organization)) - = tab_item('Visits', today_visits_path(:organization_key => @organization.key)) - = tab_item('Reports', report_path(:action => 'index', :organization_key => @organization.key)) + = tab_item('Home', organization_path(@organization), request.path, ) + = tab_item('Visits', default_visits_path(:organization_key => @organization.key), request.path, :select_children => true) + = tab_item('Reports', report_path(:action => 'index', :organization_key => @organization.key), request.path, :select_children => true) -if permit? "admin or (manager of :organization)" - =tab_item('Settings', edit_organization_path(@organization)) + =tab_item('Settings', edit_organization_path(@organization), request.path) -else - =tab_item('Home', root_path) + =tab_item('Home', root_path, request.path) -if logged_in? && !current_user.organization.nil? - = tab_item(current_user.organization.name, organization_path(current_user.organization)) + = tab_item(current_user.organization.name, organization_path(current_user.organization), request.path) %div.content#application_body.flex-container = yield %div{:style => 'clear:both;'} diff --git a/config/routes.rb b/config/routes.rb index 3976db7d..0752cd25 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,6 +22,9 @@ :controller => 'visits', :action => 'day', :requirements => {:year => /\d{4}/, :day => /\d{1,2}/, :month => /\d{1,2}/} + map.default_visits ':organization_key/visits', + :controller => 'visits', :action => 'today' + map.reports ':organization_key/reports', :controller => 'reports', :action => 'index' map.report ':organization_key/reports/:action', :controller => 'reports' diff --git a/test/functional/application_helper_test.rb b/test/functional/application_helper_test.rb new file mode 100644 index 00000000..ae7d3a0d --- /dev/null +++ b/test/functional/application_helper_test.rb @@ -0,0 +1,16 @@ +require 'test_helper' + +class ApplicationHelperTest < ActiveSupport::TestCase + + def test_tab_item + assert_match /selected/, tab_item('Home', '/', '/') + assert_match /selected/, tab_item('Home', '/sfbk', '/sfbk') + assert_no_match /selected/, tab_item('Home', '/sfbk', '/sfbk/edit') + assert_match /selected/, tab_item('Visits', '/sfbk/visits', '/sfbk/visits', :select_children => true) + assert_match /selected/, tab_item('Visits', '/sfbk/visits', '/sfbk/visits/2020/1/21', :select_children => true) + assert_match /selected/, tab_item('Reports', '/sfbk/reports', '/sfbk/reports', :select_children => true) + assert_match /selected/, tab_item('Reports', '/sfbk/reports', '/sfbk/reports/visits', :select_children => true) + assert_match /selected/, tab_item('Settings', '/sfbk/edit', '/sfbk/edit') + assert_no_match /selected/, tab_item('Settings', '/sfbk', '/sfbk/edit') + end +end diff --git a/test/functional/visits_controller_test.rb b/test/functional/visits_controller_test.rb index 8c984805..98501ad5 100644 --- a/test/functional/visits_controller_test.rb +++ b/test/functional/visits_controller_test.rb @@ -116,4 +116,9 @@ def test_visits_for_day assert_equal 0, assigns(:groups)[:volunteers].size assert_equal 2, assigns(:groups)[:patrons].size end + + def test_visits_for_today + get :today, :organization_key => 'sfbk' + assert_redirected_to today_visits_path(:organization_key => 'sfbk') + end end