Fixes bug where the delete inventory event would wipe or reset inventory form fields

This commit is contained in:
mabashian 2019-06-11 13:56:05 -04:00
parent d4ad674899
commit 3ea6171b54

View File

@ -11,7 +11,7 @@
*/
function InventoriesList($scope,
$filter, Rest, InventoryList, Prompt,
$filter, qs, InventoryList, Prompt,
ProcessErrors, GetBasePath, Wait, $state,
Dataset, canAdd, i18n, Inventory, InventoryHostsStrings,
ngToast) {
@ -168,24 +168,31 @@ function InventoriesList($scope,
inventory.pending_deletion = true;
}
if (data.status === 'deleted') {
let reloadListStateParams = null;
let reloadListStateParams = _.cloneDeep($state.params);
if($scope.inventories.length === 1 && $state.params.inventory_search && _.has($state, 'params.inventory_search.page') && $state.params.inventory_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
if($scope.inventories.length === 1 && $state.params.inventory_search && _.hasIn($state, 'params.inventory_search.page') && $state.params.inventory_search.page !== '1') {
reloadListStateParams.inventory_search.page = (parseInt(reloadListStateParams.inventory_search.page)-1).toString();
}
if (parseInt($state.params.inventory_id) === data.inventory_id || parseInt($state.params.smartinventory_id) === data.inventory_id) {
$state.go("inventories", reloadListStateParams, {reload: true});
} else {
$state.go('.', reloadListStateParams, {reload: true});
Wait('start');
$state.go('.', reloadListStateParams);
const path = GetBasePath($scope.list.basePath) || GetBasePath($scope.list.name);
qs.search(path, reloadListStateParams.inventory_search)
.then((searchResponse) => {
$scope.inventories_dataset = searchResponse.data;
$scope.inventories = searchResponse.data.results;
})
.finally(() => Wait('stop'));
}
}
});
}
export default ['$scope',
'$filter', 'Rest', 'InventoryList', 'Prompt',
'$filter', 'QuerySet', 'InventoryList', 'Prompt',
'ProcessErrors', 'GetBasePath', 'Wait',
'$state', 'Dataset', 'canAdd', 'i18n', 'InventoryModel',
'InventoryHostsStrings', 'ngToast', InventoriesList