This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/directives/ui/application-manager.js

66 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-11-12 16:09:47 +00:00
/**
* Element for managing the applications of an organization.
*/
angular.module('quay').directive('applicationManager', function () {
var directiveDefinitionObject = {
priority: 0,
templateUrl: '/static/directives/application-manager.html',
replace: false,
transclude: false,
restrict: 'C',
scope: {
'organization': '=organization',
'makevisible': '=makevisible'
},
controller: function($scope, $element, ApiService) {
$scope.loading = false;
$scope.applications = [];
$scope.feedback = null;
$scope.createApplication = function(appName) {
if (!appName) { return; }
var params = {
'orgname': $scope.organization.name
};
var data = {
'name': appName
};
ApiService.createOrganizationApplication(data, params).then(function(resp) {
$scope.applications.push(resp);
$scope.feedback = {
'kind': 'success',
'message': 'Application {application_name} created',
'data': {
'application_name': appName
}
};
}, ApiService.errorDisplay('Cannot create application'));
};
var update = function() {
if (!$scope.organization || !$scope.makevisible) { return; }
if ($scope.loading) { return; }
$scope.loading = true;
var params = {
'orgname': $scope.organization.name
};
ApiService.getOrganizationApplications(null, params).then(function(resp) {
$scope.loading = false;
$scope.applications = resp['applications'] || [];
});
};
$scope.$watch('organization', update);
$scope.$watch('makevisible', update);
}
};
return directiveDefinitionObject;
});