-
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.
Use dropdown for course states, remove stepper term, add state change
validations for course model
- Loading branch information
Showing
13 changed files
with
174 additions
and
94 deletions.
There are no files selected for viewing
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
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
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,35 @@ | ||
# 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 Dropdown::Events::Courses | ||
class State < ::Dropdown::Base | ||
|
||
attr_reader :course, :template | ||
|
||
delegate :t, to: :template | ||
|
||
def initialize(template, course) | ||
@course = course | ||
@template = template | ||
super(template, current_state_label, :'exchange-alt') | ||
init_items | ||
end | ||
|
||
private | ||
|
||
def current_state_label | ||
t("activerecord.attributes.event/course.states.#{course.state}") | ||
end | ||
|
||
def init_items | ||
course.available_states.each do |step| | ||
link = template.state_group_event_path(template.params[:group_id], course, { state: step }) | ||
add_item(template.t(".state_buttons.#{step}"), link, method: :put) | ||
end | ||
end | ||
end | ||
end |
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,50 @@ | ||
# 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 Events::Courses::State | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
# key: current state | ||
# value: possible next state | ||
SAC_COURSE_STATES = | ||
{ created: [:application_open], | ||
application_open: [:application_paused, :created, :canceled], | ||
application_paused: [:application_open], | ||
application_closed: [:assignment_closed, :canceled], | ||
assignment_closed: [:ready, :canceled], | ||
ready: [:closed, :canceled], | ||
canceled: [:application_open], | ||
closed: [:ready] | ||
}.freeze | ||
|
||
self.possible_states = SAC_COURSE_STATES.keys.collect(&:to_s) | ||
|
||
validate :assert_valid_state_change, if: :state_changed? | ||
before_create :set_default_state | ||
end | ||
|
||
def available_states(state = self.state) | ||
SAC_COURSE_STATES[state.to_sym] | ||
end | ||
|
||
def state_possible?(new_state) | ||
available_states.any?(new_state.to_sym) | ||
end | ||
|
||
private | ||
|
||
def assert_valid_state_change | ||
unless available_states(state_was).include?(state.to_sym) | ||
errors.add(:state, "State cannot be changed from #{state_was} to #{state}") | ||
end | ||
end | ||
|
||
def set_default_state | ||
self.state = :created | ||
end | ||
end |
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
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
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
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
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
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
Oops, something went wrong.