mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-01 12:24:28 +01:00
WIP: migrate machine card to react
This commit is contained in:
parent
17ab75cfa5
commit
99792e8610
@ -0,0 +1,16 @@
|
||||
import React from 'react';
|
||||
import { Machine } from '../../models/machine';
|
||||
|
||||
interface MachineCardProps {
|
||||
machine: Machine
|
||||
}
|
||||
|
||||
/**
|
||||
* This component is a box showing the picture of the given machine and two buttons: one to start the reservation process
|
||||
* and another to redirect the user to the machine description page.
|
||||
*/
|
||||
const MachineCard: React.FC<MachineCardProps> = ({ machine }) => {
|
||||
return (
|
||||
<div/>
|
||||
)
|
||||
}
|
@ -112,14 +112,14 @@ const _reserveMachine = function (machine, e) {
|
||||
return machine = _this.Machine.get({ id: machine.id }, function () {
|
||||
// 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 || (machine.trainings.length === 0)) {
|
||||
if (machine.current_user_is_trained || (machine.trainings.length === 0)) {
|
||||
return _this.$state.go('app.logged.machines_reserve', { id: machine.slug });
|
||||
} else {
|
||||
// otherwise, if a user is authenticated ...
|
||||
if (_this.$scope.isAuthenticated()) {
|
||||
// ... and have booked a training for this machine, tell him that he must wait for an admin to validate
|
||||
// the training before he can book the reservation
|
||||
if (machine.current_user_training_reservation) {
|
||||
if (machine.current_user_next_training_reservation) {
|
||||
return _this.$uibModal.open({
|
||||
templateUrl: '/machines/training_reservation_modal.html',
|
||||
controller: ['$scope', '$uibModalInstance', function ($scope, $uibModalInstance) {
|
||||
|
28
app/frontend/src/javascript/models/machine.ts
Normal file
28
app/frontend/src/javascript/models/machine.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { Reservation } from './reservation';
|
||||
|
||||
export interface Machine {
|
||||
id: number,
|
||||
name: string,
|
||||
description?: string,
|
||||
spec?: string,
|
||||
disabled: boolean,
|
||||
slug: string,
|
||||
machine_image: string,
|
||||
machine_files_attributes?: Array<{
|
||||
id: number,
|
||||
attachment: string,
|
||||
attachment_url: string
|
||||
}>,
|
||||
trainings?: Array<{
|
||||
id: number,
|
||||
name: string,
|
||||
disabled: boolean,
|
||||
}>,
|
||||
current_user_is_trained?: boolean,
|
||||
current_user_next_training_reservation?: Reservation,
|
||||
machine_projects?: Array<{
|
||||
id: number,
|
||||
name: string,
|
||||
slug: string,
|
||||
}>
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p translate> {{ 'app.shared.training_reservation_modal.you_must_wait_for_your_training_is_being_validated_by_the_fablab_team_to_book_this_machine' }}</p>
|
||||
<p>{{ 'app.shared.training_reservation_modal.your_training_will_occur_' | translate }} <span class="sbold">{{machine.current_user_training_reservation.slots[0].start_at | amDateFormat: 'LL'}} : {{machine.current_user_training_reservation.slots[0].start_at | amDateFormat:'LT'}} - {{machine.current_user_training_reservation.slots[0].end_at | amDateFormat:'LT'}}</span></p>
|
||||
<p>{{ 'app.shared.training_reservation_modal.your_training_will_occur_' | translate }} <span class="sbold">{{machine.current_user_next_training_reservation.slots[0].start_at | amDateFormat: 'LL'}} : {{machine.current_user_next_training_reservation.slots[0].start_at | amDateFormat:'LT'}} - {{machine.current_user_next_training_reservation.slots[0].end_at | amDateFormat:'LT'}}</span></p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-warning" ng-click="cancel()" translate>{{ 'app.shared.buttons.close' }}</button>
|
||||
|
@ -127,8 +127,14 @@ class User < ApplicationRecord
|
||||
trainings.map(&:machines).flatten.uniq.include?(machine)
|
||||
end
|
||||
|
||||
def training_reservation_by_machine(machine)
|
||||
reservations.where(reservable_type: 'Training', reservable_id: machine.trainings.map(&:id)).first
|
||||
def next_training_reservation_by_machine(machine)
|
||||
reservations.where(reservable_type: 'Training', reservable_id: machine.trainings.map(&:id))
|
||||
.includes(:slots)
|
||||
.where('slots.start_at>= ?', DateTime.current)
|
||||
.order('slots.start_at': :asc)
|
||||
.references(:slots)
|
||||
.limit(1)
|
||||
.first
|
||||
end
|
||||
|
||||
def subscribed_plan
|
||||
|
@ -1,5 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.array!(@machines) do |machine|
|
||||
json.extract! machine, :id, :name, :description, :spec, :slug, :disabled
|
||||
|
||||
json.extract! machine, :id, :name, :slug, :disabled
|
||||
|
||||
json.machine_image machine.machine_image.attachment.medium.url if machine.machine_image
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.extract! @machine, :id, :name, :description, :spec, :disabled, :created_at, :updated_at, :slug
|
||||
json.extract! @machine, :id, :name, :description, :spec, :disabled, :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
|
||||
@ -8,10 +8,10 @@ json.machine_files_attributes @machine.machine_files do |f|
|
||||
json.attachment_url f.attachment_url
|
||||
end
|
||||
json.trainings @machine.trainings.each, :id, :name, :disabled
|
||||
json.current_user_is_training current_user.training_machine?(@machine) if current_user
|
||||
if current_user && !current_user.training_machine?(@machine) && current_user.training_reservation_by_machine(@machine)
|
||||
json.current_user_training_reservation do
|
||||
json.partial! 'api/reservations/reservation', reservation: current_user.training_reservation_by_machine(@machine)
|
||||
json.current_user_is_trained current_user.training_machine?(@machine) if current_user
|
||||
if current_user && !current_user.training_machine?(@machine) && current_user.next_training_reservation_by_machine(@machine)
|
||||
json.current_user_next_training_reservation do
|
||||
json.partial! 'api/reservations/reservation', reservation: current_user.next_training_reservation_by_machine(@machine)
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user