aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/bootstrap/vue.js
blob: c6816a21a380dbebe7148a7f22dd8ba811d3982d (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
/**
 * The following block of code is used to automatically register your
 * Vue components. It will recursively scan this directory for the Vue
 * components and automatically register them with their "basename".
 *
 * Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
 */
STUDIP.ready(() => {
    $('[data-vue-app]').each(function () {
        if ($(this).is('[data-vue-app-created]')) {
            return;
        }

        const config = Object.assign({}, {
            id: false,
            components: [],
            store: false
        }, $(this).data().vueApp);

        let data = {};
        if (config.id && window.STUDIP.AppData && window.STUDIP.AppData[config.id] !== undefined) {
            data = window.STUDIP.AppData[config.id];
        }

        let components = {};
        config.components.forEach(component => {
            components[component] = () => import(`../../../vue/components/${component}.vue`);
        });

        STUDIP.Vue.load().then(async ({createApp, store}) => {
            if (config.store) {
                const storeConfig = await import(`../../../vue/store/${config.store}.js`);

                store.registerModule(config.id, storeConfig.default, {root: true});

                Object.keys(data).forEach(command => {
                    store.commit(`${config.id}/${command}`, data[command]);
                });
            }

            createApp({components, data}).$mount(this);
        });

        $(this).attr('data-vue-app-created', '');
    });
});