mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
[ongoing] create multiple availabilities according to UI
This commit is contained in:
parent
0d740c95a9
commit
a60a39ff9e
@ -9,6 +9,7 @@
|
||||
- Fix a security issue: fixed [CVE-2019-15587](https://github.com/advisories/GHSA-c3gv-9cxf-6f57)
|
||||
- [TODO DEPLOY] add the `SLOT_DURATION` environment variable (see [doc/environment.md](doc/environment.md#SLOT_DURATION) for configuration details)
|
||||
- [TODO DEPLOY] -> (only dev) `bundle install`
|
||||
- [TODO DEPLOY] `rake db:migrate`
|
||||
|
||||
## v4.2.4 2019 October 30
|
||||
|
||||
|
@ -476,9 +476,13 @@ Application.Controllers.controller('CreateEventModalController', ['$scope', '$ui
|
||||
} else if ($scope.availability.available_type === 'space') {
|
||||
$scope.availability.space_ids = [$scope.selectedSpace.id];
|
||||
}
|
||||
if ($scope.availability.is_recurrent) {
|
||||
$scope.availability.occurrences = $scope.occurrences;
|
||||
}
|
||||
return Availability.save(
|
||||
{ availability: $scope.availability }
|
||||
, function (availability) { $uibModalInstance.close(availability); });
|
||||
{ availability: $scope.availability },
|
||||
function (availability) { $uibModalInstance.close(availability); }
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -47,6 +47,8 @@ class API::AvailabilitiesController < API::ApiController
|
||||
def create
|
||||
authorize Availability
|
||||
@availability = Availability.new(availability_params)
|
||||
service = Availabilities::CreateAvailabilitiesService.new
|
||||
service.create(@availability, params[:availability][:occurrences])
|
||||
if @availability.save
|
||||
render :show, status: :created, location: @availability
|
||||
else
|
||||
@ -140,6 +142,7 @@ class API::AvailabilitiesController < API::ApiController
|
||||
|
||||
def availability_params
|
||||
params.require(:availability).permit(:start_at, :end_at, :available_type, :machine_ids, :training_ids, :nb_total_places,
|
||||
:is_recurrent, :period, :nb_periods, :end_date,
|
||||
machine_ids: [], training_ids: [], space_ids: [], tag_ids: [],
|
||||
machines_attributes: %i[id _destroy])
|
||||
end
|
||||
|
@ -36,7 +36,7 @@ class Availability < ActiveRecord::Base
|
||||
attr_accessor :is_reserved, :slot_id, :can_modify
|
||||
|
||||
validates :start_at, :end_at, presence: true
|
||||
validate :length_must_be_1h_minimum, unless: proc { end_at.blank? or start_at.blank? }
|
||||
validate :length_must_be_slot_multiple, unless: proc { end_at.blank? or start_at.blank? }
|
||||
validate :should_be_associated
|
||||
|
||||
## elastic callbacks
|
||||
@ -155,8 +155,10 @@ class Availability < ActiveRecord::Base
|
||||
|
||||
private
|
||||
|
||||
def length_must_be_1h_minimum
|
||||
errors.add(:end_at, I18n.t('availabilities.must_be_at_least_1_hour_after_the_start_date')) if end_at < (start_at + 1.hour)
|
||||
def length_must_be_slot_multiple
|
||||
if end_at < (start_at + Rails.application.secrets.slot_duration.minutes)
|
||||
errors.add(:end_at, I18n.t('availabilities.length_must_be_slot_multiple', MIN: Rails.application.secrets.slot_duration))
|
||||
end
|
||||
end
|
||||
|
||||
def should_be_associated
|
||||
|
25
app/services/availabilities/create_availabilities_service.rb
Normal file
25
app/services/availabilities/create_availabilities_service.rb
Normal file
@ -0,0 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Provides helper methods toi create an Availability with multiple occurrences
|
||||
class Availabilities::CreateAvailabilitiesService
|
||||
def create(availability, occurrences)
|
||||
availability.update_attributes(occurrence_id: availability.id)
|
||||
|
||||
occurrences.each do |o|
|
||||
Availability.new(
|
||||
start_at: o[:start_at],
|
||||
end_at: o[:end_at],
|
||||
available_type: availability.available_type,
|
||||
is_recurrent: availability.is_recurrent,
|
||||
period: availability.period,
|
||||
nb_periods: availability.nb_periods,
|
||||
end_date: availability.end_date,
|
||||
occurrence_id: availability.occurrence_id,
|
||||
machine_ids: availability.machine_ids,
|
||||
training_ids: availability.training_ids,
|
||||
space_ids: availability.space_ids,
|
||||
tag_ids: availability.tag_ids
|
||||
).save!
|
||||
end
|
||||
end
|
||||
end
|
@ -62,7 +62,7 @@ en:
|
||||
# availability slots in the calendar
|
||||
not_available: "Not available"
|
||||
i_ve_reserved: "I've reserved"
|
||||
must_be_at_least_1_hour_after_the_start_date: "must be at least 1 hour after the start date"
|
||||
length_must_be_slot_multiple: "must be at least %{MIN} minutes after the start date"
|
||||
must_be_associated_with_at_least_1_machine: "must be associated with at least 1 machine"
|
||||
|
||||
members:
|
||||
|
@ -62,7 +62,7 @@ es:
|
||||
# availability slots in the calendar
|
||||
not_available: "No disponible"
|
||||
i_ve_reserved: "He reservado"
|
||||
must_be_at_least_1_hour_after_the_start_date: "Debe ser al menos 1 hora después de la fecha de inicio"
|
||||
length_must_be_slot_multiple: "Debe ser al menos %{MIN} minutos después de la fecha de inicio"
|
||||
must_be_associated_with_at_least_1_machine: "debe estar asociado con al menos 1 máquina"
|
||||
|
||||
members:
|
||||
|
@ -62,7 +62,7 @@ fr:
|
||||
# créneaux de disponibilité dans le calendrier
|
||||
not_available: "Non disponible"
|
||||
i_ve_reserved: "J'ai réservé"
|
||||
must_be_at_least_1_hour_after_the_start_date: "doit être au moins 1 heure après la date de début"
|
||||
length_must_be_slot_multiple: "doit être au moins %{MIN} minutes après la date de début"
|
||||
must_be_associated_with_at_least_1_machine: "doit être associé avec au moins 1 machine"
|
||||
|
||||
members:
|
||||
|
@ -62,7 +62,7 @@ pt:
|
||||
# availability slots in the calendar
|
||||
not_available: "Não disponível "
|
||||
i_ve_reserved: "Eu reservei"
|
||||
must_be_at_least_1_hour_after_the_start_date: "deve ser pelo menos 1 hora após a data de início"
|
||||
length_must_be_slot_multiple: "deve ser pelo menos %{MIN} minutos após a data de início"
|
||||
must_be_associated_with_at_least_1_machine: "deve estar associada a pelo menos uma máquina"
|
||||
|
||||
members:
|
||||
|
@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# From this migration, we store recurrence info into the availability object, the availability can be linked to others, which are
|
||||
# its "children".
|
||||
class AddRecurrenceToAvailabilities < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :availabilities, :is_recurrent, :boolean
|
||||
add_column :availabilities, :occurrence_id, :integer
|
||||
add_column :availabilities, :period, :string
|
||||
add_column :availabilities, :nb_periods, :integer
|
||||
add_column :availabilities, :end_date, :datetime
|
||||
end
|
||||
end
|
@ -11,12 +11,12 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20190924140726) do
|
||||
ActiveRecord::Schema.define(version: 20191113103352) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
enable_extension "unaccent"
|
||||
enable_extension "pg_trgm"
|
||||
enable_extension "unaccent"
|
||||
|
||||
create_table "abuses", force: :cascade do |t|
|
||||
t.integer "signaled_id"
|
||||
@ -92,6 +92,11 @@ ActiveRecord::Schema.define(version: 20190924140726) do
|
||||
t.integer "nb_total_places"
|
||||
t.boolean "destroying", default: false
|
||||
t.boolean "lock", default: false
|
||||
t.boolean "is_recurrent"
|
||||
t.integer "occurrence_id"
|
||||
t.string "period"
|
||||
t.integer "nb_periods"
|
||||
t.datetime "end_date"
|
||||
end
|
||||
|
||||
create_table "availability_tags", force: :cascade do |t|
|
||||
|
Loading…
x
Reference in New Issue
Block a user