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 { catchError, throwError } from 'rxjs';
|
||||||
import { UserResetComponent } from './user-reset/user-reset.component';
|
import { UserResetComponent } from './user-reset/user-reset.component';
|
||||||
import { LocalStorageService } from 'src/app/services/local-storage.service';
|
import { LocalStorageService } from 'src/app/services/local-storage.service';
|
||||||
|
import { Group } from 'src/app/types/group';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-account-mgmt',
|
selector: 'app-account-mgmt',
|
||||||
@@ -18,6 +19,7 @@ import { LocalStorageService } from 'src/app/services/local-storage.service';
|
|||||||
|
|
||||||
|
|
||||||
export class AccountMgmtComponent implements OnInit, AfterViewInit {
|
export class AccountMgmtComponent implements OnInit, AfterViewInit {
|
||||||
|
protected groups: Group[] = []
|
||||||
users: MatTableDataSource<any>
|
users: MatTableDataSource<any>
|
||||||
loading = false
|
loading = false
|
||||||
@ViewChild(MatPaginator) paginator!: MatPaginator
|
@ViewChild(MatPaginator) paginator!: MatPaginator
|
||||||
@@ -45,7 +47,8 @@ export class AccountMgmtComponent implements OnInit, AfterViewInit {
|
|||||||
this.loading = true
|
this.loading = true
|
||||||
this.ac.accs.getAccs().subscribe((data)=>{
|
this.ac.accs.getAccs().subscribe((data)=>{
|
||||||
this.loading = false
|
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) {
|
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) {
|
if (reply) {
|
||||||
this.ac.accs.putAcc(item._id, reply).pipe(catchError((err)=>{
|
this.ac.accs.putAcc(item._id, reply).pipe(catchError((err)=>{
|
||||||
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
|
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
|
||||||
@@ -73,7 +76,7 @@ export class AccountMgmtComponent implements OnInit, AfterViewInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
new() {
|
new() {
|
||||||
this.dialog.open(UserEditComponent).afterClosed().subscribe(reply => {
|
this.dialog.open(UserEditComponent, {data: {groups: this.groups}}).afterClosed().subscribe(reply => {
|
||||||
if (reply) {
|
if (reply) {
|
||||||
this.ac.accs.postAcc(reply).pipe(catchError((err)=>{
|
this.ac.accs.postAcc(reply).pipe(catchError((err)=>{
|
||||||
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
|
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
|
||||||
|
|||||||
@@ -15,6 +15,14 @@
|
|||||||
<mat-label>Nazwa użytkownika</mat-label>
|
<mat-label>Nazwa użytkownika</mat-label>
|
||||||
<input type="text" matInput required formControlName="uname">
|
<input type="text" matInput required formControlName="uname">
|
||||||
</mat-form-field>
|
</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-form-field *ngIf="this.ls.permChecker(32)">
|
||||||
<mat-label>Uprawnienia</mat-label>
|
<mat-label>Uprawnienia</mat-label>
|
||||||
<mat-select multiple formControlName="flags">
|
<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 { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||||
import { FormControl, FormGroup } from '@angular/forms';
|
import { FormControl, FormGroup } from '@angular/forms';
|
||||||
import { LocalStorageService } from 'src/app/services/local-storage.service';
|
import { LocalStorageService } from 'src/app/services/local-storage.service';
|
||||||
|
import { Group } from 'src/app/types/group';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-user-edit',
|
selector: 'app-user-edit',
|
||||||
@@ -10,42 +11,49 @@ import { LocalStorageService } from 'src/app/services/local-storage.service';
|
|||||||
})
|
})
|
||||||
export class UserEditComponent {
|
export class UserEditComponent {
|
||||||
form: FormGroup
|
form: FormGroup
|
||||||
|
groups: Group[]
|
||||||
constructor (public dialogRef: MatDialogRef<UserEditComponent>, @Inject(MAT_DIALOG_DATA) public data: any, readonly ls: LocalStorageService) {
|
constructor (public dialogRef: MatDialogRef<UserEditComponent>, @Inject(MAT_DIALOG_DATA) public data: any, readonly ls: LocalStorageService) {
|
||||||
if (data == null) {
|
if (data.user == null) {
|
||||||
data = {
|
data.user = {
|
||||||
fname: "",
|
fname: "",
|
||||||
surname: "",
|
surname: "",
|
||||||
room: 0,
|
room: "",
|
||||||
uname: "",
|
uname: "",
|
||||||
|
groups: [],
|
||||||
admin: 0
|
admin: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.groups = data.groups
|
||||||
var flags: Array<number> = []
|
var flags: Array<number> = []
|
||||||
if (data.admin) {
|
if (data.user.admin) {
|
||||||
if ((data.admin & 1) == 1) flags.push(1)
|
if ((data.user.admin & 1) == 1) flags.push(1)
|
||||||
if ((data.admin & 2) == 2) flags.push(2)
|
if ((data.user.admin & 2) == 2) flags.push(2)
|
||||||
if ((data.admin & 4) == 4) flags.push(4)
|
if ((data.user.admin & 4) == 4) flags.push(4)
|
||||||
if ((data.admin & 8) == 8) flags.push(8)
|
if ((data.user.admin & 8) == 8) flags.push(8)
|
||||||
if ((data.admin & 16) == 16) flags.push(16)
|
if ((data.user.admin & 16) == 16) flags.push(16)
|
||||||
if ((data.admin & 32) == 32) flags.push(32)
|
if ((data.user.admin & 32) == 32) flags.push(32)
|
||||||
if ((data.admin & 64) == 64) flags.push(64)
|
if ((data.user.admin & 64) == 64) flags.push(64)
|
||||||
if ((data.admin & 128) == 128) flags.push(128)
|
if ((data.user.admin & 128) == 128) flags.push(128)
|
||||||
}
|
}
|
||||||
this.form = new FormGroup({
|
this.form = new FormGroup({
|
||||||
fname: new FormControl(data.fname),
|
fname: new FormControl(data.user.fname),
|
||||||
surname: new FormControl(data.surname),
|
surname: new FormControl(data.user.surname),
|
||||||
room: new FormControl<number>(data.room),
|
room: new FormControl(data.user.room),
|
||||||
uname: new FormControl(data.uname),
|
uname: new FormControl<string>(data.user.uname),
|
||||||
|
groups: new FormControl<Array<string>>(data.user.groups),
|
||||||
flags: new FormControl<Array<number>>(flags),
|
flags: new FormControl<Array<number>>(flags),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
protected editUser() {
|
protected editUser() {
|
||||||
|
console.log(this.form.value);
|
||||||
|
|
||||||
this.dialogRef.close({
|
this.dialogRef.close({
|
||||||
fname: this.form.get('fname')?.value,
|
fname: this.form.get('fname')?.value,
|
||||||
surname: this.form.get('surname')?.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,
|
uname: this.form.get('uname')?.value,
|
||||||
|
groups: this.form.get('groups')?.value,
|
||||||
flags: (() => {
|
flags: (() => {
|
||||||
var value = this.form.get('flags')?.value.reduce((a: number,b: number)=>a+b,0)
|
var value = this.form.get('flags')?.value.reduce((a: number,b: number)=>a+b,0)
|
||||||
if (this.ls.capCheck(32)) {
|
if (this.ls.capCheck(32)) {
|
||||||
|
|||||||
@@ -120,7 +120,20 @@ export class AdminCommService {
|
|||||||
//#region amgmt
|
//#region amgmt
|
||||||
accs = {
|
accs = {
|
||||||
getAccs: () => {
|
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) => {
|
postAcc: (item: any) => {
|
||||||
@@ -145,14 +158,6 @@ export class AdminCommService {
|
|||||||
getGroups: () => {
|
getGroups: () => {
|
||||||
return this.http.get<Group[]>(environment.apiEndpoint+`/admin/groups`, {withCredentials: true})
|
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) => {
|
newGroup: (name: string) => {
|
||||||
return this.http.post<Status>(environment.apiEndpoint+`/admin/groups`, {name: name}, {withCredentials: true})
|
return this.http.post<Status>(environment.apiEndpoint+`/admin/groups`, {name: name}, {withCredentials: true})
|
||||||
|
|||||||
@@ -3,22 +3,6 @@
|
|||||||
<mat-card-header>
|
<mat-card-header>
|
||||||
<mat-card-title contenteditable appCe (edit)="nameEdit(item._id, $event)">{{item.name}}</mat-card-title>
|
<mat-card-title contenteditable appCe (edit)="nameEdit(item._id, $event)">{{item.name}}</mat-card-title>
|
||||||
</mat-card-header>
|
</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>
|
<mat-card-actions>
|
||||||
<button mat-button color="warn" (click)="remove(item._id)">Usuń</button>
|
<button mat-button color="warn" (click)="remove(item._id)">Usuń</button>
|
||||||
</mat-card-actions>
|
</mat-card-actions>
|
||||||
|
|||||||
@@ -38,14 +38,6 @@ export class GroupsComponent implements OnInit {
|
|||||||
return groups.flatMap((g) => g.name)
|
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[]) {
|
protected nameEdit(id: string, name: string | string[]) {
|
||||||
name = name as string
|
name = name as string
|
||||||
this.acs.groups.editName(id, name).subscribe((s) => this.refreshIfGood(s))
|
this.acs.groups.editName(id, name).subscribe((s) => this.refreshIfGood(s))
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</mat-radio-button>
|
</mat-radio-button>
|
||||||
<mat-radio-button value="all">Wychowankowie</mat-radio-button>
|
|
||||||
</mat-radio-group>
|
</mat-radio-group>
|
||||||
</div>
|
</div>
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
export interface Group {
|
export interface Group {
|
||||||
_id: string;
|
_id: string;
|
||||||
name: string;
|
name: string;
|
||||||
rooms?: number[];
|
|
||||||
unames?: string[]
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user