diff --git a/app/helpers/sac_cas/sheet/group/nav_left.rb b/app/helpers/sac_cas/sheet/group/nav_left.rb new file mode 100644 index 000000000..f9c6bbd0a --- /dev/null +++ b/app/helpers/sac_cas/sheet/group/nav_left.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of +# hitobito_sac_cas and licensed under the Affero General Public License version 3 +# or later. See the COPYING file at the top-level directory or at +# https://github.com/hitobito/hitobito_sac_cas + +module SacCas::Sheet::Group::NavLeft + NAME_WITHOUT_PREFIX = "REPLACE(REPLACE(name, 'SAC ', ''), 'CAS ', '')".freeze + + private + + def sub_layers + super.reorder(Arel.sql(NAME_WITHOUT_PREFIX)) + end +end diff --git a/lib/hitobito_sac_cas/wagon.rb b/lib/hitobito_sac_cas/wagon.rb index ec95ee358..3e0d54856 100644 --- a/lib/hitobito_sac_cas/wagon.rb +++ b/lib/hitobito_sac_cas/wagon.rb @@ -105,6 +105,7 @@ class Wagon < Rails::Engine Dropdown::TableDisplays.prepend SacCas::Dropdown::TableDisplays Dropdown::GroupEdit.prepend SacCas::Dropdown::GroupEdit Event::ParticipationButtons.prepend SacCas::Event::ParticipationButtons + Sheet::Group::NavLeft.prepend SacCas::Sheet::Group::NavLeft admin_item = NavigationHelper::MAIN.find { |item| item[:label] == :admin } admin_item[:active_for] += %w(cost_centers cost_units) diff --git a/spec/helpers/sheet/group/nav_left_spec.rb b/spec/helpers/sheet/group/nav_left_spec.rb new file mode 100644 index 000000000..feff0e678 --- /dev/null +++ b/spec/helpers/sheet/group/nav_left_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +# Copyright (c) 2024, Schweizer Alpen-Club. This file is part of +# hitobito_sac_cas and licensed under the Affero General Public License version 3 +# or later. See the COPYING file at the top-level directory or at +# https://github.com/hitobito/hitobito_sac_cas + +require 'spec_helper' + +describe 'Sheet::Group::NavLeft' do + let(:group) { groups(:root) } + let(:sheet) { Sheet::Group.new(self, nil, group) } + let(:nav) { Sheet::Group::NavLeft.new(sheet) } + + let(:request) { ActionController::TestRequest.create({}) } + + let(:html) { nav.render } + subject(:dom) { Capybara::Node::Simple.new(html) } + + def can?(*_args) + true + end + + describe 'ordering of sections' do + let(:links) { dom.all('li').map(&:text) } + let(:sections) { links[links.index('Sektionen')+1..] } + let(:bluemlisalp) { groups(:bluemlisalp) } + let(:matterhorn) { groups(:matterhorn) } + + it 'orders sections by name' do + expect(sections).to eq ['SAC Blüemlisalp', 'SAC Matterhorn'] + end + + it 'ignores cas prefix' do + matterhorn.update!(name: 'CAS Matterhorn') + expect(sections).to eq ['SAC Blüemlisalp', 'CAS Matterhorn'] + end + + it 'ignores sac prefix' do + bluemlisalp.update!(name: 'CAS Blüemlisalp') + matterhorn.update!(name: 'SAC Altels') + expect(sections).to eq ['SAC Altels', 'CAS Blüemlisalp'] + end + end +end