webapp.scripts.components.entities.settings.service.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of centraldogma-server Show documentation
Show all versions of centraldogma-server Show documentation
Highly-available version-controlled service configuration repository based on Git, ZooKeeper and HTTP/2 (centraldogma-server)
'use strict';
angular.module('CentralDogmaAdmin')
.factory('SettingsService',
function (ApiV1Service, EntitiesUtil, $q) {
return {
listTokens: function () {
var defer = $q.defer();
ApiV1Service.get("tokens").then(function (tokens) {
var i;
if (angular.isArray(tokens)) {
for (i in tokens) {
tokens[i].creationTimeStr = moment(tokens[i].creation.timestamp).fromNow();
tokens[i].isActive = !angular.isDefined(tokens[i].deactivation);
tokens[i].isDeleted = angular.isDefined(tokens[i].deletion);
}
defer.resolve(tokens);
} else {
defer.resolve([]);
}
}, function (error) {
defer.reject(error);
});
return defer.promise;
},
createToken: function (data) {
return ApiV1Service.post('tokens', data, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
},
activateToken: function (id) {
return ApiV1Service.jsonPatch('tokens/' + id,
EntitiesUtil.toReplaceJsonPatch('/status', 'active'));
},
deactivateToken: function (id) {
return ApiV1Service.jsonPatch('tokens/' + id,
EntitiesUtil.toReplaceJsonPatch('/status', 'inactive'));
},
deleteToken: function (id) {
return ApiV1Service.delete('tokens/' + id);
}
};
});