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

View File

@ -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", "");
}
}

View File

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