Fixes pagination on IG/Instance jobs lists

This commit is contained in:
mabashian
2018-07-26 10:55:56 -04:00
parent 979eaeddfa
commit 7a509a4dcb
16 changed files with 96 additions and 58 deletions

View File

@@ -4,7 +4,7 @@ function IndexJobsController ($scope, strings, dataset) {
vm.count = dataset.data.count; vm.count = dataset.data.count;
$scope.$on('updateCount', (e, count) => { $scope.$on('updateCount', (e, count) => {
if (count) { if (typeof count === 'number') {
vm.count = count; vm.count = count;
} }
}); });

View File

@@ -16,7 +16,8 @@ function ListJobsController (
$filter, $filter,
ProcessErrors, ProcessErrors,
Wait, Wait,
Rest Rest,
SearchBasePath
) { ) {
const vm = this || {}; const vm = this || {};
const [unifiedJob] = resolvedModels; const [unifiedJob] = resolvedModels;
@@ -26,21 +27,21 @@ function ListJobsController (
// smart-search // smart-search
const name = 'jobs'; const name = 'jobs';
const iterator = 'job'; const iterator = 'job';
const key = 'job_dataset';
let launchModalOpen = false; let launchModalOpen = false;
let refreshAfterLaunchClose = false; let refreshAfterLaunchClose = false;
$scope.list = { iterator, name }; vm.searchBasePath = SearchBasePath;
$scope.collection = { iterator, basePath: 'unified_jobs' };
$scope[key] = Dataset.data; vm.list = { iterator, name };
$scope[name] = Dataset.data.results; vm.job_dataset = Dataset.data;
$scope.$emit('updateCount', Dataset.data.count, 'jobs'); vm.jobs = Dataset.data.results;
$scope.$on('updateDataset', (e, dataset) => { vm.querySet = $state.params.job_search;
$scope[key] = dataset;
$scope[name] = dataset.results; $scope.$watch('vm.job_dataset.count', () => {
$scope.$emit('updateCount', dataset.count, 'jobs'); $scope.$emit('updateCount', vm.job_dataset.count, 'jobs');
}); });
$scope.$on('ws-jobs', () => { $scope.$on('ws-jobs', () => {
if (!launchModalOpen) { if (!launchModalOpen) {
refreshJobs(); refreshJobs();
@@ -114,7 +115,7 @@ function ListJobsController (
.then(() => { .then(() => {
let reloadListStateParams = null; let reloadListStateParams = null;
if ($scope.jobs.length === 1 && $state.params.job_search && if (vm.jobs.length === 1 && $state.params.job_search &&
_.has($state, 'params.job_search.page') && _.has($state, 'params.job_search.page') &&
$state.params.job_search.page !== '1') { $state.params.job_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params); reloadListStateParams = _.cloneDeep($state.params);
@@ -155,7 +156,7 @@ function ListJobsController (
.then(() => { .then(() => {
let reloadListStateParams = null; let reloadListStateParams = null;
if ($scope.jobs.length === 1 && $state.params.job_search && if (vm.jobs.length === 1 && $state.params.job_search &&
!_.isEmpty($state.params.job_search.page) && !_.isEmpty($state.params.job_search.page) &&
$state.params.job_search.page !== '1') { $state.params.job_search.page !== '1') {
const page = `${(parseInt(reloadListStateParams const page = `${(parseInt(reloadListStateParams
@@ -190,9 +191,10 @@ function ListJobsController (
}; };
function refreshJobs () { function refreshJobs () {
qs.search(unifiedJob.path, $state.params.job_search) qs.search(SearchBasePath, $state.params.job_search)
.then(({ data }) => { .then(({ data }) => {
$scope.$emit('updateDataset', data); vm.jobs = data.results;
vm.job_dataset = data;
}); });
} }
} }
@@ -208,7 +210,8 @@ ListJobsController.$inject = [
'$filter', '$filter',
'ProcessErrors', 'ProcessErrors',
'Wait', 'Wait',
'Rest' 'Rest',
'SearchBasePath'
]; ];
export default ListJobsController; export default ListJobsController;

View File

@@ -3,19 +3,19 @@
<smart-search <smart-search
class="at-List-search" class="at-List-search"
django-model="jobs" django-model="jobs"
base-path="unified_jobs" base-path="{{vm.searchBasePath}}"
iterator="job" iterator="job"
list="list" list="vm.list"
dataset="job_dataset" dataset="vm.job_dataset"
collection="collection" collection="vm.jobs"
search-tags="searchTags" search-tags="searchTags"
query-set="querySet" query-set="vm.querySet"
search-bar-full-width="vm.isPortalMode"> search-bar-full-width="vm.isPortalMode">
</smart-search> </smart-search>
</div> </div>
<at-list results="jobs" empty-list-reason="{{ vm.emptyListReason }}"> <at-list results="vm.jobs" empty-list-reason="{{ vm.emptyListReason }}">
<!-- TODO: implement resources are missing red indicator as present in mockup --> <!-- TODO: implement resources are missing red indicator as present in mockup -->
<at-row ng-repeat="job in jobs" job-id="{{ job.id }}"> <at-row ng-repeat="job in vm.jobs" job-id="{{ job.id }}">
<div class="at-Row-items"> <div class="at-Row-items">
<!-- TODO: include workflow tab as well --> <!-- TODO: include workflow tab as well -->
<at-row-item <at-row-item
@@ -94,10 +94,10 @@
</at-row> </at-row>
</at-list> </at-list>
<paginate <paginate
collection="collection" collection="vm.jobs"
dataset="job_dataset" dataset="vm.job_dataset"
iterator="job" iterator="job"
base-path="unified_jobs" base-path="{{vm.searchBasePath}}"
query-set="querySet"> query-set="vm.querySet">
</paginate> </paginate>
</at-panel-body> </at-panel-body>

View File

@@ -53,6 +53,10 @@ export default {
return qs.search(searchPath, searchParam) return qs.search(searchPath, searchParam)
.finally(() => Wait('stop')); .finally(() => Wait('stop'));
} }
],
SearchBasePath: [
'GetBasePath',
(GetBasePath) => GetBasePath('unified_jobs')
] ]
} }
}; };

View File

@@ -59,6 +59,10 @@ export default {
return qs.search(searchPath, searchParam) return qs.search(searchPath, searchParam)
.finally(() => Wait('stop')); .finally(() => Wait('stop'));
} }
],
SearchBasePath: [
'$stateParams',
($stateParams) => `api/v2/instance_groups/${$stateParams.instance_group_id}/jobs`
] ]
} }
}; };

View File

@@ -59,6 +59,10 @@ export default {
return qs.search(searchPath, searchParam) return qs.search(searchPath, searchParam)
.finally(() => Wait('stop')); .finally(() => Wait('stop'));
} }
],
SearchBasePath: [
'$stateParams',
($stateParams) => `api/v2/instances/${$stateParams.instance_id}/jobs`
] ]
} }
}; };

