Skip to content
Snippets Groups Projects
Commit 2aa22a3d authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

convert stock images to new vue bootstrapping mechanism, fixes #4305

Closes #4305

Merge request studip/studip!3185
parent ff0220b3
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,10 @@ class StockImagesController extends AuthenticatedController ...@@ -22,6 +22,10 @@ class StockImagesController extends AuthenticatedController
*/ */
public function index_action(): void public function index_action(): void
{ {
$this->render_vue_app(
Studip\VueApp::create('stock-images/Page')
->withPlugin('StockImagesPlugin', 'stock-images')
);
} }
/** /**
......
...@@ -38,6 +38,7 @@ final class VueApp implements Stringable ...@@ -38,6 +38,7 @@ final class VueApp implements Stringable
return new self($base_component); return new self($base_component);
} }
private array $plugins = [];
private array $props = []; private array $props = [];
private array $stores = []; private array $stores = [];
private array $storeData = []; private array $storeData = [];
...@@ -129,6 +130,27 @@ final class VueApp implements Stringable ...@@ -129,6 +130,27 @@ final class VueApp implements Stringable
return $this->storeData; return $this->storeData;
} }
/**
* Adds a plugin
*
* You may specify a different filename for the plugin.
*/
public function withPlugin(string $plugin, string $filename = null): VueApp
{
$clone = clone $this;
$clone->plugins[$plugin] = $filename ?? $plugin;
return $clone;
}
/**
* Returns all plugins
*/
public function getPlugins(): array
{
return $this->plugins;
}
/** /**
* Returns the template to render the vue app * Returns the template to render the vue app
*/ */
...@@ -142,6 +164,10 @@ final class VueApp implements Stringable ...@@ -142,6 +164,10 @@ final class VueApp implements Stringable
$data['stores'] = $this->stores; $data['stores'] = $this->stores;
} }
if (count($this->plugins) > 0) {
$data['plugins'] = $this->plugins;
}
$template = $GLOBALS['template_factory']->open('vue-app.php'); $template = $GLOBALS['template_factory']->open('vue-app.php');
$template->baseComponent = basename($this->base_component); $template->baseComponent = basename($this->base_component);
$template->attributes = ['data-vue-app' => json_encode($data)]; $template->attributes = ['data-vue-app' => json_encode($data)];
......
import StockImages from '../lib/stock-images.js';
STUDIP.domReady(() => {
StockImages.init();
});
...@@ -3,6 +3,7 @@ STUDIP.ready(() => { ...@@ -3,6 +3,7 @@ STUDIP.ready(() => {
const config = Object.assign( const config = Object.assign(
{ {
components: [], components: [],
plugins: {},
stores: {} stores: {}
}, },
JSON.parse(node.dataset.vueApp) JSON.parse(node.dataset.vueApp)
...@@ -37,7 +38,7 @@ STUDIP.ready(() => { ...@@ -37,7 +38,7 @@ STUDIP.ready(() => {
}; };
}); });
STUDIP.Vue.load().then(async ({createApp, store}) => { STUDIP.Vue.load().then(async ({createApp, store, Vue}) => {
for (const [index, name] of Object.entries(config.stores)) { for (const [index, name] of Object.entries(config.stores)) {
import(`../../../vue/store/${name}.js`).then(storeConfig => { import(`../../../vue/store/${name}.js`).then(storeConfig => {
store.registerModule(index, storeConfig.default); store.registerModule(index, storeConfig.default);
...@@ -53,6 +54,13 @@ STUDIP.ready(() => { ...@@ -53,6 +54,13 @@ STUDIP.ready(() => {
} }
}); });
} }
for (const [plugin, filename] of Object.entries(config.plugins)) {
import(`../../../vue/plugins/${filename}.js`)
.then((temp) => Vue.use(temp[plugin], { store }));
}
createApp({ createApp({
components, components,
store, store,
......
...@@ -77,7 +77,6 @@ import "./bootstrap/scroll_to_top.js" ...@@ -77,7 +77,6 @@ import "./bootstrap/scroll_to_top.js"
import "./bootstrap/admin-courses.js" import "./bootstrap/admin-courses.js"
import "./bootstrap/oer.js" import "./bootstrap/oer.js"
import "./bootstrap/courseware.js" import "./bootstrap/courseware.js"
import "./bootstrap/stock-images.js"
import "./bootstrap/external_pages.js" import "./bootstrap/external_pages.js"
import "./mvv_course_wizard.js" import "./mvv_course_wizard.js"
......
const StockImages = {
init() {
const stockImagesPage = document.querySelector('div.stock-images');
if (stockImagesPage !== null) {
Promise.all([window.STUDIP.Vue.load(), StockImages.plugin()]).then(
([{ Vue, createApp, store }, StockImagesPlugin]) => {
Vue.use(StockImagesPlugin, { store });
createApp({
el: stockImagesPage,
render: (h) => {
return h(Vue.component('StockImagesPage'), { props: {} });
},
});
}
);
}
},
plugin() {
return import('@/vue/plugins/stock-images.js').then(({ StockImagesPlugin }) => StockImagesPlugin);
},
};
export default StockImages;
<template> <template>
<div> <div>
<StudipPagination <StudipPagination
:style="{ visibility: totalItems <= perPage ? 'hidden' : 'visible' }" v-show="totalItems > perPage"
:currentOffset="offset" :currentOffset="offset"
:totalItems="totalItems" :totalItems="totalItems"
:itemsPerPage="perPage" :itemsPerPage="perPage"
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
/> />
<slot></slot> <slot></slot>
<StudipPagination <StudipPagination
:style="{ visibility: totalItems <= perPage ? 'hidden' : 'visible' }" v-show="totalItems > perPage"
:currentOffset="offset" :currentOffset="offset"
:totalItems="totalItems" :totalItems="totalItems"
:itemsPerPage="perPage" :itemsPerPage="perPage"
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<button <button
v-if="showSearchResults" v-if="showSearchResults"
@click.prevent="onReset" @click.prevent="onReset"
class="reset-search" class="reset-search as-link"
:title="$gettext('Suchformular zurücksetzen')" :title="$gettext('Suchformular zurücksetzen')"
> >
<studip-icon shape="decline" :size="20" role="presentation" alt="" /> <studip-icon shape="decline" :size="20" role="presentation" alt="" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment