1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-30 11:24:21 +01:00

[feature] per training planning w/ ability to switch back to global view

This commit is contained in:
Sylvain 2016-06-27 15:00:23 +02:00
parent d313d7ff87
commit 05fa32cdd4
9 changed files with 63 additions and 14 deletions

View File

@ -45,8 +45,8 @@ Application.Controllers.controller "ShowTrainingController", ['$scope', '$state'
# training can be reserved during the reservation process (the shopping cart may contains only one training and a subscription).
##
Application.Controllers.controller "ReserveTrainingController", ["$scope", "$state", '$stateParams', "$uibModal", 'Auth', 'dialogs', '$timeout', 'Price', 'Availability', 'Slot', 'Member', 'Setting', 'CustomAsset', '$compile', 'availabilityTrainingsPromise', 'plansPromise', 'groupsPromise', 'growl', 'settingsPromise', '_t',
($scope, $state, $stateParams, $uibModal, Auth, dialogs, $timeout, Price, Availability, Slot, Member, Setting, CustomAsset, $compile, availabilityTrainingsPromise, plansPromise, groupsPromise, growl, settingsPromise, _t) ->
Application.Controllers.controller "ReserveTrainingController", ["$scope", "$state", '$stateParams', '$filter', '$compile', "$uibModal", 'Auth', 'dialogs', '$timeout', 'Price', 'Availability', 'Slot', 'Member', 'Setting', 'CustomAsset', 'availabilityTrainingsPromise', 'plansPromise', 'groupsPromise', 'growl', 'settingsPromise', 'trainingPromise', '_t'
, ($scope, $state, $stateParams, $filter, $compile, $uibModal, Auth, dialogs, $timeout, Price, Availability, Slot, Member, Setting, CustomAsset, availabilityTrainingsPromise, plansPromise, groupsPromise, growl, settingsPromise, trainingPromise, _t) ->
@ -110,6 +110,9 @@ Application.Controllers.controller "ReserveTrainingController", ["$scope", "$sta
## Once a training reservation was modified, will contains {newReservedSlot:{}, oldReservedSlot:{}}
$scope.modifiedSlots = null
## Selected training unless 'all' trainings are displayed
$scope.training = trainingPromise
## fullCalendar (v2) configuration
$scope.calendarConfig =
timezone: Fablab.timezone
@ -164,7 +167,7 @@ Application.Controllers.controller "ReserveTrainingController", ["$scope", "$sta
if $scope.ctrl.member
Member.get {id: $scope.ctrl.member.id}, (member) ->
$scope.ctrl.member = member
Availability.trainings {member_id: $scope.ctrl.member.id}, (trainings) ->
Availability.trainings {trainingId: $stateParams.id, member_id: $scope.ctrl.member.id}, (trainings) ->
$scope.calendar.fullCalendar 'removeEvents'
$scope.eventSources.push
events: trainings
@ -480,7 +483,7 @@ Application.Controllers.controller "ReserveTrainingController", ["$scope", "$sta
##
eventRenderCb = (event, element, view)->
element.attr(
'uib-popover': event.training.description
'uib-popover': $filter('humanize')($filter('simpleText')(event.training.description), 70)
'popover-trigger': 'mouseenter'
)
$compile(element)($scope)

View File

@ -391,7 +391,7 @@ angular.module('application.router', ['ui.router']).
Translations.query(['app.public.training_show']).$promise
]
.state 'app.logged.trainings_reserve',
url: '/trainings/reserve'
url: '/trainings/:id/reserve'
views:
'main@':
templateUrl: '<%= asset_path "trainings/reserve.html" %>'
@ -406,8 +406,11 @@ angular.module('application.router', ['ui.router']).
groupsPromise: ['Group', (Group)->
Group.query().$promise
]
availabilityTrainingsPromise: ['Availability', (Availability)->
Availability.trainings().$promise
availabilityTrainingsPromise: ['Availability', '$stateParams', (Availability, $stateParams)->
Availability.trainings({trainingId: $stateParams.id}).$promise
]
trainingPromise: ['Training', '$stateParams', (Training, $stateParams)->
Training.get({id: $stateParams.id}).$promise unless $stateParams.id == 'all'
]
settingsPromise: ['Setting', (Setting)->
Setting.query(names: "['booking_window_start',

View File

@ -14,7 +14,8 @@ Application.Services.factory 'Availability', ["$resource", ($resource)->
isArray: true
trainings:
method: 'GET'
url: '/api/availabilities/trainings'
url: '/api/availabilities/trainings/:trainingId'
params: {trainingId: "@trainingId"}
isArray: true
update:
method: 'PUT'

View File

@ -7,7 +7,8 @@
</div>
<div class="col-xs-10 col-sm-10 col-md-8 b-l">
<section class="heading-title">
<h1 translate>{{ 'trainings_planning' }}</h1>
<h1 ng-hide="training" translate>{{ 'trainings_planning' }}</h1>
<h1 ng-show="training"><span translate>{{ 'planning_of' }}</span> {{training.name}}</h1>
</section>
</div>
@ -24,6 +25,12 @@
<div class="col-sm-12 col-md-12 col-lg-3">
<div class="text-center m-t">
<a class="btn btn-warning-full width-70 rounded text-sm" ui-sref="app.logged.trainings_reserve({id:'all'})" translate>
{{ 'all_trainings' }}
</a>
</div>
<div ng-if="currentUser.role === 'admin'">
<select-member></select-member>
</div>

View File

@ -77,14 +77,33 @@ class API::AvailabilitiesController < API::ApiController
@user = current_user
end
@slots = []
@reservations = @user.reservations.where("reservable_type = 'Training'").joins(:slots).where('slots.start_at > ?', Time.now)
# first, we get the already-made reservations
@reservations = @user.reservations.where("reservable_type = 'Training'")
@reservations = @reservations.where('reservable_id = :id', id: params[:training_id].to_i) if params[:training_id].is_number?
@reservations = @reservations.joins(:slots).where('slots.start_at > ?', Time.now)
# what is requested?
# 1) a single training
if params[:training_id].is_number?
@availabilities = Training.find(params[:training_id]).availabilities
# 2) all trainings
else
@availabilities = Availability.trainings
end
# who made the request?
# 1) an admin (he can see all future availabilities)
if @user.is_admin?
@availabilities = Availability.trainings.where('start_at > ?', Time.now)
@availabilities = @availabilities.where('start_at > ?', Time.now)
# 2) an user (he cannot see availabilities further than 1 (or 3) months)
else
end_at = 1.month.since
end_at = 3.months.since if can_show_slot_plus_three_months(@user)
@availabilities = Availability.trainings.includes(:availability_tags).where('start_at > ? AND start_at < ?', Time.now, end_at).where('availability_tags.tag_id' => @user.tag_ids.concat([nil]))
@availabilities = @availabilities.includes(:availability_tags).where('start_at > ? AND start_at < ?', Time.now, end_at).where('availability_tags.tag_id' => @user.tag_ids.concat([nil]))
end
# finally, we merge the availabilities with the reservations
@availabilities.each do |a|
a = verify_training_is_reserved(a, @reservations)
end

View File

@ -0,0 +1,12 @@
## Helper method: will return true if the current string
## can be parsed as a number (float or integer), false otherwise
# exemples:
# "2" => true
# "4.5" => true
# "hello" => false
# "" => false
class String
def is_number?
true if Float(self) rescue false
end
end

View File

@ -128,6 +128,8 @@ en:
trainings_reserve:
# book a training
trainings_planning: "Trainings planning"
planning_of: "Planning of" # followed by the training name (eg. "Planning of 3d printer training")
all_trainings: "All trainings"
select_a_slot_in_the_calendar: "Select a slot in the calendar"
you_ve_just_selected_the_slot: "You've just selected the slot:"
datetime_to_time: "{{START_DATETIME}} to {{END_TIME}}" # angular interpolation, eg: Thursday, September 4 1986 8:30 PM to 10:00 PM

View File

@ -127,7 +127,9 @@ fr:
trainings_reserve:
# réserver une formation
trainings_planning: "Planning formation"
trainings_planning: "Planning formations"
planning_of: "Planning de la" # suivi du nom de la formation (eg. "Planning de la formation imprimante 3d")
all_trainings: "Toutes les formations"
select_a_slot_in_the_calendar: "Sélectionnez un créneau dans le calendrier"
you_ve_just_selected_the_slot: "Vous venez de sélectionner le créneau :"
datetime_to_time: "{{START_DATETIME}} à {{END_TIME}}" # angular interpolation, eg: Thursday, September 4 1986 8:30 PM to 10:00 PM

View File

@ -63,7 +63,7 @@ Rails.application.routes.draw do
resources :availabilities do
get 'machines/:machine_id', action: 'machine', on: :collection
get 'trainings', on: :collection
get 'trainings/:training_id', action: 'trainings', on: :collection
get 'reservations', on: :member
end