From 5be3105d60eb2b084ec254958a2652e9e6456cc7 Mon Sep 17 00:00:00 2001
From: mabashian
Date: Thu, 24 Aug 2017 17:12:58 -0400
Subject: [PATCH] Edit a host from within the smart inventory tree
---
.../src/inventories-hosts/inventories/main.js | 4 ++-
.../hosts/edit/smart-host-edit.route.js | 29 +++++++++++++++++++
...t.route.js => standard-host-edit.route.js} | 0
.../hosts/list/host-list.controller.js | 2 +-
.../related/hosts/related-host.form.js | 5 ++--
.../shared/inventories.service.js | 7 +++++
awx/ui/client/src/shared/form-generator.js | 8 +++--
7 files changed, 49 insertions(+), 6 deletions(-)
create mode 100644 awx/ui/client/src/inventories-hosts/inventories/related/hosts/edit/smart-host-edit.route.js
rename awx/ui/client/src/inventories-hosts/inventories/related/hosts/edit/{host-edit.route.js => standard-host-edit.route.js} (100%)
diff --git a/awx/ui/client/src/inventories-hosts/inventories/main.js b/awx/ui/client/src/inventories-hosts/inventories/main.js
index 4c2e576aba..c22d0ab5c5 100644
--- a/awx/ui/client/src/inventories-hosts/inventories/main.js
+++ b/awx/ui/client/src/inventories-hosts/inventories/main.js
@@ -33,7 +33,8 @@ import inventoryHosts from './related/hosts/related-host.route';
import smartInventoryHosts from './smart-inventory/smart-inventory-hosts.route';
import inventoriesList from './inventories.route';
import inventoryHostsAdd from './related/hosts/add/host-add.route';
-import inventoryHostsEdit from './related/hosts/edit/host-edit.route';
+import inventoryHostsEdit from './related/hosts/edit/standard-host-edit.route';
+import smartInventoryHostsEdit from './related/hosts/edit/smart-host-edit.route';
import ansibleFactsRoute from '../shared/ansible-facts/ansible-facts.route';
import insightsRoute from './insights/insights.route';
import inventorySourcesCredentialRoute from './related/sources/lookup/sources-lookup-credential.route';
@@ -322,6 +323,7 @@ angular.module('inventory', [
stateExtender.buildDefinition(smartInventoryHosts),
stateExtender.buildDefinition(inventoryHostsAdd),
stateExtender.buildDefinition(inventoryHostsEdit),
+ stateExtender.buildDefinition(smartInventoryHostsEdit),
stateExtender.buildDefinition(hostNestedGroupsRoute),
stateExtender.buildDefinition(inventorySourceListRoute),
stateExtender.buildDefinition(inventorySourceAddRoute),
diff --git a/awx/ui/client/src/inventories-hosts/inventories/related/hosts/edit/smart-host-edit.route.js b/awx/ui/client/src/inventories-hosts/inventories/related/hosts/edit/smart-host-edit.route.js
new file mode 100644
index 0000000000..033e6054ca
--- /dev/null
+++ b/awx/ui/client/src/inventories-hosts/inventories/related/hosts/edit/smart-host-edit.route.js
@@ -0,0 +1,29 @@
+export default {
+ name: "inventories.editSmartInventory.hosts.edit",
+ url: "/edit/:host_id",
+ ncyBreadcrumb: {
+ parent: "inventories.editSmartInventory.hosts",
+ label: "{{breadcrumb.host_name}}"
+ },
+ views: {
+ 'hostForm@inventories': {
+ templateProvider: function(GenerateForm, RelatedHostsFormDefinition) {
+ let form = _.cloneDeep(RelatedHostsFormDefinition);
+ form.stateTree = 'inventories.editSmartInventory.hosts';
+ delete form.related;
+ return GenerateForm.buildHTML(form, {
+ mode: 'edit',
+ related: false
+ });
+ },
+ controller: 'RelatedHostEditController'
+ }
+ },
+ resolve: {
+ host: ['$stateParams', 'InventoriesService', function($stateParams, InventoriesService) {
+ return InventoriesService.getHost($stateParams.smartinventory_id, $stateParams.host_id).then(function(res) {
+ return res.data.results[0];
+ });
+ }]
+ }
+};
diff --git a/awx/ui/client/src/inventories-hosts/inventories/related/hosts/edit/host-edit.route.js b/awx/ui/client/src/inventories-hosts/inventories/related/hosts/edit/standard-host-edit.route.js
similarity index 100%
rename from awx/ui/client/src/inventories-hosts/inventories/related/hosts/edit/host-edit.route.js
rename to awx/ui/client/src/inventories-hosts/inventories/related/hosts/edit/standard-host-edit.route.js
diff --git a/awx/ui/client/src/inventories-hosts/inventories/related/hosts/list/host-list.controller.js b/awx/ui/client/src/inventories-hosts/inventories/related/hosts/list/host-list.controller.js
index 81e0de24ed..c19110b627 100644
--- a/awx/ui/client/src/inventories-hosts/inventories/related/hosts/list/host-list.controller.js
+++ b/awx/ui/client/src/inventories-hosts/inventories/related/hosts/list/host-list.controller.js
@@ -89,7 +89,7 @@ export default ['$scope', 'ListDefinition', '$rootScope', 'GetBasePath',
$state.go('inventories.edit.hosts.add');
};
$scope.editHost = function(host){
- $state.go('inventories.edit.hosts.edit', {inventory_id: host.inventory_id, host_id: host.id});
+ $state.go('.edit', {inventory_id: host.inventory_id, host_id: host.id});
};
$scope.goToInsights = function(host){
$state.go('inventories.edit.hosts.edit.insights', {inventory_id: host.inventory_id, host_id:host.id});
diff --git a/awx/ui/client/src/inventories-hosts/inventories/related/hosts/related-host.form.js b/awx/ui/client/src/inventories-hosts/inventories/related/hosts/related-host.form.js
index 1f11a8fc28..047d7ce456 100644
--- a/awx/ui/client/src/inventories-hosts/inventories/related/hosts/related-host.form.js
+++ b/awx/ui/client/src/inventories-hosts/inventories/related/hosts/related-host.form.js
@@ -37,7 +37,7 @@ function(i18n) {
" set by the inventory sync process.") +
"
",
dataTitle: i18n._('Host Enabled'),
- ngDisabled: 'host.has_inventory_sources'
+ ngDisabled: '!host.summary_fields.user_capabilities.edit || host.has_inventory_sources'
}
},
fields: {
@@ -78,7 +78,8 @@ function(i18n) {
'' + i18n.sprintf(i18n._('View YAML examples at %s'), 'docs.ansible.com') + '
',
dataTitle: i18n._('Host Variables'),
dataPlacement: 'right',
- dataContainer: 'body'
+ dataContainer: 'body',
+ ngDisabled: '!(host.summary_fields.user_capabilities.edit || canAdd)'
}
},
diff --git a/awx/ui/client/src/inventories-hosts/shared/inventories.service.js b/awx/ui/client/src/inventories-hosts/shared/inventories.service.js
index ed02ce4cf1..9ca46ba998 100644
--- a/awx/ui/client/src/inventories-hosts/shared/inventories.service.js
+++ b/awx/ui/client/src/inventories-hosts/shared/inventories.service.js
@@ -69,6 +69,13 @@
return Rest.get()
.success(this.success.bind(this))
.error(this.error.bind(this));
+ },
+ getHost: function(inventoryId, hostId) {
+ this.url = GetBasePath('inventory') + inventoryId + '/hosts?id=' + hostId;
+ Rest.setUrl(this.url);
+ return Rest.get()
+ .success(this.success.bind(this))
+ .error(this.error.bind(this));
}
};
}];
diff --git a/awx/ui/client/src/shared/form-generator.js b/awx/ui/client/src/shared/form-generator.js
index c5f067a782..bb0c140b58 100644
--- a/awx/ui/client/src/shared/form-generator.js
+++ b/awx/ui/client/src/shared/form-generator.js
@@ -533,9 +533,13 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
html += (field.ngDisabled) ? ', "ScheduleToggle--disabled": ' + field.ngDisabled : '';
html += "\}' aw-tool-tip='" + field.awToolTip + "' data-placement='" + field.dataPlacement + "' data-tip-watch='" + field.dataTipWatch + "'>";
+ html += "' ";
+ html += (field.ngDisabled) ? `ng-disabled="${field.ngDisabled}" ` : "";
+ html += " class='ScheduleToggle-switch' ng-click='" + field.ngClick + "'>" + i18n._("OFF") + "";
}
return html;
},