mirror of
https://github.com/ansible/awx.git
synced 2026-01-15 11:50:42 -03:30
Merge branch 'inventory-codemirrors' of https://github.com/mabashian/ansible-tower into mabashian-inventory-codemirrors
# Conflicts: # awx/ui/client/src/inventories/hosts/host.form.js
This commit is contained in:
commit
786fa89db6
@ -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,
|
||||
];
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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'
|
||||
},
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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 });
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
}
|
||||
];
|
||||
@ -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'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -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'
|
||||
},
|
||||
|
||||
@ -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'
|
||||
},
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
@ -38,11 +38,11 @@
|
||||
$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',
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -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'
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user