aboutsummaryrefslogtreecommitdiff
path: root/resources/vue/courseware-content-bookmark-app.js
blob: 7a05033af69466409a9eb97165fefc7a623912b3 (plain)
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
import ContentBookmarkApp from './components/courseware/ContentBookmarkApp.vue';
import CoursewareModule from './store/courseware/courseware.module';
import axios from 'axios';
import { h } from "vue";

const mountApp = (STUDIP, createApp, store, element) => {
    const getHttpClient = () =>
    axios.create({
        baseURL: STUDIP.URLHelper.getURL(`jsonapi.php/v1`, {}, true),
        headers: {
            'Content-Type': 'application/vnd.api+json',
        },
    });

    const httpClient = getHttpClient();

    store.registerModule('courseware', CoursewareModule);

    let entry_id = null;
    let entry_type = null;
    let elem;

    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;
            }
        }
    }

    store.dispatch('setUserId', STUDIP.USER_ID);
    store.dispatch('users/loadById', {id: STUDIP.USER_ID});
    store.dispatch('loadUsersBookmarks', STUDIP.USER_ID);
    store.dispatch('setHttpClient', httpClient);
    store.dispatch('coursewareContext', {
        id: entry_id,
        type: entry_type,
    });

    const app = createApp({
        render: () => h(ContentBookmarkApp),
    });
    app.mount(element);

    return app;
}

export default mountApp;