View File

@@ -58,6 +58,10 @@ export default {
return qs.search(searchPath, searchParam) return qs.search(searchPath, searchParam)
.finally(() => Wait('stop')); .finally(() => Wait('stop'));
} }
],
SearchBasePath: [
'GetBasePath',
(GetBasePath) => GetBasePath('unified_jobs')
] ]
} }
}; };

View File

@@ -56,6 +56,10 @@ export default {
.finally(() => Wait('stop')); .finally(() => Wait('stop'));
} }
], ],
SearchBasePath: [
'GetBasePath',
(GetBasePath) => GetBasePath('unified_jobs')
]
}, },
views: { views: {
'@': { '@': {

View File

@@ -55,6 +55,10 @@ export default {
return qs.search(searchPath, searchParam) return qs.search(searchPath, searchParam)
.finally(() => Wait('stop')); .finally(() => Wait('stop'));
} }
],
SearchBasePath: [
'GetBasePath',
(GetBasePath) => GetBasePath('unified_jobs')
] ]
} }
}; };

View File

@@ -54,6 +54,10 @@ export default {
return qs.search(searchPath, searchParam) return qs.search(searchPath, searchParam)
.finally(() => Wait('stop')); .finally(() => Wait('stop'));
} }
],
SearchBasePath: [
'GetBasePath',
(GetBasePath) => GetBasePath('unified_jobs')
] ]
} }
}; };

View File

