fix: Changed group assignment. Closes #1.

This commit is contained in:
2025-05-05 18:54:20 +02:00
parent 6c8b40cbad
commit fd9380a61d
8 changed files with 53 additions and 56 deletions

View File

@@ -9,6 +9,7 @@ import { UserEditComponent } from './user-edit/user-edit.component';
import { catchError, throwError } from 'rxjs';
import { UserResetComponent } from './user-reset/user-reset.component';
import { LocalStorageService } from 'src/app/services/local-storage.service';
import { Group } from 'src/app/types/group';
@Component({
selector: 'app-account-mgmt',
@@ -18,6 +19,7 @@ import { LocalStorageService } from 'src/app/services/local-storage.service';
export class AccountMgmtComponent implements OnInit, AfterViewInit {
protected groups: Group[] = []
users: MatTableDataSource<any>
loading = false
@ViewChild(MatPaginator) paginator!: MatPaginator
@@ -45,7 +47,8 @@ export class AccountMgmtComponent implements OnInit, AfterViewInit {
this.loading = true
this.ac.accs.getAccs().subscribe((data)=>{
this.loading = false
this.users.data = data
this.users.data = data.users
this.groups = data.groups
})
}
@@ -55,7 +58,7 @@ export class AccountMgmtComponent implements OnInit, AfterViewInit {
}
edit(item: any) {
this.dialog.open(UserEditComponent, {data: item}).afterClosed().subscribe(reply => {
this.dialog.open(UserEditComponent, {data: {user: item, groups: this.groups}}).afterClosed().subscribe(reply => {
if (reply) {
this.ac.accs.putAcc(item._id, reply).pipe(catchError((err)=>{
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
@@ -73,7 +76,7 @@ export class AccountMgmtComponent implements OnInit, AfterViewInit {
}
new() {
this.dialog.open(UserEditComponent).afterClosed().subscribe(reply => {
this.dialog.open(UserEditComponent, {data: {groups: this.groups}}).afterClosed().subscribe(reply => {
if (reply) {
this.ac.accs.postAcc(reply).pipe(catchError((err)=>{
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")

View File

@@ -15,6 +15,14 @@
<mat-label>Nazwa użytkownika</mat-label>
<input type="text" matInput required formControlName="uname">
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Grupy</mat-label>
<mat-select multiple formControlName="groups">
@for (item of groups; track $index) {
<mat-option [value]="item._id">{{item.name}}</mat-option>
}
</mat-select>
</mat-form-field>
<mat-form-field *ngIf="this.ls.permChecker(32)">
<mat-label>Uprawnienia</mat-label>
<mat-select multiple formControlName="flags">

View File

@@ -2,6 +2,7 @@ import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { FormControl, FormGroup } from '@angular/forms';
import { LocalStorageService } from 'src/app/services/local-storage.service';
import { Group } from 'src/app/types/group';
@Component({
selector: 'app-user-edit',
@@ -10,42 +11,49 @@ import { LocalStorageService } from 'src/app/services/local-storage.service';
})
export class UserEditComponent {
form: FormGroup
groups: Group[]
constructor (public dialogRef: MatDialogRef<UserEditComponent>, @Inject(MAT_DIALOG_DATA) public data: any, readonly ls: LocalStorageService) {
if (data == null) {
data = {
if (data.user == null) {
data.user = {
fname: "",
surname: "",
room: 0,
room: "",
uname: "",
groups: [],
admin: 0
}
}
this.groups = data.groups
var flags: Array<number> = []
if (data.admin) {
if ((data.admin & 1) == 1) flags.push(1)
if ((data.admin & 2) == 2) flags.push(2)
if ((data.admin & 4) == 4) flags.push(4)
if ((data.admin & 8) == 8) flags.push(8)
if ((data.admin & 16) == 16) flags.push(16)
if ((data.admin & 32) == 32) flags.push(32)
if ((data.admin & 64) == 64) flags.push(64)
if ((data.admin & 128) == 128) flags.push(128)
if (data.user.admin) {
if ((data.user.admin & 1) == 1) flags.push(1)
if ((data.user.admin & 2) == 2) flags.push(2)
if ((data.user.admin & 4) == 4) flags.push(4)
if ((data.user.admin & 8) == 8) flags.push(8)
if ((data.user.admin & 16) == 16) flags.push(16)
if ((data.user.admin & 32) == 32) flags.push(32)
if ((data.user.admin & 64) == 64) flags.push(64)
if ((data.user.admin & 128) == 128) flags.push(128)
}
this.form = new FormGroup({
fname: new FormControl(data.fname),
surname: new FormControl(data.surname),
room: new FormControl<number>(data.room),
uname: new FormControl(data.uname),
fname: new FormControl(data.user.fname),
surname: new FormControl(data.user.surname),
room: new FormControl(data.user.room),
uname: new FormControl<string>(data.user.uname),
groups: new FormControl<Array<string>>(data.user.groups),
flags: new FormControl<Array<number>>(flags),
})
}
protected editUser() {
console.log(this.form.value);
this.dialogRef.close({
fname: this.form.get('fname')?.value,
surname: this.form.get('surname')?.value,
room: this.form.get('room')?.value,
room: this.form.get('room')?.value.length == 0 ? undefined : this.form.get('room')?.value,
uname: this.form.get('uname')?.value,
groups: this.form.get('groups')?.value,
flags: (() => {
var value = this.form.get('flags')?.value.reduce((a: number,b: number)=>a+b,0)
if (this.ls.capCheck(32)) {

View File

@@ -120,7 +120,20 @@ export class AdminCommService {
//#region amgmt
accs = {
getAccs: () => {
return this.http.get<any[]>(environment.apiEndpoint+`/admin/accs`, {withCredentials: true})
return this.http.get<{
users: {
_id: string;
uname: string;
pass: string;
room?: string;
admin?: number;
locked?: boolean;
fname?: string;
surname?: string;
groups: string[];
}[],
groups: Group[]
}>(environment.apiEndpoint+`/admin/accs`, {withCredentials: true})
},
postAcc: (item: any) => {
@@ -146,14 +159,6 @@ export class AdminCommService {
return this.http.get<Group[]>(environment.apiEndpoint+`/admin/groups`, {withCredentials: true})
},
editRooms: (id: string, rooms: number[]) => {
return this.putGroups(id, {rooms: rooms})
},
editUsers: (id: string, users: string[]) => {
return this.putGroups(id, {unames: users})
},
newGroup: (name: string) => {
return this.http.post<Status>(environment.apiEndpoint+`/admin/groups`, {name: name}, {withCredentials: true})
},

View File

@@ -3,22 +3,6 @@
<mat-card-header>
<mat-card-title contenteditable appCe (edit)="nameEdit(item._id, $event)">{{item.name}}</mat-card-title>
</mat-card-header>
<mat-card-content>
<table>
<thead>
<tr>
<th>Pokoje</th>
<th>Użytkownicy</th>
</tr>
</thead>
<tbody>
<tr>
<td><app-list-editor [converter]="item.rooms" (edit)="editRooms(item._id, $event)"/></td>
<td><app-list-editor [converter]="item.unames"/></td>
</tr>
</tbody>
</table>
</mat-card-content>
<mat-card-actions>
<button mat-button color="warn" (click)="remove(item._id)">Usuń</button>
</mat-card-actions>

View File

@@ -38,14 +38,6 @@ export class GroupsComponent implements OnInit {
return groups.flatMap((g) => g.name)
}
protected editRooms(id: string, rooms: string[]) {
this.acs.groups.editRooms(id, rooms.map(Number)).subscribe((s) => this.refreshIfGood(s))
}
protected editUsers(id: string, users: string[]) {
this.acs.groups.editUsers(id, users).subscribe((s) => this.refreshIfGood(s))
}
protected nameEdit(id: string, name: string | string[]) {
name = name as string
this.acs.groups.editName(id, name).subscribe((s) => this.refreshIfGood(s))

View File

@@ -22,7 +22,6 @@
</mat-select>
</mat-form-field>
</mat-radio-button>
<mat-radio-button value="all">Wychowankowie</mat-radio-button>
</mat-radio-group>
</div>
<mat-form-field>

View File

@@ -1,6 +1,4 @@
export interface Group {
_id: string;
name: string;
rooms?: number[];
unames?: string[]
}