mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-01 12:24:28 +01:00
availability type filter
This commit is contained in:
parent
c1cdea18f3
commit
066458ca70
@ -9,18 +9,20 @@ Application.Controllers.controller "CalendarController", ["$scope", "$state", "$
|
|||||||
|
|
||||||
|
|
||||||
### PRIVATE STATIC CONSTANTS ###
|
### PRIVATE STATIC CONSTANTS ###
|
||||||
|
availableTypes = ['machines', 'training', 'event']
|
||||||
|
availabilitySource =
|
||||||
|
url: "/api/availabilities/public?#{$.param({available_type: availableTypes})}"
|
||||||
|
textColor: 'black'
|
||||||
|
|
||||||
|
|
||||||
### PUBLIC SCOPE ###
|
### PUBLIC SCOPE ###
|
||||||
|
|
||||||
## add availabilities url to event sources
|
## add availabilities source to event sources
|
||||||
$scope.eventSources = []
|
$scope.eventSources = []
|
||||||
$scope.eventSources.push
|
|
||||||
url: '/api/availabilities/public'
|
|
||||||
textColor: 'black'
|
|
||||||
|
|
||||||
## fullCalendar (v2) configuration
|
## fullCalendar (v2) configuration
|
||||||
$scope.calendarConfig = CalendarConfig
|
$scope.calendarConfig = CalendarConfig
|
||||||
|
events: availabilitySource.url
|
||||||
slotEventOverlap: true
|
slotEventOverlap: true
|
||||||
header:
|
header:
|
||||||
left: 'month agendaWeek agendaDay'
|
left: 'month agendaWeek agendaDay'
|
||||||
@ -35,6 +37,15 @@ Application.Controllers.controller "CalendarController", ["$scope", "$state", "$
|
|||||||
eventRender: (event, element, view) ->
|
eventRender: (event, element, view) ->
|
||||||
eventRenderCb(event, element)
|
eventRenderCb(event, element)
|
||||||
|
|
||||||
|
$scope.filterAvailableType = (type) ->
|
||||||
|
index = availableTypes.indexOf(type)
|
||||||
|
if index != -1
|
||||||
|
availableTypes.splice(index, 1)
|
||||||
|
else
|
||||||
|
availableTypes.push(type)
|
||||||
|
availabilitySource.url = "/api/availabilities/public?#{$.param({available_type: availableTypes})}"
|
||||||
|
$scope.calendarConfig.events = availabilitySource.url
|
||||||
|
|
||||||
|
|
||||||
### PRIVATE SCOPE ###
|
### PRIVATE SCOPE ###
|
||||||
|
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
|
|
||||||
<div class="col-xs-12 col-sm-12 col-md-3 b-t hide-b-md">
|
<div class="col-xs-12 col-sm-12 col-md-3 b-t hide-b-md">
|
||||||
<section class="heading-actions wrapper">
|
<section class="heading-actions wrapper">
|
||||||
<span class="badge text-sm bg-formation m-t-md" translate>{{ 'trainings' }}</span>
|
<span class="badge text-sm bg-formation m-t-md" translate ng-click="filterAvailableType('training')">{{ 'trainings' }}</span>
|
||||||
<span class="badge text-sm bg-machine" translate>{{ 'machines' }}</span>
|
<span class="badge text-sm bg-machine" translate ng-click="filterAvailableType('machines')">{{ 'machines' }}</span>
|
||||||
<span class="badge text-sm bg-event" translate>{{ 'events' }}</span>
|
<span class="badge text-sm bg-event" translate ng-click="filterAvailableType('event')">{{ 'events' }}</span>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -17,11 +17,12 @@ class API::AvailabilitiesController < API::ApiController
|
|||||||
def public
|
def public
|
||||||
start_date = ActiveSupport::TimeZone[params[:timezone]].parse(params[:start])
|
start_date = ActiveSupport::TimeZone[params[:timezone]].parse(params[:start])
|
||||||
end_date = ActiveSupport::TimeZone[params[:timezone]].parse(params[:end]).end_of_day
|
end_date = ActiveSupport::TimeZone[params[:timezone]].parse(params[:end]).end_of_day
|
||||||
|
available_type = params[:available_type] || []
|
||||||
@reservations = Reservation.includes(:slots, user: [:profile]).references(:slots, :user).where('slots.start_at >= ? AND slots.end_at <= ?', start_date, end_date)
|
@reservations = Reservation.includes(:slots, user: [:profile]).references(:slots, :user).where('slots.start_at >= ? AND slots.end_at <= ?', start_date, end_date)
|
||||||
if in_same_day(start_date, end_date)
|
if in_same_day(start_date, end_date)
|
||||||
@training_and_event_availabilities = Availability.includes(:tags, :trainings, :event, :slots).where.not(available_type: 'machines')
|
@training_and_event_availabilities = Availability.includes(:tags, :trainings, :event, :slots).where(available_type: available_type.dup.delete_if {|t| t == 'machines'})
|
||||||
.where('start_at >= ? AND end_at <= ?', start_date, end_date)
|
.where('start_at >= ? AND end_at <= ?', start_date, end_date)
|
||||||
@machine_availabilities = Availability.includes(:tags, :machines).where(available_type: 'machines')
|
@machine_availabilities = Availability.includes(:tags, :machines).where(available_type: available_type.dup.delete_if {|t| t == 'training' or t == 'event'})
|
||||||
.where('start_at >= ? AND end_at <= ?', start_date, end_date)
|
.where('start_at >= ? AND end_at <= ?', start_date, end_date)
|
||||||
@machine_slots = []
|
@machine_slots = []
|
||||||
@machine_availabilities.each do |a|
|
@machine_availabilities.each do |a|
|
||||||
@ -37,6 +38,7 @@ class API::AvailabilitiesController < API::ApiController
|
|||||||
else
|
else
|
||||||
|
|
||||||
@availabilities = Availability.includes(:tags, :machines, :trainings, :event, :slots)
|
@availabilities = Availability.includes(:tags, :machines, :trainings, :event, :slots)
|
||||||
|
.where(available_type: available_type)
|
||||||
.where('start_at >= ? AND end_at <= ?', start_date, end_date)
|
.where('start_at >= ? AND end_at <= ?', start_date, end_date)
|
||||||
@availabilities.each do |a|
|
@availabilities.each do |a|
|
||||||
a = verify_training_event_is_reserved(a, @reservations)
|
a = verify_training_event_is_reserved(a, @reservations)
|
||||||
|
@ -3,6 +3,7 @@ json.array!(@availabilities) do |availability|
|
|||||||
json.title availability.title
|
json.title availability.title
|
||||||
json.start availability.start_at.iso8601
|
json.start availability.start_at.iso8601
|
||||||
json.end availability.end_at.iso8601
|
json.end availability.end_at.iso8601
|
||||||
|
json.textColor 'black'
|
||||||
json.backgroundColor 'white'
|
json.backgroundColor 'white'
|
||||||
# availability object
|
# availability object
|
||||||
if availability.try(:available_type)
|
if availability.try(:available_type)
|
||||||
|
Loading…
Reference in New Issue
Block a user