From 14e154acce81a64c56eca9a6588dc960c817a329 Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Mon, 19 Dec 2016 22:48:46 -0800 Subject: [PATCH] fixing related notification lists --- awx/ui/client/src/forms/Groups.js | 1 + .../src/shared/stateDefinitions.factory.js | 142 ++++++++++++++++-- 2 files changed, 134 insertions(+), 9 deletions(-) diff --git a/awx/ui/client/src/forms/Groups.js b/awx/ui/client/src/forms/Groups.js index 9f9828a10f..b5c876c3b9 100644 --- a/awx/ui/client/src/forms/Groups.js +++ b/awx/ui/client/src/forms/Groups.js @@ -354,6 +354,7 @@ export default GroupFormObject.related[itm] = angular.copy(NotificationsList); GroupFormObject.related[itm].generateList = true; GroupFormObject.related[itm].disabled = "source === undefined || source.value === ''"; + GroupFormObject.related[itm].ngClick = "$state.go('inventoryManage.editGroup.notifications')"; } } return GroupFormObject; diff --git a/awx/ui/client/src/shared/stateDefinitions.factory.js b/awx/ui/client/src/shared/stateDefinitions.factory.js index 2c3bb8c4cb..25382af7ab 100644 --- a/awx/ui/client/src/shared/stateDefinitions.factory.js +++ b/awx/ui/client/src/shared/stateDefinitions.factory.js @@ -361,19 +361,143 @@ export default ['$injector', '$stateExtender', '$log', function($injector, $stat return states; } + function buildNotificationState(field) { + let state, + list = field.include ? $injector.get(field.include) : field; + state = $stateExtender.buildDefinition({ + searchPrefix: `${list.iterator}`, + name: `${formStateDefinition.name}.${list.iterator}s`, + url: `/${list.iterator}s`, + ncyBreadcrumb: { + parent: `${formStateDefinition.name}`, + label: `${field.iterator}s` + }, + params: { + [list.iterator + '_search']: { + value: { order_by: field.order_by ? field.order_by : 'name' } + } + }, + views: { + 'related': { + templateProvider: function(FormDefinition, GenerateForm) { + let html = GenerateForm.buildCollection({ + mode: 'edit', + related: `${list.iterator}s`, + form: typeof(FormDefinition) === 'function' ? + FormDefinition() : FormDefinition + }); + return html; + }, + controller: ['$scope', 'ListDefinition', 'Dataset', 'ToggleNotification', 'NotificationsListInit', 'GetBasePath', '$stateParams', 'inventorySourceData', + function($scope, list, Dataset, ToggleNotification, NotificationsListInit, GetBasePath, $stateParams, inventorySourceData) { + var url , params = $stateParams, id; + if(params.hasOwnProperty('project_id')){ + id = params.project_id; + url = GetBasePath('projects'); + } + if(params.hasOwnProperty('job_template_id')){ + id = params.job_template_id; + url = GetBasePath('job_templates'); + } + if(params.hasOwnProperty('workflow_job_template_id')){ + id = params.workflow_job_template_id; + url = GetBasePath('workflow_job_templates'); + } + if(params.hasOwnProperty('inventory_id')){ + id = inventorySourceData.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: { + 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]); + } + }], + 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 + let path, interpolator; + if (GetBasePath(list.basePath)) { + path = GetBasePath(list.basePath); + } else { + interpolator = $interpolate(list.basePath); + path = interpolator({ $rootScope: $rootScope, $stateParams: $stateParams }); + } + return qs.search(path, $stateParams[`${list.iterator}_search`]); + } + ] + } + }); + // // appy any default search parameters in form definition + // if (field.search) { + // state.params[`${field.iterator}_search`].value = _.merge(state.params[`${field.iterator}_search`].value, field.search); + // } + return state; + } + function buildListNodes(field) { let states = []; - states.push(buildListDefinition(field)); - if (field.iterator === 'permission' && field.actions && field.actions.add) { - if (form.name === 'user' || form.name === 'team'){ - states.push(buildRbacUserTeamDirective()); - - } - else { - states.push(buildRbacResourceDirective()); - } + if(field.iterator === 'notification'){ + states.push(buildNotificationState(field)); states = _.flatten(states); } + else{ + states.push(buildListDefinition(field)); + if (field.iterator === 'permission' && field.actions && field.actions.add) { + if (form.name === 'user' || form.name === 'team'){ + states.push(buildRbacUserTeamDirective()); + + } + else { + states.push(buildRbacResourceDirective()); + } + states = _.flatten(states); + } + } return states; }