From 06d5f16730a1b475fe97751494c83e96f76162ba Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Fri, 12 May 2017 12:23:16 -0400 Subject: [PATCH] Fixed inventory codemirror namespace clashing amongst other small bug fixes --- .../edit/inventory-edit.controller.js | 94 +++++++------------ .../groups/add/groups-add.controller.js | 6 +- .../groups/edit/groups-edit.controller.js | 17 ++-- .../src/inventories/groups/groups.form.js | 5 +- .../inventories/groups/nested-groups/main.js | 8 +- .../nested-groups-add.controller.js | 62 ++++++++++++ .../nested-groups/nested-groups-add.route.js | 6 +- .../nested-groups/nested-groups.form.js | 5 +- .../groups/nested-hosts/nested-hosts.form.js | 2 - .../client/src/inventories/hosts/host.form.js | 2 - .../client/src/inventories/inventory.form.js | 6 +- .../edit/host-edit.controller.js | 13 +-- .../related-hosts/edit/host-edit.route.js | 2 +- .../related-hosts/related-host.form.js | 4 +- 14 files changed, 130 insertions(+), 102 deletions(-) create mode 100644 awx/ui/client/src/inventories/groups/nested-groups/nested-groups-add.controller.js diff --git a/awx/ui/client/src/inventories/edit/inventory-edit.controller.js b/awx/ui/client/src/inventories/edit/inventory-edit.controller.js index 355b20735e..20c039216d 100644 --- a/awx/ui/client/src/inventories/edit/inventory-edit.controller.js +++ b/awx/ui/client/src/inventories/edit/inventory-edit.controller.js @@ -13,23 +13,46 @@ function InventoriesEdit($scope, $location, $stateParams, InventoryForm, Rest, ProcessErrors, ClearScope, GetBasePath, ParseTypeChange, Wait, ToJSON, - ParseVariableString, $state, OrgAdminLookup, $rootScope) { + ParseVariableString, $state, OrgAdminLookup, $rootScope, resourceData) { // Inject dynamic view var defaultUrl = GetBasePath('inventory'), form = InventoryForm, - inventory_id = $stateParams.inventory_id, - master = {}, - fld, data; + fld, data, + inventoryData = resourceData.data; - ClearScope(); init(); function init() { - ClearScope(); form.formLabelSize = null; form.formFieldSize = null; - $scope.inventory_id = inventory_id; + + $scope = angular.extend($scope, inventoryData); + + $scope.organization_name = inventoryData.summary_fields.organization.name; + + $scope.inventory_variables = inventoryData.variables === null || inventoryData.variables === '' ? '---' : ParseVariableString(inventoryData.variables); + + $scope.parseType = 'yaml'; + + $rootScope.$on('$stateChangeSuccess', function(event, toState) { + if(toState.name === 'inventories.edit') { + ParseTypeChange({ + scope: $scope, + variable: 'inventory_variables', + parse_variable: 'parseType', + field_id: 'inventory_inventory_variables' + }); + } + }); + + OrgAdminLookup.checkForAdminAccess({organization: inventoryData.organization}) + .then(function(canEditOrg){ + $scope.canEditOrg = canEditOrg; + }); + + $scope.inventory_obj = inventoryData; + $rootScope.breadcrumb.inventory_name = inventoryData.name; $scope.$watch('inventory_obj.summary_fields.user_capabilities.edit', function(val) { if (val === false) { @@ -38,59 +61,6 @@ function InventoriesEdit($scope, $location, }); } - - Wait('start'); - Rest.setUrl(GetBasePath('inventory') + inventory_id + '/'); - Rest.get() - .success(function(data) { - var fld; - for (fld in form.fields) { - if (fld === 'inventory_variables') { - $scope.inventory_variables = ParseVariableString(data.variables); - master.inventory_variables = $scope.variables; - } else if (fld === 'inventory_name') { - $scope[fld] = data.name; - master[fld] = $scope[fld]; - } else if (fld === 'inventory_description') { - $scope[fld] = data.description; - master[fld] = $scope[fld]; - } else if (data[fld]) { - $scope[fld] = data[fld]; - master[fld] = $scope[fld]; - } - if (form.fields[fld].sourceModel && data.summary_fields && - data.summary_fields[form.fields[fld].sourceModel]) { - $scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] = - data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField]; - master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] = - data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField]; - } - } - - Wait('stop'); - $scope.parseType = 'yaml'; - ParseTypeChange({ - scope: $scope, - variable: 'inventory_variables', - parse_variable: 'parseType', - field_id: 'inventory_inventory_variables' - }); - - OrgAdminLookup.checkForAdminAccess({organization: data.organization}) - .then(function(canEditOrg){ - $scope.canEditOrg = canEditOrg; - }); - - $scope.inventory_obj = data; - $rootScope.breadcrumb.inventory_name = data.name; - $scope.name = data.name; - }) - .error(function(data, status) { - ProcessErrors($scope, data, status, null, { - hdr: 'Error!', - msg: 'Failed to get inventory: ' + inventory_id + '. GET returned: ' + status - }); - }); // Save $scope.formSave = function() { Wait('start'); @@ -104,7 +74,7 @@ function InventoriesEdit($scope, $location, } } - Rest.setUrl(defaultUrl + inventory_id + '/'); + Rest.setUrl(defaultUrl + $stateParams.inventory_id + '/'); Rest.put(data) .success(function() { Wait('stop'); @@ -128,5 +98,5 @@ export default ['$scope', '$location', '$stateParams', 'InventoryForm', 'Rest', 'ProcessErrors', 'ClearScope', 'GetBasePath', 'ParseTypeChange', 'Wait', 'ToJSON', 'ParseVariableString', - '$state', 'OrgAdminLookup', '$rootScope', InventoriesEdit, + '$state', 'OrgAdminLookup', '$rootScope', 'resourceData', InventoriesEdit, ]; diff --git a/awx/ui/client/src/inventories/groups/add/groups-add.controller.js b/awx/ui/client/src/inventories/groups/add/groups-add.controller.js index ae37692ba1..f25959d1fe 100644 --- a/awx/ui/client/src/inventories/groups/add/groups-add.controller.js +++ b/awx/ui/client/src/inventories/groups/add/groups-add.controller.js @@ -28,8 +28,8 @@ export default ['$state', '$stateParams', '$scope', 'GroupForm', $scope.envParseType = 'yaml'; ParseTypeChange({ scope: $scope, - field_id: 'group_variables', - variable: 'variables', + field_id: 'group_group_variables', + variable: 'group_variables', }); } @@ -39,7 +39,7 @@ export default ['$state', '$stateParams', '$scope', 'GroupForm', $scope.formSave = function() { var json_data; - json_data = ToJSON($scope.parseType, $scope.variables, true); + json_data = ToJSON($scope.parseType, $scope.group_variables, true); var group = { variables: json_data, diff --git a/awx/ui/client/src/inventories/groups/edit/groups-edit.controller.js b/awx/ui/client/src/inventories/groups/edit/groups-edit.controller.js index 794df0daad..f4e235a061 100644 --- a/awx/ui/client/src/inventories/groups/edit/groups-edit.controller.js +++ b/awx/ui/client/src/inventories/groups/edit/groups-edit.controller.js @@ -26,16 +26,19 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString', 'rbac }); // init codemirror(s) - $scope.variables = $scope.variables === null || $scope.variables === '' ? '---' : ParseVariableString($scope.variables); + $scope.group_variables = $scope.variables === null || $scope.variables === '' ? '---' : ParseVariableString($scope.variables); $scope.parseType = 'yaml'; $scope.envParseType = 'yaml'; - ParseTypeChange({ - scope: $scope, - field_id: 'group_variables', - variable: 'variables', + $rootScope.$on('$stateChangeSuccess', function(event, toState) { + if(toState.name === 'inventories.edit.groups.edit') { + ParseTypeChange({ + scope: $scope, + field_id: 'group_group_variables', + variable: 'group_variables', + }); + } }); - } $scope.formCancel = function() { @@ -44,7 +47,7 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString', 'rbac $scope.formSave = function() { var json_data; - json_data = ToJSON($scope.parseType, $scope.variables, true); + json_data = ToJSON($scope.parseType, $scope.group_variables, true); // group fields var group = { variables: json_data, diff --git a/awx/ui/client/src/inventories/groups/groups.form.js b/awx/ui/client/src/inventories/groups/groups.form.js index b8a378c733..eb52db6ad7 100644 --- a/awx/ui/client/src/inventories/groups/groups.form.js +++ b/awx/ui/client/src/inventories/groups/groups.form.js @@ -41,7 +41,8 @@ function(i18n){ ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)', tab: 'properties' }, - variables: { + group_variables: { + realName: 'variables', label: 'Variables', type: 'textarea', class: 'Form-textAreaLabel Form-formGroup--fullWidth', @@ -85,8 +86,6 @@ function(i18n){ awToolTip: i18n._('Please save before defining groups'), dataPlacement: 'top', ngClick: "$state.go('inventories.edit.groups.edit.nested_groups')", - include: "NestedGroupListDefinition", - includeForm: "NestedGroupFormDefinition", title: i18n._('Groups'), iterator: 'nested_group' }, diff --git a/awx/ui/client/src/inventories/groups/nested-groups/main.js b/awx/ui/client/src/inventories/groups/nested-groups/main.js index 9146e87664..e846f24b36 100644 --- a/awx/ui/client/src/inventories/groups/nested-groups/main.js +++ b/awx/ui/client/src/inventories/groups/nested-groups/main.js @@ -5,11 +5,13 @@ *************************************************/ import nestedGroupListDefinition from './nested-groups.list'; -import nestedGroupFormDefinition from './nested-groups.form'; +import NestedGroupForm from './nested-groups.form'; import controller from './nested-groups-list.controller'; +import addController from './nested-groups-add.controller'; export default angular.module('nestedGroups', []) .value('NestedGroupListDefinition', nestedGroupListDefinition) - .factory('NestedGroupFormDefinition', nestedGroupFormDefinition) - .controller('NestedGroupsListController', controller); + .factory('NestedGroupForm', NestedGroupForm) + .controller('NestedGroupsListController', controller) + .controller('NestedGroupsAddController', addController); diff --git a/awx/ui/client/src/inventories/groups/nested-groups/nested-groups-add.controller.js b/awx/ui/client/src/inventories/groups/nested-groups/nested-groups-add.controller.js new file mode 100644 index 0000000000..76e6d1329f --- /dev/null +++ b/awx/ui/client/src/inventories/groups/nested-groups/nested-groups-add.controller.js @@ -0,0 +1,62 @@ +/************************************************* + * Copyright (c) 2017 Ansible, Inc. + * + * All Rights Reserved + *************************************************/ + +export default ['$state', '$stateParams', '$scope', 'NestedGroupForm', + 'ParseTypeChange', 'GenerateForm', 'inventoryData', 'GroupManageService', + 'GetChoices', 'GetBasePath', 'CreateSelect2', + 'rbacUiControlService', 'ToJSON', + function($state, $stateParams, $scope, NestedGroupForm, ParseTypeChange, + GenerateForm, inventoryData, GroupManageService, GetChoices, + GetBasePath, CreateSelect2, rbacUiControlService, + ToJSON) { + + let form = NestedGroupForm; + init(); + + function init() { + // apply form definition's default field values + GenerateForm.applyDefaults(form, $scope); + + rbacUiControlService.canAdd(GetBasePath('inventory') + $stateParams.inventory_id + "/groups") + .then(function(canAdd) { + $scope.canAdd = canAdd; + }); + $scope.parseType = 'yaml'; + $scope.envParseType = 'yaml'; + ParseTypeChange({ + scope: $scope, + field_id: 'nested_group_nested_group_variables', + variable: 'nested_group_variables', + }); + } + + $scope.formCancel = function() { + $state.go('^'); + }; + + $scope.formSave = function() { + var json_data; + json_data = ToJSON($scope.parseType, $scope.nested_group_variables, true); + + var group = { + variables: json_data, + name: $scope.name, + description: $scope.description, + inventory: inventoryData.id + }; + + GroupManageService.post(group).then(res => { + if ($stateParams.group_id) { + return GroupManageService.associateGroup(res.data, $stateParams.group_id) + .then(() => $state.go('^', null, { reload: true })); + } else { + $state.go('^.edit', { group_id: res.data.id }, { reload: true }); + } + }); + + }; + } +]; diff --git a/awx/ui/client/src/inventories/groups/nested-groups/nested-groups-add.route.js b/awx/ui/client/src/inventories/groups/nested-groups/nested-groups-add.route.js index e524d445fb..78f866e2b9 100644 --- a/awx/ui/client/src/inventories/groups/nested-groups/nested-groups-add.route.js +++ b/awx/ui/client/src/inventories/groups/nested-groups/nested-groups-add.route.js @@ -9,14 +9,14 @@ export default { }, views: { 'nestedGroupForm@inventories': { - templateProvider: function(GenerateForm, GroupForm) { - let form = GroupForm; + templateProvider: function(GenerateForm, NestedGroupForm) { + let form = NestedGroupForm; return GenerateForm.buildHTML(form, { mode: 'add', related: false }); }, - controller: 'GroupAddController' + controller: 'NestedGroupsAddController' } } }; diff --git a/awx/ui/client/src/inventories/groups/nested-groups/nested-groups.form.js b/awx/ui/client/src/inventories/groups/nested-groups/nested-groups.form.js index 7b5d7cc77e..96b55daff8 100644 --- a/awx/ui/client/src/inventories/groups/nested-groups/nested-groups.form.js +++ b/awx/ui/client/src/inventories/groups/nested-groups/nested-groups.form.js @@ -42,7 +42,8 @@ function(i18n){ ngDisabled: '!(group_obj.summary_fields.user_capabilities.edit || canAdd)', tab: 'properties' }, - variables: { + nested_group_variables: { + realName: 'variables', label: 'Variables', type: 'textarea', class: 'Form-textAreaLabel Form-formGroup--fullWidth', @@ -84,8 +85,6 @@ function(i18n){ nested_groups: { name: 'related_groups', ngClick: "$state.go('inventories.edit.groups.edit.related_groups')", - include: "RelatedGroupListDefinition", - includeForm: "RelatedGroupFormDefinition", title: i18n._('Groups'), iterator: 'related_group' }, diff --git a/awx/ui/client/src/inventories/groups/nested-hosts/nested-hosts.form.js b/awx/ui/client/src/inventories/groups/nested-hosts/nested-hosts.form.js index 780df59dcf..50cc60cdb4 100644 --- a/awx/ui/client/src/inventories/groups/nested-hosts/nested-hosts.form.js +++ b/awx/ui/client/src/inventories/groups/nested-hosts/nested-hosts.form.js @@ -117,8 +117,6 @@ function(i18n) { awToolTip: i18n._('Please save before defining groups'), dataPlacement: 'top', ngClick: "$state.go('inventories.edit.groups.edit.nested_hosts.edit.nested_groups')", - include: "NestedGroupListDefinition", - includeForm: "NestedGroupFormDefinition", title: i18n._('Groups'), iterator: 'nested_group' }, diff --git a/awx/ui/client/src/inventories/hosts/host.form.js b/awx/ui/client/src/inventories/hosts/host.form.js index 474121457a..05ad0aa96b 100644 --- a/awx/ui/client/src/inventories/hosts/host.form.js +++ b/awx/ui/client/src/inventories/hosts/host.form.js @@ -116,8 +116,6 @@ function(i18n) { awToolTip: i18n._('Please save before defining groups'), dataPlacement: 'top', ngClick: "$state.go('hosts.edit.nested_groups')", - include: "NestedGroupListDefinition", - includeForm: "NestedGroupFormDefinition", title: i18n._('Groups'), iterator: 'nested_group' }, diff --git a/awx/ui/client/src/inventories/inventory.form.js b/awx/ui/client/src/inventories/inventory.form.js index 5e2535205d..08e3d8df48 100644 --- a/awx/ui/client/src/inventories/inventory.form.js +++ b/awx/ui/client/src/inventories/inventory.form.js @@ -40,7 +40,7 @@ function(i18n, InventoryCompletedJobsList) { tabs: true, fields: { - inventory_name: { + name: { realName: 'name', label: i18n._('Name'), type: 'text', @@ -48,7 +48,7 @@ function(i18n, InventoryCompletedJobsList) { capitalize: false, ngDisabled: '!(inventory_obj.summary_fields.user_capabilities.edit || canAdd)' }, - inventory_description: { + description: { realName: 'description', label: i18n._('Description'), type: 'text', @@ -172,8 +172,6 @@ function(i18n, InventoryCompletedJobsList) { name: 'inventory_sources', awToolTip: i18n._('Please save before defining inventory sources'), dataPlacement: 'top', - include: "SourcesListDefinition", - includeForm: "SourcesFormDefinition", title: i18n._('Sources'), iterator: 'inventory_source', skipGenerator: true diff --git a/awx/ui/client/src/inventories/related-hosts/edit/host-edit.controller.js b/awx/ui/client/src/inventories/related-hosts/edit/host-edit.controller.js index 048388f791..fa793fc097 100644 --- a/awx/ui/client/src/inventories/related-hosts/edit/host-edit.controller.js +++ b/awx/ui/client/src/inventories/related-hosts/edit/host-edit.controller.js @@ -5,8 +5,8 @@ *************************************************/ export default - ['$scope', '$state', '$stateParams', 'DashboardHostsForm', 'GenerateForm', 'ParseTypeChange', 'DashboardHostService', 'host', - function($scope, $state, $stateParams, DashboardHostsForm, GenerateForm, ParseTypeChange, DashboardHostService, host){ + ['$scope', '$state', '$stateParams', 'DashboardHostsForm', 'GenerateForm', 'ParseTypeChange', 'DashboardHostService', 'host', '$rootScope', + function($scope, $state, $stateParams, DashboardHostsForm, GenerateForm, ParseTypeChange, DashboardHostService, host, $rootScope){ $scope.parseType = 'yaml'; $scope.formCancel = function(){ $state.go('^', null, {reload: true}); @@ -23,7 +23,7 @@ $scope.formSave = function(){ var host = { id: $scope.host.id, - variables: $scope.variables === '---' || $scope.variables === '{}' ? null : $scope.variables, + variables: $scope.host_variables === '---' || $scope.host_variables === '{}' ? null : $scope.host_variables, name: $scope.name, description: $scope.description, enabled: $scope.host.enabled @@ -36,12 +36,13 @@ var init = function(){ $scope.host = host; $scope.name = host.name; + $rootScope.breadcrumb.host_name = host.name; $scope.description = host.description; - $scope.variables = getVars(host.variables); + $scope.host_variables = getVars(host.variables); ParseTypeChange({ scope: $scope, - field_id: 'host_variables', - variable: 'variables', + field_id: 'host_host_variables', + variable: 'host_variables', }); }; diff --git a/awx/ui/client/src/inventories/related-hosts/edit/host-edit.route.js b/awx/ui/client/src/inventories/related-hosts/edit/host-edit.route.js index f44066c625..5bc5d264b5 100644 --- a/awx/ui/client/src/inventories/related-hosts/edit/host-edit.route.js +++ b/awx/ui/client/src/inventories/related-hosts/edit/host-edit.route.js @@ -3,7 +3,7 @@ export default { url: "/edit/:host_id", ncyBreadcrumb: { parent: "inventories.edit.hosts", - label: "HOSTS" + label: "{{breadcrumb.host_name}}" }, views: { 'hostForm@inventories': { diff --git a/awx/ui/client/src/inventories/related-hosts/related-host.form.js b/awx/ui/client/src/inventories/related-hosts/related-host.form.js index 9dc29daf31..941f98d995 100644 --- a/awx/ui/client/src/inventories/related-hosts/related-host.form.js +++ b/awx/ui/client/src/inventories/related-hosts/related-host.form.js @@ -64,7 +64,7 @@ function(i18n) { ngDisabled: '!(host.summary_fields.user_capabilities.edit || canAdd)', type: 'text' }, - variables: { + host_variables: { label: i18n._('Variables'), type: 'textarea', rows: 6, @@ -117,8 +117,6 @@ function(i18n) { awToolTip: i18n._('Please save before defining groups'), dataPlacement: 'top', ngClick: "$state.go('inventories.edit.hosts.edit.nested_groups')", - include: "NestedGroupListDefinition", - includeForm: "NestedGroupFormDefinition", title: i18n._('Groups'), iterator: 'nested_group' },