Inventory Manage > copy/move groups disable copy option where impossible, add to Root Group target, resolves #1749 (#2218)

This commit is contained in:
Leigh 2016-06-10 18:36:53 -04:00 committed by GitHub
parent 587b243ebb
commit dc3d1e7e7a
5 changed files with 56 additions and 32 deletions

View File

@ -26,24 +26,43 @@
GroupManageService.associateGroup(group, $scope.selected.id).then(() => $state.go('^', null, {reload: true}));
break;
case 'move':
// 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, _.last($stateParams.group))
.then(() => $state.go('^', null, {reload: true}));
});
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;
}
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);
});
};
var init = function(){
var url = GetBasePath('inventory') + $stateParams.inventory_id + '/groups/';
url += $stateParams.group ? '?not__id__in=' + group.id + ',' + _.last($stateParams.group) : '?not__id=' + group.id;
list.basePath = url;
$scope.atRootLevel = $stateParams.group ? false : true;
view.inject(list, {
mode: 'lookup',
id: 'copyMove-list',
@ -65,4 +84,4 @@
// remove the current group from list
};
init();
}];
}];

View File

@ -34,7 +34,7 @@
HostManageService.associateGroup(host, $scope.selected.id).then(() => {
HostManageService.disassociateGroup(host, _.last($stateParams.group))
.then(() => $state.go('^', null, {reload: true}));
});
});
}
break;
}
@ -62,4 +62,4 @@
$scope.search(list.iterator, null, true, false);
};
init();
}];
}];

View File

@ -23,4 +23,7 @@
.copyMove-buttons{
height: 30px;
margin-top: 10px;
}
}
.copyMove-root{
margin-top: 10px;
}

View File

@ -2,16 +2,18 @@
<div class="Form-header">
<div class="Form-title ng-binding">{{item.name}}</div>
</div>
<div class="form-group copyMove-choices">
<label class="radio-inline">
<input type="radio" ng-model="submitMode" value="copy" class="ng-pristine ng-valid ng-touched"> Copy
<div class="form-group copyMove-choices clearfix">
<label class="radio-inline" ng-disabled="atRootLevel || targetRootGroup">
<input type="radio" ng-model="submitMode" value="copy" class="ng-pristine ng-valid ng-touched" ng-disabled="atRootLevel || targetRootGroup"> Copy
</label>
<label class="radio-inline">
<input type="radio" ng-model="submitMode" value="move" class="ng-pristine ng-untouched ng-valid"> Move
</label>
</div>
<div id="copyMove-select"></div>
<div id="copyMove-list"></div>
<div class="copyMove-root form-group pull-left" ng-hide="atRootLevel">
<span><input type="checkbox" ng-model="targetRootGroup" ng-change="toggleTargetRootGroup()"> Use the inventory root</span>
</div>
<div class="copyMove-buttons">
<button type="button" class="pull-right btn btn-sm btn-default Form-cancelButton" ng-click="formCancel()">Cancel</button>
<button type="button" class="pull-right btn btn-sm Form-saveButton" ng-disabled="!selected" ng-click="formSave()">Save</button>

View File

@ -34,7 +34,7 @@ export default
return Rest.post(group)
.success(this.success.bind(this))
.error(this.error.bind(this))
.finally(Wait('stop'));
.finally(Wait('stop'));
},
put: function(group){
Wait('start');
@ -43,7 +43,7 @@ export default
return Rest.put(group)
.success(this.success.bind(this))
.error(this.error.bind(this))
.finally(Wait('stop'));
.finally(Wait('stop'));
},
delete: function(id){
Wait('start');
@ -52,7 +52,7 @@ export default
return Rest.destroy()
.success(this.success.bind(this))
.error(this.error.bind(this))
.finally(Wait('stop'));
.finally(Wait('stop'));
},
getCredential: function(id){
Wait('start');
@ -60,8 +60,8 @@ export default
Rest.setUrl(this.url);
return Rest.get()
.success(this.success.bind(this))
.error(this.error.bind(this))
.finally(Wait('stop'));
.error(this.error.bind(this))
.finally(Wait('stop'));
},
getInventorySource: function(params){
Wait('start');
@ -70,7 +70,7 @@ export default
return Rest.get()
.success(this.success.bind(this))
.error(this.error.bind(this))
.finally(Wait('stop'));
.finally(Wait('stop'));
},
putInventorySource: function(params, url){
Wait('start');
@ -79,9 +79,9 @@ export default
return Rest.put(params)
.success(this.success.bind(this))
.error(this.error.bind(this))
.finally(Wait('stop'));
.finally(Wait('stop'));
},
// these relationship setters could be consolidated, but verbosity makes the operation feel more clear @ controller level
// these relationship setters could be consolidated, but verbosity makes the operation feel more clear @ controller level
associateGroup: function(group, target){
Wait('start');
this.url = GetBasePath('groups') + target + '/children/';
@ -89,7 +89,7 @@ export default
return Rest.post(group)
.success(this.success.bind(this))
.error(this.error.bind(this))
.finally(Wait('stop'));
.finally(Wait('stop'));
},
disassociateGroup: function(group, parent){
Wait('start');
@ -98,7 +98,7 @@ export default
return Rest.post({id: group, disassociate: 1})
.success(this.success.bind(this))
.error(this.error.bind(this))
.finally(Wait('stop'));
.finally(Wait('stop'));
},
promote: function(group, inventory){
Wait('start');
@ -107,7 +107,7 @@ export default
return Rest.post({id: group, disassociate: 1})
.success(this.success.bind(this))
.error(this.error.bind(this))
.finally(Wait('stop'));
}
.finally(Wait('stop'));
}
};
}];
}];