2015-03-16 21:03:26 +00:00
|
|
|
/**
|
|
|
|
* An element which displays a table of events on a repository and allows them to be
|
|
|
|
* edited.
|
|
|
|
*/
|
|
|
|
angular.module('quay').directive('repositoryEventsTable', function () {
|
|
|
|
var directiveDefinitionObject = {
|
|
|
|
priority: 0,
|
|
|
|
templateUrl: '/static/directives/repository-events-table.html',
|
|
|
|
replace: false,
|
|
|
|
transclude: true,
|
|
|
|
restrict: 'C',
|
|
|
|
scope: {
|
2015-05-06 22:16:03 +00:00
|
|
|
'repository': '=repository',
|
|
|
|
'isEnabled': '=isEnabled'
|
2015-03-16 21:03:26 +00:00
|
|
|
},
|
|
|
|
controller: function($scope, $element, ApiService, Restangular, UtilService, ExternalNotificationData) {
|
|
|
|
$scope.showNewNotificationCounter = 0;
|
|
|
|
|
|
|
|
var loadNotifications = function() {
|
2015-05-06 22:16:03 +00:00
|
|
|
if (!$scope.repository || $scope.notificationsResource || !$scope.isEnabled) { return; }
|
|
|
|
|
2015-03-16 21:03:26 +00:00
|
|
|
var params = {
|
|
|
|
'repository': $scope.repository.namespace + '/' + $scope.repository.name
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.notificationsResource = ApiService.listRepoNotificationsAsResource(params).get(
|
|
|
|
function(resp) {
|
|
|
|
$scope.notifications = resp.notifications;
|
|
|
|
return $scope.notifications;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.$watch('repository', loadNotifications);
|
2015-05-06 22:16:03 +00:00
|
|
|
$scope.$watch('isEnabled', loadNotifications);
|
|
|
|
|
2015-03-16 21:03:26 +00:00
|
|
|
loadNotifications();
|
|
|
|
|
|
|
|
$scope.handleNotificationCreated = function(notification) {
|
|
|
|
$scope.notifications.push(notification);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.askCreateNotification = function() {
|
|
|
|
$scope.showNewNotificationCounter++;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.getEventInfo = function(notification) {
|
|
|
|
return ExternalNotificationData.getEventInfo(notification.event);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.getMethodInfo = function(notification) {
|
|
|
|
return ExternalNotificationData.getMethodInfo(notification.method);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.deleteNotification = function(notification) {
|
|
|
|
var params = {
|
|
|
|
'repository': $scope.repository.namespace + '/' + $scope.repository.name,
|
|
|
|
'uuid': notification.uuid
|
|
|
|
};
|
|
|
|
|
|
|
|
ApiService.deleteRepoNotification(null, params).then(function() {
|
|
|
|
var index = $.inArray(notification, $scope.notifications);
|
|
|
|
if (index < 0) { return; }
|
|
|
|
$scope.notifications.splice(index, 1);
|
|
|
|
}, ApiService.errorDisplay('Cannot delete notification'));
|
|
|
|
};
|
|
|
|
|
2015-08-17 20:30:15 +00:00
|
|
|
$scope.showNotifyInfo = function(notification, field) {
|
|
|
|
var dom = document.createElement('input');
|
|
|
|
dom.setAttribute('type', 'text');
|
|
|
|
dom.setAttribute('class', 'form-control');
|
|
|
|
dom.setAttribute('value', notification.config[field]);
|
|
|
|
dom.setAttribute('readonly', 'readonly');
|
|
|
|
|
|
|
|
bootbox.dialog({
|
|
|
|
'title': (notification.title || 'Notification') + ' ' + field,
|
|
|
|
'message': dom.outerHTML,
|
|
|
|
'buttons': {
|
|
|
|
"Done": {
|
|
|
|
className: "btn-primary",
|
|
|
|
callback: function() {}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-16 21:03:26 +00:00
|
|
|
$scope.showWebhookInfo = function(notification) {
|
|
|
|
var eventId = notification.event;
|
|
|
|
document.location = 'http://docs.quay.io/guides/notifications.html#webhook_' + eventId;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.testNotification = function(notification) {
|
|
|
|
var params = {
|
|
|
|
'repository': $scope.repository.namespace + '/' + $scope.repository.name,
|
|
|
|
'uuid': notification.uuid
|
|
|
|
};
|
|
|
|
|
|
|
|
ApiService.testRepoNotification(null, params).then(function() {
|
|
|
|
bootbox.dialog({
|
|
|
|
"title": "Test Notification Queued",
|
|
|
|
"message": "A test version of this notification has been queued and should appear shortly",
|
|
|
|
"buttons": {
|
|
|
|
"close": {
|
|
|
|
"label": "Close",
|
|
|
|
"className": "btn-primary"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, ApiService.errorDisplay('Could not issue test notification'));
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return directiveDefinitionObject;
|
|
|
|
});
|