mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-24 07:17:55 +01:00
feat: ✨ Aggiunto supporto per il bootstrap di un modulo
This commit is contained in:
parent
5098f06f07
commit
27644cc3a3
@ -7,6 +7,7 @@ import redaxios from 'redaxios';
|
||||
import {registerSW} from 'virtual:pwa-register';
|
||||
|
||||
import {type Page} from './Components';
|
||||
import {OpenSTAManager} from './types/modules';
|
||||
import {
|
||||
__ as translator,
|
||||
showSnackbar
|
||||
@ -19,6 +20,22 @@ globalThis.__ = translator;
|
||||
|
||||
InertiaProgress.init();
|
||||
|
||||
const importedModules: Record<string, {default: any, bootstrap?: Function}> = {};
|
||||
|
||||
// @ts-ignore
|
||||
const modules = globalThis.modules as OpenSTAManager.Modules;
|
||||
for (const [name, module] of Object.entries(modules)) {
|
||||
if (module.hasBootstrap) {
|
||||
// eslint-disable-next-line no-await-in-loop,@typescript-eslint/no-unsafe-assignment
|
||||
importedModules[name] = await import(
|
||||
/* @vite-ignore */
|
||||
`${importPath}/vendor/${name}/index.js`
|
||||
);
|
||||
|
||||
importedModules[name].bootstrap?.();
|
||||
}
|
||||
}
|
||||
|
||||
await createInertiaApp({
|
||||
title: ((title) => `${title} - OpenSTAManager`),
|
||||
resolve: async (name: string) => {
|
||||
@ -35,10 +52,12 @@ await createInertiaApp({
|
||||
const [modulePath, page] = split;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const osmModule: {default: unknown, [key: string]: unknown} = await import(
|
||||
/* @vite-ignore */
|
||||
`${importPath}/vendor/${modulePath}/index.js`
|
||||
);
|
||||
const osmModule: {default: unknown, [key: string]: unknown} = modulePath in importedModules
|
||||
? importedModules[modulePath]
|
||||
: await import(
|
||||
/* @vite-ignore */
|
||||
`${importPath}/vendor/${modulePath}/index.js`
|
||||
);
|
||||
|
||||
return osmModule[page];
|
||||
},
|
||||
|
4
resources/js/globals.d.ts
vendored
4
resources/js/globals.d.ts
vendored
@ -5,11 +5,13 @@ import type cash from 'cash-dom';
|
||||
import type Mithril from 'mithril';
|
||||
import type router from 'ziggy-js';
|
||||
|
||||
import {OpenSTAManager} from './types/modules';
|
||||
import type {__ as translator} from './utils';
|
||||
|
||||
declare global {
|
||||
let importPath: string;
|
||||
const translations: {[key: string]: string};
|
||||
let translations: Record<string, string>;
|
||||
let modules: Record<string, OpenSTAManager.Modules>;
|
||||
const route: typeof router;
|
||||
|
||||
var $: typeof cash;
|
||||
|
9
resources/js/types/modules.d.ts
vendored
Normal file
9
resources/js/types/modules.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
import {MaterialIcons} from '../types';
|
||||
|
||||
declare module OpenSTAManager {
|
||||
export type Modules = Record<string, Module>;
|
||||
export interface Module {
|
||||
hasBootstrap?: boolean;
|
||||
icon: MaterialIcons;
|
||||
}
|
||||
}
|
@ -33,16 +33,7 @@
|
||||
|
||||
@include('layouts.top-app-bar-menus')
|
||||
|
||||
<script>
|
||||
window.importPath = '{{Str::contains(vite_asset(''), config('vite.dev_url')) ? config('vite.dev_url') : '.'}}';
|
||||
window.modules = @js($modules);
|
||||
</script>
|
||||
|
||||
@routes
|
||||
|
||||
@vite('app')
|
||||
|
||||
@include('layouts.translations')
|
||||
@include('layouts.footer')
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
@ -3,11 +3,6 @@
|
||||
@include('layouts.head')
|
||||
<body>
|
||||
@inertia
|
||||
|
||||
@routes
|
||||
|
||||
@vite('app')
|
||||
|
||||
@include('layouts.translations')
|
||||
@include('layouts.footer')
|
||||
</body>
|
||||
</html>
|
||||
|
14
resources/views/layouts/footer.blade.php
Normal file
14
resources/views/layouts/footer.blade.php
Normal file
@ -0,0 +1,14 @@
|
||||
@php
|
||||
/** @var string $translations */
|
||||
$translations = cache('translations_' . app()->getLocale());
|
||||
|
||||
/** @var \Illuminate\Support\Collection $modules */
|
||||
@endphp
|
||||
<script>
|
||||
window.importPath = '{{Str::contains(vite_asset(''), config('vite.dev_url')) ? config('vite.dev_url') : '.'}}';
|
||||
window.modules = @js($modules->pluck('modules')->collapse()->all());
|
||||
window.translations = @js($translations);
|
||||
</script>
|
||||
|
||||
@routes
|
||||
@vite('app')
|
@ -1,7 +0,0 @@
|
||||
@php
|
||||
/** @var string $translations */
|
||||
$translations = cache('translations_' . app()->getLocale());
|
||||
@endphp
|
||||
<script>
|
||||
window.translations = @js($translations);
|
||||
</script>
|
Loading…
x
Reference in New Issue
Block a user