diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..1e4e282 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,8 @@ +angular.json +compose.yml +*.md +tsconfig*.json +*.html +.vscode +package*.json +ngsw-config.json diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..1867496 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "arrowParens": "avoid", + "semi": false, + "trailingComma": "es5", + "bracketSpacing": true +} diff --git a/package-lock.json b/package-lock.json index 5a89392..b773019 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,6 +40,7 @@ "karma-coverage": "~2.2.0", "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.0.0", + "prettier": "3.5.3", "typescript": "~5.8.3" } }, @@ -7794,6 +7795,22 @@ "dev": true, "license": "MIT" }, + "node_modules/prettier": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.3.tgz", + "integrity": "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/proc-log": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/proc-log/-/proc-log-5.0.0.tgz", diff --git a/package.json b/package.json index 8e8b97e..7f76fa4 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "karma-coverage": "~2.2.0", "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.0.0", + "prettier": "3.5.3", "typescript": "~5.8.3" } } diff --git a/src/app/admin-view/account-mgmt/account-mgmt.component.scss b/src/app/admin-view/account-mgmt/account-mgmt.component.scss index 4ba8bd5..390db66 100644 --- a/src/app/admin-view/account-mgmt/account-mgmt.component.scss +++ b/src/app/admin-view/account-mgmt/account-mgmt.component.scss @@ -1,23 +1,23 @@ :host { - display: flex; - flex-direction: column; - height: 100%; + display: flex; + flex-direction: column; + height: 100%; } mat-paginator { - margin-top: auto; + margin-top: auto; } mat-form-field { - flex-grow: 1; + flex-grow: 1; } #upper-bar { - display: flex; + display: flex; } button[mat-icon-button] { - margin-left: 4pt; - margin-right: 4pt; - margin-top: 4pt; -} \ No newline at end of file + margin-left: 4pt; + margin-right: 4pt; + margin-top: 4pt; +} diff --git a/src/app/admin-view/account-mgmt/account-mgmt.component.spec.ts b/src/app/admin-view/account-mgmt/account-mgmt.component.spec.ts index a9db799..836b7e5 100644 --- a/src/app/admin-view/account-mgmt/account-mgmt.component.spec.ts +++ b/src/app/admin-view/account-mgmt/account-mgmt.component.spec.ts @@ -1,52 +1,50 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { AccountMgmtComponent } from './account-mgmt.component'; -import { AdminCommService } from '../admin-comm.service'; -import { MatDialogModule } from '@angular/material/dialog'; -import { MatSnackBarModule } from '@angular/material/snack-bar'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatIconModule } from '@angular/material/icon'; -import { MatPaginatorModule } from '@angular/material/paginator'; -import { of } from 'rxjs'; -import { MatTableModule } from '@angular/material/table'; -import { MatInputModule } from '@angular/material/input'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; +import { AccountMgmtComponent } from './account-mgmt.component' +import { AdminCommService } from '../admin-comm.service' +import { MatDialogModule } from '@angular/material/dialog' +import { MatSnackBarModule } from '@angular/material/snack-bar' +import { MatFormFieldModule } from '@angular/material/form-field' +import { MatIconModule } from '@angular/material/icon' +import { MatPaginatorModule } from '@angular/material/paginator' +import { of } from 'rxjs' +import { MatTableModule } from '@angular/material/table' +import { MatInputModule } from '@angular/material/input' +import { BrowserAnimationsModule } from '@angular/platform-browser/animations' +import { MatProgressSpinnerModule } from '@angular/material/progress-spinner' describe('AccountMgmtComponent', () => { - let component: AccountMgmtComponent; - let fixture: ComponentFixture; + let component: AccountMgmtComponent + let fixture: ComponentFixture let acMock beforeEach(async () => { acMock = { accs: { - getAccs: jasmine.createSpy("getAccs").and.returnValue(of()) - } + getAccs: jasmine.createSpy('getAccs').and.returnValue(of()), + }, } await TestBed.configureTestingModule({ declarations: [AccountMgmtComponent], - providers: [ - {provide: AdminCommService, useValue: acMock} - ], + providers: [{ provide: AdminCommService, useValue: acMock }], imports: [ - MatDialogModule, - MatSnackBarModule, - MatFormFieldModule, - MatIconModule, - MatPaginatorModule, - MatTableModule, - MatInputModule, + MatDialogModule, + MatSnackBarModule, + MatFormFieldModule, + MatIconModule, + MatPaginatorModule, + MatTableModule, + MatInputModule, BrowserAnimationsModule, - MatProgressSpinnerModule - ] - }).compileComponents(); - fixture = TestBed.createComponent(AccountMgmtComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + MatProgressSpinnerModule, + ], + }).compileComponents() + fixture = TestBed.createComponent(AccountMgmtComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/account-mgmt/account-mgmt.component.ts b/src/app/admin-view/account-mgmt/account-mgmt.component.ts index 9f07d14..cfb37f4 100644 --- a/src/app/admin-view/account-mgmt/account-mgmt.component.ts +++ b/src/app/admin-view/account-mgmt/account-mgmt.component.ts @@ -1,49 +1,57 @@ -import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core'; -import { AdminCommService } from '../admin-comm.service'; -import { MatDialog } from '@angular/material/dialog'; -import { MatTableDataSource } from '@angular/material/table'; -import { MatPaginator } from '@angular/material/paginator'; -import { MatSnackBar } from '@angular/material/snack-bar'; -import { UserEditComponent } from './user-edit/user-edit.component'; -import { LocalStorageService } from 'src/app/services/local-storage.service'; -import { Group } from 'src/app/types/group'; -import User from 'src/app/types/user'; +import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core' +import { AdminCommService } from '../admin-comm.service' +import { MatDialog } from '@angular/material/dialog' +import { MatTableDataSource } from '@angular/material/table' +import { MatPaginator } from '@angular/material/paginator' +import { MatSnackBar } from '@angular/material/snack-bar' +import { UserEditComponent } from './user-edit/user-edit.component' +import { LocalStorageService } from 'src/app/services/local-storage.service' +import { Group } from 'src/app/types/group' +import User from 'src/app/types/user' @Component({ - selector: 'app-account-mgmt', - templateUrl: './account-mgmt.component.html', - styleUrls: ['./account-mgmt.component.scss'], - standalone: false + selector: 'app-account-mgmt', + templateUrl: './account-mgmt.component.html', + styleUrls: ['./account-mgmt.component.scss'], + standalone: false, }) - - export class AccountMgmtComponent implements OnInit, AfterViewInit { protected groups: Group[] = [] - users: MatTableDataSource> + users: MatTableDataSource> loading = false @ViewChild(MatPaginator) paginator!: MatPaginator - constructor(readonly ac:AdminCommService, private dialog: MatDialog, private sb: MatSnackBar, protected readonly ls: LocalStorageService) { - this.users = new MatTableDataSource>(); - this.users.filterPredicate = (data: Record, filter: string): boolean => { - const dataStr = Object.keys(data).reduce((curr: string, key: string) => { - if (["_id", "admin", "groups", "__v", "locked"].find(v => v == key)) { - return curr + '' - } - return curr + data[key] + '⫂' - }, '').toLowerCase() + constructor( + readonly ac: AdminCommService, + private dialog: MatDialog, + private sb: MatSnackBar, + protected readonly ls: LocalStorageService + ) { + this.users = new MatTableDataSource>() + this.users.filterPredicate = ( + data: Record, + filter: string + ): boolean => { + const dataStr = Object.keys(data) + .reduce((curr: string, key: string) => { + if (['_id', 'admin', 'groups', '__v', 'locked'].find(v => v == key)) { + return curr + '' + } + return curr + data[key] + '⫂' + }, '') + .toLowerCase() const filternew = filter.trim().toLowerCase() return dataStr.indexOf(filternew) != -1 } } - + ngAfterViewInit() { this.users.paginator = this.paginator } ngOnInit() { this.loading = true - this.ac.accs.getAccs().subscribe((data)=>{ + this.ac.accs.getAccs().subscribe(data => { this.loading = false this.users.data = data.users this.groups = data.groups @@ -56,9 +64,18 @@ export class AccountMgmtComponent implements OnInit, AfterViewInit { } openUserCard(id?: string) { - this.dialog.open(UserEditComponent, {data: {id: id, type: id ? "edit" : "new", groups: this.groups}}).afterClosed().subscribe(r => { - if (r) this.ngOnInit() - }) + this.dialog + .open< + UserEditComponent, + UserEditComponent.InputData, + UserEditComponent.ReturnData + >(UserEditComponent, { + data: { id: id, type: id ? 'edit' : 'new', groups: this.groups }, + }) + .afterClosed() + .subscribe(r => { + if (r) this.ngOnInit() + }) } collumns = ['name', 'surname', 'uname', 'actions'] diff --git a/src/app/admin-view/account-mgmt/user-delete/user-delete.component.spec.ts b/src/app/admin-view/account-mgmt/user-delete/user-delete.component.spec.ts index 92a13ae..de6317a 100644 --- a/src/app/admin-view/account-mgmt/user-delete/user-delete.component.spec.ts +++ b/src/app/admin-view/account-mgmt/user-delete/user-delete.component.spec.ts @@ -1,23 +1,23 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { UserDeleteComponent } from './user-delete.component'; -import { MatDialogModule } from '@angular/material/dialog'; +import { UserDeleteComponent } from './user-delete.component' +import { MatDialogModule } from '@angular/material/dialog' describe('UserDeleteComponent', () => { - let component: UserDeleteComponent; - let fixture: ComponentFixture; + let component: UserDeleteComponent + let fixture: ComponentFixture beforeEach(() => { TestBed.configureTestingModule({ declarations: [UserDeleteComponent], - imports: [MatDialogModule] - }); - fixture = TestBed.createComponent(UserDeleteComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [MatDialogModule], + }) + fixture = TestBed.createComponent(UserDeleteComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/account-mgmt/user-delete/user-delete.component.ts b/src/app/admin-view/account-mgmt/user-delete/user-delete.component.ts index 89423d6..de9b1f4 100644 --- a/src/app/admin-view/account-mgmt/user-delete/user-delete.component.ts +++ b/src/app/admin-view/account-mgmt/user-delete/user-delete.component.ts @@ -1,11 +1,9 @@ -import { Component } from '@angular/core'; +import { Component } from '@angular/core' @Component({ - selector: 'app-user-delete', - templateUrl: './user-delete.component.html', - styleUrls: ['./user-delete.component.scss'], - standalone: false + selector: 'app-user-delete', + templateUrl: './user-delete.component.html', + styleUrls: ['./user-delete.component.scss'], + standalone: false, }) -export class UserDeleteComponent { - -} +export class UserDeleteComponent {} diff --git a/src/app/admin-view/account-mgmt/user-edit/user-edit.component.scss b/src/app/admin-view/account-mgmt/user-edit/user-edit.component.scss index 9290470..eb8fb5e 100644 --- a/src/app/admin-view/account-mgmt/user-edit/user-edit.component.scss +++ b/src/app/admin-view/account-mgmt/user-edit/user-edit.component.scss @@ -1,32 +1,32 @@ :host { - padding: 8pt; - display: block; + padding: 8pt; + display: block; } form { - margin-top: 1ch !important; - display: flex; - grid-auto-flow: column; - flex-direction: row; - flex-wrap: wrap; + margin-top: 1ch !important; + display: flex; + grid-auto-flow: column; + flex-direction: row; + flex-wrap: wrap; + 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; - 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; - } + button { + align-self: stretch; + justify-self: stretch; + height: auto; + margin-bottom: 1lh; } + } } mat-dialog-actions { - display: flex; - justify-content: flex-end; -} \ No newline at end of file + display: flex; + justify-content: flex-end; +} diff --git a/src/app/admin-view/account-mgmt/user-edit/user-edit.component.spec.ts b/src/app/admin-view/account-mgmt/user-edit/user-edit.component.spec.ts index 34aa67b..9cd2277 100644 --- a/src/app/admin-view/account-mgmt/user-edit/user-edit.component.spec.ts +++ b/src/app/admin-view/account-mgmt/user-edit/user-edit.component.spec.ts @@ -1,24 +1,26 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { UserEditComponent } from './user-edit.component'; -import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms'; -import { MatInputModule } from '@angular/material/input'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { AdminCommService } from '../../admin-comm.service'; -import { forwardRef } from '@angular/core'; -import { MatSelectModule } from '@angular/material/select'; +import { UserEditComponent } from './user-edit.component' +import { + MAT_DIALOG_DATA, + MatDialogModule, + MatDialogRef, +} from '@angular/material/dialog' +import { MatFormFieldModule } from '@angular/material/form-field' +import { NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@angular/forms' +import { MatInputModule } from '@angular/material/input' +import { NoopAnimationsModule } from '@angular/platform-browser/animations' +import { AdminCommService } from '../../admin-comm.service' +import { forwardRef } from '@angular/core' +import { MatSelectModule } from '@angular/material/select' describe('UserEditComponent', () => { - let component: UserEditComponent; - let fixture: ComponentFixture; + let component: UserEditComponent + let fixture: ComponentFixture let acMock beforeEach(async () => { - acMock = { - - } + acMock = {} await TestBed.configureTestingModule({ declarations: [UserEditComponent], imports: [ @@ -27,20 +29,20 @@ describe('UserEditComponent', () => { ReactiveFormsModule, MatInputModule, NoopAnimationsModule, - MatSelectModule + MatSelectModule, ], providers: [ { provide: MatDialogRef, useValue: {} }, { provide: MAT_DIALOG_DATA, useValue: { groups: [] } }, { provide: AdminCommService, useValue: acMock }, - ] - }).compileComponents(); - fixture = TestBed.createComponent(UserEditComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + ], + }).compileComponents() + fixture = TestBed.createComponent(UserEditComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/account-mgmt/user-edit/user-edit.component.ts b/src/app/admin-view/account-mgmt/user-edit/user-edit.component.ts index d10164c..93bdfd8 100644 --- a/src/app/admin-view/account-mgmt/user-edit/user-edit.component.ts +++ b/src/app/admin-view/account-mgmt/user-edit/user-edit.component.ts @@ -1,53 +1,57 @@ -import { Component, Inject } from '@angular/core'; -import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog'; -import { FormControl, FormGroup } from '@angular/forms'; -import { LocalStorageService } from 'src/app/services/local-storage.service'; -import { Group } from 'src/app/types/group'; -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 { DateTime } from 'luxon'; +import { Component, Inject } from '@angular/core' +import { + MAT_DIALOG_DATA, + MatDialog, + MatDialogRef, +} from '@angular/material/dialog' +import { FormControl, FormGroup } from '@angular/forms' +import { LocalStorageService } from 'src/app/services/local-storage.service' +import { Group } from 'src/app/types/group' +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 { DateTime } from 'luxon' export namespace UserEditComponent { - export type InputData = {type: "new" | "edit", id?: string, groups: Group[]} + export type InputData = { type: 'new' | 'edit'; id?: string; groups: Group[] } export type ReturnData = true | undefined } @Component({ - selector: 'app-user-edit', - templateUrl: './user-edit.component.html', - styleUrls: ['./user-edit.component.scss'], - standalone: false + selector: 'app-user-edit', + templateUrl: './user-edit.component.html', + styleUrls: ['./user-edit.component.scss'], + standalone: false, }) -export class UserEditComponent { - lockout = false; - locked = false; - loading = false; +export class UserEditComponent { + lockout = false + locked = false + loading = false form: FormGroup = new FormGroup({ - fname: new FormControl(""), - surname: new FormControl(""), - room: new FormControl(""), - uname: new FormControl(""), + fname: new FormControl(''), + surname: new FormControl(''), + room: new FormControl(''), + uname: new FormControl(''), groups: new FormControl>([]), flags: new FormControl>([]), }) groups: Group[] id?: string - regDate?: DateTime; - constructor ( - public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: UserEditComponent.InputData, - readonly ls: LocalStorageService, - readonly acu: AdminCommService, + regDate?: DateTime + constructor( + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: UserEditComponent.InputData, + readonly ls: LocalStorageService, + readonly acu: AdminCommService, private dialog: MatDialog, private sb: MatSnackBar ) { this.groups = data.groups - if (data.type == "edit") { + if (data.type == 'edit') { this.id = data.id - this.acu.accs.getUser(data.id!).subscribe((r) => { + this.acu.accs.getUser(data.id!).subscribe(r => { this.regDate = DateTime.fromISO(r.regDate) var flags: Array = [] if (r.admin) { @@ -62,64 +66,83 @@ export class UserEditComponent { } 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) + 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 - } - }) + 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 - } - }) + 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.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 + } + }) } - protected getForm() { + protected getForm() { return { fname: this.form.get('fname')?.value, surname: this.form.get('surname')?.value, @@ -127,48 +150,60 @@ export class UserEditComponent { uname: this.form.get('uname')?.value, groups: this.form.get('groups')?.value, flags: (() => { - var value = this.form.get('flags')?.value.reduce((a: number,b: number)=>a+b,0) + var value = this.form + .get('flags') + ?.value.reduce((a: number, b: number) => a + b, 0) if (this.ls.capCheck(32)) { return value } else { 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); - } - }) - } - }) + 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 - } - }) - } - }) + 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) => { + this.acu.accs.putAcc(this.id!, { locked: state }).subscribe(res => { if (res.status == 200) { this.locked = state } diff --git a/src/app/admin-view/account-mgmt/user-reset/user-reset.component.spec.ts b/src/app/admin-view/account-mgmt/user-reset/user-reset.component.spec.ts index 69483b4..708c718 100644 --- a/src/app/admin-view/account-mgmt/user-reset/user-reset.component.spec.ts +++ b/src/app/admin-view/account-mgmt/user-reset/user-reset.component.spec.ts @@ -1,25 +1,23 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { UserResetComponent } from './user-reset.component'; -import { MatDialogModule } from '@angular/material/dialog'; +import { UserResetComponent } from './user-reset.component' +import { MatDialogModule } from '@angular/material/dialog' describe('UserResetComponent', () => { - let component: UserResetComponent; - let fixture: ComponentFixture; + let component: UserResetComponent + let fixture: ComponentFixture beforeEach(() => { TestBed.configureTestingModule({ declarations: [UserResetComponent], - imports: [ - MatDialogModule - ] - }); - fixture = TestBed.createComponent(UserResetComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [MatDialogModule], + }) + fixture = TestBed.createComponent(UserResetComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/account-mgmt/user-reset/user-reset.component.ts b/src/app/admin-view/account-mgmt/user-reset/user-reset.component.ts index 51ed6bc..6626255 100644 --- a/src/app/admin-view/account-mgmt/user-reset/user-reset.component.ts +++ b/src/app/admin-view/account-mgmt/user-reset/user-reset.component.ts @@ -1,11 +1,9 @@ -import { Component } from '@angular/core'; +import { Component } from '@angular/core' @Component({ - selector: 'app-user-reset', - templateUrl: './user-reset.component.html', - styleUrls: ['./user-reset.component.scss'], - standalone: false + selector: 'app-user-reset', + templateUrl: './user-reset.component.html', + styleUrls: ['./user-reset.component.scss'], + standalone: false, }) -export class UserResetComponent { - -} +export class UserResetComponent {} diff --git a/src/app/admin-view/admin-comm.service.spec.ts b/src/app/admin-view/admin-comm.service.spec.ts index e1e32d9..cd4a931 100644 --- a/src/app/admin-view/admin-comm.service.spec.ts +++ b/src/app/admin-view/admin-comm.service.spec.ts @@ -1,25 +1,35 @@ -import { TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing' -import { AdminCommService } from './admin-comm.service'; -import { HttpClient, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; -import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing'; +import { AdminCommService } from './admin-comm.service' +import { + HttpClient, + provideHttpClient, + withInterceptorsFromDi, +} from '@angular/common/http' +import { + HttpTestingController, + provideHttpClientTesting, +} from '@angular/common/http/testing' describe('AdminCommService', () => { - let service: AdminCommService; + let service: AdminCommService let httpClient: HttpClient let httpTestingController: HttpTestingController beforeEach(() => { TestBed.configureTestingModule({ - imports: [], - providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()] -}); - service = TestBed.inject(AdminCommService); - httpClient = TestBed.inject(HttpClient); - httpTestingController = TestBed.inject(HttpTestingController); - }); + imports: [], + providers: [ + provideHttpClient(withInterceptorsFromDi()), + provideHttpClientTesting(), + ], + }) + service = TestBed.inject(AdminCommService) + httpClient = TestBed.inject(HttpClient) + httpTestingController = TestBed.inject(HttpTestingController) + }) it('should be created', () => { - expect(service).toBeTruthy(); - }); -}); + expect(service).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/admin-comm.service.ts b/src/app/admin-view/admin-comm.service.ts index 68fbee9..46f42a4 100644 --- a/src/app/admin-view/admin-comm.service.ts +++ b/src/app/admin-view/admin-comm.service.ts @@ -1,285 +1,468 @@ -import { HttpClient } from '@angular/common/http'; -import { Injectable } from '@angular/core'; -import { environment } from 'src/environments/environment'; -import { Menu } from '../types/menu'; -import { Status } from '../types/status'; -import { Group } from '../types/group'; -import { map } from 'rxjs'; -import { Notification } from '../types/notification'; -import { News } from '../types/news'; -import { AKey } from '../types/key'; -import { IUSettings } from './settings/settings.component'; -import User from '../types/user'; -import { DateTime } from 'luxon'; +import { HttpClient } from '@angular/common/http' +import { Injectable } from '@angular/core' +import { environment } from 'src/environments/environment' +import { Menu } from '../types/menu' +import { Status } from '../types/status' +import { Group } from '../types/group' +import { map } from 'rxjs' +import { Notification } from '../types/notification' +import { News } from '../types/news' +import { AKey } from '../types/key' +import { IUSettings } from './settings/settings.component' +import User from '../types/user' +import { DateTime } from 'luxon' @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class AdminCommService { - - constructor(private http: HttpClient) { } + constructor(private http: HttpClient) {} //#region Menu menu = { getMenu: (start?: DateTime | null, end?: DateTime | null) => { if (start && end) { - const body = {start: start.toString(), end: end.toString()} - return this.http.get<(Omit & {day: string})[]>(environment.apiEndpoint+"/admin/menu", {withCredentials: true, params: body}) + const body = { start: start.toString(), end: end.toString() } + return this.http.get<(Omit & { day: string })[]>( + environment.apiEndpoint + '/admin/menu', + { withCredentials: true, params: body } + ) } return }, getOpts: () => { - return this.http.get(environment.apiEndpoint+`/admin/menu/opts`, {withCredentials: true}) + return this.http.get(environment.apiEndpoint + `/admin/menu/opts`, { + withCredentials: true, + }) }, postMenu: (file: File) => { if (file) { - const formData = new FormData(); - formData.append("menu", file) - return this.http.post(environment.apiEndpoint+"/admin/menu/upload", formData, {withCredentials: true}) + const formData = new FormData() + formData.append('menu', file) + return this.http.post( + environment.apiEndpoint + '/admin/menu/upload', + formData, + { withCredentials: true } + ) } return }, editSn: (id: string, content: Menu['sn']) => { - return this.putMenu(id, {sn: content}) + return this.putMenu(id, { sn: content }) }, editOb: (id: string, content: Menu['ob']) => { - return this.putMenu(id, {ob: content}) + return this.putMenu(id, { ob: content }) }, editKol: (id: string, content: Menu['kol']) => { - return this.putMenu(id, {kol: content}) + return this.putMenu(id, { kol: content }) }, editTitle: (id: string, content: Menu['dayTitle']) => { - return this.putMenu(id, {dayTitle: content}) + return this.putMenu(id, { dayTitle: content }) }, print: (start?: DateTime | null, end?: DateTime | null) => { if (start && end) { - const body = {start: start.toString(), end: end.toString()} - return this.http.get(environment.apiEndpoint+"/admin/menu/print", {withCredentials: true, params: body, responseType: "text"}) + const body = { start: start.toString(), end: end.toString() } + return this.http.get(environment.apiEndpoint + '/admin/menu/print', { + withCredentials: true, + params: body, + responseType: 'text', + }) } return }, - stat: (day: DateTime, m: "ob" | "kol") => { - return this.http.get<{y: number, n: number}>(environment.apiEndpoint+`/admin/menu/${day.toISO()}/votes/${m}`, {withCredentials: true}) + stat: (day: DateTime, m: 'ob' | 'kol') => { + return this.http.get<{ y: number; n: number }>( + environment.apiEndpoint + `/admin/menu/${day.toISO()}/votes/${m}`, + { withCredentials: true } + ) }, new: { single: (day: DateTime) => { - return this.http.post(environment.apiEndpoint+`/admin/menu/${day.toISO()}`, null, {withCredentials: true}) + return this.http.post( + environment.apiEndpoint + `/admin/menu/${day.toISO()}`, + null, + { withCredentials: true } + ) }, range: (start: DateTime, count: number) => { - return this.http.post(environment.apiEndpoint+`/admin/menu/${start.toISO()}/${count}/`, null, {withCredentials: true}) - } + return this.http.post( + environment.apiEndpoint + `/admin/menu/${start.toISO()}/${count}/`, + null, + { withCredentials: true } + ) + }, }, rm: (id: string) => { - return this.http.delete(environment.apiEndpoint+`/admin/menu/${id}`, {withCredentials: true}) - } + return this.http.delete( + environment.apiEndpoint + `/admin/menu/${id}`, + { withCredentials: true } + ) + }, } - + private putMenu(id: string, update: Partial) { - return this.http.put(environment.apiEndpoint+`/admin/menu/${id}`, update, {withCredentials: true}) + return this.http.put( + environment.apiEndpoint + `/admin/menu/${id}`, + update, + { withCredentials: true } + ) } //#endregion //#region News news = { getNews: () => { - return this.http.get(environment.apiEndpoint+`/admin/news`, {withCredentials: true}) + return this.http.get(environment.apiEndpoint + `/admin/news`, { + withCredentials: true, + }) }, postNews: (title: string, content: string) => { - return this.http.post(environment.apiEndpoint+`/admin/news`, {title: title, content: content}, {withCredentials: true}) + return this.http.post( + environment.apiEndpoint + `/admin/news`, + { title: title, content: content }, + { withCredentials: true } + ) }, deleteNews: (id: string) => { - return this.http.delete(environment.apiEndpoint+`/admin/news/${id}`, {withCredentials: true}) + return this.http.delete( + environment.apiEndpoint + `/admin/news/${id}`, + { withCredentials: true } + ) }, toggleNews: (id: string, inverter: boolean) => { - return this.putNews(id,{visible: !inverter}) + return this.putNews(id, { visible: !inverter }) }, togglePin: (id: string, inverter: boolean) => { - return this.putNews(id,{pinned: !inverter}) + return this.putNews(id, { pinned: !inverter }) }, updateNews: (id: string, title: string, content: string) => { - return this.putNews(id,{title: title, content: content, date: Date.now}) - } + return this.putNews(id, { + title: title, + content: content, + date: Date.now, + }) + }, } private putNews(id: string, update: object) { - return this.http.put(environment.apiEndpoint+`/admin/news/${id}`, update, {withCredentials: true}) + return this.http.put( + environment.apiEndpoint + `/admin/news/${id}`, + update, + { withCredentials: true } + ) } //#endregion //#region amgmt accs = { getAccs: () => { return this.http.get<{ - users: Omit[], + users: Omit[] groups: Group[] - }>(environment.apiEndpoint+`/admin/accs`, {withCredentials: true}) + }>(environment.apiEndpoint + `/admin/accs`, { withCredentials: true }) }, postAcc: (item: any) => { - return this.http.post(environment.apiEndpoint+`/admin/accs`, item, {withCredentials: true}) + return this.http.post( + environment.apiEndpoint + `/admin/accs`, + item, + { withCredentials: true } + ) }, putAcc: (id: string, update: Partial) => { - return this.http.put(environment.apiEndpoint+`/admin/accs/${id}`, update, {withCredentials: true}) + return this.http.put( + environment.apiEndpoint + `/admin/accs/${id}`, + update, + { withCredentials: true } + ) }, resetPass: (id: string) => { - return this.http.patch(environment.apiEndpoint+`/admin/accs/${id}/reset`, {}, {withCredentials: true}) + return this.http.patch( + environment.apiEndpoint + `/admin/accs/${id}/reset`, + {}, + { withCredentials: true } + ) }, - + deleteAcc: (id: string) => { - return this.http.delete(environment.apiEndpoint+`/admin/accs/${id}`, {withCredentials: true}) + return this.http.delete( + environment.apiEndpoint + `/admin/accs/${id}`, + { withCredentials: true } + ) }, getUser: (id: string) => { - return this.http.get & {lockout: boolean, regDate: string}>(environment.apiEndpoint+`/admin/accs/${id}`, {withCredentials: true}) + return this.http.get< + Omit & { lockout: boolean; regDate: string } + >(environment.apiEndpoint + `/admin/accs/${id}`, { + withCredentials: true, + }) }, clearLockout: (id: string) => { - return this.http.delete(environment.apiEndpoint+`/admin/accs/${id}/lockout`, {withCredentials: true}) - } + return this.http.delete( + environment.apiEndpoint + `/admin/accs/${id}/lockout`, + { withCredentials: true } + ) + }, } //#endregion //#region Groups groups = { getGroups: () => { - return this.http.get(environment.apiEndpoint+`/admin/groups`, {withCredentials: true}) + return this.http.get(environment.apiEndpoint + `/admin/groups`, { + withCredentials: true, + }) }, newGroup: (name: string) => { - return this.http.post(environment.apiEndpoint+`/admin/groups`, {name: name}, {withCredentials: true}) + return this.http.post( + environment.apiEndpoint + `/admin/groups`, + { name: name }, + { withCredentials: true } + ) }, - + editName: (id: string, name: string) => { - return this.putGroups(id, {name: name.trim()}) + return this.putGroups(id, { name: name.trim() }) }, remove: (id: string) => { - return this.http.delete(environment.apiEndpoint+`/admin/groups/${id}`, {withCredentials: true}) - } + return this.http.delete( + environment.apiEndpoint + `/admin/groups/${id}`, + { withCredentials: true } + ) + }, } private putGroups(id: string, update: Partial) { - return this.http.put(environment.apiEndpoint+`/admin/groups/${id}`, update, {withCredentials: true}) + return this.http.put( + environment.apiEndpoint + `/admin/groups/${id}`, + update, + { withCredentials: true } + ) } //#endregion //#region Notif notif = { send: (n: Notification) => { - return this.http.post<{sent: number, possible: number}>(environment.apiEndpoint+"/admin/notif/send", n, {withCredentials: true}) + return this.http.post<{ sent: number; possible: number }>( + environment.apiEndpoint + '/admin/notif/send', + n, + { withCredentials: true } + ) }, getGroups: () => { - return this.http.get(environment.apiEndpoint+"/admin/notif/groups", {withCredentials: true}) + return this.http.get( + environment.apiEndpoint + '/admin/notif/groups', + { withCredentials: true } + ) }, outbox: { getSent: () => { - return this.http.get<{_id: string, sentDate: string, title: string}[]>(environment.apiEndpoint+"/admin/notif/outbox", {withCredentials: true}).pipe(map(v => v.map(i => ({ - ...i, - sentDate: DateTime.fromISO(i.sentDate) - })))) + return this.http + .get< + { _id: string; sentDate: string; title: string }[] + >(environment.apiEndpoint + '/admin/notif/outbox', { withCredentials: true }) + .pipe( + map(v => + v.map(i => ({ + ...i, + sentDate: DateTime.fromISO(i.sentDate), + })) + ) + ) }, getBody: (id: string) => { - return this.http.get(environment.apiEndpoint+`/admin/notif/outbox/${id}/message`, {withCredentials: true, responseType: "text"}) + 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}) - } - } + return this.http.get< + { + _id: string + uname: string + room?: string + fname?: string + surname?: string + }[] + >(environment.apiEndpoint + `/admin/notif/outbox/${id}/rcpts`, { + withCredentials: true, + }) + }, + }, } //#endregion //#region Keys keys = { getKeys: () => { - return this.http.get<(Omit & {borrow: string, tb?: string})[]>(environment.apiEndpoint+`/admin/keys`, {withCredentials: true}).pipe(map((v) => { - return v.map((r) => { - let newkey: any = {...r} - newkey.borrow = DateTime.fromISO(r.borrow!) - if (newkey.tb) newkey.tb = DateTime.fromISO(r.tb!) - return newkey as AKey - }) - })) + return this.http + .get< + (Omit & { borrow: string; tb?: string })[] + >(environment.apiEndpoint + `/admin/keys`, { withCredentials: true }) + .pipe( + map(v => { + return v.map(r => { + let newkey: any = { ...r } + newkey.borrow = DateTime.fromISO(r.borrow!) + if (newkey.tb) newkey.tb = DateTime.fromISO(r.tb!) + return newkey as AKey + }) + }) + ) }, avalKeys: () => { - return this.http.get(environment.apiEndpoint+`/admin/keys/available`, {withCredentials: true}) + return this.http.get( + environment.apiEndpoint + `/admin/keys/available`, + { withCredentials: true } + ) }, postKey: (room: string, uname: string) => { - return this.http.post(environment.apiEndpoint+`/admin/keys/`, {room: room, whom: uname}, {withCredentials: true}) + return this.http.post( + environment.apiEndpoint + `/admin/keys/`, + { room: room, whom: uname }, + { withCredentials: true } + ) }, returnKey: (id: string) => { - return this.putKeys(id, {tb: DateTime.now()}) - } + return this.putKeys(id, { tb: DateTime.now() }) + }, } private putKeys(id: string, update: Partial) { - return this.http.put(environment.apiEndpoint+`/admin/keys/${id}`, update, {withCredentials: true}) + return this.http.put( + environment.apiEndpoint + `/admin/keys/${id}`, + update, + { withCredentials: true } + ) } //#endregion //#region Clean clean = { getConfig: () => { - return this.http.get<{rooms: string[], things: string[]}>(environment.apiEndpoint+`/admin/clean/config`, {withCredentials: true}) + return this.http.get<{ rooms: string[]; things: string[] }>( + environment.apiEndpoint + `/admin/clean/config`, + { withCredentials: true } + ) }, getClean: (date: string, room: string) => { - return this.http.get<{_id: string, date: string, grade: number, gradeDate: string, notes: {label: string, weight: number}[], room: string, tips: string} | null>(environment.apiEndpoint+`/admin/clean/${date}/${room}`, {withCredentials: true}) + return this.http.get<{ + _id: string + date: string + grade: number + gradeDate: string + notes: { label: string; weight: number }[] + room: string + tips: string + } | null>(environment.apiEndpoint + `/admin/clean/${date}/${room}`, { + withCredentials: true, + }) }, postClean: (obj: Object) => { - return this.http.post(environment.apiEndpoint+`/admin/clean/`, obj, {withCredentials: true}) + return this.http.post( + environment.apiEndpoint + `/admin/clean/`, + obj, + { withCredentials: true } + ) }, delete: (id: string) => { - return this.http.delete(environment.apiEndpoint+`/admin/clean/${id}`, {withCredentials: true}) + return this.http.delete( + environment.apiEndpoint + `/admin/clean/${id}`, + { withCredentials: true } + ) }, summary: { getSummary: (start: DateTime, end: DateTime) => { - return this.http.get<{room: string, avg: number}[]>(environment.apiEndpoint+`/admin/clean/summary/${start.toISO()}/${end.toISO()}`, {withCredentials: true}) - } + return this.http.get<{ room: string; avg: number }[]>( + environment.apiEndpoint + + `/admin/clean/summary/${start.toISO()}/${end.toISO()}`, + { withCredentials: true } + ) + }, }, attendence: { getUsers: (room: string) => { - 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}) + 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: {auto: {id: string, hour?: string}[], notes: string}) => { - return this.http.post(environment.apiEndpoint+`/admin/clean/attendence/${room}`, attendence, {withCredentials: true}) + postAttendence: ( + room: string, + attendence: { auto: { id: string; hour?: string }[]; notes: string } + ) => { + return this.http.post( + environment.apiEndpoint + `/admin/clean/attendence/${room}`, + attendence, + { withCredentials: true } + ) }, getSummary: () => { - return this.http.get<{room: string, hours: string[], notes: string, auto: boolean}[]>(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(environment.apiEndpoint+`/admin/clean/attendence/${room}`, {withCredentials: true}) - } - } + return this.http.delete( + environment.apiEndpoint + `/admin/clean/attendence/${room}`, + { withCredentials: true } + ) + }, + }, } //#endregion //#region Settings settings = { getAll: () => { - return this.http.get(environment.apiEndpoint+`/admin/settings/`, {withCredentials: true}) + return this.http.get( + environment.apiEndpoint + `/admin/settings/`, + { withCredentials: true } + ) }, post: (settings: IUSettings) => { - return this.http.post(environment.apiEndpoint+`/admin/settings/`, settings, {withCredentials: true}) + return this.http.post( + environment.apiEndpoint + `/admin/settings/`, + settings, + { withCredentials: true } + ) }, reload: () => { - return this.http.get(environment.apiEndpoint+`/admin/settings/reload/`, {withCredentials: true}) - } + return this.http.get( + environment.apiEndpoint + `/admin/settings/reload/`, + { withCredentials: true } + ) + }, } //#endregion //#region misc userFilter = (query: string) => { - return this.http.get(environment.apiEndpoint+`/admin/usearch`, {params: {q: query}, withCredentials: true}) + return this.http.get(environment.apiEndpoint + `/admin/usearch`, { + params: { q: query }, + withCredentials: true, + }) } //#endregion } diff --git a/src/app/admin-view/admin-view.component.scss b/src/app/admin-view/admin-view.component.scss index 54bb687..b336ecb 100644 --- a/src/app/admin-view/admin-view.component.scss +++ b/src/app/admin-view/admin-view.component.scss @@ -1,14 +1,15 @@ :host { - width: 100%; - height: 100%; - display: flex; - flex-direction: column; + width: 100%; + height: 100%; + display: flex; + flex-direction: column; } -mat-sidenav, mat-toolbar { - padding: 8pt +mat-sidenav, +mat-toolbar { + padding: 8pt; } mat-sidenav-container { - flex-grow: 1; -} \ No newline at end of file + flex-grow: 1; +} diff --git a/src/app/admin-view/admin-view.component.spec.ts b/src/app/admin-view/admin-view.component.spec.ts index 2610882..afcd8bf 100644 --- a/src/app/admin-view/admin-view.component.spec.ts +++ b/src/app/admin-view/admin-view.component.spec.ts @@ -1,37 +1,45 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { AdminViewComponent } from './admin-view.component'; -import { MatToolbarModule } from '@angular/material/toolbar'; -import { MatIconModule } from '@angular/material/icon'; -import { MatDrawer, MatSidenavModule } from '@angular/material/sidenav'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { MatListModule } from '@angular/material/list'; -import { RouterModule } from '@angular/router'; -import { Component, Input } from '@angular/core'; +import { AdminViewComponent } from './admin-view.component' +import { MatToolbarModule } from '@angular/material/toolbar' +import { MatIconModule } from '@angular/material/icon' +import { MatDrawer, MatSidenavModule } from '@angular/material/sidenav' +import { BrowserAnimationsModule } from '@angular/platform-browser/animations' +import { MatListModule } from '@angular/material/list' +import { RouterModule } from '@angular/router' +import { Component, Input } from '@angular/core' @Component({ - selector: "app-toolbar", template: '', - standalone: false + selector: 'app-toolbar', + template: '', + standalone: false, }) class ToolbarMock { - @Input() drawer!: MatDrawer; + @Input() drawer!: MatDrawer } describe('AdminViewComponent', () => { - let component: AdminViewComponent; - let fixture: ComponentFixture; + let component: AdminViewComponent + let fixture: ComponentFixture beforeEach(() => { TestBed.configureTestingModule({ declarations: [AdminViewComponent, ToolbarMock], - imports: [MatToolbarModule, MatIconModule, MatSidenavModule, BrowserAnimationsModule, MatListModule, RouterModule.forRoot([])] - }); - fixture = TestBed.createComponent(AdminViewComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [ + MatToolbarModule, + MatIconModule, + MatSidenavModule, + BrowserAnimationsModule, + MatListModule, + RouterModule.forRoot([]), + ], + }) + fixture = TestBed.createComponent(AdminViewComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/admin-view.component.ts b/src/app/admin-view/admin-view.component.ts index 787bd2c..362dea4 100644 --- a/src/app/admin-view/admin-view.component.ts +++ b/src/app/admin-view/admin-view.component.ts @@ -1,30 +1,78 @@ -import { Component } from '@angular/core'; -import { Router } from '@angular/router'; -import { LocalStorageService } from '../services/local-storage.service'; -import { Link } from '../types/link'; +import { Component } from '@angular/core' +import { Router } from '@angular/router' +import { LocalStorageService } from '../services/local-storage.service' +import { Link } from '../types/link' @Component({ selector: 'app-admin-view', templateUrl: './admin-view.component.html', styleUrls: ['./admin-view.component.scss'], - standalone: false + standalone: false, }) export class AdminViewComponent { private readonly _LINKS: Link[] = [ - { title: "Wiadomości", icon: "newspaper", href: "news", enabled: this.ls.permChecker(1) && this.ls.capCheck(1) }, - { title: "Jadłospis", icon: "restaurant_menu", href: "menu", enabled: this.ls.permChecker(2) && this.ls.capCheck(2) }, - { title: "Wysyłanie powiadomień", icon: "notifications", href: "notifications", enabled: this.ls.permChecker(4) && this.ls.capCheck(4) }, - { title: "Grupy", icon: "groups", href: "groups", enabled: this.ls.permChecker(8) && this.ls.capCheck(8) }, - { title: "Zarządzanie kontami", icon: "manage_accounts", href: "accounts", enabled: this.ls.permChecker(16) }, - { title: "Klucze", icon: "key", href: "keys", enabled: this.ls.permChecker(64) && this.ls.capCheck(32) }, - { title: "Czystość", icon: "cleaning_services", href: "grades", enabled: this.ls.permChecker(128) && this.ls.capCheck(16) }, - { title: "Frekwencja", icon: "checklist", href: "attendence", enabled: false }, - { title: "Ustawienia", icon: "settings_applications", href: "settings", enabled: this.ls.permChecker(32) }, - ]; + { + title: 'Wiadomości', + icon: 'newspaper', + href: 'news', + enabled: this.ls.permChecker(1) && this.ls.capCheck(1), + }, + { + title: 'Jadłospis', + icon: 'restaurant_menu', + href: 'menu', + enabled: this.ls.permChecker(2) && this.ls.capCheck(2), + }, + { + title: 'Wysyłanie powiadomień', + icon: 'notifications', + href: 'notifications', + enabled: this.ls.permChecker(4) && this.ls.capCheck(4), + }, + { + title: 'Grupy', + icon: 'groups', + href: 'groups', + enabled: this.ls.permChecker(8) && this.ls.capCheck(8), + }, + { + title: 'Zarządzanie kontami', + icon: 'manage_accounts', + href: 'accounts', + enabled: this.ls.permChecker(16), + }, + { + title: 'Klucze', + icon: 'key', + href: 'keys', + enabled: this.ls.permChecker(64) && this.ls.capCheck(32), + }, + { + title: 'Czystość', + icon: 'cleaning_services', + href: 'grades', + enabled: this.ls.permChecker(128) && this.ls.capCheck(16), + }, + { + title: 'Frekwencja', + icon: 'checklist', + href: 'attendence', + enabled: false, + }, + { + title: 'Ustawienia', + icon: 'settings_applications', + href: 'settings', + enabled: this.ls.permChecker(32), + }, + ] public get LINKS(): Link[] { - return this._LINKS.filter(v => v.enabled); + return this._LINKS.filter(v => v.enabled) } - constructor(readonly router: Router, readonly ls: LocalStorageService) { } + constructor( + readonly router: Router, + readonly ls: LocalStorageService + ) {} goNormal() { this.router.navigateByUrl('app') } diff --git a/src/app/admin-view/grades/attendence-summary/attendence-summary.component.scss b/src/app/admin-view/grades/attendence-summary/attendence-summary.component.scss index cc9b457..02ef824 100644 --- a/src/app/admin-view/grades/attendence-summary/attendence-summary.component.scss +++ b/src/app/admin-view/grades/attendence-summary/attendence-summary.component.scss @@ -1,34 +1,34 @@ -@use 'sass:list'; +@use "sass:list"; #guide { - margin: 1em + margin: 1em; } #legend { - display: flex; - justify-self: center; - gap: 3ch; - * { - margin: 2px; - } + display: flex; + justify-self: center; + gap: 3ch; + * { + margin: 2px; + } } .circle { - &::before { - border-radius: 7.5%; - width: 2.5ch; - height: 2.5ch; - display: inline-block; - content: ""; - vertical-align: middle; - margin-right: 3px; - } + &::before { + border-radius: 7.5%; + width: 2.5ch; + height: 2.5ch; + display: inline-block; + content: ""; + vertical-align: middle; + margin-right: 3px; + } - $list: (red, yellow, green); + $list: (red, yellow, green); - @for $n from 1 through 3 { - &:nth-of-type(#{$n})::before { - background-color: list.nth($list, $n); - } + @for $n from 1 through 3 { + &:nth-of-type(#{$n})::before { + background-color: list.nth($list, $n); } -} \ No newline at end of file + } +} diff --git a/src/app/admin-view/grades/attendence-summary/attendence-summary.component.spec.ts b/src/app/admin-view/grades/attendence-summary/attendence-summary.component.spec.ts index 89806eb..a5be846 100644 --- a/src/app/admin-view/grades/attendence-summary/attendence-summary.component.spec.ts +++ b/src/app/admin-view/grades/attendence-summary/attendence-summary.component.spec.ts @@ -1,42 +1,36 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { AttendenceSummaryComponent } from './attendence-summary.component'; -import { RouterModule } from '@angular/router'; -import { AdminCommService } from '../../admin-comm.service'; -import { of } from 'rxjs'; -import { MatTableModule } from '@angular/material/table'; +import { AttendenceSummaryComponent } from './attendence-summary.component' +import { RouterModule } from '@angular/router' +import { AdminCommService } from '../../admin-comm.service' +import { of } from 'rxjs' +import { MatTableModule } from '@angular/material/table' describe('AttendenceSummaryComponent', () => { - let component: AttendenceSummaryComponent; - let fixture: ComponentFixture; + let component: AttendenceSummaryComponent + let fixture: ComponentFixture let acMock beforeEach(async () => { acMock = { clean: { attendence: { - getSummary: jasmine.createSpy("getSummary").and.returnValue(of()) - } - } + getSummary: jasmine.createSpy('getSummary').and.returnValue(of()), + }, + }, } await TestBed.configureTestingModule({ declarations: [AttendenceSummaryComponent], - imports: [ - RouterModule.forRoot([]), - MatTableModule - ], - providers: [ - {provide: AdminCommService, useValue: acMock} - ] - }) - .compileComponents(); - - fixture = TestBed.createComponent(AttendenceSummaryComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [RouterModule.forRoot([]), MatTableModule], + providers: [{ provide: AdminCommService, useValue: acMock }], + }).compileComponents() + + fixture = TestBed.createComponent(AttendenceSummaryComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/grades/attendence-summary/attendence-summary.component.ts b/src/app/admin-view/grades/attendence-summary/attendence-summary.component.ts index 5116c4a..4834cf9 100644 --- a/src/app/admin-view/grades/attendence-summary/attendence-summary.component.ts +++ b/src/app/admin-view/grades/attendence-summary/attendence-summary.component.ts @@ -1,24 +1,38 @@ -import { Component, OnInit } from '@angular/core'; -import { ToolbarService } from '../../toolbar/toolbar.service'; -import { Router, ActivatedRoute } from '@angular/router'; -import { MatTableDataSource } from '@angular/material/table'; -import { AdminCommService } from '../../admin-comm.service'; +import { Component, OnInit } from '@angular/core' +import { ToolbarService } from '../../toolbar/toolbar.service' +import { Router, ActivatedRoute } from '@angular/router' +import { MatTableDataSource } from '@angular/material/table' +import { AdminCommService } from '../../admin-comm.service' @Component({ - selector: 'app-attendence-summary', - templateUrl: './attendence-summary.component.html', - styleUrl: './attendence-summary.component.scss', - standalone: false + selector: 'app-attendence-summary', + templateUrl: './attendence-summary.component.html', + styleUrl: './attendence-summary.component.scss', + standalone: false, }) export class AttendenceSummaryComponent implements OnInit { - - data: MatTableDataSource<{room: string, hours: string[], notes: string, auto: boolean}> = new MatTableDataSource<{room: string, hours: string[], notes: string, auto: boolean}>(); + data: MatTableDataSource<{ + room: string + hours: string[] + notes: string + auto: boolean + }> = new MatTableDataSource<{ + room: string + hours: string[] + notes: string + auto: boolean + }>() 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.menu = [ - {check: true, title: "Ocenianie", fn: "goBack", icon: "arrow_back"} + { check: true, title: 'Ocenianie', fn: 'goBack', icon: 'arrow_back' }, ] } @@ -35,6 +49,6 @@ export class AttendenceSummaryComponent implements OnInit { } goBack() { - this.router.navigate(['../'], {relativeTo: this.route}) + this.router.navigate(['../'], { relativeTo: this.route }) } } diff --git a/src/app/admin-view/grades/attendence-summary/hour-display/hour-display.component.scss b/src/app/admin-view/grades/attendence-summary/hour-display/hour-display.component.scss index aaa7428..ebbcfce 100644 --- a/src/app/admin-view/grades/attendence-summary/hour-display/hour-display.component.scss +++ b/src/app/admin-view/grades/attendence-summary/hour-display/hour-display.component.scss @@ -1,8 +1,8 @@ :host { - display: inline; + display: inline; } span { - padding: 2px; - border-radius: 7.5%; -} \ No newline at end of file + padding: 2px; + border-radius: 7.5%; +} diff --git a/src/app/admin-view/grades/attendence-summary/hour-display/hour-display.component.spec.ts b/src/app/admin-view/grades/attendence-summary/hour-display/hour-display.component.spec.ts index dac40de..fde16b8 100644 --- a/src/app/admin-view/grades/attendence-summary/hour-display/hour-display.component.spec.ts +++ b/src/app/admin-view/grades/attendence-summary/hour-display/hour-display.component.spec.ts @@ -1,23 +1,22 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { HourDisplayComponent } from './hour-display.component'; +import { HourDisplayComponent } from './hour-display.component' describe('HourDisplayComponent', () => { - let component: HourDisplayComponent; - let fixture: ComponentFixture; + let component: HourDisplayComponent + let fixture: ComponentFixture beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [HourDisplayComponent] - }) - .compileComponents(); - - fixture = TestBed.createComponent(HourDisplayComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + declarations: [HourDisplayComponent], + }).compileComponents() + + fixture = TestBed.createComponent(HourDisplayComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/grades/attendence-summary/hour-display/hour-display.component.ts b/src/app/admin-view/grades/attendence-summary/hour-display/hour-display.component.ts index 4adf26b..39341fa 100644 --- a/src/app/admin-view/grades/attendence-summary/hour-display/hour-display.component.ts +++ b/src/app/admin-view/grades/attendence-summary/hour-display/hour-display.component.ts @@ -1,27 +1,27 @@ -import { Component, Input } from '@angular/core'; -import { DateTime } from "luxon"; +import { Component, Input } from '@angular/core' +import { DateTime } from 'luxon' @Component({ - selector: 'app-hour-display', - templateUrl: './hour-display.component.html', - styleUrl: './hour-display.component.scss', - standalone: false + selector: 'app-hour-display', + templateUrl: './hour-display.component.html', + styleUrl: './hour-display.component.scss', + standalone: false, }) export class HourDisplayComponent { - @Input() value = ""; - - style () { + @Input() value = '' + + style() { if (/(0+[0-9]|1[0-9]|2[0-3]):(0+[0-9]|[1-5][0-9])/g.test(this.value)) { - var diff = DateTime.fromFormat(this.value, "HH:mm").diffNow("minutes") - if (diff.as("minutes") > 30) { - return { "background-color": "red" } - } else if (diff.as("minutes") > 0) { - return { "background-color": "yellow", "color": "black"} + var diff = DateTime.fromFormat(this.value, 'HH:mm').diffNow('minutes') + if (diff.as('minutes') > 30) { + return { 'background-color': 'red' } + } else if (diff.as('minutes') > 0) { + return { 'background-color': 'yellow', color: 'black' } } else { - return { "background-color": "green"} + return { 'background-color': 'green' } } } else { - return { "color": "gray"} + return { color: 'gray' } } } } diff --git a/src/app/admin-view/grades/attendence/attendence.component.spec.ts b/src/app/admin-view/grades/attendence/attendence.component.spec.ts index e80dfa6..0aee3bf 100644 --- a/src/app/admin-view/grades/attendence/attendence.component.spec.ts +++ b/src/app/admin-view/grades/attendence/attendence.component.spec.ts @@ -1,32 +1,36 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { AttendenceComponent } from './attendence.component'; -import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog'; -import { AdminCommService } from '../../admin-comm.service'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { of } from 'rxjs'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { MatInputModule } from '@angular/material/input'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { AttendenceComponent } from './attendence.component' +import { + MAT_DIALOG_DATA, + MatDialogModule, + MatDialogRef, +} from '@angular/material/dialog' +import { AdminCommService } from '../../admin-comm.service' +import { MatFormFieldModule } from '@angular/material/form-field' +import { of } from 'rxjs' +import { FormsModule, ReactiveFormsModule } from '@angular/forms' +import { MatInputModule } from '@angular/material/input' +import { NoopAnimationsModule } from '@angular/platform-browser/animations' describe('AttendenceComponent', () => { - let component: AttendenceComponent; - let fixture: ComponentFixture; + let component: AttendenceComponent + let fixture: ComponentFixture beforeEach(async () => { const acMock = { clean: { attendence: { - getUsers: jasmine.createSpy("getUsers").and.returnValue(of()) - } - } + getUsers: jasmine.createSpy('getUsers').and.returnValue(of()), + }, + }, } await TestBed.configureTestingModule({ declarations: [AttendenceComponent], providers: [ - {provide: MAT_DIALOG_DATA, useValue: {}}, - {provide: MatDialogRef, useValue: {}}, - {provide: AdminCommService, useValue: acMock} + { provide: MAT_DIALOG_DATA, useValue: {} }, + { provide: MatDialogRef, useValue: {} }, + { provide: AdminCommService, useValue: acMock }, ], imports: [ MatDialogModule, @@ -34,17 +38,16 @@ describe('AttendenceComponent', () => { FormsModule, ReactiveFormsModule, MatInputModule, - NoopAnimationsModule - ] - }) - .compileComponents(); - - fixture = TestBed.createComponent(AttendenceComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + NoopAnimationsModule, + ], + }).compileComponents() + + fixture = TestBed.createComponent(AttendenceComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/grades/attendence/attendence.component.ts b/src/app/admin-view/grades/attendence/attendence.component.ts index 1a7bfd8..ed57dec 100644 --- a/src/app/admin-view/grades/attendence/attendence.component.ts +++ b/src/app/admin-view/grades/attendence/attendence.component.ts @@ -1,29 +1,37 @@ -import { Component, Inject, OnInit } from '@angular/core'; -import { FormArray, FormBuilder, FormGroup } from '@angular/forms'; -import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; -import { AdminCommService } from '../../admin-comm.service'; +import { Component, Inject, OnInit } from '@angular/core' +import { FormArray, FormBuilder, FormGroup } from '@angular/forms' +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog' +import { AdminCommService } from '../../admin-comm.service' @Component({ - selector: 'app-attendence', - templateUrl: './attendence.component.html', - styleUrl: './attendence.component.scss', - standalone: false + selector: 'app-attendence', + templateUrl: './attendence.component.html', + styleUrl: './attendence.component.scss', + standalone: false, }) export class AttendenceComponent implements OnInit { - - constructor(private fb: FormBuilder, @Inject(MAT_DIALOG_DATA) public data: { room: string }, public dialogRef: MatDialogRef, private ac: AdminCommService) { } + constructor( + private fb: FormBuilder, + @Inject(MAT_DIALOG_DATA) public data: { room: string }, + public dialogRef: MatDialogRef, + private ac: AdminCommService + ) {} ngOnInit(): void { this.room = this.data.room this.ac.clean.attendence.getUsers(this.room).subscribe(query => { query.users.forEach(v => { - var att = query.attendence ? query.attendence.auto.find(z => z.id == v._id) : false - this.users.push(this.fb.group({ - id: v._id, - label: `${v.fname} ${v.surname}`, - att: this.fb.control(att), - hour: this.fb.control(att ? att.hour : ""), - })) + var att = query.attendence + ? query.attendence.auto.find(z => z.id == v._id) + : false + this.users.push( + this.fb.group({ + id: v._id, + label: `${v.fname} ${v.surname}`, + att: this.fb.control(att), + hour: this.fb.control(att ? att.hour : ''), + }) + ) }) this.form.get('notes')?.setValue(query.attendence?.notes) }) @@ -32,15 +40,15 @@ export class AttendenceComponent implements OnInit { save() { this.dialogRef.close({ room: this.room, - ...this.form.value + ...this.form.value, }) } - room: string = ""; + room: string = '' form: FormGroup = this.fb.group({ users: this.fb.array([]), - notes: this.fb.control(""), + notes: this.fb.control(''), }) get users() { diff --git a/src/app/admin-view/grades/grades.component.scss b/src/app/admin-view/grades/grades.component.scss index 65972e2..86943de 100644 --- a/src/app/admin-view/grades/grades.component.scss +++ b/src/app/admin-view/grades/grades.component.scss @@ -1,10 +1,10 @@ div#things { - display: flex; - flex-direction: column; + display: flex; + flex-direction: column; } div#buttons { - * { - margin: 0 2px 0 2px; - } -} \ No newline at end of file + * { + margin: 0 2px 0 2px; + } +} diff --git a/src/app/admin-view/grades/grades.component.spec.ts b/src/app/admin-view/grades/grades.component.spec.ts index 63c5104..c0f3488 100644 --- a/src/app/admin-view/grades/grades.component.spec.ts +++ b/src/app/admin-view/grades/grades.component.spec.ts @@ -1,52 +1,52 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { GradesComponent } from './grades.component'; -import { AdminCommService } from '../admin-comm.service'; -import { RouterModule } from '@angular/router'; -import { Component, EventEmitter, Input, Output } from '@angular/core'; -import { MatIconModule } from '@angular/material/icon'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { of } from 'rxjs'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { MatInputModule } from '@angular/material/input'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { DateTime } from 'luxon'; +import { GradesComponent } from './grades.component' +import { AdminCommService } from '../admin-comm.service' +import { RouterModule } from '@angular/router' +import { Component, EventEmitter, Input, Output } from '@angular/core' +import { MatIconModule } from '@angular/material/icon' +import { MatFormFieldModule } from '@angular/material/form-field' +import { of } from 'rxjs' +import { FormsModule, ReactiveFormsModule } from '@angular/forms' +import { MatInputModule } from '@angular/material/input' +import { NoopAnimationsModule } from '@angular/platform-browser/animations' +import { DateTime } from 'luxon' @Component({ - selector: "app-date-selector", template: '', - standalone: false + selector: 'app-date-selector', + template: '', + standalone: false, }) class DateSelectorStub { - @Input() date: string = DateTime.now().toISODate(); - @Output() dateChange = new EventEmitter(); - @Input() filter: (date: DateTime | null) => boolean = () => true + @Input() date: string = DateTime.now().toISODate() + @Output() dateChange = new EventEmitter() + @Input() filter: (date: DateTime | null) => boolean = () => true } @Component({ - selector: "app-room-chooser", template: '', - standalone: false + selector: 'app-room-chooser', + template: '', + standalone: false, }) class RoomSelectorStub { @Input() rooms: string[] = [] - @Output() room: EventEmitter = new EventEmitter(); + @Output() room: EventEmitter = new EventEmitter() } describe('GradesComponent', () => { - let component: GradesComponent; - let fixture: ComponentFixture; + let component: GradesComponent + let fixture: ComponentFixture let acMock beforeEach(async () => { acMock = { clean: { - getConfig: jasmine.createSpy("getConfig").and.returnValue(of()) - } + getConfig: jasmine.createSpy('getConfig').and.returnValue(of()), + }, } await TestBed.configureTestingModule({ declarations: [GradesComponent, DateSelectorStub, RoomSelectorStub], - providers: [ - {provide: AdminCommService, useValue: acMock} - ], + providers: [{ provide: AdminCommService, useValue: acMock }], imports: [ RouterModule.forRoot([]), MatIconModule, @@ -54,17 +54,16 @@ describe('GradesComponent', () => { FormsModule, ReactiveFormsModule, MatInputModule, - NoopAnimationsModule - ] - }) - .compileComponents(); - - fixture = TestBed.createComponent(GradesComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + NoopAnimationsModule, + ], + }).compileComponents() + + fixture = TestBed.createComponent(GradesComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/grades/grades.component.ts b/src/app/admin-view/grades/grades.component.ts index 101e633..c05be09 100644 --- a/src/app/admin-view/grades/grades.component.ts +++ b/src/app/admin-view/grades/grades.component.ts @@ -1,46 +1,52 @@ -import { Component, OnDestroy, OnInit } from '@angular/core'; -import { AdminCommService } from '../admin-comm.service'; -import { FormArray, FormBuilder } from '@angular/forms'; -import { weekendFilter } from 'src/app/fd.da'; -import { MatSnackBar } from '@angular/material/snack-bar'; -import { ToolbarService } from '../toolbar/toolbar.service'; -import { ActivatedRoute, Router } from '@angular/router'; -import { MatDialog } from '@angular/material/dialog'; -import { AttendenceComponent } from './attendence/attendence.component'; -import { DateTime } from 'luxon'; +import { Component, OnDestroy, OnInit } from '@angular/core' +import { AdminCommService } from '../admin-comm.service' +import { FormArray, FormBuilder } from '@angular/forms' +import { weekendFilter } from 'src/app/fd.da' +import { MatSnackBar } from '@angular/material/snack-bar' +import { ToolbarService } from '../toolbar/toolbar.service' +import { ActivatedRoute, Router } from '@angular/router' +import { MatDialog } from '@angular/material/dialog' +import { AttendenceComponent } from './attendence/attendence.component' +import { DateTime } from 'luxon' @Component({ - selector: 'app-grades', - templateUrl: './grades.component.html', - styleUrl: './grades.component.scss', - standalone: false + selector: 'app-grades', + templateUrl: './grades.component.html', + styleUrl: './grades.component.scss', + standalone: false, }) export class GradesComponent implements OnInit, OnDestroy { rooms!: string[] - room: string = "0"; - protected _date: DateTime; + room: string = '0' + protected _date: DateTime public get date(): string { - return this._date.toISODate()!; + return this._date.toISODate()! } public set date(value: string) { - this._date = DateTime.fromISO(value); + this._date = DateTime.fromISO(value) } grade: number = 6 - gradeDate?: DateTime; + gradeDate?: DateTime id?: string filter = weekendFilter - get notes(): { label: string, weight: number }[] { - var th = this.things.value as { cb: boolean, label: string, weight: number }[] - return th.filter((v) => v.cb).map((v) => { - return { ...v, cb: undefined } - }) + get notes(): { label: string; weight: number }[] { + var th = this.things.value as { + cb: boolean + label: string + weight: number + }[] + return th + .filter(v => v.cb) + .map(v => { + return { ...v, cb: undefined } + }) } - set notes(value: { label: string, weight: number }[]) { + set notes(value: { label: string; weight: number }[]) { var things = this.things.controls - things.forEach((v) => { - var thing = value.find((s) => s.label == v.get('label')?.value) + things.forEach(v => { + var thing = value.find(s => s.label == v.get('label')?.value) if (thing) { v.get('cb')?.setValue(true) v.get('weight')?.setValue(thing.weight) @@ -51,22 +57,35 @@ export class GradesComponent implements OnInit, OnDestroy { }) } - constructor(private ac: AdminCommService, private fb: FormBuilder, private sb: MatSnackBar, private toolbar: ToolbarService, private router: Router, private route: ActivatedRoute, private dialog: MatDialog) { + constructor( + private ac: AdminCommService, + private fb: FormBuilder, + private sb: MatSnackBar, + private toolbar: ToolbarService, + private router: Router, + private route: ActivatedRoute, + private dialog: MatDialog + ) { this._date = DateTime.now() // if (!this.filter(this.date)) this.date.isoWeekday(8); this.toolbar.comp = this this.toolbar.menu = [ - { title: "Pokoje do sprawdzenia", check: true, fn: "attendenceSummary", icon: "overview"}, - { title: "Podsumowanie", check: true, fn: "summary", icon: "analytics" }, + { + title: 'Pokoje do sprawdzenia', + check: true, + fn: 'attendenceSummary', + icon: 'overview', + }, + { title: 'Podsumowanie', check: true, fn: 'summary', icon: 'analytics' }, ] - this.form.valueChanges.subscribe((v) => { + this.form.valueChanges.subscribe(v => { this.calculate() }) } form = this.fb.group({ things: this.fb.array([]), - tips: this.fb.control("") + tips: this.fb.control(''), }) get things() { @@ -74,21 +93,25 @@ export class GradesComponent implements OnInit, OnDestroy { } summary() { - this.router.navigate(["summary"], { relativeTo: this.route }) + this.router.navigate(['summary'], { relativeTo: this.route }) } attendenceSummary() { - this.router.navigate(["attendenceSummary"], {relativeTo: this.route}) + this.router.navigate(['attendenceSummary'], { relativeTo: this.route }) } ngOnInit(): void { - this.ac.clean.getConfig().subscribe((s) => { + this.ac.clean.getConfig().subscribe(s => { this.rooms = s.rooms - s.things.forEach((s) => this.things.push(this.fb.group({ - cb: this.fb.control(false), - label: this.fb.control(s), - weight: this.fb.control(1) - }))) + s.things.forEach(s => + this.things.push( + this.fb.group({ + cb: this.fb.control(false), + label: this.fb.control(s), + weight: this.fb.control(1), + }) + ) + ) }) } @@ -98,19 +121,19 @@ export class GradesComponent implements OnInit, OnDestroy { } downloadData() { - this.ac.clean.getClean(this.date, this.room).subscribe((v) => { + this.ac.clean.getClean(this.date, this.room).subscribe(v => { if (v) { this.notes = v.notes this.gradeDate = DateTime.fromISO(v.gradeDate) this.grade = v.grade this.id = v._id - this.form.get("tips")?.setValue(v.tips) + this.form.get('tips')?.setValue(v.tips) } else { this.gradeDate = undefined this.grade = 6 this.notes = [] this.id = undefined - this.form.get("tips")?.setValue("") + this.form.get('tips')?.setValue('') } }) } @@ -139,7 +162,7 @@ export class GradesComponent implements OnInit, OnDestroy { weight.setValue(weight.value - 1) } } - } + }, } save() { @@ -149,16 +172,16 @@ export class GradesComponent implements OnInit, OnDestroy { date: this.date, room: this.room, notes: this.notes, - tips: this.form.get("tips")?.value + tips: this.form.get('tips')?.value, } - this.ac.clean.postClean(obj).subscribe((s) => { - this.sb.open("Zapisano!", undefined, { duration: 1500 }) + this.ac.clean.postClean(obj).subscribe(s => { + this.sb.open('Zapisano!', undefined, { duration: 1500 }) this.downloadData() }) } remove() { - this.ac.clean.delete(this.id!).subscribe((s) => { + this.ac.clean.delete(this.id!).subscribe(s => { if (s.status == 200) { this.downloadData() } @@ -171,22 +194,35 @@ export class GradesComponent implements OnInit, OnDestroy { } attendence() { - 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}[]} = { - room: v.room, - users: [] - } - v.users.forEach(i => { - if (i.att && i.hour) { - x.users.push({id: i.id, hour: i.hour}) + 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 }[] } = { + room: v.room, + users: [], + } + v.users.forEach(i => { + if (i.att && i.hour) { + x.users.push({ id: i.id, hour: i.hour }) + } + }) + this.ac.clean.attendence + .postAttendence(x.room, { auto: x.users, notes: v.notes }) + .subscribe(s => { + if (s.status == 200) { + this.sb.open('Zapisano obecność!', undefined, { + duration: 1500, + }) + } + }) } - }) - this.ac.clean.attendence.postAttendence(x.room, {auto: x.users, notes: v.notes}).subscribe((s) => { - if (s.status == 200) { - this.sb.open("Zapisano obecność!", undefined, {duration: 1500}) - } - }) - }) + ) } } diff --git a/src/app/admin-view/grades/summary/summary.component.spec.ts b/src/app/admin-view/grades/summary/summary.component.spec.ts index 1641397..cfc285d 100644 --- a/src/app/admin-view/grades/summary/summary.component.spec.ts +++ b/src/app/admin-view/grades/summary/summary.component.spec.ts @@ -1,34 +1,34 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { SummaryComponent } from './summary.component'; -import { RouterModule } from '@angular/router'; -import { AdminCommService } from '../../admin-comm.service'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatDatepickerModule } from '@angular/material/datepicker'; -import { MatIconModule } from '@angular/material/icon'; -import { of } from 'rxjs'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { MatTableModule } from '@angular/material/table'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { provideLuxonDateAdapter } from '@angular/material-luxon-adapter'; +import { SummaryComponent } from './summary.component' +import { RouterModule } from '@angular/router' +import { AdminCommService } from '../../admin-comm.service' +import { MatFormFieldModule } from '@angular/material/form-field' +import { MatDatepickerModule } from '@angular/material/datepicker' +import { MatIconModule } from '@angular/material/icon' +import { of } from 'rxjs' +import { FormsModule, ReactiveFormsModule } from '@angular/forms' +import { MatTableModule } from '@angular/material/table' +import { NoopAnimationsModule } from '@angular/platform-browser/animations' +import { provideLuxonDateAdapter } from '@angular/material-luxon-adapter' describe('SummaryComponent', () => { - let component: SummaryComponent; - let fixture: ComponentFixture; + let component: SummaryComponent + let fixture: ComponentFixture beforeEach(async () => { const acMock = { clean: { summary: { - getSummary: jasmine.createSpy("getSummary").and.returnValue(of()) - } - } + getSummary: jasmine.createSpy('getSummary').and.returnValue(of()), + }, + }, } await TestBed.configureTestingModule({ declarations: [SummaryComponent], providers: [ { provide: AdminCommService, useValue: acMock }, - provideLuxonDateAdapter() + provideLuxonDateAdapter(), ], imports: [ RouterModule.forRoot([]), @@ -38,17 +38,16 @@ describe('SummaryComponent', () => { FormsModule, ReactiveFormsModule, MatTableModule, - NoopAnimationsModule - ] - }) - .compileComponents(); + NoopAnimationsModule, + ], + }).compileComponents() - fixture = TestBed.createComponent(SummaryComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + fixture = TestBed.createComponent(SummaryComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/grades/summary/summary.component.ts b/src/app/admin-view/grades/summary/summary.component.ts index f5092aa..e8693c4 100644 --- a/src/app/admin-view/grades/summary/summary.component.ts +++ b/src/app/admin-view/grades/summary/summary.component.ts @@ -1,58 +1,68 @@ -import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; -import { ToolbarService } from '../../toolbar/toolbar.service'; -import { ActivatedRoute, Router } from '@angular/router'; -import { AdminCommService } from '../../admin-comm.service'; -import { MatTableDataSource } from '@angular/material/table'; -import { FormBuilder } from '@angular/forms'; -import { MatSort } from '@angular/material/sort'; -import { DateTime } from 'luxon'; +import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core' +import { ToolbarService } from '../../toolbar/toolbar.service' +import { ActivatedRoute, Router } from '@angular/router' +import { AdminCommService } from '../../admin-comm.service' +import { MatTableDataSource } from '@angular/material/table' +import { FormBuilder } from '@angular/forms' +import { MatSort } from '@angular/material/sort' +import { DateTime } from 'luxon' @Component({ - selector: 'app-summary', - templateUrl: './summary.component.html', - styleUrl: './summary.component.scss', - standalone: false + selector: 'app-summary', + templateUrl: './summary.component.html', + styleUrl: './summary.component.scss', + standalone: false, }) export class SummaryComponent implements OnInit, OnDestroy { - - data: MatTableDataSource<{room: string, avg: number}> = new MatTableDataSource<{room: string, avg: number}>(); + data: MatTableDataSource<{ room: string; avg: number }> = + new MatTableDataSource<{ room: string; avg: number }>() collumns = ['room', 'avg'] dateSelector = this.fb.group({ start: this.fb.control(DateTime.utc().startOf('day')), - end: this.fb.control(DateTime.utc().endOf('day')) + end: this.fb.control(DateTime.utc().endOf('day')), }) - @ViewChild(MatSort, {static: false}) set content(sort: MatSort) { + @ViewChild(MatSort, { static: false }) set content(sort: MatSort) { this.data.sort = sort } - constructor (private toolbar: ToolbarService, private router: Router, private route: ActivatedRoute, private ac: AdminCommService, private fb: FormBuilder) { + constructor( + private toolbar: ToolbarService, + private router: Router, + private route: ActivatedRoute, + private ac: AdminCommService, + private fb: FormBuilder + ) { this.toolbar.comp = this this.toolbar.menu = [ - {check: true, title: "Ocenianie", fn: "goBack", icon: "arrow_back"} + { check: true, title: 'Ocenianie', fn: 'goBack', icon: 'arrow_back' }, ] - this.dateSelector.valueChanges.subscribe((v) => { + this.dateSelector.valueChanges.subscribe(v => { this.download() }) } ngOnInit(): void { this.download() } - + download() { - this.ac.clean.summary.getSummary(this.dateSelector.get('start')?.value!.startOf('day')!, this.dateSelector.get('end')?.value!.endOf('day')!).subscribe((v) => { - this.data.data = v - }) + this.ac.clean.summary + .getSummary( + this.dateSelector.get('start')?.value!.startOf('day')!, + this.dateSelector.get('end')?.value!.endOf('day')! + ) + .subscribe(v => { + this.data.data = v + }) } - + goBack() { - this.router.navigate(['../'], {relativeTo: this.route}) + this.router.navigate(['../'], { relativeTo: this.route }) } ngOnDestroy(): void { this.toolbar.comp = undefined this.toolbar.menu = undefined } - } diff --git a/src/app/admin-view/groups/groups.component.scss b/src/app/admin-view/groups/groups.component.scss index 46d77b7..fc953ba 100644 --- a/src/app/admin-view/groups/groups.component.scss +++ b/src/app/admin-view/groups/groups.component.scss @@ -1,12 +1,12 @@ :host { - display: flex; + display: flex; } mat-card { - margin: 15px; - padding: 1ch; + margin: 15px; + padding: 1ch; } mat-card-title { - font-size: 1.5rem; -} \ No newline at end of file + font-size: 1.5rem; +} diff --git a/src/app/admin-view/groups/groups.component.spec.ts b/src/app/admin-view/groups/groups.component.spec.ts index 72f9172..82b75cb 100644 --- a/src/app/admin-view/groups/groups.component.spec.ts +++ b/src/app/admin-view/groups/groups.component.spec.ts @@ -1,31 +1,29 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { GroupsComponent } from './groups.component'; -import { AdminCommService } from '../admin-comm.service'; -import { of } from 'rxjs'; +import { GroupsComponent } from './groups.component' +import { AdminCommService } from '../admin-comm.service' +import { of } from 'rxjs' describe('GroupsComponent', () => { - let component: GroupsComponent; - let fixture: ComponentFixture; + let component: GroupsComponent + let fixture: ComponentFixture beforeEach(() => { const acMock = { groups: { - getGroups: jasmine.createSpy("getGroups").and.returnValue(of()) - } + getGroups: jasmine.createSpy('getGroups').and.returnValue(of()), + }, } TestBed.configureTestingModule({ declarations: [GroupsComponent], - providers: [ - {provide: AdminCommService, useValue: acMock} - ] - }); - fixture = TestBed.createComponent(GroupsComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + providers: [{ provide: AdminCommService, useValue: acMock }], + }) + fixture = TestBed.createComponent(GroupsComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/groups/groups.component.ts b/src/app/admin-view/groups/groups.component.ts index 4e51a89..fc1515f 100644 --- a/src/app/admin-view/groups/groups.component.ts +++ b/src/app/admin-view/groups/groups.component.ts @@ -1,21 +1,24 @@ -import { Component, OnInit } from '@angular/core'; -import { AdminCommService } from '../admin-comm.service'; -import { Group } from 'src/app/types/group'; -import { Status } from 'src/app/types/status'; -import { MatDialog } from '@angular/material/dialog'; -import { RemoveConfirmComponent } from './remove-confirm/remove-confirm.component'; +import { Component, OnInit } from '@angular/core' +import { AdminCommService } from '../admin-comm.service' +import { Group } from 'src/app/types/group' +import { Status } from 'src/app/types/status' +import { MatDialog } from '@angular/material/dialog' +import { RemoveConfirmComponent } from './remove-confirm/remove-confirm.component' @Component({ - selector: 'app-groups', - templateUrl: './groups.component.html', - styleUrls: ['./groups.component.scss'], - standalone: false + selector: 'app-groups', + templateUrl: './groups.component.html', + styleUrls: ['./groups.component.scss'], + standalone: false, }) export class GroupsComponent implements OnInit { groups?: Group[] - constructor (protected readonly acs: AdminCommService, private readonly dialog: MatDialog) {} + constructor( + protected readonly acs: AdminCommService, + private readonly dialog: MatDialog + ) {} ngOnInit(): void { - this.acs.groups.getGroups().subscribe((v) => { + this.acs.groups.getGroups().subscribe(v => { this.groups = v }) } @@ -26,36 +29,41 @@ export class GroupsComponent implements OnInit { } } - get groupOptions(): {id: string, text: string}[] { - return this.groups!.map((v)=> {return {id: v._id as string, text: v.name as string}}) + get groupOptions(): { id: string; text: string }[] { + return this.groups!.map(v => { + return { id: v._id as string, text: v.name as string } + }) } protected getId(g: Group[] | undefined) { if (!g) return undefined - return g.map((v)=>v._id) + return g.map(v => v._id) } groupNames(groups: Group[]) { - return groups.flatMap((g) => g.name) + return groups.flatMap(g => g.name) } protected nameEdit(id: string, name: string | string[]) { name = name as string - this.acs.groups.editName(id, name).subscribe((s) => this.refreshIfGood(s)) + this.acs.groups.editName(id, name).subscribe(s => this.refreshIfGood(s)) } protected newGroup() { - let name = prompt("Nazwa grupy") + let name = prompt('Nazwa grupy') if (name) { - this.acs.groups.newGroup(name).subscribe((s) => this.refreshIfGood(s)) + this.acs.groups.newGroup(name).subscribe(s => this.refreshIfGood(s)) } } - + protected remove(id: string) { - this.dialog.open(RemoveConfirmComponent).afterClosed().subscribe((v) => { - if (v) { - this.acs.groups.remove(id).subscribe((s) => this.refreshIfGood(s)) - } - }) + this.dialog + .open(RemoveConfirmComponent) + .afterClosed() + .subscribe(v => { + if (v) { + this.acs.groups.remove(id).subscribe(s => this.refreshIfGood(s)) + } + }) } } diff --git a/src/app/admin-view/groups/remove-confirm/remove-confirm.component.spec.ts b/src/app/admin-view/groups/remove-confirm/remove-confirm.component.spec.ts index fcca4c3..ed4e6b0 100644 --- a/src/app/admin-view/groups/remove-confirm/remove-confirm.component.spec.ts +++ b/src/app/admin-view/groups/remove-confirm/remove-confirm.component.spec.ts @@ -1,23 +1,23 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { RemoveConfirmComponent } from './remove-confirm.component'; -import { MatDialogModule } from '@angular/material/dialog'; +import { RemoveConfirmComponent } from './remove-confirm.component' +import { MatDialogModule } from '@angular/material/dialog' describe('RemoveConfirmComponent', () => { - let component: RemoveConfirmComponent; - let fixture: ComponentFixture; + let component: RemoveConfirmComponent + let fixture: ComponentFixture beforeEach(() => { TestBed.configureTestingModule({ declarations: [RemoveConfirmComponent], - imports: [MatDialogModule] - }); - fixture = TestBed.createComponent(RemoveConfirmComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [MatDialogModule], + }) + fixture = TestBed.createComponent(RemoveConfirmComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/groups/remove-confirm/remove-confirm.component.ts b/src/app/admin-view/groups/remove-confirm/remove-confirm.component.ts index e41f5b6..e43ea51 100644 --- a/src/app/admin-view/groups/remove-confirm/remove-confirm.component.ts +++ b/src/app/admin-view/groups/remove-confirm/remove-confirm.component.ts @@ -1,11 +1,9 @@ -import { Component } from '@angular/core'; +import { Component } from '@angular/core' @Component({ - selector: 'app-remove-confirm', - templateUrl: './remove-confirm.component.html', - styleUrls: ['./remove-confirm.component.scss'], - standalone: false + selector: 'app-remove-confirm', + templateUrl: './remove-confirm.component.html', + styleUrls: ['./remove-confirm.component.scss'], + standalone: false, }) -export class RemoveConfirmComponent { - -} +export class RemoveConfirmComponent {} diff --git a/src/app/admin-view/key/key.component.scss b/src/app/admin-view/key/key.component.scss index 04ebe7c..27a1492 100644 --- a/src/app/admin-view/key/key.component.scss +++ b/src/app/admin-view/key/key.component.scss @@ -1,5 +1,5 @@ #upper-bar { - display: flex; - align-items: baseline; - gap: 4pt; -} \ No newline at end of file + display: flex; + align-items: baseline; + gap: 4pt; +} diff --git a/src/app/admin-view/key/key.component.spec.ts b/src/app/admin-view/key/key.component.spec.ts index 2858ee0..ebf3d0c 100644 --- a/src/app/admin-view/key/key.component.spec.ts +++ b/src/app/admin-view/key/key.component.spec.ts @@ -1,44 +1,51 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { AdminKeyComponent } from './key.component'; -import { of } from 'rxjs'; -import { AdminCommService } from '../admin-comm.service'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatChipsModule } from '@angular/material/chips'; -import { MatIconModule } from '@angular/material/icon'; -import { MatPaginatorModule } from '@angular/material/paginator'; -import { FormsModule } from '@angular/forms'; -import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; -import { MatTableModule } from '@angular/material/table'; -import { MatInputModule } from '@angular/material/input'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { AdminKeyComponent } from './key.component' +import { of } from 'rxjs' +import { AdminCommService } from '../admin-comm.service' +import { MatFormFieldModule } from '@angular/material/form-field' +import { MatChipsModule } from '@angular/material/chips' +import { MatIconModule } from '@angular/material/icon' +import { MatPaginatorModule } from '@angular/material/paginator' +import { FormsModule } from '@angular/forms' +import { MatProgressSpinnerModule } from '@angular/material/progress-spinner' +import { MatTableModule } from '@angular/material/table' +import { MatInputModule } from '@angular/material/input' +import { NoopAnimationsModule } from '@angular/platform-browser/animations' describe('AdminKeyComponent', () => { - let component: AdminKeyComponent; - let fixture: ComponentFixture; + let component: AdminKeyComponent + let fixture: ComponentFixture let acMock beforeEach(async () => { acMock = { keys: { - getKeys: jasmine.createSpy("getKeys").and.returnValue(of()) - } + getKeys: jasmine.createSpy('getKeys').and.returnValue(of()), + }, } await TestBed.configureTestingModule({ declarations: [AdminKeyComponent], - providers: [ - {provide: AdminCommService, useValue: acMock} + providers: [{ provide: AdminCommService, useValue: acMock }], + imports: [ + MatFormFieldModule, + MatChipsModule, + MatIconModule, + MatPaginatorModule, + FormsModule, + MatProgressSpinnerModule, + MatTableModule, + MatInputModule, + NoopAnimationsModule, ], - imports: [MatFormFieldModule, MatChipsModule, MatIconModule, MatPaginatorModule, FormsModule, MatProgressSpinnerModule, MatTableModule, MatInputModule, NoopAnimationsModule] - }) - .compileComponents(); - - fixture = TestBed.createComponent(AdminKeyComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + }).compileComponents() + + fixture = TestBed.createComponent(AdminKeyComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/key/key.component.ts b/src/app/admin-view/key/key.component.ts index 2b97e95..8fc65cd 100644 --- a/src/app/admin-view/key/key.component.ts +++ b/src/app/admin-view/key/key.component.ts @@ -1,46 +1,50 @@ -import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core'; -import { MatPaginator } from '@angular/material/paginator'; -import { MatTableDataSource } from '@angular/material/table'; -import { AKey } from 'src/app/types/key'; -import { AdminCommService } from '../admin-comm.service'; -import { MatDialog } from '@angular/material/dialog'; -import { NewKeyComponent } from './new-key/new-key.component'; -import { catchError, throwError } from 'rxjs'; -import { MatSnackBar } from '@angular/material/snack-bar'; +import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core' +import { MatPaginator } from '@angular/material/paginator' +import { MatTableDataSource } from '@angular/material/table' +import { AKey } from 'src/app/types/key' +import { AdminCommService } from '../admin-comm.service' +import { MatDialog } from '@angular/material/dialog' +import { NewKeyComponent } from './new-key/new-key.component' +import { catchError, throwError } from 'rxjs' +import { MatSnackBar } from '@angular/material/snack-bar' @Component({ - selector: 'app-admin-key', - templateUrl: './key.component.html', - styleUrl: './key.component.scss', - standalone: false + selector: 'app-admin-key', + templateUrl: './key.component.html', + styleUrl: './key.component.scss', + standalone: false, }) export class AdminKeyComponent implements AfterViewInit, OnInit { - keys: MatTableDataSource = new MatTableDataSource(); + keys: MatTableDataSource = new MatTableDataSource() pureData: AKey[] = [] - private _filters: string[] = []; + private _filters: string[] = [] public get filters(): string[] { - return this._filters; + return this._filters } collumns = ['room', 'whom', 'borrow', 'tb', 'actions'] public set filters(value: string[]) { - if (value.includes("showAll")) { + if (value.includes('showAll')) { this.collumns = ['room', 'whom', 'borrow', 'tb', 'actions'] } else { this.collumns = ['room', 'whom', 'borrow', 'actions'] } - this._filters = value; - this.transformData(); + this._filters = value + this.transformData() } loading = true @ViewChild(MatPaginator) paginator!: MatPaginator - - constructor (private ac: AdminCommService, private dialog: MatDialog, private sb: MatSnackBar) { + + constructor( + private ac: AdminCommService, + private dialog: MatDialog, + private sb: MatSnackBar + ) { this.filters = [] } - + fetchData() { this.loading = true - this.ac.keys.getKeys().subscribe((r) => { + this.ac.keys.getKeys().subscribe(r => { this.loading = false this.pureData = r this.transformData() @@ -49,15 +53,16 @@ export class AdminKeyComponent implements AfterViewInit, OnInit { transformData() { var finalData: AKey[] = this.pureData - if (!this.filters.includes('showAll')) finalData = finalData.filter((v) => v.tb == undefined) + if (!this.filters.includes('showAll')) + finalData = finalData.filter(v => v.tb == undefined) this.keys.data = finalData } - + filter(event: Event) { const value = (event.target as HTMLInputElement).value this.keys.filter = value.toLowerCase().trim() } - + ngAfterViewInit(): void { this.keys.paginator = this.paginator } @@ -68,26 +73,36 @@ export class AdminKeyComponent implements AfterViewInit, OnInit { // {room: "Kawiarenka", borrow: moment().subtract(15, "minutes"), whom: {_id: "test", room: 303, uname: "sk"}} // ] } - + new() { - this.dialog.open(NewKeyComponent).afterClosed().subscribe(v => { - if (v) { - this.ac.keys.postKey(v.room, v.user).pipe(catchError((err,caught)=>{ - if (err.status == 404) { - this.sb.open("Nie znaleziono użytkownika", undefined, {duration: 2500}) - } - return throwError(() => new Error(err.message)) - })).subscribe((s) => { - if (s.status == 201) { - this.fetchData() - } - }) - } - }) + this.dialog + .open(NewKeyComponent) + .afterClosed() + .subscribe(v => { + if (v) { + this.ac.keys + .postKey(v.room, v.user) + .pipe( + catchError((err, caught) => { + if (err.status == 404) { + this.sb.open('Nie znaleziono użytkownika', undefined, { + duration: 2500, + }) + } + return throwError(() => new Error(err.message)) + }) + ) + .subscribe(s => { + if (s.status == 201) { + this.fetchData() + } + }) + } + }) } - + tb(id: string) { - this.ac.keys.returnKey(id).subscribe((r) => { + this.ac.keys.returnKey(id).subscribe(r => { if (r.status == 200) { this.fetchData() } diff --git a/src/app/admin-view/key/new-key/new-key.component.scss b/src/app/admin-view/key/new-key/new-key.component.scss index 3ee2b75..6807926 100644 --- a/src/app/admin-view/key/new-key/new-key.component.scss +++ b/src/app/admin-view/key/new-key/new-key.component.scss @@ -1,4 +1,4 @@ form { - display: flex; - flex-direction: column; -} \ No newline at end of file + display: flex; + flex-direction: column; +} diff --git a/src/app/admin-view/key/new-key/new-key.component.spec.ts b/src/app/admin-view/key/new-key/new-key.component.spec.ts index 2606dc2..503a615 100644 --- a/src/app/admin-view/key/new-key/new-key.component.spec.ts +++ b/src/app/admin-view/key/new-key/new-key.component.spec.ts @@ -1,42 +1,58 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { NewKeyComponent } from './new-key.component'; -import { AdminCommService } from '../../admin-comm.service'; -import { MatDialogModule, MatDialogRef } from '@angular/material/dialog'; -import { MatFormFieldControl, MatFormFieldModule } from '@angular/material/form-field'; -import { MatSelectModule } from '@angular/material/select'; -import { Component, forwardRef, Optional, Self } from '@angular/core'; -import { Observable, of } from 'rxjs'; -import { AbstractControlDirective, ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR, NgControl, ReactiveFormsModule } from '@angular/forms'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { NewKeyComponent } from './new-key.component' +import { AdminCommService } from '../../admin-comm.service' +import { MatDialogModule, MatDialogRef } from '@angular/material/dialog' +import { + MatFormFieldControl, + MatFormFieldModule, +} from '@angular/material/form-field' +import { MatSelectModule } from '@angular/material/select' +import { Component, forwardRef, Optional, Self } from '@angular/core' +import { Observable, of } from 'rxjs' +import { + AbstractControlDirective, + ControlValueAccessor, + FormsModule, + NG_VALUE_ACCESSOR, + NgControl, + ReactiveFormsModule, +} from '@angular/forms' +import { NoopAnimationsModule } from '@angular/platform-browser/animations' @Component({ - selector: "app-user-search", template: '', providers: [{ - provide: NG_VALUE_ACCESSOR, - useExisting: forwardRef(() => UserSearchStub), - multi: true, - }, - { - provide: MatFormFieldControl, - useExisting: UserSearchStub - }], - standalone: false + selector: 'app-user-search', + template: '', + providers: [ + { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => UserSearchStub), + multi: true, + }, + { + provide: MatFormFieldControl, + useExisting: UserSearchStub, + }, + ], + standalone: false, }) -class UserSearchStub implements ControlValueAccessor, MatFormFieldControl { - value: null = null; - stateChanges: Observable = of(); - id: string = ""; - placeholder: string = ""; - ngControl: NgControl | AbstractControlDirective | null = null; - focused: boolean = false; - empty: boolean = true; - shouldLabelFloat: boolean = true; - required: boolean = false; - disabled: boolean = false; - errorState: boolean = false; - controlType?: string | undefined; - autofilled?: boolean | undefined; - userAriaDescribedBy?: string | undefined; +class UserSearchStub + implements ControlValueAccessor, MatFormFieldControl +{ + value: null = null + stateChanges: Observable = of() + id: string = '' + placeholder: string = '' + ngControl: NgControl | AbstractControlDirective | null = null + focused: boolean = false + empty: boolean = true + shouldLabelFloat: boolean = true + required: boolean = false + disabled: boolean = false + errorState: boolean = false + controlType?: string | undefined + autofilled?: boolean | undefined + userAriaDescribedBy?: string | undefined setDescribedByIds(ids: string[]): void {} onContainerClick(event: MouseEvent): void {} writeValue(obj: any): void {} @@ -46,21 +62,21 @@ class UserSearchStub implements ControlValueAccessor, MatFormFieldControl } describe('NewKeyComponent', () => { - let component: NewKeyComponent; - let fixture: ComponentFixture; + let component: NewKeyComponent + let fixture: ComponentFixture let acMock beforeEach(async () => { acMock = { keys: { - avalKeys: jasmine.createSpy("avalKeys").and.returnValue(of()) - } + avalKeys: jasmine.createSpy('avalKeys').and.returnValue(of()), + }, } await TestBed.configureTestingModule({ declarations: [NewKeyComponent, UserSearchStub], providers: [ { provide: AdminCommService, useValue: acMock }, - { provide: MatDialogRef, useValue: {} } + { provide: MatDialogRef, useValue: {} }, ], imports: [ MatDialogModule, @@ -68,17 +84,16 @@ describe('NewKeyComponent', () => { MatSelectModule, FormsModule, ReactiveFormsModule, - NoopAnimationsModule - ] - }) - .compileComponents(); + NoopAnimationsModule, + ], + }).compileComponents() - fixture = TestBed.createComponent(NewKeyComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + fixture = TestBed.createComponent(NewKeyComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/key/new-key/new-key.component.ts b/src/app/admin-view/key/new-key/new-key.component.ts index 03c2bfb..eb70ad0 100644 --- a/src/app/admin-view/key/new-key/new-key.component.ts +++ b/src/app/admin-view/key/new-key/new-key.component.ts @@ -1,26 +1,29 @@ -import { Component, OnInit } from '@angular/core'; -import { AdminCommService } from '../../admin-comm.service'; -import { MatDialogRef } from '@angular/material/dialog'; -import { FormControl, FormGroup } from '@angular/forms'; -import { UserSearchResult } from 'src/app/commonComponents/user-search/user-search.component'; +import { Component, OnInit } from '@angular/core' +import { AdminCommService } from '../../admin-comm.service' +import { MatDialogRef } from '@angular/material/dialog' +import { FormControl, FormGroup } from '@angular/forms' +import { UserSearchResult } from 'src/app/commonComponents/user-search/user-search.component' @Component({ - selector: 'app-new-key', - templateUrl: './new-key.component.html', - styleUrl: './new-key.component.scss', - standalone: false + selector: 'app-new-key', + templateUrl: './new-key.component.html', + styleUrl: './new-key.component.scss', + standalone: false, }) export class NewKeyComponent implements OnInit { rooms: string[] = [] form = new FormGroup({ - room: new FormControl(""), - user: new FormControl(null) + room: new FormControl(''), + user: new FormControl(null), }) unames: any[] = [] - constructor ( private ac: AdminCommService, public dialogRef: MatDialogRef ) {} + constructor( + private ac: AdminCommService, + public dialogRef: MatDialogRef + ) {} ngOnInit(): void { - this.ac.keys.avalKeys().subscribe((v) => { + this.ac.keys.avalKeys().subscribe(v => { this.rooms = v }) } @@ -28,7 +31,6 @@ export class NewKeyComponent implements OnInit { send() { if (this.form.valid) { this.dialogRef.close(this.form.value) - } + } } - } diff --git a/src/app/admin-view/menu-new/menu-add/menu-add.component.spec.ts b/src/app/admin-view/menu-new/menu-add/menu-add.component.spec.ts index edddd4d..0de82b8 100644 --- a/src/app/admin-view/menu-new/menu-add/menu-add.component.spec.ts +++ b/src/app/admin-view/menu-new/menu-add/menu-add.component.spec.ts @@ -1,36 +1,39 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { MenuAddComponent } from './menu-add.component'; -import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog'; -import { MatRadioModule } from '@angular/material/radio'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { MenuAddComponent } from './menu-add.component' +import { + MAT_DIALOG_DATA, + MatDialogModule, + MatDialogRef, +} from '@angular/material/dialog' +import { MatRadioModule } from '@angular/material/radio' +import { FormsModule, ReactiveFormsModule } from '@angular/forms' describe('MenuAddComponent', () => { - let component: MenuAddComponent; - let fixture: ComponentFixture; + let component: MenuAddComponent + let fixture: ComponentFixture beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [MenuAddComponent], providers: [ - {provide: MAT_DIALOG_DATA, useValue: {}}, - {provide: MatDialogRef, useValue: {}} + { provide: MAT_DIALOG_DATA, useValue: {} }, + { provide: MatDialogRef, useValue: {} }, ], imports: [ MatDialogModule, MatRadioModule, ReactiveFormsModule, - FormsModule - ] - }) - .compileComponents(); - - fixture = TestBed.createComponent(MenuAddComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + FormsModule, + ], + }).compileComponents() + + fixture = TestBed.createComponent(MenuAddComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/menu-new/menu-add/menu-add.component.ts b/src/app/admin-view/menu-new/menu-add/menu-add.component.ts index 78b596f..aef9fc3 100644 --- a/src/app/admin-view/menu-new/menu-add/menu-add.component.ts +++ b/src/app/admin-view/menu-new/menu-add/menu-add.component.ts @@ -1,51 +1,60 @@ -import { Component } from '@angular/core'; -import { MenuUploadComponent } from '../menu-upload/menu-upload.component'; -import { MatDialog, MatDialogRef } from '@angular/material/dialog'; -import { FDSelection, weekendFilter } from 'src/app/fd.da'; -import { FormControl, FormGroup } from '@angular/forms'; -import { MAT_DATE_RANGE_SELECTION_STRATEGY } from '@angular/material/datepicker'; -import { DateTime } from 'luxon'; +import { Component } from '@angular/core' +import { MenuUploadComponent } from '../menu-upload/menu-upload.component' +import { MatDialog, MatDialogRef } from '@angular/material/dialog' +import { FDSelection, weekendFilter } from 'src/app/fd.da' +import { FormControl, FormGroup } from '@angular/forms' +import { MAT_DATE_RANGE_SELECTION_STRATEGY } from '@angular/material/datepicker' +import { DateTime } from 'luxon' @Component({ - selector: 'app-menu-add', - templateUrl: './menu-add.component.html', - styleUrl: './menu-add.component.scss', - providers: [ - { provide: MAT_DATE_RANGE_SELECTION_STRATEGY, useClass: FDSelection } - ], - standalone: false + selector: 'app-menu-add', + templateUrl: './menu-add.component.html', + styleUrl: './menu-add.component.scss', + providers: [ + { provide: MAT_DATE_RANGE_SELECTION_STRATEGY, useClass: FDSelection }, + ], + standalone: false, }) export class MenuAddComponent { - type: string | undefined; + type: string | undefined filter = weekendFilter - day: string = DateTime.now().toISODate(); + day: string = DateTime.now().toISODate() range = new FormGroup({ - start: new FormControl(null), - end: new FormControl(null), + start: new FormControl(null), + end: new FormControl(null), }) - constructor (public dialogRef: MatDialogRef, private dialog: MatDialog) { } + constructor( + public dialogRef: MatDialogRef, + private dialog: MatDialog + ) {} submit() { switch (this.type) { - case "day": - this.dialogRef.close({type: "day", value: this.day}) - break; - case "week": - this.dialogRef.close({type: "week", value: {start: this.range.value.start?.toISODate(), count: 5}}) - break; + case 'day': + this.dialogRef.close({ type: 'day', value: this.day }) + break + case 'week': + this.dialogRef.close({ + type: 'week', + value: { start: this.range.value.start?.toISODate(), count: 5 }, + }) + break default: - break; + break } } activateUpload() { - this.dialog.open(MenuUploadComponent).afterClosed().subscribe((data) => { - if (data) { - this.dialogRef.close({type: "file", ...data}); - } - }) + this.dialog + .open(MenuUploadComponent) + .afterClosed() + .subscribe(data => { + if (data) { + this.dialogRef.close({ type: 'file', ...data }) + } + }) } } diff --git a/src/app/admin-view/menu-new/menu-new.component.scss b/src/app/admin-view/menu-new/menu-new.component.scss index 22350a6..078bdcb 100644 --- a/src/app/admin-view/menu-new/menu-new.component.scss +++ b/src/app/admin-view/menu-new/menu-new.component.scss @@ -1,18 +1,18 @@ #upper-bar { - display: flex; + display: flex; } mat-form-field { - flex-grow: 1; + flex-grow: 1; } button[mat-icon-button] { - margin-left: 4pt; - margin-right: 4pt; - margin-top: 4pt; + margin-left: 4pt; + margin-right: 4pt; + margin-top: 4pt; } .non-editable { - color: gray; - font-style: italic; -} \ No newline at end of file + color: gray; + font-style: italic; +} diff --git a/src/app/admin-view/menu-new/menu-new.component.spec.ts b/src/app/admin-view/menu-new/menu-new.component.spec.ts index eb0ee61..e730464 100644 --- a/src/app/admin-view/menu-new/menu-new.component.spec.ts +++ b/src/app/admin-view/menu-new/menu-new.component.spec.ts @@ -1,41 +1,52 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { MenuNewComponent } from './menu-new.component'; -import { MatTableModule } from '@angular/material/table'; -import { MatInputModule } from '@angular/material/input'; -import { MAT_DATE_RANGE_SELECTION_STRATEGY, MatDatepickerModule } from '@angular/material/datepicker'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { FDSelection } from 'src/app/fd.da'; -import { ReactiveFormsModule } from '@angular/forms'; -import { AdminCommService } from '../admin-comm.service'; -import { of } from 'rxjs'; -import { MatDialogModule } from '@angular/material/dialog'; -import { MatIconModule } from '@angular/material/icon'; -import { provideLuxonDateAdapter } from '@angular/material-luxon-adapter'; +import { MenuNewComponent } from './menu-new.component' +import { MatTableModule } from '@angular/material/table' +import { MatInputModule } from '@angular/material/input' +import { + MAT_DATE_RANGE_SELECTION_STRATEGY, + MatDatepickerModule, +} from '@angular/material/datepicker' +import { BrowserAnimationsModule } from '@angular/platform-browser/animations' +import { FDSelection } from 'src/app/fd.da' +import { ReactiveFormsModule } from '@angular/forms' +import { AdminCommService } from '../admin-comm.service' +import { of } from 'rxjs' +import { MatDialogModule } from '@angular/material/dialog' +import { MatIconModule } from '@angular/material/icon' +import { provideLuxonDateAdapter } from '@angular/material-luxon-adapter' describe('MenuNewComponent', () => { - let component: MenuNewComponent; - let fixture: ComponentFixture; + let component: MenuNewComponent + let fixture: ComponentFixture beforeEach(() => { const acMock = jasmine.createSpyObj('AdminCommService', { - getMenu: of() + getMenu: of(), }) TestBed.configureTestingModule({ declarations: [MenuNewComponent], - imports: [MatTableModule, MatInputModule, MatDatepickerModule, BrowserAnimationsModule, ReactiveFormsModule, MatDialogModule, MatIconModule], + imports: [ + MatTableModule, + MatInputModule, + MatDatepickerModule, + BrowserAnimationsModule, + ReactiveFormsModule, + MatDialogModule, + MatIconModule, + ], providers: [ provideLuxonDateAdapter(), - {provide: MAT_DATE_RANGE_SELECTION_STRATEGY, useClass: FDSelection}, - {provide: AdminCommService, useValue: acMock} + { provide: MAT_DATE_RANGE_SELECTION_STRATEGY, useClass: FDSelection }, + { provide: AdminCommService, useValue: acMock }, ], - }); - fixture = TestBed.createComponent(MenuNewComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + }) + fixture = TestBed.createComponent(MenuNewComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/menu-new/menu-new.component.ts b/src/app/admin-view/menu-new/menu-new.component.ts index 346358d..a62c1e5 100644 --- a/src/app/admin-view/menu-new/menu-new.component.ts +++ b/src/app/admin-view/menu-new/menu-new.component.ts @@ -1,85 +1,105 @@ -import { Component } from '@angular/core'; -import { FormControl, FormGroup } from '@angular/forms'; -import { MAT_DATE_RANGE_SELECTION_STRATEGY } from '@angular/material/datepicker'; -import { FDSelection } from 'src/app/fd.da'; -import { Menu } from 'src/app/types/menu'; -import { AdminCommService } from '../admin-comm.service'; -import { MatTableDataSource } from '@angular/material/table'; -import { MatDialog } from '@angular/material/dialog'; -import { MenuUploadComponent } from './menu-upload/menu-upload.component'; -import { Status } from 'src/app/types/status'; -import { MatSnackBar } from '@angular/material/snack-bar'; -import { MenuAddComponent } from './menu-add/menu-add.component'; -import { LocalStorageService } from 'src/app/services/local-storage.service'; -import { DateTime } from 'luxon'; +import { Component } from '@angular/core' +import { FormControl, FormGroup } from '@angular/forms' +import { MAT_DATE_RANGE_SELECTION_STRATEGY } from '@angular/material/datepicker' +import { FDSelection } from 'src/app/fd.da' +import { Menu } from 'src/app/types/menu' +import { AdminCommService } from '../admin-comm.service' +import { MatTableDataSource } from '@angular/material/table' +import { MatDialog } from '@angular/material/dialog' +import { MenuUploadComponent } from './menu-upload/menu-upload.component' +import { Status } from 'src/app/types/status' +import { MatSnackBar } from '@angular/material/snack-bar' +import { MenuAddComponent } from './menu-add/menu-add.component' +import { LocalStorageService } from 'src/app/services/local-storage.service' +import { DateTime } from 'luxon' @Component({ - selector: 'app-menu-new', - templateUrl: './menu-new.component.html', - styleUrls: ['./menu-new.component.scss'], - providers: [ - { provide: MAT_DATE_RANGE_SELECTION_STRATEGY, useClass: FDSelection } - ], - standalone: false + selector: 'app-menu-new', + templateUrl: './menu-new.component.html', + styleUrls: ['./menu-new.component.scss'], + providers: [ + { provide: MAT_DATE_RANGE_SELECTION_STRATEGY, useClass: FDSelection }, + ], + standalone: false, }) export class MenuNewComponent { dcols: string[] = ['day', 'sn', 'ob', 'kol'] dataSource: MatTableDataSource = new MatTableDataSource() range = new FormGroup({ - start: new FormControl(null), - end: new FormControl(null), + start: new FormControl(null), + end: new FormControl(null), }) loading = false - public options: any; + public options: any - constructor (private ac: AdminCommService, private dialog: MatDialog, private sb: MatSnackBar, readonly ls: LocalStorageService) { } + constructor( + private ac: AdminCommService, + private dialog: MatDialog, + private sb: MatSnackBar, + readonly ls: LocalStorageService + ) {} print() { - this.ac.menu.print(this.range.value.start, this.range.value.end)?.subscribe((r) => { - if (r && r.length > 0) { - var mywindow = window.open(undefined, 'Drukowanie', 'height=400,width=400') - mywindow?.document.write(r) - mywindow?.print() - mywindow?.close() - } - }) + this.ac.menu + .print(this.range.value.start, this.range.value.end) + ?.subscribe(r => { + if (r && r.length > 0) { + var mywindow = window.open( + undefined, + 'Drukowanie', + 'height=400,width=400' + ) + mywindow?.document.write(r) + mywindow?.print() + mywindow?.close() + } + }) } addDate() { - this.dialog.open(MenuAddComponent).afterClosed().subscribe((data) => { - if (data) { - switch (data.type) { - case "day": - this.ac.menu.new.single(data.value).subscribe(s => this.refreshIfGood(s)) - break; - case "week": - this.ac.menu.new.range(data.value.start, data.value.count).subscribe(s => this.refreshIfGood(s)) - break; - case "file": - this.requestData() - break; - default: - break; + this.dialog + .open(MenuAddComponent) + .afterClosed() + .subscribe(data => { + if (data) { + switch (data.type) { + case 'day': + this.ac.menu.new + .single(data.value) + .subscribe(s => this.refreshIfGood(s)) + break + case 'week': + this.ac.menu.new + .range(data.value.start, data.value.count) + .subscribe(s => this.refreshIfGood(s)) + break + case 'file': + this.requestData() + break + default: + break + } } - } - }) + }) } - + requestData() { this.loading = true - this.ac.menu.getOpts().subscribe((o) => { - this.options = o; + this.ac.menu.getOpts().subscribe(o => { + this.options = o }) - this.ac.menu.getMenu(this.range.value.start, this.range.value.end)?.subscribe((data) => { - this.loading = false - this.dataSource.data = data.map((v) => { - let newMenu: Menu = { - ...v, - day: DateTime.fromISO(v.day) - } - return newMenu + this.ac.menu + .getMenu(this.range.value.start, this.range.value.end) + ?.subscribe(data => { + this.loading = false + this.dataSource.data = data.map(v => { + let newMenu: Menu = { + ...v, + day: DateTime.fromISO(v.day), + } + return newMenu + }) }) - }) } private refreshIfGood(s: Status) { @@ -87,33 +107,52 @@ export class MenuNewComponent { this.requestData() } } - + activateUpload() { - this.dialog.open(MenuUploadComponent).afterClosed().subscribe((data) => { - if (data) { - this.requestData() - } - }) + this.dialog + .open(MenuUploadComponent) + .afterClosed() + .subscribe(data => { + if (data) { + this.requestData() + } + }) } editSn(id: string) { - this.ac.menu.editSn(id, this.dataSource.data.find(v => v._id == id)!.sn).subscribe(s => this.refreshIfGood(s)) + this.ac.menu + .editSn(id, this.dataSource.data.find(v => v._id == id)!.sn) + .subscribe(s => this.refreshIfGood(s)) } editOb(id: string) { - this.ac.menu.editOb(id, this.dataSource.data.find(v => v._id == id)!.ob).subscribe(s => this.refreshIfGood(s)) + this.ac.menu + .editOb(id, this.dataSource.data.find(v => v._id == id)!.ob) + .subscribe(s => this.refreshIfGood(s)) } editKol(id: string) { - this.ac.menu.editKol(id, this.dataSource.data.find(v => v._id == id)?.kol).subscribe(s => this.refreshIfGood(s)) + this.ac.menu + .editKol(id, this.dataSource.data.find(v => v._id == id)?.kol) + .subscribe(s => this.refreshIfGood(s)) } editTitle(id: string) { - this.ac.menu.editTitle(id, this.dataSource.data.find(v => v._id == id)?.dayTitle).subscribe(s => this.refreshIfGood(s)) + this.ac.menu + .editTitle(id, this.dataSource.data.find(v => v._id == id)?.dayTitle) + .subscribe(s => this.refreshIfGood(s)) } - getStat(day: DateTime, m: "ob" | "kol") { - this.ac.menu.stat(day, m).subscribe((s) => this.sb.open(`${s.y} / ${s.y+s.n} = ${((s.y/(s.y+s.n))*100).toFixed(2)}%`, "Zamknij", {duration: 2500})) + getStat(day: DateTime, m: 'ob' | 'kol') { + this.ac.menu + .stat(day, m) + .subscribe(s => + this.sb.open( + `${s.y} / ${s.y + s.n} = ${((s.y / (s.y + s.n)) * 100).toFixed(2)}%`, + 'Zamknij', + { duration: 2500 } + ) + ) } remove(id: string) { diff --git a/src/app/admin-view/menu-new/menu-upload/menu-upload.component.scss b/src/app/admin-view/menu-new/menu-upload/menu-upload.component.scss index 273b78f..e6f808d 100644 --- a/src/app/admin-view/menu-new/menu-upload/menu-upload.component.scss +++ b/src/app/admin-view/menu-new/menu-upload/menu-upload.component.scss @@ -1,4 +1,4 @@ :host { - margin: 8pt; - display: block; -} \ No newline at end of file + margin: 8pt; + display: block; +} diff --git a/src/app/admin-view/menu-new/menu-upload/menu-upload.component.spec.ts b/src/app/admin-view/menu-new/menu-upload/menu-upload.component.spec.ts index b63a3ca..7078f51 100644 --- a/src/app/admin-view/menu-new/menu-upload/menu-upload.component.spec.ts +++ b/src/app/admin-view/menu-new/menu-upload/menu-upload.component.spec.ts @@ -1,29 +1,29 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { MenuUploadComponent } from './menu-upload.component'; -import { AdminCommService } from '../../admin-comm.service'; -import { MatDialogModule, MatDialogRef } from '@angular/material/dialog'; +import { MenuUploadComponent } from './menu-upload.component' +import { AdminCommService } from '../../admin-comm.service' +import { MatDialogModule, MatDialogRef } from '@angular/material/dialog' describe('MenuUploadComponent', () => { - let component: MenuUploadComponent; - let fixture: ComponentFixture; + let component: MenuUploadComponent + let fixture: ComponentFixture beforeEach(() => { const acMock = jasmine.createSpyObj('AdminCommService', ['postMenu']) TestBed.configureTestingModule({ declarations: [MenuUploadComponent], providers: [ - {provide: AdminCommService, useValue: acMock}, - {provide: MatDialogRef, useValue: {}} + { provide: AdminCommService, useValue: acMock }, + { provide: MatDialogRef, useValue: {} }, ], - imports: [MatDialogModule] - }); - fixture = TestBed.createComponent(MenuUploadComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [MatDialogModule], + }) + fixture = TestBed.createComponent(MenuUploadComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/menu-new/menu-upload/menu-upload.component.ts b/src/app/admin-view/menu-new/menu-upload/menu-upload.component.ts index 23900dc..1e461f3 100644 --- a/src/app/admin-view/menu-new/menu-upload/menu-upload.component.ts +++ b/src/app/admin-view/menu-new/menu-upload/menu-upload.component.ts @@ -1,27 +1,30 @@ -import { Component } from '@angular/core'; -import { AdminCommService } from '../../admin-comm.service'; -import { MatDialogRef } from '@angular/material/dialog'; +import { Component } from '@angular/core' +import { AdminCommService } from '../../admin-comm.service' +import { MatDialogRef } from '@angular/material/dialog' @Component({ - selector: 'app-upload-edit', - templateUrl: './menu-upload.component.html', - styleUrls: ['./menu-upload.component.scss'], - standalone: false + selector: 'app-upload-edit', + templateUrl: './menu-upload.component.html', + styleUrls: ['./menu-upload.component.scss'], + standalone: false, }) export class MenuUploadComponent { - constructor(private ac:AdminCommService, public dialogRef: MatDialogRef) {} - protected file: File | undefined; + constructor( + private ac: AdminCommService, + public dialogRef: MatDialogRef + ) {} + protected file: File | undefined onFileChange(event: Event) { - const file:File = (event.target as HTMLInputElement).files![0]; + const file: File = (event.target as HTMLInputElement).files![0] if (file) { this.file = file } else { this.file = undefined } } - + submit() { - this.ac.menu.postMenu(this.file!)?.subscribe((value) => { + this.ac.menu.postMenu(this.file!)?.subscribe(value => { this.dialogRef.close(value) }) } diff --git a/src/app/admin-view/news-edit/new-post/edit-post.component.scss b/src/app/admin-view/news-edit/new-post/edit-post.component.scss index 5caa806..4631ede 100644 --- a/src/app/admin-view/news-edit/new-post/edit-post.component.scss +++ b/src/app/admin-view/news-edit/new-post/edit-post.component.scss @@ -1,10 +1,10 @@ :host { - padding: 8pt; - display: block; + padding: 8pt; + display: block; } form { - display: flex; - flex-direction: column; - align-items: stretch; -} \ No newline at end of file + display: flex; + flex-direction: column; + align-items: stretch; +} diff --git a/src/app/admin-view/news-edit/new-post/edit-post.component.spec.ts b/src/app/admin-view/news-edit/new-post/edit-post.component.spec.ts index 3039bf6..a775c5e 100644 --- a/src/app/admin-view/news-edit/new-post/edit-post.component.spec.ts +++ b/src/app/admin-view/news-edit/new-post/edit-post.component.spec.ts @@ -1,31 +1,41 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { NewPostComponent } from './edit-post.component'; -import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatInputModule } from '@angular/material/input'; -import { ReactiveFormsModule } from '@angular/forms'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { NewPostComponent } from './edit-post.component' +import { + MAT_DIALOG_DATA, + MatDialogModule, + MatDialogRef, +} from '@angular/material/dialog' +import { MatFormFieldModule } from '@angular/material/form-field' +import { MatInputModule } from '@angular/material/input' +import { ReactiveFormsModule } from '@angular/forms' +import { BrowserAnimationsModule } from '@angular/platform-browser/animations' describe('NewPostComponent', () => { - let component: NewPostComponent; - let fixture: ComponentFixture; + let component: NewPostComponent + let fixture: ComponentFixture beforeEach(() => { TestBed.configureTestingModule({ declarations: [NewPostComponent], - imports: [MatDialogModule, MatFormFieldModule, MatInputModule, ReactiveFormsModule, BrowserAnimationsModule], + imports: [ + MatDialogModule, + MatFormFieldModule, + MatInputModule, + ReactiveFormsModule, + BrowserAnimationsModule, + ], providers: [ - {provide: MatDialogRef, useValue: {}}, - {provide: MAT_DIALOG_DATA, useValue: {}} - ] - }); - fixture = TestBed.createComponent(NewPostComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + { provide: MatDialogRef, useValue: {} }, + { provide: MAT_DIALOG_DATA, useValue: {} }, + ], + }) + fixture = TestBed.createComponent(NewPostComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/news-edit/new-post/edit-post.component.ts b/src/app/admin-view/news-edit/new-post/edit-post.component.ts index 646f852..a4447a2 100644 --- a/src/app/admin-view/news-edit/new-post/edit-post.component.ts +++ b/src/app/admin-view/news-edit/new-post/edit-post.component.ts @@ -1,32 +1,35 @@ -import { Component, Inject } from '@angular/core'; -import { FormControl, FormGroup } from '@angular/forms'; -import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import { Component, Inject } from '@angular/core' +import { FormControl, FormGroup } from '@angular/forms' +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog' @Component({ - selector: 'app-edit-post', - templateUrl: './edit-post.component.html', - styleUrls: ['./edit-post.component.scss'], - standalone: false + selector: 'app-edit-post', + templateUrl: './edit-post.component.html', + styleUrls: ['./edit-post.component.scss'], + standalone: false, }) export class NewPostComponent { - form: FormGroup; - constructor (public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any) { + form: FormGroup + constructor( + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: any + ) { if (data == null) { data = { - title:"", - content:"", + title: '', + content: '', } } this.form = new FormGroup({ title: new FormControl(data.title), - content: new FormControl(data.content) + content: new FormControl(data.content), }) } protected makePost() { this.dialogRef.close({ title: this.form.get('title')?.value, - content: this.form.get('content')?.value + content: this.form.get('content')?.value, }) } } diff --git a/src/app/admin-view/news-edit/news-edit.component.scss b/src/app/admin-view/news-edit/news-edit.component.scss index eb3cebf..f8241bf 100644 --- a/src/app/admin-view/news-edit/news-edit.component.scss +++ b/src/app/admin-view/news-edit/news-edit.component.scss @@ -1,38 +1,38 @@ mat-card { - margin: 15px; - padding: 1ch; - width: 100%; + margin: 15px; + padding: 1ch; + width: 100%; } mat-card-title { - font-size: 1.5rem; + font-size: 1.5rem; } mat-card-footer p { - font-size: 0.8rem; - color: #4a4a4a; - margin-bottom: 0; - text-align: end; - @media (prefers-color-scheme: dark) { - color: #999999 - } + font-size: 0.8rem; + color: #4a4a4a; + margin-bottom: 0; + text-align: end; + @media (prefers-color-scheme: dark) { + color: #999999; + } } mat-card-content p { - white-space: pre-line; + white-space: pre-line; } mat-card p { - margin: 15px; + margin: 15px; } button { - margin-right: 4pt; + margin-right: 4pt; } :host { - padding: 8pt; - display: flex; - flex-direction: column; - align-items: center; + padding: 8pt; + display: flex; + flex-direction: column; + align-items: center; } diff --git a/src/app/admin-view/news-edit/news-edit.component.spec.ts b/src/app/admin-view/news-edit/news-edit.component.spec.ts index 8ff4c7a..dfc8004 100644 --- a/src/app/admin-view/news-edit/news-edit.component.spec.ts +++ b/src/app/admin-view/news-edit/news-edit.component.spec.ts @@ -1,36 +1,34 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { NewsEditComponent } from './news-edit.component'; -import { AdminCommService } from '../admin-comm.service'; -import { MatDialogModule } from '@angular/material/dialog'; -import { MatSnackBarModule } from '@angular/material/snack-bar'; -import { of } from 'rxjs'; -import { MatCardModule } from '@angular/material/card'; +import { NewsEditComponent } from './news-edit.component' +import { AdminCommService } from '../admin-comm.service' +import { MatDialogModule } from '@angular/material/dialog' +import { MatSnackBarModule } from '@angular/material/snack-bar' +import { of } from 'rxjs' +import { MatCardModule } from '@angular/material/card' describe('NewsEditComponent', () => { - let component: NewsEditComponent; - let fixture: ComponentFixture; + let component: NewsEditComponent + let fixture: ComponentFixture let acMock beforeEach(() => { acMock = { news: { - getNews: jasmine.createSpy('getNews').and.returnValue(of([])) - } + getNews: jasmine.createSpy('getNews').and.returnValue(of([])), + }, } TestBed.configureTestingModule({ declarations: [NewsEditComponent], - providers: [ - {provide: AdminCommService, useValue: acMock} - ], - imports: [MatDialogModule, MatSnackBarModule, MatCardModule] - }); - fixture = TestBed.createComponent(NewsEditComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + providers: [{ provide: AdminCommService, useValue: acMock }], + imports: [MatDialogModule, MatSnackBarModule, MatCardModule], + }) + fixture = TestBed.createComponent(NewsEditComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/news-edit/news-edit.component.ts b/src/app/admin-view/news-edit/news-edit.component.ts index bf0ff51..235e842 100644 --- a/src/app/admin-view/news-edit/news-edit.component.ts +++ b/src/app/admin-view/news-edit/news-edit.component.ts @@ -1,32 +1,38 @@ -import { Component, OnInit } from '@angular/core'; -import { AdminCommService } from '../admin-comm.service'; -import { MatDialog } from '@angular/material/dialog'; -import { NewPostComponent } from './new-post/edit-post.component'; -import { catchError, throwError } from 'rxjs'; -import { MatSnackBar } from '@angular/material/snack-bar'; -import { News } from 'src/app/types/news'; -import { marked } from 'marked'; +import { Component, OnInit } from '@angular/core' +import { AdminCommService } from '../admin-comm.service' +import { MatDialog } from '@angular/material/dialog' +import { NewPostComponent } from './new-post/edit-post.component' +import { catchError, throwError } from 'rxjs' +import { MatSnackBar } from '@angular/material/snack-bar' +import { News } from 'src/app/types/news' +import { marked } from 'marked' @Component({ - selector: 'app-news-edit', - templateUrl: './news-edit.component.html', - styleUrls: ['./news-edit.component.scss'], - standalone: false + selector: 'app-news-edit', + templateUrl: './news-edit.component.html', + styleUrls: ['./news-edit.component.scss'], + standalone: false, }) export class NewsEditComponent implements OnInit { - news:Array = new Array + news: Array = new Array< + News & { formatted: string } + >() loading = true - constructor(private ac:AdminCommService, private dialog:MatDialog, private sb:MatSnackBar) {} + constructor( + private ac: AdminCommService, + private dialog: MatDialog, + private sb: MatSnackBar + ) {} ngOnInit() { this.loading = true this.ac.news.getNews().subscribe(data => { this.loading = false this.news = data.map(v => { - var nd: News & {formatted: string} = { + var nd: News & { formatted: string } = { ...v, - formatted: marked.parse(v.content, {breaks: true}).toString() + formatted: marked.parse(v.content, { breaks: true }).toString(), } return nd }) @@ -34,35 +40,51 @@ export class NewsEditComponent implements OnInit { } newPost() { - this.dialog.open(NewPostComponent, {width: "90vw"}).afterClosed().subscribe(result=> { - if (result == undefined) return - this.ac.news.postNews(result.title, result.content).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.ngOnInit() - } else { - this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.") - } + this.dialog + .open(NewPostComponent, { width: '90vw' }) + .afterClosed() + .subscribe(result => { + if (result == undefined) return + this.ac.news + .postNews(result.title, result.content) + .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.ngOnInit() + } else { + this.sb.open('Wystąpił błąd. Skontaktuj się z obsługą programu.') + } + }) }) - }) } editPost(item: any) { - this.dialog.open(NewPostComponent, {data: item, width: "90vh"}).afterClosed().subscribe(result=>{ - if (result == undefined) return - this.ac.news.updateNews(item._id, result.title, result.content).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.ngOnInit() - } else { - this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.") - } + this.dialog + .open(NewPostComponent, { data: item, width: '90vh' }) + .afterClosed() + .subscribe(result => { + if (result == undefined) return + this.ac.news + .updateNews(item._id, result.title, result.content) + .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.ngOnInit() + } else { + this.sb.open('Wystąpił błąd. Skontaktuj się z obsługą programu.') + } + }) }) - }) } delete(id: string) { @@ -74,29 +96,39 @@ export class NewsEditComponent implements OnInit { } visibleToggle(item: any) { - this.ac.news.toggleNews(item._id, item.visible).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.ngOnInit() - } else { - this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.") - } - }) + this.ac.news + .toggleNews(item._id, item.visible) + .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.ngOnInit() + } else { + this.sb.open('Wystąpił błąd. Skontaktuj się z obsługą programu.') + } + }) } - pinToggle(item:any) { + pinToggle(item: any) { console.log(item.pinned) - this.ac.news.togglePin(item._id, item.pinned).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.ngOnInit() - } else { - this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.") - } - }) + this.ac.news + .togglePin(item._id, item.pinned) + .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.ngOnInit() + } else { + this.sb.open('Wystąpił błąd. Skontaktuj się z obsługą programu.') + } + }) } } diff --git a/src/app/admin-view/notifications/notifications.component.scss b/src/app/admin-view/notifications/notifications.component.scss index 2eb3d89..2bfd14c 100644 --- a/src/app/admin-view/notifications/notifications.component.scss +++ b/src/app/admin-view/notifications/notifications.component.scss @@ -1,3 +1,3 @@ mat-radio-button { - display: block; -} \ No newline at end of file + display: block; +} diff --git a/src/app/admin-view/notifications/notifications.component.spec.ts b/src/app/admin-view/notifications/notifications.component.spec.ts index bb59ef6..252ff84 100644 --- a/src/app/admin-view/notifications/notifications.component.spec.ts +++ b/src/app/admin-view/notifications/notifications.component.spec.ts @@ -1,44 +1,60 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { NotificationsComponent } from './notifications.component'; -import { AdminCommService } from '../admin-comm.service'; -import { RouterModule } from '@angular/router'; -import { MatRadioModule } from '@angular/material/radio'; -import { MatFormFieldControl, MatFormFieldModule } from '@angular/material/form-field'; -import { Component, forwardRef } from '@angular/core'; -import { MatIconModule } from '@angular/material/icon'; -import { Observable, of } from 'rxjs'; -import { AbstractControlDirective, ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR, NgControl, ReactiveFormsModule } from '@angular/forms'; -import { MatInputModule } from '@angular/material/input'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { NotificationsComponent } from './notifications.component' +import { AdminCommService } from '../admin-comm.service' +import { RouterModule } from '@angular/router' +import { MatRadioModule } from '@angular/material/radio' +import { + MatFormFieldControl, + MatFormFieldModule, +} from '@angular/material/form-field' +import { Component, forwardRef } from '@angular/core' +import { MatIconModule } from '@angular/material/icon' +import { Observable, of } from 'rxjs' +import { + AbstractControlDirective, + ControlValueAccessor, + FormsModule, + NG_VALUE_ACCESSOR, + NgControl, + ReactiveFormsModule, +} from '@angular/forms' +import { MatInputModule } from '@angular/material/input' +import { NoopAnimationsModule } from '@angular/platform-browser/animations' @Component({ - selector: "app-user-search", template: '', providers: [{ - provide: NG_VALUE_ACCESSOR, - useExisting: forwardRef(() => UserSearchStub), - multi: true, - }, - { - provide: MatFormFieldControl, - useExisting: UserSearchStub - }], - standalone: false + selector: 'app-user-search', + template: '', + providers: [ + { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => UserSearchStub), + multi: true, + }, + { + provide: MatFormFieldControl, + useExisting: UserSearchStub, + }, + ], + standalone: false, }) -class UserSearchStub implements ControlValueAccessor, MatFormFieldControl { - value: null = null; - stateChanges: Observable = of(); - id: string = ""; - placeholder: string = ""; - ngControl: NgControl | AbstractControlDirective | null = null; - focused: boolean = false; - empty: boolean = true; - shouldLabelFloat: boolean = true; - required: boolean = false; - disabled: boolean = false; - errorState: boolean = false; - controlType?: string | undefined; - autofilled?: boolean | undefined; - userAriaDescribedBy?: string | undefined; +class UserSearchStub + implements ControlValueAccessor, MatFormFieldControl +{ + value: null = null + stateChanges: Observable = of() + id: string = '' + placeholder: string = '' + ngControl: NgControl | AbstractControlDirective | null = null + focused: boolean = false + empty: boolean = true + shouldLabelFloat: boolean = true + required: boolean = false + disabled: boolean = false + errorState: boolean = false + controlType?: string | undefined + autofilled?: boolean | undefined + userAriaDescribedBy?: string | undefined setDescribedByIds(ids: string[]): void {} onContainerClick(event: MouseEvent): void {} writeValue(obj: any): void {} @@ -48,20 +64,18 @@ class UserSearchStub implements ControlValueAccessor, MatFormFieldControl } describe('NotificationsComponent', () => { - let component: NotificationsComponent; - let fixture: ComponentFixture; + let component: NotificationsComponent + let fixture: ComponentFixture beforeEach(() => { const acMock = { notif: { - getGroups: jasmine.createSpy("getGroups").and.returnValue(of()) - } + getGroups: jasmine.createSpy('getGroups').and.returnValue(of()), + }, } TestBed.configureTestingModule({ declarations: [NotificationsComponent, UserSearchStub], - providers: [ - {provide: AdminCommService, useValue: acMock} - ], + providers: [{ provide: AdminCommService, useValue: acMock }], imports: [ RouterModule.forRoot([]), MatRadioModule, @@ -70,15 +84,15 @@ describe('NotificationsComponent', () => { FormsModule, ReactiveFormsModule, MatInputModule, - NoopAnimationsModule - ] - }); - fixture = TestBed.createComponent(NotificationsComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + NoopAnimationsModule, + ], + }) + fixture = TestBed.createComponent(NotificationsComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/notifications/notifications.component.ts b/src/app/admin-view/notifications/notifications.component.ts index 45b5f52..d6aa36b 100644 --- a/src/app/admin-view/notifications/notifications.component.ts +++ b/src/app/admin-view/notifications/notifications.component.ts @@ -1,46 +1,52 @@ -import { Component, OnDestroy, OnInit } from '@angular/core'; -import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; -import { AdminCommService } from '../admin-comm.service'; -import { Notification } from 'src/app/types/notification'; -import { Group } from 'src/app/types/group'; -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'; +import { Component, OnDestroy, OnInit } from '@angular/core' +import { FormBuilder, FormControl, FormGroup } from '@angular/forms' +import { AdminCommService } from '../admin-comm.service' +import { Notification } from 'src/app/types/notification' +import { Group } from 'src/app/types/group' +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({ - selector: 'app-notifications', - templateUrl: './notifications.component.html', - styleUrls: ['./notifications.component.scss'], - standalone: false + selector: 'app-notifications', + templateUrl: './notifications.component.html', + styleUrls: ['./notifications.component.scss'], + standalone: false, }) export class NotificationsComponent implements OnInit, OnDestroy { - groups!: Group[] form = this.fb.group({ recp: this.fb.group({ uid: this.fb.control(null), - room: this.fb.control(null), + room: this.fb.control(null), group: this.fb.control(''), - type: this.fb.control<"room" | "uname" | "group">('uname', {nonNullable: true}) + type: this.fb.control<'room' | 'uname' | 'group'>('uname', { + nonNullable: true, + }), }), - title: this.fb.control('', {nonNullable: true}), - body: this.fb.control('', {nonNullable: true}) + title: this.fb.control('', { nonNullable: true }), + body: this.fb.control('', { nonNullable: true }), }) - constructor (private readonly acs: AdminCommService, readonly ls: LocalStorageService, private toolbar: ToolbarService, private router: Router, private route: ActivatedRoute, private fb: FormBuilder ) { + constructor( + private readonly acs: AdminCommService, + readonly ls: LocalStorageService, + private toolbar: ToolbarService, + private router: Router, + private route: ActivatedRoute, + private fb: FormBuilder + ) { this.toolbar.comp = this - this.toolbar.menu = [ - { title: "Wysłane", fn: "outbox", icon: "outbox" } - ] + this.toolbar.menu = [{ title: 'Wysłane', fn: 'outbox', icon: 'outbox' }] } - + outbox() { - this.router.navigate(["outbox"], { relativeTo: this.route }) + this.router.navigate(['outbox'], { relativeTo: this.route }) } ngOnInit(): void { - this.acs.notif.getGroups().subscribe((v) => { + this.acs.notif.getGroups().subscribe(v => { this.groups = v }) } @@ -50,16 +56,21 @@ export class NotificationsComponent implements OnInit, OnDestroy { this.toolbar.menu = undefined } - public inbox() { - - } - - success?: { sent: number; possible: number; }; + public inbox() {} + success?: { sent: number; possible: number } submit() { - 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.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 + }) } } diff --git a/src/app/admin-view/notifications/outbox/message/message.component.scss b/src/app/admin-view/notifications/outbox/message/message.component.scss index 68af8c3..0835c9f 100644 --- a/src/app/admin-view/notifications/outbox/message/message.component.scss +++ b/src/app/admin-view/notifications/outbox/message/message.component.scss @@ -1,3 +1,3 @@ mat-card-title { - font-size: 24pt; -} \ No newline at end of file + font-size: 24pt; +} diff --git a/src/app/admin-view/notifications/outbox/message/message.component.spec.ts b/src/app/admin-view/notifications/outbox/message/message.component.spec.ts index a3d9d57..b292697 100644 --- a/src/app/admin-view/notifications/outbox/message/message.component.spec.ts +++ b/src/app/admin-view/notifications/outbox/message/message.component.spec.ts @@ -1,35 +1,28 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { MessageComponent } from './message.component'; -import { AdminCommService } from 'src/app/admin-view/admin-comm.service'; -import { MatCardModule } from '@angular/material/card'; -import { DateTime } from 'luxon'; +import { ComponentFixture, TestBed } from '@angular/core/testing' +import { MessageComponent } from './message.component' +import { AdminCommService } from 'src/app/admin-view/admin-comm.service' +import { MatCardModule } from '@angular/material/card' +import { DateTime } from 'luxon' describe('MessageComponent', () => { - let component: MessageComponent; - let fixture: ComponentFixture; + let component: MessageComponent + let fixture: ComponentFixture beforeEach(async () => { - const acMock = { - - } + const acMock = {} await TestBed.configureTestingModule({ declarations: [MessageComponent], - providers: [ - {provide: AdminCommService, useValue: acMock} - ], - imports: [ - MatCardModule - ] - }) - .compileComponents(); - - fixture = TestBed.createComponent(MessageComponent); - component = fixture.componentInstance; - component.item = {_id: "test", sentDate: DateTime.now(), title: "Test"} - fixture.detectChanges(); - }); + providers: [{ provide: AdminCommService, useValue: acMock }], + imports: [MatCardModule], + }).compileComponents() + + fixture = TestBed.createComponent(MessageComponent) + component = fixture.componentInstance + component.item = { _id: 'test', sentDate: DateTime.now(), title: 'Test' } + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/notifications/outbox/message/message.component.ts b/src/app/admin-view/notifications/outbox/message/message.component.ts index 8a2e37c..15b682f 100644 --- a/src/app/admin-view/notifications/outbox/message/message.component.ts +++ b/src/app/admin-view/notifications/outbox/message/message.component.ts @@ -1,19 +1,25 @@ -import { Component, Input } from '@angular/core'; -import { DateTime } from 'luxon'; -import { AdminCommService } from 'src/app/admin-view/admin-comm.service'; +import { Component, Input } from '@angular/core' +import { DateTime } from 'luxon' +import { AdminCommService } from 'src/app/admin-view/admin-comm.service' @Component({ - selector: 'app-message', - templateUrl: './message.component.html', - styleUrl: './message.component.scss', - standalone: false + selector: 'app-message', + templateUrl: './message.component.html', + styleUrl: './message.component.scss', + standalone: false, }) export class MessageComponent { - @Input() item!: {_id: string, sentDate: DateTime, title: string} + @Input() item!: { _id: string; sentDate: DateTime; title: string } body?: string - rcpts?: {_id: string, uname: string, room?: string, fname?: string, surname?: string}[] + rcpts?: { + _id: string + uname: string + room?: string + fname?: string + surname?: string + }[] loading: boolean = false - constructor (readonly acu: AdminCommService) {} + constructor(readonly acu: AdminCommService) {} getMessage() { this.loading = true diff --git a/src/app/admin-view/notifications/outbox/outbox.component.scss b/src/app/admin-view/notifications/outbox/outbox.component.scss index 0702771..8dc662f 100644 --- a/src/app/admin-view/notifications/outbox/outbox.component.scss +++ b/src/app/admin-view/notifications/outbox/outbox.component.scss @@ -1,6 +1,6 @@ .cardContainer { - display: flex; - flex-wrap: wrap; - gap: 1ch; - margin: 1ch; -} \ No newline at end of file + display: flex; + flex-wrap: wrap; + gap: 1ch; + margin: 1ch; +} diff --git a/src/app/admin-view/notifications/outbox/outbox.component.spec.ts b/src/app/admin-view/notifications/outbox/outbox.component.spec.ts index fcaec00..833416f 100644 --- a/src/app/admin-view/notifications/outbox/outbox.component.spec.ts +++ b/src/app/admin-view/notifications/outbox/outbox.component.spec.ts @@ -1,39 +1,34 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { OutboxComponent } from './outbox.component'; -import { AdminCommService } from '../../admin-comm.service'; -import { RouterModule } from '@angular/router'; -import { of } from 'rxjs'; +import { OutboxComponent } from './outbox.component' +import { AdminCommService } from '../../admin-comm.service' +import { RouterModule } from '@angular/router' +import { of } from 'rxjs' describe('OutboxComponent', () => { - let component: OutboxComponent; - let fixture: ComponentFixture; + let component: OutboxComponent + let fixture: ComponentFixture beforeEach(async () => { const acMock = { notif: { outbox: { - getSent: jasmine.createSpy("getSent").and.returnValue(of()) - } - } + getSent: jasmine.createSpy('getSent').and.returnValue(of()), + }, + }, } await TestBed.configureTestingModule({ declarations: [OutboxComponent], - providers: [ - {provide: AdminCommService, useValue: acMock} - ], - imports: [ - RouterModule.forRoot([]) - ] - }) - .compileComponents(); - - fixture = TestBed.createComponent(OutboxComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + providers: [{ provide: AdminCommService, useValue: acMock }], + imports: [RouterModule.forRoot([])], + }).compileComponents() + + fixture = TestBed.createComponent(OutboxComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/notifications/outbox/outbox.component.ts b/src/app/admin-view/notifications/outbox/outbox.component.ts index e3ed2ee..b0255c3 100644 --- a/src/app/admin-view/notifications/outbox/outbox.component.ts +++ b/src/app/admin-view/notifications/outbox/outbox.component.ts @@ -1,38 +1,41 @@ -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 { DateTime } from 'luxon'; +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 { DateTime } from 'luxon' @Component({ - selector: 'app-outbox', - templateUrl: './outbox.component.html', - styleUrl: './outbox.component.scss', - standalone: false + selector: 'app-outbox', + templateUrl: './outbox.component.html', + styleUrl: './outbox.component.scss', + standalone: false, }) export class OutboxComponent implements OnInit { - messages!: { - _id: string; - sentDate: DateTime; - title: string; + _id: string + sentDate: DateTime + title: string }[] - constructor (private readonly acs: AdminCommService, private toolbar: ToolbarService, private router: Router, private route: ActivatedRoute ) { + 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" } + { title: 'Powiadomienia', fn: 'goBack', icon: 'arrow_back' }, ] } goBack() { - this.router.navigate(['../'], {relativeTo: this.route}) + this.router.navigate(['../'], { relativeTo: this.route }) } ngOnInit(): void { - this.acs.notif.outbox.getSent().subscribe((v) => { + this.acs.notif.outbox.getSent().subscribe(v => { this.messages = v }) } - } diff --git a/src/app/admin-view/settings/settings.component.scss b/src/app/admin-view/settings/settings.component.scss index a4e2097..292a1dc 100644 --- a/src/app/admin-view/settings/settings.component.scss +++ b/src/app/admin-view/settings/settings.component.scss @@ -1,4 +1,4 @@ :host { - margin: 15px; - display: block; -} \ No newline at end of file + margin: 15px; + display: block; +} diff --git a/src/app/admin-view/settings/settings.component.spec.ts b/src/app/admin-view/settings/settings.component.spec.ts index c20964c..a802232 100644 --- a/src/app/admin-view/settings/settings.component.spec.ts +++ b/src/app/admin-view/settings/settings.component.spec.ts @@ -1,42 +1,40 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { SettingsComponent } from './settings.component'; -import { AdminCommService } from '../admin-comm.service'; -import { MatExpansionModule } from '@angular/material/expansion'; -import { Component, Input } from '@angular/core'; -import { MatTabsModule } from '@angular/material/tabs'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { MatIconModule } from '@angular/material/icon'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { of } from 'rxjs'; -import { MatInputModule } from '@angular/material/input'; +import { SettingsComponent } from './settings.component' +import { AdminCommService } from '../admin-comm.service' +import { MatExpansionModule } from '@angular/material/expansion' +import { Component, Input } from '@angular/core' +import { MatTabsModule } from '@angular/material/tabs' +import { MatFormFieldModule } from '@angular/material/form-field' +import { FormsModule, ReactiveFormsModule } from '@angular/forms' +import { MatIconModule } from '@angular/material/icon' +import { NoopAnimationsModule } from '@angular/platform-browser/animations' +import { of } from 'rxjs' +import { MatInputModule } from '@angular/material/input' @Component({ - selector: 'app-list-editor', template: '', - standalone: false + selector: 'app-list-editor', + template: '', + standalone: false, }) class ListEditorStub { - @Input() converter?: any[]; - @Input() list?: string[]; - + @Input() converter?: any[] + @Input() list?: string[] } describe('SettingsComponent', () => { - let component: SettingsComponent; - let fixture: ComponentFixture; + let component: SettingsComponent + let fixture: ComponentFixture beforeEach(async () => { const acMock = { settings: { - getAll: jasmine.createSpy("getAll").and.returnValue(of()) - } + getAll: jasmine.createSpy('getAll').and.returnValue(of()), + }, } await TestBed.configureTestingModule({ declarations: [SettingsComponent, ListEditorStub], - providers: [ - {provide: AdminCommService, useValue: acMock} - ], + providers: [{ provide: AdminCommService, useValue: acMock }], imports: [ MatExpansionModule, MatTabsModule, @@ -45,17 +43,16 @@ describe('SettingsComponent', () => { ReactiveFormsModule, MatIconModule, NoopAnimationsModule, - MatInputModule - ] - }) - .compileComponents(); - - fixture = TestBed.createComponent(SettingsComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + MatInputModule, + ], + }).compileComponents() + + fixture = TestBed.createComponent(SettingsComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/settings/settings.component.ts b/src/app/admin-view/settings/settings.component.ts index 4de7e9b..2d395ec 100644 --- a/src/app/admin-view/settings/settings.component.ts +++ b/src/app/admin-view/settings/settings.component.ts @@ -1,28 +1,38 @@ -import { Component, OnInit } from '@angular/core'; -import { AdminCommService } from '../admin-comm.service'; -import { MatSnackBar } from '@angular/material/snack-bar'; -import { FormBuilder } from '@angular/forms'; +import { Component, OnInit } from '@angular/core' +import { AdminCommService } from '../admin-comm.service' +import { MatSnackBar } from '@angular/material/snack-bar' +import { FormBuilder } from '@angular/forms' @Component({ - selector: 'app-settings', - templateUrl: './settings.component.html', - styleUrl: './settings.component.scss', - standalone: false + selector: 'app-settings', + templateUrl: './settings.component.html', + styleUrl: './settings.component.scss', + standalone: false, }) export class SettingsComponent implements OnInit { - usettings: IUSettings = {cleanThings: [], keyrooms: [], menu: {defaultItems: {kol: [], sn: []}}, rooms: [], security: {loginTimeout: {attempts: 0, lockout: 0, time: 0}}} - reloadTimeout: boolean = false; + usettings: IUSettings = { + cleanThings: [], + keyrooms: [], + menu: { defaultItems: { kol: [], sn: [] } }, + rooms: [], + security: { loginTimeout: { attempts: 0, lockout: 0, time: 0 } }, + } + reloadTimeout: boolean = false + + constructor( + private readonly acu: AdminCommService, + private readonly sb: MatSnackBar, + private readonly fb: FormBuilder + ) {} - 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), + lockout: this.fb.nonNullable.control(1), }) ngOnInit(): void { - this.acu.settings.getAll().subscribe((r) => { + this.acu.settings.getAll().subscribe(r => { this.usettings = r this.accSecTimeouts = r.security.loginTimeout }) @@ -59,23 +69,23 @@ export class SettingsComponent implements OnInit { this.accSec.setValue({ attempts: value.attempts, lockout: value.lockout / 60, - time: value.time / 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 + time: this.accSec.controls['time'].value * 60, } } send() { - this.acu.settings.post(this.usettings).subscribe((s) => { + this.acu.settings.post(this.usettings).subscribe(s => { if (s.status == 200) { - this.sb.open("Zapisano!", undefined, { duration: 1000 }) + this.sb.open('Zapisano!', undefined, { duration: 1000 }) } else { - console.error(s); + console.error(s) } }) } @@ -87,32 +97,32 @@ export class SettingsComponent implements OnInit { this.reloadTimeout = true setTimeout(() => { this.reloadTimeout = false - }, 5000); - this.acu.settings.reload().subscribe((s) => { + }, 5000) + this.acu.settings.reload().subscribe(s => { if (s.status == 200) { - this.sb.open("Przeładowano ustawienia!", undefined, { duration: 3000 }) + this.sb.open('Przeładowano ustawienia!', undefined, { duration: 3000 }) } else { - console.error(s); + console.error(s) } }) } } export interface IUSettings { - keyrooms: string[]; - rooms: string[]; - cleanThings: string[]; + keyrooms: string[] + rooms: string[] + cleanThings: string[] menu: { defaultItems: { - sn: string[]; - kol: string[]; - } - }; - security: { - loginTimeout: { - attempts: number; - time: number; - lockout: number; + sn: string[] + kol: string[] } } -} \ No newline at end of file + security: { + loginTimeout: { + attempts: number + time: number + lockout: number + } + } +} diff --git a/src/app/admin-view/start/start.component.scss b/src/app/admin-view/start/start.component.scss index 8e24cb3..c7ff7e9 100644 --- a/src/app/admin-view/start/start.component.scss +++ b/src/app/admin-view/start/start.component.scss @@ -1,13 +1,13 @@ .main { - margin-top: 8px; - margin-left: 16px; - display: flex; - align-items: center; - gap: 1ch; + margin-top: 8px; + margin-left: 16px; + display: flex; + align-items: center; + gap: 1ch; } .icon { - width: fit-content; - height: fit-content; - font-size: 32pt; -} \ No newline at end of file + width: fit-content; + height: fit-content; + font-size: 32pt; +} diff --git a/src/app/admin-view/start/start.component.spec.ts b/src/app/admin-view/start/start.component.spec.ts index 04d19da..8336d78 100644 --- a/src/app/admin-view/start/start.component.spec.ts +++ b/src/app/admin-view/start/start.component.spec.ts @@ -1,27 +1,24 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { StartAdminComponent } from './start.component'; -import { MatIconModule } from '@angular/material/icon'; +import { StartAdminComponent } from './start.component' +import { MatIconModule } from '@angular/material/icon' describe('StartAdminComponent', () => { - let component: StartAdminComponent; - let fixture: ComponentFixture; + let component: StartAdminComponent + let fixture: ComponentFixture beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [StartAdminComponent], - imports: [ - MatIconModule - ] - }) - .compileComponents(); - - fixture = TestBed.createComponent(StartAdminComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [MatIconModule], + }).compileComponents() + + fixture = TestBed.createComponent(StartAdminComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/start/start.component.ts b/src/app/admin-view/start/start.component.ts index 7cc0c68..b05a4ef 100644 --- a/src/app/admin-view/start/start.component.ts +++ b/src/app/admin-view/start/start.component.ts @@ -1,11 +1,9 @@ -import { Component } from '@angular/core'; +import { Component } from '@angular/core' @Component({ - selector: 'app-start', - templateUrl: './start.component.html', - styleUrl: './start.component.scss', - standalone: false + selector: 'app-start', + templateUrl: './start.component.html', + styleUrl: './start.component.scss', + standalone: false, }) -export class StartAdminComponent { - -} +export class StartAdminComponent {} diff --git a/src/app/admin-view/toolbar/toolbar.component.spec.ts b/src/app/admin-view/toolbar/toolbar.component.spec.ts index 8b85cff..3d615a0 100644 --- a/src/app/admin-view/toolbar/toolbar.component.spec.ts +++ b/src/app/admin-view/toolbar/toolbar.component.spec.ts @@ -1,27 +1,26 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { ToolbarComponent } from './toolbar.component'; -import { MatToolbarModule } from '@angular/material/toolbar'; -import { MatIconModule } from '@angular/material/icon'; -import { MatMenuModule } from '@angular/material/menu'; +import { ToolbarComponent } from './toolbar.component' +import { MatToolbarModule } from '@angular/material/toolbar' +import { MatIconModule } from '@angular/material/icon' +import { MatMenuModule } from '@angular/material/menu' describe('ToolbarComponent', () => { - let component: ToolbarComponent; - let fixture: ComponentFixture; + let component: ToolbarComponent + let fixture: ComponentFixture beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [ToolbarComponent], - imports: [MatToolbarModule, MatIconModule, MatMenuModule] - }) - .compileComponents(); - - fixture = TestBed.createComponent(ToolbarComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [MatToolbarModule, MatIconModule, MatMenuModule], + }).compileComponents() + + fixture = TestBed.createComponent(ToolbarComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/toolbar/toolbar.component.ts b/src/app/admin-view/toolbar/toolbar.component.ts index 5a23615..3b9b4b9 100644 --- a/src/app/admin-view/toolbar/toolbar.component.ts +++ b/src/app/admin-view/toolbar/toolbar.component.ts @@ -1,26 +1,27 @@ -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'; +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', - standalone: false + selector: 'app-toolbar', + templateUrl: './toolbar.component.html', + styleUrl: './toolbar.component.scss', + standalone: false, }) export class ToolbarComponent { - @Input() drawer!: MatDrawer; - @ViewChild(MatMenuTrigger) trigger!: MatMenuTrigger; + @Input() drawer!: MatDrawer + @ViewChild(MatMenuTrigger) trigger!: MatMenuTrigger protected _menu?: typeof this.toolbar.menu - constructor(readonly title: Title, protected toolbar: ToolbarService) { - - } + constructor( + readonly title: Title, + protected toolbar: ToolbarService + ) {} - openMenu () { + openMenu() { this._menu = this.toolbar.menu this.trigger.openMenu() } diff --git a/src/app/admin-view/toolbar/toolbar.service.spec.ts b/src/app/admin-view/toolbar/toolbar.service.spec.ts index 70d22f4..d56edac 100644 --- a/src/app/admin-view/toolbar/toolbar.service.spec.ts +++ b/src/app/admin-view/toolbar/toolbar.service.spec.ts @@ -1,16 +1,16 @@ -import { TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing' -import { ToolbarService } from './toolbar.service'; +import { ToolbarService } from './toolbar.service' describe('ToolbarService', () => { - let service: ToolbarService; + let service: ToolbarService beforeEach(() => { - TestBed.configureTestingModule({}); - service = TestBed.inject(ToolbarService); - }); + TestBed.configureTestingModule({}) + service = TestBed.inject(ToolbarService) + }) it('should be created', () => { - expect(service).toBeTruthy(); - }); -}); + expect(service).toBeTruthy() + }) +}) diff --git a/src/app/admin-view/toolbar/toolbar.service.ts b/src/app/admin-view/toolbar/toolbar.service.ts index 6bd02da..bc90946 100644 --- a/src/app/admin-view/toolbar/toolbar.service.ts +++ b/src/app/admin-view/toolbar/toolbar.service.ts @@ -1,11 +1,9 @@ -import { Injectable } from '@angular/core'; +import { Injectable } from '@angular/core' @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class ToolbarService { - - public comp?: any; - public menu?: {title: string, check?: boolean, icon?: string, fn: string}[] - + public comp?: any + public menu?: { title: string; check?: boolean; icon?: string; fn: string }[] } diff --git a/src/app/admin.guard.spec.ts b/src/app/admin.guard.spec.ts index 9f1d4b8..2541c15 100644 --- a/src/app/admin.guard.spec.ts +++ b/src/app/admin.guard.spec.ts @@ -1,17 +1,17 @@ -import { TestBed } from '@angular/core/testing'; -import { CanActivateChildFn } from '@angular/router'; +import { TestBed } from '@angular/core/testing' +import { CanActivateChildFn } from '@angular/router' -import { adminGuard } from './admin.guard'; +import { adminGuard } from './admin.guard' describe('adminGuard', () => { - const executeGuard: CanActivateChildFn = (...guardParameters) => - TestBed.runInInjectionContext(() => adminGuard(...guardParameters)); + const executeGuard: CanActivateChildFn = (...guardParameters) => + TestBed.runInInjectionContext(() => adminGuard(...guardParameters)) beforeEach(() => { - TestBed.configureTestingModule({}); - }); + TestBed.configureTestingModule({}) + }) it('should be created', () => { - expect(executeGuard).toBeTruthy(); - }); -}); + expect(executeGuard).toBeTruthy() + }) +}) diff --git a/src/app/admin.guard.ts b/src/app/admin.guard.ts index 67f2ee6..a36ee73 100644 --- a/src/app/admin.guard.ts +++ b/src/app/admin.guard.ts @@ -1,9 +1,10 @@ -import { inject } from '@angular/core'; -import { CanActivateChildFn, RedirectCommand, Router } from '@angular/router'; -import { LocalStorageService } from './services/local-storage.service'; +import { inject } from '@angular/core' +import { CanActivateChildFn, RedirectCommand, Router } from '@angular/router' +import { LocalStorageService } from './services/local-storage.service' export const adminGuard: CanActivateChildFn = (childRoute, state) => { const router = inject(Router) - if (inject(LocalStorageService).admin == undefined) return new RedirectCommand(router.parseUrl('/')) + if (inject(LocalStorageService).admin == undefined) + return new RedirectCommand(router.parseUrl('/')) return true -}; +} diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 664ec13..7861dbe 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -1,58 +1,106 @@ -import { NgModule } from '@angular/core'; -import { RouterModule, Routes } from '@angular/router'; -import { NewsComponent } from './app-view/news/news.component'; -import { MenuComponent } from './app-view/menu/menu.component'; -import { AppViewComponent } from './app-view/app-view.component'; -import { LoginComponent } from './login/login.component'; -import { authGuard } from './auth.guard'; -import { PersonalComponent } from './app-view/personal/personal.component'; -import { AdminViewComponent } from './admin-view/admin-view.component'; -import { NewsEditComponent } from './admin-view/news-edit/news-edit.component'; -import { AccountMgmtComponent } from './admin-view/account-mgmt/account-mgmt.component'; -import { MenuNewComponent } from './admin-view/menu-new/menu-new.component'; -import { adminGuard } from './admin.guard'; -import { GroupsComponent } from './admin-view/groups/groups.component'; -import { StartComponent } from './app-view/start/start.component'; -import { AdminKeyComponent } from './admin-view/key/key.component'; -import { GradesComponent } from './admin-view/grades/grades.component'; -import { SummaryComponent } from './admin-view/grades/summary/summary.component'; -import { SettingsComponent } from './admin-view/settings/settings.component'; -import { AttendenceSummaryComponent } from './admin-view/grades/attendence-summary/attendence-summary.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'; +import { NgModule } from '@angular/core' +import { RouterModule, Routes } from '@angular/router' +import { NewsComponent } from './app-view/news/news.component' +import { MenuComponent } from './app-view/menu/menu.component' +import { AppViewComponent } from './app-view/app-view.component' +import { LoginComponent } from './login/login.component' +import { authGuard } from './auth.guard' +import { PersonalComponent } from './app-view/personal/personal.component' +import { AdminViewComponent } from './admin-view/admin-view.component' +import { NewsEditComponent } from './admin-view/news-edit/news-edit.component' +import { AccountMgmtComponent } from './admin-view/account-mgmt/account-mgmt.component' +import { MenuNewComponent } from './admin-view/menu-new/menu-new.component' +import { adminGuard } from './admin.guard' +import { GroupsComponent } from './admin-view/groups/groups.component' +import { StartComponent } from './app-view/start/start.component' +import { AdminKeyComponent } from './admin-view/key/key.component' +import { GradesComponent } from './admin-view/grades/grades.component' +import { SummaryComponent } from './admin-view/grades/summary/summary.component' +import { SettingsComponent } from './admin-view/settings/settings.component' +import { AttendenceSummaryComponent } from './admin-view/grades/attendence-summary/attendence-summary.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 = [ - {path: "", redirectTo: "login", pathMatch: "full"}, - {path: "login", component: LoginComponent}, - {path: "app", component: AppViewComponent, title: "Internat", canActivateChild: [authGuard], children: [ - {path: "", component: StartComponent, pathMatch: "full"}, - {path: "news",component: NewsComponent, title: "Wiadomości"}, - {path: "menu", component: MenuComponent, title: "Jadłospis"}, - {path: "grades", component: PersonalComponent, title: "Konto"} - ]}, - {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: "menu", title: "Edytowanie jadłospisu", component: MenuNewComponent}, - {path: "accounts", title: "Użytkownicy", component: AccountMgmtComponent}, - {path: "notifications", children: [ - {path: "", pathMatch: "full", title: "Powiadomienia", component: NotificationsComponent}, - {path: "outbox", title: "Wysłane", component: OutboxComponent} - ]}, - {path: "groups", title: "Grupy", component: GroupsComponent}, - {path: "keys", title: "Klucze", component: AdminKeyComponent}, - {path: "grades", children: [ - {path: "", pathMatch: "full", title: "Oceny", component: GradesComponent}, - {path: "summary", title: "Podsumowanie ocen", component: SummaryComponent}, - {path: "attendenceSummary", title: "Obecność", component: AttendenceSummaryComponent} - ]}, - {path: "settings", title: "Ustawienia", component: SettingsComponent} - ]} -]; + { path: '', redirectTo: 'login', pathMatch: 'full' }, + { path: 'login', component: LoginComponent }, + { + path: 'app', + component: AppViewComponent, + title: 'Internat', + canActivateChild: [authGuard], + children: [ + { path: '', component: StartComponent, pathMatch: 'full' }, + { path: 'news', component: NewsComponent, title: 'Wiadomości' }, + { path: 'menu', component: MenuComponent, title: 'Jadłospis' }, + { path: 'grades', component: PersonalComponent, title: 'Konto' }, + ], + }, + { + 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: 'menu', + title: 'Edytowanie jadłospisu', + component: MenuNewComponent, + }, + { + path: 'accounts', + title: 'Użytkownicy', + component: AccountMgmtComponent, + }, + { + path: 'notifications', + children: [ + { + path: '', + pathMatch: 'full', + title: 'Powiadomienia', + component: NotificationsComponent, + }, + { path: 'outbox', title: 'Wysłane', component: OutboxComponent }, + ], + }, + { path: 'groups', title: 'Grupy', component: GroupsComponent }, + { path: 'keys', title: 'Klucze', component: AdminKeyComponent }, + { + path: 'grades', + children: [ + { + path: '', + pathMatch: 'full', + title: 'Oceny', + component: GradesComponent, + }, + { + path: 'summary', + title: 'Podsumowanie ocen', + component: SummaryComponent, + }, + { + path: 'attendenceSummary', + title: 'Obecność', + component: AttendenceSummaryComponent, + }, + ], + }, + { path: 'settings', title: 'Ustawienia', component: SettingsComponent }, + ], + }, +] @NgModule({ imports: [RouterModule.forRoot(routes)], - exports: [RouterModule] + exports: [RouterModule], }) -export class AppRoutingModule { } +export class AppRoutingModule {} diff --git a/src/app/app-view/app-view.component.scss b/src/app/app-view/app-view.component.scss index b05d7d9..b4b55a1 100644 --- a/src/app/app-view/app-view.component.scss +++ b/src/app/app-view/app-view.component.scss @@ -1,29 +1,29 @@ #bot-navigation { - width: 100%; + width: 100%; } #outlet { - width: 100%; - flex: 1 1 auto; - overflow-y: auto; + width: 100%; + flex: 1 1 auto; + overflow-y: auto; } #scrollable { - overflow: auto; - height: 100%; - position: relative; + overflow: auto; + height: 100%; + position: relative; } :host { - width: 100%; - height: 100vh; - display: flex; - flex-direction: column; - @supports (-webkit-touch-callout: none) { - height: 95vh; - } + width: 100%; + height: 100vh; + display: flex; + flex-direction: column; + @supports (-webkit-touch-callout: none) { + height: 95vh; + } } a { - text-decoration-line: none; -} \ No newline at end of file + text-decoration-line: none; +} diff --git a/src/app/app-view/app-view.component.spec.ts b/src/app/app-view/app-view.component.spec.ts index a83e9ac..364a75b 100644 --- a/src/app/app-view/app-view.component.spec.ts +++ b/src/app/app-view/app-view.component.spec.ts @@ -1,40 +1,40 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { AppViewComponent } from './app-view.component'; -import { AuthClient } from '../services/auth.client'; -import { SwPush } from '@angular/service-worker'; -import { UpdatesService } from '../services/updates.service'; -import { MatTabsModule } from '@angular/material/tabs'; -import { RouterModule } from '@angular/router'; -import { MatIconModule } from '@angular/material/icon'; -import { of } from 'rxjs'; +import { AppViewComponent } from './app-view.component' +import { AuthClient } from '../services/auth.client' +import { SwPush } from '@angular/service-worker' +import { UpdatesService } from '../services/updates.service' +import { MatTabsModule } from '@angular/material/tabs' +import { RouterModule } from '@angular/router' +import { MatIconModule } from '@angular/material/icon' +import { of } from 'rxjs' describe('AppViewComponent', () => { - let component: AppViewComponent; - let fixture: ComponentFixture; + let component: AppViewComponent + let fixture: ComponentFixture beforeEach(() => { const authSpy = jasmine.createSpyObj('AuthClient', ['check']) const pushSpy = jasmine.createSpyObj('SwPush', ['requestSubscription']) const updatesSpy = jasmine.createSpyObj('UpdatesService', { - newsCheck: of() + newsCheck: of(), }) TestBed.configureTestingModule({ declarations: [AppViewComponent], providers: [ - {provide: AuthClient, useValue: authSpy}, - {provide: SwPush, useValue: pushSpy}, - {provide: UpdatesService, useValue: updatesSpy} + { provide: AuthClient, useValue: authSpy }, + { provide: SwPush, useValue: pushSpy }, + { provide: UpdatesService, useValue: updatesSpy }, ], - imports: [MatTabsModule, RouterModule.forRoot([]), MatIconModule] - }); - fixture = TestBed.createComponent(AppViewComponent); - component = fixture.componentInstance; + imports: [MatTabsModule, RouterModule.forRoot([]), MatIconModule], + }) + fixture = TestBed.createComponent(AppViewComponent) + component = fixture.componentInstance - fixture.detectChanges(); - }); + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/app-view/app-view.component.ts b/src/app/app-view/app-view.component.ts index 44a4ff2..1ddaa0d 100644 --- a/src/app/app-view/app-view.component.ts +++ b/src/app/app-view/app-view.component.ts @@ -1,49 +1,61 @@ -import { Component, OnInit } from '@angular/core'; -import { AuthClient } from '../services/auth.client'; -import { SwPush } from '@angular/service-worker'; -import { UpdatesService } from '../services/updates.service'; -import { Link } from '../types/link'; -import { LocalStorageService } from '../services/local-storage.service'; -import { interval } from 'rxjs'; -import { MatSnackBar } from '@angular/material/snack-bar'; -import { MatDialog } from '@angular/material/dialog'; -import { NotifDialogComponent } from './notif-dialog/notif-dialog.component'; +import { Component, OnInit } from '@angular/core' +import { AuthClient } from '../services/auth.client' +import { SwPush } from '@angular/service-worker' +import { UpdatesService } from '../services/updates.service' +import { Link } from '../types/link' +import { LocalStorageService } from '../services/local-storage.service' +import { interval } from 'rxjs' +import { MatSnackBar } from '@angular/material/snack-bar' +import { MatDialog } from '@angular/material/dialog' +import { NotifDialogComponent } from './notif-dialog/notif-dialog.component' @Component({ - selector: 'app-app-view', - templateUrl: './app-view.component.html', - styleUrls: ['./app-view.component.scss'], - standalone: false + selector: 'app-app-view', + templateUrl: './app-view.component.html', + styleUrls: ['./app-view.component.scss'], + standalone: false, }) export class AppViewComponent implements OnInit { private readonly _LINKS: Link[] = [ - { title: "Jadłospis", href: "menu", icon: "restaurant_menu", enabled: this.ls.capCheck(2) }, - { title: "Wiadomości", href: "news", icon: "newspaper", enabled: this.ls.capCheck(1) }, - { title: "Konto", href: "grades", icon: "account_circle", enabled: true } - ]; + { + title: 'Jadłospis', + href: 'menu', + icon: 'restaurant_menu', + enabled: this.ls.capCheck(2), + }, + { + title: 'Wiadomości', + href: 'news', + icon: 'newspaper', + enabled: this.ls.capCheck(1), + }, + { title: 'Konto', href: 'grades', icon: 'account_circle', enabled: true }, + ] public get LINKS() { - return this._LINKS.filter((v) => { + return this._LINKS.filter(v => { return v.enabled - }); + }) } - constructor ( - private ac: AuthClient, - readonly swPush: SwPush, - private us: UpdatesService, - private ls: LocalStorageService, + constructor( + private ac: AuthClient, + readonly swPush: SwPush, + private us: UpdatesService, + private ls: LocalStorageService, private sb: MatSnackBar, private dialog: MatDialog ) {} - + subscribeToNotif() { if (this.swPush.isEnabled && this.ls.capCheck(4)) { - this.swPush.requestSubscription({ - serverPublicKey: this.ls.vapid - }).then(sub => { - this.us.postNotif(sub) - }) + this.swPush + .requestSubscription({ + serverPublicKey: this.ls.vapid, + }) + .then(sub => { + this.us.postNotif(sub) + }) } } @@ -56,18 +68,21 @@ export class AppViewComponent implements OnInit { newsCheck() { if (this.ls.capCheck(4)) { - this.us.getNotifCheck().subscribe((s) => { + this.us.getNotifCheck().subscribe(s => { s.forEach(v => { - this.dialog.open(NotifDialogComponent, {data: v}) + this.dialog.open(NotifDialogComponent, { data: v }) }) }) } - if (this.ls.newsflag) return; - this.us.newsCheck().subscribe((s) => { + if (this.ls.newsflag) return + this.us.newsCheck().subscribe(s => { if (s.hash != this.ls.newsCheck.hash) { this.ls.newsflag = this.ls.newsCheck.count - s.count this.ls.newsCheck = s - this.sb.open("Nowe wiadomości", "Zamknij", {duration: 5000, verticalPosition: 'bottom'}) + this.sb.open('Nowe wiadomości', 'Zamknij', { + duration: 5000, + verticalPosition: 'bottom', + }) } }) } diff --git a/src/app/app-view/menu/allergens/allergens.component.scss b/src/app/app-view/menu/allergens/allergens.component.scss index e625ac2..5aa03f7 100644 --- a/src/app/app-view/menu/allergens/allergens.component.scss +++ b/src/app/app-view/menu/allergens/allergens.component.scss @@ -1,3 +1,3 @@ -ol>li::marker { - font-weight: bold; -} \ No newline at end of file +ol > li::marker { + font-weight: bold; +} diff --git a/src/app/app-view/menu/allergens/allergens.component.spec.ts b/src/app/app-view/menu/allergens/allergens.component.spec.ts index 27e94dc..d270616 100644 --- a/src/app/app-view/menu/allergens/allergens.component.spec.ts +++ b/src/app/app-view/menu/allergens/allergens.component.spec.ts @@ -1,21 +1,21 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { AllergensComponent } from './allergens.component'; +import { AllergensComponent } from './allergens.component' describe('AllergensComponent', () => { - let component: AllergensComponent; - let fixture: ComponentFixture; + let component: AllergensComponent + let fixture: ComponentFixture beforeEach(() => { TestBed.configureTestingModule({ - declarations: [AllergensComponent] - }); - fixture = TestBed.createComponent(AllergensComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + declarations: [AllergensComponent], + }) + fixture = TestBed.createComponent(AllergensComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/app-view/menu/allergens/allergens.component.ts b/src/app/app-view/menu/allergens/allergens.component.ts index d973875..035cc87 100644 --- a/src/app/app-view/menu/allergens/allergens.component.ts +++ b/src/app/app-view/menu/allergens/allergens.component.ts @@ -1,11 +1,9 @@ -import { Component } from '@angular/core'; +import { Component } from '@angular/core' @Component({ - selector: 'app-allergens', - templateUrl: './allergens.component.html', - styleUrls: ['./allergens.component.scss'], - standalone: false + selector: 'app-allergens', + templateUrl: './allergens.component.html', + styleUrls: ['./allergens.component.scss'], + standalone: false, }) -export class AllergensComponent { - -} +export class AllergensComponent {} diff --git a/src/app/app-view/menu/menu.component.scss b/src/app/app-view/menu/menu.component.scss index 0ec2aca..56fd1d0 100644 --- a/src/app/app-view/menu/menu.component.scss +++ b/src/app/app-view/menu/menu.component.scss @@ -1,41 +1,41 @@ :host { - display: flex; - flex-direction: column; - overflow: none; - height: 100%; + display: flex; + flex-direction: column; + overflow: none; + height: 100%; } #cards { - display: flex; - flex-direction: column; - flex-grow: 1; - overflow: auto; + display: flex; + flex-direction: column; + flex-grow: 1; + overflow: auto; } #alrg { - align-self: center; + align-self: center; } mat-spinner { - align-self: center; + align-self: center; } mat-card { - margin: 15px; - padding: 1ch; + margin: 15px; + padding: 1ch; } #no-data { - color: #777; - @media (prefers-color-scheme: dark) { - color: #AAA - } + color: #777; + @media (prefers-color-scheme: dark) { + color: #aaa; + } } mat-card-title { - font-size: 1.5rem; + font-size: 1.5rem; } app-date-selector { - width: 100%; -} \ No newline at end of file + width: 100%; +} diff --git a/src/app/app-view/menu/menu.component.spec.ts b/src/app/app-view/menu/menu.component.spec.ts index a44fec2..e1e2095 100644 --- a/src/app/app-view/menu/menu.component.spec.ts +++ b/src/app/app-view/menu/menu.component.spec.ts @@ -1,55 +1,54 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { MenuComponent } from './menu.component'; -import { UpdatesService } from 'src/app/services/updates.service'; -import { DateSelectorComponent } from '../../commonComponents/date-selector/date-selector.component'; -import { MatIconModule } from '@angular/material/icon'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatDatepickerModule } from '@angular/material/datepicker'; -import { MatCardModule } from '@angular/material/card'; -import { ReactiveFormsModule } from '@angular/forms'; -import { MatInputModule } from '@angular/material/input'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { MatDialogRef } from '@angular/material/dialog'; -import { MatBottomSheetModule } from '@angular/material/bottom-sheet'; -import { of } from 'rxjs'; -import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; -import { provideLuxonDateAdapter } from '@angular/material-luxon-adapter'; +import { MenuComponent } from './menu.component' +import { UpdatesService } from 'src/app/services/updates.service' +import { DateSelectorComponent } from '../../commonComponents/date-selector/date-selector.component' +import { MatIconModule } from '@angular/material/icon' +import { MatFormFieldModule } from '@angular/material/form-field' +import { MatDatepickerModule } from '@angular/material/datepicker' +import { MatCardModule } from '@angular/material/card' +import { ReactiveFormsModule } from '@angular/forms' +import { MatInputModule } from '@angular/material/input' +import { BrowserAnimationsModule } from '@angular/platform-browser/animations' +import { MatDialogRef } from '@angular/material/dialog' +import { MatBottomSheetModule } from '@angular/material/bottom-sheet' +import { of } from 'rxjs' +import { MatProgressSpinnerModule } from '@angular/material/progress-spinner' +import { provideLuxonDateAdapter } from '@angular/material-luxon-adapter' describe('MenuComponent', () => { - let component: MenuComponent; - let fixture: ComponentFixture; + let component: MenuComponent + let fixture: ComponentFixture beforeEach(async () => { const updatesSpy = jasmine.createSpyObj('UpdatesService', { - getMenu: of() + getMenu: of(), }) await TestBed.configureTestingModule({ - declarations: [ MenuComponent, DateSelectorComponent], + declarations: [MenuComponent, DateSelectorComponent], providers: [ - {provide: UpdatesService, useValue: updatesSpy}, - provideLuxonDateAdapter() + { provide: UpdatesService, useValue: updatesSpy }, + provideLuxonDateAdapter(), ], imports: [ - MatIconModule, - MatFormFieldModule, - MatDatepickerModule, - MatCardModule, - ReactiveFormsModule, - MatInputModule, - BrowserAnimationsModule, + MatIconModule, + MatFormFieldModule, + MatDatepickerModule, + MatCardModule, + ReactiveFormsModule, + MatInputModule, + BrowserAnimationsModule, MatBottomSheetModule, - MatProgressSpinnerModule - ] - }) - .compileComponents(); + MatProgressSpinnerModule, + ], + }).compileComponents() - fixture = TestBed.createComponent(MenuComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + fixture = TestBed.createComponent(MenuComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/app-view/menu/menu.component.ts b/src/app/app-view/menu/menu.component.ts index ec59541..31923bb 100644 --- a/src/app/app-view/menu/menu.component.ts +++ b/src/app/app-view/menu/menu.component.ts @@ -1,42 +1,60 @@ -import { Component, OnInit } from '@angular/core'; -import { UpdatesService } from '../../services/updates.service'; -import { Menu } from '../../types/menu'; -import { MatBottomSheet } from '@angular/material/bottom-sheet'; -import { AllergensComponent } from './allergens/allergens.component'; -import { weekendFilter } from "../../fd.da"; -import { LocalStorageService } from 'src/app/services/local-storage.service'; -import { DateTime } from 'luxon'; +import { Component, OnInit } from '@angular/core' +import { UpdatesService } from '../../services/updates.service' +import { Menu } from '../../types/menu' +import { MatBottomSheet } from '@angular/material/bottom-sheet' +import { AllergensComponent } from './allergens/allergens.component' +import { weekendFilter } from '../../fd.da' +import { LocalStorageService } from 'src/app/services/local-storage.service' +import { DateTime } from 'luxon' @Component({ selector: 'app-menu', templateUrl: './menu.component.html', styleUrls: ['./menu.component.scss'], - standalone: false + standalone: false, }) export class MenuComponent { - constructor(private uc: UpdatesService, readonly bs: MatBottomSheet, readonly ls: LocalStorageService) { + constructor( + private uc: UpdatesService, + readonly bs: MatBottomSheet, + readonly ls: LocalStorageService + ) { this._day = DateTime.now().toISODate() } loading = true public filter = weekendFilter - private _day: string; + private _day: string public get day(): string { - return this._day; + return this._day } public set day(value: string) { - this._day = value; + this._day = value this.updateMenu() } - menu?: Menu; - get getsn() { return (this.menu && this.checkIfAnyProperty(this.menu.sn)) ? this.menu.sn : 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 gettitle() { return (this.menu && this.menu.dayTitle && this.menu.dayTitle != "") ? this.menu.dayTitle : null } + menu?: Menu + get getsn() { + return this.menu && this.checkIfAnyProperty(this.menu.sn) + ? this.menu.sn + : 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 gettitle() { + return this.menu && this.menu.dayTitle && this.menu.dayTitle != '' + ? this.menu.dayTitle + : null + } - private checkIfAnyProperty(obj: { [x: string]: string | string[]; }) { + private checkIfAnyProperty(obj: { [x: string]: string | string[] }) { for (let i in obj) { if (Array.isArray(obj[i])) { if (obj[i].length > 0) return true @@ -57,7 +75,7 @@ export class MenuComponent { this.uc.getMenu(this.day).subscribe(m => { this.loading = false this.menu = m - console.log(m); + console.log(m) }) } @@ -66,14 +84,14 @@ export class MenuComponent { } protected vegeColor(text: string) { - if (text.startsWith("V: ")) { - return "#43A047" + if (text.startsWith('V: ')) { + return '#43A047' } - return "inherit" + return 'inherit' } - vote(type: "ob" | "kol", vote: "-" | "+" | "n") { - this.uc.postVote(this.menu!.day.toISO()!, type, vote).subscribe((data) => { + vote(type: 'ob' | 'kol', vote: '-' | '+' | 'n') { + this.uc.postVote(this.menu!.day.toISO()!, type, vote).subscribe(data => { this.updateMenu(true) }) } diff --git a/src/app/app-view/news/news.component.scss b/src/app/app-view/news/news.component.scss index ceae4f8..759f54f 100644 --- a/src/app/app-view/news/news.component.scss +++ b/src/app/app-view/news/news.component.scss @@ -1,35 +1,35 @@ :host { - display: flex; - flex-direction: column; + display: flex; + flex-direction: column; } mat-card { - margin: 15px; - padding: 1ch; + margin: 15px; + padding: 1ch; } mat-spinner { - align-self: center; + align-self: center; } mat-card-title { - font-size: 1.5rem; + font-size: 1.5rem; } mat-card-footer p { - font-size: 0.8rem; - color: #4a4a4a; - margin-bottom: 0; - text-align: end; - @media (prefers-color-scheme: dark) { - color: #999999 - } + font-size: 0.8rem; + color: #4a4a4a; + margin-bottom: 0; + text-align: end; + @media (prefers-color-scheme: dark) { + color: #999999; + } } mat-card-content p { - white-space: pre-line; + white-space: pre-line; } mat-card p { - margin: 15px; -} \ No newline at end of file + margin: 15px; +} diff --git a/src/app/app-view/news/news.component.spec.ts b/src/app/app-view/news/news.component.spec.ts index 490907c..6823807 100644 --- a/src/app/app-view/news/news.component.spec.ts +++ b/src/app/app-view/news/news.component.spec.ts @@ -1,44 +1,39 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { NewsComponent } from './news.component'; -import { UpdatesService } from 'src/app/services/updates.service'; -import { of } from 'rxjs'; -import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { LocalStorageService } from 'src/app/services/local-storage.service'; -import { MatCardModule } from '@angular/material/card'; +import { NewsComponent } from './news.component' +import { UpdatesService } from 'src/app/services/updates.service' +import { of } from 'rxjs' +import { MatProgressSpinnerModule } from '@angular/material/progress-spinner' +import { NoopAnimationsModule } from '@angular/platform-browser/animations' +import { LocalStorageService } from 'src/app/services/local-storage.service' +import { MatCardModule } from '@angular/material/card' describe('NewsComponent', () => { - let component: NewsComponent; - let fixture: ComponentFixture; + let component: NewsComponent + let fixture: ComponentFixture beforeEach(async () => { const updatesMock = jasmine.createSpyObj('UpdatesService', { - getNews: of() + getNews: of(), }) const lsMock = { - news: [] + news: [], } await TestBed.configureTestingModule({ - declarations: [ NewsComponent ], + declarations: [NewsComponent], providers: [ - {provide: UpdatesService, useValue: updatesMock}, - {provide: LocalStorageService, useValue: lsMock} + { provide: UpdatesService, useValue: updatesMock }, + { provide: LocalStorageService, useValue: lsMock }, ], - imports: [ - MatProgressSpinnerModule, - NoopAnimationsModule, - MatCardModule - ] - }) - .compileComponents(); + imports: [MatProgressSpinnerModule, NoopAnimationsModule, MatCardModule], + }).compileComponents() - fixture = TestBed.createComponent(NewsComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + fixture = TestBed.createComponent(NewsComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/app-view/news/news.component.ts b/src/app/app-view/news/news.component.ts index 6aa4b02..a1a94c8 100644 --- a/src/app/app-view/news/news.component.ts +++ b/src/app/app-view/news/news.component.ts @@ -1,19 +1,22 @@ -import { Component, OnInit } from '@angular/core'; -import { UpdatesService } from '../../services/updates.service'; -import { LocalStorageService } from 'src/app/services/local-storage.service'; -import { News } from 'src/app/types/news'; -import { marked } from 'marked'; +import { Component, OnInit } from '@angular/core' +import { UpdatesService } from '../../services/updates.service' +import { LocalStorageService } from 'src/app/services/local-storage.service' +import { News } from 'src/app/types/news' +import { marked } from 'marked' @Component({ - selector: 'app-news', - templateUrl: './news.component.html', - styleUrls: ['./news.component.scss'], - standalone: false + selector: 'app-news', + templateUrl: './news.component.html', + styleUrls: ['./news.component.scss'], + standalone: false, }) export class NewsComponent implements OnInit { - news:Array = new Array + news: Array = new Array() loading = true - constructor(private newsapi:UpdatesService, private ls: LocalStorageService) { } + constructor( + private newsapi: UpdatesService, + private ls: LocalStorageService + ) {} ngOnInit() { this.ls.newsflag = false @@ -22,9 +25,9 @@ export class NewsComponent implements OnInit { this.newsapi.getNews().subscribe(data => { this.loading = false this.news = data.map(v => { - v.content = marked.parse(v.content, {breaks: true}).toString() + v.content = marked.parse(v.content, { breaks: true }).toString() return v - }); + }) this.ls.news = this.news }) } diff --git a/src/app/app-view/notif-dialog/notif-dialog.component.spec.ts b/src/app/app-view/notif-dialog/notif-dialog.component.spec.ts index cd8869f..590eaa5 100644 --- a/src/app/app-view/notif-dialog/notif-dialog.component.spec.ts +++ b/src/app/app-view/notif-dialog/notif-dialog.component.spec.ts @@ -1,37 +1,38 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { NotifDialogComponent } from './notif-dialog.component'; -import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog'; -import { UpdatesService } from 'src/app/services/updates.service'; -import { of } from 'rxjs'; +import { NotifDialogComponent } from './notif-dialog.component' +import { + MAT_DIALOG_DATA, + MatDialogModule, + MatDialogRef, +} from '@angular/material/dialog' +import { UpdatesService } from 'src/app/services/updates.service' +import { of } from 'rxjs' describe('NotifDialogComponent', () => { - let component: NotifDialogComponent; - let fixture: ComponentFixture; - + let component: NotifDialogComponent + let fixture: ComponentFixture + beforeEach(async () => { - const uMock = jasmine.createSpyObj("UpdatesService", { - postInfoAck: of() + const uMock = jasmine.createSpyObj('UpdatesService', { + postInfoAck: of(), }) await TestBed.configureTestingModule({ declarations: [NotifDialogComponent], providers: [ - {provide: MAT_DIALOG_DATA, useValue: {message: "Test"}}, - {provide: MatDialogRef, useValue: {}}, - {provide: UpdatesService, useValue: uMock} + { provide: MAT_DIALOG_DATA, useValue: { message: 'Test' } }, + { provide: MatDialogRef, useValue: {} }, + { provide: UpdatesService, useValue: uMock }, ], - imports: [ - MatDialogModule - ] - }) - .compileComponents(); - - fixture = TestBed.createComponent(NotifDialogComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [MatDialogModule], + }).compileComponents() + + fixture = TestBed.createComponent(NotifDialogComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/app-view/notif-dialog/notif-dialog.component.ts b/src/app/app-view/notif-dialog/notif-dialog.component.ts index 2c49b25..420c174 100644 --- a/src/app/app-view/notif-dialog/notif-dialog.component.ts +++ b/src/app/app-view/notif-dialog/notif-dialog.component.ts @@ -1,30 +1,33 @@ -import { Component, Inject } from '@angular/core'; -import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; -import { DateTime } from 'luxon'; -import { UpdatesService } from 'src/app/services/updates.service'; +import { Component, Inject } from '@angular/core' +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog' +import { DateTime } from 'luxon' +import { UpdatesService } from 'src/app/services/updates.service' @Component({ - selector: 'app-notif-dialog', - templateUrl: './notif-dialog.component.html', - styleUrl: './notif-dialog.component.scss', - standalone: false + selector: 'app-notif-dialog', + templateUrl: './notif-dialog.component.html', + styleUrl: './notif-dialog.component.scss', + standalone: false, }) export class NotifDialogComponent { - date: DateTime - constructor ( - @Inject(MAT_DIALOG_DATA) public data: {_id: string, message: {title: string, body: string}, sentDate: string}, + constructor( + @Inject(MAT_DIALOG_DATA) + public data: { + _id: string + message: { title: string; body: string } + sentDate: string + }, public dialogRef: MatDialogRef, private uc: UpdatesService ) { this.date = DateTime.fromISO(data.sentDate) } - ack () { - this.uc.postInfoAck(this.data._id).subscribe((v) => { + ack() { + this.uc.postInfoAck(this.data._id).subscribe(v => { this.dialogRef.close() }) } - } diff --git a/src/app/app-view/personal/about/about.component.spec.ts b/src/app/app-view/personal/about/about.component.spec.ts index 151f748..8194a99 100644 --- a/src/app/app-view/personal/about/about.component.spec.ts +++ b/src/app/app-view/personal/about/about.component.spec.ts @@ -1,29 +1,25 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { AboutComponent } from './about.component'; -import { MatDialogModule } from '@angular/material/dialog'; -import { MatListModule } from '@angular/material/list'; +import { AboutComponent } from './about.component' +import { MatDialogModule } from '@angular/material/dialog' +import { MatListModule } from '@angular/material/list' describe('AboutComponent', () => { - let component: AboutComponent; - let fixture: ComponentFixture; + let component: AboutComponent + let fixture: ComponentFixture beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [AboutComponent], - imports: [ - MatDialogModule, - MatListModule - ] - }) - .compileComponents(); - - fixture = TestBed.createComponent(AboutComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [MatDialogModule, MatListModule], + }).compileComponents() + + fixture = TestBed.createComponent(AboutComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/app-view/personal/about/about.component.ts b/src/app/app-view/personal/about/about.component.ts index 480c18d..562b5c1 100644 --- a/src/app/app-view/personal/about/about.component.ts +++ b/src/app/app-view/personal/about/about.component.ts @@ -1,31 +1,31 @@ -import { Component } from '@angular/core'; -import { Link } from 'src/app/types/link'; +import { Component } from '@angular/core' +import { Link } from 'src/app/types/link' @Component({ - selector: 'app-about', - templateUrl: './about.component.html', - styleUrl: './about.component.scss', - standalone: false + selector: 'app-about', + templateUrl: './about.component.html', + styleUrl: './about.component.scss', + standalone: false, }) export class AboutComponent { - LINKS: { title: string, info: string, icon: string, link: string }[] = [ - { - title: "Autor", - info: "Jan Szumotalski", - icon: "person", - link: "https://github.com/Slasherss1/" + LINKS: { title: string; info: string; icon: string; link: string }[] = [ + { + title: 'Autor', + info: 'Jan Szumotalski', + icon: 'person', + link: 'https://github.com/Slasherss1/', }, { title: 'Źrodło', info: 'Aplikacja jest darmowa i może ją uruchomić każdy!', icon: 'code', - link: 'https://github.com/Slasherss1/ipwa-selfhosted' + link: 'https://github.com/Slasherss1/ipwa-selfhosted', }, { - title: "Licencja", + title: 'Licencja', info: 'GPL-3.0', icon: 'license', - link: 'https://www.gnu.org/licenses/gpl-3.0-standalone.html' - } + link: 'https://www.gnu.org/licenses/gpl-3.0-standalone.html', + }, ] } diff --git a/src/app/app-view/personal/change-password-dialog/change-password-dialog.component.scss b/src/app/app-view/personal/change-password-dialog/change-password-dialog.component.scss index 34f4d79..63927fd 100644 --- a/src/app/app-view/personal/change-password-dialog/change-password-dialog.component.scss +++ b/src/app/app-view/personal/change-password-dialog/change-password-dialog.component.scss @@ -1,10 +1,10 @@ mat-error { - font-size: 10pt; + font-size: 10pt; } form { - margin: 1rem; - display: flex; - align-items: center; - flex-direction: column; - width: fit-content; -} \ No newline at end of file + margin: 1rem; + display: flex; + align-items: center; + flex-direction: column; + width: fit-content; +} diff --git a/src/app/app-view/personal/change-password-dialog/change-password-dialog.component.spec.ts b/src/app/app-view/personal/change-password-dialog/change-password-dialog.component.spec.ts index 1800f3f..f68f39b 100644 --- a/src/app/app-view/personal/change-password-dialog/change-password-dialog.component.spec.ts +++ b/src/app/app-view/personal/change-password-dialog/change-password-dialog.component.spec.ts @@ -1,33 +1,39 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { ChangePasswordDialogComponent } from './change-password-dialog.component'; -import { AuthClient } from 'src/app/services/auth.client'; -import { MatDialogModule, MatDialogRef } from '@angular/material/dialog'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { ReactiveFormsModule } from '@angular/forms'; -import { MatInputModule } from '@angular/material/input'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { ChangePasswordDialogComponent } from './change-password-dialog.component' +import { AuthClient } from 'src/app/services/auth.client' +import { MatDialogModule, MatDialogRef } from '@angular/material/dialog' +import { MatFormFieldModule } from '@angular/material/form-field' +import { ReactiveFormsModule } from '@angular/forms' +import { MatInputModule } from '@angular/material/input' +import { BrowserAnimationsModule } from '@angular/platform-browser/animations' describe('ChangePasswordDialogComponent', () => { - let component: ChangePasswordDialogComponent; - let fixture: ComponentFixture; + let component: ChangePasswordDialogComponent + let fixture: ComponentFixture beforeEach(() => { const authMock = jasmine.createSpyObj('AuthClient', ['chpass']) TestBed.configureTestingModule({ declarations: [ChangePasswordDialogComponent], providers: [ - {provide: AuthClient, useValue: authMock}, - {provide: MatDialogRef, useValue: {}} + { provide: AuthClient, useValue: authMock }, + { provide: MatDialogRef, useValue: {} }, ], - imports: [MatDialogModule, MatFormFieldModule, ReactiveFormsModule, MatInputModule, BrowserAnimationsModule] - }); - fixture = TestBed.createComponent(ChangePasswordDialogComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [ + MatDialogModule, + MatFormFieldModule, + ReactiveFormsModule, + MatInputModule, + BrowserAnimationsModule, + ], + }) + fixture = TestBed.createComponent(ChangePasswordDialogComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/app-view/personal/change-password-dialog/change-password-dialog.component.ts b/src/app/app-view/personal/change-password-dialog/change-password-dialog.component.ts index c9e63f8..6aa0e03 100644 --- a/src/app/app-view/personal/change-password-dialog/change-password-dialog.component.ts +++ b/src/app/app-view/personal/change-password-dialog/change-password-dialog.component.ts @@ -1,34 +1,50 @@ -import { Component } from '@angular/core'; -import { AuthClient } from '../../../services/auth.client'; -import { AbstractControl, FormBuilder, FormControl, FormGroup, ValidationErrors, ValidatorFn, Validators } from '@angular/forms'; -import { catchError, throwError } from 'rxjs'; -import { MatDialogRef } from '@angular/material/dialog'; -import { Router } from '@angular/router'; -import { LocalStorageService } from 'src/app/services/local-storage.service'; +import { Component } from '@angular/core' +import { AuthClient } from '../../../services/auth.client' +import { + AbstractControl, + FormBuilder, + FormControl, + FormGroup, + ValidationErrors, + ValidatorFn, + Validators, +} from '@angular/forms' +import { catchError, throwError } from 'rxjs' +import { MatDialogRef } from '@angular/material/dialog' +import { Router } from '@angular/router' +import { LocalStorageService } from 'src/app/services/local-storage.service' @Component({ - selector: 'app-change-password-dialog', - templateUrl: './change-password-dialog.component.html', - styleUrls: ['./change-password-dialog.component.scss'], - standalone: false + selector: 'app-change-password-dialog', + templateUrl: './change-password-dialog.component.html', + styleUrls: ['./change-password-dialog.component.scss'], + standalone: false, }) export class ChangePasswordDialogComponent { - error: string | null = null; - form: FormGroup; - constructor (private ac: AuthClient, public dr: MatDialogRef, private router: Router, private ls: LocalStorageService) { - this.form = new FormGroup({ - oldPass: new FormControl(), - newPass: new FormControl(), - newPassRepeat: new FormControl(), - }, {validators: [this.matchpass(), Validators.required]}) + error: string | null = null + form: FormGroup + constructor( + private ac: AuthClient, + public dr: MatDialogRef, + private router: Router, + private ls: LocalStorageService + ) { + this.form = new FormGroup( + { + oldPass: new FormControl(), + newPass: new FormControl(), + newPassRepeat: new FormControl(), + }, + { validators: [this.matchpass(), Validators.required] } + ) } - private matchpass() : ValidatorFn { - return (control: AbstractControl) : ValidationErrors | null => { + private matchpass(): ValidatorFn { + return (control: AbstractControl): ValidationErrors | null => { const newpass = control.get('newPass') - const newpassrepeat = control.get("newPassRepeat") + const newpassrepeat = control.get('newPassRepeat') if (newpass?.value != newpassrepeat?.value) { - const err = {noMatch: true} + const err = { noMatch: true } newpassrepeat?.setErrors(err) return err } @@ -39,21 +55,26 @@ export class ChangePasswordDialogComponent { protected changePass() { if (this.form.errors) { - return; + return } - this.ac.chpass(this.form.get('oldPass')?.value, this.form.get('newPass')?.value).pipe(catchError((err)=>{ - if (err.status == 401) { - this.error = "Niepoprawne dane" - return throwError(() => new Error(err.message)) - } - this.error = "Nieznany błąd" - return throwError(() => new Error(err.message)) - })).subscribe((data) => { - if (this.error == null) { - this.dr.close() - this.ls.logOut() - this.router.navigateByUrl("/login") - } - }) + this.ac + .chpass(this.form.get('oldPass')?.value, this.form.get('newPass')?.value) + .pipe( + catchError(err => { + if (err.status == 401) { + this.error = 'Niepoprawne dane' + return throwError(() => new Error(err.message)) + } + this.error = 'Nieznany błąd' + return throwError(() => new Error(err.message)) + }) + ) + .subscribe(data => { + if (this.error == null) { + this.dr.close() + this.ls.logOut() + this.router.navigateByUrl('/login') + } + }) } } diff --git a/src/app/app-view/personal/clean/clean.component.spec.ts b/src/app/app-view/personal/clean/clean.component.spec.ts index 67374ab..ef95763 100644 --- a/src/app/app-view/personal/clean/clean.component.spec.ts +++ b/src/app/app-view/personal/clean/clean.component.spec.ts @@ -1,49 +1,52 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { CleanComponent } from './clean.component'; -import { UpdatesService } from 'src/app/services/updates.service'; -import { of } from 'rxjs'; -import { MatDialogModule } from '@angular/material/dialog'; -import { MatIconModule } from '@angular/material/icon'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatDatepicker } from '@angular/material/datepicker'; -import { Component, EventEmitter, Input, Output } from '@angular/core'; -import { DateTime } from 'luxon'; +import { CleanComponent } from './clean.component' +import { UpdatesService } from 'src/app/services/updates.service' +import { of } from 'rxjs' +import { MatDialogModule } from '@angular/material/dialog' +import { MatIconModule } from '@angular/material/icon' +import { MatFormFieldModule } from '@angular/material/form-field' +import { MatDatepicker } from '@angular/material/datepicker' +import { Component, EventEmitter, Input, Output } from '@angular/core' +import { DateTime } from 'luxon' @Component({ - selector: "app-date-selector", template: '', - standalone: false + selector: 'app-date-selector', + template: '', + standalone: false, }) class DateSelectorStub { - @Input() date: string = DateTime.now().toISODate(); - @Output() dateChange = new EventEmitter(); - @Input() filter: (date: DateTime | null) => boolean = () => true + @Input() date: string = DateTime.now().toISODate() + @Output() dateChange = new EventEmitter() + @Input() filter: (date: DateTime | null) => boolean = () => true } describe('CleanComponent', () => { - let component: CleanComponent; - let fixture: ComponentFixture; + let component: CleanComponent + let fixture: ComponentFixture let updates: jasmine.SpyObj beforeEach(async () => { - updates = jasmine.createSpyObj("UpdatesService", { - getClean: of() + updates = jasmine.createSpyObj('UpdatesService', { + getClean: of(), }) await TestBed.configureTestingModule({ declarations: [CleanComponent, DateSelectorStub], - providers: [ - {provide: UpdatesService, useValue: updates} + providers: [{ provide: UpdatesService, useValue: updates }], + imports: [ + MatDialogModule, + MatIconModule, + MatFormFieldModule, + MatDatepicker, ], - imports: [MatDialogModule, MatIconModule, MatFormFieldModule, MatDatepicker] - }) - .compileComponents(); - - fixture = TestBed.createComponent(CleanComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + }).compileComponents() + + fixture = TestBed.createComponent(CleanComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/app-view/personal/clean/clean.component.ts b/src/app/app-view/personal/clean/clean.component.ts index f07bc3e..8eea445 100644 --- a/src/app/app-view/personal/clean/clean.component.ts +++ b/src/app/app-view/personal/clean/clean.component.ts @@ -1,32 +1,32 @@ -import { Component, OnInit } from '@angular/core'; -import { DateTime } from 'luxon'; -import { weekendFilter } from 'src/app/fd.da'; -import { UpdatesService } from 'src/app/services/updates.service'; -import { CleanNote } from 'src/app/types/clean-note'; +import { Component, OnInit } from '@angular/core' +import { DateTime } from 'luxon' +import { weekendFilter } from 'src/app/fd.da' +import { UpdatesService } from 'src/app/services/updates.service' +import { CleanNote } from 'src/app/types/clean-note' @Component({ - selector: 'app-clean', - templateUrl: './clean.component.html', - styleUrl: './clean.component.scss', - standalone: false + selector: 'app-clean', + templateUrl: './clean.component.html', + styleUrl: './clean.component.scss', + standalone: false, }) export class CleanComponent implements OnInit { protected day: string grade: number | null = null notes: CleanNote[] = [] - tips: string = "" + tips: string = '' filter = weekendFilter - - constructor (private updates: UpdatesService) { + + constructor(private updates: UpdatesService) { this.day = DateTime.now().toISODate() } ngOnInit(): void { this.update() } - + update() { - this.updates.getClean(this.day).subscribe((v) => { + this.updates.getClean(this.day).subscribe(v => { if (v) { this.grade = v.grade this.notes = v.notes @@ -34,7 +34,7 @@ export class CleanComponent implements OnInit { } else { this.grade = null this.notes = [] - this.tips = "" + this.tips = '' } }) } @@ -42,19 +42,19 @@ export class CleanComponent implements OnInit { protected gradeColor() { switch (this.grade) { case 1: - return { color: "red" } + return { color: 'red' } case 2: - return { color: "darkorange" } + return { color: 'darkorange' } case 3: - return { color: "orange" } + return { color: 'orange' } case 4: - return { color: "olive" } + return { color: 'olive' } case 5: - return { color: "green" } + return { color: 'green' } case 6: - return { color: "springgreen" } + return { color: 'springgreen' } default: - return { color: "inherit" } + return { color: 'inherit' } } } } diff --git a/src/app/app-view/personal/extra/extra.component.spec.ts b/src/app/app-view/personal/extra/extra.component.spec.ts index a0f0e59..6c6318b 100644 --- a/src/app/app-view/personal/extra/extra.component.spec.ts +++ b/src/app/app-view/personal/extra/extra.component.spec.ts @@ -1,29 +1,25 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { ExtraComponent } from './extra.component'; -import { MatDialogModule } from '@angular/material/dialog'; -import { MatListModule } from '@angular/material/list'; +import { ExtraComponent } from './extra.component' +import { MatDialogModule } from '@angular/material/dialog' +import { MatListModule } from '@angular/material/list' describe('ExtraComponent', () => { - let component: ExtraComponent; - let fixture: ComponentFixture; + let component: ExtraComponent + let fixture: ComponentFixture beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [ExtraComponent], - imports: [ - MatDialogModule, - MatListModule - ] - }) - .compileComponents(); - - fixture = TestBed.createComponent(ExtraComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [MatDialogModule, MatListModule], + }).compileComponents() + + fixture = TestBed.createComponent(ExtraComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/app-view/personal/extra/extra.component.ts b/src/app/app-view/personal/extra/extra.component.ts index 34f398d..511a3fc 100644 --- a/src/app/app-view/personal/extra/extra.component.ts +++ b/src/app/app-view/personal/extra/extra.component.ts @@ -1,27 +1,33 @@ -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'; +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', - standalone: false + selector: 'app-extra', + templateUrl: './extra.component.html', + styleUrl: './extra.component.scss', + standalone: false, }) export class ExtraComponent { + constructor(private dialog: MatDialog) {} - constructor (private dialog: MatDialog) {} - - private readonly _LINKS: (Omit & {component: ComponentType})[] = [ - { title: "Domyślna strona po logowaniu", component: RedirectComponent, enabled: true, icon: "home" } + private readonly _LINKS: (Omit & { + component: ComponentType + })[] = [ + { + title: 'Domyślna strona po logowaniu', + component: RedirectComponent, + enabled: true, + icon: 'home', + }, ] public get LINKS() { - return this._LINKS.filter((v) => { + return this._LINKS.filter(v => { return v.enabled - }); + }) } open(component: ComponentType) { diff --git a/src/app/app-view/personal/extra/redirect/redirect.component.spec.ts b/src/app/app-view/personal/extra/redirect/redirect.component.spec.ts index ad0748e..b081fca 100644 --- a/src/app/app-view/personal/extra/redirect/redirect.component.spec.ts +++ b/src/app/app-view/personal/extra/redirect/redirect.component.spec.ts @@ -1,40 +1,49 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' import { MatInputHarness } from '@angular/material/input/testing' -import { RedirectComponent } from './redirect.component'; -import { MatDialogModule, MatDialogRef } from '@angular/material/dialog'; -import { AuthClient } from 'src/app/services/auth.client'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { HarnessLoader } from '@angular/cdk/testing'; +import { RedirectComponent } from './redirect.component' +import { MatDialogModule, MatDialogRef } from '@angular/material/dialog' +import { AuthClient } from 'src/app/services/auth.client' +import { MatFormFieldModule } from '@angular/material/form-field' +import { HarnessLoader } from '@angular/cdk/testing' import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed' -import { FormsModule } from '@angular/forms'; -import { MatInputModule } from '@angular/material/input'; -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { FormsModule } from '@angular/forms' +import { MatInputModule } from '@angular/material/input' +import { NoopAnimationsModule } from '@angular/platform-browser/animations' describe('RedirectComponent', () => { - let component: RedirectComponent; - let fixture: ComponentFixture; + let component: RedirectComponent + let fixture: ComponentFixture let loader: HarnessLoader let authMock beforeEach(async () => { - authMock = jasmine.createSpyObj("AuthClient", {}, {redirect: ''}) + authMock = jasmine.createSpyObj( + 'AuthClient', + {}, + { redirect: '' } + ) await TestBed.configureTestingModule({ declarations: [RedirectComponent], providers: [ - {provide: MatDialogRef, useValue: {}}, - {provide: AuthClient, useValue: authMock} + { provide: MatDialogRef, useValue: {} }, + { provide: AuthClient, useValue: authMock }, ], - imports: [MatDialogModule, MatFormFieldModule, MatInputModule, FormsModule, NoopAnimationsModule] - }) - .compileComponents(); - - fixture = TestBed.createComponent(RedirectComponent); - component = fixture.componentInstance; - fixture.detectChanges(); + imports: [ + MatDialogModule, + MatFormFieldModule, + MatInputModule, + FormsModule, + NoopAnimationsModule, + ], + }).compileComponents() + + fixture = TestBed.createComponent(RedirectComponent) + component = fixture.componentInstance + fixture.detectChanges() loader = TestbedHarnessEnvironment.loader(fixture) - }); + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/app-view/personal/extra/redirect/redirect.component.ts b/src/app/app-view/personal/extra/redirect/redirect.component.ts index 1293963..3648065 100644 --- a/src/app/app-view/personal/extra/redirect/redirect.component.ts +++ b/src/app/app-view/personal/extra/redirect/redirect.component.ts @@ -1,16 +1,19 @@ -import { Component } from '@angular/core'; -import { MatDialogRef } from '@angular/material/dialog'; -import { AuthClient } from 'src/app/services/auth.client'; +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', - standalone: false + selector: 'app-redirect', + templateUrl: './redirect.component.html', + styleUrl: './redirect.component.scss', + standalone: false, }) export class RedirectComponent { - protected redirect = "" - constructor (public dialogRef: MatDialogRef, private ac: AuthClient) { + protected redirect = '' + constructor( + public dialogRef: MatDialogRef, + private ac: AuthClient + ) { this.redirect = ac.redirect } diff --git a/src/app/app-view/personal/key/key.component.scss b/src/app/app-view/personal/key/key.component.scss index 825c94f..c0b2648 100644 --- a/src/app/app-view/personal/key/key.component.scss +++ b/src/app/app-view/personal/key/key.component.scss @@ -1,6 +1,6 @@ .free { - color: black; - @media (prefers-color-scheme: dark) { - color: white; - } -} \ No newline at end of file + color: black; + @media (prefers-color-scheme: dark) { + color: white; + } +} diff --git a/src/app/app-view/personal/key/key.component.spec.ts b/src/app/app-view/personal/key/key.component.spec.ts index cab566d..ee08b82 100644 --- a/src/app/app-view/personal/key/key.component.spec.ts +++ b/src/app/app-view/personal/key/key.component.spec.ts @@ -1,35 +1,32 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { KeyComponent } from './key.component'; -import { UpdatesService } from 'src/app/services/updates.service'; -import { of } from 'rxjs'; -import { MatDialogModule } from '@angular/material/dialog'; -import { MatIconModule } from '@angular/material/icon'; +import { KeyComponent } from './key.component' +import { UpdatesService } from 'src/app/services/updates.service' +import { of } from 'rxjs' +import { MatDialogModule } from '@angular/material/dialog' +import { MatIconModule } from '@angular/material/icon' describe('KeyComponent', () => { - let component: KeyComponent; - let fixture: ComponentFixture; + let component: KeyComponent + let fixture: ComponentFixture let uMock: jasmine.SpyObj beforeEach(async () => { - uMock = jasmine.createSpyObj("UpdatesService", { - getKeys: of() + uMock = jasmine.createSpyObj('UpdatesService', { + getKeys: of(), }) await TestBed.configureTestingModule({ declarations: [KeyComponent], - providers: [ - {provide: UpdatesService, useValue: uMock} - ], - imports: [MatDialogModule, MatIconModule] - }) - .compileComponents(); - - fixture = TestBed.createComponent(KeyComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + providers: [{ provide: UpdatesService, useValue: uMock }], + imports: [MatDialogModule, MatIconModule], + }).compileComponents() + + fixture = TestBed.createComponent(KeyComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/app-view/personal/key/key.component.ts b/src/app/app-view/personal/key/key.component.ts index 40e29ac..ec37cff 100644 --- a/src/app/app-view/personal/key/key.component.ts +++ b/src/app/app-view/personal/key/key.component.ts @@ -1,21 +1,20 @@ -import { Component, OnInit } from '@angular/core'; -import { UpdatesService } from 'src/app/services/updates.service'; -import { UKey } from 'src/app/types/key'; +import { Component, OnInit } from '@angular/core' +import { UpdatesService } from 'src/app/services/updates.service' +import { UKey } from 'src/app/types/key' @Component({ - selector: 'app-key', - templateUrl: './key.component.html', - styleUrl: './key.component.scss', - standalone: false + selector: 'app-key', + templateUrl: './key.component.html', + styleUrl: './key.component.scss', + standalone: false, }) export class KeyComponent implements OnInit { - - constructor (private us: UpdatesService){} + constructor(private us: UpdatesService) {} keys!: UKey[] ngOnInit(): void { - this.us.getKeys().subscribe((v) => { + this.us.getKeys().subscribe(v => { this.keys = v }) } diff --git a/src/app/app-view/personal/logout-confirmation/logout-confirmation.component.spec.ts b/src/app/app-view/personal/logout-confirmation/logout-confirmation.component.spec.ts index 3722599..1b32ff7 100644 --- a/src/app/app-view/personal/logout-confirmation/logout-confirmation.component.spec.ts +++ b/src/app/app-view/personal/logout-confirmation/logout-confirmation.component.spec.ts @@ -1,23 +1,23 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { LogoutConfirmationComponent } from './logout-confirmation.component'; -import { MatDialogModule } from '@angular/material/dialog'; +import { LogoutConfirmationComponent } from './logout-confirmation.component' +import { MatDialogModule } from '@angular/material/dialog' describe('LogoutConfirmationComponent', () => { - let component: LogoutConfirmationComponent; - let fixture: ComponentFixture; + let component: LogoutConfirmationComponent + let fixture: ComponentFixture beforeEach(() => { TestBed.configureTestingModule({ declarations: [LogoutConfirmationComponent], - imports: [MatDialogModule] - }); - fixture = TestBed.createComponent(LogoutConfirmationComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [MatDialogModule], + }) + fixture = TestBed.createComponent(LogoutConfirmationComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/app-view/personal/logout-confirmation/logout-confirmation.component.ts b/src/app/app-view/personal/logout-confirmation/logout-confirmation.component.ts index 5c10c61..a09a27a 100644 --- a/src/app/app-view/personal/logout-confirmation/logout-confirmation.component.ts +++ b/src/app/app-view/personal/logout-confirmation/logout-confirmation.component.ts @@ -1,11 +1,9 @@ -import { Component } from '@angular/core'; +import { Component } from '@angular/core' @Component({ - selector: 'app-logout-confirmation', - templateUrl: './logout-confirmation.component.html', - styleUrls: ['./logout-confirmation.component.scss'], - standalone: false + selector: 'app-logout-confirmation', + templateUrl: './logout-confirmation.component.html', + styleUrls: ['./logout-confirmation.component.scss'], + standalone: false, }) -export class LogoutConfirmationComponent { - -} +export class LogoutConfirmationComponent {} diff --git a/src/app/app-view/personal/personal.component.spec.ts b/src/app/app-view/personal/personal.component.spec.ts index 2eea8b9..61a2045 100644 --- a/src/app/app-view/personal/personal.component.spec.ts +++ b/src/app/app-view/personal/personal.component.spec.ts @@ -1,39 +1,48 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { PersonalComponent } from './personal.component'; -import { AuthClient } from 'src/app/services/auth.client'; -import { MatDialogModule } from '@angular/material/dialog'; -import { MatSnackBarModule } from '@angular/material/snack-bar'; -import { MatListModule } from '@angular/material/list'; -import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { AppUpdateService } from 'src/app/services/app-update.service'; -import { of } from 'rxjs'; -import { MatIconModule } from '@angular/material/icon'; +import { PersonalComponent } from './personal.component' +import { AuthClient } from 'src/app/services/auth.client' +import { MatDialogModule } from '@angular/material/dialog' +import { MatSnackBarModule } from '@angular/material/snack-bar' +import { MatListModule } from '@angular/material/list' +import { + BrowserAnimationsModule, + NoopAnimationsModule, +} from '@angular/platform-browser/animations' +import { AppUpdateService } from 'src/app/services/app-update.service' +import { of } from 'rxjs' +import { MatIconModule } from '@angular/material/icon' describe('PersonalComponent', () => { - let component: PersonalComponent; - let fixture: ComponentFixture; + let component: PersonalComponent + let fixture: ComponentFixture let auMock: jasmine.SpyObj beforeEach(() => { - auMock = jasmine.createSpyObj("aumock", { - checkForUpdate: of() + auMock = jasmine.createSpyObj('aumock', { + checkForUpdate: of(), }) const authMock = jasmine.createSpyObj('AuthClient', ['s']) TestBed.configureTestingModule({ declarations: [PersonalComponent], providers: [ - {provide: AuthClient, useValue: authMock}, - {provide: AppUpdateService, useValue: auMock} + { provide: AuthClient, useValue: authMock }, + { provide: AppUpdateService, useValue: auMock }, ], - imports: [MatDialogModule, MatSnackBarModule, MatListModule, NoopAnimationsModule, MatIconModule] - }); - fixture = TestBed.createComponent(PersonalComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [ + MatDialogModule, + MatSnackBarModule, + MatListModule, + NoopAnimationsModule, + MatIconModule, + ], + }) + fixture = TestBed.createComponent(PersonalComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/app-view/personal/personal.component.ts b/src/app/app-view/personal/personal.component.ts index 88351c8..6672057 100644 --- a/src/app/app-view/personal/personal.component.ts +++ b/src/app/app-view/personal/personal.component.ts @@ -1,35 +1,41 @@ -import { Component } from '@angular/core'; -import { AuthClient } from '../../services/auth.client'; -import { Router } from '@angular/router'; -import { MatDialog } from '@angular/material/dialog'; -import { ChangePasswordDialogComponent } from './change-password-dialog/change-password-dialog.component'; -import { environment } from 'src/environments/environment'; -import { LogoutConfirmationComponent } from './logout-confirmation/logout-confirmation.component'; -import { AppUpdateService } from 'src/app/services/app-update.service'; -import { LocalStorageService } from 'src/app/services/local-storage.service'; -import { KeyComponent } from './key/key.component'; -import { CleanComponent } from './clean/clean.component'; -import { AboutComponent } from './about/about.component'; -import { ExtraComponent } from './extra/extra.component'; +import { Component } from '@angular/core' +import { AuthClient } from '../../services/auth.client' +import { Router } from '@angular/router' +import { MatDialog } from '@angular/material/dialog' +import { ChangePasswordDialogComponent } from './change-password-dialog/change-password-dialog.component' +import { environment } from 'src/environments/environment' +import { LogoutConfirmationComponent } from './logout-confirmation/logout-confirmation.component' +import { AppUpdateService } from 'src/app/services/app-update.service' +import { LocalStorageService } from 'src/app/services/local-storage.service' +import { KeyComponent } from './key/key.component' +import { CleanComponent } from './clean/clean.component' +import { AboutComponent } from './about/about.component' +import { ExtraComponent } from './extra/extra.component' @Component({ - selector: 'app-personal', - templateUrl: './personal.component.html', - styleUrls: ['./personal.component.scss'], - standalone: false + selector: 'app-personal', + templateUrl: './personal.component.html', + styleUrls: ['./personal.component.scss'], + standalone: false, }) export class PersonalComponent { updateaval: boolean | unknown = false - checking: boolean | "err" | "aval" = false - constructor (private ac: AuthClient, private router: Router, private dialog: MatDialog, readonly update: AppUpdateService, protected ls: LocalStorageService) {} - public version: any = environment.version; + checking: boolean | 'err' | 'aval' = false + constructor( + private ac: AuthClient, + private router: Router, + private dialog: MatDialog, + readonly update: AppUpdateService, + protected ls: LocalStorageService + ) {} + public version: any = environment.version protected logout() { let dialogRef = this.dialog.open(LogoutConfirmationComponent) dialogRef.afterClosed().subscribe(result => { if (result) { this.ac.logout().subscribe(() => { - this.router.navigateByUrl("/login") - this.ls.logOut() + this.router.navigateByUrl('/login') + this.ls.logOut() }) } }) @@ -48,19 +54,19 @@ export class PersonalComponent { } protected goToAdmin() { - this.router.navigateByUrl("admin") + this.router.navigateByUrl('admin') } protected async checkUpdate() { this.checking = true this.update.checkForUpdate().subscribe({ - next: (v) => { + next: v => { this.checking = false if (v) { - this.checking = "aval" + this.checking = 'aval' } }, - error: () => this.checking = "err" + error: () => (this.checking = 'err'), }) this.ac.check() } diff --git a/src/app/app-view/start/start.component.scss b/src/app/app-view/start/start.component.scss index a8fdb47..73a940f 100644 --- a/src/app/app-view/start/start.component.scss +++ b/src/app/app-view/start/start.component.scss @@ -1,6 +1,6 @@ :host { - display: flex; - height: 100%; - justify-content: center; - align-items: center; -} \ No newline at end of file + display: flex; + height: 100%; + justify-content: center; + align-items: center; +} diff --git a/src/app/app-view/start/start.component.spec.ts b/src/app/app-view/start/start.component.spec.ts index d07cd5a..92de6d1 100644 --- a/src/app/app-view/start/start.component.spec.ts +++ b/src/app/app-view/start/start.component.spec.ts @@ -1,29 +1,25 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { StartComponent } from './start.component'; -import { RouterModule } from '@angular/router'; -import { MatListModule } from '@angular/material/list'; +import { StartComponent } from './start.component' +import { RouterModule } from '@angular/router' +import { MatListModule } from '@angular/material/list' describe('StartComponent', () => { - let component: StartComponent; - let fixture: ComponentFixture; + let component: StartComponent + let fixture: ComponentFixture beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [StartComponent], - imports: [ - RouterModule.forRoot([]), - MatListModule - ] - }) - .compileComponents(); - - fixture = TestBed.createComponent(StartComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [RouterModule.forRoot([]), MatListModule], + }).compileComponents() + + fixture = TestBed.createComponent(StartComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/app-view/start/start.component.ts b/src/app/app-view/start/start.component.ts index 59d5b4b..904c562 100644 --- a/src/app/app-view/start/start.component.ts +++ b/src/app/app-view/start/start.component.ts @@ -1,27 +1,61 @@ -import { Component } from '@angular/core'; -import { ActivatedRoute, Router } from '@angular/router'; -import { LocalStorageService } from 'src/app/services/local-storage.service'; -import { Link } from 'src/app/types/link'; +import { Component } from '@angular/core' +import { ActivatedRoute, Router } from '@angular/router' +import { LocalStorageService } from 'src/app/services/local-storage.service' +import { Link } from 'src/app/types/link' @Component({ - selector: 'app-start', - templateUrl: './start.component.html', - styleUrl: './start.component.scss', - standalone: false + selector: 'app-start', + templateUrl: './start.component.html', + styleUrl: './start.component.scss', + standalone: false, }) export class StartComponent { private readonly _LINKS: Link[] = [ - { title: "Jadłospis (z funkcją głosowania)", href: "menu", icon: "restaurant_menu", enabled: this.ls.capCheck(2) }, - { title: "Wiadomości", href: "news", icon: "newspaper", enabled: this.ls.capCheck(1) }, - { title: "Ustawienia konta", href: "grades", icon: "settings_account_box", enabled: true }, - { title: "Klucze do sal", href: "grades", icon: "key", enabled: this.ls.capCheck(32) }, - { title: "Oceny za czystość", href: "grades", icon: "cleaning_services", enabled: this.ls.capCheck(16) }, - { title: "Administracja", href: "grades", icon: "admin_panel_settings", enabled: this.ls.admin != 0 }, - ]; + { + title: 'Jadłospis (z funkcją głosowania)', + href: 'menu', + icon: 'restaurant_menu', + enabled: this.ls.capCheck(2), + }, + { + title: 'Wiadomości', + href: 'news', + icon: 'newspaper', + enabled: this.ls.capCheck(1), + }, + { + title: 'Ustawienia konta', + href: 'grades', + icon: 'settings_account_box', + enabled: true, + }, + { + title: 'Klucze do sal', + href: 'grades', + icon: 'key', + enabled: this.ls.capCheck(32), + }, + { + title: 'Oceny za czystość', + href: 'grades', + icon: 'cleaning_services', + enabled: this.ls.capCheck(16), + }, + { + title: 'Administracja', + href: 'grades', + icon: 'admin_panel_settings', + enabled: this.ls.admin != 0, + }, + ] public get LINKS(): Link[] { - return this._LINKS.filter(v => v.enabled); + return this._LINKS.filter(v => v.enabled) } - constructor(private r: Router, private readonly route: ActivatedRoute, private ls: LocalStorageService) { } + constructor( + private r: Router, + private readonly route: ActivatedRoute, + private ls: LocalStorageService + ) {} protected redirect(link: any) { this.r.navigate([link], { relativeTo: this.route }) } diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 81f0d0e..5000d15 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -1,34 +1,28 @@ -import { TestBed } from '@angular/core/testing'; -import { AppComponent } from './app.component'; -import { AppUpdateService } from './services/app-update.service'; -import { RouterModule } from '@angular/router'; +import { TestBed } from '@angular/core/testing' +import { AppComponent } from './app.component' +import { AppUpdateService } from './services/app-update.service' +import { RouterModule } from '@angular/router' describe('AppComponent', () => { let auMock beforeEach(async () => { auMock = {} await TestBed.configureTestingModule({ - declarations: [ - AppComponent - ], - providers: [ - {provide: AppUpdateService, useValue: auMock} - ], - imports: [ - RouterModule - ] - }).compileComponents(); - }); + declarations: [AppComponent], + providers: [{ provide: AppUpdateService, useValue: auMock }], + imports: [RouterModule], + }).compileComponents() + }) it('should create the app', () => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.componentInstance; - expect(app).toBeTruthy(); - }); + const fixture = TestBed.createComponent(AppComponent) + const app = fixture.componentInstance + expect(app).toBeTruthy() + }) it(`should have as title 'Internat'`, () => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.componentInstance; - expect(app.title).toEqual('Internat'); - }); -}); + const fixture = TestBed.createComponent(AppComponent) + const app = fixture.componentInstance + expect(app.title).toEqual('Internat') + }) +}) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 7bdbab9..289c268 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,18 +1,22 @@ -import { Component, Inject, LOCALE_ID } from '@angular/core'; -import { AppUpdateService } from './services/app-update.service'; -import { MatIconRegistry } from '@angular/material/icon'; -import { Settings } from 'luxon'; +import { Component, Inject, LOCALE_ID } from '@angular/core' +import { AppUpdateService } from './services/app-update.service' +import { MatIconRegistry } from '@angular/material/icon' +import { Settings } from 'luxon' @Component({ - selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.scss'], - standalone: false + selector: 'app-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.scss'], + standalone: false, }) export class AppComponent { - constructor (readonly updates: AppUpdateService, mir: MatIconRegistry, @Inject(LOCALE_ID) lang: string) { - mir.setDefaultFontSetClass("material-symbols-rounded") + constructor( + readonly updates: AppUpdateService, + mir: MatIconRegistry, + @Inject(LOCALE_ID) lang: string + ) { + mir.setDefaultFontSetClass('material-symbols-rounded') Settings.defaultLocale = lang } - title = 'Internat'; + title = 'Internat' } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e12c9bc..4a76131 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,186 +1,190 @@ -import { NgModule, isDevMode } from '@angular/core'; -import { BrowserModule } from '@angular/platform-browser'; +import { NgModule, isDevMode } from '@angular/core' +import { BrowserModule } from '@angular/platform-browser' -import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { MatButtonModule } from "@angular/material/button"; -import { MatCardModule } from "@angular/material/card"; -import { MatDatepickerModule } from "@angular/material/datepicker"; -import { MatDialogModule } from '@angular/material/dialog'; -import { MatIconModule } from "@angular/material/icon"; -import { MatInputModule } from '@angular/material/input'; -import { MatListModule } from "@angular/material/list"; -import { MatTabsModule } from '@angular/material/tabs'; -import { MatToolbarModule } from "@angular/material/toolbar"; -import { MatSidenavModule } from "@angular/material/sidenav"; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { ServiceWorkerModule } from '@angular/service-worker'; -import { AdminViewComponent } from './admin-view/admin-view.component'; -import { AppRoutingModule } from './app-routing.module'; -import { AppViewComponent } from './app-view/app-view.component'; -import { DateSelectorComponent } from './commonComponents/date-selector/date-selector.component'; -import { MenuComponent } from './app-view/menu/menu.component'; -import { NewsComponent } from './app-view/news/news.component'; -import { ChangePasswordDialogComponent } from './app-view/personal/change-password-dialog/change-password-dialog.component'; -import { LogoutConfirmationComponent } from './app-view/personal/logout-confirmation/logout-confirmation.component'; -import { PersonalComponent } from './app-view/personal/personal.component'; -import { AppComponent } from './app.component'; -import { LoginComponent } from './login/login.component'; -import { MenuUploadComponent } from './admin-view/menu-new/menu-upload/menu-upload.component'; -import { NewsEditComponent } from './admin-view/news-edit/news-edit.component'; -import { MatSnackBarModule } from "@angular/material/snack-bar"; -import { NewPostComponent } from './admin-view/news-edit/new-post/edit-post.component'; -import { AccountMgmtComponent } from './admin-view/account-mgmt/account-mgmt.component'; -import { MatTableModule } from "@angular/material/table"; -import { UserEditComponent } from './admin-view/account-mgmt/user-edit/user-edit.component'; -import { MatPaginatorModule } from "@angular/material/paginator"; -import { UserDeleteComponent } from './admin-view/account-mgmt/user-delete/user-delete.component'; -import { MatSelectModule } from '@angular/material/select'; -import { MenuNewComponent } from './admin-view/menu-new/menu-new.component'; -import { FDSelection } from './fd.da'; -import { CeDirective } from './ce.directive'; -import { AllergensComponent } from './app-view/menu/allergens/allergens.component'; -import { MatBottomSheetModule } from "@angular/material/bottom-sheet"; -import { UserResetComponent } from './admin-view/account-mgmt/user-reset/user-reset.component'; -import { MatSlideToggleModule } from '@angular/material/slide-toggle'; -import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; -import { MatRadioModule } from '@angular/material/radio'; -import { NotificationsComponent } from './admin-view/notifications/notifications.component'; -import { GroupsComponent } from './admin-view/groups/groups.component'; -import { ListEditorComponent } from './commonComponents/list-editor/list-editor.component'; -import { RemoveConfirmComponent } from './admin-view/groups/remove-confirm/remove-confirm.component'; -import { StartComponent } from './app-view/start/start.component'; -import { KeyComponent } from './app-view/personal/key/key.component'; -import { AdminKeyComponent } from './admin-view/key/key.component'; +import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http' +import { FormsModule, ReactiveFormsModule } from '@angular/forms' +import { MatButtonModule } from '@angular/material/button' +import { MatCardModule } from '@angular/material/card' +import { MatDatepickerModule } from '@angular/material/datepicker' +import { MatDialogModule } from '@angular/material/dialog' +import { MatIconModule } from '@angular/material/icon' +import { MatInputModule } from '@angular/material/input' +import { MatListModule } from '@angular/material/list' +import { MatTabsModule } from '@angular/material/tabs' +import { MatToolbarModule } from '@angular/material/toolbar' +import { MatSidenavModule } from '@angular/material/sidenav' +import { BrowserAnimationsModule } from '@angular/platform-browser/animations' +import { ServiceWorkerModule } from '@angular/service-worker' +import { AdminViewComponent } from './admin-view/admin-view.component' +import { AppRoutingModule } from './app-routing.module' +import { AppViewComponent } from './app-view/app-view.component' +import { DateSelectorComponent } from './commonComponents/date-selector/date-selector.component' +import { MenuComponent } from './app-view/menu/menu.component' +import { NewsComponent } from './app-view/news/news.component' +import { ChangePasswordDialogComponent } from './app-view/personal/change-password-dialog/change-password-dialog.component' +import { LogoutConfirmationComponent } from './app-view/personal/logout-confirmation/logout-confirmation.component' +import { PersonalComponent } from './app-view/personal/personal.component' +import { AppComponent } from './app.component' +import { LoginComponent } from './login/login.component' +import { MenuUploadComponent } from './admin-view/menu-new/menu-upload/menu-upload.component' +import { NewsEditComponent } from './admin-view/news-edit/news-edit.component' +import { MatSnackBarModule } from '@angular/material/snack-bar' +import { NewPostComponent } from './admin-view/news-edit/new-post/edit-post.component' +import { AccountMgmtComponent } from './admin-view/account-mgmt/account-mgmt.component' +import { MatTableModule } from '@angular/material/table' +import { UserEditComponent } from './admin-view/account-mgmt/user-edit/user-edit.component' +import { MatPaginatorModule } from '@angular/material/paginator' +import { UserDeleteComponent } from './admin-view/account-mgmt/user-delete/user-delete.component' +import { MatSelectModule } from '@angular/material/select' +import { MenuNewComponent } from './admin-view/menu-new/menu-new.component' +import { FDSelection } from './fd.da' +import { CeDirective } from './ce.directive' +import { AllergensComponent } from './app-view/menu/allergens/allergens.component' +import { MatBottomSheetModule } from '@angular/material/bottom-sheet' +import { UserResetComponent } from './admin-view/account-mgmt/user-reset/user-reset.component' +import { MatSlideToggleModule } from '@angular/material/slide-toggle' +import { MatProgressSpinnerModule } from '@angular/material/progress-spinner' +import { MatRadioModule } from '@angular/material/radio' +import { NotificationsComponent } from './admin-view/notifications/notifications.component' +import { GroupsComponent } from './admin-view/groups/groups.component' +import { ListEditorComponent } from './commonComponents/list-editor/list-editor.component' +import { RemoveConfirmComponent } from './admin-view/groups/remove-confirm/remove-confirm.component' +import { StartComponent } from './app-view/start/start.component' +import { KeyComponent } from './app-view/personal/key/key.component' +import { AdminKeyComponent } from './admin-view/key/key.component' import { MatChipsModule } from '@angular/material/chips' -import { NewKeyComponent } from './admin-view/key/new-key/new-key.component'; -import { GradesComponent } from './admin-view/grades/grades.component'; -import { RoomChooserComponent } from './commonComponents/room-chooser/room-chooser.component'; -import { CleanComponent } from './app-view/personal/clean/clean.component'; +import { NewKeyComponent } from './admin-view/key/new-key/new-key.component' +import { GradesComponent } from './admin-view/grades/grades.component' +import { RoomChooserComponent } from './commonComponents/room-chooser/room-chooser.component' +import { CleanComponent } from './app-view/personal/clean/clean.component' import { MatCheckboxModule } from '@angular/material/checkbox' -import { LabelDirective } from './label.directive'; +import { LabelDirective } from './label.directive' import { MatMenuModule } from '@angular/material/menu' -import { SummaryComponent } from './admin-view/grades/summary/summary.component'; -import { MatSortModule } from '@angular/material/sort'; -import {MatButtonToggleModule} from '@angular/material/button-toggle'; -import { SettingsComponent } from './admin-view/settings/settings.component'; +import { SummaryComponent } from './admin-view/grades/summary/summary.component' +import { MatSortModule } from '@angular/material/sort' +import { MatButtonToggleModule } from '@angular/material/button-toggle' +import { SettingsComponent } from './admin-view/settings/settings.component' import { MatExpansionModule } from '@angular/material/expansion' -import { DragDropModule } from "@angular/cdk/drag-drop"; -import { MatBadgeModule } from "@angular/material/badge"; -import { MenuAddComponent } from './admin-view/menu-new/menu-add/menu-add.component'; -import { FieldEditorComponent } from './commonComponents/field-editor/field-editor.component'; -import { A11yModule } from '@angular/cdk/a11y'; -import { PortalModule } from '@angular/cdk/portal'; -import { MatAutocompleteModule } from "@angular/material/autocomplete"; -import { AttendenceComponent } from './admin-view/grades/attendence/attendence.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 { 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'; -import { provideLuxonDateAdapter } from "@angular/material-luxon-adapter"; +import { DragDropModule } from '@angular/cdk/drag-drop' +import { MatBadgeModule } from '@angular/material/badge' +import { MenuAddComponent } from './admin-view/menu-new/menu-add/menu-add.component' +import { FieldEditorComponent } from './commonComponents/field-editor/field-editor.component' +import { A11yModule } from '@angular/cdk/a11y' +import { PortalModule } from '@angular/cdk/portal' +import { MatAutocompleteModule } from '@angular/material/autocomplete' +import { AttendenceComponent } from './admin-view/grades/attendence/attendence.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 { 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' +import { provideLuxonDateAdapter } from '@angular/material-luxon-adapter' -@NgModule({ declarations: [ - AppComponent, - NewsComponent, - MenuComponent, - LoginComponent, - AppViewComponent, - PersonalComponent, - ChangePasswordDialogComponent, - LogoutConfirmationComponent, - DateSelectorComponent, - AdminViewComponent, - MenuUploadComponent, - NewsEditComponent, - NewPostComponent, - AccountMgmtComponent, - UserEditComponent, - UserDeleteComponent, - MenuNewComponent, - CeDirective, - LabelDirective, - AllergensComponent, - UserResetComponent, - NotificationsComponent, - GroupsComponent, - ListEditorComponent, - RemoveConfirmComponent, - StartComponent, - KeyComponent, - AdminKeyComponent, - NewKeyComponent, - GradesComponent, - RoomChooserComponent, - CleanComponent, - SummaryComponent, - SettingsComponent, - MenuAddComponent, - FieldEditorComponent, - AttendenceComponent, - AttendenceSummaryComponent, - HourDisplayComponent, - AboutComponent, - ExtraComponent, - RedirectComponent, - OutboxComponent, - ToolbarComponent, - MessageComponent, - NotifDialogComponent, - UserSearchComponent, - StartAdminComponent, - ], - bootstrap: [AppComponent], - imports: [ - BrowserModule, - AppRoutingModule, - BrowserAnimationsModule, - MatTabsModule, - MatCardModule, - MatButtonModule, - MatIconModule, - MatDatepickerModule, - MatInputModule, - ReactiveFormsModule, - FormsModule, - MatDialogModule, - MatListModule, - MatToolbarModule, - MatSidenavModule, - MatSnackBarModule, - MatTableModule, - MatPaginatorModule, - MatSelectModule, - MatBottomSheetModule, - MatSlideToggleModule, - MatProgressSpinnerModule, - MatRadioModule, - MatChipsModule, - MatCheckboxModule, - MatMenuModule, - MatSortModule, - MatButtonToggleModule, - MatExpansionModule, - DragDropModule, - MatBadgeModule, - PortalModule, - A11yModule, - MatAutocompleteModule, - ServiceWorkerModule.register('ngsw-worker.js', { - enabled: environment.production, - // Register the ServiceWorker as soon as the application is stable - // or after 30 seconds (whichever comes first). - registrationStrategy: 'registerWhenStable:30000' - })], providers: [ - provideLuxonDateAdapter(), - FDSelection, - provideHttpClient(withInterceptorsFromDi()), - ] }) -export class AppModule { } +@NgModule({ + declarations: [ + AppComponent, + NewsComponent, + MenuComponent, + LoginComponent, + AppViewComponent, + PersonalComponent, + ChangePasswordDialogComponent, + LogoutConfirmationComponent, + DateSelectorComponent, + AdminViewComponent, + MenuUploadComponent, + NewsEditComponent, + NewPostComponent, + AccountMgmtComponent, + UserEditComponent, + UserDeleteComponent, + MenuNewComponent, + CeDirective, + LabelDirective, + AllergensComponent, + UserResetComponent, + NotificationsComponent, + GroupsComponent, + ListEditorComponent, + RemoveConfirmComponent, + StartComponent, + KeyComponent, + AdminKeyComponent, + NewKeyComponent, + GradesComponent, + RoomChooserComponent, + CleanComponent, + SummaryComponent, + SettingsComponent, + MenuAddComponent, + FieldEditorComponent, + AttendenceComponent, + AttendenceSummaryComponent, + HourDisplayComponent, + AboutComponent, + ExtraComponent, + RedirectComponent, + OutboxComponent, + ToolbarComponent, + MessageComponent, + NotifDialogComponent, + UserSearchComponent, + StartAdminComponent, + ], + bootstrap: [AppComponent], + imports: [ + BrowserModule, + AppRoutingModule, + BrowserAnimationsModule, + MatTabsModule, + MatCardModule, + MatButtonModule, + MatIconModule, + MatDatepickerModule, + MatInputModule, + ReactiveFormsModule, + FormsModule, + MatDialogModule, + MatListModule, + MatToolbarModule, + MatSidenavModule, + MatSnackBarModule, + MatTableModule, + MatPaginatorModule, + MatSelectModule, + MatBottomSheetModule, + MatSlideToggleModule, + MatProgressSpinnerModule, + MatRadioModule, + MatChipsModule, + MatCheckboxModule, + MatMenuModule, + MatSortModule, + MatButtonToggleModule, + MatExpansionModule, + DragDropModule, + MatBadgeModule, + PortalModule, + A11yModule, + MatAutocompleteModule, + ServiceWorkerModule.register('ngsw-worker.js', { + enabled: environment.production, + // Register the ServiceWorker as soon as the application is stable + // or after 30 seconds (whichever comes first). + registrationStrategy: 'registerWhenStable:30000', + }), + ], + providers: [ + provideLuxonDateAdapter(), + FDSelection, + provideHttpClient(withInterceptorsFromDi()), + ], +}) +export class AppModule {} diff --git a/src/app/auth.guard.spec.ts b/src/app/auth.guard.spec.ts index 4ae275e..8bd7996 100644 --- a/src/app/auth.guard.spec.ts +++ b/src/app/auth.guard.spec.ts @@ -1,17 +1,17 @@ -import { TestBed } from '@angular/core/testing'; -import { CanActivateFn } from '@angular/router'; +import { TestBed } from '@angular/core/testing' +import { CanActivateFn } from '@angular/router' -import { authGuard } from './auth.guard'; +import { authGuard } from './auth.guard' describe('authGuard', () => { - const executeGuard: CanActivateFn = (...guardParameters) => - TestBed.runInInjectionContext(() => authGuard(...guardParameters)); + const executeGuard: CanActivateFn = (...guardParameters) => + TestBed.runInInjectionContext(() => authGuard(...guardParameters)) beforeEach(() => { - TestBed.configureTestingModule({}); - }); + TestBed.configureTestingModule({}) + }) it('should be created', () => { - expect(executeGuard).toBeTruthy(); - }); -}); + expect(executeGuard).toBeTruthy() + }) +}) diff --git a/src/app/auth.guard.ts b/src/app/auth.guard.ts index 89baeb2..620445c 100644 --- a/src/app/auth.guard.ts +++ b/src/app/auth.guard.ts @@ -1,9 +1,10 @@ -import { inject } from '@angular/core'; -import { CanActivateChildFn, RedirectCommand, Router } from '@angular/router'; -import { LocalStorageService } from './services/local-storage.service'; +import { inject } from '@angular/core' +import { CanActivateChildFn, RedirectCommand, Router } from '@angular/router' +import { LocalStorageService } from './services/local-storage.service' export const authGuard: CanActivateChildFn = (childRoute, state) => { const router = inject(Router) - if (!inject(LocalStorageService).loggedIn) return new RedirectCommand(router.parseUrl('/login')) + if (!inject(LocalStorageService).loggedIn) + return new RedirectCommand(router.parseUrl('/login')) return true -}; +} diff --git a/src/app/ce.directive.spec.ts b/src/app/ce.directive.spec.ts index 7a18a43..964e6b5 100644 --- a/src/app/ce.directive.spec.ts +++ b/src/app/ce.directive.spec.ts @@ -1,12 +1,12 @@ -import { ElementRef } from '@angular/core'; -import { CeDirective } from './ce.directive'; +import { ElementRef } from '@angular/core' +import { CeDirective } from './ce.directive' describe('CeDirective', () => { it('should create an instance', () => { const elref = jasmine.createSpyObj({ - nativeElement: null + nativeElement: null, }) - const directive = new CeDirective(elref); - expect(directive).toBeTruthy(); - }); -}); + const directive = new CeDirective(elref) + expect(directive).toBeTruthy() + }) +}) diff --git a/src/app/ce.directive.ts b/src/app/ce.directive.ts index 0bf7e8a..677ef9f 100644 --- a/src/app/ce.directive.ts +++ b/src/app/ce.directive.ts @@ -1,8 +1,15 @@ -import { Directive, ElementRef, EventEmitter, HostListener, Input, Output } from '@angular/core'; +import { + Directive, + ElementRef, + EventEmitter, + HostListener, + Input, + Output, +} from '@angular/core' @Directive({ - selector: '[appCe] [contenteditable]', - standalone: false + selector: '[appCe] [contenteditable]', + standalone: false, }) export class CeDirective { @Input() multiline: boolean = false @@ -13,11 +20,11 @@ export class CeDirective { this.originalValue = el.nativeElement.innerText } - @HostListener("focusin") focusin() { + @HostListener('focusin') focusin() { this.originalValue = this.el.nativeElement.innerText } - @HostListener("focusout") focusout() { + @HostListener('focusout') focusout() { var newText = this.el.nativeElement.innerText if (newText != this.originalValue) { this.edit.emit(newText) @@ -26,9 +33,9 @@ export class CeDirective { @HostListener('keydown', ['$event']) keyup(e: KeyboardEvent) { if (this.multiline) return - if (e.key == "Enter") { + if (e.key == 'Enter') { e.preventDefault() this.el.nativeElement.blur() } } -} \ No newline at end of file +} diff --git a/src/app/commonComponents/date-selector/date-selector.component.scss b/src/app/commonComponents/date-selector/date-selector.component.scss index 92b7988..7abdb68 100644 --- a/src/app/commonComponents/date-selector/date-selector.component.scss +++ b/src/app/commonComponents/date-selector/date-selector.component.scss @@ -1,11 +1,11 @@ :host { - display: flex; - flex-direction: row; - align-items: center; - justify-content: center; - width: 100%; + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; + width: 100%; } p { - font-size: 15pt; - user-select: none; -} \ No newline at end of file + font-size: 15pt; + user-select: none; +} diff --git a/src/app/commonComponents/date-selector/date-selector.component.spec.ts b/src/app/commonComponents/date-selector/date-selector.component.spec.ts index 5e1bd37..55d5fec 100644 --- a/src/app/commonComponents/date-selector/date-selector.component.spec.ts +++ b/src/app/commonComponents/date-selector/date-selector.component.spec.ts @@ -1,32 +1,37 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { DateSelectorComponent } from './date-selector.component'; -import { MatIconModule } from '@angular/material/icon'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatDatepickerModule } from '@angular/material/datepicker'; -import { MatInputModule } from '@angular/material/input'; -import { ReactiveFormsModule } from '@angular/forms'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { provideLuxonDateAdapter } from '@angular/material-luxon-adapter'; +import { DateSelectorComponent } from './date-selector.component' +import { MatIconModule } from '@angular/material/icon' +import { MatFormFieldModule } from '@angular/material/form-field' +import { MatDatepickerModule } from '@angular/material/datepicker' +import { MatInputModule } from '@angular/material/input' +import { ReactiveFormsModule } from '@angular/forms' +import { BrowserAnimationsModule } from '@angular/platform-browser/animations' +import { provideLuxonDateAdapter } from '@angular/material-luxon-adapter' describe('DateSelectorComponent', () => { - let component: DateSelectorComponent; - let fixture: ComponentFixture; + let component: DateSelectorComponent + let fixture: ComponentFixture beforeEach(() => { TestBed.configureTestingModule({ declarations: [DateSelectorComponent], - imports: [MatIconModule, MatFormFieldModule, MatDatepickerModule, ReactiveFormsModule, MatInputModule, BrowserAnimationsModule], - providers: [ - provideLuxonDateAdapter() - ] - }); - fixture = TestBed.createComponent(DateSelectorComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [ + MatIconModule, + MatFormFieldModule, + MatDatepickerModule, + ReactiveFormsModule, + MatInputModule, + BrowserAnimationsModule, + ], + providers: [provideLuxonDateAdapter()], + }) + fixture = TestBed.createComponent(DateSelectorComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/commonComponents/date-selector/date-selector.component.ts b/src/app/commonComponents/date-selector/date-selector.component.ts index 9bce676..a669e4e 100644 --- a/src/app/commonComponents/date-selector/date-selector.component.ts +++ b/src/app/commonComponents/date-selector/date-selector.component.ts @@ -1,56 +1,64 @@ -import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core'; -import { FormControl } from '@angular/forms'; -import { DateFilterFn } from '@angular/material/datepicker'; -import { DateTime } from 'luxon'; +import { + Component, + EventEmitter, + Input, + OnChanges, + OnInit, + Output, + SimpleChanges, +} from '@angular/core' +import { FormControl } from '@angular/forms' +import { DateFilterFn } from '@angular/material/datepicker' +import { DateTime } from 'luxon' @Component({ - selector: 'app-date-selector', - templateUrl: './date-selector.component.html', - styleUrls: ['./date-selector.component.scss'], - standalone: false + selector: 'app-date-selector', + templateUrl: './date-selector.component.html', + styleUrls: ['./date-selector.component.scss'], + standalone: false, }) export class DateSelectorComponent implements OnChanges { - protected _date_1: DateTime = DateTime.now(); + protected _date_1: DateTime = DateTime.now() protected set _date(value: DateTime) { - this._date_1 = value; + this._date_1 = value this.date = value.toISODate()! } @Input() public set date(value: string) { - this._date_1 = DateTime.fromISO(value); + this._date_1 = DateTime.fromISO(value) } - @Output() dateChange = new EventEmitter(); + @Output() dateChange = new EventEmitter() @Input() filter: DateFilterFn = () => true protected dateInput: FormControl - constructor () { - this.dateInput = new FormControl(this._date_1, {nonNullable: true}); - this.dateInput.valueChanges.subscribe((v) => { + constructor() { + this.dateInput = new FormControl(this._date_1, { nonNullable: true }) + this.dateInput.valueChanges.subscribe(v => { this.dateChange.emit(v.toISODate()!) }) } ngOnChanges(changes: SimpleChanges): void { if (changes['date']) { - this.dateInput.setValue(this._date_1), {emitEvent: false} + this.dateInput.setValue(this._date_1), { emitEvent: false } } } - + prevDay(): void { - let yesterday = this._date_1.minus({day: 1}) + let yesterday = this._date_1.minus({ day: 1 }) if (this.filter(yesterday)) { this.dateInput.setValue(yesterday) } else { - this.dateInput.setValue(this._date.set({weekday: 5}).minus({week: 1})) + this.dateInput.setValue(this._date.set({ weekday: 5 }).minus({ week: 1 })) } } nextDay(): void { - let tomorrow = this._date_1.plus({day: 1}) + let tomorrow = this._date_1.plus({ day: 1 }) if (this.filter(tomorrow)) { this.dateInput.setValue(tomorrow) } else { - this.dateInput.setValue(this._date.set({weekday: 1}).plus({week: 1})) + this.dateInput.setValue(this._date.set({ weekday: 1 }).plus({ week: 1 })) } } } diff --git a/src/app/commonComponents/field-editor/field-editor.component.scss b/src/app/commonComponents/field-editor/field-editor.component.scss index 34b644d..89d0dbc 100644 --- a/src/app/commonComponents/field-editor/field-editor.component.scss +++ b/src/app/commonComponents/field-editor/field-editor.component.scss @@ -1,4 +1,4 @@ .empty { - color: lightgray; - font-style: italic; -} \ No newline at end of file + color: lightgray; + font-style: italic; +} diff --git a/src/app/commonComponents/field-editor/field-editor.component.spec.ts b/src/app/commonComponents/field-editor/field-editor.component.spec.ts index cfff487..02c56b5 100644 --- a/src/app/commonComponents/field-editor/field-editor.component.spec.ts +++ b/src/app/commonComponents/field-editor/field-editor.component.spec.ts @@ -1,23 +1,22 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { FieldEditorComponent } from './field-editor.component'; +import { FieldEditorComponent } from './field-editor.component' describe('FieldEditorComponent', () => { - let component: FieldEditorComponent; - let fixture: ComponentFixture; + let component: FieldEditorComponent + let fixture: ComponentFixture beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [FieldEditorComponent] - }) - .compileComponents(); - - fixture = TestBed.createComponent(FieldEditorComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + declarations: [FieldEditorComponent], + }).compileComponents() + + fixture = TestBed.createComponent(FieldEditorComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/commonComponents/field-editor/field-editor.component.ts b/src/app/commonComponents/field-editor/field-editor.component.ts index f411bfb..0ddffb0 100644 --- a/src/app/commonComponents/field-editor/field-editor.component.ts +++ b/src/app/commonComponents/field-editor/field-editor.component.ts @@ -1,34 +1,42 @@ -import { Component, ElementRef, EventEmitter, HostBinding, HostListener, Input, Output } from '@angular/core'; +import { + Component, + ElementRef, + EventEmitter, + HostBinding, + HostListener, + Input, + Output, +} from '@angular/core' @Component({ - selector: 'app-field-editor', - templateUrl: './field-editor.component.html', - styleUrl: './field-editor.component.scss', - standalone: false + selector: 'app-field-editor', + templateUrl: './field-editor.component.html', + styleUrl: './field-editor.component.scss', + standalone: false, }) export class FieldEditorComponent { - @HostBinding('tabindex') tabindex = 0; - @Input() word!: string; - @Output() wordChange = new EventEmitter(); - @Input() category!: string; - @Input() list?: string; + @HostBinding('tabindex') tabindex = 0 + @Input() word!: string + @Output() wordChange = new EventEmitter() + @Input() category!: string + @Input() list?: string - constructor (private elRef: ElementRef) { } + constructor(private elRef: ElementRef) {} - focused = false; + focused = false @HostListener('click') focusin() { if (!this.focused) { - console.log("in"); + console.log('in') this.focused = true } } @HostListener('focusout') focusout() { - console.log("out"); + console.log('out') } - save(event: Event,v: string) { + save(event: Event, v: string) { this.wordChange.emit(v) this.elRef.nativeElement.blur() this.focused = false diff --git a/src/app/commonComponents/list-editor/list-editor.component.scss b/src/app/commonComponents/list-editor/list-editor.component.scss index 7f51547..ace8461 100644 --- a/src/app/commonComponents/list-editor/list-editor.component.scss +++ b/src/app/commonComponents/list-editor/list-editor.component.scss @@ -1,4 +1,4 @@ div.vertical { - display: flex; - flex-direction: column; -} \ No newline at end of file + display: flex; + flex-direction: column; +} diff --git a/src/app/commonComponents/list-editor/list-editor.component.spec.ts b/src/app/commonComponents/list-editor/list-editor.component.spec.ts index 09de2e7..cea54bb 100644 --- a/src/app/commonComponents/list-editor/list-editor.component.spec.ts +++ b/src/app/commonComponents/list-editor/list-editor.component.spec.ts @@ -1,21 +1,21 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { ListEditorComponent } from './list-editor.component'; +import { ListEditorComponent } from './list-editor.component' describe('ListEditorComponent', () => { - let component: ListEditorComponent; - let fixture: ComponentFixture; + let component: ListEditorComponent + let fixture: ComponentFixture beforeEach(() => { TestBed.configureTestingModule({ - declarations: [ListEditorComponent] - }); - fixture = TestBed.createComponent(ListEditorComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + declarations: [ListEditorComponent], + }) + fixture = TestBed.createComponent(ListEditorComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/commonComponents/list-editor/list-editor.component.ts b/src/app/commonComponents/list-editor/list-editor.component.ts index 6e58512..256d33e 100644 --- a/src/app/commonComponents/list-editor/list-editor.component.ts +++ b/src/app/commonComponents/list-editor/list-editor.component.ts @@ -1,29 +1,42 @@ -import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop'; -import { ChangeDetectorRef, Component, ElementRef, EventEmitter, HostBinding, HostListener, Input, OnChanges, Output, QueryList, SimpleChanges, ViewChildren } from '@angular/core'; +import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop' +import { + ChangeDetectorRef, + Component, + ElementRef, + EventEmitter, + HostBinding, + HostListener, + Input, + OnChanges, + Output, + QueryList, + SimpleChanges, + ViewChildren, +} from '@angular/core' @Component({ - selector: 'app-list-editor[list], app-list-editor[converter]', - templateUrl: './list-editor.component.html', - styleUrls: ['./list-editor.component.scss'], - standalone: false + selector: 'app-list-editor[list], app-list-editor[converter]', + templateUrl: './list-editor.component.html', + styleUrls: ['./list-editor.component.scss'], + standalone: false, }) export class ListEditorComponent implements OnChanges { - @HostBinding('tabindex') tabindex = 0; - @Input() list?: string[]; - @Output() listChange = new EventEmitter(); - @Input() converter?: any[]; - @Input() options?: {id: string, text: string}[] - @Input() dropdown?: boolean; - @Input() dataList?: string; - @Output() edit = new EventEmitter(); + @HostBinding('tabindex') tabindex = 0 + @Input() list?: string[] + @Output() listChange = new EventEmitter() + @Input() converter?: any[] + @Input() options?: { id: string; text: string }[] + @Input() dropdown?: boolean + @Input() dataList?: string + @Output() edit = new EventEmitter() @ViewChildren('input') inputList!: QueryList - protected _list: string[] = []; - workList: string[] = []; - focused = false; + protected _list: string[] = [] + workList: string[] = [] + focused = false - constructor (private cdRef: ChangeDetectorRef) {} + constructor(private cdRef: ChangeDetectorRef) {} ngOnChanges(changes: SimpleChanges): void { if (this.list) { @@ -59,12 +72,12 @@ export class ListEditorComponent implements OnChanges { } 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() + this.inputList.get(index + 1)?.nativeElement.focus() } - trackByIndex(index: number, _entry:any) { + trackByIndex(index: number, _entry: any) { return index } @@ -73,7 +86,7 @@ export class ListEditorComponent implements OnChanges { } protected idToOption(item: string) { - return this.options?.find((v)=>{ + return this.options?.find(v => { return v.id == item })?.text } diff --git a/src/app/commonComponents/room-chooser/room-chooser.component.scss b/src/app/commonComponents/room-chooser/room-chooser.component.scss index 041cdc5..a28221b 100644 --- a/src/app/commonComponents/room-chooser/room-chooser.component.scss +++ b/src/app/commonComponents/room-chooser/room-chooser.component.scss @@ -1,12 +1,12 @@ :host { - display: flex; - flex-direction: row; - align-items: center; - justify-content: center; - width: 100%; + display: flex; + flex-direction: row; + align-items: center; + justify-content: center; + width: 100%; } p { - font-size: 15pt; - user-select: none; -} \ No newline at end of file + font-size: 15pt; + user-select: none; +} diff --git a/src/app/commonComponents/room-chooser/room-chooser.component.spec.ts b/src/app/commonComponents/room-chooser/room-chooser.component.spec.ts index 18ad739..e682686 100644 --- a/src/app/commonComponents/room-chooser/room-chooser.component.spec.ts +++ b/src/app/commonComponents/room-chooser/room-chooser.component.spec.ts @@ -1,25 +1,24 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { RoomChooserComponent } from './room-chooser.component'; -import { MatIconModule } from '@angular/material/icon'; +import { RoomChooserComponent } from './room-chooser.component' +import { MatIconModule } from '@angular/material/icon' describe('RoomChooserComponent', () => { - let component: RoomChooserComponent; - let fixture: ComponentFixture; + let component: RoomChooserComponent + let fixture: ComponentFixture beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [RoomChooserComponent], - imports: [MatIconModule] - }) - .compileComponents(); - - fixture = TestBed.createComponent(RoomChooserComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + imports: [MatIconModule], + }).compileComponents() + + fixture = TestBed.createComponent(RoomChooserComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/commonComponents/room-chooser/room-chooser.component.ts b/src/app/commonComponents/room-chooser/room-chooser.component.ts index 0e462c2..6237e7b 100644 --- a/src/app/commonComponents/room-chooser/room-chooser.component.ts +++ b/src/app/commonComponents/room-chooser/room-chooser.component.ts @@ -1,42 +1,49 @@ -import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core'; +import { + Component, + EventEmitter, + Input, + OnChanges, + Output, + SimpleChanges, +} from '@angular/core' @Component({ - selector: 'app-room-chooser', - templateUrl: './room-chooser.component.html', - styleUrl: './room-chooser.component.scss', - standalone: false + selector: 'app-room-chooser', + templateUrl: './room-chooser.component.html', + styleUrl: './room-chooser.component.scss', + standalone: false, }) export class RoomChooserComponent implements OnChanges { @Input() rooms: string[] = [] - private _roomIndex: number = 0; + private _roomIndex: number = 0 public get roomIndex(): number { - return this._roomIndex; + return this._roomIndex } public set roomIndex(value: number) { - if (value < 0 || value+1 > this.rooms.length) { + if (value < 0 || value + 1 > this.rooms.length) { return } - this._roomIndex = value; + this._roomIndex = value } - private _room: string = this.rooms[this.roomIndex]; + private _room: string = this.rooms[this.roomIndex] protected get room_1() { - return this._room; + return this._room } protected set room_1(value) { this.room.emit(value) - this._room = value; + this._room = value } - @Output() room: EventEmitter = new EventEmitter(); + @Output() room: EventEmitter = new EventEmitter() ngOnChanges(changes: SimpleChanges): void { - if (changes["rooms"] && this.rooms) { + if (changes['rooms'] && this.rooms) { if (this.rooms.length > 0) { this._roomIndex = 0 this.room_1 = this.rooms[this.roomIndex] } } } - + prevRoom() { this.roomIndex -= 1 this.room_1 = this.rooms[this.roomIndex] diff --git a/src/app/commonComponents/user-search/user-search.component.scss b/src/app/commonComponents/user-search/user-search.component.scss index 0313682..64c972f 100644 --- a/src/app/commonComponents/user-search/user-search.component.scss +++ b/src/app/commonComponents/user-search/user-search.component.scss @@ -1,18 +1,18 @@ :host { - display: flex; - align-items: center; - gap: 1ch; + display: flex; + align-items: center; + gap: 1ch; } .room { - color: gray; + color: gray; } input { - border: none; - background: none; - padding: 0; - outline: 0; - font: inherit; - color: currentColor; -} \ No newline at end of file + border: none; + background: none; + padding: 0; + outline: 0; + font: inherit; + color: currentColor; +} diff --git a/src/app/commonComponents/user-search/user-search.component.spec.ts b/src/app/commonComponents/user-search/user-search.component.spec.ts index 7888bba..a774428 100644 --- a/src/app/commonComponents/user-search/user-search.component.spec.ts +++ b/src/app/commonComponents/user-search/user-search.component.spec.ts @@ -1,40 +1,35 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { UserSearchComponent } from './user-search.component'; -import { AdminCommService } from 'src/app/admin-view/admin-comm.service'; -import { MatAutocompleteModule } from '@angular/material/autocomplete'; -import { MatInputModule } from '@angular/material/input'; -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { UserSearchComponent } from './user-search.component' +import { AdminCommService } from 'src/app/admin-view/admin-comm.service' +import { MatAutocompleteModule } from '@angular/material/autocomplete' +import { MatInputModule } from '@angular/material/input' +import { FormsModule, ReactiveFormsModule } from '@angular/forms' describe('UserSearchComponent', () => { - let component: UserSearchComponent; - let fixture: ComponentFixture; + let component: UserSearchComponent + let fixture: ComponentFixture let acMock beforeEach(async () => { - acMock = { - - } + acMock = {} await TestBed.configureTestingModule({ declarations: [UserSearchComponent], - providers: [ - { provide: AdminCommService, useValue: acMock } - ], + providers: [{ provide: AdminCommService, useValue: acMock }], imports: [ - MatAutocompleteModule, + MatAutocompleteModule, MatInputModule, FormsModule, - ReactiveFormsModule - ] - }) - .compileComponents(); - - fixture = TestBed.createComponent(UserSearchComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + ReactiveFormsModule, + ], + }).compileComponents() + + fixture = TestBed.createComponent(UserSearchComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/commonComponents/user-search/user-search.component.ts b/src/app/commonComponents/user-search/user-search.component.ts index 31c9db1..a5d95ec 100644 --- a/src/app/commonComponents/user-search/user-search.component.ts +++ b/src/app/commonComponents/user-search/user-search.component.ts @@ -1,47 +1,68 @@ -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'; +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; + _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()' + selector: 'app-user-search', + templateUrl: './user-search.component.html', + styleUrl: './user-search.component.scss', + providers: [ + { + provide: MatFormFieldControl, + useExisting: UserSearchComponent, }, - standalone: false + ], + host: { + '(blur)': '_onTouched()', + }, + standalone: false, }) -export class UserSearchComponent implements ControlValueAccessor, MatFormFieldControl, OnDestroy, DoCheck { +export class UserSearchComponent + implements + ControlValueAccessor, + MatFormFieldControl, + OnDestroy, + DoCheck +{ protected loading: boolean = false - control: FormControl = new FormControl(); + control: FormControl = new FormControl() protected list: UserSearchResult[] = [] private timeout?: NodeJS.Timeout private _onChange!: (_: UserSearchResult) => void private _onTouched!: any - static nextId = 0; + static nextId = 0 @Input() public get value(): UserSearchResult | null { - return this.control.value; + return this.control.value } public set value(value: UserSearchResult | null) { @@ -51,34 +72,36 @@ export class UserSearchComponent implements ControlValueAccessor, MatFormFieldCo touched = false - stateChanges = new Subject(); + stateChanges = new Subject() - @HostBinding() id: string = `app-user-search-${UserSearchComponent.nextId++}`; + @HostBinding() id: string = `app-user-search-${UserSearchComponent.nextId++}` - private _placeholder: string = ""; + private _placeholder: string = '' @Input() public get placeholder(): string { - return this._placeholder; + return this._placeholder } public set placeholder(value: string) { - this._placeholder = value; + this._placeholder = value this.stateChanges.next() } - focused: boolean = false; + focused: boolean = false onFocusIn(event: FocusEvent) { if (!this.focused) { - this.focused = true; - this.stateChanges.next(); + this.focused = true + this.stateChanges.next() } } onFocusOut(event: FocusEvent) { - if (!this._elementRef.nativeElement.contains(event.relatedTarget as Element)) { + if ( + !this._elementRef.nativeElement.contains(event.relatedTarget as Element) + ) { this.touched = true - this.focused = false; - this._onTouched(); - this.stateChanges.next(); + this.focused = false + this._onTouched() + this.stateChanges.next() } } get empty(): boolean { @@ -88,33 +111,35 @@ export class UserSearchComponent implements ControlValueAccessor, MatFormFieldCo get shouldLabelFloat(): boolean { return this.focused || !this.empty } - private _required: boolean = false; + private _required: boolean = false @Input() public get required(): boolean { - return this._required; + return this._required } public set required(value: BooleanInput) { - this._required = coerceBooleanProperty(value); + this._required = coerceBooleanProperty(value) this.stateChanges.next() } - private _disabled: boolean = false; + private _disabled: boolean = false @Input() public get disabled(): boolean { - return this._disabled; + return this._disabled } public set disabled(value: BooleanInput) { - this._disabled = coerceBooleanProperty(value); + 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; + 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')!; + const controlElement = this._elementRef.nativeElement.querySelector( + '.app-user-search-container' + )! controlElement.setAttribute('aria-describedby', ids.join(' ')) } onContainerClick(event: MouseEvent): void { @@ -131,10 +156,10 @@ export class UserSearchComponent implements ControlValueAccessor, MatFormFieldCo private _elementRef: ElementRef ) { if (this.ngControl != null) { - (this.ngControl as NgControl).valueAccessor = this + ;(this.ngControl as NgControl).valueAccessor = this } this.control.valueChanges.subscribe(() => { - if (typeof this.control.value == "object") return; + if (typeof this.control.value == 'object') return this.loading = true if (this.timeout) clearTimeout(this.timeout) this.timeout = setTimeout(() => { @@ -153,8 +178,10 @@ export class UserSearchComponent implements ControlValueAccessor, MatFormFieldCo private updateErrorState() { const parent = this._parentFormGroup || this._parentForm - const oldState = this.errorState; - const newState = (this.ngControl?.invalid || this.control.invalid) && (this.touched || parent.submitted); + const oldState = this.errorState + const newState = + (this.ngControl?.invalid || this.control.invalid) && + (this.touched || parent.submitted) if (oldState !== newState) { this.errorState = newState diff --git a/src/app/fd.da.ts b/src/app/fd.da.ts index 3d5cc9a..c9899fb 100644 --- a/src/app/fd.da.ts +++ b/src/app/fd.da.ts @@ -1,28 +1,33 @@ -import { Injectable } from "@angular/core"; -import { DateFilterFn, DateRange, MatDateRangeSelectionStrategy } from "@angular/material/datepicker"; -import { DateTime } from "luxon"; +import { Injectable } from '@angular/core' +import { + DateFilterFn, + DateRange, + MatDateRangeSelectionStrategy, +} from '@angular/material/datepicker' +import { DateTime } from 'luxon' @Injectable() export class FDSelection implements MatDateRangeSelectionStrategy { - selectionFinished(date: DateTime | null): DateRange { - return this._cr(date) - } - createPreview(activeDate: DateTime | null): DateRange { - return this._cr(activeDate) - } + selectionFinished(date: DateTime | null): DateRange { + return this._cr(date) + } + createPreview(activeDate: DateTime | null): DateRange { + return this._cr(activeDate) + } - private _cr(date: DateTime | null) { - if (date) { - const start = date.toUTC().startOf('week') - const end = date.toUTC().set({weekday: 5}).endOf('day') - return new DateRange(start, end) - } - return new DateRange(null, null) + private _cr(date: DateTime | null) { + if (date) { + const start = date.toUTC().startOf('week') + const end = date.toUTC().set({ weekday: 5 }).endOf('day') + return new DateRange(start, end) } - + return new DateRange(null, null) + } } -export const weekendFilter: DateFilterFn = (date: DateTime | null): boolean => { - const day = date?.weekday - return day !== 6 && day !== 7 - } \ No newline at end of file +export const weekendFilter: DateFilterFn = ( + date: DateTime | null +): boolean => { + const day = date?.weekday + return day !== 6 && day !== 7 +} diff --git a/src/app/label.directive.spec.ts b/src/app/label.directive.spec.ts index 32bf5a1..8910715 100644 --- a/src/app/label.directive.spec.ts +++ b/src/app/label.directive.spec.ts @@ -1,8 +1,8 @@ -import { LabelDirective } from './label.directive'; +import { LabelDirective } from './label.directive' describe('LabelDirective', () => { it('should create an instance', () => { - const directive = new LabelDirective(); - expect(directive).toBeTruthy(); - }); -}); + const directive = new LabelDirective() + expect(directive).toBeTruthy() + }) +}) diff --git a/src/app/label.directive.ts b/src/app/label.directive.ts index b29aca1..44ef48a 100644 --- a/src/app/label.directive.ts +++ b/src/app/label.directive.ts @@ -1,16 +1,16 @@ -import { Directive, HostBinding, Input, Optional } from '@angular/core'; -import { ControlContainer } from '@angular/forms'; +import { Directive, HostBinding, Input, Optional } from '@angular/core' +import { ControlContainer } from '@angular/forms' @Directive({ - selector: 'span[control]', - standalone: false + selector: 'span[control]', + standalone: false, }) export class LabelDirective { - @Input() control: string = "" - constructor(@Optional() private parent?: ControlContainer) { } + @Input() control: string = '' + constructor(@Optional() private parent?: ControlContainer) {} @HostBinding('textContent') get controlValue() { - return this.parent ? this.parent.control?.get(this.control)?.value : "" + return this.parent ? this.parent.control?.get(this.control)?.value : '' } } diff --git a/src/app/login/login.component.scss b/src/app/login/login.component.scss index c210190..c25c2a2 100644 --- a/src/app/login/login.component.scss +++ b/src/app/login/login.component.scss @@ -1,15 +1,15 @@ form { - display: flex; - flex-direction: column; + display: flex; + flex-direction: column; } mat-card { - margin: 15px; - width: fit-content; + margin: 15px; + width: fit-content; } :host { - width: 100%; - height: 100%; - display: grid; - align-items: center; - justify-items: center; -} \ No newline at end of file + width: 100%; + height: 100%; + display: grid; + align-items: center; + justify-items: center; +} diff --git a/src/app/login/login.component.spec.ts b/src/app/login/login.component.spec.ts index eca2777..a42d129 100644 --- a/src/app/login/login.component.spec.ts +++ b/src/app/login/login.component.spec.ts @@ -1,38 +1,41 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ComponentFixture, TestBed } from '@angular/core/testing' -import { LoginComponent } from './login.component'; -import { AuthClient } from '../services/auth.client'; -import { of } from 'rxjs'; -import { MatCardModule } from '@angular/material/card'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatInputModule } from '@angular/material/input'; -import { ReactiveFormsModule } from '@angular/forms'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { LoginComponent } from './login.component' +import { AuthClient } from '../services/auth.client' +import { of } from 'rxjs' +import { MatCardModule } from '@angular/material/card' +import { MatFormFieldModule } from '@angular/material/form-field' +import { MatInputModule } from '@angular/material/input' +import { ReactiveFormsModule } from '@angular/forms' +import { BrowserAnimationsModule } from '@angular/platform-browser/animations' describe('LoginComponent', () => { - let component: LoginComponent; - let fixture: ComponentFixture; + let component: LoginComponent + let fixture: ComponentFixture let authMock: AuthClient beforeEach(async () => { - authMock = jasmine.createSpyObj("AuthClient", { - login: of() + authMock = jasmine.createSpyObj('AuthClient', { + login: of(), }) await TestBed.configureTestingModule({ - declarations: [ LoginComponent ], - providers: [ - {provide: AuthClient, useValue: authMock} + declarations: [LoginComponent], + providers: [{ provide: AuthClient, useValue: authMock }], + imports: [ + MatCardModule, + MatFormFieldModule, + MatInputModule, + ReactiveFormsModule, + BrowserAnimationsModule, ], - imports: [MatCardModule, MatFormFieldModule, MatInputModule, ReactiveFormsModule, BrowserAnimationsModule] - }) - .compileComponents(); + }).compileComponents() - fixture = TestBed.createComponent(LoginComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); + fixture = TestBed.createComponent(LoginComponent) + component = fixture.componentInstance + fixture.detectChanges() + }) it('should create', () => { - expect(component).toBeTruthy(); - }); -}); + expect(component).toBeTruthy() + }) +}) diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index fc905aa..cc68e5d 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -1,23 +1,28 @@ -import { Component, OnInit } from '@angular/core'; -import { FormBuilder, FormGroup } from '@angular/forms'; -import { AuthClient } from '../services/auth.client'; -import { Router } from '@angular/router'; -import { catchError, throwError } from 'rxjs'; -import { LocalStorageService } from '../services/local-storage.service'; +import { Component, OnInit } from '@angular/core' +import { FormBuilder, FormGroup } from '@angular/forms' +import { AuthClient } from '../services/auth.client' +import { Router } from '@angular/router' +import { catchError, throwError } from 'rxjs' +import { LocalStorageService } from '../services/local-storage.service' @Component({ - selector: 'app-login', - templateUrl: './login.component.html', - styleUrls: ['./login.component.scss'], - standalone: false + selector: 'app-login', + templateUrl: './login.component.html', + styleUrls: ['./login.component.scss'], + standalone: false, }) export class LoginComponent implements OnInit { - protected error: string | null = null; - form: FormGroup; - constructor (private ac: AuthClient, private fb: FormBuilder, private router: Router, private ls: LocalStorageService) { + protected error: string | null = null + form: FormGroup + constructor( + private ac: AuthClient, + private fb: FormBuilder, + private router: Router, + private ls: LocalStorageService + ) { this.form = this.fb.group({ uname: [''], - pass: [''] + pass: [''], }) } @@ -29,15 +34,20 @@ export class LoginComponent implements OnInit { submit() { const val = this.form.value - this.ac.login(val.uname, val.pass).pipe(catchError((err,caught)=>{ - this.error = err.error.message - return throwError(() => new Error(err.message)) - })).subscribe((data) => { - this.ls.loggedIn = true - this.router.navigateByUrl(this.ac.redirect || 'app') - if (data.admin) { - this.ls.admin = data.admin - } - }) + this.ac + .login(val.uname, val.pass) + .pipe( + catchError((err, caught) => { + this.error = err.error.message + return throwError(() => new Error(err.message)) + }) + ) + .subscribe(data => { + this.ls.loggedIn = true + this.router.navigateByUrl(this.ac.redirect || 'app') + if (data.admin) { + this.ls.admin = data.admin + } + }) } } diff --git a/src/app/services/app-update.service.spec.ts b/src/app/services/app-update.service.spec.ts index b7f03a0..abe0c92 100644 --- a/src/app/services/app-update.service.spec.ts +++ b/src/app/services/app-update.service.spec.ts @@ -1,16 +1,16 @@ -import { TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing' -import { AppUpdateService } from './app-update.service'; +import { AppUpdateService } from './app-update.service' describe('AppUpdateService', () => { - let service: AppUpdateService; + let service: AppUpdateService beforeEach(() => { - TestBed.configureTestingModule({}); - service = TestBed.inject(AppUpdateService); - }); + TestBed.configureTestingModule({}) + service = TestBed.inject(AppUpdateService) + }) xit('should be created', () => { - expect(service).toBeTruthy(); - }); -}); + expect(service).toBeTruthy() + }) +}) diff --git a/src/app/services/app-update.service.ts b/src/app/services/app-update.service.ts index 7384f00..8d7061d 100644 --- a/src/app/services/app-update.service.ts +++ b/src/app/services/app-update.service.ts @@ -1,50 +1,74 @@ -import { ApplicationRef, Injectable, OnInit } from '@angular/core'; -import { MatSnackBar } from '@angular/material/snack-bar'; -import { SwUpdate } from '@angular/service-worker'; -import { catchError, concat, first, from, interval, tap, throwError } from 'rxjs'; +import { ApplicationRef, Injectable, OnInit } from '@angular/core' +import { MatSnackBar } from '@angular/material/snack-bar' +import { SwUpdate } from '@angular/service-worker' +import { + catchError, + concat, + first, + from, + interval, + tap, + throwError, +} from 'rxjs' @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class AppUpdateService implements OnInit { - - constructor(readonly appRef: ApplicationRef, readonly update: SwUpdate, readonly sb: MatSnackBar) { - this.update.versionUpdates.subscribe((evt) => { + 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; + console.log(`Downloading ${evt.version.hash}`) + break case 'VERSION_READY': - console.log(`Current: ${evt.currentVersion.hash}, new: ${evt.latestVersion.hash}`); - break; + 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; + console.error(`Failed to install ${evt.version.hash}: ${evt.error}`) + break } }) } - + ngOnInit(): void { - const appIsStable = this.appRef.isStable.pipe(first(isStable => isStable === true)) + const appIsStable = this.appRef.isStable.pipe( + first(isStable => isStable === true) + ) const everyday = interval(1000 * 60 * 60 * 24) const stableDay = concat(appIsStable, everyday) - + stableDay.subscribe(this.checkForUpdate) } - + checkForUpdate() { let ov = from(this.update.checkForUpdate()) - return ov.pipe(catchError((err) => { - console.error('Failed to check for updates:', err); - return throwError(() => err) - })).pipe(tap((val)=>{ - if (val) this.promptUser() - })) + return ov + .pipe( + catchError(err => { + console.error('Failed to check for updates:', err) + return throwError(() => err) + }) + ) + .pipe( + tap(val => { + if (val) this.promptUser() + }) + ) } promptUser() { - this.sb.open("Dostępna jest aktualizacja", "Restart").onAction().subscribe(() => { - document.location.reload() - }) + this.sb + .open('Dostępna jest aktualizacja', 'Restart') + .onAction() + .subscribe(() => { + document.location.reload() + }) } } diff --git a/src/app/services/auth.client.spec.ts b/src/app/services/auth.client.spec.ts index 44415b5..c46ecc9 100644 --- a/src/app/services/auth.client.spec.ts +++ b/src/app/services/auth.client.spec.ts @@ -1,25 +1,35 @@ -import { TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing' -import { AuthClient } from './auth.client'; -import { HttpClient, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; -import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing' +import { AuthClient } from './auth.client' +import { + HttpClient, + provideHttpClient, + withInterceptorsFromDi, +} from '@angular/common/http' +import { + HttpTestingController, + provideHttpClientTesting, +} from '@angular/common/http/testing' describe('AuthService', () => { - let service: AuthClient; + let service: AuthClient let httpClient: HttpClient let httpTestingController: HttpTestingController beforeEach(() => { TestBed.configureTestingModule({ - imports: [], - providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()] -}); - service = TestBed.inject(AuthClient); - httpClient = TestBed.inject(HttpClient); - httpTestingController = TestBed.inject(HttpTestingController); - }); + imports: [], + providers: [ + provideHttpClient(withInterceptorsFromDi()), + provideHttpClientTesting(), + ], + }) + service = TestBed.inject(AuthClient) + httpClient = TestBed.inject(HttpClient) + httpTestingController = TestBed.inject(HttpTestingController) + }) it('should be created', () => { - expect(service).toBeTruthy(); - }); -}); + expect(service).toBeTruthy() + }) +}) diff --git a/src/app/services/auth.client.ts b/src/app/services/auth.client.ts index 156c851..9307261 100644 --- a/src/app/services/auth.client.ts +++ b/src/app/services/auth.client.ts @@ -1,77 +1,104 @@ -import { HttpClient } from '@angular/common/http'; -import { Injectable } from '@angular/core'; -import { Router } from '@angular/router'; -import { catchError, EMPTY, tap, throwError } from 'rxjs'; -import { environment } from 'src/environments/environment'; -import { LocalStorageService } from './local-storage.service'; -import { Status } from '../types/status'; +import { HttpClient } from '@angular/common/http' +import { Injectable } from '@angular/core' +import { Router } from '@angular/router' +import { catchError, EMPTY, tap, throwError } from 'rxjs' +import { environment } from 'src/environments/environment' +import { LocalStorageService } from './local-storage.service' +import { Status } from '../types/status' @Injectable({ - providedIn: 'root' + providedIn: 'root', }) 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 = ""; + private _redirect: string = '' public get redirect(): string { - return this._redirect; + return this._redirect } public set redirect(value: string) { - this._redirect = value; + this._redirect = value this.putRedirect(value).subscribe() } public login(uname: string, pass: string) { - return this.http.post(environment.apiEndpoint + '/auth/login', { - username: uname, - password: pass - }, {withCredentials: true}).pipe(tap((v) => { - if (v.redirect) this._redirect = v.redirect - })) + return this.http + .post( + environment.apiEndpoint + '/auth/login', + { + username: uname, + password: pass, + }, + { withCredentials: true } + ) + .pipe( + tap(v => { + if (v.redirect) this._redirect = v.redirect + }) + ) } public logout() { - return this.http.delete(environment.apiEndpoint+"/auth/logout", {withCredentials: true}) - } - - public check() { - 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) { - this.ls.logOut() - this.router.navigateByUrl("/login") - return EMPTY - } - return throwError(() => new Error(err.message)) - })).subscribe((data)=>{ - this.ls.admin = data.admin - if (this.ls.capFlag != data.features) { - this.ls.capFlag = data.features - document.location.reload() - } - this.ls.room = data.room - this.ls.vapid = data.vapid - if (data.menu.defaultItems) { - this.ls.defaultItems = data.menu.defaultItems - } + return this.http.delete(environment.apiEndpoint + '/auth/logout', { + withCredentials: true, }) } - public chpass(oldpass:string,newpass:string) { - return this.http.post(environment.apiEndpoint + '/auth/chpass', {"oldPass": oldpass, "newPass": newpass}, {withCredentials: true, responseType: "text"}) + public check() { + 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) { + this.ls.logOut() + this.router.navigateByUrl('/login') + return EMPTY + } + return throwError(() => new Error(err.message)) + }) + ) + .subscribe(data => { + this.ls.admin = data.admin + if (this.ls.capFlag != data.features) { + this.ls.capFlag = data.features + document.location.reload() + } + this.ls.room = data.room + this.ls.vapid = data.vapid + if (data.menu.defaultItems) { + this.ls.defaultItems = data.menu.defaultItems + } + }) + } + + public chpass(oldpass: string, newpass: string) { + return this.http.post( + environment.apiEndpoint + '/auth/chpass', + { oldPass: oldpass, newPass: newpass }, + { withCredentials: true, responseType: 'text' } + ) } private putRedirect(redirect: string) { - return this.http.put(environment.apiEndpoint + '/auth/redirect', {redirect: redirect}, {withCredentials: true}) + return this.http.put( + environment.apiEndpoint + '/auth/redirect', + { redirect: redirect }, + { withCredentials: true } + ) } } diff --git a/src/app/services/local-storage.service.spec.ts b/src/app/services/local-storage.service.spec.ts index ba1dbd4..2517e92 100644 --- a/src/app/services/local-storage.service.spec.ts +++ b/src/app/services/local-storage.service.spec.ts @@ -1,16 +1,16 @@ -import { TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing' -import { LocalStorageService } from './local-storage.service'; +import { LocalStorageService } from './local-storage.service' describe('LocalStorageService', () => { - let service: LocalStorageService; + let service: LocalStorageService beforeEach(() => { - TestBed.configureTestingModule({}); - service = TestBed.inject(LocalStorageService); - }); + TestBed.configureTestingModule({}) + service = TestBed.inject(LocalStorageService) + }) it('should be created', () => { - expect(service).toBeTruthy(); - }); -}); + expect(service).toBeTruthy() + }) +}) diff --git a/src/app/services/local-storage.service.ts b/src/app/services/local-storage.service.ts index 5ccebf0..7968466 100644 --- a/src/app/services/local-storage.service.ts +++ b/src/app/services/local-storage.service.ts @@ -1,15 +1,17 @@ -import { Injectable } from '@angular/core'; -import { News } from '../types/news'; +import { Injectable } from '@angular/core' +import { News } from '../types/news' @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class LocalStorageService { - - constructor() { } + constructor() {} permChecker(neededPermNumber: number) { - return ((Number.parseInt(localStorage.getItem("admin")!) & neededPermNumber) == neededPermNumber) + return ( + (Number.parseInt(localStorage.getItem('admin')!) & neededPermNumber) == + neededPermNumber + ) } logOut() { @@ -46,7 +48,7 @@ export class LocalStorageService { } get loggedIn() { - if (localStorage.getItem("loggedIn")) { + if (localStorage.getItem('loggedIn')) { return true } return @@ -54,35 +56,35 @@ export class LocalStorageService { set loggedIn(is: true | undefined) { if (is) { - localStorage.setItem("loggedIn", "true") + localStorage.setItem('loggedIn', 'true') } else { - localStorage.removeItem("loggedIn") + localStorage.removeItem('loggedIn') } } set admin(newInt: number | undefined) { if (newInt) { - localStorage.setItem("admin", newInt.toString()) + localStorage.setItem('admin', newInt.toString()) } else { localStorage.removeItem('admin') } } get admin() { - var lsa = localStorage.getItem("admin") + var lsa = localStorage.getItem('admin') return lsa ? Number.parseInt(lsa) : undefined } set amgreg(toggle: boolean) { if (toggle) { - localStorage.setItem('amgrb', "true") + localStorage.setItem('amgrb', 'true') } else { localStorage.removeItem('amgrb') } } get amgreg() { - if (localStorage.getItem("amgrb") == "true") { + if (localStorage.getItem('amgrb') == 'true') { return true } return false @@ -106,40 +108,40 @@ export class LocalStorageService { } public capCheck(perm: number) { - return ((this.capFlag! & perm) == perm) + return (this.capFlag! & perm) == perm } - public get newsCheck(): { hash: string; count: number; } { - let nc = localStorage.getItem("newsCheck") + public get newsCheck(): { hash: string; count: number } { + let nc = localStorage.getItem('newsCheck') if (nc) { return JSON.parse(nc) } else { - return {hash: "", count: 0} + return { hash: '', count: 0 } } } - public set newsCheck(value: { hash: string; count: number; }) { - localStorage.setItem("newsCheck", JSON.stringify(value)) + public set newsCheck(value: { hash: string; count: number }) { + localStorage.setItem('newsCheck', JSON.stringify(value)) } - public get defaultItems(): {sn: string[]; kol: string[];} { + public get defaultItems(): { sn: string[]; kol: string[] } { let di = localStorage.getItem('defaultItems') if (di) { return JSON.parse(di) } else { - return {sn: [], kol: []} + return { sn: [], kol: [] } } } - public set defaultItems(value: {sn: string[]; kol: string[];}) { + public set defaultItems(value: { sn: string[]; kol: string[] }) { localStorage.setItem('defaultItems', JSON.stringify(value)) } - public newsflag: number | false = false; + public newsflag: number | false = false public get vapid(): string { return localStorage.getItem('vapid')! } public set vapid(value: string) { - localStorage.setItem("vapid", value) + localStorage.setItem('vapid', value) } } diff --git a/src/app/services/updates.service.spec.ts b/src/app/services/updates.service.spec.ts index 472e6c9..f40b8a0 100644 --- a/src/app/services/updates.service.spec.ts +++ b/src/app/services/updates.service.spec.ts @@ -1,25 +1,35 @@ -import { TestBed } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing' -import { UpdatesService } from './updates.service'; -import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing'; -import { HttpClient, provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; +import { UpdatesService } from './updates.service' +import { + HttpTestingController, + provideHttpClientTesting, +} from '@angular/common/http/testing' +import { + HttpClient, + provideHttpClient, + withInterceptorsFromDi, +} from '@angular/common/http' describe('UpdatesService', () => { - let service: UpdatesService; + let service: UpdatesService let httpClient: HttpClient let httpTestingController: HttpTestingController beforeEach(() => { TestBed.configureTestingModule({ - imports: [], - providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()] -}); - service = TestBed.inject(UpdatesService); - httpClient = TestBed.inject(HttpClient); - httpTestingController = TestBed.inject(HttpTestingController); - }); + imports: [], + providers: [ + provideHttpClient(withInterceptorsFromDi()), + provideHttpClientTesting(), + ], + }) + service = TestBed.inject(UpdatesService) + httpClient = TestBed.inject(HttpClient) + httpTestingController = TestBed.inject(HttpTestingController) + }) it('should be created', () => { - expect(service).toBeTruthy(); - }); -}); + expect(service).toBeTruthy() + }) +}) diff --git a/src/app/services/updates.service.ts b/src/app/services/updates.service.ts index 1474994..aebb619 100644 --- a/src/app/services/updates.service.ts +++ b/src/app/services/updates.service.ts @@ -1,66 +1,98 @@ -import { Injectable } from '@angular/core'; +import { Injectable } from '@angular/core' import { HttpClient } from '@angular/common/http' -import { Menu } from '../types/menu'; -import { environment } from 'src/environments/environment'; -import { News } from '../types/news'; -import { UKey } from '../types/key'; -import { CleanNote } from '../types/clean-note'; -import { Status } from '../types/status'; -import { DateTime } from 'luxon'; +import { Menu } from '../types/menu' +import { environment } from 'src/environments/environment' +import { News } from '../types/news' +import { UKey } from '../types/key' +import { CleanNote } from '../types/clean-note' +import { Status } from '../types/status' +import { DateTime } from 'luxon' @Injectable({ - providedIn: 'root' + providedIn: 'root', }) export class UpdatesService { - - constructor(private http:HttpClient) { } + constructor(private http: HttpClient) {} getNews() { const headers = { 'Content-Type': 'application/json', } - return this.http.get(environment.apiEndpoint+"/app/news", {headers: headers, withCredentials: true}) + return this.http.get(environment.apiEndpoint + '/app/news', { + headers: headers, + withCredentials: true, + }) } newsCheck() { - return this.http.get<{ hash: string; count: number; }>(environment.apiEndpoint+`/app/news/check`, {withCredentials: true}) + return this.http.get<{ hash: string; count: number }>( + environment.apiEndpoint + `/app/news/check`, + { withCredentials: true } + ) } getMenu(dom: string) { const headers = { 'Content-Type': 'application/json', } - return this.http.get(environment.apiEndpoint+`/app/menu/${dom}`, {headers: headers, withCredentials: true}) + return this.http.get(environment.apiEndpoint + `/app/menu/${dom}`, { + headers: headers, + withCredentials: true, + }) } - postVote(date: string, type: "ob" | "kol", vote: "-" | "+" | "n") { - return this.http.post(environment.apiEndpoint+`/app/menu/${date}`, { - doc: DateTime.now(), - tom: type, - vote: vote - }, {withCredentials: true}) + postVote(date: string, type: 'ob' | 'kol', vote: '-' | '+' | 'n') { + return this.http.post( + environment.apiEndpoint + `/app/menu/${date}`, + { + doc: DateTime.now(), + tom: type, + vote: vote, + }, + { withCredentials: true } + ) } postNotif(nd: object) { const headers = { 'Content-Type': 'application/json', } - this.http.post(environment.apiEndpoint+`/notif`, nd, {headers: headers, withCredentials: true}).subscribe() + this.http + .post(environment.apiEndpoint + `/notif`, nd, { + headers: headers, + withCredentials: true, + }) + .subscribe() } getKeys() { - return this.http.get(environment.apiEndpoint+`/app/keys`, {withCredentials: true}) + return this.http.get(environment.apiEndpoint + `/app/keys`, { + withCredentials: true, + }) } getClean(date: string) { - return this.http.get<{grade: number, notes: CleanNote[], tips: string}>(environment.apiEndpoint+`/app/clean/${date}`, {withCredentials: true}) + return this.http.get<{ grade: number; notes: CleanNote[]; tips: string }>( + environment.apiEndpoint + `/app/clean/${date}`, + { withCredentials: true } + ) } getNotifCheck() { - return this.http.get<{_id: string, message: {title: string, body: string}, sentDate: string}[]>(environment.apiEndpoint+`/app/notif/check`, {withCredentials: true}) + return this.http.get< + { + _id: string + message: { title: string; body: string } + sentDate: string + }[] + >(environment.apiEndpoint + `/app/notif/check`, { withCredentials: true }) } postInfoAck(id: string) { - return this.http.post(environment.apiEndpoint+`/app/notif/${id}/ack`, undefined, {withCredentials: true}) + return this.http.post( + environment.apiEndpoint + `/app/notif/${id}/ack`, + undefined, + { withCredentials: true } + ) } } diff --git a/src/app/types/clean-note.ts b/src/app/types/clean-note.ts index 8b1838c..bfadb70 100644 --- a/src/app/types/clean-note.ts +++ b/src/app/types/clean-note.ts @@ -1,4 +1,4 @@ export interface CleanNote { - label: string; - weight: number; -} \ No newline at end of file + label: string + weight: number +} diff --git a/src/app/types/group.ts b/src/app/types/group.ts index beb298d..a52c79c 100644 --- a/src/app/types/group.ts +++ b/src/app/types/group.ts @@ -1,4 +1,4 @@ export interface Group { - _id: string; - name: string; + _id: string + name: string } diff --git a/src/app/types/key.ts b/src/app/types/key.ts index 6fdc6d2..6cb6e86 100644 --- a/src/app/types/key.ts +++ b/src/app/types/key.ts @@ -1,15 +1,15 @@ -import { DateTime } from "luxon"; +import { DateTime } from 'luxon' interface UKey { - room: string; - taken: boolean; + room: string + taken: boolean } interface AKey { - room: string; - whom?: {_id: string, uname: string, room: string}; - borrow: DateTime; - tb?: DateTime; + room: string + whom?: { _id: string; uname: string; room: string } + borrow: DateTime + tb?: DateTime } -export { UKey, AKey } \ No newline at end of file +export { UKey, AKey } diff --git a/src/app/types/link.ts b/src/app/types/link.ts index 1d5e151..ed3de18 100644 --- a/src/app/types/link.ts +++ b/src/app/types/link.ts @@ -1,6 +1,6 @@ export interface Link { - title: string; - href: string; - icon?: string; - enabled: boolean; + title: string + href: string + icon?: string + enabled: boolean } diff --git a/src/app/types/menu.ts b/src/app/types/menu.ts index c44aef0..115cb0b 100644 --- a/src/app/types/menu.ts +++ b/src/app/types/menu.ts @@ -1,23 +1,23 @@ -import { DateTime } from "luxon"; +import { DateTime } from 'luxon' export interface Menu { - _id: string; - day: DateTime; + _id: string + day: DateTime sn: { - fancy: string[]; - second: string; - }; + fancy: string[] + second: string + } ob: { - soup: string; - vege: string; - meal: string; - condiments: string[]; - drink: string; - other: string[]; - }; - kol?: string; - kolv?: "+" | "-" | "n"; - obv?: "+" | "-" | "n"; - stat?: {kol?: string, ob?: string}; - dayTitle?: string; + soup: string + vege: string + meal: string + condiments: string[] + drink: string + other: string[] + } + kol?: string + kolv?: '+' | '-' | 'n' + obv?: '+' | '-' | 'n' + stat?: { kol?: string; ob?: string } + dayTitle?: string } diff --git a/src/app/types/news.ts b/src/app/types/news.ts index c27399d..1638f11 100644 --- a/src/app/types/news.ts +++ b/src/app/types/news.ts @@ -1,8 +1,8 @@ export interface News { - _id: string; - title: string; - content: string - date: string - visible?: boolean; - pinned?: boolean + _id: string + title: string + content: string + date: string + visible?: boolean + pinned?: boolean } diff --git a/src/app/types/notification.ts b/src/app/types/notification.ts index 62c8524..e2405e5 100644 --- a/src/app/types/notification.ts +++ b/src/app/types/notification.ts @@ -1,9 +1,9 @@ export interface Notification { - body: string; - title: string; - recp: { - uid: string | null; - room: string | null; - type: "all" | "room" | "uname" - } + body: string + title: string + recp: { + uid: string | null + room: string | null + type: 'all' | 'room' | 'uname' + } } diff --git a/src/app/types/status.ts b/src/app/types/status.ts index faf2ff4..8a563fa 100644 --- a/src/app/types/status.ts +++ b/src/app/types/status.ts @@ -1,4 +1,4 @@ export interface Status { - status: number, - message?: string + status: number + message?: string } diff --git a/src/app/types/user.ts b/src/app/types/user.ts index 00c954d..ebecf77 100644 --- a/src/app/types/user.ts +++ b/src/app/types/user.ts @@ -1,15 +1,15 @@ -import { DateTime } from "luxon"; +import { DateTime } from 'luxon' export default interface User { - _id: string; - uname: string; - pass: string; - room?: string; - admin?: number; - locked?: boolean; - fname?: string; - surname?: string; - groups: string[]; - regDate: DateTime; - defaultPage?: string; -} \ No newline at end of file + _id: string + uname: string + pass: string + room?: string + admin?: number + locked?: boolean + fname?: string + surname?: string + groups: string[] + regDate: DateTime + defaultPage?: string +} diff --git a/src/environments/environment.development.ts b/src/environments/environment.development.ts index 9344c2d..1054337 100644 --- a/src/environments/environment.development.ts +++ b/src/environments/environment.development.ts @@ -1,5 +1,5 @@ export const environment = { - apiEndpoint: `http://${window.location.hostname}:12230`, - version: "testing", - production: false -}; + apiEndpoint: `http://${window.location.hostname}:12230`, + version: 'testing', + production: false, +} diff --git a/src/environments/environment.swdev.ts b/src/environments/environment.swdev.ts index 35fd6cc..0c9d072 100644 --- a/src/environments/environment.swdev.ts +++ b/src/environments/environment.swdev.ts @@ -1,5 +1,5 @@ export const environment = { - apiEndpoint: `http://localhost:12230`, - version: "testing (swDev)", - production: true -}; + apiEndpoint: `http://localhost:12230`, + version: 'testing (swDev)', + production: true, +} diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 49fc1c4..4faf420 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -1,5 +1,5 @@ export const environment = { - apiEndpoint: `${window.location.origin}/api`, - version: "v1.2.0", - production: true -}; + apiEndpoint: `${window.location.origin}/api`, + version: 'v1.2.0', + production: true, +} diff --git a/src/main.ts b/src/main.ts index 679eb4b..56c38f2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,13 +1,13 @@ -import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; +import { platformBrowser } from '@angular/platform-browser' -import { AppModule } from './app/app.module'; -import { environment } from './environments/environment'; +import { AppModule } from './app/app.module' +import { environment } from './environments/environment' - -platformBrowserDynamic().bootstrapModule(AppModule) +platformBrowser() + .bootstrapModule(AppModule) .then(() => { if ('serviceWorker' in navigator && environment.production) { navigator.serviceWorker.register('./ngsw-worker.js') } }) - .catch(err => console.error(err)); + .catch(err => console.error(err)) diff --git a/src/styles.scss b/src/styles.scss index 672d1bf..23bc132 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -1,7 +1,6 @@ - // Custom Theming for Angular Material // For more information: https://material.angular.io/guide/theming -@use '@angular/material' as mat; +@use "@angular/material" as mat; // Plus imports for other components in your app. // Include the common styles for Angular Material. We include this here so that you only @@ -31,8 +30,8 @@ $ipwa-palette: ( 600: white, 700: white, 800: white, - 900: white - ) + 900: white, + ), ); $accent-palette: ( @@ -56,8 +55,8 @@ $accent-palette: ( 600: white, 700: white, 800: white, - 900: white - ) + 900: white, + ), ); // Define the palettes for your theme using the Material Design palettes available in palette.scss @@ -71,22 +70,26 @@ $ipwa-warn: mat.m2-define-palette(mat.$m2-red-palette); // Create the theme object. A theme consists of configurations for individual // theming systems such as "color" or "typography". -$ipwa-theme: mat.m2-define-light-theme(( - color: ( - primary: $ipwa-primary, - accent: $ipwa-accent, - warn: $ipwa-warn, +$ipwa-theme: mat.m2-define-light-theme( + ( + color: ( + primary: $ipwa-primary, + accent: $ipwa-accent, + warn: $ipwa-warn, + ), ) -)); +); -$ipwa-dark: mat.m2-define-dark-theme(( - color: ( - primary: $ipwa-primary, - accent: $ipwa-accent, - warn: $ipwa-warn, - ), - density: 0 -)); +$ipwa-dark: mat.m2-define-dark-theme( + ( + color: ( + primary: $ipwa-primary, + accent: $ipwa-accent, + warn: $ipwa-warn, + ), + density: 0, + ) +); // Include theme styles for core and each component used in your app. // Alternatively, you can import and @include the theme mixins for each component @@ -97,8 +100,9 @@ $ipwa-dark: mat.m2-define-dark-theme(( } /* You can add global styles to this file, and also import other style files */ -html, body { - height: 100%; +html, +body { + height: 100%; overscroll-behavior-y: contain; } @@ -109,9 +113,9 @@ body { @media (prefers-color-scheme: dark) { :link { - color: rgb(114, 192, 255) + color: rgb(114, 192, 255); } :visited { - color: rgb(114, 114, 255) + color: rgb(114, 114, 255); } -} \ No newline at end of file +}