Skip to content

Commit

Permalink
Merge pull request #21 from ulmic/feature/request_end_date
Browse files Browse the repository at this point in the history
 #event fix request collecting state
  • Loading branch information
moshinaan committed Mar 17, 2020
2 parents 28d8ea0 + 3c8b301 commit ebda14c
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def model_given?
end

def form_given?
Tramway::Admin.forms.include? params[:form].underscore.sub(/^admin\//, '').sub(/_form$/, '')
Tramway::Admin.forms.include? params[:form].underscore.sub(%r{^admin/}, '').sub(/_form$/, '')
end

def available_scope_given?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Tramway::Admin::HasAndBelongsToManyRecordsController < ::Tramway::Admin::ApplicationController
def create
base_object = params[:model_class].constantize.find params[:object_id]
Expand Down
6 changes: 4 additions & 2 deletions tramway-admin/app/helpers/tramway/admin/actions_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# frozen_string_literal: true

module Tramway::Admin::ActionsHelper
def destroy_is_available?(association_object, main_object)
def destroy_is_available?(association_object, _main_object)
::Tramway::Admin.action_is_available?(
association_object,
project: (@application_engine || @application.name),
model_name: association_object.model.class.name,
role: current_user.role,
action: :destroy
)
)
end

def habtm_destroy_is_available?(association_object, main_object)
Expand Down
2 changes: 1 addition & 1 deletion tramway-admin/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

resources :records
resource :singleton, only: %i[new create show edit update]
resources :has_and_belongs_to_many_records, only: [ :create, :destroy]
resources :has_and_belongs_to_many_records, only: %i[create destroy]
end
2 changes: 2 additions & 0 deletions tramway-admin/lib/tramway/admin/forms.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Tramway::Admin::Forms
attr_accessor :forms
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def index
actual_events = ::Tramway::Event::EventLinkDecorator.decorate ::Tramway::Event::Event.active.actual.open.order :begin_date
@links = actual_events + past_events_links
@close_events = ::Tramway::Event::Event.actual.open.map do |event|
::Tramway::Event::EventAsPageWithButtonDecorator.decorate event
::Tramway::Event::EventAsPageWithButtonDecorator.decorate event
end
@partners = ::Tramway::Partner::Partnership.partnership_type.values.reduce({}) do |hash, partnership_type|
hash.merge! partnership_type => (@unity.send(partnership_type.to_s.pluralize).active.map do |partner|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Tramway::Core::Associations::ClassHelper
def decorate_association(association_name, decorator: nil, as: nil, state_machines: [])
@@decorated_associations ||= []
Expand All @@ -23,8 +25,6 @@ def decorate_associations(*association_names)
decorate_association association_name
end
end


def define_main_association_method(association_name, decorator)
define_method association_name do
association = object.class.reflect_on_association(association_name)
Expand All @@ -33,7 +33,7 @@ def define_main_association_method(association_name, decorator)
raise error.message
end
decorator_class_name = decorator || "#{class_name(association).to_s.singularize}Decorator".constantize
if association.class.in? [ ActiveRecord::Reflection::HasManyReflection, ActiveRecord::Reflection::HasAndBelongsToManyReflection ]
if association.class.in? [ActiveRecord::Reflection::HasManyReflection, ActiveRecord::Reflection::HasAndBelongsToManyReflection]
return object.send(association_name).active.map do |association_object|
decorator_class_name.decorate association_object
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Tramway::Core::Associations::ObjectHelper
def class_name(association)
if association.polymorphic?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.create_form_class(uuid, event, **simple_properties)
def self.build_validations(field)
case field.field_type
when 'checkbox'
field.validations.except('presence').deep_merge! inclusion: { in: [ 'true' ] }
field.validations.except('presence').deep_merge! inclusion: { in: ['true'] }
else
field.validations
end
Expand Down
4 changes: 2 additions & 2 deletions tramway-event/app/models/tramway/event/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def check_dimensions
def request_collecting_state
return :not_initialized unless request_collecting_begin_date.present? || request_collecting_end_date.present?
return :will_begin_soon if request_collecting_begin_date > DateTime.now
return :is_over if request_collecting_end_date.present? && request_collecting_end_date < DateTime.now
return :are_being_right_now if request_collecting_begin_date&.past? && request_collecting_end_date&.future?
return :is_over if request_collecting_end_date.present? && request_collecting_end_date.to_date < Date.today
return :are_being_right_now if request_collecting_begin_date&.past? && (request_collecting_end_date&.future? || request_collecting_end_date&.today?)
return :are_being_right_now if request_collecting_begin_date < DateTime.now && !request_collecting_end_date.present?
end

Expand Down

0 comments on commit ebda14c

Please sign in to comment.