refactor: Entfernen der right_group-Eigenschaft aus der Representation-Entität

- Die Spalte `right_group` aus der `Representation`-Entität entfernt, um die Zuordnung von Benutzern oder Gruppen zu spezifischen Gruppen zu entfernen.
- Stattdessen wurde die `group`-Eigenschaft hinzugefügt, um flexible Zuordnungen zu ermöglichen.
- Ermöglicht nun `user-user`, `user-group`, `group-user` und `group-group` Repräsentationen.
This commit is contained in:
Developer 02
2024-09-09 17:25:12 +02:00
parent 75e708d02d
commit 25a4b0752b
15 changed files with 86 additions and 85 deletions

View File

@@ -22,13 +22,13 @@ export class UserRepTableComponent extends BaseTableComponent<UserRep, UserRepSe
this.loading = false
}
override fetchData(userId?: number): void {
this.service.getAll(false, true, true, true, userId).subscribe({
override fetchData(userId?: number, groupId?: number): void {
this.service.getAll({ withUser: false, withRepGroup: true, withGroup: false, withRepUser: true, userId: userId, groupId: groupId }).subscribe({
next: (response: UserRep[]) => {
this.source = response;
this.loading = false;
},
error: (error: any) => {}
error: (error: any) => { }
});
}
}

View File

@@ -58,12 +58,12 @@ export interface UserRep {
id?: number,
userId: number,
repGroupId?: number,
rightGroupId: number,
groupId?: number,
addedWho: string,
repUserId?: number,
user?: User,
repGroup?: Group,
rightGroup?: Group,
group?: Group,
repUser?: User
}

View File

@@ -7,10 +7,13 @@
<mat-tab label="Benutzer">
<app-user-table #users [onSelectedRows]="userOnSelectedRows"></app-user-table>
</mat-tab>
<mat-tab label="Gruppe">
<app-group-table #rightGroups [columns]="groupColumns" [onSelectedRows]="groupOnSelectedRows"></app-group-table>
</mat-tab>
</mat-tab-group>
</div>
<!-- (1, 2): representations -->
<div class="col-2">
<div class="col-4">
<mat-tab-group>
<mat-tab label="Rep. Benutzer">
<app-user-table #repUsers [onSelectedRows]="repUserOnSelectedRows"></app-user-table>
@@ -20,14 +23,6 @@
</mat-tab>
</mat-tab-group>
</div>
<!-- (1, 3): right groups -->
<div class="col-2">
<mat-tab-group>
<mat-tab label="Rechte Gruppe">
<app-group-table #rightGroups] [columns]="groupRightColumns" [onSelectedRows]="rightGroupOnSelectedRows"></app-group-table>
</mat-tab>
</mat-tab-group>
</div>
<!-- (1, 4): assigned users -->
<div class="col-3">
<mat-tab-group>

View File

@@ -8,6 +8,7 @@ import Swal from 'sweetalert2';
import { MatTabsModule, MatTabGroup } from '@angular/material/tabs';
import { env } from '../../../environments/environment';
import { BasePageComponent } from '../base-page/base-page.component';
import { UserRep } from '../../models/user-management.api.models';
@Component({
standalone: true,
@@ -19,8 +20,8 @@ import { BasePageComponent } from '../base-page/base-page.component';
export class UserRepresentationComponent extends BasePageComponent implements AfterViewInit {
useRepLabel: string = "";
groupColumns: Array<GuiColumn>;
groupRepCols: Array<GuiColumn>;
groupRightColumns: Array<GuiColumn>;
slUserId: null | number = null;
slRepUserId: null | number = null;
slRepGroupId: null | number = null;
@@ -32,7 +33,7 @@ export class UserRepresentationComponent extends BasePageComponent implements Af
constructor(private userRepService: UserRepService) {
super()
this.groupRepCols = env.columnNames.group.representative;
this.groupRightColumns = env.columnNames.group.right;
this.groupColumns = env.columnNames.group.right;
this.userRepService = userRepService;
}
@@ -43,7 +44,7 @@ export class UserRepresentationComponent extends BasePageComponent implements Af
this.users.fetchData();
this.repUsers.fetchData();
this.repGroups.fetchData();
this.rightGroups.fetchData();
this.groups.fetchData();
})
this.transferService.add(() => {
this.repUsers.safelyUnselectAll();
@@ -53,26 +54,34 @@ export class UserRepresentationComponent extends BasePageComponent implements Af
}
@ViewChild("users") users!: UserTableComponent;
@ViewChild("groups") groups!: GroupTableComponent;
@ViewChild("repUsers") repUsers!: UserTableComponent;
@ViewChild("repGroups") repGroups!: GroupTableComponent;
@ViewChild("rightGroups") rightGroups!: GroupTableComponent;
@ViewChild("userReps") userReps!: UserRepTableComponent;
userOnSelectedRows = (rows: GuiSelectedRow[]) => {
userGroupOnSelectedRows = (rows: GuiSelectedRow[], isUser: boolean = true) => {
if (rows.length > 0) {
this.users.safelyUnselectAll();
this.useRepLabel = `Vertretungen von ${rows[0].source?.username}`
this.userReps.fetchData(rows[0].source?.id)
this.slUserId = rows[0].source?.id
if (isUser) {
this.useRepLabel = `Vertretungen von ${rows[0].source?.username}`
this.userReps.fetchData(rows[0].source?.id)
this.slUserId = rows[0].source?.id
}
else {
this.useRepLabel = `Vertretungen von ${rows[0].source?.name}`
this.userReps.fetchData(undefined, rows[0].source?.id)
this.slUserId = rows[0].source?.id
}
}
}
rightGroupOnSelectedRows = (rows: GuiSelectedRow[]) => {
if (rows.length > 0) {
this.slRightGroupId = rows[0].source?.id
} else {
this.slRightGroupId = null;
}
userOnSelectedRows = (rows: GuiSelectedRow[]) => {
this.userGroupOnSelectedRows(rows, true);
}
groupOnSelectedRows = (rows: GuiSelectedRow[]) => {
this.userGroupOnSelectedRows(rows, false);
}
repUserOnSelectedRows = (rows: GuiSelectedRow[]) => {
@@ -91,17 +100,9 @@ export class UserRepresentationComponent extends BasePageComponent implements Af
text: "Bitte wählen Sie die Vertretungen Benutzer!",
});
}
else if (!this.slRightGroupId) {
Swal.fire({
icon: "error",
title: "Oops...",
text: "Bitte wählen Sie die Rechte Gruppe!",
});
}
else {
var newUserRep = {
var newUserRep: UserRep = {
userId: this.slUserId,
rightGroupId: this.slRightGroupId,
repUserId: this.slRepUserId,
addedWho: 'DEFAULT'
}
@@ -145,17 +146,9 @@ export class UserRepresentationComponent extends BasePageComponent implements Af
text: "Bitte wählen Sie die Vertretungen Gruppe!",
});
}
else if (!this.slRightGroupId) {
Swal.fire({
icon: "error",
title: "Oops...",
text: "Bitte wählen Sie die rechte Gruppe!",
});
}
else {
var newUserRep = {
userId: this.slUserId,
rightGroupId: this.slRightGroupId,
repGroupId: this.slRepGroupId,
addedWho: 'DEFAULT'
}

View File

@@ -9,28 +9,42 @@ import { UrlService } from "./url.service";
providedIn: "root"
})
export class UserRepService extends ApiService<UserRep> {
constructor(http: HttpClient, urlService : UrlService) {
constructor(http: HttpClient, urlService: UrlService) {
super(http, urlService.apiRoute.userRep)
}
override getAll(withUser: boolean = false, withRepGroup: boolean = false, withRightGroup: boolean = false, withRepUser: boolean = false, userId?: number): Observable<UserRep[]> {
override getAll(options?: Options): Observable<UserRep[]> {
let params = new HttpParams();
if (withUser) {
params = params.set('withUser', withUser);
}
if (withRepGroup) {
params = params.set('withRepGroup', withRepGroup);
}
if (withRightGroup) {
params = params.set('withRightGroup', withRightGroup);
}
if (withRepUser) {
params = params.set('withRepUser', withRepUser);
}
if (userId) {
params = params.set('userId', userId)
if (options) {
if (options.withUser) {
params = params.set('withUser', options.withUser);
}
if (options.withRepGroup) {
params = params.set('withRepGroup', options.withRepGroup);
}
if (options.withGroup) {
params = params.set('withRightGroup', options.withGroup);
}
if (options.withRepUser) {
params = params.set('withRepUser', options.withRepUser);
}
if (options.userId) {
params = params.set('userId', options.userId)
}
if (options.groupId) {
params = params.set('groupId', options.groupId)
}
}
return this.http.get<UserRep[]>(`${this.baseUrl}`, { params: params, withCredentials: true });
}
}
interface Options {
withUser: boolean;
withRepGroup: boolean;
withGroup: boolean;
withRepUser: boolean;
userId?: number;
groupId?: number;
}

View File

@@ -189,10 +189,6 @@ export const env = {
header: "Repr. Gruppen",
field: (ur: any) => ur.repGroup?.name
},
{
header: "Rechte Gruppen",
field: (ur: any) => ur.rightGroup?.name
},
{
header: "Repr. Benutzer",
field: (ur: any) => ur.repUser?.username

View File

@@ -21,11 +21,11 @@ namespace DigitalData.UserManager.API.Controllers
}
[HttpGet]
public async Task<IActionResult> GetAll(bool withUser = false, bool withRepGroup = false, bool withRightGroup = false, bool withRepUser = false, int? userId = null)
public async Task<IActionResult> GetAll(bool withUser = false, bool withRepGroup = false, bool withGroup = false, bool withRepUser = false, int? userId = null, int? groupId = null)
{
try
{
return await _service.ReadAllAsync(withUser, withRepGroup, withRightGroup, withRepUser, userId).ThenAsync(Ok, IActionResult (m, n) =>
return await _service.ReadAllAsync(withUser, withRepGroup, withGroup, withRepUser, userId, groupId).ThenAsync(Ok, IActionResult (m, n) =>
{
_logger.LogNotice(n);
return NotFound();