diff --git a/awx/ui/client/src/management-jobs/notifications/notification.controller.js b/awx/ui/client/src/management-jobs/notifications/notification.controller.js index 2bcf063536..62e8dff8a3 100644 --- a/awx/ui/client/src/management-jobs/notifications/notification.controller.js +++ b/awx/ui/client/src/management-jobs/notifications/notification.controller.js @@ -5,55 +5,33 @@ *************************************************/ export default - [ '$rootScope','Wait', 'generateList', 'NotificationsList', - 'GetBasePath' , 'Rest' , - 'ProcessErrors', 'Prompt', '$state', 'GetChoices', 'Empty', 'Find', - 'ngToast', '$compile', '$filter','ToggleNotification', - 'NotificationsListInit', '$stateParams', 'management_job', + [ 'NotificationsList', 'GetBasePath', 'ToggleNotification', 'NotificationsListInit', + '$stateParams', 'Dataset', '$scope', function( - $rootScope,Wait, GenerateList, NotificationsList, - GetBasePath, Rest, - ProcessErrors, Prompt, $state, GetChoices, Empty, Find, ngToast, - $compile, $filter, ToggleNotification, NotificationsListInit, - $stateParams, management_job) { - var scope = $rootScope.$new(), - url = GetBasePath('notification_templates'), - defaultUrl = GetBasePath('system_job_templates'), - list, - view = GenerateList, + NotificationsList, GetBasePath, ToggleNotification, NotificationsListInit, + $stateParams, Dataset, $scope) { + var defaultUrl = GetBasePath('system_job_templates'), + list = NotificationsList, id = $stateParams.management_id; - list = _.cloneDeep(NotificationsList); - delete list.actions.add; - list.listTitle = `${management_job.name}
Notifications`; - list.searchSize = "col-lg-12 col-md-12 col-sm-12 col-xs-12"; - list.searchRowActions = { - add: { - label: 'Add Notification', - mode: 'all', // One of: edit, select, all - ngClick: 'addNotificationTemplate()', - awToolTip: 'Create a new notification template', - actionClass: 'btn List-buttonSubmit', - buttonContent: '+ ADD NOTIFICATION TEMPLATE' - } - }; - view.inject( list, { - mode: 'edit', - cancelButton: true, - scope: scope - }); + function init() { + $scope.list = list; + $scope[`${list.iterator}_dataset`] = Dataset.data; + $scope[list.name] = $scope[`${list.iterator}_dataset`].results; - NotificationsListInit({ - scope: scope, - url: defaultUrl, - id: id - }); + NotificationsListInit({ + scope: $scope, + url: defaultUrl, + id: id + }); - scope.formCancel = function() { - $state.go('managementJobsList'); - }; + $scope.$watch(`${list.iterator}_dataset`, function() { + // The list data has changed and we need to update which notifications are on/off + $scope.$emit('relatednotifications'); + }); + } - scope.toggleNotification = function(event, notifier_id, column) { + $scope.toggleNotification = function(event, notifier_id, column) { var notifier = this.notification; try { $(event.target).tooltip('hide'); @@ -62,60 +40,15 @@ export default // ignore } ToggleNotification({ - scope: scope, - url: defaultUrl, - id: id, + scope: $scope, + url: defaultUrl + id, notifier: notifier, column: column, callback: 'NotificationRefresh' }); }; - if (scope.removePostRefresh) { - scope.removePostRefresh(); - } - scope.removePostRefresh = scope.$on('PostRefresh', function () { - scope.$emit('relatednotifications'); - }); - - if (scope.removeChoicesHere) { - scope.removeChoicesHere(); - } - scope.removeChoicesHere = scope.$on('choicesReadyNotifierList', function () { - list.fields.notification_type.searchOptions = scope.notification_type_options; - - // @issue: OLD SEARCH - // SearchInit({ - // scope: scope, - // set: 'notifications', - // list: list, - // url: url - // }); - - if ($rootScope.addedItem) { - scope.addedItem = $rootScope.addedItem; - delete $rootScope.addedItem; - } - - // @issue: OLD SEARCH - // PaginateInit({ - // scope: scope, - // list: list, - // url: url - // }); - // - // scope.search(list.iterator); - - }); - - GetChoices({ - scope: scope, - url: url, - field: 'notification_type', - variable: 'notification_type_options', - callback: 'choicesReadyNotifierList' - }); - + init(); } ]; diff --git a/awx/ui/client/src/management-jobs/notifications/notification.route.js b/awx/ui/client/src/management-jobs/notifications/notification.route.js index 8995bd8e6c..0d72dc0319 100644 --- a/awx/ui/client/src/management-jobs/notifications/notification.route.js +++ b/awx/ui/client/src/management-jobs/notifications/notification.route.js @@ -4,43 +4,40 @@ * All Rights Reserved *************************************************/ -import {templateUrl} from '../../shared/template-url/template-url.factory'; - export default { name: 'managementJobsList.notifications', route: '/:management_id/notifications', - templateUrl: templateUrl('management-jobs/notifications/notifications'), - controller: 'managementJobsNotificationsController', - params: {card: null}, - resolve: { - management_job: - [ '$stateParams', - '$q', - 'Rest', - 'GetBasePath', - 'ProcessErrors', - function($stateParams, $q, rest, getBasePath, ProcessErrors) { - - if ($stateParams.card) { - return $q.when($stateParams.card); - } - - var managementJobId = $stateParams.management_id; - - var url = getBasePath('system_job_templates') + managementJobId + '/'; - rest.setUrl(url); - return rest.get() - .then(function(data) { - return data.data; - }).catch(function (response) { - ProcessErrors(null, response.data, response.status, null, { - hdr: 'Error!', - msg: 'Failed to get management job info. GET returned status: ' + - response.status - }); - }); + params: { + notification_search: {} + }, + searchPrefix: 'notification', + views: { + '@managementJobsList': { + controller: 'managementJobsNotificationsController', + templateProvider: function(NotificationsList, generateList, ParentObject) { + // include name of parent resource in listTitle + NotificationsList.listTitle = `${ParentObject.name}
Notifications`; + let html = generateList.build({ + list: NotificationsList, + mode: 'edit' + }); + html = generateList.wrapPanel(html); + return generateList.insertFormView() + html; } - ] + } + }, + resolve: { + Dataset: ['NotificationsList', 'QuerySet', '$stateParams', 'GetBasePath', + function(list, qs, $stateParams, GetBasePath) { + let path = `${GetBasePath('notification_templates')}`; + return qs.search(path, $stateParams[`${list.iterator}_search`]); + } + ], + ParentObject: ['$stateParams', 'Rest', 'GetBasePath', function($stateParams, Rest, GetBasePath) { + let path = `${GetBasePath('system_job_templates')}${$stateParams.management_id}`; + Rest.setUrl(path); + return Rest.get(path).then((res) => res.data); + }] }, ncyBreadcrumb: { parent: 'managementJobsList',