Merge pull request #6165 from jaredevantabor/inventory-cleanup

removing old inv manage files
This commit is contained in:
Jared Tabor 2017-05-03 20:51:39 -04:00 committed by GitHub
commit 1f4c6edced
8 changed files with 0 additions and 1030 deletions

View File

@ -1,70 +0,0 @@
/*************************************************
* Copyright (c) 2016 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
export default
['$scope', '$state', '$stateParams', 'GroupManageService', 'CopyMoveGroupList', 'group', 'Dataset',
function($scope, $state, $stateParams, GroupManageService, CopyMoveGroupList, group, Dataset){
var list = CopyMoveGroupList;
$scope.item = group;
$scope.submitMode = $stateParams.groups === undefined ? 'move' : 'copy';
$scope.updateSelected = function(selectedGroup) {
$scope.selected = angular.copy(selectedGroup);
};
$scope.formCancel = function(){
$state.go('^');
};
$scope.formSave = function(){
switch($scope.submitMode) {
case 'copy':
GroupManageService.associateGroup(group, $scope.selected.id).then(() => $state.go('^', null, {reload: true}));
break;
case 'move':
switch($scope.targetRootGroup){
case true:
// disassociating group will bubble it to the root group level
GroupManageService.disassociateGroup(group.id, _.last($stateParams.group)).then(() => $state.go('^', null, {reload: true}));
break;
default:
// at the root group level, no dissassociation is needed
if (!$stateParams.group){
GroupManageService.associateGroup(group, $scope.selected.id).then(() => $state.go('^', null, {reload: true}));
}
else{
// unsure if orphaned resources get garbage collected, safe bet is to associate before disassociate
GroupManageService.associateGroup(group, $scope.selected.id).then(() => {
GroupManageService.disassociateGroup(group.id, _.last($stateParams.group))
.then(() => $state.go('^', null, {reload: true}));
});
}
break;
}
}
};
$scope.toggleTargetRootGroup = function(){
$scope.selected = !$scope.selected;
// cannot perform copy operations to root group level
$scope.submitMode = 'move';
// toggle off anything currently selected in the list, for clarity
_.forEach($scope.groups, (item) => {item.checked = null;});
// disable list selections
$('#copyMove-list :input').each((idx, el) => {
$(el).prop('disabled', (idx, value) => !value);
});
};
function init(){
$scope.atRootLevel = $stateParams.group ? false : true;
// search init
$scope.list = list;
$scope[`${list.iterator}_dataset`] = Dataset.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
}
init();
}];

View File

@ -1,48 +0,0 @@
/*************************************************
* Copyright (c) 2016 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
export default
['$scope', '$state', '$stateParams', 'HostManageService', 'CopyMoveGroupList', 'host', 'Dataset',
function($scope, $state, $stateParams, HostManageService, CopyMoveGroupList, host, Dataset){
var list = CopyMoveGroupList;
$scope.item = host;
$scope.submitMode = 'copy';
$scope.updateSelected = function(selectedGroup) {
$scope.selected = angular.copy(selectedGroup);
};
$scope.formCancel = function(){
$state.go('^');
};
$scope.formSave = function(){
switch($scope.submitMode) {
case 'copy':
HostManageService.associateGroup(host, $scope.selected.id).then(() => $state.go('^'));
break;
case 'move':
// at the root group level, no dissassociation is needed
if (!$stateParams.group){
HostManageService.associateGroup(host, $scope.selected.id).then(() => $state.go('^', null, {reload: true}));
}
else{
HostManageService.associateGroup(host, $scope.selected.id).then(() => {
HostManageService.disassociateGroup(host, _.last($stateParams.group))
.then(() => $state.go('^', null, {reload: true}));
});
}
break;
}
};
var init = function(){
// search init
$scope.list = list;
$scope[`${list.iterator}_dataset`] = Dataset.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
};
init();
}];

View File

@ -1,44 +0,0 @@
/*************************************************
* Copyright (c) 2016 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
export default
['$scope', 'CopyMoveGroupList', 'Dataset',
function($scope, list, Dataset){
init();
function init() {
$scope.list = list;
$scope[`${list.iterator}_dataset`] = Dataset.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
$scope.$watch('groups', function(){
if($scope.selectedGroup){
$scope.groups.forEach(function(row, i) {
if(row.id === $scope.selectedGroup.id) {
$scope.groups[i].checked = 1;
}
else {
$scope.groups[i].checked = 0;
}
});
}
});
}
$scope.toggle_row = function(id) {
// toggle off anything else currently selected
_.forEach($scope.groups, (item) => {
if(item.id === id) {
item.checked = 1;
$scope.selectedGroup = item;
$scope.updateSelected(item);
}
else {
item.checked = null;
}
});
};
}];

View File

@ -1,101 +0,0 @@
/*************************************************
* Copyright (c) 2016 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
import {templateUrl} from '../../../shared/template-url/template-url.factory';
import { N_ } from '../../../i18n';
import CopyMoveGroupsController from './copy-move-groups.controller';
import CopyMoveHostsController from './copy-move-hosts.controller';
import CopyMoveListController from './copy-move-list.controller';
var copyMoveGroupRoute = {
name: 'inventoryManage.copyMoveGroup',
url: '/copy-move-group/{group_id:int}',
searchPrefix: 'copy',
data: {
group_id: 'group_id',
},
params: {
copy_search: {
value: {
not__id__in: null
},
dynamic: true,
squash: ''
}
},
ncyBreadcrumb: {
label: N_("COPY OR MOVE") + " {{item.name}}"
},
resolve: {
Dataset: ['CopyMoveGroupList', 'QuerySet', '$stateParams', 'GetBasePath', 'group',
function(list, qs, $stateParams, GetBasePath, group) {
$stateParams.copy_search.not__id__in = ($stateParams.group && $stateParams.group.length > 0 ? group.id + ',' + _.last($stateParams.group) : group.id.toString());
let path = GetBasePath('inventory') + $stateParams.inventory_id + '/groups/';
return qs.search(path, $stateParams.copy_search);
}
],
group: ['GroupManageService', '$stateParams', function(GroupManageService, $stateParams){
return GroupManageService.get({id: $stateParams.group_id}).then(res => res.data.results[0]);
}]
},
views: {
'form@inventoryManage' : {
controller: CopyMoveGroupsController,
templateUrl: templateUrl('inventories/manage/copy-move/copy-move'),
},
'copyMoveList@inventoryManage.copyMoveGroup': {
templateProvider: function(CopyMoveGroupList, generateList) {
let html = generateList.build({
list: CopyMoveGroupList,
mode: 'lookup',
input_type: 'radio'
});
return html;
},
controller: CopyMoveListController
}
}
};
var copyMoveHostRoute = {
name: 'inventoryManage.copyMoveHost',
url: '/copy-move-host/{host_id}',
searchPrefix: 'copy',
ncyBreadcrumb: {
label: N_("COPY OR MOVE") + " {{item.name}}"
},
resolve: {
Dataset: ['CopyMoveGroupList', 'QuerySet', '$stateParams', 'GetBasePath',
function(list, qs, $stateParams, GetBasePath) {
let path = GetBasePath('inventory') + $stateParams.inventory_id + '/groups/';
return qs.search(path, $stateParams.copy_search);
}
],
host: ['HostManageService', '$stateParams', function(HostManageService, $stateParams){
return HostManageService.get({id: $stateParams.host_id}).then(res => res.data.results[0]);
}]
},
views: {
'form@inventoryManage': {
templateUrl: templateUrl('inventories/manage/copy-move/copy-move'),
controller: CopyMoveHostsController,
},
'copyMoveList@inventoryManage.copyMoveHost': {
templateProvider: function(CopyMoveGroupList, generateList, $stateParams, GetBasePath) {
let list = CopyMoveGroupList;
list.basePath = GetBasePath('inventory') + $stateParams.inventory_id + '/groups/';
let html = generateList.build({
list: CopyMoveGroupList,
mode: 'lookup',
input_type: 'radio'
});
return html;
},
controller: CopyMoveListController
}
}
};
export {copyMoveGroupRoute, copyMoveHostRoute};

View File

@ -1,221 +0,0 @@
/*************************************************
* Copyright (c) 2016 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
export default ['$state', '$stateParams', '$scope', 'GroupForm', 'ParseTypeChange', 'GenerateForm', 'inventoryData',
'GroupManageService', 'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions', 'rbacUiControlService', 'ToJSON',
function($state, $stateParams, $scope, GroupForm, ParseTypeChange, GenerateForm, inventoryData,
GroupManageService, GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions, rbacUiControlService, ToJSON) {
let form = GroupForm();
init();
function init() {
// apply form definition's default field values
GenerateForm.applyDefaults(form, $scope);
rbacUiControlService.canAdd(GetBasePath('inventory') + $stateParams.inventory_id + "/groups")
.then(function(params) {
$scope.canAdd = params.canAdd;
});
$scope.parseType = 'yaml';
$scope.envParseType = 'yaml';
ParseTypeChange({
scope: $scope,
field_id: 'group_variables',
variable: 'variables',
});
initSources();
}
$scope.lookupCredential = function(){
let kind = ($scope.source.value === "ec2") ? "aws" : $scope.source.value;
$state.go('.credential', {
credential_search: {
kind: kind,
page_size: '5',
page: '1'
}
});
};
$scope.formCancel = function() {
$state.go('^');
};
$scope.formSave = function() {
var params, source, json_data;
json_data = ToJSON($scope.parseType, $scope.variables, true);
// group fields
var group = {
variables: json_data,
name: $scope.name,
description: $scope.description,
inventory: inventoryData.id
};
if ($scope.source) {
// inventory_source fields
params = {
instance_filters: $scope.instance_filters,
source_vars: $scope[$scope.source.value + '_variables'] === '---' || $scope[$scope.source.value + '_variables'] === '{}' ? null : $scope[$scope.source.value + '_variables'],
source_script: $scope.inventory_script,
source: $scope.source.value,
credential: $scope.credential,
overwrite: $scope.overwrite,
overwrite_vars: $scope.overwrite_vars,
update_on_launch: $scope.update_on_launch,
update_cache_timeout: $scope.update_cache_timeout || 0,
// comma-delimited strings
group_by: _.map($scope.group_by, 'value').join(','),
source_regions: _.map($scope.source_regions, 'value').join(',')
};
source = $scope.source.value;
} else {
source = null;
}
switch (source) {
// no inventory source set, just create a new group
// '' is the value supplied for Manual source type
case null || '':
GroupManageService.post(group).then(res => {
// associate
if ($stateParams.group) {
return GroupManageService.associateGroup(res.data, _.last($stateParams.group))
.then(() => $state.go('^', null, { reload: true }));
} else {
$state.go('^', null, { reload: true });
}
});
break;
// create a new group and create/associate an inventory source
// equal to case 'rax' || 'ec2' || 'azure' || 'azure_rm' || 'vmware' || 'satellite6' || 'cloudforms' || 'openstack' || 'custom'
default:
GroupManageService.post(group)
// associate to group
.then(res => {
if ($stateParams.group) {
GroupManageService.associateGroup(res.data, _.last($stateParams.group));
return res;
} else {
return res; }
// pass the original POST response and not the association response
})
.then(res => GroupManageService.putInventorySource(
// put the received group ID into inventory source payload
// and pass the related endpoint
_.assign(params, { group: res.data.id }), res.data.related.inventory_source))
.then(res => $state.go('inventoryManage.editGroup', { group_id: res.data.group }, { reload: true }));
break;
}
};
$scope.sourceChange = function(source) {
source = source.value;
if (source === 'custom'){
$scope.credentialBasePath = GetBasePath('inventory_script');
}
// equal to case 'ec2' || 'rax' || 'azure' || 'azure_rm' || 'vmware' || 'satellite6' || 'cloudforms' || 'openstack'
else{
$scope.credentialBasePath = (source === 'ec2') ? GetBasePath('credentials') + '?kind=aws' : GetBasePath('credentials') + (source === '' ? '' : '?kind=' + (source));
}
if (source === 'ec2' || source === 'custom' || source === 'vmware' || source === 'openstack') {
ParseTypeChange({
scope: $scope,
field_id: source + '_variables',
variable: source + '_variables',
parse_variable: 'envParseType'
});
}
// reset fields
$scope.group_by_choices = source === 'ec2' ? $scope.ec2_group_by : null;
// azure_rm regions choices are keyed as "azure" in an OPTIONS request to the inventory_sources endpoint
$scope.source_region_choices = source === 'azure_rm' ? $scope.azure_regions : $scope[source + '_regions'];
$scope.cloudCredentialRequired = source !== '' && source !== 'custom' && source !== 'ec2' ? true : false;
$scope.group_by = null;
$scope.source_regions = null;
$scope.credential = null;
$scope.credential_name = null;
initRegionSelect();
};
// region / source options callback
$scope.$on('choicesReadyGroup', function() {
initRegionSelect();
});
$scope.$on('sourceTypeOptionsReady', function() {
initSourceSelect();
});
function initRegionSelect(){
CreateSelect2({
element: '#group_source_regions',
multiple: true
});
CreateSelect2({
element: '#group_group_by',
multiple: true
});
}
function initSourceSelect(){
CreateSelect2({
element: '#group_source',
multiple: false
});
}
function initSources(){
GetChoices({
scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'source_regions',
variable: 'rax_regions',
choice_name: 'rax_region_choices',
callback: 'choicesReadyGroup'
});
GetChoices({
scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'source_regions',
variable: 'ec2_regions',
choice_name: 'ec2_region_choices',
callback: 'choicesReadyGroup'
});
GetChoices({
scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'source_regions',
variable: 'gce_regions',
choice_name: 'gce_region_choices',
callback: 'choicesReadyGroup'
});
GetChoices({
scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'source_regions',
variable: 'azure_regions',
choice_name: 'azure_region_choices',
callback: 'choicesReadyGroup'
});
// Load options for group_by
GetChoices({
scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'group_by',
variable: 'ec2_group_by',
choice_name: 'ec2_group_by_choices',
callback: 'choicesReadyGroup'
});
GetSourceTypeOptions({
scope: $scope,
variable: 'source_type_options',
//callback: 'sourceTypeOptionsReady' this callback is hard-coded into GetSourceTypeOptions(), included for ref
});
}
}
];

View File

@ -1,247 +0,0 @@
/*************************************************
* Copyright (c) 2016 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
export default ['$state', '$stateParams', '$scope', 'ParseVariableString', 'rbacUiControlService', 'ToJSON',
'ParseTypeChange', 'GroupManageService', 'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions', 'groupData', 'inventorySourceData',
function($state, $stateParams, $scope, ParseVariableString, rbacUiControlService, ToJSON,
ParseTypeChange, GroupManageService, GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions, groupData, inventorySourceData) {
init();
function init() {
rbacUiControlService.canAdd(GetBasePath('inventory') + $stateParams.inventory_id + "/groups")
.then(function(params) {
$scope.canAdd = params.canAdd;
});
// instantiate expected $scope values from inventorySourceData & groupData
_.assign($scope, { credential: inventorySourceData.credential }, { overwrite: inventorySourceData.overwrite }, { overwrite_vars: inventorySourceData.overwrite_vars }, { update_on_launch: inventorySourceData.update_on_launch }, { update_cache_timeout: inventorySourceData.update_cache_timeout }, { instance_filters: inventorySourceData.instance_filters }, { inventory_script: inventorySourceData.source_script });
if (inventorySourceData.credential) {
$scope.credential_name = inventorySourceData.summary_fields.credential.name;
}
$scope = angular.extend($scope, groupData);
// display custom inventory_script name
if (inventorySourceData.source === 'custom') {
$scope.inventory_script_name = inventorySourceData.summary_fields.source_script.name;
}
$scope.$watch('summary_fields.user_capabilities.edit', function(val) {
$scope.canAdd = val;
});
// init codemirror(s)
$scope.variables = $scope.variables === null || $scope.variables === '' ? '---' : ParseVariableString($scope.variables);
$scope.parseType = 'yaml';
$scope.envParseType = 'yaml';
ParseTypeChange({
scope: $scope,
field_id: 'group_variables',
variable: 'variables',
});
initSources();
}
var initRegionSelect = function() {
CreateSelect2({
element: '#group_source_regions',
multiple: true
});
CreateSelect2({
element: '#group_group_by',
multiple: true
});
};
$scope.lookupCredential = function(){
let kind = ($scope.source.value === "ec2") ? "aws" : $scope.source.value;
$state.go('.credential', {
credential_search: {
kind: kind,
page_size: '5',
page: '1'
}
});
};
$scope.formCancel = function() {
$state.go('^');
};
$scope.formSave = function() {
var params, source, json_data;
json_data = ToJSON($scope.parseType, $scope.variables, true);
// group fields
var group = {
variables: json_data,
name: $scope.name,
description: $scope.description,
inventory: $scope.inventory,
id: groupData.id
};
if ($scope.source) {
// inventory_source fields
params = {
group: groupData.id,
source: $scope.source.value,
credential: $scope.credential,
overwrite: $scope.overwrite,
overwrite_vars: $scope.overwrite_vars,
source_script: $scope.inventory_script,
update_on_launch: $scope.update_on_launch,
update_cache_timeout: $scope.update_cache_timeout || 0,
// comma-delimited strings
group_by: _.map($scope.group_by, 'value').join(','),
source_regions: _.map($scope.source_regions, 'value').join(','),
instance_filters: $scope.instance_filters,
source_vars: $scope[$scope.source.value + '_variables'] === '---' || $scope[$scope.source.value + '_variables'] === '{}' ? null : $scope[$scope.source.value + '_variables']
};
source = $scope.source.value;
} else {
source = null;
}
switch (source) {
// no inventory source set, just create a new group
// '' is the value supplied for Manual source type
case null || '':
GroupManageService.put(group).then(() => $state.go($state.current, null, { reload: true }));
break;
// create a new group and create/associate an inventory source
// equal to case 'rax' || 'ec2' || 'azure' || 'azure_rm' || 'vmware' || 'satellite6' || 'cloudforms' || 'openstack' || 'custom'
default:
GroupManageService.put(group)
.then(() => GroupManageService.putInventorySource(params, groupData.related.inventory_source))
.then(() => $state.go($state.current, null, { reload: true }));
break;
}
};
$scope.sourceChange = function(source) {
$scope.source = source;
if (source.value === 'ec2' || source.value === 'custom' ||
source.value === 'vmware' || source.value === 'openstack') {
$scope[source.value + '_variables'] = $scope[source.value + '_variables'] === (null || undefined) ? '---' : $scope[source.value + '_variables'];
ParseTypeChange({
scope: $scope,
field_id: source.value + '_variables',
variable: source.value + '_variables',
parse_variable: 'envParseType',
});
}
// reset fields
// azure_rm regions choices are keyed as "azure" in an OPTIONS request to the inventory_sources endpoint
$scope.source_region_choices = source.value === 'azure_rm' ? $scope.azure_regions : $scope[source.value + '_regions'];
$scope.cloudCredentialRequired = source.value !== '' && source.value !== 'custom' && source.value !== 'ec2' ? true : false;
$scope.group_by = null;
$scope.source_regions = null;
$scope.credential = null;
$scope.credential_name = null;
initRegionSelect();
};
function initSourceSelect() {
$scope.source = _.find($scope.source_type_options, { value: inventorySourceData.source });
CreateSelect2({
element: '#group_source',
multiple: false
});
// After the source is set, conditional fields will be visible
// CodeMirror is buggy if you instantiate it in a not-visible element
// So we initialize it here instead of the init() routine
if (inventorySourceData.source === 'ec2' || inventorySourceData.source === 'openstack' ||
inventorySourceData.source === 'custom' || inventorySourceData.source === 'vmware') {
$scope[inventorySourceData.source + '_variables'] = inventorySourceData.source_vars === null || inventorySourceData.source_vars === '' ? '---' : ParseVariableString(inventorySourceData.source_vars);
ParseTypeChange({
scope: $scope,
field_id: inventorySourceData.source + '_variables',
variable: inventorySourceData.source + '_variables',
parse_variable: 'envParseType',
});
}
}
function initRegionData() {
var source = $scope.source.value === 'azure_rm' ? 'azure' : $scope.source.value;
var regions = inventorySourceData.source_regions.split(',');
// azure_rm regions choices are keyed as "azure" in an OPTIONS request to the inventory_sources endpoint
$scope.source_region_choices = $scope[source + '_regions'];
// the API stores azure regions as all-lowercase strings - but the azure regions received from OPTIONS are Snake_Cased
if (source === 'azure') {
$scope.source_regions = _.map(regions, (region) => _.find($scope[source + '_regions'], (o) => o.value.toLowerCase() === region));
}
// all other regions are 1-1
else {
$scope.source_regions = _.map(regions, (region) => _.find($scope[source + '_regions'], (o) => o.value === region));
}
$scope.group_by_choices = source === 'ec2' ? $scope.ec2_group_by : null;
if (source === 'ec2') {
var group_by = inventorySourceData.group_by.split(',');
$scope.group_by = _.map(group_by, (item) => _.find($scope.ec2_group_by, { value: item }));
}
initRegionSelect();
}
function initSources() {
GetSourceTypeOptions({
scope: $scope,
variable: 'source_type_options',
//callback: 'sourceTypeOptionsReady' this callback is hard-coded into GetSourceTypeOptions(), included for ref
});
GetChoices({
scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'source_regions',
variable: 'rax_regions',
choice_name: 'rax_region_choices',
callback: 'choicesReadyGroup'
});
GetChoices({
scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'source_regions',
variable: 'ec2_regions',
choice_name: 'ec2_region_choices',
callback: 'choicesReadyGroup'
});
GetChoices({
scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'source_regions',
variable: 'gce_regions',
choice_name: 'gce_region_choices',
callback: 'choicesReadyGroup'
});
GetChoices({
scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'source_regions',
variable: 'azure_regions',
choice_name: 'azure_region_choices',
callback: 'choicesReadyGroup'
});
GetChoices({
scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'group_by',
variable: 'ec2_group_by',
choice_name: 'ec2_group_by_choices',
callback: 'choicesReadyGroup'
});
}
// region / source options callback
$scope.$on('choicesReadyGroup', function() {
if (angular.isObject($scope.source)) {
initRegionData();
}
});
$scope.$on('sourceTypeOptionsReady', function() {
initSourceSelect();
});
}
];

View File

@ -1,236 +0,0 @@
/*************************************************
* Copyright (c) 2016 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
export default
['$scope', '$rootScope', '$state', '$stateParams', 'InventoryGroups', 'InventoryUpdate',
'GroupManageService', 'GroupsCancelUpdate', 'ViewUpdateStatus', 'rbacUiControlService', 'GetBasePath',
'GetSyncStatusMsg', 'GetHostsStatusMsg', 'groupsDataset', 'Find', 'QuerySet',
function($scope, $rootScope, $state, $stateParams, InventoryGroups, InventoryUpdate,
GroupManageService, GroupsCancelUpdate, ViewUpdateStatus, rbacUiControlService, GetBasePath,
GetSyncStatusMsg, GetHostsStatusMsg, groupsDataset, Find, qs){
let list = InventoryGroups;
init();
function init(){
$scope.inventory_id = $stateParams.inventory_id;
$scope.canAdd = false;
rbacUiControlService.canAdd(GetBasePath('inventory') + $scope.inventory_id + "/groups")
.then(function(params) {
$scope.canAdd = params.canAdd;
});
// Search init
$scope.list = list;
$scope[`${list.iterator}_dataset`] = groupsDataset.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
// The ncy breadcrumb directive will look at this attribute when attempting to bind to the correct scope.
// In this case, we don't want to incidentally bind to this scope when editing a host or a group. See:
// https://github.com/ncuillery/angular-breadcrumb/issues/42 for a little more information on the
// problem that this solves.
$scope.ncyBreadcrumbIgnore = true;
if($state.current.name === "inventoryManage.editGroup") {
$scope.rowBeingEdited = $state.params.group_id;
$scope.listBeingEdited = "groups";
}
$scope.inventory_id = $stateParams.inventory_id;
_.forEach($scope[list.name], buildStatusIndicators);
}
function buildStatusIndicators(group){
if (group === undefined || group === null) {
group = {};
}
let group_status, hosts_status;
group_status = GetSyncStatusMsg({
status: group.summary_fields.inventory_source.status,
has_inventory_sources: group.has_inventory_sources,
source: ( (group.summary_fields.inventory_source) ? group.summary_fields.inventory_source.source : null )
});
hosts_status = GetHostsStatusMsg({
active_failures: group.hosts_with_active_failures,
total_hosts: group.total_hosts,
inventory_id: $scope.inventory_id,
group_id: group.id
});
_.assign(group,
{status_class: group_status.class},
{status_tooltip: group_status.tooltip},
{launch_tooltip: group_status.launch_tip},
{launch_class: group_status.launch_class},
{group_schedule_tooltip: group_status.schedule_tip},
{hosts_status_tip: hosts_status.tooltip},
{hosts_status_class: hosts_status.class},
{source: group.summary_fields.inventory_source ? group.summary_fields.inventory_source.source : null},
{status: group.summary_fields.inventory_source ? group.summary_fields.inventory_source.status : null});
}
$scope.groupSelect = function(id){
var group = $stateParams.group === undefined ? [id] : _($stateParams.group).concat(id).value();
$state.go('inventoryManage', {
inventory_id: $stateParams.inventory_id,
group: group,
group_search: {
page_size: '20',
page: '1',
order_by: 'name',
}
}, {reload: true});
};
$scope.createGroup = function(){
$state.go('inventoryManage.addGroup');
};
$scope.editGroup = function(id){
$state.go('inventoryManage.editGroup', {group_id: id});
};
$scope.deleteGroup = function(group){
$scope.toDelete = {};
angular.extend($scope.toDelete, group);
if($scope.toDelete.total_groups === 0 && $scope.toDelete.total_hosts === 0) {
// This group doesn't have any child groups or hosts - the user is just trying to delete
// the group
$scope.deleteOption = "delete";
}
$('#group-delete-modal').modal('show');
};
$scope.confirmDelete = function(){
// Bind an even listener for the modal closing. Trying to $state.go() before the modal closes
// will mean that these two things are running async and the modal may not finish closing before
// the state finishes transitioning.
$('#group-delete-modal').off('hidden.bs.modal').on('hidden.bs.modal', function () {
// Remove the event handler so that we don't end up with multiple bindings
$('#group-delete-modal').off('hidden.bs.modal');
// Reload the inventory manage page and show that the group has been removed
$state.go('inventoryManage', null, {reload: true});
});
switch($scope.deleteOption){
case 'promote':
GroupManageService.promote($scope.toDelete.id, $stateParams.inventory_id)
.then(() => {
if (parseInt($state.params.group_id) === $scope.toDelete.id) {
$state.go("inventoryManage", null, {reload: true});
} else {
$state.go($state.current, null, {reload: true});
}
$('#group-delete-modal').modal('hide');
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
});
break;
default:
GroupManageService.delete($scope.toDelete.id).then(() => {
if (parseInt($state.params.group_id) === $scope.toDelete.id) {
$state.go("inventoryManage", null, {reload: true});
} else {
$state.go($state.current, null, {reload: true});
}
$('#group-delete-modal').modal('hide');
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
});
}
};
$scope.updateGroup = function(group) {
GroupManageService.getInventorySource({group: group.id}).then(res =>InventoryUpdate({
scope: $scope,
group_id: group.id,
url: res.data.results[0].related.update,
group_name: group.name,
group_source: res.data.results[0].source
}));
};
$scope.$on(`ws-jobs`, function(e, data){
var group = Find({ list: $scope.groups, key: 'id', val: data.group_id });
if (group === undefined || group === null) {
group = {};
}
if(data.status === 'failed' || data.status === 'successful'){
let path;
if($stateParams && $stateParams.group && $stateParams.group.length > 0) {
path = GetBasePath('groups') + _.last($stateParams.group) + '/children';
}
else {
//reaches here if the user is on the root level group
path = GetBasePath('inventory') + $stateParams.inventory_id + '/root_groups';
}
qs.search(path, $state.params[`${list.iterator}_search`])
.then(function(searchResponse) {
$scope[`${list.iterator}_dataset`] = searchResponse.data;
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
_.forEach($scope[list.name], buildStatusIndicators);
});
} else {
var status = GetSyncStatusMsg({
status: data.status,
has_inventory_sources: group.has_inventory_sources,
source: group.source
});
group.status = data.status;
group.status_class = status.class;
group.status_tooltip = status.tooltip;
group.launch_tooltip = status.launch_tip;
group.launch_class = status.launch_class;
}
});
$scope.cancelUpdate = function (id) {
GroupsCancelUpdate({ scope: $scope, id: id });
};
$scope.viewUpdateStatus = function (id) {
ViewUpdateStatus({
scope: $scope,
group_id: id
});
};
$scope.showFailedHosts = function() {
$state.go('inventoryManage', {failed: true}, {reload: true});
};
$scope.scheduleGroup = function(id) {
// Add this group's id to the array of group id's so that it gets
// added to the breadcrumb trail
var groupsArr = $stateParams.group ? $stateParams.group : [];
groupsArr.push(id);
$state.go('inventoryManage.editGroup.schedules', {group_id: id, group: groupsArr}, {reload: true});
};
// $scope.$parent governed by InventoryManageController, for unified multiSelect options
$scope.$on('multiSelectList.selectionChanged', (event, selection) => {
$scope.$parent.groupsSelected = selection.length > 0 ? true : false;
$scope.$parent.groupsSelectedItems = selection.selectedItems;
});
$scope.copyMoveGroup = function(id){
$state.go('inventoryManage.copyMoveGroup', {group_id: id, groups: $stateParams.groups});
};
var cleanUpStateChangeListener = $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams) {
if (toState.name === "inventoryManage.editGroup") {
$scope.rowBeingEdited = toParams.group_id;
$scope.listBeingEdited = "groups";
}
else {
delete $scope.rowBeingEdited;
delete $scope.listBeingEdited;
}
});
// Remove the listener when the scope is destroyed to avoid a memory leak
$scope.$on('$destroy', function() {
cleanUpStateChangeListener();
});
}];

View File

@ -1,63 +0,0 @@
/*************************************************
* Copyright (c) 2016 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
export default ['$state', '$stateParams', '$scope', 'HostForm', 'ParseTypeChange',
'GenerateForm', 'HostManageService', 'rbacUiControlService', 'GetBasePath', 'ToJSON',
function($state, $stateParams, $scope, HostForm, ParseTypeChange,
GenerateForm, HostManageService, rbacUiControlService, GetBasePath, ToJSON) {
init();
function init() {
$scope.canAdd = false;
rbacUiControlService.canAdd(GetBasePath('inventory') + $stateParams.inventory_id + "/hosts")
.then(function(params) {
$scope.canAdd = params.canAdd;
});
$scope.parseType = 'yaml';
$scope.host = { enabled: true };
// apply form definition's default field values
GenerateForm.applyDefaults(HostForm, $scope);
ParseTypeChange({
scope: $scope,
field_id: 'host_variables',
variable: 'variables',
parse_variable: 'parseType'
});
}
$scope.formCancel = function() {
$state.go('^');
};
$scope.toggleHostEnabled = function() {
if ($scope.host.has_inventory_sources){
return;
}
$scope.host.enabled = !$scope.host.enabled;
};
$scope.formSave = function(){
var json_data = ToJSON($scope.parseType, $scope.variables, true),
params = {
variables: json_data,// $scope.variables === '---' || $scope.variables === '{}' ? null : $scope.variables,
name: $scope.name,
description: $scope.description,
enabled: $scope.host.enabled,
inventory: $stateParams.inventory_id
};
HostManageService.post(params).then(function(res) {
// assign the host to current group if not at the root level
if ($stateParams.group) {
HostManageService.associateGroup(res.data, _.last($stateParams.group)).then(function() {
$state.go('inventoryManage.editHost', { host_id: res.data.id }, { reload: true });
});
} else {
$state.go('inventoryManage.editHost', { host_id: res.data.id }, { reload: true });
}
});
};
}
];