Skip to content

Commit

Permalink
Add the possiblity to load custom javascript on startup (#6457)
Browse files Browse the repository at this point in the history
Signed-off-by: Giovanni Ferrari <giovanni.ferrari@soft.it>
  • Loading branch information
quinarygio committed May 16, 2024
1 parent f4a2e50 commit 4dc7529
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ services:
volumes:
- "./ui-config:/usr/share/nginx/html/config"
- "./nginx.conf:/etc/nginx/conf.d/default.conf"
- "./externalJs:/usr/share/nginx/html/externalJs"
- "../../src/test/externalWebAppExample:/usr/share/nginx/html/external/appExample"
cards-external-diffusion:
container_name: cards-external-diffusion
Expand Down
1 change: 1 addition & 0 deletions config/docker/externalJs/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Custom js example executed');
3 changes: 2 additions & 1 deletion config/docker/ui-config/web-ui.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,6 @@
]
}
}
}
},
"customJsToLoad": ["http://localhost:2002/externalJs/example.js", "http://localhost:2002/externalJs/missing.js"]
}
12 changes: 12 additions & 0 deletions ui/main/src/app/business/application-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class ApplicationLoader {
this.initServices();
loadBuildInTemplates();
this.initOpfabAPI();
await this.loadCustomScripts();
await this.waitForStreamInitDone();
this.goToEntryPage();
this.loadingInProgress = false;
Expand Down Expand Up @@ -306,4 +307,15 @@ export class ApplicationLoader {
RouterService.navigateTo(defaultEntryPage);
}
}

private async loadCustomScripts() {
const customScripts = ConfigService.getConfigValue('customJsToLoad');
if (customScripts) {
for (const script of customScripts) {
await import(/* webpackIgnore: true */ script).catch((err) =>
logger.error('Error loading custom script ' + script + ' : ' + err)
);
}
}
}
}

0 comments on commit 4dc7529

Please sign in to comment.