mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
display spaces status in client calendar
This commit is contained in:
parent
0e94f8c3d4
commit
c936b283f7
@ -5,7 +5,7 @@ class API::AvailabilitiesController < API::ApiController
|
||||
before_action :set_availability, only: [:show, :update, :destroy, :reservations]
|
||||
respond_to :json
|
||||
|
||||
## machine availabilities are divided in multiple slots of 60 minutes
|
||||
## machine/spaces availabilities are divided in multiple slots of 60 minutes
|
||||
SLOT_DURATION = 60
|
||||
|
||||
def index
|
||||
@ -68,8 +68,10 @@ class API::AvailabilitiesController < API::ApiController
|
||||
@availabilities = Availability.includes(:tags, :machines, :trainings, :spaces, :event, :slots)
|
||||
.where('start_at >= ? AND end_at <= ?', start_date, end_date)
|
||||
@availabilities.each do |a|
|
||||
if a.available_type != 'machines'
|
||||
if a.available_type == 'training' or a.available_type == 'event'
|
||||
a = verify_training_event_is_reserved(a, @reservations, current_user)
|
||||
elsif a.available_type == 'space'
|
||||
a.is_reserved = is_reserved_availability(a, current_user.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -225,6 +227,16 @@ class API::AvailabilitiesController < API::ApiController
|
||||
:machines_attributes => [:id, :_destroy])
|
||||
end
|
||||
|
||||
def is_reserved_availability(availability, user_id)
|
||||
reserved_slots = []
|
||||
availability.slots.each do |s|
|
||||
if s.canceled_at.nil?
|
||||
reserved_slots << s
|
||||
end
|
||||
end
|
||||
reserved_slots.map(&:reservations).flatten.map(&:user_id).include? user_id
|
||||
end
|
||||
|
||||
def is_reserved(start_at, reservations)
|
||||
is_reserved = false
|
||||
reservations.each do |r|
|
||||
|
@ -1,5 +1,8 @@
|
||||
class Availability < ActiveRecord::Base
|
||||
|
||||
## machine/spaces availabilities are divided in multiple slots of 60 minutes
|
||||
SLOT_DURATION = 60
|
||||
|
||||
# elastic initialisations
|
||||
include Elasticsearch::Model
|
||||
index_name 'fablab'
|
||||
@ -69,6 +72,13 @@ class Availability < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
## compute the total number of places over the whole space availability
|
||||
def available_space_places
|
||||
if available_type === 'space'
|
||||
((end_at - start_at)/SLOT_DURATION.minutes).to_i * nb_total_places
|
||||
end
|
||||
end
|
||||
|
||||
def title(filter = {})
|
||||
case available_type
|
||||
when 'machines'
|
||||
|
@ -30,11 +30,16 @@ json.array!(@availabilities) do |availability|
|
||||
json.title "#{availability.title} - #{t('trainings.completed')}"
|
||||
end
|
||||
elsif availability.available_type == 'space'
|
||||
complete = availability.slots.map{ |s| s.is_complete? }.reduce :&
|
||||
complete = availability.slots.length >= availability.available_space_places
|
||||
json.is_completed complete
|
||||
json.borderColor availability_border_color(availability)
|
||||
if complete
|
||||
json.title "#{availability.title} - #{t('trainings.completed')}"
|
||||
json.borderColor AvailabilityHelper::IS_COMPLETED
|
||||
end
|
||||
if availability.is_reserved
|
||||
json.is_reserved true
|
||||
json.title "#{availability.title} - #{t('trainings.i_ve_reserved')}"
|
||||
end
|
||||
else
|
||||
json.borderColor availability_border_color(availability)
|
||||
|
32
db/schema.rb
32
db/schema.rb
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20170213142543) do
|
||||
ActiveRecord::Schema.define(version: 20170227114634) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -542,15 +542,23 @@ ActiveRecord::Schema.define(version: 20170213142543) do
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "availability_id"
|
||||
t.datetime "ex_start_at"
|
||||
t.datetime "ex_end_at"
|
||||
t.boolean "destroying", default: false
|
||||
t.boolean "offered"
|
||||
t.datetime "canceled_at"
|
||||
t.boolean "offered", default: false
|
||||
t.integer "reservation_id"
|
||||
t.datetime "ex_end_at"
|
||||
t.datetime "ex_start_at"
|
||||
end
|
||||
|
||||
add_index "slots", ["availability_id"], name: "index_slots_on_availability_id", using: :btree
|
||||
|
||||
create_table "slots_reservations", force: :cascade do |t|
|
||||
t.integer "slot_id"
|
||||
t.integer "reservation_id"
|
||||
end
|
||||
|
||||
add_index "slots_reservations", ["reservation_id"], name: "index_slots_reservations_on_reservation_id", using: :btree
|
||||
add_index "slots_reservations", ["slot_id"], name: "index_slots_reservations_on_slot_id", using: :btree
|
||||
|
||||
create_table "spaces", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.integer "default_places"
|
||||
@ -561,6 +569,16 @@ ActiveRecord::Schema.define(version: 20170213142543) do
|
||||
t.text "characteristics"
|
||||
end
|
||||
|
||||
create_table "spaces_availabilities", force: :cascade do |t|
|
||||
t.integer "space_id"
|
||||
t.integer "availability_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "spaces_availabilities", ["availability_id"], name: "index_spaces_availabilities_on_availability_id", using: :btree
|
||||
add_index "spaces_availabilities", ["space_id"], name: "index_spaces_availabilities_on_space_id", using: :btree
|
||||
|
||||
create_table "statistic_custom_aggregations", force: :cascade do |t|
|
||||
t.text "query"
|
||||
t.integer "statistic_type_id"
|
||||
@ -839,6 +857,10 @@ ActiveRecord::Schema.define(version: 20170213142543) do
|
||||
add_foreign_key "prices", "plans"
|
||||
add_foreign_key "projects_spaces", "projects"
|
||||
add_foreign_key "projects_spaces", "spaces"
|
||||
add_foreign_key "slots_reservations", "reservations"
|
||||
add_foreign_key "slots_reservations", "slots"
|
||||
add_foreign_key "spaces_availabilities", "availabilities"
|
||||
add_foreign_key "spaces_availabilities", "spaces"
|
||||
add_foreign_key "statistic_custom_aggregations", "statistic_types"
|
||||
add_foreign_key "tickets", "event_price_categories"
|
||||
add_foreign_key "tickets", "reservations"
|
||||
|
Loading…
x
Reference in New Issue
Block a user