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})); GroupManageService.associateGroup(group, $scope.selected.id).then(() => $state.go('^', null, {reload: true}));
break; break;
case 'move': case 'move':
// at the root group level, no dissassociation is needed switch($scope.targetRootGroup){
if (!$stateParams.group){ case true:
GroupManageService.associateGroup(group, $scope.selected.id).then(() => $state.go('^', null, {reload: true})); // disassociating group will bubble it to the root group level
} GroupManageService.disassociateGroup(group.id, _.last($stateParams.group)).then(() => $state.go('^', null, {reload: true}));
else{ break;
// unsure if orphaned resources get garbage collected, safe bet is to associate before disassociate default:
GroupManageService.associateGroup(group, $scope.selected.id).then(() => { // at the root group level, no dissassociation is needed
GroupManageService.disassociateGroup(group, _.last($stateParams.group)) if (!$stateParams.group){
.then(() => $state.go('^', null, {reload: true})); 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 init = function(){
var url = GetBasePath('inventory') + $stateParams.inventory_id + '/groups/'; var url = GetBasePath('inventory') + $stateParams.inventory_id + '/groups/';
url += $stateParams.group ? '?not__id__in=' + group.id + ',' + _.last($stateParams.group) : '?not__id=' + group.id; url += $stateParams.group ? '?not__id__in=' + group.id + ',' + _.last($stateParams.group) : '?not__id=' + group.id;
list.basePath = url; list.basePath = url;
$scope.atRootLevel = $stateParams.group ? false : true;
view.inject(list, { view.inject(list, {
mode: 'lookup', mode: 'lookup',
id: 'copyMove-list', id: 'copyMove-list',
@@ -65,4 +84,4 @@
// remove the current group from list // remove the current group from list
}; };
init(); init();
}]; }];

View File

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

View File

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

View File

@@ -2,16 +2,18 @@
<div class="Form-header"> <div class="Form-header">
<div class="Form-title ng-binding">{{item.name}}</div> <div class="Form-title ng-binding">{{item.name}}</div>
</div> </div>
<div class="form-group copyMove-choices"> <div class="form-group copyMove-choices clearfix">
<label class="radio-inline"> <label class="radio-inline" ng-disabled="atRootLevel || targetRootGroup">
<input type="radio" ng-model="submitMode" value="copy" class="ng-pristine ng-valid ng-touched"> Copy <input type="radio" ng-model="submitMode" value="copy" class="ng-pristine ng-valid ng-touched" ng-disabled="atRootLevel || targetRootGroup"> Copy
</label> </label>
<label class="radio-inline"> <label class="radio-inline">
<input type="radio" ng-model="submitMode" value="move" class="ng-pristine ng-untouched ng-valid"> Move <input type="radio" ng-model="submitMode" value="move" class="ng-pristine ng-untouched ng-valid"> Move
</label> </label>
</div> </div>
<div id="copyMove-select"></div>
<div id="copyMove-list"></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"> <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 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> <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) return Rest.post(group)
.success(this.success.bind(this)) .success(this.success.bind(this))
.error(this.error.bind(this)) .error(this.error.bind(this))
.finally(Wait('stop')); .finally(Wait('stop'));
}, },
put: function(group){ put: function(group){
Wait('start'); Wait('start');
@@ -43,7 +43,7 @@ export default
return Rest.put(group) return Rest.put(group)
.success(this.success.bind(this)) .success(this.success.bind(this))
.error(this.error.bind(this)) .error(this.error.bind(this))
.finally(Wait('stop')); .finally(Wait('stop'));
}, },
delete: function(id){ delete: function(id){
Wait('start'); Wait('start');
@@ -52,7 +52,7 @@ export default
return Rest.destroy() return Rest.destroy()
.success(this.success.bind(this)) .success(this.success.bind(this))
.error(this.error.bind(this)) .error(this.error.bind(this))
.finally(Wait('stop')); .finally(Wait('stop'));
}, },
getCredential: function(id){ getCredential: function(id){
Wait('start'); Wait('start');
@@ -60,8 +60,8 @@ export default
Rest.setUrl(this.url); Rest.setUrl(this.url);
return Rest.get() return Rest.get()
.success(this.success.bind(this)) .success(this.success.bind(this))
.error(this.error.bind(this)) .error(this.error.bind(this))
.finally(Wait('stop')); .finally(Wait('stop'));
}, },
getInventorySource: function(params){ getInventorySource: function(params){
Wait('start'); Wait('start');
@@ -70,7 +70,7 @@ export default
return Rest.get() return Rest.get()
.success(this.success.bind(this)) .success(this.success.bind(this))
.error(this.error.bind(this)) .error(this.error.bind(this))
.finally(Wait('stop')); .finally(Wait('stop'));
}, },
putInventorySource: function(params, url){ putInventorySource: function(params, url){
Wait('start'); Wait('start');
@@ -79,9 +79,9 @@ export default
return Rest.put(params) return Rest.put(params)
.success(this.success.bind(this)) .success(this.success.bind(this))
.error(this.error.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){ associateGroup: function(group, target){
Wait('start'); Wait('start');
this.url = GetBasePath('groups') + target + '/children/'; this.url = GetBasePath('groups') + target + '/children/';
@@ -89,7 +89,7 @@ export default
return Rest.post(group) return Rest.post(group)
.success(this.success.bind(this)) .success(this.success.bind(this))
.error(this.error.bind(this)) .error(this.error.bind(this))
.finally(Wait('stop')); .finally(Wait('stop'));
}, },
disassociateGroup: function(group, parent){ disassociateGroup: function(group, parent){
Wait('start'); Wait('start');
@@ -98,7 +98,7 @@ export default
return Rest.post({id: group, disassociate: 1}) return Rest.post({id: group, disassociate: 1})
.success(this.success.bind(this)) .success(this.success.bind(this))
.error(this.error.bind(this)) .error(this.error.bind(this))
.finally(Wait('stop')); .finally(Wait('stop'));
}, },
promote: function(group, inventory){ promote: function(group, inventory){
Wait('start'); Wait('start');
@@ -107,7 +107,7 @@ export default
return Rest.post({id: group, disassociate: 1}) return Rest.post({id: group, disassociate: 1})
.success(this.success.bind(this)) .success(this.success.bind(this))
.error(this.error.bind(this)) .error(this.error.bind(this))
.finally(Wait('stop')); .finally(Wait('stop'));
} }
}; };
}]; }];