From 4d9da0c5f91418056ca4c2ca1901ed0bce81611e Mon Sep 17 00:00:00 2001 From: Du Peng Date: Thu, 12 May 2022 12:51:52 +0200 Subject: [PATCH] hide machines list in edition of training if machines module is disabled --- .../src/javascript/controllers/admin/trainings.js | 12 ++++++++---- app/frontend/src/javascript/router.js | 6 ++++-- app/frontend/templates/admin/trainings/_form.html | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/frontend/src/javascript/controllers/admin/trainings.js b/app/frontend/src/javascript/controllers/admin/trainings.js index af1a630d3..9e95fd31b 100644 --- a/app/frontend/src/javascript/controllers/admin/trainings.js +++ b/app/frontend/src/javascript/controllers/admin/trainings.js @@ -81,8 +81,8 @@ class TrainingsController { /** * Controller used in the training creation page (admin) */ -Application.Controllers.controller('NewTrainingController', ['$scope', '$state', 'machinesPromise', 'CSRF', - function ($scope, $state, machinesPromise, CSRF) { +Application.Controllers.controller('NewTrainingController', ['$scope', '$state', 'machinesPromise', 'settingsPromise', 'CSRF', + function ($scope, $state, machinesPromise, settingsPromise, CSRF) { /* PUBLIC SCOPE */ // Form action on the following URL @@ -94,6 +94,8 @@ Application.Controllers.controller('NewTrainingController', ['$scope', '$state', // list of machines $scope.machines = machinesPromise; + $scope.enableMachinesModule = settingsPromise.machines_module === 'true'; + /* PRIVATE SCOPE */ /** @@ -114,8 +116,8 @@ Application.Controllers.controller('NewTrainingController', ['$scope', '$state', /** * Controller used in the training edition page (admin) */ -Application.Controllers.controller('EditTrainingController', ['$scope', '$state', '$transition$', 'trainingPromise', 'machinesPromise', 'CSRF', - function ($scope, $state, $transition$, trainingPromise, machinesPromise, CSRF) { +Application.Controllers.controller('EditTrainingController', ['$scope', '$state', '$transition$', 'trainingPromise', 'machinesPromise', 'settingsPromise', 'CSRF', + function ($scope, $state, $transition$, trainingPromise, machinesPromise, settingsPromise, CSRF) { /* PUBLIC SCOPE */ // Form action on the following URL @@ -130,6 +132,8 @@ Application.Controllers.controller('EditTrainingController', ['$scope', '$state' // list of machines $scope.machines = machinesPromise; + $scope.enableMachinesModule = settingsPromise.machines_module === 'true'; + /* PRIVATE SCOPE */ /** diff --git a/app/frontend/src/javascript/router.js b/app/frontend/src/javascript/router.js index b5aedcea9..b52874d70 100644 --- a/app/frontend/src/javascript/router.js +++ b/app/frontend/src/javascript/router.js @@ -683,7 +683,8 @@ angular.module('application.router', ['ui.router']) } }, resolve: { - machinesPromise: ['Machine', function (Machine) { return Machine.query().$promise; }] + machinesPromise: ['Machine', function (Machine) { return Machine.query().$promise; }], + settingsPromise: ['Setting', function (Setting) { return Setting.query({ names: "['machines_module']" }).$promise; }] } }) .state('app.admin.trainings_edit', { @@ -697,7 +698,8 @@ angular.module('application.router', ['ui.router']) }, resolve: { trainingPromise: ['Training', '$transition$', function (Training, $transition$) { return Training.get({ id: $transition$.params().id }).$promise; }], - machinesPromise: ['Machine', function (Machine) { return Machine.query().$promise; }] + machinesPromise: ['Machine', function (Machine) { return Machine.query().$promise; }], + settingsPromise: ['Setting', function (Setting) { return Setting.query({ names: "['machines_module']" }).$promise; }] } }) // events diff --git a/app/frontend/templates/admin/trainings/_form.html b/app/frontend/templates/admin/trainings/_form.html index ae5817b43..17a9d4421 100644 --- a/app/frontend/templates/admin/trainings/_form.html +++ b/app/frontend/templates/admin/trainings/_form.html @@ -65,7 +65,7 @@ -
+