WIP UserManagement

master
FlayInAHook 4 years ago
parent 229fd46b3d
commit 7b98536b7b

@ -31,7 +31,7 @@ import { MatSortModule } from '@angular/material/sort';
import { MatDialogModule } from '@angular/material/dialog'; import { MatDialogModule } from '@angular/material/dialog';
import { MatAutocompleteModule } from '@angular/material/autocomplete'; import { MatAutocompleteModule } from '@angular/material/autocomplete';
import { MatDatepickerModule } from '@angular/material/datepicker'; import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatNativeDateModule, MAT_DATE_LOCALE } from '@angular/material/core'; import { MatNativeDateModule, MatOptionModule, MAT_DATE_LOCALE } from '@angular/material/core';
import { MatChipsModule } from '@angular/material/chips'; import { MatChipsModule } from '@angular/material/chips';
import { AppRoutingModule } from './app-routing.module'; import { AppRoutingModule } from './app-routing.module';
@ -87,6 +87,7 @@ import { BikeEventsComponent } from './pages/tables/bike-events/bike-events.comp
import { BikeEventTypesComponent } from './pages/tables/bike-event-types/bike-event-types.component'; import { BikeEventTypesComponent } from './pages/tables/bike-event-types/bike-event-types.component';
import { WorkshopTypesComponent } from './pages/tables/workshop-types/workshop-types.component'; import { WorkshopTypesComponent } from './pages/tables/workshop-types/workshop-types.component';
import { FilterRowComponent } from './components/tableComponents/filter-row/filter-row.component'; import { FilterRowComponent } from './components/tableComponents/filter-row/filter-row.component';
import {FormSelectSearchComponent} from './components/from-select-search/form-select-search.component';
import {DeleteDialogComponent} from './components/dialogs/delete/delete.dialog.component'; import {DeleteDialogComponent} from './components/dialogs/delete/delete.dialog.component';
import {AddDialogComponent} from './components/dialogs/add/add.dialog.component'; import {AddDialogComponent} from './components/dialogs/add/add.dialog.component';
import {EditDialogComponent} from './components/dialogs/edit/edit.dialog.component'; import {EditDialogComponent} from './components/dialogs/edit/edit.dialog.component';
@ -117,6 +118,7 @@ import {EditDialogComponent} from './components/dialogs/edit/edit.dialog.compone
SelectObjectDialogComponent, SelectObjectDialogComponent,
AutocompleteSelectComponent, AutocompleteSelectComponent,
LendingStationComponent, LendingStationComponent,
FormSelectSearchComponent,
AddDialogComponent, AddDialogComponent,
EditDialogComponent, EditDialogComponent,
DeleteDialogComponent, DeleteDialogComponent,
@ -168,6 +170,7 @@ import {EditDialogComponent} from './components/dialogs/edit/edit.dialog.compone
GraphQLModule, GraphQLModule,
DragDropModule, DragDropModule,
MatTooltipModule, MatTooltipModule,
MatOptionModule,
MatSelectModule, MatSelectModule,
MatPaginatorModule, MatPaginatorModule,
MatSortModule, MatSortModule,

