[FIX] correct the front on some back error

This commit is contained in:
Edouard DUPIN 2024-05-09 00:18:47 +02:00
parent ef304bc1fe
commit 7a4c5c2625
3 changed files with 52 additions and 35 deletions

View File

@ -21,29 +21,38 @@
<td>{{user.login}}</td> <td>{{user.login}}</td>
<td>{{user.email}}</td> <td>{{user.email}}</td>
<td> <td>
@if(adminLogin !== user.login && user.adminState === undefined) { @if(user.adminState) {
<app-async-status-component
[value]="user.adminState" />
}
@else if(adminLogin !== user.login) {
<app-checkbox <app-checkbox
[value]="user.admin" [value]="user.admin"
(changeValue)="onSetAdmin($event, user)"/> (changeValue)="onSetAdmin($event, user)"/>
} }
{{adminLogin === user.login?"yes":""}} @else {
@if(user.adminState !== undefined) { <app-checkbox
<app-async-status-component [isDisable]="true"
[value]="user.adminState" /> [value]="true"/>
} }
</td> </td>
<td> <td>
@if(adminLogin !== user.login && user.blockedState === undefined) { @if(user.blockedState) {
<app-async-status-component [value]="user.blockedState"/>
}
@else if(adminLogin !== user.login) {
<app-checkbox <app-checkbox
[value]="user.blocked" [value]="user.blocked"
(changeValue)="onSetBlocked($event, user)"/> (changeValue)="onSetBlocked($event, user)"/>
} }
@if(user.blockedState !== undefined) { @else {
<app-async-status-component [value]="user.blockedState"/> <app-checkbox
[isDisable]="true"
[value]="false"/>
} }
</td> </td>
<td>{{user.avatar?"yes":"---"}}</td> <td>{{user.avatar?"yes":"---"}}</td>
<td>{{formatTimestamp(user.lastConnection)}}</td> <td>{{formatIso(user.lastConnection)}}</td>
</tr> </tr>
} }
</table> </table>

View File

