From faf0b6645d10e81acfda0da5062a7e4affbf8ad0 Mon Sep 17 00:00:00 2001 From: Saidi Date: Mon, 30 Sep 2024 13:04:53 +0200 Subject: [PATCH 1/2] handle async loading dashbaord #3103 --- .../dashboard/TheHistoAppDashboard.vue | 70 ++++++++++++++----- .../vue/components/dashboard/requests.ts | 2 +- 2 files changed, 52 insertions(+), 20 deletions(-) diff --git a/assets/scripts/vue/components/dashboard/TheHistoAppDashboard.vue b/assets/scripts/vue/components/dashboard/TheHistoAppDashboard.vue index 5408a28b3..31d914c9d 100644 --- a/assets/scripts/vue/components/dashboard/TheHistoAppDashboard.vue +++ b/assets/scripts/vue/components/dashboard/TheHistoAppDashboard.vue @@ -87,7 +87,7 @@ export default defineComponent({ isLoadingRefresh: false } }, - created () { + async created () { if (initElements !== null) { this.sharedProps.ajaxurlSettings = initElements.dataset.ajaxurlSettings this.sharedProps.ajaxurlKpi = initElements.dataset.ajaxurlKpi @@ -95,8 +95,13 @@ export default defineComponent({ this.sharedProps.ajaxurlSignalementsNosuivi = initElements.dataset.ajaxurlSignalementsNosuivi this.sharedProps.ajaxurlSignalementsPerTerritoire = initElements.dataset.ajaxurlSignalementsPerTerritoire this.sharedProps.ajaxurlConnectionsEsabora = initElements.dataset.ajaxurlConnectionsEsabora - requests.initSettings(this.handleInitSettings) - requests.initKPI(this.handleInitKPI) + try { + await this.initSettingsWithPromise() + await this.initKPIWithPromise() + } catch (error) { + console.error('Error during initialization', error) + this.isErrorInit = true + } } else { this.isErrorInit = true } @@ -127,24 +132,25 @@ export default defineComponent({ } else { this.isLoadingInit = false this.isLoadingRefresh = false - this.processResponseInit(requestResponse) - if (this.sharedState.user.isAdmin || this.sharedState.user.isResponsableTerritoire) { - this.countTablesToLoad++ - requests.initAffectationPartner(this.handleAffectationPartner) - } - if (this.sharedState.user.isResponsableTerritoire) { - this.countTablesToLoad++ - requests.initSignalementsNoSuivi(this.handleSignalementsNoSuivi) - } - if (this.sharedState.user.isAdmin) { - this.countTablesToLoad++ - requests.initSignalementsPerTerritoire(this.handleSignalementsPerTerritoire) - this.countTablesToLoad++ - requests.initEsaboraEvents(this.handleEsaboraEvents) - } + this.processResponseInit(requestResponse, () => { + if (this.sharedState.user.isAdmin || this.sharedState.user.isResponsableTerritoire) { + this.countTablesToLoad++ + requests.initAffectationPartner(this.handleAffectationPartner) + } + if (this.sharedState.user.isResponsableTerritoire) { + this.countTablesToLoad++ + requests.initSignalementsNoSuivi(this.handleSignalementsNoSuivi) + } + if (this.sharedState.user.isAdmin) { + this.countTablesToLoad++ + requests.initSignalementsPerTerritoire(this.handleSignalementsPerTerritoire) + this.countTablesToLoad++ + requests.initEsaboraEvents(this.handleEsaboraEvents) + } + }) } }, - processResponseInit (requestResponse: any) { + processResponseInit (requestResponse: any, callback: () => void) { this.sharedState.signalements.count = requestResponse.data.countSignalement.active this.sharedState.signalements.percent = requestResponse.data.countSignalement.percentage.active this.sharedState.closedSignalements.count = requestResponse.data.countSignalement.closed @@ -182,6 +188,8 @@ export default defineComponent({ this.sharedState.nonDecenceSignalements.linkActive = dataWidget.cardSignalementsEnCoursNonDecence?.link this.sharedState.noSuiviAfter3Relances.count = dataWidget.cardNoSuiviAfter3Relances?.count this.sharedState.noSuiviAfter3Relances.link = dataWidget.cardNoSuiviAfter3Relances?.link + + if (callback) callback() }, handleAffectationPartner (requestResponse: any) { this.countTablesLoaded++ @@ -240,6 +248,30 @@ export default defineComponent({ handleChangeTerritoire () { this.isLoadingRefresh = true requests.initKPI(this.handleInitKPI) + }, + initSettingsWithPromise (): Promise { + return new Promise((resolve, reject) => { + requests.initSettings((response: any) => { + try { + this.handleInitSettings(response) + resolve() + } catch (error) { + reject(error) + } + }) + }) + }, + initKPIWithPromise (): Promise { + return new Promise((resolve, reject) => { + requests.initKPI((response: any) => { + try { + this.handleInitKPI(response) + resolve() + } catch (error) { + reject(error) + } + }) + }) } } }) diff --git a/assets/scripts/vue/components/dashboard/requests.ts b/assets/scripts/vue/components/dashboard/requests.ts index 8d9d9d4ee..966021f37 100644 --- a/assets/scripts/vue/components/dashboard/requests.ts +++ b/assets/scripts/vue/components/dashboard/requests.ts @@ -5,7 +5,7 @@ import * as Sentry from '@sentry/browser' export const requests = { doRequest (ajaxUrl: string, functionReturn: Function) { axios - .get(ajaxUrl, { timeout: 15000 }) + .get(ajaxUrl, { timeout: 30000 }) .then(response => { const responseData = response.data functionReturn(responseData) From 81abeed3eee24e1e14ff3753bac53a7c3bd9991d Mon Sep 17 00:00:00 2001 From: Saidi Date: Mon, 30 Sep 2024 13:46:17 +0200 Subject: [PATCH 2/2] update config eslint #3103 --- .../scripts/vue/components/dashboard/TheHistoAppDashboard.vue | 4 +++- package.json | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/assets/scripts/vue/components/dashboard/TheHistoAppDashboard.vue b/assets/scripts/vue/components/dashboard/TheHistoAppDashboard.vue index 31d914c9d..0c07160a0 100644 --- a/assets/scripts/vue/components/dashboard/TheHistoAppDashboard.vue +++ b/assets/scripts/vue/components/dashboard/TheHistoAppDashboard.vue @@ -189,7 +189,9 @@ export default defineComponent({ this.sharedState.noSuiviAfter3Relances.count = dataWidget.cardNoSuiviAfter3Relances?.count this.sharedState.noSuiviAfter3Relances.link = dataWidget.cardNoSuiviAfter3Relances?.link - if (callback) callback() + if (callback) { + callback() + } }, handleAffectationPartner (requestResponse: any) { this.countTablesLoaded++ diff --git a/package.json b/package.json index ea6ae2dbf..051e5627c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "dev": "encore dev", "watch": "encore dev --watch", "build": "encore production --progress", - "es-vue-fix": "node_modules/.bin/eslint --config=.eslintrc.js assets/vue --fix" + "es-vue-fix": "node_modules/.bin/eslint --config=.eslintrc.js assets/scripts/vue --fix" }, "engines": { "node": "18.14.2"