Skip to content

Commit 892ab07

Browse files
authored
Merge pull request #4616 from rtibbles/paginate_topics
Paginate topics
2 parents 9f40dab + cf8d7b2 commit 892ab07

File tree

10 files changed

+248
-125
lines changed

10 files changed

+248
-125
lines changed

contentcuration/contentcuration/frontend/channelEdit/views/CurrentTopicView.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@
172172
@deselect="selected = selected.filter(id => id !== $event)"
173173
@scroll="scroll"
174174
@editTitleDescription="showTitleDescriptionModal"
175-
/>
175+
>
176+
<template #pagination>
177+
<slot name="pagination"></slot>
178+
</template>
179+
</NodePanel>
176180
</DraggableRegion>
177181
</VFadeTransition>
178182
<ResourceDrawer

contentcuration/contentcuration/frontend/channelEdit/views/NodePanel.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
/>
4646
</template>
4747
</VList>
48+
<slot name="pagination"></slot>
4849
</div>
4950

5051
</template>

contentcuration/contentcuration/frontend/channelEdit/views/TreeView/index.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const GETTERS = {
2222
canManage: jest.fn(() => true),
2323
},
2424
contentNode: {
25-
getContentNodeChildren: () => jest.fn(() => []),
25+
getContentNodeChildren: () => jest.fn(() => ({ results: [], more: null })),
2626
getContentNodeAncestors: () => jest.fn(() => []),
2727
getContentNode: () => jest.fn(() => ({})),
2828
getTopicAndResourceCounts: () => jest.fn(() => ({ topicCount: 0, resourceCount: 0 })),
@@ -35,7 +35,7 @@ const ACTIONS = {
3535
loadContentNode: jest.fn(),
3636
headContentNode: () => jest.fn(),
3737
loadContentNodes: jest.fn(),
38-
loadChildren: jest.fn(),
38+
loadChildren: jest.fn(() => ({ results: [], more: null })),
3939
},
4040
};
4141

contentcuration/contentcuration/frontend/channelEdit/views/TreeView/index.vue

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@
128128
/>
129129
</div>
130130
</template>
131+
<template #pagination>
132+
<div class="pagination-container">
133+
<KButton v-if="more" :disabled="moreLoading" @click="loadMore">
134+
{{ $tr('showMore') }}
135+
</KButton>
136+
</div>
137+
</template>
131138
</CurrentTopicView>
132139
</VContent>
133140
</TreeViewBase>
@@ -192,6 +199,8 @@
192199
},
193200
loading: true,
194201
listElevated: false,
202+
more: null,
203+
moreLoading: false,
195204
};
196205
},
197206
computed: {
@@ -285,25 +294,30 @@
285294
},
286295
},
287296
created() {
288-
let childrenPromise;
289-
// If viewing the root-level node, don't request anything, since the NodePanel.created
290-
// hook will make a redundant request
291-
if (this.nodeId === this.rootId) {
292-
childrenPromise = Promise.resolve();
293-
} else {
294-
childrenPromise = this.loadContentNodes({ parent: this.rootId });
295-
}
296-
Promise.all([childrenPromise, this.loadAncestors({ id: this.nodeId })]).then(() => {
297-
this.loading = false;
298-
this.jumpToLocation();
299-
});
297+
const childrenPromise = this.loadChildren({ parent: this.rootId });
298+
Promise.all([childrenPromise, this.loadAncestors({ id: this.nodeId })]).then(
299+
([childrenResponse]) => {
300+
this.loading = false;
301+
this.more = childrenResponse.more || null;
302+
this.jumpToLocation();
303+
}
304+
);
300305
},
301306
methods: {
302307
...mapMutations('contentNode', {
303308
collapseAll: 'COLLAPSE_ALL_EXPANDED',
304309
setExpanded: 'SET_EXPANSION',
305310
}),
306-
...mapActions('contentNode', ['loadAncestors', 'loadContentNodes']),
311+
...mapActions('contentNode', ['loadAncestors', 'loadChildren', 'loadContentNodes']),
312+
loadMore() {
313+
if (this.more && !this.moreLoading) {
314+
this.moreLoading = true;
315+
this.loadContentNodes(this.more).then(response => {
316+
this.more = response.more || null;
317+
this.moreLoading = false;
318+
});
319+
}
320+
},
307321
verifyContentNodeId(id) {
308322
this.nodeNotFound = false;
309323
return this.$store.dispatch('contentNode/headContentNode', id).catch(() => {
@@ -400,6 +414,7 @@
400414
openCurrentLocationButton: 'Expand to current folder location',
401415
updatedResourcesReadyForReview: 'Updated resources are ready for review',
402416
closeDrawer: 'Close',
417+
showMore: 'Show more',
403418
},
404419
};
405420
@@ -447,4 +462,10 @@
447462
}
448463
}
449464
465+
.pagination-container {
466+
display: flex;
467+
justify-content: flex-start;
468+
margin: 4px;
469+
}
470+
450471
</style>

