From a823c420bcbb57f79f5be986c40a9383ff55b244 Mon Sep 17 00:00:00 2001 From: FlayInAHook Date: Wed, 16 Dec 2020 00:42:03 +0100 Subject: [PATCH] implemented a working user management --- .../admin-data-page.component.html | 14 ++--- .../admin-data-page.component.ts | 55 +++---------------- .../dialogs/delete/delete.dialog.component.ts | 22 +++++++- .../dialogs/delete/delete.dialog.css | 11 ++++ .../dialogs/delete/delete.dialog.html | 23 ++++++++ src/app/models/user.ts | 1 + src/app/pages/profile/profile.component.html | 4 +- src/app/pages/profile/profile.component.scss | 9 +++ src/app/services/user.service.ts | 12 ++-- 9 files changed, 90 insertions(+), 61 deletions(-) diff --git a/src/app/components/admin-data-page/admin-data-page.component.html b/src/app/components/admin-data-page/admin-data-page.component.html index 09f5f1e..66621e0 100644 --- a/src/app/components/admin-data-page/admin-data-page.component.html +++ b/src/app/components/admin-data-page/admin-data-page.component.html @@ -1,18 +1,18 @@ - - Admin Table - - Reload data: + +

Benutzerverwaltung - +

+ +
- +
@@ -52,7 +52,7 @@ edit - diff --git a/src/app/components/admin-data-page/admin-data-page.component.ts b/src/app/components/admin-data-page/admin-data-page.component.ts index 7286367..99cc29b 100644 --- a/src/app/components/admin-data-page/admin-data-page.component.ts +++ b/src/app/components/admin-data-page/admin-data-page.component.ts @@ -68,6 +68,7 @@ export class AdminDataPageComponent implements OnInit { let newUserData = this.userService.getDialogData(); console.log("add user data"); + newUserData.password = ''; newUserData.rolesString = newUserData.roles.join(', '); this.dataSource.data.push(newUserData); @@ -90,6 +91,7 @@ export class AdminDataPageComponent implements OnInit { let newUserData = this.userService.getDialogData(); const foundIndex = this.dataSource.data.findIndex(x => x.id === newUserData.id); + newUserData.password = ''; newUserData.rolesString = newUserData.roles.join(', '); this.dataSource.data[foundIndex] = newUserData; @@ -99,16 +101,15 @@ export class AdminDataPageComponent implements OnInit { } - deleteItem(i: number, id: number, title: string, state: string, url: string) { - this.index = i; - this.id = id; + deleteItem(user : User) { const dialogRef = this.dialog.open(DeleteDialogComponent, { - data: {id: id, title: title, state: state, url: url} + data: user }); dialogRef.afterClosed().subscribe(result => { if (result === 1) { - const foundIndex = this.dataSource.data.findIndex(x => x.id === this.id); + let newUserData = this.userService.getDialogData(); + const foundIndex = this.dataSource.data.findIndex(x => x.id === newUserData.id); this.dataSource.data.splice(foundIndex, 1); this.refreshTable(); @@ -133,6 +134,7 @@ export class AdminDataPageComponent implements OnInit { roles.push(role.name); } user.rolesString = roles.join(', '); + user.email_old = user.email; } this.dataSource = new MatTableDataSource(data); }); @@ -161,48 +163,7 @@ export class AdminDataPageComponent implements OnInit { this.dataSource.sort = this.sort; } - - - private load() { - console.log("trying to load"); - - } - - delete(user: User) { - let ownPassword : string; - this.userService.deleteUser(user.email, ownPassword) - .pipe(first()) - .subscribe( - data => { - //this.loadAllObjects(); - }, - error => { - - } - ); - } - - edit(user: User) { - let ownPassword : string; - this.userService.updateUser(user, ownPassword) - .pipe(first()) - .subscribe( - data => { - //this.loadAllObjects(); - }, - error => { - - } - ); - } - - /*findActualData(_id: string) { - for (let data of this.actualData) { - if (data._id === _id) { - return data; - } - } - } */ + } diff --git a/src/app/components/dialogs/delete/delete.dialog.component.ts b/src/app/components/dialogs/delete/delete.dialog.component.ts index 97aadfa..ec250ce 100644 --- a/src/app/components/dialogs/delete/delete.dialog.component.ts +++ b/src/app/components/dialogs/delete/delete.dialog.component.ts @@ -1,6 +1,9 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import {Component, Inject} from '@angular/core'; import {UserService} from '../../../services/user.service'; +import { SnackBarService } from 'src/app/services/snackbar.service'; +import { first } from 'rxjs/operators'; +import { FormControl } from '@angular/forms'; @Component({ @@ -11,14 +14,29 @@ import {UserService} from '../../../services/user.service'; export class DeleteDialogComponent { constructor(public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: any, public userService: UserService) { } + @Inject(MAT_DIALOG_DATA) public data: any, public userService: UserService, + public snackbarService: SnackBarService) { } + hide = true; + selectedRoles: FormControl = new FormControl(); + + onNoClick(): void { this.dialogRef.close(); } confirmDelete(): void { - this.userService.deleteUser(this.data.mail, this.data.ownPassword); + console.log("delete data " + JSON.stringify(this.data)); + this.userService.deleteUser(this.data).pipe(first()) + .subscribe( + data => { + this.snackbarService.openSnackBar("Erfolgreich: " + data.success); + //this.loadAllObjects(); + }, + error => { + this.snackbarService.openSnackBar(error, "Ok", true); + } + ); //this.dataService.deleteIssue(this.data.id); } } diff --git a/src/app/components/dialogs/delete/delete.dialog.css b/src/app/components/dialogs/delete/delete.dialog.css index 93a17ae..6ce1688 100644 --- a/src/app/components/dialogs/delete/delete.dialog.css +++ b/src/app/components/dialogs/delete/delete.dialog.css @@ -6,3 +6,14 @@ .container > * { width: 100%; } + + +.form { + display: flex; + padding-top: 6px; +} + +.mat-form-field { + font-size: 16px; + flex-grow: 1; +} \ No newline at end of file diff --git a/src/app/components/dialogs/delete/delete.dialog.html b/src/app/components/dialogs/delete/delete.dialog.html index 18f2d1f..804716d 100644 --- a/src/app/components/dialogs/delete/delete.dialog.html +++ b/src/app/components/dialogs/delete/delete.dialog.html @@ -7,6 +7,29 @@

+ +
+ + Admin Passwort + + + +
+
diff --git a/src/app/models/user.ts b/src/app/models/user.ts index 5ea2f87..3a73b42 100644 --- a/src/app/models/user.ts +++ b/src/app/models/user.ts @@ -8,6 +8,7 @@ export class User { id: number; name: string; email: string; + email_old?: string; own_password: string; password: string; roles: Role[]; diff --git a/src/app/pages/profile/profile.component.html b/src/app/pages/profile/profile.component.html index 191c9c2..29e627e 100644 --- a/src/app/pages/profile/profile.component.html +++ b/src/app/pages/profile/profile.component.html @@ -89,7 +89,9 @@ - +
+ +