From 7a4c5c2625e72b9b9097396c0d536521ddb6fd33 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 9 May 2024 00:18:47 +0200 Subject: [PATCH] [FIX] correct the front on some back error --- .../manage-accounts/manage-accounts.html | 27 ++++++--- .../scene/manage-accounts/manage-accounts.ts | 58 +++++++++++-------- front/src/base/scene/settings/settings.html | 2 +- 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/front/src/base/scene/manage-accounts/manage-accounts.html b/front/src/base/scene/manage-accounts/manage-accounts.html index b19d143..5a746e9 100644 --- a/front/src/base/scene/manage-accounts/manage-accounts.html +++ b/front/src/base/scene/manage-accounts/manage-accounts.html @@ -21,29 +21,38 @@ {{user.login}} {{user.email}} - @if(adminLogin !== user.login && user.adminState === undefined) { + @if(user.adminState) { + + } + @else if(adminLogin !== user.login) { } - {{adminLogin === user.login?"yes":""}} - @if(user.adminState !== undefined) { - + @else { + } - @if(adminLogin !== user.login && user.blockedState === undefined) { + @if(user.blockedState) { + + } + @else if(adminLogin !== user.login) { } - @if(user.blockedState !== undefined) { - + @else { + } {{user.avatar?"yes":"---"}} - {{formatTimestamp(user.lastConnection)}} + {{formatIso(user.lastConnection)}} } diff --git a/front/src/base/scene/manage-accounts/manage-accounts.ts b/front/src/base/scene/manage-accounts/manage-accounts.ts index 142f10a..25a632b 100644 --- a/front/src/base/scene/manage-accounts/manage-accounts.ts +++ b/front/src/base/scene/manage-accounts/manage-accounts.ts @@ -6,9 +6,15 @@ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; import { SessionService, AsyncActionState, createPasswordState, createLoginState, checkEmailValidity } from '@kangaroo-and-rabbit/kar-cw'; +import { UserAuthGet } from 'back-api'; import { AdminUserService } from 'base/service'; +interface UserAccountEdit extends UserAuthGet { + adminState?: AsyncActionState; + blockedState?: AsyncActionState; +} + @Component({ selector: 'app-settings', templateUrl: './manage-accounts.html', @@ -16,7 +22,7 @@ import { AdminUserService } from 'base/service'; changeDetection: ChangeDetectionStrategy.Default, }) export class ManageAccountsScene implements OnInit { - users: any = []; + users: UserAccountEdit[] = []; adminLogin: string = ''; constructor( @@ -30,16 +36,16 @@ export class ManageAccountsScene implements OnInit { const self = this; this.adminUserService .getUsers() - .then((response: any) => { + .then((response: UserAuthGet[]) => { console.log(`??? get full response: ${JSON.stringify(response, null, 4)}`); self.users = response; }) - .catch((error: any) => { + .catch((error) => { console.log(`??? get ERROR response: ${JSON.stringify(error, null, 4)}`); }); } - onSetAdmin(value: boolean, user: any) { + onSetAdmin(value: boolean, user: UserAccountEdit) { user.admin = value; console.log(`onSetAdmin: ${value} on ${user.login}`); user.adminState = AsyncActionState.LOADING; @@ -53,7 +59,7 @@ export class ManageAccountsScene implements OnInit { setTimeout(() => { user.adminState = undefined; self.cdr.detectChanges(); - }, 3000); + }, 300); } ).catch( @@ -61,14 +67,14 @@ export class ManageAccountsScene implements OnInit { user.adminState = AsyncActionState.FAIL; self.cdr.detectChanges(); setTimeout(() => { - user.adminState = undefined; user.admin = !value; + user.adminState = undefined; self.cdr.detectChanges(); }, 3000); } ); } - onSetBlocked(value: boolean, user: any) { + onSetBlocked(value: boolean, user: UserAccountEdit) { user.blocked = value; console.log(`onSetBlocked: ${value} on ${user.login}`); user.blockedState = AsyncActionState.LOADING; @@ -77,20 +83,22 @@ export class ManageAccountsScene implements OnInit { this.adminUserService.setBlocked(user.id, value) .then( () => { + console.log("all is fine ..."); user.blockedState = AsyncActionState.DONE; self.cdr.detectChanges(); setTimeout(() => { user.blockedState = undefined; self.cdr.detectChanges(); - }, 3000); + }, 300); } ).catch( (error: any) => { + console.log(`catch error ... ${JSON.stringify(error, null, 2)}`); user.blockedState = AsyncActionState.FAIL; + user.blocked = !value; self.cdr.detectChanges(); setTimeout(() => { user.blockedState = undefined; - user.blocked = !value; self.cdr.detectChanges(); }, 3000); } @@ -175,23 +183,22 @@ export class ManageAccountsScene implements OnInit { const self = this; this.adminUserService .checkLogin(this.login) - .then((isNotUsed: boolean) => { + .then((loginExist: boolean) => { // check if the answer is correct with the question if (newValue !== self.login) { return; } - if (isNotUsed === false) { + if (loginExist === false) { + self.loginState = true; + } else { // the login exist ... ==> it is found... self.loginState = 'Login already used ...'; - self.updateButtonVisibility(); - } else { - self.loginState = true; - self.updateButtonVisibility(); } + self.updateButtonVisibility(); }) .catch((error: number) => { console.log(`Status ${error}`); - self.loginState = 'ErrorOccured in fetching data ...'; + self.loginState = 'Error Occurred in fetching data ...'; self.updateButtonVisibility(); }); } @@ -201,31 +208,29 @@ export class ManageAccountsScene implements OnInit { checkEmail(newValue: string): void { this.email = newValue; if (!checkEmailValidity(this.email)) { - this.emailState = "E-mail is not well formated."; + this.emailState = "E-mail is not well formatted."; this.updateButtonVisibility(); return; } this.emailState = "Checking email ..."; const self = this; this.adminUserService.checkEMail(this.email).then( - (isNotUsed: boolean) => { + (emailExist: boolean) => { // check if the answer is correct with the question if (newValue !== self.email) { return; } - if (isNotUsed === false) { + if (emailExist === false) { + self.emailState = true; + } else { // the email exist ... ==> it is found... self.emailState = 'email already used ...'; - self.updateButtonVisibility(); - } else { - self.emailState = true; - self.updateButtonVisibility(); - return; } + self.updateButtonVisibility(); }) .catch((error: number) => { console.log(`Status ${error}`); - self.emailState = 'ErrorOccured in fetching data ...'; + self.emailState = 'Error Occurred in fetching data ...'; self.updateButtonVisibility(); } ); @@ -236,4 +241,7 @@ export class ManageAccountsScene implements OnInit { //return new Date(unix_timestamp).toUTCString(); //return new Date(unix_timestamp).toLocaleString(); } + formatIso(isoTS: string): string { + return isoTS.replace("T", " ").replace("Z", " GMT").replace(".000", ""); + } } diff --git a/front/src/base/scene/settings/settings.html b/front/src/base/scene/settings/settings.html index 860e10c..c10d931 100644 --- a/front/src/base/scene/settings/settings.html +++ b/front/src/base/scene/settings/settings.html @@ -6,7 +6,7 @@ {{data.title}} {{data.description}} - @if(data.values===undefined) { + @if(!data.values) { } @else {