Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order sections by name without prefix, (#523) #529

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/helpers/sac_cas/sheet/group/nav_left.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lib/hitobito_sac_cas/wagon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
45 changes: 45 additions & 0 deletions spec/helpers/sheet/group/nav_left_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading