Replaced console logging with logger utility across the frontend, removed unused code, and centralized session management in useActiveUserStore.

This commit is contained in:
Jan 2025-11-18 18:39:34 +01:00
parent 47aab96dfa
commit a381ac3299
18 changed files with 88 additions and 92 deletions

View file

@ -1,6 +1,7 @@
import logger from "@/logger.js";
import {useNotificationStore} from "@/store/notification.js";
import {config} from "@/config";
import {useActiveUserStore} from "@/store/activeuser.js";
const getCsrfToken = () => {
const value = `; ${document.cookie}`;
@ -11,43 +12,6 @@ const getCsrfToken = () => {
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 params = {
@ -159,7 +123,9 @@ function handleErrorResponse(data, requestingStore, request) {
}
const executeRequest = async (requestingStore, request) => {
trackActivity();
useActiveUserStore().trackActivity();
const response = await fetch(request.url, request.params
).catch(e => {
@ -231,4 +197,4 @@ const executeRequest = async (requestingStore, request) => {
}
export default performRequest;
export {performUpload, performDownload, getCsrfToken, startSessionRefresh, stopSessionRefresh};
export {performUpload, performDownload, getCsrfToken};

View file

@ -66,10 +66,6 @@ export default {
},
},
created() {
console.log(this.error);
console.log(this.error.trace);
},
methods: {
highlightClasses(traceItem) {
return traceItem.className?.includes('de.avatic.lcc') ? 'highlight-trace-item' : 'trace-item';

View file

@ -99,7 +99,6 @@ export default {
if (!this.disableButton) {
const app = await this.appsStore.addApp(this.appName, this.selectedGroups);
this.stage1 = false;
console.log("app in add app", app);
this.clientSecret = app.client_secret;
this.clientId = app.client_id;
}

View file

@ -75,7 +75,6 @@ export default {
const idx = this.user.groups?.indexOf(groupName);
console.log("update selected", idx, checked, groupName, this.user.groups);
if (checked) {
if ((idx ?? null) !== null && idx === -1)
@ -83,7 +82,7 @@ export default {
} else {
if ((idx ?? null) !== null && idx !== -1)
this.user.groups.splice(idx);
this.user.groups.splice(idx,1);
}
},

View file

@ -41,16 +41,15 @@
import Checkbox from "@/components/UI/Checkbox.vue";
import {mapStores} from "pinia";
import {usePremiseEditStore} from "@/store/premiseEdit.js";
import {set} from "@vueuse/core";
import {parseNumberFromString} from "@/common.js";
import {useDestinationSingleEditStore} from "@/store/destinationSingleEdit.js";
import logger from "@/logger.js";
export default {
name: "DestinationEditHandlingCost",
components: {Checkbox},
created() {
console.log("Destination:", this.destination)
logger.log("Destination:", this.destination)
},
computed: {
...mapStores(useDestinationSingleEditStore),

View file

@ -81,6 +81,7 @@ import {mapStores} from "pinia";
import {parseNumberFromString} from "@/common.js";
import Tooltip from "@/components/UI/Tooltip.vue";
import {useDestinationSingleEditStore} from "@/store/destinationSingleEdit.js";
import logger from "@/logger.js";
export default {
name: "DestinationEditRoutes",
@ -117,7 +118,7 @@ export default {
}
},
created() {
console.log("Destination:", this.destination)
logger.log("Destination:", this.destination)
},
data() {
return {

View file

@ -2,7 +2,7 @@
<div class="error-modal-container">
<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>
<icon-button icon="x" @click="$emit('close')"></icon-button>
</div>
@ -36,6 +36,12 @@ export default {
required: true
}
},
methods: {
handleTabChange(eventData) {
const {_, tab} = eventData;
this.tabsError.forEach(t => t.props.isSelected = t.title === tab.title);
}
},
computed: {
tabsError() {
const tabs = [];

View file

@ -49,10 +49,6 @@ export default {
},
},
created() {
console.log(this.error);
console.log(this.error.trace);
},
methods: {
highlightClasses(traceItem) {
return traceItem.fullPath?.includes('de.avatic.lcc') ? 'highlight-trace-item' : 'trace-item';

View file

@ -1,38 +1,42 @@
import router from './router.js';
//import store from './store/index.js';
import { setupErrorBuffer } from './store/notification.js'
import {setupErrorBuffer} from './store/notification.js'
import {createApp} from 'vue'
import {createPinia} from 'pinia';
import {startSessionRefresh} from "@/backend.js";
import App from './App.vue'
import {
PhStar,
PhCalculator,
PhSealCheck,
PhCloudArrowUp,
PhX,
PhTrain,
PhTruckTrailer,
PhTruck,
PhArchive,
PhArrowCounterClockwise,
PhBoat,
PhPencilSimple,
PhBug,
PhCalculator,
PhCheck,
PhClipboard,
PhCloudArrowUp,
PhDesktop,
PhDownload,
PhFile,
PhFloppyDisk,
PhHardDrives,
PhLock,
PhLockOpen,
PhWarning,
PhMagnifyingGlass,
PhPencilSimple,
PhPlus,
PhUpload,
PhDownload,
PhSealCheck,
PhShuffle,
PhStack,
PhStar,
PhTrain,
PhTrash,
PhArchive,
PhFloppyDisk,
PhArrowCounterClockwise,
PhCheck, PhBug, PhShuffle, PhStack, PhFile, PhFilePlus, PhDownloadSimple, PhMonitor, PhCpu, PhFileJs, PhFileCloud,
PhCloudX, PhDesktop, PhHardDrives, PhClipboard
PhTruck,
PhTruckTrailer,
PhUpload,
PhWarning,
PhX
} from "@phosphor-icons/vue";
import {setupSessionRefresh} from "@/store/activeuser.js";
const app = createApp(App);
@ -75,6 +79,6 @@ app.use(router);
setupErrorBuffer()
startSessionRefresh();
setupSessionRefresh();
app.mount('#app');

View file

@ -169,8 +169,6 @@ export default {
async handleMultiselectAction(action) {
this.selectedStatus = await this.premiseStore.resolveStatus();
console.log("status: ", this.selectedStatus)
if (action === "delete") {
if (0 === this.selectedStatus.draft.length) {

View file

@ -121,7 +121,7 @@ export default {
},
methods: {
handleTabChange(eventData) {
const {index, tab} = eventData;
const {_, tab} = eventData;
this.tabsConfig.forEach(t => t.props.isSelected = t.title === tab.title);
}
}

View file

@ -18,6 +18,7 @@ import TabContainer from "@/components/UI/TabContainer.vue";
import {markRaw} from "vue";
import CalculationDumpList from "@/components/layout/dev/CalculationDumpList.vue";
import DevUserControl from "@/components/layout/dev/DevUserControl.vue";
import logger from "@/logger.js";
export default {
name: "DevPage",
@ -47,10 +48,9 @@ export default {
methods: {
handleTabChange(eventData) {
console.log("handleTabChange")
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);

View file

@ -74,7 +74,6 @@ export default {
methods: {
async fetchData(query) {
console.log("fetchData")
await this.errorLogStore.setQuery(query);
this.pagination = this.errorLogStore.getPagination;
return this.errorLogStore.getErrors;
@ -83,7 +82,6 @@ export default {
return buildDate(date, true);
},
showDetails(error) {
console.log("click")
this.error = error;
this.showModal = true;
}

View file

@ -1,12 +1,15 @@
import {defineStore} from 'pinia'
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', {
state: () => {
return {
user: null,
lastActivity: Date.now(),
sessionRefreshInterval: null
}
},
getters: {
@ -63,6 +66,29 @@ export const useActiveUserStore = defineStore('activeUser', {
},
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() {
if (this.user === null)
await this.load();
@ -72,4 +98,16 @@ export const useActiveUserStore = defineStore('activeUser', {
this.user = resp.data;
}
}
});
});
export function setupSessionRefresh() {
useActiveUserStore().setupSessionRefresh();
}
// const stopSessionRefresh = () => {
// useActiveUserStore().stopSessionRefresh
// if (sessionRefreshInterval) {
// clearInterval(sessionRefreshInterval);
// }
// }

View file

@ -2,6 +2,7 @@ import {defineStore} from 'pinia'
import {config} from '@/config'
import {useNotificationStore} from "@/store/notification.js";
import performRequest from "@/backend.js";
import logger from "@/logger.js";
export const useAssistantStore = defineStore('assistant', {
@ -89,7 +90,7 @@ export const useAssistantStore = defineStore('assistant', {
const url = `${config.backendUrl}/calculation/search/`;
console.log(`${url} with query ${query}`);
logger.log(`${url} with query ${query}`);
try {
const resp = await performRequest(this, 'GET', `${config.backendUrl}/calculation/search/?search=${encodeURIComponent(query)}`, null, true);

View file

@ -53,8 +53,6 @@ export const useContainerRateStore = defineStore('containerRate', {
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'))};
console.log(this.pagination)
this.loading = false;
}

View file

@ -50,7 +50,6 @@ export const useErrorLogStore = defineStore('errorLog', {
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'))};
console.log(this.pagination)
this.loading = false;

View file

@ -36,8 +36,6 @@ export const usePropertiesStore = defineStore('properties', {
async setProperty(property) {
if(this.properties === null) return;
console.log(property)
const prop = this.properties.find(p => p.external_mapping_id === property.id);
if((prop ?? null) === null) return;