1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

(feat) machines reservable or not

This commit is contained in:
Sylvain 2022-12-27 16:14:29 +01:00
parent f0d9537182
commit 7fc79d44e5
13 changed files with 29 additions and 8 deletions

View File

@ -1,6 +1,7 @@
# Changelog Fab-manager
- Ability to group machines by categories
- Ability to mark a machine as reservable or not
- Private note on member's profile
- Optional external identifier for users
- Ability to disable generation of invoices at zero

View File

@ -49,7 +49,7 @@ class API::MachinesController < API::ApiController
end
def machine_params
params.require(:machine).permit(:name, :description, :spec, :disabled, :machine_category_id, :plan_ids,
params.require(:machine).permit(:name, :description, :spec, :disabled, :machine_category_id, :plan_ids, :reservable,
plan_ids: [], machine_image_attributes: [:attachment],
machine_files_attributes: %i[id attachment _destroy],
advanced_accounting_attributes: %i[code analytical_section])

View File

@ -55,13 +55,13 @@ const MachineCard: React.FC<MachineCardProps> = ({ user, machine, onShowMachine,
};
return (
<div className={`machine-card ${loading ? 'loading' : ''} ${machine.disabled ? 'disabled' : ''}`}>
<div className={`machine-card ${loading ? 'loading' : ''} ${machine.disabled ? 'disabled' : ''} ${!machine.reservable ? 'unreservable' : ''}`}>
{machinePicture()}
<div className="machine-name">
{machine.name}
</div>
<div className="machine-actions">
{!machine.disabled && <ReserveButton currentUser={user}
{!machine.disabled && machine.reservable && <ReserveButton currentUser={user}
machineId={machine.id}
onLoadingStart={() => setLoading(true)}
onLoadingEnd={() => setLoading(false)}

View File

@ -110,6 +110,10 @@ export const MachineForm: React.FC<MachineFormProps> = ({ action, machine, onErr
id="machine_files_attributes"
className="machine-files" />
<FormSwitch control={control}
id="reservable"
label={t('app.admin.machine_form.reservable')}
defaultValue={true} />
<FormSwitch control={control}
id="disabled"
label={t('app.admin.machine_form.disable_machine')}

View File

@ -43,7 +43,7 @@ Application.Controllers.controller('AdminCalendarController', ['$scope', '$state
$scope.trainings = trainingsPromise.filter(t => !t.disabled);
// list of the FabLab machines
$scope.machines = machinesPromise;
$scope.machines = machinesPromise.filter(m => !m.disabled && m.reservable);
// List of machine categories
$scope.machineCategories = machineCategoriesPromise;
@ -712,7 +712,7 @@ Application.Controllers.controller('CreateEventModalController', ['$scope', '$ui
$scope.end = end;
// machines list
$scope.machines = machinesPromise.filter(function (m) { return !m.disabled; });
$scope.machines = machinesPromise.filter(function (m) { return !m.disabled && m.reservable; });
// trainings list
$scope.trainings = trainingsPromise.filter(function (t) { return !t.disabled; });

View File

@ -18,6 +18,7 @@ export interface Machine {
description?: string,
spec?: string,
disabled: boolean,
reservable: boolean,
slug: string,
machine_image_attributes?: FileType,
machine_files_attributes?: Array<FileType>,

View File

@ -113,7 +113,10 @@
&.disabled {
opacity: 0.5;
}
&.disabled,
&.unreservable {
.machine-actions > span {
width: 100%;
}

View File

@ -15,7 +15,7 @@
<div class="col-xs-12 col-sm-12 col-md-4 b-t hide-b-md">
<section class="heading-actions wrapper">
<reserve-button ng-hide="machine.disabled"
<reserve-button ng-hide="machine.disabled || !machine.reservable"
class-name="'btn btn-lg btn-warning bg-white b-2x rounded m-t-xs'"
current-user="currentUser"
machine-id="machine.id"

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
json.extract! machine, :id, :name, :slug, :disabled, :machine_category_id
json.extract! machine, :id, :name, :slug, :disabled, :machine_category_id, :reservable
if machine.machine_image
json.machine_image_attributes do

View File

@ -38,6 +38,7 @@ en:
add_an_attachment: "Add an attachment"
disable_machine: "Disable machine"
disabled_help: "When disabled, the machine won't be reservable and won't appear by default in the machines list."
reservable: "Can this machine be reserved?"
ACTION_machine: "{ACTION, select, create{Create} other{Update}} the machine"
create_success: "The machine was created successfully"
update_success: "The machine was updated successfully"

View File

@ -536,3 +536,5 @@ en:
spaces: "Spaces"
events: "Events"
externals: "Other calendars"
machine:
machine_uncategorized: "Uncategorized machines"

View File

@ -0,0 +1,8 @@
# frozen_string_literal: true
# From this migration, the machines will be able to appear in the list, but without being reservable
class AddReservableToMachine < ActiveRecord::Migration[5.2]
def change
add_column :machines, :reservable, :boolean, default: true
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_12_20_105939) do
ActiveRecord::Schema.define(version: 2022_12_27_141529) do
# These are extensions that must be enabled in order to support this database
enable_extension "fuzzystrmatch"
@ -397,6 +397,7 @@ ActiveRecord::Schema.define(version: 2022_12_20_105939) do
t.boolean "disabled"
t.datetime "deleted_at"
t.bigint "machine_category_id"
t.boolean "reservable", default: true
t.index ["deleted_at"], name: "index_machines_on_deleted_at"
t.index ["machine_category_id"], name: "index_machines_on_machine_category_id"
t.index ["slug"], name: "index_machines_on_slug", unique: true