contentcuration/contentcuration/frontend/channelEdit/vuex/contentNode/actions.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ import * as publicApi from 'shared/data/public';
1919
import db from 'shared/data/db';
2020

2121
export function loadContentNodes(context, params = {}) {
22-
return ContentNode.where(params).then(contentNodes => {
22+
return ContentNode.where(params).then(response => {
23+
const contentNodes = response.results ? response.results : response;
2324
context.commit('ADD_CONTENTNODES', contentNodes);
24-
return contentNodes;
25+
return response;
2526
});
2627
}
2728

@@ -70,7 +71,7 @@ export function loadContentNodeByNodeId(context, nodeId) {
7071
}
7172

7273
export function loadChildren(context, { parent, published = null, complete = null }) {
73-
const params = { parent };
74+
const params = { parent, max_results: 25 };
7475
if (published !== null) {
7576
params.published = published;
7677
}

contentcuration/contentcuration/frontend/shared/data/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const CHANGE_TYPES_LOOKUP = invert(CHANGE_TYPES);
2929

3030
// Tables
3131
export const CHANGES_TABLE = 'changesForSyncing';
32+
export const PAGINATION_TABLE = 'pagination';
3233

3334
export const TABLE_NAMES = {
3435
SESSION: 'session',

contentcuration/contentcuration/frontend/shared/data/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Sentry from '@sentry/vue';
22
import mapValues from 'lodash/mapValues';
3-
import { CHANGES_TABLE, TABLE_NAMES } from './constants';
3+
import { CHANGES_TABLE, PAGINATION_TABLE, TABLE_NAMES } from './constants';
44
import db from './db';
55
import { INDEXEDDB_RESOURCES } from './registry';
66
import { startSyncing, stopSyncing, syncOnChanges } from './serverSync';
@@ -14,14 +14,18 @@ export function setupSchema() {
1414
if (!Object.keys(resources).length) {
1515
console.warn('No resources defined!'); // eslint-disable-line no-console
1616
}
17-
// Version incremented to 3 to add new index on CHANGES_TABLE.
17+
// Version incremented to 2 to add Bookmark table and new index on CHANGES_TABLE.
18+
// Version incremented to 3 to add:
19+
// new index on CHANGES_TABLE.
20+
// PAGINATION_TABLE.
1821
db.version(3).stores({
1922
// A special table for logging unsynced changes
2023
// Dexie.js appears to have a table for this,
2124
// but it seems to squash and remove changes in ways
2225
// that I do not currently understand, so we engage
2326
// in somewhat duplicative behaviour instead.
2427
[CHANGES_TABLE]: 'rev++,[table+key],server_rev,type',
28+
[PAGINATION_TABLE]: '[table+queryString]',
2529
...mapValues(INDEXEDDB_RESOURCES, value => value.schema),
2630
});
2731
}

0 commit comments

Comments
 (0)