-
Notifications
You must be signed in to change notification settings - Fork 17
/
loadContentHistory.js
43 lines (38 loc) · 1.93 KB
/
loadContentHistory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { shortTitle } from '../../configs/general';
import deckContentTypeError from '../error/deckContentTypeError';
import slideIdTypeError from '../error/slideIdTypeError';
import { AllowedPattern } from '../error/util/allowedPattern';
import DeckTreeStore from '../../stores/DeckTreeStore.js';
import { isEmpty } from '../../common.js';
export default function loadContentHistory(context, payload, done) {
if(!(['deck', 'slide', 'question'].indexOf(payload.params.stype) > -1 || payload.params.stype === undefined)) {
context.executeAction(deckContentTypeError, payload).catch((err) => {done(err);});
return;
}
if (!(AllowedPattern.SLIDE_ID.test(payload.params.sid) || payload.params.sid === undefined)) {
context.executeAction(slideIdTypeError, payload, done);
return;
}
// we need the spath for the history service call
if (isEmpty(payload.params.spath)) {
// in current state of the UI, the history tab is always loaded alongside the deck tree,
// and the loading happens on user click after the page has completed loading,
// therefore the spath is already calculated and stored in the DeckTreeStore state
let deckTreeStore = context.getStore(DeckTreeStore);
let deckTreeState = deckTreeStore.getState();
payload.params.spath = deckTreeState.selector.get('spath');
}
context.service.read('history.list', payload, {timeout: 20 * 1000}, (err, res) => {
if (err) {
context.dispatch('LOAD_CONTENT_HISTORY_FAILURE', err);
} else {
context.dispatch('LOAD_CONTENT_HISTORY_SUCCESS', res);
context.dispatch('UPDATE_MODULE_TYPE_SUCCESS', {moduleType: 'history'});
}
let pageTitle = shortTitle + ' | Content History | ' + payload.params.stype + ' | ' + payload.params.sid;
context.dispatch('UPDATE_PAGE_TITLE', {
pageTitle: pageTitle
});
done();
});
}