2018-10-25 16:51:20 +02:00
|
|
|
/* eslint-disable
|
|
|
|
no-return-assign,
|
|
|
|
no-undef,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2018-10-25 16:50:16 +02:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2018-11-21 11:08:53 +01:00
|
|
|
'use strict';
|
2018-10-25 16:51:20 +02:00
|
|
|
|
2020-02-25 10:47:16 +01:00
|
|
|
Application.Controllers.controller('ProjectElementsController', ['$scope', '$state', 'Component', 'Licence', 'Theme', 'componentsPromise', 'licencesPromise', 'themesPromise', '_t', 'Member', 'uiTourService',
|
|
|
|
function ($scope, $state, Component, Licence, Theme, componentsPromise, licencesPromise, themesPromise, _t, Member, uiTourService) {
|
|
|
|
// Materials list (plastic, wood ...)
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.components = componentsPromise;
|
2018-10-25 16:51:20 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
// Licences list (Creative Common ...)
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.licences = licencesPromise;
|
2018-10-25 16:51:20 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
// Themes list (cooking, sport ...)
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.themes = themesPromise;
|
2018-10-25 16:51:20 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
/**
|
|
|
|
* Saves a new component / Update an existing material to the server (form validation callback)
|
|
|
|
* @param data {Object} component name
|
|
|
|
* @param [data] {number} component id, in case of update
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.saveComponent = function (data, id) {
|
|
|
|
if (id != null) {
|
2018-11-21 11:08:53 +01:00
|
|
|
return Component.update({ id }, data);
|
2018-10-25 16:51:20 +02:00
|
|
|
} else {
|
2018-11-21 11:08:53 +01:00
|
|
|
return Component.save(data, resp => $scope.components[$scope.components.length - 1].id = resp.id);
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
/**
|
|
|
|
* Deletes the component at the specified index
|
|
|
|
* @param index {number} component index in the $scope.components array
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.removeComponent = function (index) {
|
2018-11-21 11:08:53 +01:00
|
|
|
Component.delete($scope.components[index]);
|
|
|
|
return $scope.components.splice(index, 1);
|
|
|
|
};
|
2015-05-05 03:10:25 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
/**
|
|
|
|
* Creates a new empty entry in the $scope.components array
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.addComponent = function () {
|
|
|
|
$scope.inserted =
|
2018-11-21 11:08:53 +01:00
|
|
|
{ name: '' };
|
|
|
|
return $scope.components.push($scope.inserted);
|
|
|
|
};
|
2015-05-05 03:10:25 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
/**
|
|
|
|
* Removes the newly inserted but not saved component / Cancel the current component modification
|
|
|
|
* @param rowform {Object} see http://vitalets.github.io/angular-xeditable/
|
|
|
|
* @param index {number} component index in the $scope.components array
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.cancelComponent = function (rowform, index) {
|
|
|
|
if ($scope.components[index].id != null) {
|
2018-11-21 11:08:53 +01:00
|
|
|
return rowform.$cancel();
|
2018-10-25 16:51:20 +02:00
|
|
|
} else {
|
2018-11-21 11:08:53 +01:00
|
|
|
return $scope.components.splice(index, 1);
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
/**
|
|
|
|
* Saves a new theme / Update an existing theme to the server (form validation callback)
|
|
|
|
* @param data {Object} theme name
|
|
|
|
* @param [data] {number} theme id, in case of update
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.saveTheme = function (data, id) {
|
|
|
|
if (id != null) {
|
2018-11-21 11:08:53 +01:00
|
|
|
return Theme.update({ id }, data);
|
2018-10-25 16:51:20 +02:00
|
|
|
} else {
|
2018-11-21 11:08:53 +01:00
|
|
|
return Theme.save(data, resp => $scope.themes[$scope.themes.length - 1].id = resp.id);
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
/**
|
|
|
|
* Deletes the theme at the specified index
|
|
|
|
* @param index {number} theme index in the $scope.themes array
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.removeTheme = function (index) {
|
2018-11-21 11:08:53 +01:00
|
|
|
Theme.delete($scope.themes[index]);
|
|
|
|
return $scope.themes.splice(index, 1);
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
/**
|
|
|
|
* Creates a new empty entry in the $scope.themes array
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.addTheme = function () {
|
|
|
|
$scope.inserted =
|
2018-11-21 11:08:53 +01:00
|
|
|
{ name: '' };
|
|
|
|
return $scope.themes.push($scope.inserted);
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
/**
|
|
|
|
* Removes the newly inserted but not saved theme / Cancel the current theme modification
|
|
|
|
* @param rowform {Object} see http://vitalets.github.io/angular-xeditable/
|
|
|
|
* @param index {number} theme index in the $scope.themes array
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.cancelTheme = function (rowform, index) {
|
|
|
|
if ($scope.themes[index].id != null) {
|
2018-11-21 11:08:53 +01:00
|
|
|
return rowform.$cancel();
|
2018-10-25 16:51:20 +02:00
|
|
|
} else {
|
2018-11-21 11:08:53 +01:00
|
|
|
return $scope.themes.splice(index, 1);
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
/**
|
|
|
|
* Saves a new licence / Update an existing licence to the server (form validation callback)
|
|
|
|
* @param data {Object} licence name and description
|
|
|
|
* @param [data] {number} licence id, in case of update
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.saveLicence = function (data, id) {
|
|
|
|
if (id != null) {
|
2018-11-21 11:08:53 +01:00
|
|
|
return Licence.update({ id }, data);
|
2018-10-25 16:51:20 +02:00
|
|
|
} else {
|
2018-11-21 11:08:53 +01:00
|
|
|
return Licence.save(data, resp => $scope.licences[$scope.licences.length - 1].id = resp.id);
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
/**
|
|
|
|
* Deletes the licence at the specified index
|
|
|
|
* @param index {number} licence index in the $scope.licences array
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.removeLicence = function (index) {
|
2018-11-21 11:08:53 +01:00
|
|
|
Licence.delete($scope.licences[index]);
|
|
|
|
return $scope.licences.splice(index, 1);
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
/**
|
|
|
|
* Creates a new empty entry in the $scope.licences array
|
|
|
|
*/
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.addLicence = function () {
|
|
|
|
$scope.inserted = {
|
|
|
|
name: '',
|
|
|
|
description: ''
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
|
|
|
return $scope.licences.push($scope.inserted);
|
|
|
|
};
|
2018-10-25 16:50:16 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
/**
|
|
|
|
* Removes the newly inserted but not saved licence / Cancel the current licence modification
|
|
|
|
* @param rowform {Object} see http://vitalets.github.io/angular-xeditable/
|
|
|
|
* @param index {number} licence index in the $scope.licences array
|
|
|
|
*/
|
2020-02-25 10:47:16 +01:00
|
|
|
$scope.cancelLicence = function (rowform, index) {
|
2018-10-25 16:51:20 +02:00
|
|
|
if ($scope.licences[index].id != null) {
|
2018-11-21 11:08:53 +01:00
|
|
|
return rowform.$cancel();
|
2018-10-25 16:51:20 +02:00
|
|
|
} else {
|
2018-11-21 11:08:53 +01:00
|
|
|
return $scope.licences.splice(index, 1);
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2020-02-25 10:47:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the feature-tour for the admin/project_elements page.
|
|
|
|
* This is intended as a contextual help (when pressing F1)
|
|
|
|
*/
|
|
|
|
$scope.setupProjectElementsTour = function () {
|
|
|
|
// get the tour defined by the ui-tour directive
|
|
|
|
const uitour = uiTourService.getTourByName('project-elements');
|
|
|
|
uitour.createStep({
|
|
|
|
selector: 'body',
|
|
|
|
stepId: 'welcome',
|
|
|
|
order: 0,
|
2020-02-25 11:47:30 +01:00
|
|
|
title: _t('app.admin.tour.project_elements.welcome.title'),
|
|
|
|
content: _t('app.admin.tour.project_elements.welcome.content'),
|
2020-02-25 10:47:16 +01:00
|
|
|
placement: 'bottom',
|
|
|
|
orphan: true
|
|
|
|
});
|
|
|
|
uitour.createStep({
|
|
|
|
selector: '.heading .abuses-button',
|
|
|
|
stepId: 'abuses',
|
|
|
|
order: 1,
|
2020-02-25 11:47:30 +01:00
|
|
|
title: _t('app.admin.tour.project_elements.abuses.title'),
|
|
|
|
content: _t('app.admin.tour.project_elements.abuses.content'),
|
2020-03-03 11:20:17 +01:00
|
|
|
placement: 'bottom',
|
|
|
|
popupClass: 'shift-left-40'
|
2020-02-25 10:47:16 +01:00
|
|
|
});
|
|
|
|
uitour.createStep({
|
|
|
|
selector: 'body',
|
|
|
|
stepId: 'conclusion',
|
2020-02-25 11:06:03 +01:00
|
|
|
order: 2,
|
2020-02-25 10:47:16 +01:00
|
|
|
title: _t('app.admin.tour.conclusion.title'),
|
|
|
|
content: _t('app.admin.tour.conclusion.content'),
|
|
|
|
placement: 'bottom',
|
|
|
|
orphan: true
|
|
|
|
});
|
|
|
|
// on tour end, save the status in database
|
|
|
|
uitour.on('ended', function () {
|
|
|
|
if (uitour.getStatus() === uitour.Status.ON && $scope.currentUser.profile.tours.indexOf('project-elements') < 0) {
|
|
|
|
Member.completeTour({ id: $scope.currentUser.id }, { tour: 'project-elements' }, function (res) {
|
|
|
|
$scope.currentUser.profile.tours = res.tours;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// if the user has never seen the tour, show him now
|
2020-03-02 11:17:28 +01:00
|
|
|
if (Fablab.featureTourDisplay !== 'manual' && $scope.currentUser.profile.tours.indexOf('project-elements') < 0) {
|
2020-02-25 10:47:16 +01:00
|
|
|
uitour.start();
|
|
|
|
}
|
|
|
|
// start this tour when an user press F1 - this is contextual help
|
|
|
|
window.addEventListener('keydown', handleF1);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* PRIVATE SCOPE */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Kind of constructor: these actions will be realized first when the controller is loaded
|
|
|
|
*/
|
|
|
|
const initialize = function () {
|
|
|
|
// listen the $destroy event of the controller to remove the F1 key binding
|
|
|
|
$scope.$on('$destroy', function () {
|
|
|
|
window.removeEventListener('keydown', handleF1);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback used to trigger the feature tour when the user press the F1 key.
|
|
|
|
* @param e {KeyboardEvent}
|
|
|
|
*/
|
|
|
|
const handleF1 = function (e) {
|
|
|
|
if (e.key === 'F1') {
|
|
|
|
e.preventDefault();
|
|
|
|
const tour = uiTourService.getTourByName('project-elements');
|
|
|
|
if (tour) { tour.start(); }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// !!! MUST BE CALLED AT THE END of the controller
|
|
|
|
return initialize();
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
]);
|