@@ -4,7 +4,7 @@ function IndexTemplatesController ($scope, strings, dataset) {
vm.count = dataset.data.count; vm.count = dataset.data.count;
$scope.$on('updateCount', (e, count) => { $scope.$on('updateCount', (e, count) => {
if (count) { if (typeof count === 'number') {
vm.count = count; vm.count = count;
} }
}); });

View File

@@ -1,36 +1,39 @@
function InstanceGroupJobsContainerController (strings, $state) { function InstanceGroupJobsContainerController ($scope, strings, $state) {
const vm = this || {}; const vm = this || {};
init(); const instanceGroupId = $state.params.instance_group_id;
function init() {
const instanceGroupId = $state.params.instance_group_id;
vm.panelTitle = strings.get('jobs.PANEL_TITLE'); vm.panelTitle = strings.get('jobs.PANEL_TITLE');
vm.strings = strings; vm.strings = strings;
vm.tab = { vm.tab = {
details: { details: {
_go: 'instanceGroups.edit', _go: 'instanceGroups.edit',
_params: { instance_group_id: instanceGroupId }, _params: { instance_group_id: instanceGroupId },
_label: strings.get('tab.DETAILS') _label: strings.get('tab.DETAILS')
}, },
instances: { instances: {
_go: 'instanceGroups.instances', _go: 'instanceGroups.instances',
_params: { instance_group_id: instanceGroupId }, _params: { instance_group_id: instanceGroupId },
_label: strings.get('tab.INSTANCES') _label: strings.get('tab.INSTANCES')
}, },
jobs: { jobs: {
_active: true, _active: true,
_params: { instance_group_id: instanceGroupId }, _params: { instance_group_id: instanceGroupId },
_label: strings.get('tab.JOBS') _label: strings.get('tab.JOBS')
} }
}; };
}
$scope.$on('updateCount', (e, count) => {
if (typeof count === 'number') {
vm.count = count;
}
});
} }
InstanceGroupJobsContainerController.$inject = [ InstanceGroupJobsContainerController.$inject = [
'$scope',
'InstanceGroupsStrings', 'InstanceGroupsStrings',
'$state' '$state'
]; ];

View File

@@ -1,5 +1,5 @@
<at-panel> <at-panel>
<at-panel-heading title="{{:: vm.panelTitle }}"></at-panel-heading> <at-panel-heading title="{{:: vm.panelTitle }}" badge="{{ vm.count }}"></at-panel-heading>
<at-tab-group class="at-TabGroup--padBelow"> <at-tab-group class="at-TabGroup--padBelow">
<at-tab state="vm.tab.details">{{:: vm.strings.get('tab.DETAILS') }}</at-tab> <at-tab state="vm.tab.details">{{:: vm.strings.get('tab.DETAILS') }}</at-tab>

View File

@@ -1,5 +1,5 @@
function InstanceGroupJobsContainerController (strings) { function InstanceGroupJobsContainerController ($scope, strings) {
const vm = this || {}; const vm = this || {};
init(); init();
@@ -8,9 +8,15 @@ function InstanceGroupJobsContainerController (strings) {
vm.strings = strings; vm.strings = strings;
} }
$scope.$on('updateCount', (e, count) => {
if (typeof count === 'number') {
vm.count = count;
}
});
} }
InstanceGroupJobsContainerController.$inject = [ InstanceGroupJobsContainerController.$inject = [
'$scope',
'InstanceGroupsStrings' 'InstanceGroupsStrings'
]; ];

View File

@@ -1,5 +1,5 @@
<at-panel> <at-panel>
<at-panel-heading title="{{:: vm.panelTitle }}"></at-panel-heading> <at-panel-heading title="{{:: vm.panelTitle }}" badge="{{ vm.count }}"></at-panel-heading>
<div ui-view="jobsList"></div> <div ui-view="jobsList"></div>
</at-panel> </at-panel>

View File

@@ -73,8 +73,6 @@ xdescribe('Directive: lookupModal', () => {
$parent.mock = 1; // resource id $parent.mock = 1; // resource id
$parent.mock_name = 'Mock Resource 1'; // resource name $parent.mock_name = 'Mock Resource 1'; // resource name
console.log($scope);
element = $compile(dom)($scope); element = $compile(dom)($scope);
$scope.$digest(); $scope.$digest();