mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 14:27:42 -02:30
Fix for smart search back/forward browser page navigation
This commit is contained in:
@@ -44,7 +44,7 @@ export default ['$scope', '$state', 'QuerySet', 'GetBasePath',
|
|||||||
|
|
||||||
queryset = _.merge($state.params[`${$scope.columnIterator}_search`], { order_by: order_by });
|
queryset = _.merge($state.params[`${$scope.columnIterator}_search`], { order_by: order_by });
|
||||||
path = GetBasePath($scope.basePath) || $scope.basePath;
|
path = GetBasePath($scope.basePath) || $scope.basePath;
|
||||||
$state.go('.', { [$scope.columnIterator + '_search']: queryset });
|
$state.go('.', { [$scope.columnIterator + '_search']: queryset }, {notify: false});
|
||||||
qs.search(path, queryset).then((res) =>{
|
qs.search(path, queryset).then((res) =>{
|
||||||
$scope.dataset = res.data;
|
$scope.dataset = res.data;
|
||||||
$scope.collection = res.data.results;
|
$scope.collection = res.data.results;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export default ['$scope', '$stateParams', '$state', '$filter', 'GetBasePath', 'Q
|
|||||||
queryset = _.merge($stateParams[`${$scope.iterator}_search`], { page: page });
|
queryset = _.merge($stateParams[`${$scope.iterator}_search`], { page: page });
|
||||||
$state.go('.', {
|
$state.go('.', {
|
||||||
[$scope.iterator + '_search']: queryset
|
[$scope.iterator + '_search']: queryset
|
||||||
});
|
}, {notify: false});
|
||||||
qs.search(path, queryset).then((res) => {
|
qs.search(path, queryset).then((res) => {
|
||||||
$scope.dataset = res.data;
|
$scope.dataset = res.data;
|
||||||
$scope.collection = res.data.results;
|
$scope.collection = res.data.results;
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', '
|
|||||||
defaults = _.find($state.$current.path, (step) => {
|
defaults = _.find($state.$current.path, (step) => {
|
||||||
return step.params.hasOwnProperty(`${$scope.iterator}_search`);
|
return step.params.hasOwnProperty(`${$scope.iterator}_search`);
|
||||||
}).params[`${$scope.iterator}_search`].config.value,
|
}).params[`${$scope.iterator}_search`].config.value,
|
||||||
queryset = $stateParams[`${$scope.iterator}_search`];
|
queryset = $stateParams[`${$scope.iterator}_search`],
|
||||||
|
stateChangeSuccessListener;
|
||||||
|
|
||||||
// build $scope.tags from $stateParams.QuerySet, build fieldset key
|
// build $scope.tags from $stateParams.QuerySet, build fieldset key
|
||||||
init();
|
init();
|
||||||
@@ -20,6 +21,44 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', '
|
|||||||
$scope.options = data.options.data;
|
$scope.options = data.options.data;
|
||||||
$scope.$emit(`${$scope.list.iterator}_options`, data.options);
|
$scope.$emit(`${$scope.list.iterator}_options`, data.options);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function compareParams(a, b) {
|
||||||
|
for (let key in a) {
|
||||||
|
if (!(key in b) || a[key].toString() !== b[key].toString()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let key in b) {
|
||||||
|
if (!(key in a)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(stateChangeSuccessListener) {
|
||||||
|
stateChangeSuccessListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
stateChangeSuccessListener = $scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
|
||||||
|
// State has changed - check to see if this is a param change
|
||||||
|
if(fromState.name === toState.name) {
|
||||||
|
if(!compareParams(fromParams[`${$scope.iterator}_search`], toParams[`${$scope.iterator}_search`])) {
|
||||||
|
// Params are not the same - we need to update the search. This should only happen when the user
|
||||||
|
// hits the forward/back navigation buttons in their browser.
|
||||||
|
queryset = toParams[`${$scope.iterator}_search`];
|
||||||
|
qs.search(path, queryset).then((res) => {
|
||||||
|
$scope.dataset = res.data;
|
||||||
|
$scope.collection = res.data.results;
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.searchTerm = null;
|
||||||
|
$scope.searchTags = stripDefaultParams(queryset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.$on('$destroy', stateChangeSuccessListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removes state definition defaults and pagination terms
|
// Removes state definition defaults and pagination terms
|
||||||
@@ -70,7 +109,7 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', '
|
|||||||
let cleared = _.cloneDeep(defaults);
|
let cleared = _.cloneDeep(defaults);
|
||||||
delete cleared.page;
|
delete cleared.page;
|
||||||
queryset = cleared;
|
queryset = cleared;
|
||||||
$state.go('.', {[$scope.iterator + '_search']: queryset});
|
$state.go('.', {[$scope.iterator + '_search']: queryset}, {notify: false});
|
||||||
qs.search(path, queryset).then((res) => {
|
qs.search(path, queryset).then((res) => {
|
||||||
$scope.dataset = res.data;
|
$scope.dataset = res.data;
|
||||||
$scope.collection = res.data.results;
|
$scope.collection = res.data.results;
|
||||||
@@ -117,7 +156,7 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', '
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
$state.go('.', {
|
$state.go('.', {
|
||||||
[$scope.iterator + '_search']: queryset });
|
[$scope.iterator + '_search']: queryset }, {notify: false});
|
||||||
qs.search(path, queryset).then((res) => {
|
qs.search(path, queryset).then((res) => {
|
||||||
$scope.dataset = res.data;
|
$scope.dataset = res.data;
|
||||||
$scope.collection = res.data.results;
|
$scope.collection = res.data.results;
|
||||||
@@ -188,7 +227,7 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', '
|
|||||||
// This transition will not reload controllers/resolves/views
|
// This transition will not reload controllers/resolves/views
|
||||||
// but will register new $stateParams[$scope.iterator + '_search'] terms
|
// but will register new $stateParams[$scope.iterator + '_search'] terms
|
||||||
$state.go('.', {
|
$state.go('.', {
|
||||||
[$scope.iterator + '_search']: queryset });
|
[$scope.iterator + '_search']: queryset }, {notify: false});
|
||||||
qs.search(path, queryset).then((res) => {
|
qs.search(path, queryset).then((res) => {
|
||||||
$scope.dataset = res.data;
|
$scope.dataset = res.data;
|
||||||
$scope.collection = res.data.results;
|
$scope.collection = res.data.results;
|
||||||
@@ -208,7 +247,7 @@ export default ['$stateParams', '$scope', '$state', 'QuerySet', 'GetBasePath', '
|
|||||||
// This transition will not reload controllers/resolves/views
|
// This transition will not reload controllers/resolves/views
|
||||||
// but will register new $stateParams[$scope.iterator + '_search'] terms
|
// but will register new $stateParams[$scope.iterator + '_search'] terms
|
||||||
$state.go('.', {
|
$state.go('.', {
|
||||||
[$scope.iterator + '_search']: queryset });
|
[$scope.iterator + '_search']: queryset }, {notify: false});
|
||||||
qs.search(path, queryset).then((res) => {
|
qs.search(path, queryset).then((res) => {
|
||||||
$scope.dataset = res.data;
|
$scope.dataset = res.data;
|
||||||
$scope.collection = res.data.results;
|
$scope.collection = res.data.results;
|
||||||
|
|||||||
Reference in New Issue
Block a user