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
|
|
|
|
*/
|
2020-02-25 11:47:30 +01:00
|
|
|
Application.Controllers.controller('OpenAPIClientsController', ['$scope', 'clientsPromise', 'growl', 'OpenAPIClient', 'dialogs', '_t', 'Member', 'uiTourService',
|
|
|
|
function ($scope, clientsPromise, growl, OpenAPIClient, dialogs, _t, Member, uiTourService) {
|
|
|
|
/* PUBLIC SCOPE */
|
2016-05-09 18:15:04 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
// clients list
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.clients = clientsPromise;
|
|
|
|
$scope.order = null;
|
|
|
|
$scope.clientFormVisible = false;
|
|
|
|
$scope.client = {};
|
2016-05-09 18:15:04 +02:00
|
|
|
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.toggleForm = () => $scope.clientFormVisible = !$scope.clientFormVisible;
|
2016-05-09 18:15:04 +02:00
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
// Change the order criterion to the one provided
|
|
|
|
// @param orderBy {string} ordering criterion
|
2018-11-21 10:59:07 +01:00
|
|
|
//
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.setOrder = function (orderBy) {
|
|
|
|
if ($scope.order === orderBy) {
|
2018-11-21 11:08:53 +01:00
|
|
|
return $scope.order = `-${orderBy}`;
|
2018-10-25 16:51:20 +02:00
|
|
|
} else {
|
2018-11-21 11:08:53 +01:00
|
|
|
return $scope.order = orderBy;
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2016-05-09 18:15:04 +02:00
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.saveClient = function (client) {
|
|
|
|
if (client.id != null) {
|
|
|
|
OpenAPIClient.update({ id: client.id }, { open_api_client: client }, function (clientResp) {
|
2018-11-21 11:08:53 +01:00
|
|
|
client = clientResp;
|
2019-12-17 18:06:56 +01:00
|
|
|
return growl.success(_t('app.admin.open_api_clients.client_successfully_updated'));
|
2018-11-21 11:08:53 +01:00
|
|
|
});
|
2018-10-25 16:51:20 +02:00
|
|
|
} else {
|
|
|
|
OpenAPIClient.save({ open_api_client: client }, function (client) {
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.clients.push(client);
|
2019-12-17 18:06:56 +01:00
|
|
|
return growl.success(_t('app.admin.open_api_clients.client_successfully_created'));
|
2018-11-21 11:08:53 +01:00
|
|
|
});
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2016-05-09 18:15:04 +02:00
|
|
|
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.clientFormVisible = false;
|
|
|
|
$scope.clientForm.$setPristine();
|
|
|
|
return $scope.client = {};
|
|
|
|
};
|
2016-05-09 18:15:04 +02:00
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.editClient = function (client) {
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.clientFormVisible = true;
|
|
|
|
return $scope.client = client;
|
|
|
|
};
|
2016-05-09 18:15:04 +02:00
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.deleteClient = index =>
|
|
|
|
dialogs.confirm({
|
|
|
|
resolve: {
|
|
|
|
object () {
|
|
|
|
return {
|
2019-12-17 18:06:56 +01:00
|
|
|
title: _t('app.admin.open_api_clients.confirmation_required'),
|
|
|
|
msg: _t('app.admin.open_api_clients.do_you_really_want_to_delete_this_open_api_client')
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-25 16:51:20 +02:00
|
|
|
, () =>
|
|
|
|
OpenAPIClient.delete({ id: $scope.clients[index].id }, function () {
|
2018-11-21 11:08:53 +01:00
|
|
|
$scope.clients.splice(index, 1);
|
2019-12-17 18:06:56 +01:00
|
|
|
return growl.success(_t('app.admin.open_api_clients.client_successfully_deleted'));
|
2018-10-25 16:51:20 +02:00
|
|
|
})
|
2018-11-21 11:08:53 +01:00
|
|
|
);
|
2016-05-09 18:15:04 +02:00
|
|
|
|
2020-02-25 11:47:30 +01:00
|
|
|
$scope.resetToken = client =>
|
2018-10-25 16:51:20 +02:00
|
|
|
dialogs.confirm({
|
|
|
|
resolve: {
|
|
|
|
object () {
|
|
|
|
return {
|
2019-12-17 18:06:56 +01:00
|
|
|
title: _t('app.admin.open_api_clients.confirmation_required'),
|
|
|
|
msg: _t('app.admin.open_api_clients.do_you_really_want_to_revoke_this_open_api_access')
|
2018-11-21 11:08:53 +01:00
|
|
|
};
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-25 16:51:20 +02:00
|
|
|
, () =>
|
|
|
|
OpenAPIClient.resetToken({ id: client.id }, {}, function (clientResp) {
|
2018-11-21 11:08:53 +01:00
|
|
|
client.token = clientResp.token;
|
2019-12-17 18:06:56 +01:00
|
|
|
return growl.success(_t('app.admin.open_api_clients.access_successfully_revoked'));
|
2018-10-25 16:51:20 +02:00
|
|
|
})
|
2018-11-21 11:08:53 +01:00
|
|
|
);
|
2020-02-25 11:47:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup the feature-tour for the admin/open_api_clients page.
|
|
|
|
* This is intended as a contextual help (when pressing F1)
|
|
|
|
*/
|
|
|
|
$scope.setupOpenAPITour = function () {
|
|
|
|
// get the tour defined by the ui-tour directive
|
|
|
|
const uitour = uiTourService.getTourByName('open-api');
|
|
|
|
uitour.createStep({
|
|
|
|
selector: 'body',
|
|
|
|
stepId: 'welcome',
|
|
|
|
order: 0,
|
|
|
|
title: _t('app.admin.tour.open_api.welcome.title'),
|
|
|
|
content: _t('app.admin.tour.open_api.welcome.content'),
|
|
|
|
placement: 'bottom',
|
|
|
|
orphan: true
|
|
|
|
});
|
|
|
|
uitour.createStep({
|
|
|
|
selector: '.heading .documentation-button',
|
|
|
|
stepId: 'doc',
|
|
|
|
order: 1,
|
|
|
|
title: _t('app.admin.tour.open_api.doc.title'),
|
|
|
|
content: _t('app.admin.tour.open_api.doc.content'),
|
|
|
|
placement: 'bottom'
|
|
|
|
});
|
|
|
|
uitour.createStep({
|
|
|
|
selector: 'body',
|
|
|
|
stepId: 'conclusion',
|
|
|
|
order: 2,
|
|
|
|
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('open-api') < 0) {
|
|
|
|
Member.completeTour({ id: $scope.currentUser.id }, { tour: 'open-api' }, function (res) {
|
|
|
|
$scope.currentUser.profile.tours = res.tours;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2020-02-25 18:02:41 +01:00
|
|
|
// if the user has never seen the tour, and if the display behavior is not configured to manual triggering only, show the tour now
|
|
|
|
if (Fablab.featureTourDisplay !== 'manual' && $scope.currentUser.profile.tours.indexOf('open-api') < 0) {
|
2020-02-25 11:47:30 +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('open-api');
|
|
|
|
if (tour) { tour.start(); }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// !!! MUST BE CALLED AT THE END of the controller
|
|
|
|
return initialize();
|
2018-10-25 16:51:20 +02:00
|
|
|
}
|
2016-05-09 18:15:04 +02:00
|
|
|
|
2018-11-21 11:08:53 +01:00
|
|
|
]);
|