Newer
Older
import axios from 'axios';
const getDefaultState = () => {
return {
blockAdder: {},
containerAdder: false,
consumeMode: false,
context: {},
courseware: {},
currentElement: {},
licenses: null, // we need a route for License SORM
httpClient: null,
lastElement: null,
msg: 'Dehydrated',
msgCompanionOverlay:
'Hallo! Ich bin Ihr persönlicher Companion. Wussten Sie schon, dass Courseware jetzt noch einfacher zu bedienen ist?',
styleCompanionOverlay: 'default',
pluginManager: null,
showCompanionOverlay: false,
showToolbar: false,
urlHelper: null,
userId: null,
viewMode: 'read',
filingData: {},
userIsTeacher: false,
showStructuralElementEditDialog: false,
showStructuralElementAddDialog: false,
showStructuralElementExportDialog: false,
showStructuralElementInfoDialog: false,
showStructuralElementDeleteDialog: false,
showStructuralElementOerDialog: false,
showStructuralElementLinkDialog: false,
showSuggestOerDialog: false,
importFilesState: '',
importFilesProgress: 0,
importStructuresState: '',
importStructuresProgress: 0,
permissionFilter: 'read',
sourceFilter: 'all',
showSearchResults: false,
searchResults: [],
};
};
const initialState = getDefaultState();
const getters = {
msg(state) {
return state.msg;
},
lastElement(state) {
return state.lastElement;
},
courseware(state) {
return state.courseware;
},
currentElement(state) {
return state.currentElement;
},
currentStructuralElement(state, getters, rootState, rootGetters) {
const id = getters.currentElement;
return rootGetters['courseware-structural-elements/byId']({ id });
},
currentElementBlocked(state, getters, rootState, rootGetters) {
return getters.currentStructuralElement?.relationships?.['edit-blocker']?.data !== null;
},
currentElementBlockerId(state, getters) {
return getters.currentElementBlocked ? getters.currentStructuralElement?.relationships?.['edit-blocker']?.data?.id : null;
},
currentElementBlockedByThisUser(state, getters) {
return getters.currentElementBlocked && getters.userId === getters.currentElementBlockerId;
},
currentElementBlockedByAnotherUser(state, getters) {
return getters.currentElementBlocked && getters.userId !== getters.currentElementBlockerId;
},
oerEnabled(state) {
return state.oerEnabled;
},
licenses(state) {
return state.licenses;
},
context(state) {
return state.context;
},
blockTypes(state) {
return state.courseware?.attributes?.['block-types'] ?? [];
},
containerTypes(state) {
return state.courseware?.attributes?.['container-types'] ?? [];
},
favoriteBlockTypes(state) {
const allBlockTypes = state.courseware?.attributes?.['block-types'] ?? [];
const favorites = state.courseware?.attributes?.['favorite-block-types'] ?? [];
return allBlockTypes.filter(({ type }) => favorites.includes(type));
},
viewMode(state) {
return state.viewMode;
},
dashboardViewMode(state) {
return state.dashboardViewMode;
},
showToolbar(state) {
return state.showToolbar;
},
selectedToolbarItem(state) {
return state.selectedToolbarItem;
},
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
blockAdder(state) {
return state.blockAdder;
},
containerAdder(state) {
return state.containerAdder;
},
showCompanionOverlay(state) {
return state.showCompanionOverlay;
},
msgCompanionOverlay(state) {
return state.msgCompanionOverlay;
},
styleCompanionOverlay(state) {
return state.styleCompanionOverlay;
},
consumeMode(state) {
return state.consumeMode;
},
httpClient(state) {
return state.httpClient;
},
urlHelper(state) {
return state.urlHelper;
},
userId(state) {
return state.userId;
},
userIsTeacher(state) {
return state.userIsTeacher;
},
teacherStatusLoaded(state) {
return state.teacherStatusLoaded;
},
pluginManager(state) {
return state.pluginManager;
},
filingData(state) {
return state.filingData;
},
showStructuralElementEditDialog(state) {
return state.showStructuralElementEditDialog;
},
showStructuralElementAddDialog(state) {
return state.showStructuralElementAddDialog;
},
showStructuralElementExportDialog(state) {
return state.showStructuralElementExportDialog;
},
showStructuralElementPdfExportDialog(state) {
return state.showStructuralElementPdfExportDialog;
},
showStructuralElementInfoDialog(state) {
return state.showStructuralElementInfoDialog;
},
showStructuralElementOerDialog(state) {
return state.showStructuralElementOerDialog;
},
showStructuralElementDeleteDialog(state) {
return state.showStructuralElementDeleteDialog;
showStructuralElementLinkDialog(state) {
return state.showStructuralElementLinkDialog;
},
showStructuralElementRemoveLockDialog(state) {
return state.showStructuralElementRemoveLockDialog;
},
showOverviewElementAddDialog(state) {
return state.showOverviewElementAddDialog;
},
showSuggestOerDialog(state) {
return state.showSuggestOerDialog;
},
structuralElementSortMode(state) {
return state.structuralElementSortMode;
},
importFilesState(state) {
return state.importFilesState;
},
importFilesProgress(state) {
return state.importFilesProgress;
},
importStructuresState(state) {
return state.importStructuresState;
},
importStructuresProgress(state) {
return state.importStructuresProgress;
},
exportState(state) {
return state.exportState;
},
exportProgress(state) {
return state.exportProgress;
},
permissionFilter(state) {
return state.permissionFilter;
},
sourceFilter(state) {
return state.sourceFilter;
},
showSearchResults(state) {
return state.showSearchResults;
},
searchResults(state) {
return state.searchResults;
},
};
export const state = { ...initialState };
export const actions = {
loadContainer({ dispatch }, containerId) {
const options = {
include: 'blocks,blocks.edit-blocker','fields[users]': 'formatted-name',
};
return dispatch('courseware-containers/loadById', { id: containerId, options }, { root: true });
},
loadStructuralElement({ dispatch }, structuralElementId) {
const options = {
include:
'containers,containers.edit-blocker,containers.blocks,containers.blocks.editor,containers.blocks.owner,containers.blocks.user-data-field,containers.blocks.user-progress,containers.blocks.edit-blocker,editor,edit-blocker,owner',
'fields[users]': 'formatted-name',
};
return dispatch(
'courseware-structural-elements/loadById',
{ id: structuralElementId, options },
{ root: true }
);
},
loadFileRefs({ dispatch, rootGetters }, block_id) {
const parent = {
type: 'courseware-blocks',
id: block_id,
};
const relationship = 'file-refs';
return dispatch('file-refs/loadRelated', { parent, relationship }, { root: true }).then(() =>
rootGetters['file-refs/related']({
})
);
},
async loadCoursewareActivities({ dispatch, rootGetters }, { userId, courseId }) {
const parent = {
type: 'users',
id: userId,
};
const relationship = 'activitystream';
const options = {
'filter[context-type]': 'course',
'filter[context-id]': courseId,
'filter[object-type]': 'courseware',
include: 'actor, context, object',
};
await dispatch('users/loadRelated', { parent, relationship, options }, { root: true });
const activities = rootGetters['users/all'];
const parentFetchers = activities
.filter(({ type }) => type === 'activities')
.map((activity) => this.dispatch(
'courseware-structural-elements/loadById',
{
id: activity.relationships.object.meta['object-id'],
},
));
return Promise.all(parentFetchers).then(() => activities);
},
async createFile(context, { file, filedata, folder }) {
const termId = file?.relationships['terms-of-use']?.data?.id ?? null;
const formData = new FormData();
formData.append('file', filedata, file.attributes.name);
const url = `folders/${folder.id}/file-refs`;
let request = await state.httpClient.post(url, formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
let response = null;
try {
response = await state.httpClient.get(request.headers.location);
}
catch(e) {
console.debug(e);
response = null;
}
},
async createRootFolder({ dispatch, rootGetters }, { context, folder }) {
// get root folder for this context
await dispatch(
{
parent: context,
relationship: 'folders',
},
{ root: true }
);
let folders = await rootGetters[`${context.type}/related`]({
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
parent: context,
relationship: 'folders',
});
let rootFolder = null;
for (let i = 0; i < folders.length; i++) {
if (folders[i].attributes['folder-type'] === 'RootFolder') {
rootFolder = folders[i];
}
}
const newFolder = {
data: {
type: 'folders',
attributes: {
name: folder.name,
'folder-type': 'StandardFolder',
},
relationships: {
parent: {
data: {
type: 'folders',
id: rootFolder.id,
},
},
},
},
};
return state.httpClient.post(`${context.type}/${context.id}/folders`, newFolder).then((response) => {
return response.data.data;
});
},
async createFolder(store, { context, parent, folder }) {
const newFolder = {
data: {
type: 'folders',
attributes: {
name: folder.name,
'folder-type': folder.type,
},
relationships: {
parent: parent,
},
},
};
return state.httpClient.post(`${context.type}/${context.id}/folders`, newFolder).then((response) => {
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
return response.data.data;
});
},
loadFolder({ dispatch }, folderId) {
const options = {};
return dispatch('folders/loadById', { id: folderId, options }, { root: true });
},
copyBlock({ getters }, { parentId, block }) {
const copy = {
data: {
block: block,
parent_id: parentId,
},
};
return state.httpClient.post(`courseware-blocks/${block.id}/copy`, copy).then((resp) => {
// console.log(resp);
});
},
copyContainer({ getters }, { parentId, container }) {
const copy = {
data: {
container: container,
parent_id: parentId,
},
};
return state.httpClient.post(`courseware-containers/${container.id}/copy`, copy).then((resp) => {
// console.log(resp);
});
},
async copyStructuralElement({ dispatch, getters, rootGetters }, { parentId, elementId, removePurpose, migrate }) {
const copy = { data: { parent_id: parentId, remove_purpose: removePurpose, migrate: migrate } };
const result = await state.httpClient.post(`courseware-structural-elements/${elementId}/copy`, copy);
const id = result.data.data.id;
await dispatch('loadStructuralElement', id);
const newElement = rootGetters['courseware-structural-elements/byId']({ id });
return dispatch('courseware-structure/loadDescendants', { root: newElement });
async linkStructuralElement({ dispatch, getters, rootGetters }, { parentId, elementId }) {
const link = { data: { parent_id: parentId } };
const result = await state.httpClient.post(`courseware-structural-elements/${elementId}/link`, link);
const id = result.data.data.id;
await dispatch('loadStructuralElement', id);
const newElement = rootGetters['courseware-structural-elements/byId']({ id });
return dispatch('courseware-structure/loadDescendants', { root: newElement });
},
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
async createBlockInContainer({ dispatch }, { container, blockType }) {
const block = {
attributes: {
'block-type': blockType,
payload: null,
},
relationships: {
container: {
data: { type: container.type, id: container.id },
},
},
};
await dispatch('courseware-blocks/create', block, { root: true });
return dispatch('loadContainer', container.id);
},
async deleteBlockInContainer({ dispatch }, { containerId, blockId }) {
const data = {
id: blockId,
};
await dispatch('courseware-blocks/delete', data, { root: true });
//TODO throws TypeError: block is undefined after delete
return dispatch('loadContainer', containerId);
},
async updateBlockInContainer({ dispatch }, { attributes, blockId, containerId }) {
const container = {
type: 'courseware-containers',
id: containerId,
};
const block = {
type: 'courseware-blocks',
attributes: attributes,
id: blockId,
relationships: {
container: {
data: { type: container.type, id: container.id },
},
},
};
await dispatch('courseware-blocks/update', block, { root: true });
await dispatch('unlockObject', { id: blockId, type: 'courseware-blocks' });
return dispatch('loadContainer', containerId);
},
async updateBlock({ dispatch }, { block, containerId }) {
const container = {
type: 'courseware-containers',
id: containerId,
};
const updateBlock = {
type: 'courseware-blocks',
attributes: block.attributes,
id: block.id,
relationships: {
container: {
data: { type: container.type, id: container.id },
},
},
};
await dispatch('courseware-blocks/update', updateBlock, { root: true });
return dispatch('loadContainer', containerId);
},
async deleteBlock({ dispatch }, { containerId, blockId }) {
const data = {
id: blockId,
};
await dispatch('courseware-blocks/delete', data, { root: true });
//TODO throws TypeError: block is undefined after delete
return dispatch('loadContainer', containerId);
},
async storeCoursewareSettings({ dispatch, getters }, { permission, progression }) {
const courseware = getters.courseware;
courseware.attributes['editing-permission-level'] = permission;
courseware.attributes['sequential-progression'] = progression;
return dispatch('courseware-instances/update', courseware, { root: true });
},
sortChildrenInStructualElements({ dispatch }, { parent, children }) {
const childrenResourceIdentifiers = children.map(({ type, id }) => ({ type, id }));
return dispatch(
`courseware-structural-elements/setRelated`,
{
parent: { type: parent.type, id: parent.id },
relationship: 'children',
data: childrenResourceIdentifiers,
},
{ root: true }
).then(() => dispatch(
`${parent.type}/loadRelated`,
{
parent: { type: parent.type, id: parent.id },
relationship: 'children',
},
{ root: true }
)).then(() => dispatch('courseware-structure/build', null, { root: true }));
},
async createStructuralElement({ dispatch }, { attributes, parentId, currentId }) {
const data = {
attributes,
relationships: {
parent: {
data: {
type: 'courseware-structural-elements',
id: parentId,
},
},
},
};
await dispatch('courseware-structural-elements/create', data, { root: true });
return dispatch('loadStructuralElement', currentId);
},
async createStructuralElementWithTemplate({ dispatch }, { attributes, parentId, currentId, templateId }) {
const data = {
attributes,
relationships: {
parent: {
data: {
type: 'courseware-structural-elements',
id: parentId,
},
},
},
templateId: templateId,
};
await dispatch('courseware-structural-elements/create', data, { root: true });
const options = {
include: 'children',
};
return dispatch('courseware-structural-elements/loadById', { id: currentId, options }, { root: true });
},
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
async deleteStructuralElement({ dispatch }, { id, parentId }) {
const data = {
id: id,
};
await dispatch('courseware-structural-elements/delete', data, { root: true });
return dispatch('loadStructuralElement', parentId);
},
async updateStructuralElement({ dispatch }, { element, id }) {
await dispatch('courseware-structural-elements/update', element, { root: true });
return dispatch('loadStructuralElement', id);
},
sortContainersInStructualElements({ dispatch }, { structuralElement, containers }) {
const containerResourceIdentifiers = containers.map(({ type, id }) => ({ type, id }));
return dispatch(
`courseware-structural-elements/setRelated`,
{
parent: { type: structuralElement.type, id: structuralElement.id },
relationship: 'containers',
data: containerResourceIdentifiers,
},
{ root: true }
);
},
async createContainer({ dispatch }, { attributes, structuralElementId }) {
const data = {
attributes,
relationships: {
'structural-element': {
data: {
type: 'courseware-structural-elements',
id: structuralElementId,
},
},
},
};
await dispatch('courseware-containers/create', data, { root: true });
return dispatch('loadStructuralElement', structuralElementId);
},
async deleteContainer({ dispatch }, { containerId, structuralElementId }) {
const data = {
id: containerId,
};
await dispatch('courseware-containers/delete', data, { root: true });
//TODO throws TypeError: container is undefined after delete
return dispatch('loadStructuralElement', structuralElementId);
},
async updateContainer({ dispatch }, { container, structuralElementId }) {
await dispatch('courseware-containers/update', container, { root: true });
return dispatch('loadStructuralElement', structuralElementId);
},
sortBlocksInContainer({ dispatch }, { container, sections }) {
let blockResourceIdentifiers = [];
sections.forEach((section) => {
blockResourceIdentifiers.push(...section.blocks.map(({ type, id }) => ({ type, id })));
});
return dispatch(
`courseware-containers/setRelated`,
{
parent: { type: container.type, id: container.id },
relationship: 'blocks',
data: blockResourceIdentifiers,
},
{ root: true }
);
},
lockObject({ dispatch, getters }, { id, type }) {
return dispatch(`${type}/setRelated`, {
parent: { id, type },
relationship: 'edit-blocker',
data: {
type: 'users',
id: getters.userId,
},
});
},
unlockObject({ dispatch }, { id, type }) {
return dispatch(`${type}/setRelated`, {
parent: { id, type },
relationship: 'edit-blocker',
data: null,
});
},
async companionInfo({ dispatch }, { info }) {
await dispatch('coursewareStyleCompanionOverlay', 'default');
await dispatch('coursewareMsgCompanionOverlay', info);
return dispatch('coursewareShowCompanionOverlay', true);
},
async companionSuccess({ dispatch }, { info }) {
await dispatch('coursewareStyleCompanionOverlay', 'happy');
await dispatch('coursewareMsgCompanionOverlay', info);
return dispatch('coursewareShowCompanionOverlay', true);
},
async companionError({ dispatch }, { info }) {
await dispatch('coursewareStyleCompanionOverlay', 'sad');
await dispatch('coursewareMsgCompanionOverlay', info);
return dispatch('coursewareShowCompanionOverlay', true);
},
async companionWarning({ dispatch }, { info }) {
await dispatch('coursewareStyleCompanionOverlay', 'alert');
await dispatch('coursewareMsgCompanionOverlay', info);
return dispatch('coursewareShowCompanionOverlay', true);
},
async companionSpecial({ dispatch }, { info }) {
await dispatch('coursewareStyleCompanionOverlay', 'special');
await dispatch('coursewareMsgCompanionOverlay', info);
return dispatch('coursewareShowCompanionOverlay', true);
},
// adds a favorite block type using the `type` of the BlockType
async addFavoriteBlockType({ dispatch, getters }, blockType) {
const blockTypes = new Set(getters.favoriteBlockTypes.map(({ type }) => type));
blockTypes.add(blockType);
return dispatch('storeFavoriteBlockTypes', [...blockTypes]);
},
// removes a favorite block type using the `type` of the BlockType
async removeFavoriteBlockType({ dispatch, getters }, blockType) {
const blockTypes = new Set(getters.favoriteBlockTypes.map(({ type }) => type));
blockTypes.delete(blockType);
return dispatch('storeFavoriteBlockTypes', [...blockTypes]);
},
// sets the favorite block types using an array of the `type`s of those BlockTypes
async storeFavoriteBlockTypes({ dispatch, getters }, favoriteBlockTypes) {
const courseware = getters.courseware;
courseware.attributes['favorite-block-types'] = favoriteBlockTypes;
return dispatch('courseware-instances/update', courseware, { root: true });
},
coursewareCurrentElement(context, id) {
context.commit('coursewareCurrentElementSet', id);
},
coursewareContext(context, id) {
context.commit('coursewareContextSet', id);
},
oerEnabled(context, enabled) {
context.commit('oerEnabledSet', enabled);
},
licenses(context, licenses) {
context.commit('licensesSet', licenses);
},
coursewareViewMode(context, view) {
context.commit('coursewareViewModeSet', view);
},
setDashboardViewMode(context, view) {
context.commit('setDashboardViewMode', view);
},
coursewareShowToolbar(context, toolbar) {
context.commit('coursewareShowToolbarSet', toolbar);
},
coursewareSelectedToolbarItem(context, item) {
context.commit('coursewareSelectedToolbarItemSet', item);
},
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
coursewareBlockAdder(context, adder) {
context.commit('coursewareBlockAdderSet', adder);
},
coursewareContainerAdder(context, adder) {
context.commit('coursewareContainerAdderSet', adder);
},
coursewareShowCompanionOverlay(context, companion_overlay) {
context.commit('coursewareShowCompanionOverlaySet', companion_overlay);
},
coursewareMsgCompanionOverlay(context, companion_overlay_msg) {
context.commit('coursewareMsgCompanionOverlaySet', companion_overlay_msg);
},
coursewareStyleCompanionOverlay(context, companion_overlay_style) {
context.commit('coursewareStyleCompanionOverlaySet', companion_overlay_style);
},
coursewareConsumeMode(context, mode) {
context.commit('coursewareConsumeModeSet', mode);
},
setHttpClient({ commit }, httpClient) {
commit('setHttpClient', httpClient);
},
setUrlHelper({ commit }, urlHelper) {
commit('setUrlHelper', urlHelper);
},
setUserId({ commit }, userId) {
commit('setUserId', userId);
},
showElementEditDialog(context, bool) {
},
showElementAddDialog(context, bool) {
},
showElementExportDialog(context, bool) {
showElementPdfExportDialog(context, bool) {
context.commit('setShowStructuralElementPdfExportDialog', bool);
},
showElementInfoDialog(context, bool) {
},
showElementOerDialog(context, bool) {
updateShowSuggestOerDialog(context, bool) {
context.commit('setShowSuggestOerDialog', bool);
},
showElementDeleteDialog(context, bool) {
showElementLinkDialog(context, bool) {
context.commit('setShowStructuralElementLinkDialog', bool);
},
showElementRemoveLockDialog(context, bool) {
context.commit('setShowStructuralElementRemoveLockDialog', bool);
},
setShowOverviewElementAddDialog(context, bool) {
context.commit('setShowOverviewElementAddDialog', bool);
setStructuralElementSortMode({ commit }, bool) {
commit('setStructuralElementSortMode', bool);
setImportFilesState({ commit }, state) {
commit('setImportFilesState', state);
setImportFilesProgress({ commit }, percent) {
commit('setImportFilesProgress', percent);
setImportStructuresState({ commit }, state) {
commit('setImportStructuresState', state);
},
setImportStructuresProgress({ commit }, percent) {
commit('setImportStructuresProgress', percent);
},
setImportErrors({ commit }, errors) {
setExportState({ commit }, state) {
commit('setExportState', state);
setExportProgress({ commit }, percent) {
commit('setExportProgress', percent);
setShowSearchResults({ commit }, state) {
commit('setShowSearchResults', state);
},
setSearchResults({ commit }, state) {
commit('setSearchResults', state);
},
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
addBookmark({ dispatch, rootGetters }, structuralElement) {
const cw = rootGetters['courseware'];
// get existing bookmarks
const bookmarks =
rootGetters['courseware-structural-elements/related']({
parent: cw,
relationship: 'bookmarks',
})?.map(({ type, id }) => ({ type, id })) ?? [];
// add a new bookmark
const data = [...bookmarks, { type: structuralElement.type, id: structuralElement.id }];
// send them home
return dispatch(
`courseware-structural-elements/setRelated`,
{
parent: { type: cw.type, id: cw.id },
relationship: 'bookmarks',
data,
},
{ root: true }
);
},
removeBookmark({ dispatch, rootGetters }, structuralElement) {
const cw = rootGetters['courseware'];
// get existing bookmarks
const bookmarks =
rootGetters['courseware-structural-elements/related']({
parent: cw,
relationship: 'bookmarks',
})?.map(({ type, id }) => ({ type, id })) ?? [];
// filter bookmark that must be removed
const data = bookmarks.filter(({ id }) => id !== structuralElement.id);
// send them home
return dispatch(
`courseware-structural-elements/setRelated`,
{
parent: { type: cw.type, id: cw.id },
relationship: 'bookmarks',
data,
},
{ root: true }
);
},
setPluginManager({ commit }, pluginManager) {
commit('setPluginManager', pluginManager);
},
uploadImageForStructuralElement({ dispatch, state }, { structuralElement, file }) {
const formData = new FormData();
formData.append('image', file);
const url = `courseware-structural-elements/${structuralElement.id}/image`;
return state.httpClient.post(url, formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
},
async deleteImageForStructuralElement({ dispatch, state }, structuralElement) {
const url = `courseware-structural-elements/${structuralElement.id}/image`;
await state.httpClient.delete(url);
return dispatch('loadStructuralElement', structuralElement.id);
},
cwManagerFilingData(context, msg) {
context.commit('cwManagerFilingDataSet', msg);
},

Marcus Eibrink-Lunzenauer
committed
async loadRelatedPaginated({ dispatch, rootGetters }, { type, parent, relationship, options }) {
const limit = 100;
let offset = 0;
await loadPage(offset, limit);
const total = rootGetters[`${type}/lastMeta`].page.total;
const pages = [];
for (let page = 1; page * limit < total; page++) {
pages.push(loadPage(page * limit, limit));
}
return Promise.all(pages);
function loadPage(offset, limit) {
return dispatch(

Marcus Eibrink-Lunzenauer
committed
`${type}/loadRelated`,
{
parent,