Skip to content

Commit

Permalink
handle async loading dashbaord #3103
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinx13 committed Sep 30, 2024
1 parent 70a0056 commit faf0b66
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 20 deletions.
70 changes: 51 additions & 19 deletions assets/scripts/vue/components/dashboard/TheHistoAppDashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,21 @@ export default defineComponent({
isLoadingRefresh: false
}
},
created () {
async created () {
if (initElements !== null) {
this.sharedProps.ajaxurlSettings = initElements.dataset.ajaxurlSettings
this.sharedProps.ajaxurlKpi = initElements.dataset.ajaxurlKpi
this.sharedProps.ajaxurlPartners = initElements.dataset.ajaxurlPartners
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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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++
Expand Down Expand Up @@ -240,6 +248,30 @@ export default defineComponent({
handleChangeTerritoire () {
this.isLoadingRefresh = true
requests.initKPI(this.handleInitKPI)
},
initSettingsWithPromise (): Promise<void> {
return new Promise((resolve, reject) => {
requests.initSettings((response: any) => {
try {
this.handleInitSettings(response)
resolve()
} catch (error) {
reject(error)
}
})
})
},
initKPIWithPromise (): Promise<void> {
return new Promise((resolve, reject) => {
requests.initKPI((response: any) => {
try {
this.handleInitKPI(response)
resolve()
} catch (error) {
reject(error)
}
})
})
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion assets/scripts/vue/components/dashboard/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit faf0b66

Please sign in to comment.