1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-20 14:54:15 +01:00

fixed & improved js routing

This commit is contained in:
Sylvain 2017-02-21 15:41:45 +01:00
parent 3837604dd6
commit 5a41424579
5 changed files with 8 additions and 6 deletions

View File

@ -93,7 +93,7 @@ _reserveMachine = (machine, e) ->
# if the currently logged'in user has completed the training for this machine, or this machine does not require
# a prior training, just redirect him to the machine's booking page
if machine.current_user_is_training or machine.trainings.length == 0
_this.$state.go('app.logged.machines_reserve', {id: machine.id})
_this.$state.go('app.logged.machines_reserve', {id: machine.slug})
else
# otherwise, if a user is authenticated ...
if _this.$scope.isAuthenticated()
@ -387,7 +387,7 @@ Application.Controllers.controller "ReserveMachineController", ["$scope", "$stat
slot.id = null
slot.is_reserved = false
slot.can_modify = false
refetchCalendar()
updateCalendar()
$scope.markSlotAsModifying = ->
$scope.selectedEvent.backgroundColor = '#eee'

View File

@ -65,8 +65,10 @@ Application.Directives.directive 'cart', [ '$rootScope', '$uibModal', 'dialogs',
# and decrement the total amount of the cart if needed.
# @param machineSlot {Object} fullCalendar event object
# @param index {number} index of the slot in the reservation array
# @param [event] {Object} see https://docs.angularjs.org/guide/expression#-event-
##
$scope.removeMachineSlot = (machineSlot, index)->
$scope.removeMachineSlot = (machineSlot, index, event)->
event.preventDefault() if event
$scope.events.reserved.splice(index, 1)
# if is was the last slot, we remove any plan from the cart
if $scope.events.reserved.length == 0

View File

@ -33,7 +33,7 @@
<button class="btn btn-valid btn-warning btn-block text-u-c r-b" ng-click="validateSlot(machineSlot)" ng-if="!machineSlot.isValid" translate>{{ 'confirm_this_slot' }}</button>
</div>
<div class="clear"><a class="pull-right m-b-sm text-u-l ng-scope m-r-sm" href="#" ng-click="removeMachineSlot(machineSlot, $index)" ng-if="machineSlot.isValid" translate>{{ 'remove_this_slot' }}</a></div>
<div class="clear"><a class="pull-right m-b-sm text-u-l ng-scope m-r-sm" href="#" ng-click="removeMachineSlot(machineSlot, $index, $event)" ng-if="machineSlot.isValid" translate>{{ 'remove_this_slot' }}</a></div>
</div>
<coupon show="machineSlotsValid() && (!modePlans || selectedPlan)" coupon="coupon.applied" total="totalNoCoupon" user-id="{{user.id}}"></coupon>

View File

@ -96,7 +96,7 @@ class API::AvailabilitiesController < API::ApiController
@user = current_user
end
@current_user_role = current_user.is_admin? ? 'admin' : 'user'
@machine = Machine.find(params[:machine_id])
@machine = Machine.friendly.find(params[:machine_id])
@slots = []
@reservations = Reservation.where('reservable_type = ? and reservable_id = ?', @machine.class.to_s, @machine.id).includes(:slots, user: [:profile]).references(:slots, :user).where('slots.start_at > ?', Time.now)
if @user.is_admin?

View File

@ -1,4 +1,4 @@
json.extract! @machine, :id, :name, :description, :spec, :created_at, :updated_at
json.extract! @machine, :id, :name, :description, :spec, :created_at, :updated_at, :slug
json.machine_image @machine.machine_image.attachment.large.url if @machine.machine_image
json.machine_files_attributes @machine.machine_files do |f|
json.id f.id