@ -6,9 +6,15 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { SessionService, AsyncActionState, createPasswordState, createLoginState, checkEmailValidity } from '@kangaroo-and-rabbit/kar-cw'; import { SessionService, AsyncActionState, createPasswordState, createLoginState, checkEmailValidity } from '@kangaroo-and-rabbit/kar-cw';
import { UserAuthGet } from 'back-api';
import { AdminUserService } from 'base/service'; import { AdminUserService } from 'base/service';
interface UserAccountEdit extends UserAuthGet {
adminState?: AsyncActionState;
blockedState?: AsyncActionState;
}
@Component({ @Component({
selector: 'app-settings', selector: 'app-settings',
templateUrl: './manage-accounts.html', templateUrl: './manage-accounts.html',
@ -16,7 +22,7 @@ import { AdminUserService } from 'base/service';
changeDetection: ChangeDetectionStrategy.Default, changeDetection: ChangeDetectionStrategy.Default,
}) })
export class ManageAccountsScene implements OnInit { export class ManageAccountsScene implements OnInit {
users: any = []; users: UserAccountEdit[] = [];
adminLogin: string = ''; adminLogin: string = '';
constructor( constructor(
@ -30,16 +36,16 @@ export class ManageAccountsScene implements OnInit {
const self = this; const self = this;
this.adminUserService this.adminUserService
.getUsers() .getUsers()
.then((response: any) => { .then((response: UserAuthGet[]) => {
console.log(`??? get full response: ${JSON.stringify(response, null, 4)}`); console.log(`??? get full response: ${JSON.stringify(response, null, 4)}`);
self.users = response; self.users = response;
}) })
.catch((error: any) => { .catch((error) => {
console.log(`??? get ERROR response: ${JSON.stringify(error, null, 4)}`); console.log(`??? get ERROR response: ${JSON.stringify(error, null, 4)}`);
}); });
} }
onSetAdmin(value: boolean, user: any) { onSetAdmin(value: boolean, user: UserAccountEdit) {
user.admin = value; user.admin = value;
console.log(`onSetAdmin: ${value} on ${user.login}`); console.log(`onSetAdmin: ${value} on ${user.login}`);
user.adminState = AsyncActionState.LOADING; user.adminState = AsyncActionState.LOADING;
@ -53,7 +59,7 @@ export class ManageAccountsScene implements OnInit {
setTimeout(() => { setTimeout(() => {
user.adminState = undefined; user.adminState = undefined;
self.cdr.detectChanges(); self.cdr.detectChanges();
}, 3000); }, 300);
} }
).catch( ).catch(
@ -61,14 +67,14 @@ export class ManageAccountsScene implements OnInit {
user.adminState = AsyncActionState.FAIL; user.adminState = AsyncActionState.FAIL;
self.cdr.detectChanges(); self.cdr.detectChanges();
setTimeout(() => { setTimeout(() => {
user.adminState = undefined;
user.admin = !value; user.admin = !value;
user.adminState = undefined;
self.cdr.detectChanges(); self.cdr.detectChanges();
}, 3000); }, 3000);
} }
); );
} }
onSetBlocked(value: boolean, user: any) { onSetBlocked(value: boolean, user: UserAccountEdit) {
user.blocked = value; user.blocked = value;
console.log(`onSetBlocked: ${value} on ${user.login}`); console.log(`onSetBlocked: ${value} on ${user.login}`);
user.blockedState = AsyncActionState.LOADING; user.blockedState = AsyncActionState.LOADING;
@ -77,20 +83,22 @@ export class ManageAccountsScene implements OnInit {
this.adminUserService.setBlocked(user.id, value) this.adminUserService.setBlocked(user.id, value)
.then( .then(
() => { () => {
console.log("all is fine ...");
user.blockedState = AsyncActionState.DONE; user.blockedState = AsyncActionState.DONE;
self.cdr.detectChanges(); self.cdr.detectChanges();
setTimeout(() => { setTimeout(() => {
user.blockedState = undefined; user.blockedState = undefined;
self.cdr.detectChanges(); self.cdr.detectChanges();
}, 3000); }, 300);
} }
).catch( ).catch(
(error: any) => { (error: any) => {
console.log(`catch error ... ${JSON.stringify(error, null, 2)}`);
user.blockedState = AsyncActionState.FAIL; user.blockedState = AsyncActionState.FAIL;
user.blocked = !value;
self.cdr.detectChanges(); self.cdr.detectChanges();
setTimeout(() => { setTimeout(() => {
user.blockedState = undefined; user.blockedState = undefined;
user.blocked = !value;
self.cdr.detectChanges(); self.cdr.detectChanges();
}, 3000); }, 3000);
} }
@ -175,23 +183,22 @@ export class ManageAccountsScene implements OnInit {
const self = this; const self = this;
this.adminUserService this.adminUserService
.checkLogin(this.login) .checkLogin(this.login)
.then((isNotUsed: boolean) => { .then((loginExist: boolean) => {
// check if the answer is correct with the question // check if the answer is correct with the question
if (newValue !== self.login) { if (newValue !== self.login) {
return; return;
} }
if (isNotUsed === false) { if (loginExist === false) {
self.loginState = true;
} else {
// the login exist ... ==> it is found... // the login exist ... ==> it is found...
self.loginState = 'Login already used ...'; self.loginState = 'Login already used ...';
self.updateButtonVisibility();
} else {
self.loginState = true;
self.updateButtonVisibility();
} }
self.updateButtonVisibility();
}) })
.catch((error: number) => { .catch((error: number) => {
console.log(`Status ${error}`); console.log(`Status ${error}`);
self.loginState = 'ErrorOccured in fetching data ...'; self.loginState = 'Error Occurred in fetching data ...';
self.updateButtonVisibility(); self.updateButtonVisibility();
}); });
} }
@ -201,31 +208,29 @@ export class ManageAccountsScene implements OnInit {
checkEmail(newValue: string): void { checkEmail(newValue: string): void {
this.email = newValue; this.email = newValue;
if (!checkEmailValidity(this.email)) { if (!checkEmailValidity(this.email)) {
this.emailState = "E-mail is not well formated."; this.emailState = "E-mail is not well formatted.";
this.updateButtonVisibility(); this.updateButtonVisibility();
return; return;
} }
this.emailState = "Checking email ..."; this.emailState = "Checking email ...";
const self = this; const self = this;
this.adminUserService.checkEMail(this.email).then( this.adminUserService.checkEMail(this.email).then(
(isNotUsed: boolean) => { (emailExist: boolean) => {
// check if the answer is correct with the question // check if the answer is correct with the question
if (newValue !== self.email) { if (newValue !== self.email) {
return; return;
} }
if (isNotUsed === false) { if (emailExist === false) {
self.emailState = true;
} else {
// the email exist ... ==> it is found... // the email exist ... ==> it is found...
self.emailState = 'email already used ...'; self.emailState = 'email already used ...';
self.updateButtonVisibility();
} else {
self.emailState = true;
self.updateButtonVisibility();
return;
} }
self.updateButtonVisibility();
}) })
.catch((error: number) => { .catch((error: number) => {
console.log(`Status ${error}`); console.log(`Status ${error}`);
self.emailState = 'ErrorOccured in fetching data ...'; self.emailState = 'Error Occurred in fetching data ...';
self.updateButtonVisibility(); self.updateButtonVisibility();
} }
); );
@ -236,4 +241,7 @@ export class ManageAccountsScene implements OnInit {
//return new Date(unix_timestamp).toUTCString(); //return new Date(unix_timestamp).toUTCString();
//return new Date(unix_timestamp).toLocaleString(); //return new Date(unix_timestamp).toLocaleString();
} }
formatIso(isoTS: string): string {
return isoTS.replace("T", " ").replace("Z", " GMT").replace(".000", "");
}
} }

View File

@ -6,7 +6,7 @@
<name>{{data.title}}</name> <name>{{data.title}}</name>
<description>{{data.description}}</description> <description>{{data.description}}</description>
<body> <body>
@if(data.values===undefined) { @if(!data.values) {
<spiner/> <spiner/>
} }
@else { @else {