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-10-25 16:51:20 +02:00
|
|
|
Application.Controllers.controller('OpenAPIClientsController', ['$scope', 'clientsPromise', 'growl', 'OpenAPIClient', 'dialogs', '_t',
|
|
|
|
function ($scope, clientsPromise, growl, OpenAPIClient, dialogs, _t) {
|
2018-10-25 16:50:16 +02:00
|
|
|
/* PUBLIC SCOPE */
|
2016-05-09 18:15:04 +02:00
|
|
|
|
2018-11-21 09:42:26 +01:00
|
|
|
// clients list
|
2018-10-25 16:51:20 +02:00
|
|
|
$scope.clients = clientsPromise
|
|
|
|
$scope.order = null
|
|
|
|
$scope.clientFormVisible = false
|
|
|
|
$scope.client = {}
|
2016-05-09 18:15:04 +02:00
|
|
|
|
2018-10-25 16:51:20 +02: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) {
|
|
|
|
return $scope.order = `-${orderBy}`
|
|
|
|
} else {
|
|
|
|
return $scope.order = orderBy
|
|
|
|
}
|
2018-10-25 16:50:16 +02: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) {
|
|
|
|
client = clientResp
|
|
|
|
return growl.success(_t('client_successfully_updated'))
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
OpenAPIClient.save({ open_api_client: client }, function (client) {
|
|
|
|
$scope.clients.push(client)
|
|
|
|
return growl.success(_t('client_successfully_created'))
|
|
|
|
})
|
|
|
|
}
|
2016-05-09 18:15:04 +02:00
|
|
|
|
2018-10-25 16:51:20 +02: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) {
|
|
|
|
$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 {
|
|
|
|
title: _t('confirmation_required'),
|
|
|
|
msg: _t('do_you_really_want_to_delete_this_open_api_client')
|
|
|
|
}
|
|
|
|
}
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-25 16:51:20 +02:00
|
|
|
, () =>
|
|
|
|
OpenAPIClient.delete({ id: $scope.clients[index].id }, function () {
|
|
|
|
$scope.clients.splice(index, 1)
|
|
|
|
return growl.success(_t('client_successfully_deleted'))
|
|
|
|
})
|
|
|
|
)
|
2016-05-09 18:15:04 +02:00
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
return $scope.resetToken = client =>
|
|
|
|
dialogs.confirm({
|
|
|
|
resolve: {
|
|
|
|
object () {
|
|
|
|
return {
|
|
|
|
title: _t('confirmation_required'),
|
|
|
|
msg: _t('do_you_really_want_to_revoke_this_open_api_access')
|
|
|
|
}
|
|
|
|
}
|
2018-10-25 16:50:16 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-25 16:51:20 +02:00
|
|
|
, () =>
|
|
|
|
OpenAPIClient.resetToken({ id: client.id }, {}, function (clientResp) {
|
|
|
|
client.token = clientResp.token
|
|
|
|
return growl.success(_t('access_successfully_revoked'))
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
2016-05-09 18:15:04 +02:00
|
|
|
|
2018-10-25 16:51:20 +02:00
|
|
|
])
|