-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor sac membership config forms
- Loading branch information
Showing
29 changed files
with
333 additions
and
681 deletions.
There are no files selected for viewing
27 changes: 0 additions & 27 deletions
27
app/components/sac_membership_configs/article_number_field_rows_component.rb
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
app/components/sac_membership_configs/field_rows_component.html.haml
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
app/components/sac_membership_configs/field_rows_component.rb
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
app/components/sac_membership_configs/valid_from_selector_component.html.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
%ul.pagination.pagination-sm | ||
- @available_configs.each do |config| | ||
%li.page-item{ class: [active?(config) && 'active'] } | ||
%li.page-item{ class: item_class(config) } | ||
= link_to_edit_config(config) | ||
%li.page-item{ class: [entry.new_record? && 'active'] } | ||
%li.page-item{ class: new_item_class } | ||
= link_new_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
app/components/sac_section_membership_configs/reduction_field_rows_component.rb
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
app/components/sac_section_membership_configs/valid_from_selector_component.html.haml
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
app/components/sac_section_membership_configs/valid_from_selector_component.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# 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 MembershipConfigurable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
helper_method :cancel_url, :available_configs, :group | ||
before_action :assert_group_type | ||
end | ||
|
||
def index | ||
redirect_to latest_config_entry_path | ||
end | ||
|
||
def show | ||
redirect_to edit_path(find_entry) | ||
end | ||
|
||
private | ||
|
||
def build_entry | ||
if latest_config | ||
attrs = latest_config.attributes | ||
attrs.delete('id') | ||
attrs[:valid_from] = latest_config.valid_from + 1 | ||
else | ||
attrs = new_entry_values | ||
end | ||
model_class.new(attrs) | ||
end | ||
|
||
def latest_config_entry_path | ||
if latest_config | ||
edit_path(latest_config) | ||
else | ||
new_path | ||
end | ||
end | ||
|
||
def find_entry | ||
group_configs.find(params[:id]) | ||
end | ||
|
||
def edit_path(config) | ||
polymorphic_path([group, config], action: :edit) | ||
end | ||
|
||
def new_path | ||
polymorphic_path([group, model_class], action: :new) | ||
end | ||
|
||
def cancel_url | ||
group_path(id: group.id) | ||
end | ||
|
||
def available_configs | ||
@available_configs ||= group_configs.list.to_a | ||
end | ||
|
||
def group_configs | ||
model_class.all | ||
end | ||
|
||
def latest_config | ||
available_configs.last | ||
end | ||
|
||
end |
Oops, something went wrong.