@ -15,8 +15,9 @@ import { MatSort } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table'; import { MatTableDataSource } from '@angular/material/table';
import { fromEvent } from 'rxjs'; import { fromEvent } from 'rxjs';
import { first } from 'rxjs/operators'; import { first } from 'rxjs/operators';
import { User } from '../../models/user'; import { Role, User } from '../../models/user';
import {UserService} from '../../services/user.service'; import {UserService} from '../../services/user.service';
import {RoleService} from '../../services/role.service';
import {DeleteDialogComponent} from '../../components/dialogs/delete/delete.dialog.component'; import {DeleteDialogComponent} from '../../components/dialogs/delete/delete.dialog.component';
import {AddDialogComponent} from '../../components/dialogs/add/add.dialog.component'; import {AddDialogComponent} from '../../components/dialogs/add/add.dialog.component';
import {EditDialogComponent} from '../../components/dialogs/edit/edit.dialog.component'; import {EditDialogComponent} from '../../components/dialogs/edit/edit.dialog.component';
@ -39,7 +40,8 @@ export class AdminDataPageComponent implements OnInit {
constructor(public httpClient: HttpClient, constructor(public httpClient: HttpClient,
public dialog: MatDialog, public dialog: MatDialog,
private userService: UserService) {} private userService: UserService,
private roleService: RoleService) {}
@ViewChild(MatPaginator, {static: true}) paginator: MatPaginator; @ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
@ViewChild(MatSort, {static: true}) sort: MatSort; @ViewChild(MatSort, {static: true}) sort: MatSort;
@ -55,15 +57,19 @@ export class AdminDataPageComponent implements OnInit {
addNew() { addNew() {
let dialogData: any = {};
dialogData.rolesData = deepCopy(this.roles);
const dialogRef = this.dialog.open(AddDialogComponent, { const dialogRef = this.dialog.open(AddDialogComponent, {
data: {user: User } data: dialogData,
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
if (result === 1) { if (result === 1) {
let newUserData = this.userService.getDialogData();
this.dataSource.data.push(this.userService.getDialogData()); console.log("add user data");
newUserData.rolesString = newUserData.roles.join(', ');
this.dataSource.data.push(newUserData);
this.refreshTable(); this.refreshTable();
} }
@ -72,25 +78,27 @@ export class AdminDataPageComponent implements OnInit {
startEdit(user : User) { startEdit(user : User) {
let dialogData = deepCopy(user); let dialogData = deepCopy(user);
dialogData.rolesData = deepCopy(roles); dialogData.rolesData = deepCopy(this.roles);
const dialogRef = this.dialog.open(EditDialogComponent, { const dialogRef = this.dialog.open(EditDialogComponent, {
data: deepCopy(user), data: dialogData,
}); });
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
if (result === 1) { if (result === 1) {
console.log("editing done"); console.log("editing done");
const foundIndex = this.dataSource.data.findIndex(x => x.email === this.userService.getDialogData().email); let newUserData = this.userService.getDialogData();
const foundIndex = this.dataSource.data.findIndex(x => x.id === newUserData.id);
this.dataSource.data[foundIndex] = this.userService.getDialogData(); newUserData.rolesString = newUserData.roles.join(', ');
this.dataSource.data[foundIndex] = newUserData;
this.refreshTable(); this.refreshTable();
} }
}); });
} }
deleteItem(i: number, id: number, title: string, state: string, url: string) { deleteItem(i: number, id: number, title: string, state: string, url: string) {
this.index = i; this.index = i;
this.id = id; this.id = id;
@ -115,6 +123,9 @@ export class AdminDataPageComponent implements OnInit {
} }
public loadData() { public loadData() {
this.roleService.getAllRoles().pipe(first()).subscribe((roles: Role[]) => {
this.roles = roles;
});
this.userService.getAllUsers().pipe(first()).subscribe((data: User[]) => { this.userService.getAllUsers().pipe(first()).subscribe((data: User[]) => {
for (let user of data){ for (let user of data){
let roles = []; let roles = [];

@ -3,6 +3,8 @@ import {Component, Inject} from '@angular/core';
import {UserService} from '../../../services/user.service'; import {UserService} from '../../../services/user.service';
import {FormControl, Validators} from '@angular/forms'; import {FormControl, Validators} from '@angular/forms';
import {User} from '../../../models/user'; import {User} from '../../../models/user';
import { first } from 'rxjs/operators';
import { SnackBarService } from 'src/app/services/snackbar.service';
@Component({ @Component({
selector: 'app-add.dialog', selector: 'app-add.dialog',
@ -12,8 +14,12 @@ import {User} from '../../../models/user';
export class AddDialogComponent { export class AddDialogComponent {
constructor(public dialogRef: MatDialogRef<AddDialogComponent>, constructor(public dialogRef: MatDialogRef<AddDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: User, @Inject(MAT_DIALOG_DATA) public data: any,
public userService: UserService) { } public userService: UserService,
public snackbarService: SnackBarService) { }
hide = true;
selectedRoles: FormControl = new FormControl();
formControl = new FormControl('', [ formControl = new FormControl('', [
Validators.required Validators.required
@ -35,7 +41,20 @@ export class AddDialogComponent {
} }
public confirmAdd(): void { public confirmAdd(): void {
this.userService.addUser(this.data); this.data.roles = [];
//this.dataService.addIssue(this.data); for (let role of this.selectedRoles.value){
this.data.roles.push(role.name);
}
this.userService.addUser(this.data).pipe(first())
.subscribe(
data => {
this.snackbarService.openSnackBar("Der Nutzer wurde erfolgreich hinzugefügt");
//this.loadAllObjects();
},
error => {
console.log("Eroor while editing: " + JSON.stringify(error));
this.snackbarService.openSnackBar(error, "Ok", true);
}
);
} }
} }

@ -23,6 +23,36 @@
</mat-form-field> </mat-form-field>
</div> </div>
<div class="form">
<select-search class="mat-form-field" label="Rollen"
[formCtrl]="selectedRoles"
[data]="data.rolesData"
[preSelectedData]="data.roles" multiple></select-search>
</div>
<div class="form">
<mat-form-field>
<mat-label>Admin Passwort</mat-label>
<input
matInput
[type]="hide ? 'password' : 'text'"
name="ownPassword"
[(ngModel)]="data.own_password"
required
/>
<button
mat-icon-button
matSuffix
(click)="hide = !hide"
[attr.aria-label]="'Hide password'"
[attr.aria-pressed]="hide"
>
<mat-icon>{{ hide ? "visibility_off" : "visibility" }}</mat-icon>
</button>
</mat-form-field>
</div>
<div mat-dialog-actions> <div mat-dialog-actions>
<button mat-button [type]="submit" [disabled]="!formControl.valid" [mat-dialog-close]="1" (click)="confirmAdd()">Save</button> <button mat-button [type]="submit" [disabled]="!formControl.valid" [mat-dialog-close]="1" (click)="confirmAdd()">Save</button>
<button mat-button (click)="onNoClick()" tabindex="-1">Cancel</button> <button mat-button (click)="onNoClick()" tabindex="-1">Cancel</button>

@ -14,9 +14,10 @@ export class EditDialogComponent {
hide = true; hide = true;
selectedRoles: FormControl = new FormControl();
constructor(public dialogRef: MatDialogRef<EditDialogComponent>, constructor(public dialogRef: MatDialogRef<EditDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any, @Inject(MAT_DIALOG_DATA) public data: any, public userService: UserService, public snackbarService : SnackBarService) { }
@Inject(MAT_DIALOG_DATA) public role: any, public userService: UserService, public snackbarService : SnackBarService) { }
formControl = new FormControl('', [ formControl = new FormControl('', [
Validators.required Validators.required
@ -38,7 +39,11 @@ export class EditDialogComponent {
} }
stopEdit(): void { stopEdit(): void {
console.log("Selected Role " + JSON.stringify(this.selectedRoles.value));
this.data.roles = []; this.data.roles = [];
for (let role of this.selectedRoles.value){
this.data.roles.push(role.name);
}
this.userService.updateUser(this.data).pipe(first()) this.userService.updateUser(this.data).pipe(first())
.subscribe( .subscribe(
data => { data => {

@ -23,15 +23,23 @@
</mat-form-field> </mat-form-field>
</div> </div>
<div class="form">
<select-search class="mat-form-field" label="Rollen"
[formCtrl]="selectedRoles"
[data]="data.rolesData"
[preSelectedData]="data.roles" multiple></select-search>
</div>
<div class="form"> <div class="form">
<mat-form-field> <mat-form-field>
<mat-label>Eigenes Passwort</mat-label> <mat-label>Admin Passwort</mat-label>
<input <input
matInput matInput
[type]="hide ? 'password' : 'text'" [type]="hide ? 'password' : 'text'"
name="ownPassword" name="ownPassword"
[(ngModel)]="data.own_password" [(ngModel)]="data.own_password"
required
/> />
<button <button
mat-icon-button mat-icon-button

@ -4,6 +4,6 @@
</mat-label> </mat-label>
<mat-select [ngModel]="selectedOptions" (ngModelChange)="selectedOptions" [formControl]="formCtrl" [multiple]="multiple"> <mat-select [ngModel]="selectedOptions" (ngModelChange)="selectedOptions" [formControl]="formCtrl" [multiple]="multiple">
<mat-select-search [formControl]="searchCtrl"></mat-select-search> <mat-select-search [formControl]="searchCtrl"></mat-select-search>
<mat-option *ngFor="let risk of filteredInterfacesBMulti | async" [value]="risk">{{risk.NAME}}</mat-option> <mat-option *ngFor="let risk of filteredInterfacesBMulti | async" [value]="risk">{{risk.name}}</mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>

@ -11,6 +11,7 @@ export class FormSelectSearchComponent implements OnInit, OnDestroy, OnChanges {
//@Input() group: FormGroup; //@Input() group: FormGroup;
//@Input() controlName: string; //@Input() controlName: string;
@Input() formCtrl: FormControl; @Input() formCtrl: FormControl;
//@Input() name: string;
@Input() data: any[]; @Input() data: any[];
@Input() preSelectedData: any[]; @Input() preSelectedData: any[];
@ -35,39 +36,24 @@ export class FormSelectSearchComponent implements OnInit, OnDestroy, OnChanges {
if (changes['data']) { if (changes['data']) {
if (this.preSelectedData !== undefined){ if (this.preSelectedData !== undefined){
//console.log( this.label + " is not undefined :D");
//console.log(this.label + " preselected: " + this.preSelectedData);
//console.log(JSON.stringify(this.preSelectedData))
this.riskListGeneratorB(this.preSelectedData); this.riskListGeneratorB(this.preSelectedData);
console.log(this.label + " selected options: "+ JSON.stringify(this.selectedOptions) + " all options: " + JSON.stringify(this.data));
} }
//this.listenInterfacesSearchable();
this.filterInterfacesBMulti(); this.filterInterfacesBMulti();
} }
if (changes['preSelectedData']) { if (changes['preSelectedData']) {
if (this.preSelectedData !== undefined){ if (this.preSelectedData !== undefined){
/*console.log(this.label + " preselect data change");
console.log(this.label + " preselected: " + this.preSelectedData);
console.log(JSON.stringify(this.preSelectedData))*/
this.riskListGeneratorB(this.preSelectedData); this.riskListGeneratorB(this.preSelectedData);
console.log(this.label + " selected options: "+ JSON.stringify(this.selectedOptions) + " all options: " + JSON.stringify(this.data));
} }
//this.listenInterfacesSearchable();
this.filterInterfacesBMulti(); this.filterInterfacesBMulti();
} }
} }
ngOnInit() { ngOnInit() {
//this.group.addControl('searchCtrl', this.searchCtrl);
//this.formCtrl = this.group[this.controlName];
if (this.preSelectedData !== undefined){ if (this.preSelectedData !== undefined){
/*console.log("preselected is not undefined :D");
console.log("preselected: " + this.preSelectedData);*/
this.riskListGeneratorB(this.preSelectedData); this.riskListGeneratorB(this.preSelectedData);
console.log("selected options: "+ JSON.stringify(this.selectedOptions) + " all options: " + JSON.stringify(this.data));
} }
this.listenInterfacesSearchable(); this.listenInterfacesSearchable();

@ -10,14 +10,14 @@ export class User {
email: string; email: string;
own_password: string; own_password: string;
password: string; password: string;
roles: UserRole[]; roles: Role[];
rolesString? : string; rolesString? : string;
attributes : { attributes : {
profile_url?: string; profile_url?: string;
} }
} }
export class UserRole { export class Role {
id: number; id: number;
name: string; name: string;
description: string; description: string;

Loading…
Cancel
Save