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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
import CoursewareShelfModule from './store/courseware/courseware-shelf.module';
import ShelfApp from './components/courseware/ShelfApp.vue';
import Vue from 'vue';
import Vuex from 'vuex';
import axios from 'axios';
import { mapResourceModules } from '@elan-ev/reststate-vuex';
import { StockImagesPlugin } from './plugins/stock-images.js';
const mountApp = async (STUDIP, createApp, element) => {
// handle studip 5.0 to 5.2 urls
const elemId = window.location.hash.match(/structural_element\/(\d+)/);
if (elemId) {
let url = new URL(window.location.href);
url.searchParams.set('element_id', elemId[1]);
window.location.href = url;
return false;
}
const getHttpClient = () =>
axios.create({
baseURL: STUDIP.URLHelper.getURL(`jsonapi.php/v1`, {}, true),
headers: {
'Content-Type': 'application/vnd.api+json',
},
});
let elem;
let entry_id = null;
let entry_type = null;
let licenses = null;
let feedbackSettings = null;
let course_perms = null;
if ((elem = document.getElementById(element.substring(1))) !== undefined) {
if (elem.attributes !== undefined) {
if (elem.attributes['entry-type'] !== undefined) {
entry_type = elem.attributes['entry-type'].value;
}
if (elem.attributes['entry-id'] !== undefined) {
entry_id = elem.attributes['entry-id'].value;
}
if (elem.attributes['licenses'] !== undefined) {
licenses = JSON.parse(elem.attributes['licenses'].value);
}
if (elem.attributes['feedback-settings'] !== undefined) {
feedbackSettings = JSON.parse(elem.attributes['feedback-settings'].value);
}
if (elem.attributes['course-perms'] !== undefined) {
course_perms = JSON.parse(elem.attributes['course-perms'].value);
}
}
}
const httpClient = getHttpClient();
const store = new Vuex.Store({
modules: {
'courseware-shelf': CoursewareShelfModule,
...mapResourceModules({
names: [
'courses',
'course-memberships',
'courseware-blocks',
'courseware-containers',
'courseware-instances',
'courseware-units',
'courseware-user-data-fields',
'courseware-user-progresses',
'courseware-structural-elements',
'courseware-structural-elements-shared',
'feedback-elements',
'feedback-entries',
'files',
'file-refs',
'folders',
'users',
'institutes',
'institute-memberships',
'semesters',
'sem-classes',
'sem-types',
'stock-images',
'terms-of-use'
],
httpClient,
}),
},
});
store.dispatch('setUrlHelper', STUDIP.URLHelper);
store.dispatch('setHttpClient', httpClient);
store.dispatch('setLicenses', licenses);
store.dispatch('setUserId', STUDIP.USER_ID);
await store.dispatch('users/loadById', {id: STUDIP.USER_ID});
store.dispatch('setContext', {
id: entry_id,
type: entry_type,
});
if (entry_type === 'courses') {
store.dispatch('setCoursePerms', course_perms);
await store.dispatch('loadCourseUnits', entry_id);
await store.dispatch('setFeedbackSettings', feedbackSettings);
} else {
await store.dispatch('loadUserUnits', entry_id);
await store.dispatch('courseware-structural-elements-shared/loadAll', { options: { include: 'owner' } });
}
Vue.use(StockImagesPlugin, { store });
const app = createApp({
render: (h) => h(ShelfApp),
store,
});
app.$mount(element);
};
export default mountApp;
|