diff --git a/awx/ui/client/src/inventories/main.js b/awx/ui/client/src/inventories/main.js index 046f8bfd98..ae85f2fd54 100644 --- a/awx/ui/client/src/inventories/main.js +++ b/awx/ui/client/src/inventories/main.js @@ -23,6 +23,7 @@ import { copyMoveGroupRoute, copyMoveHostRoute } from './copy-move/copy-move.rou import copyMove from './copy-move/main'; import completedJobsRoute from './completed_jobs/completed_jobs.route'; import inventorySourceEditRoute from './sources/edit/sources-edit.route'; +import inventorySourceEditNotificationsRoute from './sources/edit/sources-notifications.route'; import inventorySourceAddRoute from './sources/add/sources-add.route'; import inventorySourceListRoute from './sources/list/sources-list.route'; import inventorySourceListScheduleRoute from './sources/list/schedule/sources-schedule.route'; @@ -230,6 +231,7 @@ angular.module('inventory', [ stateExtender.buildDefinition(inventorySourceListRoute), stateExtender.buildDefinition(inventorySourceAddRoute), stateExtender.buildDefinition(inventorySourceEditRoute), + stateExtender.buildDefinition(inventorySourceEditNotificationsRoute), stateExtender.buildDefinition(inventoryCompletedJobsRoute), stateExtender.buildDefinition(smartInventoryCompletedJobsRoute), stateExtender.buildDefinition(addSourceCredential), diff --git a/awx/ui/client/src/inventories/sources/edit/sources-notifications.route.js b/awx/ui/client/src/inventories/sources/edit/sources-notifications.route.js new file mode 100644 index 0000000000..1596bfb9d7 --- /dev/null +++ b/awx/ui/client/src/inventories/sources/edit/sources-notifications.route.js @@ -0,0 +1,89 @@ +import { N_ } from '../../../i18n'; + +export default { + searchPrefix: 'notification', + name: "inventories.edit.inventory_sources.edit.notifications", + url: `/notifications`, + ncyBreadcrumb: { + parent: "inventories.edit.inventory_sources.edit", + label: N_("NOTIFICATIONS") + }, + params: { + [ 'notification_search']: { + value: { order_by: 'name' } + } + }, + views: { + 'related': { + templateProvider: function(FormDefinition, GenerateForm, $stateParams, SourcesFormDefinition) { + var form, html; + if($stateParams && $stateParams.inventory_source_id){ + form = SourcesFormDefinition; + } + else { + form = typeof(FormDefinition) === 'function' ? + FormDefinition() : FormDefinition; + } + html = GenerateForm.buildCollection({ + mode: 'edit', + related: `notifications`, + form: form + }); + return html; + }, + controller: ['$scope', 'NotificationsList', 'Dataset', 'ToggleNotification', 'NotificationsListInit', 'GetBasePath', '$stateParams', + function($scope, list, Dataset, ToggleNotification, NotificationsListInit, GetBasePath, $stateParams) { + var params = $stateParams, + id = params.inventory_source_id, + url = GetBasePath('inventory_sources'); + + function init() { + $scope.list = list; + $scope[`${list.iterator}_dataset`] = Dataset.data; + $scope[list.name] = $scope[`${list.iterator}_dataset`].results; + + + NotificationsListInit({ + scope: $scope, + url: url, + id: id + }); + + $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) { + var notifier = this.notification; + try { + $(event.target).tooltip('hide'); + } + catch(e) { + // ignore + } + ToggleNotification({ + scope: $scope, + url: url + id, + notifier: notifier, + column: column, + callback: 'NotificationRefresh' + }); + }; + + init(); + + } + ] + } + }, + resolve: { + Dataset: ['NotificationsList', 'QuerySet', '$stateParams', 'GetBasePath', + (list, qs, $stateParams, GetBasePath) => { + let path = GetBasePath(list.basePath); + return qs.search(path, $stateParams[`${list.iterator}_search`]); + } + ] + } +};