From 394c7ed3410c6682c23d7cb46b99d963c6fdb778 Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Wed, 3 May 2017 15:41:03 -0400 Subject: [PATCH] adding notifications to the inventory source --- awx/ui/client/src/inventories/sources/main.js | 2 +- .../src/inventories/sources/sources.form.js | 29 +++++++++++++++-- .../src/inventories/sources/sources.list.js | 2 +- .../shared/notification-list-init.factory.js | 22 ++++++++++--- .../src/shared/stateDefinitions.factory.js | 32 +++++++++---------- 5 files changed, 62 insertions(+), 25 deletions(-) diff --git a/awx/ui/client/src/inventories/sources/main.js b/awx/ui/client/src/inventories/sources/main.js index e2ca31f6a0..8e2c82bcb7 100644 --- a/awx/ui/client/src/inventories/sources/main.js +++ b/awx/ui/client/src/inventories/sources/main.js @@ -21,7 +21,7 @@ export default sourcesAdd.name, sourcesEdit.name ]) - .value('SourcesFormDefinition', sourcesFormDefinition) + .factory('SourcesFormDefinition', sourcesFormDefinition) .value('SourcesListDefinition', sourcesListDefinition) .factory('GetSyncStatusMsg', GetSyncStatusMsg) .factory('ViewUpdateStatus', ViewUpdateStatus) diff --git a/awx/ui/client/src/inventories/sources/sources.form.js b/awx/ui/client/src/inventories/sources/sources.form.js index 32968fc3db..dc216c7e67 100644 --- a/awx/ui/client/src/inventories/sources/sources.form.js +++ b/awx/ui/client/src/inventories/sources/sources.form.js @@ -10,7 +10,25 @@ * @description This form is for adding/editing a Group on the inventory page */ -export default { +export default ['NotificationsList', 'i18n', function(NotificationsList, i18n){ + + var notifications_object = { + name: 'notifications', + index: false, + basePath: "notifications", + include: "NotificationsList", + title: i18n._('Notifications'), + iterator: 'notification', + disabled: "source === undefined || source.value === ''", + generateList: true, + ngClick: "$state.go('inventories.edit.inventory_sources.edit.notifications')" + // search: { + // "or__job__inventory": '' + // } + }; + let clone = _.clone(NotificationsList); + notifications_object = angular.extend(clone, notifications_object); +return { addTitle: 'CREATE SOURCE', editTitle: '{{ name }}', showTitle: true, @@ -19,9 +37,10 @@ export default { parent: 'inventories.edit.sources', // the parent node this generated state definition tree expects to attach to stateTree: 'inventories', + tabs: true, // form generator inspects the current state name to determine whether or not to set an active (.is-selected) class on a form tab // this setting is optional on most forms, except where the form's edit state name is not parentStateName.edit - activeEditState: 'inventories.edit.groups.editGroup', + activeEditState: 'inventories.edit.inventory_sources.edit', detailsClick: "$state.go('inventories.edit.inventory_sources.edit')", well: false, fields: { @@ -333,5 +352,11 @@ export default { ngDisabled: true, ngShow: '(group_obj.summary_fields.user_capabilities.edit || canAdd)' } + }, + + related: { + notifications: notifications_object } }; + +}]; diff --git a/awx/ui/client/src/inventories/sources/sources.list.js b/awx/ui/client/src/inventories/sources/sources.list.js index 157477bdd1..38288bf04e 100644 --- a/awx/ui/client/src/inventories/sources/sources.list.js +++ b/awx/ui/client/src/inventories/sources/sources.list.js @@ -32,7 +32,7 @@ export default { name: { label: 'Sources', key: true, - ngClick: "groupSelect(inventory_source.id)", + ngClick: "editSource(inventory_source.id)", columnClass: 'col-lg-6 col-md-6 col-sm-6 col-xs-6', class: 'InventoryManage-breakWord', } diff --git a/awx/ui/client/src/notifications/shared/notification-list-init.factory.js b/awx/ui/client/src/notifications/shared/notification-list-init.factory.js index 319f49c436..981e7721a3 100644 --- a/awx/ui/client/src/notifications/shared/notification-list-init.factory.js +++ b/awx/ui/client/src/notifications/shared/notification-list-init.factory.js @@ -15,8 +15,8 @@ */ export default ['Wait', 'GetBasePath', 'ProcessErrors', 'Rest', 'GetChoices', - '$state', '$rootScope', - function(Wait, GetBasePath, ProcessErrors, Rest, GetChoices, $state, $rootScope) { + '$state', '$rootScope', '$stateParams', + function(Wait, GetBasePath, ProcessErrors, Rest, GetChoices, $state, $rootScope, $stateParams) { return function(params) { var scope = params.scope, url = params.url, @@ -31,8 +31,22 @@ export default ['Wait', 'GetBasePath', 'ProcessErrors', 'Rest', 'GetChoices', }); scope.addNotificationTemplate = function() { - if (id) { - $state.go('notifications.add', {organization_id: id}); + var org_id; + if($stateParams.hasOwnProperty('project_id')){ + org_id = scope.$parent.project_obj.organization; + } + else if($stateParams.hasOwnProperty('workflow_job_template_id')){ + org_id = scope.$parent.workflow_job_template_obj.organization; + } + else if($stateParams.hasOwnProperty('inventory_source_id')){ + org_id = scope.$parent.summary_fields.inventory.organization_id; + } + else if($stateParams.hasOwnProperty('organization_id')){ + org_id = scope.$parent.organization_id; + } + + if (org_id) { + $state.go('notifications.add', {organization_id: org_id}); } else { $state.go('notifications.add'); diff --git a/awx/ui/client/src/shared/stateDefinitions.factory.js b/awx/ui/client/src/shared/stateDefinitions.factory.js index 0ac639afe5..14395fc024 100644 --- a/awx/ui/client/src/shared/stateDefinitions.factory.js +++ b/awx/ui/client/src/shared/stateDefinitions.factory.js @@ -407,17 +407,24 @@ function($injector, $stateExtender, $log, i18n) { }, views: { 'related': { - templateProvider: function(FormDefinition, GenerateForm) { - let html = GenerateForm.buildCollection({ + 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: `${list.iterator}s`, - form: typeof(FormDefinition) === 'function' ? - FormDefinition() : FormDefinition + form: form }); return html; }, - controller: ['$scope', 'ListDefinition', 'Dataset', 'ToggleNotification', 'NotificationsListInit', 'GetBasePath', '$stateParams', 'inventorySourceData', - function($scope, list, Dataset, ToggleNotification, NotificationsListInit, GetBasePath, $stateParams, inventorySourceData) { + controller: ['$scope', 'ListDefinition', 'Dataset', 'ToggleNotification', 'NotificationsListInit', 'GetBasePath', '$stateParams', + function($scope, list, Dataset, ToggleNotification, NotificationsListInit, GetBasePath, $stateParams) { var url , params = $stateParams, id; if(params.hasOwnProperty('project_id')){ id = params.project_id; @@ -431,8 +438,8 @@ function($injector, $stateExtender, $log, i18n) { id = params.workflow_job_template_id; url = GetBasePath('workflow_job_templates'); } - if(params.hasOwnProperty('inventory_id')){ - id = inventorySourceData.id; + if(params.hasOwnProperty('inventory_source_id')){ + id = params.inventory_source_id; url = GetBasePath('inventory_sources'); } if(params.hasOwnProperty('organization_id')){ @@ -484,15 +491,6 @@ function($injector, $stateExtender, $log, i18n) { ListDefinition: () => { return list; }, - inventorySourceData: ['$stateParams', //'GroupManageService', - function($stateParams){ //, GroupManageService) { - if($stateParams.hasOwnProperty('group_id')){ - return; //GroupManageService.getInventorySource({ group: $stateParams.group_id }).then(res => res.data.results[0]); - } - else{ - return null; - } - }], Dataset: ['ListDefinition', 'QuerySet', '$stateParams', 'GetBasePath', '$interpolate', '$rootScope', (list, qs, $stateParams, GetBasePath, $interpolate, $rootScope) => { // allow related list definitions to use interpolated $rootScope / $stateParams in basePath field