Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactor module installation #284

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ new Vue({

useAuthStore().init();

modules.install(store, router);
modules.install(store);
5 changes: 1 addition & 4 deletions src/modules/AbstractModule.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { AllRoles } from "@/models/User";
import { useAuthStore } from "@/stores/auth";
import VueRouter from "vue-router";
import { Module, Store } from "vuex";

export default abstract class AbstractModule {
protected authStore = useAuthStore();
protected store: Store<any>;
protected router: VueRouter;

constructor(store: Store<any>, router: VueRouter) {
constructor(store: Store<any>) {
this.store = store;
this.router = router;

this.install();
}
Expand Down
2 changes: 0 additions & 2 deletions src/modules/callout/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Acl } from "@/acl";
import AbstractModule from "../AbstractModule";
import route from "./router";
import store from "./store";

export default class CalloutModule extends AbstractModule {
install() {
this.router.addRoute(route);
this.installStore(store);
}

Expand Down
2 changes: 0 additions & 2 deletions src/modules/clothes/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Acl } from "@/acl";
import AbstractModule from "../AbstractModule";
import routes from "./router";
import store from "./store";

export default class ClothesModule extends AbstractModule {
install() {
routes.forEach((route) => this.router.addRoute(route));
this.installStore(store);
}

Expand Down
5 changes: 1 addition & 4 deletions src/modules/exporter/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { Acl } from "@/acl";
import AbstractModule from "../AbstractModule";
import routes from "./router";

export default class ExporterModule extends AbstractModule {
install() {
routes.forEach((route) => this.router.addRoute(route));
}
install() {}

isAuthorized() {
return this.hasAnyRole(Acl.datenexport);
Expand Down
31 changes: 23 additions & 8 deletions src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,44 @@ import VehiclesModule from "./vehicles";
import CalloutModule from "./callout";
import ClothesModule from "./clothes";
import { Store } from "vuex";
import VueRouter from "vue-router";
import AbstractModule from "./AbstractModule";
import PeopleModule from "./people";
import ExporterModule from "./exporter";
import AppSettingsModule from "./appSettings";
import vehicleRoutes from "./vehicles/router";
import calloutRoute from "./callout/router";
import clothesRoutes from "./clothes/router";
import peopleRoutes from "./people/router";
import exporterRoutes from "./exporter/router";
import { AppRouteConfig } from "@/models/Route";

class AppModules {
modules: AbstractModule[] = [];
store?: Store<any>;

install(store: Store<any>, router: VueRouter) {
install(store: Store<any>) {
this.store = store;

this.modules = [
new AppSettingsModule(store, router),
new VehiclesModule(store, router),
new CalloutModule(store, router),
new ClothesModule(store, router),
new PeopleModule(store, router),
new ExporterModule(store, router),
new AppSettingsModule(store),
new VehiclesModule(store),
new CalloutModule(store),
new ClothesModule(store),
new PeopleModule(store),
new ExporterModule(store),
];
}

getRoutes(): Array<AppRouteConfig> {
return [
vehicleRoutes,
[calloutRoute],
clothesRoutes,
peopleRoutes,
exporterRoutes,
].flat();
}

onLogin() {
this.modules.forEach((module) => module.onLogin());
}
Expand Down
2 changes: 0 additions & 2 deletions src/modules/people/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Acl } from "@/acl";
import AbstractModule from "../AbstractModule";
import routes from "./router";
import store from "./store";

export default class PeopleModule extends AbstractModule {
install() {
routes.forEach((route) => this.router.addRoute(route));
this.installStore(store);
}

Expand Down
2 changes: 0 additions & 2 deletions src/modules/vehicles/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Acl } from "@/acl";
import AbstractModule from "../AbstractModule";
import store from "./store";
import routes from "./router";

export default class VehiclesModule extends AbstractModule {
link = null;

install() {
routes.forEach((route) => this.router.addRoute(route));
this.installStore(store);
}

Expand Down
3 changes: 2 additions & 1 deletion src/router.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import VueRouter from "vue-router";
import { checkAuth } from "./utils/routerAuth";
import { AppRouteConfig } from "./models/Route";
import modules from "./modules";

const routes: Array<AppRouteConfig> = [
{
Expand Down Expand Up @@ -54,7 +55,7 @@ const routes: Array<AppRouteConfig> = [
];

const router = new VueRouter({
routes,
routes: routes.concat(modules.getRoutes()),
});

router.beforeEach((to, from, next) => checkAuth(to, from, next));
Expand Down
Loading