mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-29 18:52:22 +01:00
[ongoing] display spaces in public calendar
This commit is contained in:
parent
4703350de5
commit
a0e7e7951f
@ -4,14 +4,15 @@
|
||||
# Controller used in the public calendar global
|
||||
##
|
||||
|
||||
Application.Controllers.controller "CalendarController", ["$scope", "$state", "$aside", "moment", "Availability", 'Slot', 'Setting', 'growl', 'dialogs', 'bookingWindowStart', 'bookingWindowEnd', '_t', 'uiCalendarConfig', 'CalendarConfig', 'trainingsPromise', 'machinesPromise',
|
||||
($scope, $state, $aside, moment, Availability, Slot, Setting, growl, dialogs, bookingWindowStart, bookingWindowEnd, _t, uiCalendarConfig, CalendarConfig, trainingsPromise, machinesPromise) ->
|
||||
Application.Controllers.controller "CalendarController", ["$scope", "$state", "$aside", "moment", "Availability", 'Slot', 'Setting', 'growl', 'dialogs', 'bookingWindowStart', 'bookingWindowEnd', '_t', 'uiCalendarConfig', 'CalendarConfig', 'trainingsPromise', 'machinesPromise', 'spacesPromise',
|
||||
($scope, $state, $aside, moment, Availability, Slot, Setting, growl, dialogs, bookingWindowStart, bookingWindowEnd, _t, uiCalendarConfig, CalendarConfig, trainingsPromise, machinesPromise, spacesPromise) ->
|
||||
|
||||
|
||||
### PRIVATE STATIC CONSTANTS ###
|
||||
currentMachineEvent = null
|
||||
machinesPromise.forEach((m) -> m.checked = true)
|
||||
trainingsPromise.forEach((t) -> t.checked = true)
|
||||
spacesPromise.forEach((s) -> s.checked = true)
|
||||
|
||||
## check all formation/machine is select in filter
|
||||
isSelectAll = (type, scope) ->
|
||||
@ -25,6 +26,9 @@ Application.Controllers.controller "CalendarController", ["$scope", "$state", "$
|
||||
## List of machines
|
||||
$scope.machines = machinesPromise
|
||||
|
||||
## List of spaces
|
||||
$scope.spaces = spacesPromise
|
||||
|
||||
## add availabilities source to event sources
|
||||
$scope.eventSources = []
|
||||
|
||||
@ -34,6 +38,7 @@ Application.Controllers.controller "CalendarController", ["$scope", "$state", "$
|
||||
scope.filter = $scope.filter =
|
||||
trainings: isSelectAll('trainings', scope)
|
||||
machines: isSelectAll('machines', scope)
|
||||
spaces: isSelectAll('spaces', scope)
|
||||
evt: filter.evt
|
||||
dispo: filter.dispo
|
||||
$scope.calendarConfig.events = availabilitySourceUrl()
|
||||
@ -43,6 +48,7 @@ Application.Controllers.controller "CalendarController", ["$scope", "$state", "$
|
||||
$scope.filter =
|
||||
trainings: isSelectAll('trainings', $scope)
|
||||
machines: isSelectAll('machines', $scope)
|
||||
spaces: isSelectAll('spaces', $scope)
|
||||
evt: true
|
||||
dispo: true
|
||||
|
||||
@ -62,15 +68,18 @@ Application.Controllers.controller "CalendarController", ["$scope", "$state", "$
|
||||
$scope.trainings
|
||||
machines: ->
|
||||
$scope.machines
|
||||
spaces: ->
|
||||
$scope.spaces
|
||||
filter: ->
|
||||
$scope.filter
|
||||
toggleFilter: ->
|
||||
$scope.toggleFilter
|
||||
filterAvailabilities: ->
|
||||
$scope.filterAvailabilities
|
||||
controller: ['$scope', '$uibModalInstance', 'trainings', 'machines', 'filter', 'toggleFilter', 'filterAvailabilities', ($scope, $uibModalInstance, trainings, machines, filter, toggleFilter, filterAvailabilities) ->
|
||||
controller: ['$scope', '$uibModalInstance', 'trainings', 'machines', 'spaces', 'filter', 'toggleFilter', 'filterAvailabilities', ($scope, $uibModalInstance, trainings, machines, spaces, filter, toggleFilter, filterAvailabilities) ->
|
||||
$scope.trainings = trainings
|
||||
$scope.machines = machines
|
||||
$scope.spaces = spaces
|
||||
$scope.filter = filter
|
||||
|
||||
$scope.toggleFilter = (type, filter) ->
|
||||
@ -94,6 +103,9 @@ Application.Controllers.controller "CalendarController", ["$scope", "$state", "$
|
||||
currentMachineEvent = event
|
||||
calendar.fullCalendar('changeView', 'agendaDay')
|
||||
calendar.fullCalendar('gotoDate', event.start)
|
||||
else if event.available_type == 'space'
|
||||
calendar.fullCalendar('changeView', 'agendaDay')
|
||||
calendar.fullCalendar('gotoDate', event.start)
|
||||
else
|
||||
if event.available_type == 'event'
|
||||
$state.go('app.public.events_show', {id: event.event_id})
|
||||
|
@ -640,6 +640,9 @@ angular.module('application.router', ['ui.router']).
|
||||
machinesPromise: ['Machine', (Machine)->
|
||||
Machine.query().$promise
|
||||
]
|
||||
spacesPromise: ['Space', (Space) ->
|
||||
Space.query().$promise
|
||||
]
|
||||
translations: [ 'Translations', (Translations) ->
|
||||
Translations.query(['app.public.calendar']).$promise
|
||||
]
|
||||
|
@ -40,4 +40,5 @@
|
||||
.text-purple { color: $violet !important; }
|
||||
.text-japonica { color: $japonica !important; }
|
||||
.text-beige { color: $beige !important; }
|
||||
.text-cyan { color: $cyan !important; }
|
||||
.text-green, .green { color: #79C84A !important; }
|
||||
|
@ -7,14 +7,14 @@
|
||||
</div>
|
||||
<div class="col-xs-10 col-sm-10 col-md-8 b-l b-r-md hide-b-r-lg">
|
||||
<section class="heading-title">
|
||||
<h1 translate>{{ 'calendar' }}</h1>
|
||||
<h1 translate>{{ 'calendar.calendar' }}</h1>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-sm-12 col-md-3 b-t hide-b-md hidden-lg">
|
||||
<div class="heading-actions wrapper">
|
||||
<button type="button" class="btn btn-default m-t m-b" ng-click="openFilterAside()">
|
||||
<span class="fa fa-filter"></span> {{ 'filter-calendar' | translate }}
|
||||
<span class="fa fa-filter"></span> {{ 'calendar.filter_calendar' | translate }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@ -38,7 +38,7 @@
|
||||
<div class="col-lg-3 hidden-md hidden-sm hidden-xs">
|
||||
<div class="widget panel b-a m m-t-lg">
|
||||
<div class="panel-heading b-b small">
|
||||
<h3 translate>{{ 'filter-calendar' }}</h3>
|
||||
<h3 translate>{{ 'calendar.filter_calendar' }}</h3>
|
||||
</div>
|
||||
<div class="widget-content no-bg auto wrapper calendar-filter">
|
||||
<ng-include src="'<%= asset_path 'calendar/filter.html' %>'"></ng-include>
|
||||
@ -53,7 +53,7 @@
|
||||
<div class="widget">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" ng-click="close($event)"><span>×</span></button>
|
||||
<h1 class="modal-title" translate>{{ 'filter-calendar' }}</h1>
|
||||
<h1 class="modal-title" translate>{{ 'calendar.filter_calendar' }}</h1>
|
||||
</div>
|
||||
<div class="modal-body widget-content calendar-filter calendar-filter-aside">
|
||||
<ng-include src="'<%= asset_path 'calendar/filter.html' %>'"></ng-include>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<div>
|
||||
<div class="row">
|
||||
<h3 class="col-md-11 col-sm-11 col-xs-11 text-purple" translate>{{ 'trainings' }}</h3>
|
||||
<h3 class="col-md-11 col-sm-11 col-xs-11 text-purple" translate>{{ 'calendar.trainings' }}</h3>
|
||||
<input class="col-md-1 col-sm-1 col-xs-1" type="checkbox" ng-model="filter.trainings" ng-change="toggleFilter('trainings', filter)">
|
||||
</div>
|
||||
<div ng-repeat="t in trainings" class="row">
|
||||
@ -10,7 +10,7 @@
|
||||
</div>
|
||||
<div class="m-t">
|
||||
<div class="row">
|
||||
<h3 class="col-md-11 col-sm-11 col-xs-11 text-beige" translate>{{ 'machines' }}</h3>
|
||||
<h3 class="col-md-11 col-sm-11 col-xs-11 text-beige" translate>{{ 'calendar.machines' }}</h3>
|
||||
<input class="col-md-1 col-sm-1 col-xs-1" type="checkbox" ng-model="filter.machines" ng-change="toggleFilter('machines', filter)">
|
||||
</div>
|
||||
<div ng-repeat="m in machines" class="row">
|
||||
@ -18,11 +18,21 @@
|
||||
<input class="col-md-1 col-sm-1 col-xs-1" type="checkbox" ng-model="m.checked" ng-change="filterAvailabilities(filter)">
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-t">
|
||||
<div class="row">
|
||||
<h3 class="col-md-11 col-sm-11 col-xs-11 text-cyan" translate>{{ 'calendar.spaces' }}</h3>
|
||||
<input class="col-md-1 col-sm-1 col-xs-1" type="checkbox" ng-model="filter.machines" ng-change="toggleFilter('spaces', filter)">
|
||||
</div>
|
||||
<div ng-repeat="s in spaces" class="row">
|
||||
<span class="col-md-11 col-sm-11 col-xs-11">{{::s.name}}</span>
|
||||
<input class="col-md-1 col-sm-1 col-xs-1" type="checkbox" ng-model="s.checked" ng-change="filterAvailabilities(filter)">
|
||||
</div>
|
||||
</div>
|
||||
<div class="m-t row">
|
||||
<h3 class="col-md-11 col-sm-11 col-xs-11 text-japonica" translate>{{ 'events' }}</h3>
|
||||
<h3 class="col-md-11 col-sm-11 col-xs-11 text-japonica" translate>{{ 'calendar.events' }}</h3>
|
||||
<input class="col-md-1 col-sm-1 col-xs-1" type="checkbox" ng-model="filter.evt" ng-change="filterAvailabilities(filter)">
|
||||
</div>
|
||||
<div class="m-t row">
|
||||
<h3 class="col-md-11 col-sm-11 col-xs-11 text-black" translate>{{ 'show_no_disponible' }}</h3>
|
||||
<h3 class="col-md-11 col-sm-11 col-xs-11 text-black" translate>{{ 'calendar.show_unavailables' }}</h3>
|
||||
<input class="col-md-1 col-sm-1 col-xs-1" type="checkbox" ng-model="filter.dispo" ng-change="filterAvailabilities(filter)">
|
||||
</div>
|
||||
|
@ -24,9 +24,13 @@ class API::AvailabilitiesController < API::ApiController
|
||||
start_date = ActiveSupport::TimeZone[params[:timezone]].parse(params[:start])
|
||||
end_date = ActiveSupport::TimeZone[params[:timezone]].parse(params[:end]).end_of_day
|
||||
@reservations = Reservation.includes(:slots, user: [:profile]).references(:slots, :user).where('slots.start_at >= ? AND slots.end_at <= ?', start_date, end_date)
|
||||
|
||||
# request for 1 single day
|
||||
if in_same_day(start_date, end_date)
|
||||
@training_and_event_availabilities = Availability.includes(:tags, :trainings, :event, :slots).where(available_type: ['training', 'event'])
|
||||
# trainings, events
|
||||
@training_and_event_availabilities = Availability.includes(:tags, :trainings, :event, :slots).where(available_type: %w(training event))
|
||||
.where('start_at >= ? AND end_at <= ?', start_date, end_date)
|
||||
# machines
|
||||
@machine_availabilities = Availability.includes(:tags, :machines).where(available_type: 'machines')
|
||||
.where('start_at >= ? AND end_at <= ?', start_date, end_date)
|
||||
@machine_slots = []
|
||||
@ -41,10 +45,27 @@ class API::AvailabilitiesController < API::ApiController
|
||||
end
|
||||
end
|
||||
end
|
||||
@availabilities = [].concat(@training_and_event_availabilities).concat(@machine_slots)
|
||||
|
||||
# spaces
|
||||
@space_availabilities = Availability.includes(:tags, :spaces).where(available_type: 'space')
|
||||
.where('start_at >= ? AND end_at <= ?', start_date, end_date)
|
||||
@space_slots = []
|
||||
@space_availabilities.each do |a|
|
||||
space = a.spaces.first
|
||||
((a.end_at - a.start_at)/SLOT_DURATION.minutes).to_i.times do |i|
|
||||
if (a.start_at + (i * SLOT_DURATION).minutes) > Time.now
|
||||
slot = Slot.new(start_at: a.start_at + (i*SLOT_DURATION).minutes, end_at: a.start_at + (i*SLOT_DURATION).minutes + SLOT_DURATION.minutes, availability_id: a.id, availability: a, space: space, title: space.name)
|
||||
slot = verify_space_is_reserved(slot, @reservations, current_user, '')
|
||||
@space_slots << slot
|
||||
end
|
||||
end
|
||||
end
|
||||
@availabilities = [].concat(@training_and_event_availabilities).concat(@machine_slots).concat(@space_slots)
|
||||
|
||||
# request for many days (week or month)
|
||||
else
|
||||
|
||||
@availabilities = Availability.includes(:tags, :machines, :trainings, :event, :slots)
|
||||
@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'
|
||||
@ -297,6 +318,12 @@ class API::AvailabilitiesController < API::ApiController
|
||||
availabilities_filtered << a
|
||||
end
|
||||
end
|
||||
# space
|
||||
if params[:m] and a.available_type == 'space'
|
||||
if params[:t].include?(a.spaces.first.id.to_s)
|
||||
availabilities_filtered << a
|
||||
end
|
||||
end
|
||||
# machines
|
||||
if params[:m] and a.available_type == 'machines'
|
||||
if (params[:m].map(&:to_i) & a.machine_ids).any?
|
||||
|
@ -5,7 +5,7 @@ json.array!(@availabilities) do |availability|
|
||||
json.textColor 'black'
|
||||
json.backgroundColor 'white'
|
||||
# availability object
|
||||
if availability.try(:available_type)
|
||||
if availability.instance_of? Availability
|
||||
json.title availability.title(@title_filter)
|
||||
if availability.available_type == 'event'
|
||||
json.event_id availability.event.id
|
||||
@ -20,7 +20,7 @@ json.array!(@availabilities) do |availability|
|
||||
json.name t.name
|
||||
end
|
||||
|
||||
if availability.available_type != 'machines'
|
||||
if availability.available_type == 'training' or availability.available_type == 'event'
|
||||
json.borderColor trainings_events_border_color(availability)
|
||||
if availability.is_reserved
|
||||
json.is_reserved true
|
||||
@ -29,20 +29,38 @@ json.array!(@availabilities) do |availability|
|
||||
json.is_completed true
|
||||
json.title "#{availability.title} - #{t('trainings.completed')}"
|
||||
end
|
||||
elsif availability.available_type == 'space'
|
||||
complete = availability.slots.map{ |s| s.is_complete? }.reduce :&
|
||||
json.is_completed complete
|
||||
json.borderColor availability_border_color(availability)
|
||||
if complete
|
||||
json.title "#{availability.title} - #{t('trainings.completed')}"
|
||||
end
|
||||
else
|
||||
json.borderColor availability_border_color(availability)
|
||||
end
|
||||
|
||||
# machine slot object ( here => availability = slot )
|
||||
else
|
||||
# slot object ( here => availability = slot )
|
||||
# -> machines / spaces
|
||||
elsif availability.instance_of? Slot
|
||||
json.title availability.title
|
||||
json.machine_id availability.machine.id
|
||||
json.borderColor machines_slot_border_color(availability)
|
||||
json.tag_ids availability.availability.tag_ids
|
||||
json.tags availability.availability.tags do |t|
|
||||
json.id t.id
|
||||
json.name t.name
|
||||
end
|
||||
json.is_reserved availability.is_reserved
|
||||
if availability.try(:machine)
|
||||
json.machine_id availability.machine.id
|
||||
json.borderColor machines_slot_border_color(availability)
|
||||
json.is_reserved availability.is_reserved
|
||||
elsif availability.try(:space)
|
||||
json.space_id availability.space.id
|
||||
json.borderColor space_slot_border_color(availability)
|
||||
json.is_completed availability.is_complete?
|
||||
else
|
||||
json.title 'Unknown slot'
|
||||
end
|
||||
else
|
||||
json.title 'Unknown object'
|
||||
end
|
||||
end
|
||||
|
@ -249,9 +249,14 @@ en:
|
||||
|
||||
calendar:
|
||||
# public calendar
|
||||
calendar: "Calendar"
|
||||
show_no_disponible: "Show the slots no disponibles"
|
||||
filter-calendar: "Filter calendar"
|
||||
calendar:
|
||||
calendar: "Calendar"
|
||||
show_unavailables: "Show unavailable slots"
|
||||
filter_calendar: "Filter calendar"
|
||||
trainings: "Trainings"
|
||||
machines: "Machines"
|
||||
spaces: "Spaces"
|
||||
events: "Events"
|
||||
|
||||
spaces_list:
|
||||
# list of spaces
|
||||
|
@ -251,9 +251,14 @@ fr:
|
||||
|
||||
calendar:
|
||||
# calendrier publique
|
||||
calendar: "Calendrier"
|
||||
show_no_disponible: "Afficher les crénaux non disponibles"
|
||||
filter-calendar: "Filtrer le calendrier"
|
||||
calendar:
|
||||
calendar: "Calendrier"
|
||||
show_unavailables: "Afficher les créneaux non disponibles"
|
||||
filter_calendar: "Filtrer le calendrier"
|
||||
trainings: "Formations"
|
||||
machines: "Machines"
|
||||
spaces: "Espaces"
|
||||
events: "Évènements"
|
||||
|
||||
spaces_list:
|
||||
# liste des espaces
|
||||
|
Loading…
x
Reference in New Issue
Block a user