feat(Benutzer-Darstellung): - openCreateSheet-Methoden in repUserOnSelectedRows-Events integriert

- create-Methode zur Komponente rep-create-form hinzugefügt
This commit is contained in:
Developer 02 2024-11-08 11:36:53 +01:00
parent 52e6eac71d
commit e8376ccd21
3 changed files with 40 additions and 15 deletions

View File

@ -1 +1 @@
<p>rep-create-form works!</p>
<button mat-flat-button (click)="create()">Erstellen</button>

View File

@ -1,6 +1,8 @@
import { Component, inject } from '@angular/core';
import { UserRep } from '../../../models/user-management.api.models';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { UserRepService } from '../../../services/api/user-representation.service';
import { GroupUpdateFormComponent } from '../group-update-form/group-update-form.component';
@Component({
selector: 'app-rep-create-form',
@ -11,6 +13,26 @@ import { MAT_DIALOG_DATA } from '@angular/material/dialog';
})
export class RepCreateFormComponent {
readonly userRep: UserRep = inject(MAT_DIALOG_DATA)
readonly userRep: UserRep;
readonly afterCreation: (any: any) => any;
readonly userRepService: UserRepService = inject(UserRepService);
readonly dialogRef: MatDialogRef<GroupUpdateFormComponent> = inject(MatDialogRef<GroupUpdateFormComponent>);
constructor() {
const dialogData: { userRep: UserRep, afterCreation: (any: any) => any } = inject(MAT_DIALOG_DATA)
this.userRep = dialogData.userRep;
this.afterCreation = dialogData.afterCreation;
}
create() {
this.userRepService.create(this.userRep).subscribe({
next: (res) => {
this.afterCreation({ successful: res });
this.dialogRef.close();
},
error: (error) => {
this.afterCreation({ error: error });
}
});
}
}

View File

@ -105,10 +105,11 @@ export class UserRepresentationComponent extends BasePageComponent implements Af
groupId: this.slGroupId,
repUserId: this.slRepUserId,
validFrom: new Date(),
validTo: new Date(new Date().setDate(new Date().getDate() + 7)) //after one week
validTo: new Date(new Date().setDate(new Date().getDate() + 7))
}
this.userRepService.create(newUserRep).subscribe({
next: (response) => {
this.openCreateSheet(newUserRep, res => {
if (res.successful) {
this.slRepUserId = undefined;
this.repUsers.safelyUnselectAll()
@ -117,8 +118,8 @@ export class UserRepresentationComponent extends BasePageComponent implements Af
this.userReps.fetchByUser(this.slUserId)
if (this.slGroupId)
this.userReps.fetchByGroup(this.slGroupId)
},
error: (error) => {
}
else if (res.error) {
Swal.fire({
icon: "error",
title: "Oops...",
@ -157,8 +158,9 @@ export class UserRepresentationComponent extends BasePageComponent implements Af
groupId: this.slGroupId,
repGroupId: this.slRepGroupId,
}
this.userRepService.create(newUserRep).subscribe({
next: (res) => {
this.openCreateSheet(newUserRep, res => {
if (res.successful) {
this.slRepGroupId = undefined;
this.repUsers.safelyUnselectAll()
this.groups.safelyUnselectAll()
@ -166,8 +168,8 @@ export class UserRepresentationComponent extends BasePageComponent implements Af
this.userReps.fetchByUser(this.slUserId)
if (this.slGroupId)
this.userReps.fetchByGroup(this.slGroupId)
},
error: (error) => {
}
else if (res.error) {
Swal.fire({
icon: "error",
title: "Oops...",
@ -211,10 +213,11 @@ export class UserRepresentationComponent extends BasePageComponent implements Af
}
}
openUpdateSheet(userRep: UserRep): void {
openCreateSheet(userRep: UserRep, afterCreation: (any: any) => any): void {
this.dialog.open(RepCreateFormComponent, {
width: "50rem",
data: userRep
data: { userRep: userRep, afterCreation: afterCreation }
});
}
}
}