Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a14d860022 | |||
| 9f97e584bd | |||
|
00daf7c972
|
|||
|
d4c7084820
|
|||
|
0c60f39152
|
|||
|
ca6037d405
|
|||
|
94702834b4
|
|||
|
3b56d40d5a
|
|||
|
efd76e16a1
|
|||
|
375bb1ceb4
|
|||
|
86347e254b
|
|||
|
cf2fa0b607
|
|||
|
45fb44712e
|
|||
|
92768ceda6
|
|||
|
26dac21e7e
|
|||
|
7d98cc2c49
|
|||
|
90d5b5da1c
|
|||
| 6ab3598d38 |
@@ -1,8 +1,4 @@
|
|||||||
# Ipwa
|
# Ipwa
|
||||||
|
|
||||||
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 15.0.4.
|
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 15.0.4.
|
||||||
This project depends on the [Backend server](https://github.com/Slasherss1/ipwa-backend2)
|
This project depends on the [Backend server](https://github.com/Slasherss1/ipwa-backend)
|
||||||
|
|
||||||
## Things to change
|
|
||||||
Change following files:
|
|
||||||
- (Optional) `src/assets/icons/*` - You can change the icons to your own
|
|
||||||
|
|||||||
24
angular.json
24
angular.json
@@ -70,6 +70,30 @@
|
|||||||
"with": "src/environments/environment.development.ts"
|
"with": "src/environments/environment.development.ts"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"swDevelopment": {
|
||||||
|
"buildOptimizer": false,
|
||||||
|
"optimization": false,
|
||||||
|
"vendorChunk": true,
|
||||||
|
"extractLicenses": false,
|
||||||
|
"sourceMap": true,
|
||||||
|
"namedChunks": true,
|
||||||
|
"outputHashing": "all",
|
||||||
|
"fileReplacements": [
|
||||||
|
{
|
||||||
|
"replace": "src/environments/environment.ts",
|
||||||
|
"with": "src/environments/environment.swdev.ts"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"assets": [
|
||||||
|
{
|
||||||
|
"glob": "ngsw-worker.js",
|
||||||
|
"input": "node_modules/@angular/servce-worker",
|
||||||
|
"output": "."
|
||||||
|
},
|
||||||
|
"src/ngsw.json",
|
||||||
|
"src/manifest.webmanifest"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"defaultConfiguration": "production"
|
"defaultConfiguration": "production"
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
{
|
{
|
||||||
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
|
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
|
||||||
"index": "./index.html",
|
"index": "/ipwa/index.html",
|
||||||
"assetGroups": [
|
"assetGroups": [
|
||||||
{
|
{
|
||||||
"name": "app",
|
"name": "app",
|
||||||
"installMode": "prefetch",
|
"installMode": "prefetch",
|
||||||
"resources": {
|
"resources": {
|
||||||
"files": [
|
"files": [
|
||||||
"/favicon.ico",
|
"/ipwa/favicon.ico",
|
||||||
"/manifest.webmanifest",
|
"/ipwa/manifest.webmanifest",
|
||||||
"/*.css",
|
"/ipwa/*.css",
|
||||||
"/*.js"
|
"/ipwa/*.js"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -20,8 +20,8 @@
|
|||||||
"updateMode": "prefetch",
|
"updateMode": "prefetch",
|
||||||
"resources": {
|
"resources": {
|
||||||
"files": [
|
"files": [
|
||||||
"./assets/**",
|
"/ipwa/assets/**",
|
||||||
"/**/*.(svg|cur|jpg|jpeg|png|apng|webp|avif|gif|otf|ttf|woff|woff2)"
|
"/ipwa/**/*.(svg|cur|jpg|jpeg|png|apng|webp|avif|gif|otf|ttf|woff|woff2)"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ipwa",
|
"name": "ipwa",
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ipwa",
|
"name": "ipwa",
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"license": "GPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<mat-label>Wyszukaj</mat-label>
|
<mat-label>Wyszukaj</mat-label>
|
||||||
<input matInput (keyup)="filter($event)">
|
<input matInput (keyup)="filter($event)">
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<button mat-icon-button (click)="new()"><mat-icon>add</mat-icon></button>
|
<button mat-icon-button (click)="openUserCard()"><mat-icon>add</mat-icon></button>
|
||||||
</div>
|
</div>
|
||||||
<mat-spinner *ngIf="loading"></mat-spinner>
|
<mat-spinner *ngIf="loading"></mat-spinner>
|
||||||
<table mat-table [dataSource]="users">
|
<table mat-table [dataSource]="users">
|
||||||
@@ -24,17 +24,9 @@
|
|||||||
<td mat-cell *matCellDef="let element">{{element.uname}}</td>
|
<td mat-cell *matCellDef="let element">{{element.uname}}</td>
|
||||||
</div>
|
</div>
|
||||||
<div matColumnDef="actions">
|
<div matColumnDef="actions">
|
||||||
<th mat-header-cell *matHeaderCellDef>Akcje</th>
|
<th mat-header-cell *matHeaderCellDef>Karta użytkownika</th>
|
||||||
<td mat-cell *matCellDef="let element">
|
<td mat-cell *matCellDef="let element">
|
||||||
<button mat-mini-fab (click)="resetPass(element._id)"><mat-icon>lock_reset</mat-icon></button>
|
<button mat-mini-fab (click)="openUserCard(element._id)"><mat-icon>manage_accounts</mat-icon></button>
|
||||||
<button mat-mini-fab (click)="edit(element)"><mat-icon>edit</mat-icon></button>
|
|
||||||
<button mat-mini-fab (click)="toggleLock(element)">
|
|
||||||
<div [ngSwitch]="element.locked">
|
|
||||||
<mat-icon *ngSwitchCase="true">lock</mat-icon>
|
|
||||||
<mat-icon *ngSwitchDefault>lock_open</mat-icon>
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
<button mat-mini-fab (click)="delete(element._id)"><mat-icon>delete_forever</mat-icon></button>
|
|
||||||
</td>
|
</td>
|
||||||
</div>
|
</div>
|
||||||
<tr mat-header-row *matHeaderRowDef="collumns"></tr>
|
<tr mat-header-row *matHeaderRowDef="collumns"></tr>
|
||||||
|
|||||||
@@ -4,12 +4,10 @@ import { MatDialog } from '@angular/material/dialog';
|
|||||||
import { MatTableDataSource } from '@angular/material/table';
|
import { MatTableDataSource } from '@angular/material/table';
|
||||||
import { MatPaginator } from '@angular/material/paginator';
|
import { MatPaginator } from '@angular/material/paginator';
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
import { UserDeleteComponent } from './user-delete/user-delete.component';
|
|
||||||
import { UserEditComponent } from './user-edit/user-edit.component';
|
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 { LocalStorageService } from 'src/app/services/local-storage.service';
|
||||||
import { Group } from 'src/app/types/group';
|
import { Group } from 'src/app/types/group';
|
||||||
|
import User from 'src/app/types/user';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-account-mgmt',
|
selector: 'app-account-mgmt',
|
||||||
@@ -20,21 +18,20 @@ import { Group } from 'src/app/types/group';
|
|||||||
|
|
||||||
export class AccountMgmtComponent implements OnInit, AfterViewInit {
|
export class AccountMgmtComponent implements OnInit, AfterViewInit {
|
||||||
protected groups: Group[] = []
|
protected groups: Group[] = []
|
||||||
users: MatTableDataSource<any>
|
users: MatTableDataSource<Omit<User, "pass">>
|
||||||
loading = false
|
loading = false
|
||||||
@ViewChild(MatPaginator) paginator!: MatPaginator
|
@ViewChild(MatPaginator) paginator!: MatPaginator
|
||||||
|
|
||||||
constructor(readonly ac:AdminCommService, private dialog: MatDialog, private sb: MatSnackBar, protected readonly ls: LocalStorageService) {
|
constructor(readonly ac:AdminCommService, private dialog: MatDialog, private sb: MatSnackBar, protected readonly ls: LocalStorageService) {
|
||||||
this.users = new MatTableDataSource<any>();
|
this.users = new MatTableDataSource<Omit<User, "pass">>();
|
||||||
this.users.filterPredicate = (data: Record<string, any>, filter: string): boolean => {
|
this.users.filterPredicate = (data: Record<string, any>, filter: string): boolean => {
|
||||||
const dataStr = Object.keys(data).reduce((curr: string, key: string) => {
|
const dataStr = Object.keys(data).reduce((curr: string, key: string) => {
|
||||||
if (key == "_id") {
|
if (["_id", "admin", "groups", "__v", "locked"].find(v => v == key)) {
|
||||||
return ''
|
return curr + ''
|
||||||
}
|
}
|
||||||
return curr + data[key] + '⫂'
|
return curr + data[key] + '⫂'
|
||||||
}, '').toLowerCase()
|
}, '').toLowerCase()
|
||||||
const filternew = filter.trim().toLowerCase()
|
const filternew = filter.trim().toLowerCase()
|
||||||
|
|
||||||
return dataStr.indexOf(filternew) != -1
|
return dataStr.indexOf(filternew) != -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,75 +54,9 @@ export class AccountMgmtComponent implements OnInit, AfterViewInit {
|
|||||||
this.users.filter = value.toLowerCase().trim()
|
this.users.filter = value.toLowerCase().trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
edit(item: any) {
|
openUserCard(id?: string) {
|
||||||
this.dialog.open(UserEditComponent, {data: {user: item, groups: this.groups}}).afterClosed().subscribe(reply => {
|
this.dialog.open<UserEditComponent, UserEditComponent.InputData, UserEditComponent.ReturnData>(UserEditComponent, {data: {id: id, type: id ? "edit" : "new", groups: this.groups}}).afterClosed().subscribe(r => {
|
||||||
if (reply) {
|
if (r) this.ngOnInit()
|
||||||
this.ac.accs.putAcc(item._id, reply).pipe(catchError((err)=>{
|
|
||||||
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
|
|
||||||
return throwError(()=> new Error(err.message))
|
|
||||||
})).subscribe((data)=> {
|
|
||||||
if (data.status == 200) {
|
|
||||||
this.sb.open("Użytkownik został zmodyfikowany.", undefined, {duration: 2500})
|
|
||||||
this.ngOnInit()
|
|
||||||
} else {
|
|
||||||
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
new() {
|
|
||||||
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.")
|
|
||||||
return throwError(()=> new Error(err.message))
|
|
||||||
})).subscribe((data)=> {
|
|
||||||
if (data.status == 201) {
|
|
||||||
this.sb.open("Użytkownik został utworzony.", undefined, {duration: 2500})
|
|
||||||
this.ngOnInit()
|
|
||||||
} else {
|
|
||||||
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(id: string) {
|
|
||||||
this.dialog.open(UserDeleteComponent).afterClosed().subscribe(reply => {
|
|
||||||
if (reply) {
|
|
||||||
this.ac.accs.deleteAcc(id).subscribe((res) => {
|
|
||||||
if (res.status == 200) {
|
|
||||||
this.sb.open("Użytkownik został usunięty.", undefined, {duration: 2500})
|
|
||||||
this.ngOnInit()
|
|
||||||
} else {
|
|
||||||
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
|
|
||||||
console.error(res);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
resetPass(id: string) {
|
|
||||||
this.dialog.open(UserResetComponent).afterClosed().subscribe((res) => {
|
|
||||||
if (res == true) {
|
|
||||||
this.ac.accs.resetPass(id).subscribe((patch)=>{
|
|
||||||
if (patch.status == 200) {
|
|
||||||
this.sb.open("Hasło zostało zresetowane", undefined, {duration: 2500})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleLock(item: any) {
|
|
||||||
this.ac.accs.putAcc(item._id, {locked: !item.locked}).subscribe((res) => {
|
|
||||||
if (res.status == 200) {
|
|
||||||
item.locked = !item.locked
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +1,67 @@
|
|||||||
<form [formGroup]="form" (ngSubmit)="editUser()">
|
<h1 mat-dialog-title>Karta użytkownika</h1>
|
||||||
<mat-form-field appearance="outline">
|
<mat-dialog-content>
|
||||||
<mat-label>Imię</mat-label>
|
<form [formGroup]="form">
|
||||||
<input type="text" matInput formControlName="fname">
|
<div>
|
||||||
</mat-form-field>
|
<mat-form-field appearance="outline" color="accent">
|
||||||
<mat-form-field appearance="outline">
|
<mat-label>Imię</mat-label>
|
||||||
<mat-label>Nazwisko</mat-label>
|
<input type="text" matInput formControlName="fname">
|
||||||
<input type="text" matInput formControlName="surname">
|
</mat-form-field>
|
||||||
</mat-form-field>
|
<mat-form-field appearance="outline" color="accent">
|
||||||
<mat-form-field appearance="outline">
|
<mat-label>Nazwisko</mat-label>
|
||||||
<mat-label>Pokój</mat-label>
|
<input type="text" matInput formControlName="surname">
|
||||||
<input type="text" matInput formControlName="room">
|
</mat-form-field>
|
||||||
</mat-form-field>
|
<mat-form-field appearance="outline" color="accent">
|
||||||
<mat-form-field appearance="outline">
|
<mat-label>Pokój</mat-label>
|
||||||
<mat-label>Nazwa użytkownika</mat-label>
|
<input type="text" matInput formControlName="room">
|
||||||
<input type="text" matInput required formControlName="uname">
|
</mat-form-field>
|
||||||
</mat-form-field>
|
<mat-form-field appearance="outline" color="accent">
|
||||||
<mat-form-field appearance="outline">
|
<mat-label>Grupy</mat-label>
|
||||||
<mat-label>Grupy</mat-label>
|
<mat-select multiple formControlName="groups">
|
||||||
<mat-select multiple formControlName="groups">
|
@for (item of groups; track $index) {
|
||||||
@for (item of groups; track $index) {
|
<mat-option [value]="item._id">{{item.name}}</mat-option>
|
||||||
<mat-option [value]="item._id">{{item.name}}</mat-option>
|
}
|
||||||
|
</mat-select>
|
||||||
|
</mat-form-field>
|
||||||
|
<span *ngIf="data.type == 'edit'">Data rejestracji:<br>{{regDate?.format('DD.MM.YYYY')}}</span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<mat-form-field appearance="outline" color="accent">
|
||||||
|
<mat-label>Nazwa użytkownika</mat-label>
|
||||||
|
<input type="text" matInput required formControlName="uname">
|
||||||
|
</mat-form-field>
|
||||||
|
@if (data.type == "edit") {
|
||||||
|
<button mat-stroked-button color="accent" (click)="resetPass()">Resetuj hasło</button>
|
||||||
|
@if (locked) {
|
||||||
|
<button mat-stroked-button color="warn" (click)="toggleLock(false)"><mat-icon>lock</mat-icon>Blokada ręczna</button>
|
||||||
|
} @else {
|
||||||
|
<button mat-stroked-button color="accent" (click)="toggleLock(true)">Zablokuj konto</button>
|
||||||
|
}
|
||||||
|
@if (lockout) {
|
||||||
|
<button mat-stroked-button color="warn" (click)="disableLockout()"><mat-icon>lock_clock</mat-icon>Auto-Blokada</button>
|
||||||
|
} @else {
|
||||||
|
<button mat-stroked-button disabled>Auto-Blokada nieczynna</button>
|
||||||
|
}
|
||||||
|
<mat-form-field *ngIf="ls.permChecker(32)" color="accent">
|
||||||
|
<mat-label>Uprawnienia</mat-label>
|
||||||
|
<mat-select multiple formControlName="flags">
|
||||||
|
<mat-option [value]="1" *ngIf="ls.capCheck(1)">Wiadomości</mat-option>
|
||||||
|
<mat-option [value]="2" *ngIf="ls.capCheck(2)">Jadłospis</mat-option>
|
||||||
|
<mat-option [value]="4" *ngIf="ls.capCheck(4)">Powiadomienia</mat-option>
|
||||||
|
<mat-option [value]="8" *ngIf="ls.capCheck(8)">Grupy</mat-option>
|
||||||
|
<mat-option [value]="16">Konta</mat-option>
|
||||||
|
<mat-option [value]="64" *ngIf="ls.capCheck(32)">Klucze</mat-option>
|
||||||
|
<mat-option [value]="128" *ngIf="ls.capCheck(16)">Czystość</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
</mat-form-field>
|
||||||
}
|
}
|
||||||
</mat-select>
|
</div>
|
||||||
</mat-form-field>
|
</form>
|
||||||
<mat-form-field *ngIf="this.ls.permChecker(32)">
|
</mat-dialog-content>
|
||||||
<mat-label>Uprawnienia</mat-label>
|
<mat-dialog-actions>
|
||||||
<mat-select multiple formControlName="flags">
|
@if (data.type == "edit") {
|
||||||
<mat-option [value]="1" *ngIf="ls.capCheck(1)">Wiadomości</mat-option>
|
<button mat-stroked-button color="warn" style="margin-right: auto;">Usuń konto</button>
|
||||||
<mat-option [value]="2" *ngIf="ls.capCheck(2)">Jadłospis</mat-option>
|
}
|
||||||
<mat-option [value]="4" *ngIf="ls.capCheck(4)">Powiadomienia</mat-option>
|
<button mat-stroked-button mat-dialog-close>Zamknij</button>
|
||||||
<mat-option [value]="8" *ngIf="ls.capCheck(8)">Grupy</mat-option>
|
<button mat-flat-button color="accent" (click)="submit()">Zapisz</button>
|
||||||
<mat-option [value]="16">Konta</mat-option>
|
<mat-spinner diameter="32" color="accent" *ngIf="loading"></mat-spinner>
|
||||||
<mat-option [value]="64" *ngIf="ls.capCheck(32)">Klucze</mat-option>
|
</mat-dialog-actions>
|
||||||
<mat-option [value]="128" *ngIf="ls.capCheck(16)">Czystość</mat-option>
|
|
||||||
</mat-select>
|
|
||||||
</mat-form-field>
|
|
||||||
<button mat-stroked-button>Wyślij</button>
|
|
||||||
</form>
|
|
||||||
@@ -4,7 +4,29 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
form {
|
form {
|
||||||
|
margin-top: 1ch !important;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
grid-auto-flow: column;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
column-gap: 3ch;
|
||||||
|
div {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
grid-template-rows: repeat(5, 1fr);
|
||||||
|
align-items: center;
|
||||||
|
button {
|
||||||
|
align-self: stretch;
|
||||||
|
justify-self: stretch;
|
||||||
|
height: auto;
|
||||||
|
margin-bottom: 1lh;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mat-dialog-actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
@@ -1,52 +1,126 @@
|
|||||||
import { Component, Inject } from '@angular/core';
|
import { Component, Inject } from '@angular/core';
|
||||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
import { MAT_DIALOG_DATA, MatDialog, 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';
|
import { Group } from 'src/app/types/group';
|
||||||
|
import { AdminCommService } from '../../admin-comm.service';
|
||||||
|
import { UserDeleteComponent } from '../user-delete/user-delete.component';
|
||||||
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
|
import { UserResetComponent } from '../user-reset/user-reset.component';
|
||||||
|
import { catchError, throwError } from 'rxjs';
|
||||||
|
import { Moment } from 'moment';
|
||||||
|
import * as moment from 'moment';
|
||||||
|
|
||||||
|
export namespace UserEditComponent {
|
||||||
|
export type InputData = {type: "new" | "edit", id?: string, groups: Group[]}
|
||||||
|
export type ReturnData = true | undefined
|
||||||
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-user-edit',
|
selector: 'app-user-edit',
|
||||||
templateUrl: './user-edit.component.html',
|
templateUrl: './user-edit.component.html',
|
||||||
styleUrls: ['./user-edit.component.scss']
|
styleUrls: ['./user-edit.component.scss']
|
||||||
})
|
})
|
||||||
export class UserEditComponent {
|
export class UserEditComponent {
|
||||||
form: FormGroup
|
lockout = false;
|
||||||
|
locked = false;
|
||||||
|
loading = false;
|
||||||
|
form: FormGroup = new FormGroup({
|
||||||
|
fname: new FormControl<string>(""),
|
||||||
|
surname: new FormControl<string>(""),
|
||||||
|
room: new FormControl<string>(""),
|
||||||
|
uname: new FormControl<string>(""),
|
||||||
|
groups: new FormControl<Array<string>>([]),
|
||||||
|
flags: new FormControl<Array<number>>([]),
|
||||||
|
})
|
||||||
groups: Group[]
|
groups: Group[]
|
||||||
constructor (public dialogRef: MatDialogRef<UserEditComponent>, @Inject(MAT_DIALOG_DATA) public data: any, readonly ls: LocalStorageService) {
|
id?: string
|
||||||
if (data.user == null) {
|
regDate?: Moment;
|
||||||
data.user = {
|
constructor (
|
||||||
fname: "",
|
public dialogRef: MatDialogRef<UserEditComponent>,
|
||||||
surname: "",
|
@Inject(MAT_DIALOG_DATA) public data: UserEditComponent.InputData,
|
||||||
room: "",
|
readonly ls: LocalStorageService,
|
||||||
uname: "",
|
readonly acu: AdminCommService,
|
||||||
groups: [],
|
private dialog: MatDialog,
|
||||||
admin: 0
|
private sb: MatSnackBar
|
||||||
|
) {
|
||||||
|
this.groups = data.groups
|
||||||
|
if (data.type == "edit") {
|
||||||
|
this.id = data.id
|
||||||
|
this.acu.accs.getUser(data.id!).subscribe((r) => {
|
||||||
|
this.regDate = moment(r.regDate)
|
||||||
|
var flags: Array<number> = []
|
||||||
|
if (r.admin) {
|
||||||
|
if ((r.admin & 1) == 1) flags.push(1)
|
||||||
|
if ((r.admin & 2) == 2) flags.push(2)
|
||||||
|
if ((r.admin & 4) == 4) flags.push(4)
|
||||||
|
if ((r.admin & 8) == 8) flags.push(8)
|
||||||
|
if ((r.admin & 16) == 16) flags.push(16)
|
||||||
|
if ((r.admin & 32) == 32) flags.push(32)
|
||||||
|
if ((r.admin & 64) == 64) flags.push(64)
|
||||||
|
if ((r.admin & 128) == 128) flags.push(128)
|
||||||
|
}
|
||||||
|
this.locked = r.locked ? true : false
|
||||||
|
this.lockout = r.lockout
|
||||||
|
this.form.get("fname")?.setValue(r.fname)
|
||||||
|
this.form.get("surname")?.setValue(r.surname)
|
||||||
|
this.form.get("room")?.setValue(r.room)
|
||||||
|
this.form.get("uname")?.setValue(r.uname)
|
||||||
|
this.form.get("groups")?.setValue(r.groups)
|
||||||
|
this.form.get("flags")?.setValue(flags)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected submit() {
|
||||||
|
this.loading = true
|
||||||
|
if (this.data.type == "edit") {
|
||||||
|
this.acu.accs.putAcc(this.id!, this.getForm()).pipe(catchError((err)=>{
|
||||||
|
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
|
||||||
|
return throwError(()=> new Error(err.message))
|
||||||
|
})).subscribe((data)=> {
|
||||||
|
if (data.status == 200) {
|
||||||
|
this.sb.open("Użytkownik został zmodyfikowany.", undefined, {duration: 2500})
|
||||||
|
this.dialogRef.close(true)
|
||||||
|
} else {
|
||||||
|
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
|
||||||
|
this.loading = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.acu.accs.postAcc(this.getForm()).pipe(catchError((err)=>{
|
||||||
|
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
|
||||||
|
return throwError(()=> new Error(err.message))
|
||||||
|
})).subscribe((data)=> {
|
||||||
|
if (data.status == 201) {
|
||||||
|
this.sb.open("Użytkownik został utworzony.", undefined, {duration: 2500})
|
||||||
|
this.dialogRef.close(true)
|
||||||
|
} else {
|
||||||
|
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
|
||||||
|
this.loading = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected disableLockout() {
|
||||||
|
this.loading = true
|
||||||
|
this.acu.accs.clearLockout(this.id!).pipe(catchError((err)=>{
|
||||||
|
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
|
||||||
|
return throwError(()=> new Error(err.message))
|
||||||
|
})).subscribe((s) => {
|
||||||
|
if (s.status == 200) {
|
||||||
|
this.loading = false
|
||||||
|
this.lockout = false
|
||||||
|
} else {
|
||||||
|
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
|
||||||
|
this.loading = false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
this.groups = data.groups ? data.groups : []
|
|
||||||
var flags: Array<number> = []
|
|
||||||
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.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() {
|
protected getForm() {
|
||||||
this.dialogRef.close({
|
return {
|
||||||
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,
|
||||||
@@ -60,6 +134,44 @@ export class UserEditComponent {
|
|||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected delete() {
|
||||||
|
this.dialog.open(UserDeleteComponent).afterClosed().subscribe(reply => {
|
||||||
|
if (reply) {
|
||||||
|
this.acu.accs.deleteAcc(this.id!).subscribe((res) => {
|
||||||
|
if (res.status == 200) {
|
||||||
|
this.sb.open("Użytkownik został usunięty.", undefined, {duration: 2500})
|
||||||
|
this.dialogRef.close()
|
||||||
|
} else {
|
||||||
|
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
|
||||||
|
console.error(res);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
protected resetPass() {
|
||||||
|
this.loading = true
|
||||||
|
this.dialog.open(UserResetComponent).afterClosed().subscribe((res) => {
|
||||||
|
if (res == true) {
|
||||||
|
this.acu.accs.resetPass(this.id!).subscribe((patch)=>{
|
||||||
|
if (patch.status == 200) {
|
||||||
|
this.sb.open("Hasło zostało zresetowane", undefined, {duration: 2500})
|
||||||
|
this.loading = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
protected toggleLock(state: boolean) {
|
||||||
|
this.acu.accs.putAcc(this.id!, {locked: state}).subscribe((res) => {
|
||||||
|
if (res.status == 200) {
|
||||||
|
this.locked = state
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { News } from '../types/news';
|
|||||||
import { AKey } from '../types/key';
|
import { AKey } from '../types/key';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import { IUSettings } from './settings/settings.component';
|
import { IUSettings } from './settings/settings.component';
|
||||||
|
import User from '../types/user';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@@ -121,17 +122,7 @@ export class AdminCommService {
|
|||||||
accs = {
|
accs = {
|
||||||
getAccs: () => {
|
getAccs: () => {
|
||||||
return this.http.get<{
|
return this.http.get<{
|
||||||
users: {
|
users: Omit<User, "pass">[],
|
||||||
_id: string;
|
|
||||||
uname: string;
|
|
||||||
pass: string;
|
|
||||||
room?: string;
|
|
||||||
admin?: number;
|
|
||||||
locked?: boolean;
|
|
||||||
fname?: string;
|
|
||||||
surname?: string;
|
|
||||||
groups: string[];
|
|
||||||
}[],
|
|
||||||
groups: Group[]
|
groups: Group[]
|
||||||
}>(environment.apiEndpoint+`/admin/accs`, {withCredentials: true})
|
}>(environment.apiEndpoint+`/admin/accs`, {withCredentials: true})
|
||||||
},
|
},
|
||||||
@@ -140,7 +131,7 @@ export class AdminCommService {
|
|||||||
return this.http.post<Status>(environment.apiEndpoint+`/admin/accs`, item, {withCredentials: true})
|
return this.http.post<Status>(environment.apiEndpoint+`/admin/accs`, item, {withCredentials: true})
|
||||||
},
|
},
|
||||||
|
|
||||||
putAcc: (id: string, update: object) => {
|
putAcc: (id: string, update: Partial<User>) => {
|
||||||
return this.http.put<Status>(environment.apiEndpoint+`/admin/accs/${id}`, update, {withCredentials: true})
|
return this.http.put<Status>(environment.apiEndpoint+`/admin/accs/${id}`, update, {withCredentials: true})
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -150,6 +141,14 @@ export class AdminCommService {
|
|||||||
|
|
||||||
deleteAcc: (id: string) => {
|
deleteAcc: (id: string) => {
|
||||||
return this.http.delete<Status>(environment.apiEndpoint+`/admin/accs/${id}`, {withCredentials: true})
|
return this.http.delete<Status>(environment.apiEndpoint+`/admin/accs/${id}`, {withCredentials: true})
|
||||||
|
},
|
||||||
|
|
||||||
|
getUser: (id: string) => {
|
||||||
|
return this.http.get<Omit<User, "pass"> & {lockout: boolean}>(environment.apiEndpoint+`/admin/accs/${id}`, {withCredentials: true})
|
||||||
|
},
|
||||||
|
|
||||||
|
clearLockout: (id: string) => {
|
||||||
|
return this.http.delete<Status>(environment.apiEndpoint+`/admin/accs/${id}/lockout`, {withCredentials: true})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
@@ -183,6 +182,17 @@ export class AdminCommService {
|
|||||||
},
|
},
|
||||||
getGroups: () => {
|
getGroups: () => {
|
||||||
return this.http.get<Group[]>(environment.apiEndpoint+"/admin/notif/groups", {withCredentials: true})
|
return this.http.get<Group[]>(environment.apiEndpoint+"/admin/notif/groups", {withCredentials: true})
|
||||||
|
},
|
||||||
|
outbox: {
|
||||||
|
getSent: () => {
|
||||||
|
return this.http.get<{_id: string, sentDate: moment.Moment, title: string}[]>(environment.apiEndpoint+"/admin/notif/outbox", {withCredentials: true})
|
||||||
|
},
|
||||||
|
getBody: (id: string) => {
|
||||||
|
return this.http.get(environment.apiEndpoint+`/admin/notif/outbox/${id}/message`, {withCredentials: true, responseType: "text"})
|
||||||
|
},
|
||||||
|
getRcpts: (id: string) => {
|
||||||
|
return this.http.get<{_id: string, uname: string, room?: string, fname?: string, surname?: string}[]>(environment.apiEndpoint+`/admin/notif/outbox/${id}/rcpts`, {withCredentials: true})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
@@ -236,13 +246,16 @@ export class AdminCommService {
|
|||||||
},
|
},
|
||||||
attendence: {
|
attendence: {
|
||||||
getUsers: (room: string) => {
|
getUsers: (room: string) => {
|
||||||
return this.http.get<{users: {fname: string, surname: string, _id: string}[], attendence?: {id: string, hour?: string}[]}>(environment.apiEndpoint+`/admin/clean/attendence/${room}`, {withCredentials: true})
|
return this.http.get<{users: {fname: string, surname: string, _id: string}[], attendence?: {auto: {id: string, hour?: string}[], notes: string}}>(environment.apiEndpoint+`/admin/clean/attendence/${room}`, {withCredentials: true})
|
||||||
},
|
},
|
||||||
postAttendence: (room: string, attendence: {id: string, hour?: string}[]) => {
|
postAttendence: (room: string, attendence: {auto: {id: string, hour?: string}[], notes: string}) => {
|
||||||
return this.http.post<Status>(environment.apiEndpoint+`/admin/clean/attendence/${room}`, attendence, {withCredentials: true})
|
return this.http.post<Status>(environment.apiEndpoint+`/admin/clean/attendence/${room}`, attendence, {withCredentials: true})
|
||||||
},
|
},
|
||||||
getSummary: () => {
|
getSummary: () => {
|
||||||
return this.http.get<{room: string, hours: string[]}[]>(environment.apiEndpoint+`/admin/clean/attendenceSummary`, {withCredentials: true})
|
return this.http.get<{room: string, hours: string[], notes: string, auto: boolean}[]>(environment.apiEndpoint+`/admin/clean/attendenceSummary`, {withCredentials: true})
|
||||||
|
},
|
||||||
|
deleteRoom: (room: string) => {
|
||||||
|
return this.http.delete<Status>(environment.apiEndpoint+`/admin/clean/attendence/${room}`, {withCredentials: true})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,4 @@
|
|||||||
<mat-toolbar color="accent">
|
<app-toolbar [drawer]="drawer"/>
|
||||||
<button mat-icon-button (click)="drawer.toggle()"><mat-icon>menu</mat-icon></button>
|
|
||||||
<span>{{title.getTitle()}}</span>
|
|
||||||
<span style="flex: 1 1 auto"></span>
|
|
||||||
<button mat-icon-button *ngIf="toolbar.menu" [matMenuTriggerFor]="menu"><mat-icon>more_vert</mat-icon></button>
|
|
||||||
</mat-toolbar>
|
|
||||||
<mat-menu #menu="matMenu">
|
|
||||||
@for (item of toolbar.menu; track $index) {
|
|
||||||
<button mat-menu-item *ngIf="item.check" (click)="toolbar.comp[item.fn]()">
|
|
||||||
<mat-icon *ngIf="item.icon">{{item.icon}}</mat-icon>
|
|
||||||
<span>{{item.title}}</span>
|
|
||||||
</button>
|
|
||||||
}
|
|
||||||
</mat-menu>
|
|
||||||
<mat-sidenav-container>
|
<mat-sidenav-container>
|
||||||
<mat-sidenav #drawer mode="over" autoFocus="false">
|
<mat-sidenav #drawer mode="over" autoFocus="false">
|
||||||
<mat-nav-list>
|
<mat-nav-list>
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { Title } from '@angular/platform-browser';
|
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { LocalStorageService } from '../services/local-storage.service';
|
import { LocalStorageService } from '../services/local-storage.service';
|
||||||
import { Link } from '../types/link';
|
import { Link } from '../types/link';
|
||||||
import { ToolbarService } from './toolbar.service';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-admin-view',
|
selector: 'app-admin-view',
|
||||||
@@ -26,7 +24,7 @@ export class AdminViewComponent {
|
|||||||
public get LINKS(): Link[] {
|
public get LINKS(): Link[] {
|
||||||
return this._LINKS.filter(v => v.enabled);
|
return this._LINKS.filter(v => v.enabled);
|
||||||
}
|
}
|
||||||
constructor(readonly title: Title, readonly router: Router, readonly ls: LocalStorageService, protected toolbar: ToolbarService) { }
|
constructor(readonly router: Router, readonly ls: LocalStorageService) { }
|
||||||
goNormal() {
|
goNormal() {
|
||||||
this.router.navigateByUrl('app')
|
this.router.navigateByUrl('app')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div matColumnDef="hours">
|
<div matColumnDef="hours">
|
||||||
<th mat-header-cell *matHeaderCellDef mat-sort-header>Godziny</th>
|
<th mat-header-cell *matHeaderCellDef mat-sort-header>Godziny</th>
|
||||||
<td mat-cell *matCellDef="let item"><span *ngFor="let i of item.hours.sort().reverse(); let isLast=last"><app-hour-display [value]="i"></app-hour-display>{{ isLast ? '' : ', '}}</span></td>
|
<td mat-cell *matCellDef="let item"><span *ngFor="let i of item.hours.sort().reverse(); let isLast=last"><app-hour-display [value]="i"></app-hour-display>{{ isLast ? '' : ', '}}</span><span>{{item.notes}}</span></td>
|
||||||
|
</div>
|
||||||
|
<div matColumnDef="actions">
|
||||||
|
<th mat-header-cell *matHeaderCellDef>Usuń</th>
|
||||||
|
<td mat-cell *matCellDef="let item"><button mat-mini-fab color="warn" (click)="delete(item.room)" *ngIf="!item.auto"><mat-icon>delete</mat-icon></button></td>
|
||||||
</div>
|
</div>
|
||||||
<tr mat-header-row *matHeaderRowDef="collumns"></tr>
|
<tr mat-header-row *matHeaderRowDef="collumns"></tr>
|
||||||
<tr mat-row *matRowDef="let rowData; columns: collumns"></tr>
|
<tr mat-row *matRowDef="let rowData; columns: collumns"></tr>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { ToolbarService } from '../../toolbar.service';
|
import { ToolbarService } from '../../toolbar/toolbar.service';
|
||||||
import { Router, ActivatedRoute } from '@angular/router';
|
import { Router, ActivatedRoute } from '@angular/router';
|
||||||
import { MatTableDataSource } from '@angular/material/table';
|
import { MatTableDataSource } from '@angular/material/table';
|
||||||
import { AdminCommService } from '../../admin-comm.service';
|
import { AdminCommService } from '../../admin-comm.service';
|
||||||
@@ -11,8 +11,8 @@ import { AdminCommService } from '../../admin-comm.service';
|
|||||||
})
|
})
|
||||||
export class AttendenceSummaryComponent implements OnInit {
|
export class AttendenceSummaryComponent implements OnInit {
|
||||||
|
|
||||||
data: MatTableDataSource<{room: string, hours: string[]}> = new MatTableDataSource<{room: string, hours: string[]}>();
|
data: MatTableDataSource<{room: string, hours: string[], notes: string, auto: boolean}> = new MatTableDataSource<{room: string, hours: string[], notes: string, auto: boolean}>();
|
||||||
collumns = ['room', 'hours']
|
collumns = ['room', 'hours', 'actions']
|
||||||
|
|
||||||
constructor (private toolbar: ToolbarService, private router: Router, private route: ActivatedRoute, private ac: AdminCommService) {
|
constructor (private toolbar: ToolbarService, private router: Router, private route: ActivatedRoute, private ac: AdminCommService) {
|
||||||
this.toolbar.comp = this
|
this.toolbar.comp = this
|
||||||
@@ -21,6 +21,12 @@ export class AttendenceSummaryComponent implements OnInit {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete(room: string) {
|
||||||
|
this.ac.clean.attendence.deleteRoom(room).subscribe(() => {
|
||||||
|
this.ngOnInit()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.ac.clean.attendence.getSummary().subscribe(v => {
|
this.ac.clean.attendence.getSummary().subscribe(v => {
|
||||||
this.data.data = v
|
this.data.data = v
|
||||||
|
|||||||
@@ -11,6 +11,10 @@
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Notatki</mat-label>
|
||||||
|
<input type="text" matInput formControlName="notes">
|
||||||
|
</mat-form-field>
|
||||||
</form>
|
</form>
|
||||||
</mat-dialog-content>
|
</mat-dialog-content>
|
||||||
<mat-dialog-actions>
|
<mat-dialog-actions>
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ import { AdminCommService } from '../../admin-comm.service';
|
|||||||
})
|
})
|
||||||
export class AttendenceComponent implements OnInit {
|
export class AttendenceComponent implements OnInit {
|
||||||
|
|
||||||
constructor (private fb: FormBuilder, @Inject(MAT_DIALOG_DATA) public data: {room: string}, public dialogRef: MatDialogRef<AttendenceComponent>, private ac: AdminCommService) {}
|
constructor(private fb: FormBuilder, @Inject(MAT_DIALOG_DATA) public data: { room: string }, public dialogRef: MatDialogRef<AttendenceComponent>, private ac: AdminCommService) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.room = this.data.room
|
this.room = this.data.room
|
||||||
this.ac.clean.attendence.getUsers(this.room).subscribe(query => {
|
this.ac.clean.attendence.getUsers(this.room).subscribe(query => {
|
||||||
query.users.forEach(v => {
|
query.users.forEach(v => {
|
||||||
var att = query.attendence ? query.attendence.find(z => z.id == v._id) : false
|
var att = query.attendence ? query.attendence.auto.find(z => z.id == v._id) : false
|
||||||
this.users.push(this.fb.group({
|
this.users.push(this.fb.group({
|
||||||
id: v._id,
|
id: v._id,
|
||||||
label: `${v.fname} ${v.surname}`,
|
label: `${v.fname} ${v.surname}`,
|
||||||
@@ -24,6 +24,7 @@ export class AttendenceComponent implements OnInit {
|
|||||||
hour: this.fb.control(att ? att.hour : ""),
|
hour: this.fb.control(att ? att.hour : ""),
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
this.form.get('notes')?.setValue(query.attendence?.notes)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +38,8 @@ export class AttendenceComponent implements OnInit {
|
|||||||
room: string = "";
|
room: string = "";
|
||||||
|
|
||||||
form: FormGroup = this.fb.group({
|
form: FormGroup = this.fb.group({
|
||||||
users: this.fb.array([])
|
users: this.fb.array([]),
|
||||||
|
notes: this.fb.control(""),
|
||||||
})
|
})
|
||||||
|
|
||||||
get users() {
|
get users() {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import * as moment from 'moment';
|
|||||||
import { FormArray, FormBuilder } from '@angular/forms';
|
import { FormArray, FormBuilder } from '@angular/forms';
|
||||||
import { weekendFilter } from 'src/app/fd.da';
|
import { weekendFilter } from 'src/app/fd.da';
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
import { ToolbarService } from '../toolbar.service';
|
import { ToolbarService } from '../toolbar/toolbar.service';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
import { AttendenceComponent } from './attendence/attendence.component';
|
import { AttendenceComponent } from './attendence/attendence.component';
|
||||||
@@ -49,8 +49,8 @@ export class GradesComponent implements OnInit, OnDestroy {
|
|||||||
if (!this.filter(this.date)) this.date.isoWeekday(8);
|
if (!this.filter(this.date)) this.date.isoWeekday(8);
|
||||||
this.toolbar.comp = this
|
this.toolbar.comp = this
|
||||||
this.toolbar.menu = [
|
this.toolbar.menu = [
|
||||||
|
{ title: "Pokoje do sprawdzenia", check: true, fn: "attendenceSummary", icon: "overview"},
|
||||||
{ title: "Podsumowanie", check: true, fn: "summary", icon: "analytics" },
|
{ title: "Podsumowanie", check: true, fn: "summary", icon: "analytics" },
|
||||||
{ title: "Obecność", check: true, fn: "attendenceSummary", icon: "overview"}
|
|
||||||
]
|
]
|
||||||
this.form.valueChanges.subscribe((v) => {
|
this.form.valueChanges.subscribe((v) => {
|
||||||
this.calculate()
|
this.calculate()
|
||||||
@@ -164,7 +164,8 @@ export class GradesComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
attendence() {
|
attendence() {
|
||||||
this.dialog.open(AttendenceComponent, {data: {room: this.room}}).afterClosed().subscribe((v: {room: string, users: {att: boolean, id: string, hour: string}[]}) => {
|
this.dialog.open(AttendenceComponent, {data: {room: this.room}}).afterClosed().subscribe((v: {room: string, users: {att: boolean, id: string, hour: string}[], notes: string}) => {
|
||||||
|
if (!v) return
|
||||||
let x: {room: string, users: {id: string, hour?: string}[]} = {
|
let x: {room: string, users: {id: string, hour?: string}[]} = {
|
||||||
room: v.room,
|
room: v.room,
|
||||||
users: []
|
users: []
|
||||||
@@ -174,7 +175,7 @@ export class GradesComponent implements OnInit, OnDestroy {
|
|||||||
x.users.push({id: i.id, hour: i.hour})
|
x.users.push({id: i.id, hour: i.hour})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
this.ac.clean.attendence.postAttendence(x.room, x.users).subscribe((s) => {
|
this.ac.clean.attendence.postAttendence(x.room, {auto: x.users, notes: v.notes}).subscribe((s) => {
|
||||||
if (s.status == 200) {
|
if (s.status == 200) {
|
||||||
this.sb.open("Zapisano obecność!", undefined, {duration: 1500})
|
this.sb.open("Zapisano obecność!", undefined, {duration: 1500})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
||||||
import { ToolbarService } from '../../toolbar.service';
|
import { ToolbarService } from '../../toolbar/toolbar.service';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { AdminCommService } from '../../admin-comm.service';
|
import { AdminCommService } from '../../admin-comm.service';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
</mat-chip-listbox>
|
</mat-chip-listbox>
|
||||||
<button mat-icon-button (click)="new()"><mat-icon>add</mat-icon></button>
|
<button mat-icon-button (click)="new()"><mat-icon>add</mat-icon></button>
|
||||||
</div>
|
</div>
|
||||||
<mat-spinner *ngIf="loading"></mat-spinner>
|
<mat-spinner *ngIf="loading" color="accent"></mat-spinner>
|
||||||
<table mat-table [dataSource]="keys">
|
<table mat-table [dataSource]="keys">
|
||||||
<div matColumnDef="room">
|
<div matColumnDef="room">
|
||||||
<th mat-header-cell *matHeaderCellDef>Sala</th>
|
<th mat-header-cell *matHeaderCellDef>Sala</th>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<mat-dialog-content>
|
<mat-dialog-content>
|
||||||
<form (ngSubmit)="send()" [formGroup]="form">
|
<form (ngSubmit)="send()" [formGroup]="form">
|
||||||
<mat-form-field>
|
<mat-form-field color="accent">
|
||||||
<mat-label>Sala</mat-label>
|
<mat-label>Sala</mat-label>
|
||||||
<mat-select formControlName="room" required>
|
<mat-select formControlName="room" required>
|
||||||
@for (item of rooms; track $index) {
|
@for (item of rooms; track $index) {
|
||||||
@@ -9,17 +9,9 @@
|
|||||||
</mat-select>
|
</mat-select>
|
||||||
<mat-error *ngIf="form.controls['room'].hasError('required')">Wymagane</mat-error>
|
<mat-error *ngIf="form.controls['room'].hasError('required')">Wymagane</mat-error>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-form-field>
|
<mat-form-field color="accent">
|
||||||
<mat-label>Wypożyczający</mat-label>
|
<mat-label>Wypożyczający</mat-label>
|
||||||
<!-- TODO: Add user selector -->
|
<app-user-search formControlName="user" required/>
|
||||||
<input matInput placeholder="Nazwa użytkownika" formControlName="user" required>
|
|
||||||
<!-- <input #input matInput placeholder="Nazwa użytkownika" formControlName="user" required [matAutocomplete]="auto" (input)="filter()">
|
|
||||||
<mat-autocomplete requireSelection #auto="matAutocomplete">
|
|
||||||
@for (item of unames; track item) {
|
|
||||||
<mat-option [value]="item">{{item}}</mat-option>
|
|
||||||
}
|
|
||||||
</mat-autocomplete> -->
|
|
||||||
<mat-error *ngIf="form.controls['user'].hasError('unf')">Zła nazwa użytkownika</mat-error>
|
|
||||||
<mat-error *ngIf="form.controls['user'].hasError('required')">Wymagane</mat-error>
|
<mat-error *ngIf="form.controls['user'].hasError('required')">Wymagane</mat-error>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<button mat-button>Wyślij</button>
|
<button mat-button>Wyślij</button>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { AdminCommService } from '../../admin-comm.service';
|
import { AdminCommService } from '../../admin-comm.service';
|
||||||
import { MatDialogRef } from '@angular/material/dialog';
|
import { MatDialogRef } from '@angular/material/dialog';
|
||||||
import { FormControl, FormGroup } from '@angular/forms';
|
import { FormControl, FormGroup } from '@angular/forms';
|
||||||
import { startWith } from 'rxjs';
|
import { UserSearchResult } from 'src/app/commonComponents/user-search/user-search.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-new-key',
|
selector: 'app-new-key',
|
||||||
@@ -10,11 +10,10 @@ import { startWith } from 'rxjs';
|
|||||||
styleUrl: './new-key.component.scss'
|
styleUrl: './new-key.component.scss'
|
||||||
})
|
})
|
||||||
export class NewKeyComponent implements OnInit {
|
export class NewKeyComponent implements OnInit {
|
||||||
// @ViewChild('input') input!: ElementRef<HTMLInputElement>
|
|
||||||
rooms: string[] = []
|
rooms: string[] = []
|
||||||
form = new FormGroup({
|
form = new FormGroup({
|
||||||
room: new FormControl<string>(""),
|
room: new FormControl<string>(""),
|
||||||
user: new FormControl<string>("")
|
user: new FormControl<UserSearchResult | null>(null)
|
||||||
})
|
})
|
||||||
unames: any[] = []
|
unames: any[] = []
|
||||||
constructor ( private ac: AdminCommService, public dialogRef: MatDialogRef<NewKeyComponent> ) {}
|
constructor ( private ac: AdminCommService, public dialogRef: MatDialogRef<NewKeyComponent> ) {}
|
||||||
@@ -24,26 +23,11 @@ export class NewKeyComponent implements OnInit {
|
|||||||
this.rooms = v
|
this.rooms = v
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter() {
|
|
||||||
// const v = this.input.nativeElement.value
|
|
||||||
// console.log(v);
|
|
||||||
|
|
||||||
// if (v) {
|
|
||||||
// this.ac.userFilter(v.toLowerCase()).subscribe((v) => {
|
|
||||||
// this.unames = v
|
|
||||||
// })
|
|
||||||
// } else {
|
|
||||||
// this.unames = []
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
send() {
|
send() {
|
||||||
if (this.form.valid) {
|
if (this.form.valid) {
|
||||||
this.dialogRef.close(this.form.value)
|
this.dialogRef.close(this.form.value)
|
||||||
} else {
|
}
|
||||||
this.form.controls['user'].setErrors({unf: true})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<h1 mat-dialog-title>Dodawanie</h1>
|
<h1 mat-dialog-title>Tworzenie wpisów do jadłospisu</h1>
|
||||||
<mat-dialog-content>
|
<mat-dialog-content>
|
||||||
<mat-radio-group [(ngModel)]="type">
|
<mat-radio-group [(ngModel)]="type">
|
||||||
<mat-radio-button value="day">Dzień</mat-radio-button>
|
<mat-radio-button value="day">Dzień</mat-radio-button>
|
||||||
@@ -28,6 +28,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</mat-dialog-content>
|
</mat-dialog-content>
|
||||||
<mat-dialog-actions>
|
<mat-dialog-actions>
|
||||||
<button mat-raised-button color="accent" (click)="submit()">Wyślij</button>
|
<button mat-raised-button color="accent" (click)="submit()">Utwórz pozycje</button>
|
||||||
<button mat-button mat-dialog-close>Anuluj</button>
|
<button mat-button mat-dialog-close>Anuluj</button>
|
||||||
</mat-dialog-actions>
|
</mat-dialog-actions>
|
||||||
@@ -31,7 +31,7 @@ export class MenuAddComponent {
|
|||||||
submit() {
|
submit() {
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case "day":
|
case "day":
|
||||||
this.dialogRef.close({type: "day", value: this.day.utc()})
|
this.dialogRef.close({type: "day", value: this.day.utc().startOf('day')})
|
||||||
break;
|
break;
|
||||||
case "week":
|
case "week":
|
||||||
this.dialogRef.close({type: "week", value: {start: this.range.value.start?.utc().hours(24), count: 5}})
|
this.dialogRef.close({type: "week", value: {start: this.range.value.start?.utc().hours(24), count: 5}})
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AfterViewInit, Component, ViewChild } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { FormControl, FormGroup } from '@angular/forms';
|
import { FormControl, FormGroup } from '@angular/forms';
|
||||||
import { MAT_DATE_RANGE_SELECTION_STRATEGY } from '@angular/material/datepicker';
|
import { MAT_DATE_RANGE_SELECTION_STRATEGY } from '@angular/material/datepicker';
|
||||||
import { Moment } from 'moment';
|
import { Moment } from 'moment';
|
||||||
@@ -54,10 +54,10 @@ export class MenuNewComponent {
|
|||||||
if (data) {
|
if (data) {
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case "day":
|
case "day":
|
||||||
this.ac.menu.new.single(data.value).subscribe()
|
this.ac.menu.new.single(data.value).subscribe(s => this.refreshIfGood(s))
|
||||||
break;
|
break;
|
||||||
case "week":
|
case "week":
|
||||||
this.ac.menu.new.range(data.value.start, data.value.count).subscribe()
|
this.ac.menu.new.range(data.value.start, data.value.count).subscribe(s => this.refreshIfGood(s))
|
||||||
break;
|
break;
|
||||||
case "file":
|
case "file":
|
||||||
this.requestData()
|
this.requestData()
|
||||||
@@ -87,7 +87,7 @@ export class MenuNewComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private refreshIfGood(s: Status) {
|
private refreshIfGood(s: Status) {
|
||||||
if (s.status == 200) {
|
if (s.status.toString().match(/2\d\d/)) {
|
||||||
this.requestData()
|
this.requestData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,25 +100,20 @@ export class MenuNewComponent {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
editDay(v: string | string[], element: Menu) {
|
|
||||||
v = v as string
|
|
||||||
element.day = moment(v, "DD.MM.YYYY", true).utc(true).startOf('day')
|
|
||||||
}
|
|
||||||
|
|
||||||
editSn(id: string) {
|
editSn(id: string) {
|
||||||
this.ac.menu.editSn(id, this.dataSource.data.find(v => v._id == id)?.sn).subscribe(this.refreshIfGood)
|
this.ac.menu.editSn(id, this.dataSource.data.find(v => v._id == id)!.sn).subscribe(s => this.refreshIfGood(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
editOb(id: string) {
|
editOb(id: string) {
|
||||||
this.ac.menu.editOb(id, this.dataSource.data.find(v => v._id == id)?.ob).subscribe(this.refreshIfGood)
|
this.ac.menu.editOb(id, this.dataSource.data.find(v => v._id == id)!.ob).subscribe(s => this.refreshIfGood(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
editKol(id: string) {
|
editKol(id: string) {
|
||||||
this.ac.menu.editKol(id, this.dataSource.data.find(v => v._id == id)?.kol).subscribe(this.refreshIfGood)
|
this.ac.menu.editKol(id, this.dataSource.data.find(v => v._id == id)?.kol).subscribe(s => this.refreshIfGood(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
editTitle(id: string) {
|
editTitle(id: string) {
|
||||||
this.ac.menu.editTitle(id, this.dataSource.data.find(v => v._id == id)?.dayTitle).subscribe(this.refreshIfGood)
|
this.ac.menu.editTitle(id, this.dataSource.data.find(v => v._id == id)?.dayTitle).subscribe(s => this.refreshIfGood(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
getStat(day: moment.Moment, m: "ob" | "kol") {
|
getStat(day: moment.Moment, m: "ob" | "kol") {
|
||||||
@@ -126,6 +121,6 @@ export class MenuNewComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
remove(id: string) {
|
remove(id: string) {
|
||||||
this.ac.menu.rm(id).subscribe(this.refreshIfGood)
|
this.ac.menu.rm(id).subscribe(s => this.refreshIfGood(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,4 +22,9 @@
|
|||||||
<mat-card-footer>
|
<mat-card-footer>
|
||||||
<p>{{item.date | date:'d-LL-yyyy HH:mm'}}</p>
|
<p>{{item.date | date:'d-LL-yyyy HH:mm'}}</p>
|
||||||
</mat-card-footer>
|
</mat-card-footer>
|
||||||
|
</mat-card>
|
||||||
|
<mat-card *ngIf="news.length == 0">
|
||||||
|
<p>
|
||||||
|
Brak wiadomości.
|
||||||
|
</p>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
@@ -22,6 +22,10 @@ mat-card-content p {
|
|||||||
white-space: pre-line;
|
white-space: pre-line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mat-card p {
|
||||||
|
margin: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
margin-right: 4pt;
|
margin-right: 4pt;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
<!-- TODO: Remake the notifications module -->
|
|
||||||
<form [formGroup]="form" (ngSubmit)="submit()">
|
<form [formGroup]="form" (ngSubmit)="submit()">
|
||||||
<div formGroupName="recp">
|
<div formGroupName="recp">
|
||||||
<mat-radio-group formControlName="type">
|
<mat-radio-group formControlName="type">
|
||||||
<mat-radio-button value="uname">
|
<mat-radio-button value="uid">
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-label>Nazwa użytkownika</mat-label>
|
<mat-label>Użytkownik</mat-label>
|
||||||
<input matInput type="text" formControlName="uname">
|
<app-user-search formControlName="uid" required/>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</mat-radio-button>
|
</mat-radio-button>
|
||||||
<mat-radio-button value="room">
|
<mat-radio-button value="room">
|
||||||
|
|||||||
@@ -1,20 +1,32 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { FormControl, FormGroup } from '@angular/forms';
|
import { FormControl, FormGroup } from '@angular/forms';
|
||||||
import { AdminCommService } from '../admin-comm.service';
|
import { AdminCommService } from '../admin-comm.service';
|
||||||
import { Notification } from 'src/app/types/notification';
|
import { Notification } from 'src/app/types/notification';
|
||||||
import { Group } from 'src/app/types/group';
|
import { Group } from 'src/app/types/group';
|
||||||
import { LocalStorageService } from 'src/app/services/local-storage.service';
|
import { LocalStorageService } from 'src/app/services/local-storage.service';
|
||||||
|
import { ToolbarService } from '../toolbar/toolbar.service';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
import { UserSearchResult } from 'src/app/commonComponents/user-search/user-search.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-notifications',
|
selector: 'app-notifications',
|
||||||
templateUrl: './notifications.component.html',
|
templateUrl: './notifications.component.html',
|
||||||
styleUrls: ['./notifications.component.scss']
|
styleUrls: ['./notifications.component.scss']
|
||||||
})
|
})
|
||||||
export class NotificationsComponent implements OnInit {
|
export class NotificationsComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
groups!: Group[]
|
groups!: Group[]
|
||||||
|
|
||||||
constructor (private readonly acs: AdminCommService, readonly ls: LocalStorageService) { }
|
constructor (private readonly acs: AdminCommService, readonly ls: LocalStorageService, private toolbar: ToolbarService, private router: Router, private route: ActivatedRoute ) {
|
||||||
|
this.toolbar.comp = this
|
||||||
|
this.toolbar.menu = [
|
||||||
|
{ title: "Wysłane", fn: "outbox", icon: "outbox" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
outbox() {
|
||||||
|
this.router.navigate(["outbox"], { relativeTo: this.route })
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.acs.notif.getGroups().subscribe((v) => {
|
this.acs.notif.getGroups().subscribe((v) => {
|
||||||
@@ -22,11 +34,20 @@ export class NotificationsComponent implements OnInit {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.toolbar.comp = undefined
|
||||||
|
this.toolbar.menu = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
public inbox() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
success?: { sent: number; possible: number; };
|
success?: { sent: number; possible: number; };
|
||||||
|
|
||||||
form = new FormGroup<NotificationForm>({
|
form = new FormGroup({
|
||||||
recp: new FormGroup({
|
recp: new FormGroup({
|
||||||
uname: new FormControl<string>(''),
|
uid: new FormControl<UserSearchResult | null>(null),
|
||||||
room: new FormControl<string|null>(null),
|
room: new FormControl<string|null>(null),
|
||||||
group: new FormControl<string>(''),
|
group: new FormControl<string>(''),
|
||||||
type: new FormControl<"room" | "uname" | "group">('uname', {nonNullable: true})
|
type: new FormControl<"room" | "uname" | "group">('uname', {nonNullable: true})
|
||||||
@@ -36,19 +57,8 @@ export class NotificationsComponent implements OnInit {
|
|||||||
})
|
})
|
||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
this.acs.notif.send(this.form.value as Notification).subscribe((data) => {
|
this.acs.notif.send({...this.form.value, recp: {...this.form.get("recp")?.value, uid: this.form.controls['recp'].controls['uid'].value?._id}} as Notification).subscribe((data) => {
|
||||||
this.success = data
|
this.success = data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NotificationForm {
|
|
||||||
body: FormControl<string>;
|
|
||||||
title: FormControl<string>;
|
|
||||||
recp: FormGroup<{
|
|
||||||
uname: FormControl<string | null>;
|
|
||||||
room: FormControl<string | null>;
|
|
||||||
group: FormControl<string | null>;
|
|
||||||
type: FormControl<"room" | "uname" | "group">;
|
|
||||||
}>
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<mat-card>
|
||||||
|
<mat-card-header>
|
||||||
|
<mat-card-title-group>
|
||||||
|
<mat-card-title>
|
||||||
|
{{item.title}}
|
||||||
|
</mat-card-title>
|
||||||
|
<mat-card-subtitle>{{item.sentDate.format('[Wysłano] dddd DD MMMM YYYYr. o HH:mm')}}</mat-card-subtitle>
|
||||||
|
</mat-card-title-group>
|
||||||
|
</mat-card-header>
|
||||||
|
<mat-card-content>
|
||||||
|
<p *ngIf="body">
|
||||||
|
{{body}}
|
||||||
|
</p>
|
||||||
|
<hr>
|
||||||
|
<ul>
|
||||||
|
@for (user of rcpts; track $index) {
|
||||||
|
<li>
|
||||||
|
<span *ngIf="user.room">{{user.room}}: </span>{{user.fname}} {{user.surname}} <span
|
||||||
|
style="color: gray">({{user.uname}})</span>
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
</mat-card-content>
|
||||||
|
<mat-card-footer>
|
||||||
|
<mat-card-actions>
|
||||||
|
<button mat-stroked-button (click)="getMessage()" *ngIf="!body">Wczytaj treść</button>
|
||||||
|
<button mat-stroked-button (click)="getRcpts()" *ngIf="!rcpts">Wczytaj odbiorców</button>
|
||||||
|
<mat-spinner diameter="32" color="accent" *ngIf="loading"></mat-spinner>
|
||||||
|
</mat-card-actions>
|
||||||
|
</mat-card-footer>
|
||||||
|
</mat-card>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
mat-card-title {
|
||||||
|
font-size: 24pt;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { MessageComponent } from './message.component';
|
||||||
|
|
||||||
|
describe('MessageComponent', () => {
|
||||||
|
let component: MessageComponent;
|
||||||
|
let fixture: ComponentFixture<MessageComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [MessageComponent]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(MessageComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { Component, Input } from '@angular/core';
|
||||||
|
import { AdminCommService } from 'src/app/admin-view/admin-comm.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-message',
|
||||||
|
templateUrl: './message.component.html',
|
||||||
|
styleUrl: './message.component.scss'
|
||||||
|
})
|
||||||
|
export class MessageComponent {
|
||||||
|
@Input() item!: {_id: string, sentDate: moment.Moment, title: string}
|
||||||
|
body?: string
|
||||||
|
rcpts?: {_id: string, uname: string, room?: string, fname?: string, surname?: string}[]
|
||||||
|
loading: boolean = false
|
||||||
|
constructor (readonly acu: AdminCommService) {}
|
||||||
|
|
||||||
|
getMessage() {
|
||||||
|
this.loading = true
|
||||||
|
this.acu.notif.outbox.getBody(this.item._id).subscribe(v => {
|
||||||
|
this.body = v
|
||||||
|
this.loading = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
getRcpts() {
|
||||||
|
this.loading = true
|
||||||
|
this.acu.notif.outbox.getRcpts(this.item._id).subscribe(v => {
|
||||||
|
this.rcpts = v
|
||||||
|
this.loading = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<p>Wysłane wiadomości:</p>
|
||||||
|
<div class="cardContainer">
|
||||||
|
@for (item of messages; track $index) {
|
||||||
|
<app-message [item]="item"></app-message>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
.cardContainer {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 1ch;
|
||||||
|
margin: 1ch;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { OutboxComponent } from './outbox.component';
|
||||||
|
|
||||||
|
describe('OutboxComponent', () => {
|
||||||
|
let component: OutboxComponent;
|
||||||
|
let fixture: ComponentFixture<OutboxComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [OutboxComponent]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(OutboxComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
42
src/app/admin-view/notifications/outbox/outbox.component.ts
Normal file
42
src/app/admin-view/notifications/outbox/outbox.component.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { AdminCommService } from '../../admin-comm.service';
|
||||||
|
import { Router, ActivatedRoute } from '@angular/router';
|
||||||
|
import { ToolbarService } from '../../toolbar/toolbar.service';
|
||||||
|
import * as moment from 'moment';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-outbox',
|
||||||
|
templateUrl: './outbox.component.html',
|
||||||
|
styleUrl: './outbox.component.scss'
|
||||||
|
})
|
||||||
|
export class OutboxComponent implements OnInit {
|
||||||
|
|
||||||
|
messages!: {
|
||||||
|
_id: string;
|
||||||
|
sentDate: moment.Moment;
|
||||||
|
title: string;
|
||||||
|
}[]
|
||||||
|
|
||||||
|
constructor (private readonly acs: AdminCommService, private toolbar: ToolbarService, private router: Router, private route: ActivatedRoute ) {
|
||||||
|
this.toolbar.comp = this
|
||||||
|
this.toolbar.menu = [
|
||||||
|
{ title: "Powiadomienia", fn: "goBack", icon: "arrow_back" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
goBack() {
|
||||||
|
this.router.navigate(['../'], {relativeTo: this.route})
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.acs.notif.outbox.getSent().subscribe((v) => {
|
||||||
|
this.messages = v.map(i => {
|
||||||
|
return {
|
||||||
|
...i,
|
||||||
|
sentDate: moment(i.sentDate)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<mat-accordion>
|
<mat-accordion>
|
||||||
|
<!-- #region Rooms-->
|
||||||
<mat-expansion-panel>
|
<mat-expansion-panel>
|
||||||
<!-- TODO: Make more ergonomic -->
|
<!-- TODO: Make more ergonomic -->
|
||||||
<mat-expansion-panel-header>
|
<mat-expansion-panel-header>
|
||||||
@@ -8,6 +9,8 @@
|
|||||||
<p>Kliknij listę aby edytować</p>
|
<p>Kliknij listę aby edytować</p>
|
||||||
<app-list-editor [converter]="usettings.rooms" (edit)="saveRoom($event)"></app-list-editor>
|
<app-list-editor [converter]="usettings.rooms" (edit)="saveRoom($event)"></app-list-editor>
|
||||||
</mat-expansion-panel>
|
</mat-expansion-panel>
|
||||||
|
<!-- #endregion -->
|
||||||
|
<!-- #region Room grade reasons-->
|
||||||
<mat-expansion-panel>
|
<mat-expansion-panel>
|
||||||
<mat-expansion-panel-header>
|
<mat-expansion-panel-header>
|
||||||
<mat-panel-title>Powody nieczystości</mat-panel-title>
|
<mat-panel-title>Powody nieczystości</mat-panel-title>
|
||||||
@@ -16,6 +19,8 @@
|
|||||||
<p>Kliknij listę aby edytować</p>
|
<p>Kliknij listę aby edytować</p>
|
||||||
<app-list-editor [list]="usettings.cleanThings" (edit)="saveCleanThings($event)"></app-list-editor>
|
<app-list-editor [list]="usettings.cleanThings" (edit)="saveCleanThings($event)"></app-list-editor>
|
||||||
</mat-expansion-panel>
|
</mat-expansion-panel>
|
||||||
|
<!-- #endregion -->
|
||||||
|
<!-- #region Key rooms-->
|
||||||
<mat-expansion-panel>
|
<mat-expansion-panel>
|
||||||
<mat-expansion-panel-header>
|
<mat-expansion-panel-header>
|
||||||
<mat-panel-title>Sale z kluczami</mat-panel-title>
|
<mat-panel-title>Sale z kluczami</mat-panel-title>
|
||||||
@@ -23,6 +28,68 @@
|
|||||||
</mat-expansion-panel-header>
|
</mat-expansion-panel-header>
|
||||||
<app-list-editor [list]="usettings.keyrooms" (edit)="saveKeyrooms($event)"></app-list-editor>
|
<app-list-editor [list]="usettings.keyrooms" (edit)="saveKeyrooms($event)"></app-list-editor>
|
||||||
</mat-expansion-panel>
|
</mat-expansion-panel>
|
||||||
|
<!-- #endregion -->
|
||||||
|
<!-- #region Default menu items-->
|
||||||
|
<mat-expansion-panel>
|
||||||
|
<mat-expansion-panel-header>
|
||||||
|
<mat-panel-title>Domyślne wpisy jadłospisu</mat-panel-title>
|
||||||
|
<mat-panel-description></mat-panel-description>
|
||||||
|
</mat-expansion-panel-header>
|
||||||
|
<table>
|
||||||
|
<caption>Domyślne wpisy w jadłospisie dla danych pozycji</caption>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Śniadanie</th>
|
||||||
|
<th>Kolacja</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<app-list-editor [list]="usettings.menu.defaultItems.sn" (edit)="saveSn($event)"/>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<app-list-editor [list]="usettings.menu.defaultItems.kol" (edit)="saveKol($event)"/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</mat-expansion-panel>
|
||||||
|
<!-- #endregion -->
|
||||||
|
<!-- #region Security-->
|
||||||
|
<mat-expansion-panel>
|
||||||
|
<mat-expansion-panel-header>
|
||||||
|
<mat-panel-title>Bezpieczeństwo</mat-panel-title>
|
||||||
|
</mat-expansion-panel-header>
|
||||||
|
<mat-tab-group color="accent">
|
||||||
|
<mat-tab label="Konta">
|
||||||
|
<p>
|
||||||
|
Domyślne hasło użytkownika po wygenerowaniu konto to <code>pierwszelogowanie</code><br>
|
||||||
|
Reset hasła powoduje zmianę na <code>reset</code>
|
||||||
|
</p>
|
||||||
|
<form [formGroup]="accSec" (submit)="saveAccSecTimeouts()">
|
||||||
|
<p>Ograniczenia logowania</p>
|
||||||
|
<mat-form-field color="accent">
|
||||||
|
<mat-label>Dozwolone próby logowania</mat-label>
|
||||||
|
<input matInput type="number" formControlName="attempts">
|
||||||
|
</mat-form-field><br>
|
||||||
|
<mat-form-field color="accent">
|
||||||
|
<mat-label>Okres liczenia prób</mat-label>
|
||||||
|
<input matInput type="number" formControlName="time">
|
||||||
|
<mat-hint>Podaj w minutach</mat-hint>
|
||||||
|
</mat-form-field><br>
|
||||||
|
<mat-form-field color="accent">
|
||||||
|
<mat-label>Czas blokady konta</mat-label>
|
||||||
|
<input matInput type="number" formControlName="lockout">
|
||||||
|
<mat-hint>Podaj w minutach</mat-hint>
|
||||||
|
</mat-form-field><br>
|
||||||
|
<button mat-flat-button color="accent">Zapisz</button>
|
||||||
|
</form>
|
||||||
|
</mat-tab>
|
||||||
|
</mat-tab-group>
|
||||||
|
</mat-expansion-panel>
|
||||||
|
<!-- #endregion -->
|
||||||
|
<!-- #region Program control-->
|
||||||
<mat-expansion-panel>
|
<mat-expansion-panel>
|
||||||
<mat-expansion-panel-header>
|
<mat-expansion-panel-header>
|
||||||
<mat-panel-title>Sterowanie programem</mat-panel-title>
|
<mat-panel-title>Sterowanie programem</mat-panel-title>
|
||||||
@@ -41,4 +108,5 @@
|
|||||||
Wyloguj wszystkich użytkowników
|
Wyloguj wszystkich użytkowników
|
||||||
</button> -->
|
</button> -->
|
||||||
</mat-expansion-panel>
|
</mat-expansion-panel>
|
||||||
|
<!-- #endregion -->
|
||||||
</mat-accordion>
|
</mat-accordion>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { AdminCommService } from '../admin-comm.service';
|
import { AdminCommService } from '../admin-comm.service';
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
|
import { FormBuilder } from '@angular/forms';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-settings',
|
selector: 'app-settings',
|
||||||
@@ -11,10 +12,18 @@ export class SettingsComponent implements OnInit {
|
|||||||
usettings!: IUSettings
|
usettings!: IUSettings
|
||||||
reloadTimeout: boolean = false;
|
reloadTimeout: boolean = false;
|
||||||
|
|
||||||
constructor (private readonly acu: AdminCommService, private readonly sb: MatSnackBar) { }
|
constructor (private readonly acu: AdminCommService, private readonly sb: MatSnackBar, private readonly fb: FormBuilder) { }
|
||||||
|
|
||||||
|
accSec = this.fb.nonNullable.group({
|
||||||
|
attempts: this.fb.nonNullable.control(1),
|
||||||
|
time: this.fb.nonNullable.control(1),
|
||||||
|
lockout: this.fb.nonNullable.control(1),
|
||||||
|
})
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.acu.settings.getAll().subscribe((r) => {
|
this.acu.settings.getAll().subscribe((r) => {
|
||||||
this.usettings = r
|
this.usettings = r
|
||||||
|
this.accSecTimeouts = r.security.loginTimeout
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,10 +40,39 @@ export class SettingsComponent implements OnInit {
|
|||||||
this.send()
|
this.send()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saveSn(event: string[]) {
|
||||||
|
this.usettings.menu.defaultItems.sn = event
|
||||||
|
this.send()
|
||||||
|
}
|
||||||
|
saveKol(event: string[]) {
|
||||||
|
this.usettings.menu.defaultItems.kol = event
|
||||||
|
this.send()
|
||||||
|
}
|
||||||
|
|
||||||
|
saveAccSecTimeouts() {
|
||||||
|
this.usettings.security.loginTimeout = this.accSecTimeouts
|
||||||
|
this.send()
|
||||||
|
}
|
||||||
|
|
||||||
|
set accSecTimeouts(value: IUSettings['security']['loginTimeout']) {
|
||||||
|
this.accSec.setValue({
|
||||||
|
attempts: value.attempts,
|
||||||
|
lockout: value.lockout / 60,
|
||||||
|
time: value.time / 60
|
||||||
|
})
|
||||||
|
}
|
||||||
|
get accSecTimeouts(): IUSettings['security']['loginTimeout'] {
|
||||||
|
return {
|
||||||
|
attempts: this.accSec.controls['attempts'].value,
|
||||||
|
lockout: this.accSec.controls['lockout'].value * 60,
|
||||||
|
time: this.accSec.controls['time'].value * 60
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
send() {
|
send() {
|
||||||
this.acu.settings.post(this.usettings).subscribe((s) => {
|
this.acu.settings.post(this.usettings).subscribe((s) => {
|
||||||
if (s.status == 200) {
|
if (s.status == 200) {
|
||||||
this.sb.open("Zapisano!", undefined, {duration: 1000})
|
this.sb.open("Zapisano!", undefined, { duration: 1000 })
|
||||||
} else {
|
} else {
|
||||||
console.error(s);
|
console.error(s);
|
||||||
}
|
}
|
||||||
@@ -51,7 +89,7 @@ export class SettingsComponent implements OnInit {
|
|||||||
}, 5000);
|
}, 5000);
|
||||||
this.acu.settings.reload().subscribe((s) => {
|
this.acu.settings.reload().subscribe((s) => {
|
||||||
if (s.status == 200) {
|
if (s.status == 200) {
|
||||||
this.sb.open("Przeładowano ustawienia!", undefined, {duration: 3000})
|
this.sb.open("Przeładowano ustawienia!", undefined, { duration: 3000 })
|
||||||
} else {
|
} else {
|
||||||
console.error(s);
|
console.error(s);
|
||||||
}
|
}
|
||||||
@@ -63,4 +101,17 @@ export interface IUSettings {
|
|||||||
keyrooms: string[];
|
keyrooms: string[];
|
||||||
rooms: string[];
|
rooms: string[];
|
||||||
cleanThings: string[];
|
cleanThings: string[];
|
||||||
|
menu: {
|
||||||
|
defaultItems: {
|
||||||
|
sn: string[];
|
||||||
|
kol: string[];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
security: {
|
||||||
|
loginTimeout: {
|
||||||
|
attempts: number;
|
||||||
|
time: number;
|
||||||
|
lockout: number;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
1
src/app/admin-view/start/start.component.html
Normal file
1
src/app/admin-view/start/start.component.html
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<span class="main"><mat-icon class="icon">arrow_upward</mat-icon><span>Wybierz zakładkę w menu</span></span>
|
||||||
13
src/app/admin-view/start/start.component.scss
Normal file
13
src/app/admin-view/start/start.component.scss
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
.main {
|
||||||
|
margin-top: 8px;
|
||||||
|
margin-left: 16px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
width: fit-content;
|
||||||
|
height: fit-content;
|
||||||
|
font-size: 32pt;
|
||||||
|
}
|
||||||
23
src/app/admin-view/start/start.component.spec.ts
Normal file
23
src/app/admin-view/start/start.component.spec.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { StartAdminComponent } from './start.component';
|
||||||
|
|
||||||
|
describe('StartComponent', () => {
|
||||||
|
let component: StartAdminComponent;
|
||||||
|
let fixture: ComponentFixture<StartAdminComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [StartAdminComponent]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(StartAdminComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
10
src/app/admin-view/start/start.component.ts
Normal file
10
src/app/admin-view/start/start.component.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-start',
|
||||||
|
templateUrl: './start.component.html',
|
||||||
|
styleUrl: './start.component.scss'
|
||||||
|
})
|
||||||
|
export class StartAdminComponent {
|
||||||
|
|
||||||
|
}
|
||||||
14
src/app/admin-view/toolbar/toolbar.component.html
Normal file
14
src/app/admin-view/toolbar/toolbar.component.html
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<mat-toolbar color="accent">
|
||||||
|
<button mat-icon-button (click)="drawer.toggle()"><mat-icon>menu</mat-icon></button>
|
||||||
|
<span>{{title.getTitle()}}</span>
|
||||||
|
<span style="flex: 1 1 auto"></span>
|
||||||
|
<button mat-icon-button *ngIf="toolbar.menu" [matMenuTriggerFor]="menu" (click)="openMenu()"><mat-icon>more_vert</mat-icon></button>
|
||||||
|
</mat-toolbar>
|
||||||
|
<mat-menu #menu="matMenu">
|
||||||
|
@for (item of _menu; track $index) {
|
||||||
|
<button mat-menu-item *ngIf="item.check ?? true" (click)="toolbar.comp[item.fn]()">
|
||||||
|
<mat-icon *ngIf="item.icon">{{item.icon}}</mat-icon>
|
||||||
|
<span>{{item.title}}</span>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</mat-menu>
|
||||||
0
src/app/admin-view/toolbar/toolbar.component.scss
Normal file
0
src/app/admin-view/toolbar/toolbar.component.scss
Normal file
23
src/app/admin-view/toolbar/toolbar.component.spec.ts
Normal file
23
src/app/admin-view/toolbar/toolbar.component.spec.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ToolbarComponent } from './toolbar.component';
|
||||||
|
|
||||||
|
describe('ToolbarComponent', () => {
|
||||||
|
let component: ToolbarComponent;
|
||||||
|
let fixture: ComponentFixture<ToolbarComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ToolbarComponent]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(ToolbarComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
26
src/app/admin-view/toolbar/toolbar.component.ts
Normal file
26
src/app/admin-view/toolbar/toolbar.component.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { Component, Input, ViewChild } from '@angular/core';
|
||||||
|
import { MatDrawer } from '@angular/material/sidenav';
|
||||||
|
import { Title } from '@angular/platform-browser';
|
||||||
|
import { ToolbarService } from './toolbar.service';
|
||||||
|
import { MatMenuTrigger } from '@angular/material/menu';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-toolbar',
|
||||||
|
templateUrl: './toolbar.component.html',
|
||||||
|
styleUrl: './toolbar.component.scss'
|
||||||
|
})
|
||||||
|
export class ToolbarComponent {
|
||||||
|
@Input() drawer!: MatDrawer;
|
||||||
|
@ViewChild(MatMenuTrigger) trigger!: MatMenuTrigger;
|
||||||
|
|
||||||
|
protected _menu?: typeof this.toolbar.menu
|
||||||
|
|
||||||
|
constructor(readonly title: Title, protected toolbar: ToolbarService) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
openMenu () {
|
||||||
|
this._menu = this.toolbar.menu
|
||||||
|
this.trigger.openMenu()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,9 +6,6 @@ import { Injectable } from '@angular/core';
|
|||||||
export class ToolbarService {
|
export class ToolbarService {
|
||||||
|
|
||||||
public comp?: any;
|
public comp?: any;
|
||||||
public menu?: {title: string, check: boolean, icon?: string, fn: string}[]
|
public menu?: {title: string, check?: boolean, icon?: string, fn: string}[]
|
||||||
|
|
||||||
constructor() { }
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,6 @@ import { LocalStorageService } from './services/local-storage.service';
|
|||||||
|
|
||||||
export const adminGuard: CanActivateChildFn = (childRoute, state) => {
|
export const adminGuard: CanActivateChildFn = (childRoute, state) => {
|
||||||
const router = inject(Router)
|
const router = inject(Router)
|
||||||
if (inject(LocalStorageService).admin == false) return router.parseUrl('/')
|
if (inject(LocalStorageService).admin == undefined) return router.parseUrl('/')
|
||||||
return true
|
return true
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ import { SummaryComponent } from './admin-view/grades/summary/summary.component'
|
|||||||
import { SettingsComponent } from './admin-view/settings/settings.component';
|
import { SettingsComponent } from './admin-view/settings/settings.component';
|
||||||
import { AttendenceSummaryComponent } from './admin-view/grades/attendence-summary/attendence-summary.component';
|
import { AttendenceSummaryComponent } from './admin-view/grades/attendence-summary/attendence-summary.component';
|
||||||
import { NotificationsComponent } from './admin-view/notifications/notifications.component';
|
import { NotificationsComponent } from './admin-view/notifications/notifications.component';
|
||||||
|
import { OutboxComponent } from './admin-view/notifications/outbox/outbox.component';
|
||||||
|
import { StartAdminComponent } from './admin-view/start/start.component';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{path: "", redirectTo: "login", pathMatch: "full"},
|
{path: "", redirectTo: "login", pathMatch: "full"},
|
||||||
@@ -30,10 +32,14 @@ const routes: Routes = [
|
|||||||
{path: "grades", component: PersonalComponent, title: "Konto"}
|
{path: "grades", component: PersonalComponent, title: "Konto"}
|
||||||
]},
|
]},
|
||||||
{path: "admin", component: AdminViewComponent, title: "Panel administracyjny", canActivateChild: [authGuard, adminGuard], children: [
|
{path: "admin", component: AdminViewComponent, title: "Panel administracyjny", canActivateChild: [authGuard, adminGuard], children: [
|
||||||
|
{path: "", pathMatch: "full", component: StartAdminComponent},
|
||||||
{path: "news", title: "Edytowanie wiadomości", component: NewsEditComponent},
|
{path: "news", title: "Edytowanie wiadomości", component: NewsEditComponent},
|
||||||
{path: "menu", title: "Edytowanie jadłospisu", component: MenuNewComponent},
|
{path: "menu", title: "Edytowanie jadłospisu", component: MenuNewComponent},
|
||||||
{path: "accounts", title: "Użytkownicy", component: AccountMgmtComponent},
|
{path: "accounts", title: "Użytkownicy", component: AccountMgmtComponent},
|
||||||
{path: "notifications", title: "Powiadomienia", component: NotificationsComponent},
|
{path: "notifications", children: [
|
||||||
|
{path: "", pathMatch: "full", title: "Powiadomienia", component: NotificationsComponent},
|
||||||
|
{path: "outbox", title: "Wysłane", component: OutboxComponent}
|
||||||
|
]},
|
||||||
{path: "groups", title: "Grupy", component: GroupsComponent},
|
{path: "groups", title: "Grupy", component: GroupsComponent},
|
||||||
{path: "keys", title: "Klucze", component: AdminKeyComponent},
|
{path: "keys", title: "Klucze", component: AdminKeyComponent},
|
||||||
{path: "grades", children: [
|
{path: "grades", children: [
|
||||||
|
|||||||
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
:host {
|
:host {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
@supports (-webkit-touch-callout: none) {
|
||||||
|
height: 95vh;
|
||||||
|
}
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { Link } from '../types/link';
|
|||||||
import { LocalStorageService } from '../services/local-storage.service';
|
import { LocalStorageService } from '../services/local-storage.service';
|
||||||
import { interval } from 'rxjs';
|
import { interval } from 'rxjs';
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
|
import { NotifDialogComponent } from './notif-dialog/notif-dialog.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-app-view',
|
selector: 'app-app-view',
|
||||||
@@ -25,7 +27,14 @@ export class AppViewComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor (private ac: AuthClient, readonly swPush: SwPush, private us: UpdatesService, private ls: LocalStorageService, private sb: MatSnackBar) {}
|
constructor (
|
||||||
|
private ac: AuthClient,
|
||||||
|
readonly swPush: SwPush,
|
||||||
|
private us: UpdatesService,
|
||||||
|
private ls: LocalStorageService,
|
||||||
|
private sb: MatSnackBar,
|
||||||
|
private dialog: MatDialog
|
||||||
|
) {}
|
||||||
|
|
||||||
subscribeToNotif() {
|
subscribeToNotif() {
|
||||||
if (this.swPush.isEnabled && this.ls.capCheck(4)) {
|
if (this.swPush.isEnabled && this.ls.capCheck(4)) {
|
||||||
@@ -45,6 +54,13 @@ export class AppViewComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
newsCheck() {
|
newsCheck() {
|
||||||
|
if (this.ls.capCheck(4)) {
|
||||||
|
this.us.getNotifCheck().subscribe((s) => {
|
||||||
|
s.forEach(v => {
|
||||||
|
this.dialog.open(NotifDialogComponent, {data: v})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
if (this.ls.newsflag) return;
|
if (this.ls.newsflag) return;
|
||||||
this.us.newsCheck().subscribe((s) => {
|
this.us.newsCheck().subscribe((s) => {
|
||||||
if (s.hash != this.ls.newsCheck.hash) {
|
if (s.hash != this.ls.newsCheck.hash) {
|
||||||
|
|||||||
@@ -13,8 +13,8 @@
|
|||||||
<mat-card-content>
|
<mat-card-content>
|
||||||
<ul>
|
<ul>
|
||||||
<li *ngFor="let i of ls.defaultItems.sn">{{i}}</li>
|
<li *ngFor="let i of ls.defaultItems.sn">{{i}}</li>
|
||||||
<li *ngFor="let i of getsn.fancy">{{i.charAt(0).toUpperCase()+i.substring(1)}}</li>
|
<li *ngFor="let i of getsn.fancy">{{capitalize(i)}}</li>
|
||||||
<li *ngIf="getsn.second">{{getsn.second.charAt(0).toUpperCase()+getsn.second.substring(1)}}</li>
|
<li *ngIf="getsn.second">{{capitalize(getsn.second)}}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</mat-card-content>
|
</mat-card-content>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
<button mat-icon-button (click)="vote('kol', '-')"><mat-icon [color]="menu!.kolv == '-' ? 'warn' : null">thumb_down</mat-icon></button>
|
<button mat-icon-button (click)="vote('kol', '-')"><mat-icon [color]="menu!.kolv == '-' ? 'warn' : null">thumb_down</mat-icon></button>
|
||||||
</mat-card-actions>
|
</mat-card-actions>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
<mat-card *ngIf="!(getkol || getob || getsn || loading)">
|
<mat-card *ngIf="!(getkol || getob || getsn || loading || gettitle)">
|
||||||
<mat-card-content id="no-data">
|
<mat-card-content id="no-data">
|
||||||
Brak danych, wybierz inny dzień.
|
Brak danych, wybierz inny dzień.
|
||||||
</mat-card-content>
|
</mat-card-content>
|
||||||
|
|||||||
@@ -32,17 +32,34 @@ export class MenuComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
menu?: Menu;
|
menu?: Menu;
|
||||||
get getsn() {return (this.menu && this.menu.sn) ? this.menu.sn : null}
|
get getsn() {return (this.menu && this.checkIfAnyProperty(this.menu.sn)) ? this.menu.sn : null}
|
||||||
get getob() {return (this.menu && this.menu.ob) ? this.menu.ob : null}
|
get getob() {return (this.menu && this.checkIfAnyProperty(this.menu.ob)) ? this.menu.ob : null}
|
||||||
get getkol() {return (this.menu && this.menu.kol) ? this.menu.kol : null}
|
get getkol() {return (this.menu && this.menu.kol) ? this.menu.kol : null}
|
||||||
get gettitle() {return (this.menu && this.menu.dayTitle && this.menu.dayTitle != "") ? this.menu.dayTitle : null}
|
get gettitle() {return (this.menu && this.menu.dayTitle && this.menu.dayTitle != "") ? this.menu.dayTitle : null}
|
||||||
|
|
||||||
|
private checkIfAnyProperty(obj: { [x: string]: string | string[];}) {
|
||||||
|
for (let i in obj) {
|
||||||
|
if (Array.isArray(obj[i])) {
|
||||||
|
if (obj[i].length > 0) return true
|
||||||
|
} else {
|
||||||
|
if (!!obj[i]) return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
capitalize(str: string) {
|
||||||
|
return str.charAt(0).toUpperCase()+str.substring(1)
|
||||||
|
}
|
||||||
|
|
||||||
updateMenu(silent?: boolean) {
|
updateMenu(silent?: boolean) {
|
||||||
this.loading = !silent
|
this.loading = !silent
|
||||||
if (!silent) this.menu = undefined
|
if (!silent) this.menu = undefined
|
||||||
this.uc.getMenu(this.day).subscribe(m => {
|
this.uc.getMenu(this.day).subscribe(m => {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
this.menu = m
|
this.menu = m
|
||||||
|
console.log(m);
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,4 +9,9 @@
|
|||||||
<mat-card-footer>
|
<mat-card-footer>
|
||||||
<p>{{item.date | date:'d-LL-yyyy HH:mm'}}</p>
|
<p>{{item.date | date:'d-LL-yyyy HH:mm'}}</p>
|
||||||
</mat-card-footer>
|
</mat-card-footer>
|
||||||
|
</mat-card>
|
||||||
|
<mat-card *ngIf="news.length == 0">
|
||||||
|
<p>
|
||||||
|
Brak wiadomości.
|
||||||
|
</p>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
@@ -29,3 +29,7 @@ mat-card-footer p {
|
|||||||
mat-card-content p {
|
mat-card-content p {
|
||||||
white-space: pre-line;
|
white-space: pre-line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mat-card p {
|
||||||
|
margin: 15px;
|
||||||
|
}
|
||||||
10
src/app/app-view/notif-dialog/notif-dialog.component.html
Normal file
10
src/app/app-view/notif-dialog/notif-dialog.component.html
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<h1 mat-dialog-title>{{data.message.title}}</h1>
|
||||||
|
<mat-dialog-content>
|
||||||
|
<p>
|
||||||
|
{{data.message.body}}
|
||||||
|
</p>
|
||||||
|
<div>{{data.sentDate.format("[Wysłano] dddd DD MMMM YYYYr. o HH:mm")}}</div>
|
||||||
|
</mat-dialog-content>
|
||||||
|
<mat-dialog-actions align="end">
|
||||||
|
<button mat-raised-button color="primary" (click)="ack()">Odczytano</button>
|
||||||
|
</mat-dialog-actions>
|
||||||
23
src/app/app-view/notif-dialog/notif-dialog.component.spec.ts
Normal file
23
src/app/app-view/notif-dialog/notif-dialog.component.spec.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { NotifDialogComponent } from './notif-dialog.component';
|
||||||
|
|
||||||
|
describe('NotifDialogComponent', () => {
|
||||||
|
let component: NotifDialogComponent;
|
||||||
|
let fixture: ComponentFixture<NotifDialogComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [NotifDialogComponent]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(NotifDialogComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
27
src/app/app-view/notif-dialog/notif-dialog.component.ts
Normal file
27
src/app/app-view/notif-dialog/notif-dialog.component.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { Component, Inject } from '@angular/core';
|
||||||
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||||
|
import * as moment from 'moment';
|
||||||
|
import { UpdatesService } from 'src/app/services/updates.service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-notif-dialog',
|
||||||
|
templateUrl: './notif-dialog.component.html',
|
||||||
|
styleUrl: './notif-dialog.component.scss'
|
||||||
|
})
|
||||||
|
export class NotifDialogComponent {
|
||||||
|
|
||||||
|
constructor (
|
||||||
|
@Inject(MAT_DIALOG_DATA) public data: {_id: string, message: {title: string, body: string}, sentDate: moment.Moment},
|
||||||
|
public dialogRef: MatDialogRef<NotifDialogComponent>,
|
||||||
|
private uc: UpdatesService
|
||||||
|
) {
|
||||||
|
data.sentDate = moment(data.sentDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
ack () {
|
||||||
|
this.uc.postInfoAck(this.data._id).subscribe((v) => {
|
||||||
|
this.dialogRef.close()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
14
src/app/app-view/personal/extra/extra.component.html
Normal file
14
src/app/app-view/personal/extra/extra.component.html
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<h1 mat-dialog-title>Dodatkowe ustawienia</h1>
|
||||||
|
<mat-dialog-content>
|
||||||
|
<mat-action-list>
|
||||||
|
@for (link of LINKS; track link) {
|
||||||
|
<button mat-list-item (click)="open(link.component)">
|
||||||
|
<mat-icon matListItemIcon *ngIf="link.icon">{{link.icon}}</mat-icon>
|
||||||
|
<div matListItemTitle>{{link.title}}</div>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</mat-action-list>
|
||||||
|
</mat-dialog-content>
|
||||||
|
<mat-dialog-actions align="end">
|
||||||
|
<button mat-dialog-close mat-button>Zamknij</button>
|
||||||
|
</mat-dialog-actions>
|
||||||
23
src/app/app-view/personal/extra/extra.component.spec.ts
Normal file
23
src/app/app-view/personal/extra/extra.component.spec.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ExtraComponent } from './extra.component';
|
||||||
|
|
||||||
|
describe('ExtraComponent', () => {
|
||||||
|
let component: ExtraComponent;
|
||||||
|
let fixture: ComponentFixture<ExtraComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [ExtraComponent]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(ExtraComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
29
src/app/app-view/personal/extra/extra.component.ts
Normal file
29
src/app/app-view/personal/extra/extra.component.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { ComponentType } from '@angular/cdk/portal';
|
||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { Link } from 'src/app/types/link';
|
||||||
|
import { RedirectComponent } from './redirect/redirect.component';
|
||||||
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-extra',
|
||||||
|
templateUrl: './extra.component.html',
|
||||||
|
styleUrl: './extra.component.scss'
|
||||||
|
})
|
||||||
|
export class ExtraComponent {
|
||||||
|
|
||||||
|
constructor (private dialog: MatDialog) {}
|
||||||
|
|
||||||
|
private readonly _LINKS: (Omit<Link, "href"> & {component: ComponentType<any>})[] = [
|
||||||
|
{ title: "Domyślna strona po logowaniu", component: RedirectComponent, enabled: true, icon: "home" }
|
||||||
|
]
|
||||||
|
|
||||||
|
public get LINKS() {
|
||||||
|
return this._LINKS.filter((v) => {
|
||||||
|
return v.enabled
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
open(component: ComponentType<any>) {
|
||||||
|
this.dialog.open(component)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<h1 mat-dialog-title>Domyślna strona po logowaniu</h1>
|
||||||
|
<mat-dialog-content>
|
||||||
|
<p>Wpisz link względem /ipwa/ w poniższym polu.</p>
|
||||||
|
<p>Przykład: /app/menu</p>
|
||||||
|
<p style="color: red">Jeśli nie wiesz co tu wpisać, najlepiej nie zmieniaj tego ustawienia</p>
|
||||||
|
<mat-form-field>
|
||||||
|
<input matInput type="text" [(ngModel)]="redirect">
|
||||||
|
<mat-label>Link</mat-label>
|
||||||
|
</mat-form-field>
|
||||||
|
</mat-dialog-content>
|
||||||
|
<mat-dialog-actions align="end">
|
||||||
|
<button mat-dialog-close mat-button>Anuluj</button>
|
||||||
|
<button (click)="save()" mat-flat-button>Zapisz</button>
|
||||||
|
</mat-dialog-actions>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { RedirectComponent } from './redirect.component';
|
||||||
|
|
||||||
|
describe('RedirectComponent', () => {
|
||||||
|
let component: RedirectComponent;
|
||||||
|
let fixture: ComponentFixture<RedirectComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [RedirectComponent]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(RedirectComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { MatDialogRef } from '@angular/material/dialog';
|
||||||
|
import { AuthClient } from 'src/app/services/auth.client';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-redirect',
|
||||||
|
templateUrl: './redirect.component.html',
|
||||||
|
styleUrl: './redirect.component.scss'
|
||||||
|
})
|
||||||
|
export class RedirectComponent {
|
||||||
|
protected redirect = ""
|
||||||
|
constructor (public dialogRef: MatDialogRef<RedirectComponent>, private ac: AuthClient) {
|
||||||
|
this.redirect = ac.redirect
|
||||||
|
}
|
||||||
|
|
||||||
|
protected save() {
|
||||||
|
this.ac.redirect = this.redirect
|
||||||
|
this.dialogRef.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,10 @@
|
|||||||
<div matListItemTitle>Panel administracyjny</div>
|
<div matListItemTitle>Panel administracyjny</div>
|
||||||
<div matListItemLine>Poprzednio Tryb edycji</div>
|
<div matListItemLine>Poprzednio Tryb edycji</div>
|
||||||
</button>
|
</button>
|
||||||
|
<button mat-list-item (click)="openExtra()">
|
||||||
|
<mat-icon matListItemIcon>settings_applications</mat-icon>
|
||||||
|
<div matListItemTitle>Dodatkowe ustawienia</div>
|
||||||
|
</button>
|
||||||
<button mat-list-item (click)="openAbout()">
|
<button mat-list-item (click)="openAbout()">
|
||||||
<mat-icon matListItemIcon>info</mat-icon>
|
<mat-icon matListItemIcon>info</mat-icon>
|
||||||
<div matListItemTitle>O programie</div>
|
<div matListItemTitle>O programie</div>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { LocalStorageService } from 'src/app/services/local-storage.service';
|
|||||||
import { KeyComponent } from './key/key.component';
|
import { KeyComponent } from './key/key.component';
|
||||||
import { CleanComponent } from './clean/clean.component';
|
import { CleanComponent } from './clean/clean.component';
|
||||||
import { AboutComponent } from './about/about.component';
|
import { AboutComponent } from './about/about.component';
|
||||||
|
import { ExtraComponent } from './extra/extra.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-personal',
|
selector: 'app-personal',
|
||||||
@@ -63,6 +64,10 @@ export class PersonalComponent {
|
|||||||
this.ac.check()
|
this.ac.check()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected openExtra() {
|
||||||
|
this.dialog.open(ExtraComponent)
|
||||||
|
}
|
||||||
|
|
||||||
protected openAbout() {
|
protected openAbout() {
|
||||||
this.dialog.open(AboutComponent)
|
this.dialog.open(AboutComponent)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,15 @@ import { AttendenceComponent } from './admin-view/grades/attendence/attendence.c
|
|||||||
import { AttendenceSummaryComponent } from './admin-view/grades/attendence-summary/attendence-summary.component';
|
import { AttendenceSummaryComponent } from './admin-view/grades/attendence-summary/attendence-summary.component';
|
||||||
import { HourDisplayComponent } from './admin-view/grades/attendence-summary/hour-display/hour-display.component';
|
import { HourDisplayComponent } from './admin-view/grades/attendence-summary/hour-display/hour-display.component';
|
||||||
import { AboutComponent } from './app-view/personal/about/about.component';
|
import { AboutComponent } from './app-view/personal/about/about.component';
|
||||||
|
import { environment } from 'src/environments/environment';
|
||||||
|
import { ExtraComponent } from './app-view/personal/extra/extra.component';
|
||||||
|
import { RedirectComponent } from './app-view/personal/extra/redirect/redirect.component';
|
||||||
|
import { OutboxComponent } from './admin-view/notifications/outbox/outbox.component';
|
||||||
|
import { ToolbarComponent } from './admin-view/toolbar/toolbar.component';
|
||||||
|
import { MessageComponent } from './admin-view/notifications/outbox/message/message.component';
|
||||||
|
import { NotifDialogComponent } from './app-view/notif-dialog/notif-dialog.component';
|
||||||
|
import { UserSearchComponent } from './commonComponents/user-search/user-search.component';
|
||||||
|
import { StartAdminComponent } from './admin-view/start/start.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
@@ -121,6 +130,14 @@ import { AboutComponent } from './app-view/personal/about/about.component';
|
|||||||
AttendenceSummaryComponent,
|
AttendenceSummaryComponent,
|
||||||
HourDisplayComponent,
|
HourDisplayComponent,
|
||||||
AboutComponent,
|
AboutComponent,
|
||||||
|
ExtraComponent,
|
||||||
|
RedirectComponent,
|
||||||
|
OutboxComponent,
|
||||||
|
ToolbarComponent,
|
||||||
|
MessageComponent,
|
||||||
|
NotifDialogComponent,
|
||||||
|
UserSearchComponent,
|
||||||
|
StartAdminComponent,
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
@@ -160,7 +177,7 @@ import { AboutComponent } from './app-view/personal/about/about.component';
|
|||||||
A11yModule,
|
A11yModule,
|
||||||
MatAutocompleteModule,
|
MatAutocompleteModule,
|
||||||
ServiceWorkerModule.register('ngsw-worker.js', {
|
ServiceWorkerModule.register('ngsw-worker.js', {
|
||||||
enabled: !isDevMode(),
|
enabled: environment.production,
|
||||||
// Register the ServiceWorker as soon as the application is stable
|
// Register the ServiceWorker as soon as the application is stable
|
||||||
// or after 30 seconds (whichever comes first).
|
// or after 30 seconds (whichever comes first).
|
||||||
registrationStrategy: 'registerWhenStable:30000'
|
registrationStrategy: 'registerWhenStable:30000'
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<div cdkDropList class="vertical" (cdkDropListDropped)="drop($event)">
|
<div cdkDropList class="vertical" (cdkDropListDropped)="drop($event)">
|
||||||
@for (item of workList; track $index) {
|
@for (item of workList; track $index) {
|
||||||
<span cdkDrag>
|
<span cdkDrag>
|
||||||
<input type="text" [(ngModel)]="workList[$index]" [attr.list]="dataList">
|
<input type="text" [(ngModel)]="workList[$index]" [attr.list]="dataList" (keyup.enter)="addPos($index)" #input>
|
||||||
<select *ngIf="dropdown" [(ngModel)]="workList[$index]">
|
<select *ngIf="dropdown" [(ngModel)]="workList[$index]">
|
||||||
<option *ngFor="let option of options" [value]="option.id" [selected]="option.id == item">{{option.text}}</option>
|
<option *ngFor="let option of options" [value]="option.id" [selected]="option.id == item">{{option.text}}</option>
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
||||||
import { Component, ElementRef, EventEmitter, HostBinding, HostListener, Input, OnChanges, Output, SimpleChanges, ViewChild } from '@angular/core';
|
import { ChangeDetectorRef, Component, ElementRef, EventEmitter, HostBinding, HostListener, Input, OnChanges, Output, QueryList, SimpleChanges, ViewChildren } from '@angular/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-list-editor[list], app-list-editor[converter]',
|
selector: 'app-list-editor[list], app-list-editor[converter]',
|
||||||
@@ -15,10 +15,15 @@ export class ListEditorComponent implements OnChanges {
|
|||||||
@Input() dropdown?: boolean;
|
@Input() dropdown?: boolean;
|
||||||
@Input() dataList?: string;
|
@Input() dataList?: string;
|
||||||
@Output() edit = new EventEmitter<string[]>();
|
@Output() edit = new EventEmitter<string[]>();
|
||||||
|
|
||||||
|
@ViewChildren('input') inputList!: QueryList<ElementRef>
|
||||||
|
|
||||||
protected _list: string[] = [];
|
protected _list: string[] = [];
|
||||||
workList: string[] = [];
|
workList: string[] = [];
|
||||||
focused = false;
|
focused = false;
|
||||||
|
|
||||||
|
constructor (private cdRef: ChangeDetectorRef) {}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges): void {
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
if (this.list) {
|
if (this.list) {
|
||||||
this._list = [...this.list]
|
this._list = [...this.list]
|
||||||
@@ -54,6 +59,8 @@ export class ListEditorComponent implements OnChanges {
|
|||||||
|
|
||||||
addPos(index: number) {
|
addPos(index: number) {
|
||||||
this.workList.splice(index+1, 0, '')
|
this.workList.splice(index+1, 0, '')
|
||||||
|
this.cdRef.detectChanges()
|
||||||
|
this.inputList.get(index+1)?.nativeElement.focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
trackByIndex(index: number, _entry:any) {
|
trackByIndex(index: number, _entry:any) {
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<div role="group" class="app-user-search-container" (focusin)="onFocusIn($event)" (focusout)="onFocusOut($event)">
|
||||||
|
<input type="text" [matAutocomplete]="ac" [formControl]="control" #inputComponent class="input-element">
|
||||||
|
<mat-spinner color="accent" diameter="16" *ngIf="loading" matSuffix></mat-spinner>
|
||||||
|
<mat-autocomplete #ac="matAutocomplete" autoActiveFirstOption (optionSelected)="saveValue($event)" [displayWith]="displayFn">
|
||||||
|
@for (item of list; track $index) {
|
||||||
|
<mat-option [value]="item">
|
||||||
|
@if (item.fname) {
|
||||||
|
{{item.fname}} {{item.surname}} <span *ngIf="item.room" class="room">({{item.room}})</span>
|
||||||
|
} @else {
|
||||||
|
{{item.uname}}
|
||||||
|
}
|
||||||
|
</mat-option>
|
||||||
|
}
|
||||||
|
</mat-autocomplete>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
:host {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1ch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.room {
|
||||||
|
color: gray;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
border: none;
|
||||||
|
background: none;
|
||||||
|
padding: 0;
|
||||||
|
outline: 0;
|
||||||
|
font: inherit;
|
||||||
|
color: currentColor;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { UserSearchComponent } from './user-search.component';
|
||||||
|
|
||||||
|
describe('UserSearchComponent', () => {
|
||||||
|
let component: UserSearchComponent;
|
||||||
|
let fixture: ComponentFixture<UserSearchComponent>;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await TestBed.configureTestingModule({
|
||||||
|
declarations: [UserSearchComponent]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
|
||||||
|
fixture = TestBed.createComponent(UserSearchComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
193
src/app/commonComponents/user-search/user-search.component.ts
Normal file
193
src/app/commonComponents/user-search/user-search.component.ts
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
import { BooleanInput, coerceBooleanProperty } from '@angular/cdk/coercion';
|
||||||
|
import { Component, DoCheck, ElementRef, HostBinding, Input, OnDestroy, Optional, Self } from '@angular/core';
|
||||||
|
import { ControlValueAccessor, FormControl, FormGroupDirective, NgControl, NgForm } from '@angular/forms';
|
||||||
|
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
||||||
|
import { MatFormFieldControl } from '@angular/material/form-field';
|
||||||
|
import { Subject } from 'rxjs';
|
||||||
|
import { AdminCommService } from 'src/app/admin-view/admin-comm.service';
|
||||||
|
|
||||||
|
export interface UserSearchResult {
|
||||||
|
_id: string;
|
||||||
|
fname: string;
|
||||||
|
surname: string;
|
||||||
|
uname: string;
|
||||||
|
room: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-user-search',
|
||||||
|
templateUrl: './user-search.component.html',
|
||||||
|
styleUrl: './user-search.component.scss',
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: MatFormFieldControl,
|
||||||
|
useExisting: UserSearchComponent
|
||||||
|
}
|
||||||
|
],
|
||||||
|
host: {
|
||||||
|
'(blur)': '_onTouched()'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
export class UserSearchComponent implements ControlValueAccessor, MatFormFieldControl<UserSearchResult>, OnDestroy, DoCheck {
|
||||||
|
protected loading: boolean = false
|
||||||
|
control: FormControl = new FormControl();
|
||||||
|
protected list: UserSearchResult[] = []
|
||||||
|
private timeout?: NodeJS.Timeout
|
||||||
|
private _onChange!: (_: UserSearchResult) => void
|
||||||
|
private _onTouched!: any
|
||||||
|
|
||||||
|
static nextId = 0;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
public get value(): UserSearchResult | null {
|
||||||
|
return this.control.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set value(value: UserSearchResult | null) {
|
||||||
|
this.control.setValue(value)
|
||||||
|
this.stateChanges.next()
|
||||||
|
}
|
||||||
|
|
||||||
|
touched = false
|
||||||
|
|
||||||
|
stateChanges = new Subject<void>();
|
||||||
|
|
||||||
|
@HostBinding() id: string = `app-user-search-${UserSearchComponent.nextId++}`;
|
||||||
|
|
||||||
|
private _placeholder: string = "";
|
||||||
|
@Input()
|
||||||
|
public get placeholder(): string {
|
||||||
|
return this._placeholder;
|
||||||
|
}
|
||||||
|
public set placeholder(value: string) {
|
||||||
|
this._placeholder = value;
|
||||||
|
this.stateChanges.next()
|
||||||
|
}
|
||||||
|
|
||||||
|
focused: boolean = false;
|
||||||
|
onFocusIn(event: FocusEvent) {
|
||||||
|
if (!this.focused) {
|
||||||
|
this.focused = true;
|
||||||
|
this.stateChanges.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onFocusOut(event: FocusEvent) {
|
||||||
|
if (!this._elementRef.nativeElement.contains(event.relatedTarget as Element)) {
|
||||||
|
this.touched = true
|
||||||
|
this.focused = false;
|
||||||
|
this._onTouched();
|
||||||
|
this.stateChanges.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get empty(): boolean {
|
||||||
|
return !this.control.value
|
||||||
|
}
|
||||||
|
@HostBinding('class.floating')
|
||||||
|
get shouldLabelFloat(): boolean {
|
||||||
|
return this.focused || !this.empty
|
||||||
|
}
|
||||||
|
private _required: boolean = false;
|
||||||
|
@Input()
|
||||||
|
public get required(): boolean {
|
||||||
|
return this._required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set required(value: BooleanInput) {
|
||||||
|
this._required = coerceBooleanProperty(value);
|
||||||
|
this.stateChanges.next()
|
||||||
|
}
|
||||||
|
|
||||||
|
private _disabled: boolean = false;
|
||||||
|
@Input()
|
||||||
|
public get disabled(): boolean {
|
||||||
|
return this._disabled;
|
||||||
|
}
|
||||||
|
public set disabled(value: BooleanInput) {
|
||||||
|
this._disabled = coerceBooleanProperty(value);
|
||||||
|
this._disabled ? this.control.disable() : this.control.enable()
|
||||||
|
this.stateChanges.next()
|
||||||
|
}
|
||||||
|
errorState: boolean = false
|
||||||
|
controlType?: string | undefined = "app-user-search";
|
||||||
|
autofilled?: boolean | undefined;
|
||||||
|
@Input('aria-describedby') userAriaDescribedBy?: string;
|
||||||
|
setDescribedByIds(ids: string[]): void {
|
||||||
|
const controlElement = this._elementRef.nativeElement.querySelector('.app-user-search-container')!;
|
||||||
|
controlElement.setAttribute('aria-describedby', ids.join(' '))
|
||||||
|
}
|
||||||
|
onContainerClick(event: MouseEvent): void {
|
||||||
|
if ((event.target as Element).tagName.toLowerCase() != 'input') {
|
||||||
|
this._elementRef.nativeElement.querySelector('input').focus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
readonly acu: AdminCommService,
|
||||||
|
@Optional() @Self() public ngControl: NgControl,
|
||||||
|
@Optional() private _parentForm: NgForm,
|
||||||
|
@Optional() private _parentFormGroup: FormGroupDirective,
|
||||||
|
private _elementRef: ElementRef
|
||||||
|
) {
|
||||||
|
if (this.ngControl != null) {
|
||||||
|
(this.ngControl as NgControl).valueAccessor = this
|
||||||
|
}
|
||||||
|
this.control.valueChanges.subscribe(() => {
|
||||||
|
if (typeof this.control.value == "object") return;
|
||||||
|
this.loading = true
|
||||||
|
if (this.timeout) clearTimeout(this.timeout)
|
||||||
|
this.timeout = setTimeout(() => {
|
||||||
|
this.acu.userFilter(this.control.value).subscribe(v => {
|
||||||
|
this.list = v
|
||||||
|
this.loading = false
|
||||||
|
})
|
||||||
|
}, 500)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
ngDoCheck(): void {
|
||||||
|
if (this.ngControl) {
|
||||||
|
this.updateErrorState()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private updateErrorState() {
|
||||||
|
const parent = this._parentFormGroup || this._parentForm
|
||||||
|
|
||||||
|
const oldState = this.errorState;
|
||||||
|
const newState = (this.ngControl?.invalid || this.control.invalid) && (this.touched || parent.submitted);
|
||||||
|
|
||||||
|
if (oldState !== newState) {
|
||||||
|
this.errorState = newState
|
||||||
|
this.stateChanges.next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.stateChanges.complete()
|
||||||
|
}
|
||||||
|
|
||||||
|
writeValue(obj: UserSearchResult): void {
|
||||||
|
this.value = obj
|
||||||
|
}
|
||||||
|
|
||||||
|
registerOnChange(fn: (_: UserSearchResult) => void): void {
|
||||||
|
this._onChange = fn
|
||||||
|
}
|
||||||
|
|
||||||
|
registerOnTouched(fn: any): void {
|
||||||
|
this._onTouched = fn
|
||||||
|
}
|
||||||
|
|
||||||
|
setDisabledState?(isDisabled: boolean): void {
|
||||||
|
this.disabled = isDisabled
|
||||||
|
}
|
||||||
|
|
||||||
|
protected displayFn(u: UserSearchResult): string {
|
||||||
|
if (!u) return ''
|
||||||
|
return u.fname ? `${u.fname} ${u.surname}` : u.uname
|
||||||
|
}
|
||||||
|
|
||||||
|
protected saveValue(e: MatAutocompleteSelectedEvent) {
|
||||||
|
this.autofilled = true
|
||||||
|
this.value = e.option.value
|
||||||
|
this._onChange(this.value!)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,30 +22,18 @@ export class LoginComponent implements OnInit {
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.ls.loggedIn) {
|
if (this.ls.loggedIn) {
|
||||||
this.router.navigateByUrl('app')
|
this.router.navigateByUrl(this.ac.redirect || 'app')
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
errorParser(err: any) {
|
|
||||||
switch (err.status) {
|
|
||||||
case 401:
|
|
||||||
this.error = "Zła nazwa użytkownika lub hasło"
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
this.error = "Nieznany błąd"
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
const val = this.form.value
|
const val = this.form.value
|
||||||
this.ac.login(val.uname, val.pass).pipe(catchError((err,caught)=>{
|
this.ac.login(val.uname, val.pass).pipe(catchError((err,caught)=>{
|
||||||
this.errorParser(err)
|
this.error = err.error.message
|
||||||
return throwError(() => new Error(err.message))
|
return throwError(() => new Error(err.message))
|
||||||
})).subscribe((data) => {
|
})).subscribe((data) => {
|
||||||
this.ls.loggedIn = true
|
this.ls.loggedIn = true
|
||||||
this.router.navigateByUrl('app')
|
this.router.navigateByUrl(this.ac.redirect || 'app')
|
||||||
if (data.admin) {
|
if (data.admin) {
|
||||||
this.ls.admin = data.admin
|
this.ls.admin = data.admin
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,21 @@ import { catchError, concat, first, from, interval, tap, throwError } from 'rxjs
|
|||||||
})
|
})
|
||||||
export class AppUpdateService implements OnInit {
|
export class AppUpdateService implements OnInit {
|
||||||
|
|
||||||
constructor(readonly appRef: ApplicationRef, readonly update: SwUpdate, readonly sb: MatSnackBar) { }
|
constructor(readonly appRef: ApplicationRef, readonly update: SwUpdate, readonly sb: MatSnackBar) {
|
||||||
|
this.update.versionUpdates.subscribe((evt) => {
|
||||||
|
switch (evt.type) {
|
||||||
|
case 'VERSION_DETECTED':
|
||||||
|
console.log(`Downloading ${evt.version.hash}`);
|
||||||
|
break;
|
||||||
|
case 'VERSION_READY':
|
||||||
|
console.log(`Current: ${evt.currentVersion.hash}, new: ${evt.latestVersion.hash}`);
|
||||||
|
break;
|
||||||
|
case 'VERSION_INSTALLATION_FAILED':
|
||||||
|
console.error(`Failed to install ${evt.version.hash}: ${evt.error}`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
const appIsStable = this.appRef.isStable.pipe(first(isStable => isStable === true))
|
const appIsStable = this.appRef.isStable.pipe(first(isStable => isStable === true))
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { catchError, EMPTY, throwError } from 'rxjs';
|
import { catchError, EMPTY, tap, throwError } from 'rxjs';
|
||||||
import { environment } from 'src/environments/environment';
|
import { environment } from 'src/environments/environment';
|
||||||
import { LocalStorageService } from './local-storage.service';
|
import { LocalStorageService } from './local-storage.service';
|
||||||
import { Status } from '../types/status';
|
import { Status } from '../types/status';
|
||||||
@@ -12,11 +12,22 @@ import { Status } from '../types/status';
|
|||||||
export class AuthClient {
|
export class AuthClient {
|
||||||
constructor(private http: HttpClient, private router: Router, private ls: LocalStorageService) { }
|
constructor(private http: HttpClient, private router: Router, private ls: LocalStorageService) { }
|
||||||
|
|
||||||
|
private _redirect: string = "";
|
||||||
|
public get redirect(): string {
|
||||||
|
return this._redirect;
|
||||||
|
}
|
||||||
|
public set redirect(value: string) {
|
||||||
|
this._redirect = value;
|
||||||
|
this.putRedirect(value).subscribe()
|
||||||
|
}
|
||||||
|
|
||||||
public login(uname: string, pass: string) {
|
public login(uname: string, pass: string) {
|
||||||
return this.http.post<any>(environment.apiEndpoint + '/auth/login', {
|
return this.http.post<Status & {admin: number, redirect: string}>(environment.apiEndpoint + '/auth/login', {
|
||||||
username: uname,
|
username: uname,
|
||||||
password: pass
|
password: pass
|
||||||
}, {withCredentials: true})
|
}, {withCredentials: true}).pipe(tap((v) => {
|
||||||
|
if (v.redirect) this._redirect = v.redirect
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
public logout() {
|
public logout() {
|
||||||
@@ -24,15 +35,26 @@ export class AuthClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public check() {
|
public check() {
|
||||||
this.http.get(environment.apiEndpoint + '/auth/check', {withCredentials: true}).pipe(catchError((err) => {
|
this.http.get<{
|
||||||
|
admin?: number,
|
||||||
|
room?: string,
|
||||||
|
features: number,
|
||||||
|
menu: {
|
||||||
|
defaultItems: {
|
||||||
|
sn: string[];
|
||||||
|
kol: string[];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
vapid: string
|
||||||
|
}>(environment.apiEndpoint + '/auth/check', {withCredentials: true}).pipe(catchError((err) => {
|
||||||
if (err.status == 401 && this.ls.loggedIn) {
|
if (err.status == 401 && this.ls.loggedIn) {
|
||||||
this.ls.logOut()
|
this.ls.logOut()
|
||||||
this.router.navigateByUrl("/login")
|
this.router.navigateByUrl("/login")
|
||||||
return EMPTY
|
return EMPTY
|
||||||
}
|
}
|
||||||
return throwError(() => new Error(err.message))
|
return throwError(() => new Error(err.message))
|
||||||
})).subscribe((data: any)=>{
|
})).subscribe((data)=>{
|
||||||
if (data.admin) { this.ls.admin = data.admin } else { this.ls.admin = false }
|
this.ls.admin = data.admin
|
||||||
if (this.ls.capFlag != data.features) {
|
if (this.ls.capFlag != data.features) {
|
||||||
this.ls.capFlag = data.features
|
this.ls.capFlag = data.features
|
||||||
document.location.reload()
|
document.location.reload()
|
||||||
@@ -48,4 +70,8 @@ export class AuthClient {
|
|||||||
public chpass(oldpass:string,newpass:string) {
|
public chpass(oldpass:string,newpass:string) {
|
||||||
return this.http.post(environment.apiEndpoint + '/auth/chpass', {"oldPass": oldpass, "newPass": newpass}, {withCredentials: true, responseType: "text"})
|
return this.http.post(environment.apiEndpoint + '/auth/chpass', {"oldPass": oldpass, "newPass": newpass}, {withCredentials: true, responseType: "text"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private putRedirect(redirect: string) {
|
||||||
|
return this.http.put<Status>(environment.apiEndpoint + '/auth/redirect', {redirect: redirect}, {withCredentials: true})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ export class LocalStorageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logOut() {
|
logOut() {
|
||||||
this.loggedIn = false
|
this.loggedIn = undefined
|
||||||
this.admin = false
|
this.admin = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
public hasRoom() {
|
public hasRoom() {
|
||||||
@@ -26,11 +26,11 @@ export class LocalStorageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get room() {
|
get room() {
|
||||||
return localStorage.getItem('room')!
|
return localStorage.getItem('room') ?? undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
set room(value: string) {
|
set room(value: string | undefined) {
|
||||||
if (value == "") {
|
if (!value) {
|
||||||
localStorage.removeItem('room')
|
localStorage.removeItem('room')
|
||||||
} else {
|
} else {
|
||||||
localStorage.setItem('room', value)
|
localStorage.setItem('room', value)
|
||||||
@@ -49,10 +49,10 @@ export class LocalStorageService {
|
|||||||
if (localStorage.getItem("loggedIn")) {
|
if (localStorage.getItem("loggedIn")) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
set loggedIn(is: boolean) {
|
set loggedIn(is: true | undefined) {
|
||||||
if (is) {
|
if (is) {
|
||||||
localStorage.setItem("loggedIn", "true")
|
localStorage.setItem("loggedIn", "true")
|
||||||
} else {
|
} else {
|
||||||
@@ -60,7 +60,7 @@ export class LocalStorageService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
set admin(newInt: number | false) {
|
set admin(newInt: number | undefined) {
|
||||||
if (newInt) {
|
if (newInt) {
|
||||||
localStorage.setItem("admin", newInt.toString())
|
localStorage.setItem("admin", newInt.toString())
|
||||||
} else {
|
} else {
|
||||||
@@ -70,7 +70,7 @@ export class LocalStorageService {
|
|||||||
|
|
||||||
get admin() {
|
get admin() {
|
||||||
var lsa = localStorage.getItem("admin")
|
var lsa = localStorage.getItem("admin")
|
||||||
return lsa ? Number.parseInt(lsa) : false
|
return lsa ? Number.parseInt(lsa) : undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
set amgreg(toggle: boolean) {
|
set amgreg(toggle: boolean) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import * as moment from 'moment';
|
|||||||
import { map } from 'rxjs';
|
import { map } from 'rxjs';
|
||||||
import { UKey } from '../types/key';
|
import { UKey } from '../types/key';
|
||||||
import { CleanNote } from '../types/clean-note';
|
import { CleanNote } from '../types/clean-note';
|
||||||
|
import { Status } from '../types/status';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@@ -55,4 +56,12 @@ export class UpdatesService {
|
|||||||
getClean(date: moment.Moment) {
|
getClean(date: moment.Moment) {
|
||||||
return this.http.get<{grade: number, notes: CleanNote[], tips: string}>(environment.apiEndpoint+`/app/clean/${date.toISOString()}`, {withCredentials: true})
|
return this.http.get<{grade: number, notes: CleanNote[], tips: string}>(environment.apiEndpoint+`/app/clean/${date.toISOString()}`, {withCredentials: true})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getNotifCheck() {
|
||||||
|
return this.http.get<{_id: string, message: {title: string, body: string}, sentDate: moment.Moment}[]>(environment.apiEndpoint+`/app/notif/check`, {withCredentials: true})
|
||||||
|
}
|
||||||
|
|
||||||
|
postInfoAck(id: string) {
|
||||||
|
return this.http.post<Status>(environment.apiEndpoint+`/app/notif/${id}/ack`, undefined, {withCredentials: true})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import { Moment } from "moment";
|
|||||||
export interface Menu {
|
export interface Menu {
|
||||||
_id: string;
|
_id: string;
|
||||||
day: Moment;
|
day: Moment;
|
||||||
sn?: {
|
sn: {
|
||||||
fancy: string[];
|
fancy: string[];
|
||||||
second: string;
|
second: string;
|
||||||
};
|
};
|
||||||
ob?: {
|
ob: {
|
||||||
soup: string;
|
soup: string;
|
||||||
vege: string;
|
vege: string;
|
||||||
meal: string;
|
meal: string;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ export interface Notification {
|
|||||||
body: string;
|
body: string;
|
||||||
title: string;
|
title: string;
|
||||||
recp: {
|
recp: {
|
||||||
uname: string | null;
|
uid: string | null;
|
||||||
room: string | null;
|
room: string | null;
|
||||||
type: "all" | "room" | "uname"
|
type: "all" | "room" | "uname"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
export interface Status {
|
export interface Status {
|
||||||
status: number
|
status: number,
|
||||||
|
message?: string
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/app/types/user.ts
Normal file
15
src/app/types/user.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { Moment } from "moment";
|
||||||
|
|
||||||
|
export default interface User {
|
||||||
|
_id: string;
|
||||||
|
uname: string;
|
||||||
|
pass: string;
|
||||||
|
room?: string;
|
||||||
|
admin?: number;
|
||||||
|
locked?: boolean;
|
||||||
|
fname?: string;
|
||||||
|
surname?: string;
|
||||||
|
groups: string[];
|
||||||
|
regDate: Moment;
|
||||||
|
defaultPage?: string;
|
||||||
|
}
|
||||||
5
src/environments/environment.swdev.ts
Normal file
5
src/environments/environment.swdev.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export const environment = {
|
||||||
|
apiEndpoint: `http://localhost:12230`,
|
||||||
|
version: "testing (swDev)",
|
||||||
|
production: true
|
||||||
|
};
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
export const environment = {
|
export const environment = {
|
||||||
apiEndpoint: `${window.location.origin}/api`,
|
apiEndpoint: `${window.location.origin}/api`,
|
||||||
version: "v1.0.0",
|
version: "v1.1.0",
|
||||||
production: true
|
production: true
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user