Skip to content

Commit

Permalink
Update submissions pageination
Browse files Browse the repository at this point in the history
  • Loading branch information
jabrah committed Nov 14, 2023
1 parent ca9f4b3 commit 1e6b036
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 25 deletions.
54 changes: 48 additions & 6 deletions app/controllers/submissions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class SubmissionsIndex extends Controller {
@service('app-static-config') configurator;
@service('emt-themes/bootstrap4') themeInstance;
@service router;
@service store;

@tracked faqUrl = null;
// Bound to message dialog.
Expand All @@ -18,11 +19,13 @@ export default class SubmissionsIndex extends Controller {
@tracked messageText = '';
@tracked tablePageSize = 50;

@tracked queuedModel;

queryParams = ['page', 'pageSize', 'filter'];

@tracked page;
@tracked pageSize;
tablePageSizeValues = [10, 25, 50]; // TODO: Make configurable?
tablePageSizeValues = [1, 5, 10, 25, 50]; // TODO: Make configurable?
@tracked filter;

filterQueryParameters = {
Expand Down Expand Up @@ -133,11 +136,11 @@ export default class SubmissionsIndex extends Controller {
}

get itemsCount() {
return this.model.submissions?.meta?.page?.totalRecords;
return this.queuedModel.meta?.page?.totalRecords;
}

get pagesCount() {
return this.model.submissions?.meta?.page?.totalPages;
return this.queuedModel.meta?.page?.totalPages;
}

@action
Expand All @@ -148,8 +151,47 @@ export default class SubmissionsIndex extends Controller {
}

@action
doQuery(query) {
console.log(`[Controller:Submissions/index] doQuery :: ${JSON.stringify(query)}`);
return this.router.transitionTo({ queryParams: { ...query } });
doQuery(params) {
let query;
const user = this.currentUser.user;

if (user.isAdmin) {
query = {
filter: { submission: 'submissionStatus=out=cancelled' },
include: 'publication',
};
} else if (user.isSubmitter) {
const userMatch = `submitter.id==${user.id},preparers.id=in=${user.id}`;
query = {
filter: {
submission: `(${userMatch});submissionStatus=out=cancelled`,
},
sort: '-submittedDate',
include: 'publication',
};
}

const { page = 1, pageSize = 10 } = params;
query.page = {
number: page,
size: pageSize,
totals: true,
};

if (params.filter) {
query.filter.submission = `(${query.filter.submission});publication.title=ini=*${params.filter}*`;
}

return this.store
.query('submission', query)
.then((data) => {
this.queuedModel = {
submissions: data,
meta: data.meta,
};
})
.catch((e) => {
console.error(e);
});
}
}
32 changes: 15 additions & 17 deletions app/routes/submissions/index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
import { service } from '@ember/service';
import CheckSessionRoute from '../check-session-route';
import RSVP from 'rsvp';
import { restartableTask, timeout } from 'ember-concurrency';

const DEBOUNCE_MS = 500;
export default class IndexRoute extends CheckSessionRoute {
@service('current-user') currentUser;
@service store;

queryParams = {
page: { refreshModel: true },
pageSize: { refreshModel: true },
filter: { refreshModel: true },
page: {},
pageSize: {},
filter: {},
};

async model(params) {
return RSVP.hash({
submissions: this.getSubmissions.perform(this.currentUser.user, params),
});
}

@restartableTask
getSubmissions = function* (user, params) {
yield timeout(DEBOUNCE_MS);

let query;

const user = this.currentUser.user;

if (user.isAdmin) {
query = {
filter: { submission: 'submissionStatus=out=cancelled' },
Expand Down Expand Up @@ -53,6 +43,14 @@ export default class IndexRoute extends CheckSessionRoute {
query.filter.submission = `(${query.filter.submission});publication.title=ini=*${params.filter}*`;
}

return this.store.query('submission', query);
};
return this.store.query('submission', query).then((data) => ({
submissions: data,
meta: data.meta,
}));
}

setupController(controller, model) {
super.setupController(...arguments);
controller.queuedModel = model;
}
}
4 changes: 2 additions & 2 deletions app/templates/submissions/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
<div class="col-12 table-container">
<div class="submission-table" data-test-submissions-index-submissions-table>
<ModelsTableServerPaginated
@data={{this.model.submissions}}
@data={{this.queuedModel.submissions}}
@columns={{this.columns}}
@themeInstance={{this.themeInstance}}
@showColumnsDropdown={{false}}
@useFilteringByColumns={{false}}
@filteringIgnoreCase={{true}}
@multipleColumnsSorting={{false}}
@authorSelected="authorclick"
@pageSize={{this.model.submissions.meta.page.limit}}
@pageSize={{this.pageSize}}
@pageSizeValues={{this.tablePageSizeValues}}
@currentPageNumber={{this.page}}
@itemsCount={{this.itemsCount}}
Expand Down

0 comments on commit 1e6b036

Please sign in to comment.