Replaced console logging with logger utility across the frontend, removed unused code, and centralized session management in useActiveUserStore.
This commit is contained in:
parent
47aab96dfa
commit
a381ac3299
18 changed files with 88 additions and 92 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import logger from "@/logger.js";
|
import logger from "@/logger.js";
|
||||||
import {useNotificationStore} from "@/store/notification.js";
|
import {useNotificationStore} from "@/store/notification.js";
|
||||||
import {config} from "@/config";
|
import {config} from "@/config";
|
||||||
|
import {useActiveUserStore} from "@/store/activeuser.js";
|
||||||
|
|
||||||
const getCsrfToken = () => {
|
const getCsrfToken = () => {
|
||||||
const value = `; ${document.cookie}`;
|
const value = `; ${document.cookie}`;
|
||||||
|
|
@ -11,43 +12,6 @@ const getCsrfToken = () => {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let sessionRefreshInterval = null;
|
|
||||||
let lastActivity = Date.now();
|
|
||||||
|
|
||||||
const refreshSession = async () => {
|
|
||||||
try {
|
|
||||||
await performRequest(null, 'GET', `${config.backendUrl}/error/`, null);
|
|
||||||
logger.log('Session refreshed');
|
|
||||||
} catch (e) {
|
|
||||||
logger.error('Session refresh failed', e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const trackActivity = () => {
|
|
||||||
lastActivity = Date.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
const startSessionRefresh = () => {
|
|
||||||
|
|
||||||
if (sessionRefreshInterval) {
|
|
||||||
clearInterval(sessionRefreshInterval);
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionRefreshInterval = setInterval(async () => {
|
|
||||||
const timeSinceActivity = Date.now() - lastActivity;
|
|
||||||
|
|
||||||
if (timeSinceActivity < (10 * 60 * 1000)) {
|
|
||||||
await refreshSession();
|
|
||||||
}
|
|
||||||
}, 2 * 60 * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
const stopSessionRefresh = () => {
|
|
||||||
if (sessionRefreshInterval) {
|
|
||||||
clearInterval(sessionRefreshInterval);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const performRequest = async (requestingStore, method, url, body, expectResponse = true, expectedException = null) => {
|
const performRequest = async (requestingStore, method, url, body, expectResponse = true, expectedException = null) => {
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
|
|
@ -159,7 +123,9 @@ function handleErrorResponse(data, requestingStore, request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const executeRequest = async (requestingStore, request) => {
|
const executeRequest = async (requestingStore, request) => {
|
||||||
trackActivity();
|
|
||||||
|
useActiveUserStore().trackActivity();
|
||||||
|
|
||||||
|
|
||||||
const response = await fetch(request.url, request.params
|
const response = await fetch(request.url, request.params
|
||||||
).catch(e => {
|
).catch(e => {
|
||||||
|
|
@ -231,4 +197,4 @@ const executeRequest = async (requestingStore, request) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default performRequest;
|
export default performRequest;
|
||||||
export {performUpload, performDownload, getCsrfToken, startSessionRefresh, stopSessionRefresh};
|
export {performUpload, performDownload, getCsrfToken};
|
||||||
|
|
|
||||||
|
|
@ -66,10 +66,6 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
created() {
|
|
||||||
console.log(this.error);
|
|
||||||
console.log(this.error.trace);
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
highlightClasses(traceItem) {
|
highlightClasses(traceItem) {
|
||||||
return traceItem.className?.includes('de.avatic.lcc') ? 'highlight-trace-item' : 'trace-item';
|
return traceItem.className?.includes('de.avatic.lcc') ? 'highlight-trace-item' : 'trace-item';
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,6 @@ export default {
|
||||||
if (!this.disableButton) {
|
if (!this.disableButton) {
|
||||||
const app = await this.appsStore.addApp(this.appName, this.selectedGroups);
|
const app = await this.appsStore.addApp(this.appName, this.selectedGroups);
|
||||||
this.stage1 = false;
|
this.stage1 = false;
|
||||||
console.log("app in add app", app);
|
|
||||||
this.clientSecret = app.client_secret;
|
this.clientSecret = app.client_secret;
|
||||||
this.clientId = app.client_id;
|
this.clientId = app.client_id;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,6 @@ export default {
|
||||||
|
|
||||||
|
|
||||||
const idx = this.user.groups?.indexOf(groupName);
|
const idx = this.user.groups?.indexOf(groupName);
|
||||||
console.log("update selected", idx, checked, groupName, this.user.groups);
|
|
||||||
|
|
||||||
if (checked) {
|
if (checked) {
|
||||||
if ((idx ?? null) !== null && idx === -1)
|
if ((idx ?? null) !== null && idx === -1)
|
||||||
|
|
@ -83,7 +82,7 @@ export default {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if ((idx ?? null) !== null && idx !== -1)
|
if ((idx ?? null) !== null && idx !== -1)
|
||||||
this.user.groups.splice(idx);
|
this.user.groups.splice(idx,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -41,16 +41,15 @@
|
||||||
|
|
||||||
import Checkbox from "@/components/UI/Checkbox.vue";
|
import Checkbox from "@/components/UI/Checkbox.vue";
|
||||||
import {mapStores} from "pinia";
|
import {mapStores} from "pinia";
|
||||||
import {usePremiseEditStore} from "@/store/premiseEdit.js";
|
|
||||||
import {set} from "@vueuse/core";
|
|
||||||
import {parseNumberFromString} from "@/common.js";
|
import {parseNumberFromString} from "@/common.js";
|
||||||
import {useDestinationSingleEditStore} from "@/store/destinationSingleEdit.js";
|
import {useDestinationSingleEditStore} from "@/store/destinationSingleEdit.js";
|
||||||
|
import logger from "@/logger.js";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "DestinationEditHandlingCost",
|
name: "DestinationEditHandlingCost",
|
||||||
components: {Checkbox},
|
components: {Checkbox},
|
||||||
created() {
|
created() {
|
||||||
console.log("Destination:", this.destination)
|
logger.log("Destination:", this.destination)
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapStores(useDestinationSingleEditStore),
|
...mapStores(useDestinationSingleEditStore),
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ import {mapStores} from "pinia";
|
||||||
import {parseNumberFromString} from "@/common.js";
|
import {parseNumberFromString} from "@/common.js";
|
||||||
import Tooltip from "@/components/UI/Tooltip.vue";
|
import Tooltip from "@/components/UI/Tooltip.vue";
|
||||||
import {useDestinationSingleEditStore} from "@/store/destinationSingleEdit.js";
|
import {useDestinationSingleEditStore} from "@/store/destinationSingleEdit.js";
|
||||||
|
import logger from "@/logger.js";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "DestinationEditRoutes",
|
name: "DestinationEditRoutes",
|
||||||
|
|
@ -117,7 +118,7 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
console.log("Destination:", this.destination)
|
logger.log("Destination:", this.destination)
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<div class="error-modal-container">
|
<div class="error-modal-container">
|
||||||
<div class="trace-view-header">
|
<div class="trace-view-header">
|
||||||
<h3 class="sub-header"> Error Details <br><span class="trace-view-message">{{ message }}</span>
|
<h3 class="sub-header"> Error Details
|
||||||
</h3>
|
</h3>
|
||||||
<icon-button icon="x" @click="$emit('close')"></icon-button>
|
<icon-button icon="x" @click="$emit('close')"></icon-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -36,6 +36,12 @@ export default {
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
handleTabChange(eventData) {
|
||||||
|
const {_, tab} = eventData;
|
||||||
|
this.tabsError.forEach(t => t.props.isSelected = t.title === tab.title);
|
||||||
|
}
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
tabsError() {
|
tabsError() {
|
||||||
const tabs = [];
|
const tabs = [];
|
||||||
|
|
|
||||||
|
|
@ -49,10 +49,6 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
created() {
|
|
||||||
console.log(this.error);
|
|
||||||
console.log(this.error.trace);
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
highlightClasses(traceItem) {
|
highlightClasses(traceItem) {
|
||||||
return traceItem.fullPath?.includes('de.avatic.lcc') ? 'highlight-trace-item' : 'trace-item';
|
return traceItem.fullPath?.includes('de.avatic.lcc') ? 'highlight-trace-item' : 'trace-item';
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,42 @@
|
||||||
import router from './router.js';
|
import router from './router.js';
|
||||||
//import store from './store/index.js';
|
//import store from './store/index.js';
|
||||||
import { setupErrorBuffer } from './store/notification.js'
|
import {setupErrorBuffer} from './store/notification.js'
|
||||||
import {createApp} from 'vue'
|
import {createApp} from 'vue'
|
||||||
import {createPinia} from 'pinia';
|
import {createPinia} from 'pinia';
|
||||||
import {startSessionRefresh} from "@/backend.js";
|
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
PhStar,
|
PhArchive,
|
||||||
PhCalculator,
|
PhArrowCounterClockwise,
|
||||||
PhSealCheck,
|
|
||||||
PhCloudArrowUp,
|
|
||||||
PhX,
|
|
||||||
PhTrain,
|
|
||||||
PhTruckTrailer,
|
|
||||||
PhTruck,
|
|
||||||
PhBoat,
|
PhBoat,
|
||||||
PhPencilSimple,
|
PhBug,
|
||||||
|
PhCalculator,
|
||||||
|
PhCheck,
|
||||||
|
PhClipboard,
|
||||||
|
PhCloudArrowUp,
|
||||||
|
PhDesktop,
|
||||||
|
PhDownload,
|
||||||
|
PhFile,
|
||||||
|
PhFloppyDisk,
|
||||||
|
PhHardDrives,
|
||||||
PhLock,
|
PhLock,
|
||||||
PhLockOpen,
|
PhLockOpen,
|
||||||
PhWarning,
|
|
||||||
PhMagnifyingGlass,
|
PhMagnifyingGlass,
|
||||||
|
PhPencilSimple,
|
||||||
PhPlus,
|
PhPlus,
|
||||||
PhUpload,
|
PhSealCheck,
|
||||||
PhDownload,
|
PhShuffle,
|
||||||
|
PhStack,
|
||||||
|
PhStar,
|
||||||
|
PhTrain,
|
||||||
PhTrash,
|
PhTrash,
|
||||||
PhArchive,
|
PhTruck,
|
||||||
PhFloppyDisk,
|
PhTruckTrailer,
|
||||||
PhArrowCounterClockwise,
|
PhUpload,
|
||||||
PhCheck, PhBug, PhShuffle, PhStack, PhFile, PhFilePlus, PhDownloadSimple, PhMonitor, PhCpu, PhFileJs, PhFileCloud,
|
PhWarning,
|
||||||
PhCloudX, PhDesktop, PhHardDrives, PhClipboard
|
PhX
|
||||||
} from "@phosphor-icons/vue";
|
} from "@phosphor-icons/vue";
|
||||||
|
import {setupSessionRefresh} from "@/store/activeuser.js";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
|
@ -75,6 +79,6 @@ app.use(router);
|
||||||
|
|
||||||
|
|
||||||
setupErrorBuffer()
|
setupErrorBuffer()
|
||||||
startSessionRefresh();
|
setupSessionRefresh();
|
||||||
|
|
||||||
app.mount('#app');
|
app.mount('#app');
|
||||||
|
|
|
||||||
|
|
@ -169,8 +169,6 @@ export default {
|
||||||
async handleMultiselectAction(action) {
|
async handleMultiselectAction(action) {
|
||||||
this.selectedStatus = await this.premiseStore.resolveStatus();
|
this.selectedStatus = await this.premiseStore.resolveStatus();
|
||||||
|
|
||||||
console.log("status: ", this.selectedStatus)
|
|
||||||
|
|
||||||
if (action === "delete") {
|
if (action === "delete") {
|
||||||
|
|
||||||
if (0 === this.selectedStatus.draft.length) {
|
if (0 === this.selectedStatus.draft.length) {
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleTabChange(eventData) {
|
handleTabChange(eventData) {
|
||||||
const {index, tab} = eventData;
|
const {_, tab} = eventData;
|
||||||
this.tabsConfig.forEach(t => t.props.isSelected = t.title === tab.title);
|
this.tabsConfig.forEach(t => t.props.isSelected = t.title === tab.title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import TabContainer from "@/components/UI/TabContainer.vue";
|
||||||
import {markRaw} from "vue";
|
import {markRaw} from "vue";
|
||||||
import CalculationDumpList from "@/components/layout/dev/CalculationDumpList.vue";
|
import CalculationDumpList from "@/components/layout/dev/CalculationDumpList.vue";
|
||||||
import DevUserControl from "@/components/layout/dev/DevUserControl.vue";
|
import DevUserControl from "@/components/layout/dev/DevUserControl.vue";
|
||||||
|
import logger from "@/logger.js";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "DevPage",
|
name: "DevPage",
|
||||||
|
|
@ -47,10 +48,9 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
handleTabChange(eventData) {
|
handleTabChange(eventData) {
|
||||||
|
|
||||||
console.log("handleTabChange")
|
|
||||||
|
|
||||||
const { index, tab } = eventData;
|
const { index, tab } = eventData;
|
||||||
console.log(`Tab ${index} activated:`, tab.title);
|
logger.log(`Tab ${index} activated:`, tab.title);
|
||||||
|
|
||||||
this.tabsConfig.forEach(t => t.props.isSelected = t.title === tab.title);
|
this.tabsConfig.forEach(t => t.props.isSelected = t.title === tab.title);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,6 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
async fetchData(query) {
|
async fetchData(query) {
|
||||||
console.log("fetchData")
|
|
||||||
await this.errorLogStore.setQuery(query);
|
await this.errorLogStore.setQuery(query);
|
||||||
this.pagination = this.errorLogStore.getPagination;
|
this.pagination = this.errorLogStore.getPagination;
|
||||||
return this.errorLogStore.getErrors;
|
return this.errorLogStore.getErrors;
|
||||||
|
|
@ -83,7 +82,6 @@ export default {
|
||||||
return buildDate(date, true);
|
return buildDate(date, true);
|
||||||
},
|
},
|
||||||
showDetails(error) {
|
showDetails(error) {
|
||||||
console.log("click")
|
|
||||||
this.error = error;
|
this.error = error;
|
||||||
this.showModal = true;
|
this.showModal = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
import {defineStore} from 'pinia'
|
import {defineStore} from 'pinia'
|
||||||
import {config} from '@/config'
|
import {config} from '@/config'
|
||||||
import performRequest from "@/backend.js";
|
import performRequest, {getCsrfToken} from "@/backend.js";
|
||||||
|
import logger from "@/logger.js";
|
||||||
|
|
||||||
|
|
||||||
export const useActiveUserStore = defineStore('activeUser', {
|
export const useActiveUserStore = defineStore('activeUser', {
|
||||||
state: () => {
|
state: () => {
|
||||||
return {
|
return {
|
||||||
user: null,
|
user: null,
|
||||||
|
lastActivity: Date.now(),
|
||||||
|
sessionRefreshInterval: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
|
|
@ -63,6 +66,29 @@ export const useActiveUserStore = defineStore('activeUser', {
|
||||||
|
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
trackActivity() {
|
||||||
|
this.lastActivity = Date.now();
|
||||||
|
},
|
||||||
|
setupSessionRefresh() {
|
||||||
|
if (this.sessionRefreshInterval) {
|
||||||
|
clearInterval(this.sessionRefreshInterval);
|
||||||
|
}
|
||||||
|
this.sessionRefreshInterval = setInterval(async () => {
|
||||||
|
const timeSinceActivity = Date.now() - this.lastActivity;
|
||||||
|
|
||||||
|
if (timeSinceActivity < (10 * 60 * 1000)) {
|
||||||
|
await this.refreshSession();
|
||||||
|
}
|
||||||
|
}, 2 * 60 * 1000);
|
||||||
|
},
|
||||||
|
async refreshSession() {
|
||||||
|
try {
|
||||||
|
await this.load();
|
||||||
|
logger.log('Session refreshed');
|
||||||
|
} catch (e) {
|
||||||
|
logger.error('Session refresh failed', e);
|
||||||
|
}
|
||||||
|
},
|
||||||
async loadIfRequired() {
|
async loadIfRequired() {
|
||||||
if (this.user === null)
|
if (this.user === null)
|
||||||
await this.load();
|
await this.load();
|
||||||
|
|
@ -72,4 +98,16 @@ export const useActiveUserStore = defineStore('activeUser', {
|
||||||
this.user = resp.data;
|
this.user = resp.data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export function setupSessionRefresh() {
|
||||||
|
useActiveUserStore().setupSessionRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
// const stopSessionRefresh = () => {
|
||||||
|
// useActiveUserStore().stopSessionRefresh
|
||||||
|
// if (sessionRefreshInterval) {
|
||||||
|
// clearInterval(sessionRefreshInterval);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {defineStore} from 'pinia'
|
||||||
import {config} from '@/config'
|
import {config} from '@/config'
|
||||||
import {useNotificationStore} from "@/store/notification.js";
|
import {useNotificationStore} from "@/store/notification.js";
|
||||||
import performRequest from "@/backend.js";
|
import performRequest from "@/backend.js";
|
||||||
|
import logger from "@/logger.js";
|
||||||
|
|
||||||
|
|
||||||
export const useAssistantStore = defineStore('assistant', {
|
export const useAssistantStore = defineStore('assistant', {
|
||||||
|
|
@ -89,7 +90,7 @@ export const useAssistantStore = defineStore('assistant', {
|
||||||
|
|
||||||
const url = `${config.backendUrl}/calculation/search/`;
|
const url = `${config.backendUrl}/calculation/search/`;
|
||||||
|
|
||||||
console.log(`${url} with query ${query}`);
|
logger.log(`${url} with query ${query}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await performRequest(this, 'GET', `${config.backendUrl}/calculation/search/?search=${encodeURIComponent(query)}`, null, true);
|
const resp = await performRequest(this, 'GET', `${config.backendUrl}/calculation/search/?search=${encodeURIComponent(query)}`, null, true);
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,6 @@ export const useContainerRateStore = defineStore('containerRate', {
|
||||||
this.rates = data;
|
this.rates = data;
|
||||||
this.pagination = { page: parseInt(headers.get('X-Current-Page')), pageCount: parseInt(headers.get('X-Page-Count')), totalCount: parseInt(headers.get('X-Total-Count'))};
|
this.pagination = { page: parseInt(headers.get('X-Current-Page')), pageCount: parseInt(headers.get('X-Page-Count')), totalCount: parseInt(headers.get('X-Total-Count'))};
|
||||||
|
|
||||||
console.log(this.pagination)
|
|
||||||
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,6 @@ export const useErrorLogStore = defineStore('errorLog', {
|
||||||
this.errors = data;
|
this.errors = data;
|
||||||
this.pagination = { page: parseInt(headers.get('X-Current-Page')), pageCount: parseInt(headers.get('X-Page-Count')), totalCount: parseInt(headers.get('X-Total-Count'))};
|
this.pagination = { page: parseInt(headers.get('X-Current-Page')), pageCount: parseInt(headers.get('X-Page-Count')), totalCount: parseInt(headers.get('X-Total-Count'))};
|
||||||
|
|
||||||
console.log(this.pagination)
|
|
||||||
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,6 @@ export const usePropertiesStore = defineStore('properties', {
|
||||||
async setProperty(property) {
|
async setProperty(property) {
|
||||||
if(this.properties === null) return;
|
if(this.properties === null) return;
|
||||||
|
|
||||||
console.log(property)
|
|
||||||
|
|
||||||
const prop = this.properties.find(p => p.external_mapping_id === property.id);
|
const prop = this.properties.find(p => p.external_mapping_id === property.id);
|
||||||
|
|
||||||
if((prop ?? null) === null) return;
|
if((prop ?? null) === null) return;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue