mirror of
https://github.com/ansible/awx.git
synced 2026-02-19 12:10:06 -03:30
Merge pull request #605 from jlmitch5/paginationEditIndicator
getting pagination to work on edit of a form item
This commit is contained in:
@@ -147,6 +147,7 @@ export default
|
|||||||
new_url += (scope[iterator + 'SearchParams']) ? '&' + scope[iterator + 'SearchParams'] +
|
new_url += (scope[iterator + 'SearchParams']) ? '&' + scope[iterator + 'SearchParams'] +
|
||||||
'&page_size=' + scope[iterator + '_page_size'] : '&page_size=' + scope[iterator + 'PageSize'];
|
'&page_size=' + scope[iterator + '_page_size'] : '&page_size=' + scope[iterator + 'PageSize'];
|
||||||
Wait('start');
|
Wait('start');
|
||||||
|
scope.getNewPage = true;
|
||||||
Refresh({ scope: scope, set: set, iterator: iterator, url: new_url });
|
Refresh({ scope: scope, set: set, iterator: iterator, url: new_url });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -24,47 +24,67 @@
|
|||||||
|
|
||||||
export default
|
export default
|
||||||
angular.module('RefreshHelper', ['RestServices', 'Utilities', 'PaginationHelpers'])
|
angular.module('RefreshHelper', ['RestServices', 'Utilities', 'PaginationHelpers'])
|
||||||
.factory('Refresh', ['ProcessErrors', 'Rest', 'Wait', 'Empty', 'PageRangeSetup',
|
.factory('Refresh', ['$location', 'ProcessErrors', 'Rest', 'Wait', 'Empty', 'PageRangeSetup', 'pagination', function ($location, ProcessErrors, Rest, Wait, Empty, PageRangeSetup, pagination) {
|
||||||
function (ProcessErrors, Rest, Wait, Empty, PageRangeSetup) {
|
return function (params) {
|
||||||
return function (params) {
|
|
||||||
|
|
||||||
var scope = params.scope,
|
var scope = params.scope,
|
||||||
set = params.set,
|
set = params.set,
|
||||||
iterator = params.iterator,
|
iterator = params.iterator,
|
||||||
url = params.url,
|
deferWaitStop = params.deferWaitStop;
|
||||||
deferWaitStop = params.deferWaitStop;
|
|
||||||
|
|
||||||
scope.current_url = url;
|
var getPage = function(url) {
|
||||||
Rest.setUrl(url);
|
scope.current_url = url;
|
||||||
Rest.get()
|
|
||||||
.success(function (data) {
|
Rest.setUrl(url);
|
||||||
var i, modifier;
|
Rest.get()
|
||||||
PageRangeSetup({
|
.success(function (data) {
|
||||||
scope: scope,
|
var i, modifier;
|
||||||
count: data.count,
|
PageRangeSetup({
|
||||||
next: data.next,
|
scope: scope,
|
||||||
previous: data.previous,
|
count: data.count,
|
||||||
iterator: iterator
|
next: data.next,
|
||||||
});
|
previous: data.previous,
|
||||||
for (i = 1; i <= 3; i++) {
|
iterator: iterator
|
||||||
modifier = (i === 1) ? '' : i;
|
|
||||||
scope[iterator + 'HoldInput' + modifier] = false;
|
|
||||||
}
|
|
||||||
scope[set] = data.results;
|
|
||||||
scope[iterator + 'Loading'] = false;
|
|
||||||
scope[iterator + 'HidePaginator'] = false;
|
|
||||||
if (!deferWaitStop) {
|
|
||||||
Wait('stop');
|
|
||||||
}
|
|
||||||
scope.$emit('PostRefresh', set);
|
|
||||||
})
|
|
||||||
.error(function (data, status) {
|
|
||||||
scope[iterator + 'HoldInput'] = false;
|
|
||||||
ProcessErrors(scope, data, status, null, {
|
|
||||||
hdr: 'Error!',
|
|
||||||
msg: 'Failed to retrieve ' + set + '. GET returned status: ' + status
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
for (i = 1; i <= 3; i++) {
|
||||||
|
modifier = (i === 1) ? '' : i;
|
||||||
|
scope[iterator + 'HoldInput' + modifier] = false;
|
||||||
|
}
|
||||||
|
scope[set] = data.results;
|
||||||
|
scope[iterator + 'Loading'] = false;
|
||||||
|
scope[iterator + 'HidePaginator'] = false;
|
||||||
|
if (!deferWaitStop) {
|
||||||
|
Wait('stop');
|
||||||
|
}
|
||||||
|
scope.$emit('PostRefresh', set);
|
||||||
|
})
|
||||||
|
.error(function (data, status) {
|
||||||
|
scope[iterator + 'HoldInput'] = false;
|
||||||
|
ProcessErrors(scope, data, status, null, {
|
||||||
|
hdr: 'Error!',
|
||||||
|
msg: 'Failed to retrieve ' + set + '. GET returned status: ' + status
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// if you're editing an object, make sure you're on the right
|
||||||
|
// page to display the element you are editing
|
||||||
|
if ($location.$$url.split("/")[1] === params.set && $location.$$url.split("/")[2] && !scope.getNewPage) {
|
||||||
|
var id = $location.$$url.split("/")[2];
|
||||||
|
var restUrl = params.url.split("?")[0];
|
||||||
|
var pageSize = scope[iterator + '_page_size'];
|
||||||
|
pagination.getInitialPageForList(id, restUrl, pageSize)
|
||||||
|
.then(function (currentPage) {
|
||||||
|
scope[iterator + '_page'] = currentPage;
|
||||||
|
params.url = params.url + "&page=" + currentPage;
|
||||||
|
getPage(params.url);
|
||||||
|
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
getPage(params.url);
|
||||||
}
|
}
|
||||||
]);
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
*************************************************/
|
*************************************************/
|
||||||
|
|
||||||
import listGenerator from './list-generator/main';
|
import listGenerator from './list-generator/main';
|
||||||
|
import pagination from './pagination/main';
|
||||||
import title from './title.directive';
|
import title from './title.directive';
|
||||||
import lodashAsPromised from './lodash-as-promised';
|
import lodashAsPromised from './lodash-as-promised';
|
||||||
import stringFilters from './string-filters/main';
|
import stringFilters from './string-filters/main';
|
||||||
@@ -14,6 +15,7 @@ import stateExtender from './stateExtender.provider';
|
|||||||
export default
|
export default
|
||||||
angular.module('shared',
|
angular.module('shared',
|
||||||
[ listGenerator.name,
|
[ listGenerator.name,
|
||||||
|
pagination.name,
|
||||||
stringFilters.name,
|
stringFilters.name,
|
||||||
'ui.router'
|
'ui.router'
|
||||||
])
|
])
|
||||||
|
|||||||
11
awx/ui/client/src/shared/pagination/main.js
Normal file
11
awx/ui/client/src/shared/pagination/main.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/*************************************************
|
||||||
|
* Copyright (c) 2015 Ansible, Inc.
|
||||||
|
*
|
||||||
|
* All Rights Reserved
|
||||||
|
*************************************************/
|
||||||
|
|
||||||
|
import pagination from './pagination.service';
|
||||||
|
|
||||||
|
export default
|
||||||
|
angular.module('pagination', [])
|
||||||
|
.factory('pagination', pagination);
|
||||||
26
awx/ui/client/src/shared/pagination/pagination.service.js
Normal file
26
awx/ui/client/src/shared/pagination/pagination.service.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*************************************************
|
||||||
|
* Copyright (c) 2015 Ansible, Inc.
|
||||||
|
*
|
||||||
|
* All Rights Reserved
|
||||||
|
*************************************************/
|
||||||
|
|
||||||
|
export default ['$q', '$http', function($q, $http) {
|
||||||
|
return {
|
||||||
|
getInitialPageForList: function(id, url, pageSize) {
|
||||||
|
// get the name of the object
|
||||||
|
return $http.get(url + "?id=" + id)
|
||||||
|
.then(function (data) {
|
||||||
|
var name = data.data.results[0].name;
|
||||||
|
// get how many results are less than or equal to
|
||||||
|
// the name
|
||||||
|
return $http.get(url + "?name__lte=" + name)
|
||||||
|
.then(function (data) {
|
||||||
|
// divide by the page size to get what
|
||||||
|
// page the data should be on
|
||||||
|
var count = data.data.count;
|
||||||
|
return Math.ceil(count/pageSize);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}];
|
||||||
Reference in New Issue
Block a user