Jonathan Druart
87e717406b
There is a couple of wrong things from the previous patch: * There is a warning in the console Firefox [Vue Router warn]: Unexpected error when starting the router: TypeError: document.getElementById(...) is null Chrome [Vue Router warn]: Unexpected error when starting the router: TypeError: Cannot read properties of null (reading 'click') That's because the tabs are not initialized yet, and so the tab is not correctly selected when the app is loaded. * "Search titles" is selected when on packages, and "Search packages" is selected when on titles This patch remove the warning and fix the second problem. However the tab is still wrong when the app is loaded. Will see later if that can be fixed, but it's not trivial at first glance. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import { createApp } from "vue";
|
|
import { createWebHistory, createRouter } from "vue-router";
|
|
import { createPinia } from "pinia";
|
|
|
|
import { library } from "@fortawesome/fontawesome-svg-core";
|
|
import {
|
|
faPlus,
|
|
faMinus,
|
|
faPencil,
|
|
faTrash,
|
|
faSpinner,
|
|
} from "@fortawesome/free-solid-svg-icons";
|
|
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
|
|
import vSelect from "vue-select";
|
|
|
|
library.add(faPlus, faMinus, faPencil, faTrash, faSpinner);
|
|
|
|
import App from "../components/ERM/Main.vue";
|
|
|
|
import { routes } from "../routes/erm";
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
linkExactActiveClass: "current",
|
|
routes,
|
|
});
|
|
|
|
import { useMainStore } from "../stores/main";
|
|
import { useVendorStore } from "../stores/vendors";
|
|
import { useAVStore } from "../stores/authorised_values";
|
|
|
|
const pinia = createPinia();
|
|
|
|
const i18n = {
|
|
install: (app, options) => {
|
|
app.config.globalProperties.$__ = (key) => {
|
|
return window["__"](key);
|
|
};
|
|
},
|
|
};
|
|
|
|
const app = createApp(App);
|
|
|
|
const rootComponent = app
|
|
.use(i18n)
|
|
.use(pinia)
|
|
.use(router)
|
|
.component("font-awesome-icon", FontAwesomeIcon)
|
|
.component("v-select", vSelect);
|
|
|
|
app.config.unwrapInjectedRef = true;
|
|
app.provide("vendorStore", useVendorStore(pinia));
|
|
const mainStore = useMainStore(pinia);
|
|
app.provide("mainStore", mainStore);
|
|
app.provide("AVStore", useAVStore(pinia));
|
|
|
|
app.mount("#erm");
|
|
|
|
const { removeMessages } = mainStore;
|
|
router.beforeEach((to, from) => {
|
|
removeMessages(); // This will actually flag the messages as displayed already
|
|
});
|
|
router.afterEach((to, from) => {
|
|
let tab_id = 1; // Agreements
|
|
if (to.path.match(/\/erm\/eholdings\/local\/packages/)) {
|
|
tab_id = 2;
|
|
} else if (to.path.match(/\/erm\/eholdings\/local\/titles/)) {
|
|
tab_id = 3;
|
|
}
|
|
let node = document.getElementById("ui-id-" + tab_id);
|
|
if (node) {
|
|
node.click();
|
|
}
|
|
});
|