From 68ddd53b5a39fc9027f88a4e0efa94b593442301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lise=20Rubio?= Date: Tue, 20 Feb 2024 18:30:49 +0100 Subject: [PATCH] :sparkles: Display & regenerate module & environment token value in UI --- .../src/lib/components/atoms/A_button.svelte | 8 +++-- .../src/lib/domain/ModuleEnvironmentToken.ts | 3 ++ .../services/ModuleEnvironmentTokenService.ts | 17 +++++++++ .../[project]/modules/[module]/+page.svelte | 35 +++++++++++++++++-- 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 modules/ui/src/lib/domain/ModuleEnvironmentToken.ts create mode 100644 modules/ui/src/lib/services/ModuleEnvironmentTokenService.ts diff --git a/modules/ui/src/lib/components/atoms/A_button.svelte b/modules/ui/src/lib/components/atoms/A_button.svelte index 80833830..3e083a8f 100644 --- a/modules/ui/src/lib/components/atoms/A_button.svelte +++ b/modules/ui/src/lib/components/atoms/A_button.svelte @@ -1,6 +1,8 @@ - + diff --git a/modules/ui/src/lib/domain/ModuleEnvironmentToken.ts b/modules/ui/src/lib/domain/ModuleEnvironmentToken.ts new file mode 100644 index 00000000..0d8b3d8a --- /dev/null +++ b/modules/ui/src/lib/domain/ModuleEnvironmentToken.ts @@ -0,0 +1,3 @@ +export type ModuleEnvironmentToken = { + tokenValue: string +} \ No newline at end of file diff --git a/modules/ui/src/lib/services/ModuleEnvironmentTokenService.ts b/modules/ui/src/lib/services/ModuleEnvironmentTokenService.ts new file mode 100644 index 00000000..3ae76361 --- /dev/null +++ b/modules/ui/src/lib/services/ModuleEnvironmentTokenService.ts @@ -0,0 +1,17 @@ +import type {ModuleEnvironmentToken} from '$lib/domain/ModuleEnvironmentToken'; +import {Http} from '$lib/services/utils/HttpService'; + +export class ModuleEnvironmentTokenService { + private static baseUrl = '/api/v1/moduleEnvironmentTokens'; + + public static byModuleAndEnvironment = async (moduleRef: string, environmentRef: string): Promise => { + return Http.get(`${ModuleEnvironmentTokenService.baseUrl}/byModuleAndEnvironmentRef/${moduleRef}/${environmentRef}`); + } + + public static regenerateToken = async (moduleRef: string, environmentRef: string): Promise => { + return Http.post(`${ModuleEnvironmentTokenService.baseUrl}/regenerateToken`, { + moduleRef: moduleRef, + environmentRef: environmentRef + }) + } +} \ No newline at end of file diff --git a/modules/ui/src/routes/projects/[project]/modules/[module]/+page.svelte b/modules/ui/src/routes/projects/[project]/modules/[module]/+page.svelte index bd26b1c3..31e56e0c 100644 --- a/modules/ui/src/routes/projects/[project]/modules/[module]/+page.svelte +++ b/modules/ui/src/routes/projects/[project]/modules/[module]/+page.svelte @@ -6,11 +6,15 @@ import {ExecutionMock} from "$lib/mocks/ExecutionMock"; import O_matrixScriptEnv from "$lib/components/organisms/O_matrix/O_matrixScriptEnv.svelte"; import M_error from "$lib/components/molecules/M_error.svelte"; + import {ModuleEnvironmentTokenService} from '$lib/services/ModuleEnvironmentTokenService'; + import type {ModuleEnvironmentToken} from '$lib/domain/ModuleEnvironmentToken'; + import A_button from '$lib/components/atoms/A_button.svelte'; let project let env let modulePromise let scriptEnvMatrix + let moduleEnvironmentTokenPromise: Promise $: if($page.params?.project) { ProjectService.byId($page.params.project).then(foundProject => { @@ -18,19 +22,36 @@ }); } - $: if($page.url.searchParams?.has('env')) { - EnvService.byId($page.url.searchParams?.get('env')).then(foundEnv => { + const environmentRef = $page.url.searchParams?.get('env'); + $: if(environmentRef) { + EnvService.byId(environmentRef).then(foundEnv => { env = foundEnv }); } - $: if($page.params?.module) { + const moduleRef = $page.params?.module; + $: if(moduleRef) { modulePromise = ModuleService.byId($page.params.module); } + $: if(environmentRef && moduleRef) { + moduleEnvironmentTokenPromise = ModuleEnvironmentTokenService.byModuleAndEnvironment( + moduleRef, + environmentRef + ) + } + $: if (project) { scriptEnvMatrix = ExecutionMock.scriptEnvMatrixByProject(project.id) } + + export function regenerateToken() { + console.log('pouet'); + moduleEnvironmentTokenPromise = ModuleEnvironmentTokenService.regenerateToken( + moduleRef, + environmentRef + ) + } {#await modulePromise} @@ -38,6 +59,14 @@ {:then module} Module {module.name} du projet {#if project} {project.name} {/if} {#if env} sur l'environnement {env.name}{/if} + {#await moduleEnvironmentTokenPromise} + Chargement du token en cours... + {:then moduleEnvironmentToken} + Token : {moduleEnvironmentToken.tokenValue} + + + {/await} +
Editer