fix: Changed group assignment. Closes #1.
This commit is contained in:
@@ -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.")
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user