feat: Added file formatting

This commit is contained in:
2025-06-11 11:56:39 +02:00
parent 772fc52cf6
commit a25a90c0d7
164 changed files with 4163 additions and 3242 deletions

8
.prettierignore Normal file
View File

@@ -0,0 +1,8 @@
angular.json
compose.yml
*.md
tsconfig*.json
*.html
.vscode
package*.json
ngsw-config.json

6
.prettierrc Normal file
View File

@@ -0,0 +1,6 @@
{
"arrowParens": "avoid",
"semi": false,
"trailingComma": "es5",
"bracketSpacing": true
}

17
package-lock.json generated
View File

@@ -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",

View File

@@ -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"
}
}

View File

@@ -1,34 +1,32 @@
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<AccountMgmtComponent>;
let component: AccountMgmtComponent
let fixture: ComponentFixture<AccountMgmtComponent>
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,
@@ -38,15 +36,15 @@ describe('AccountMgmtComponent', () => {
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()
})
})

View File

@@ -1,37 +1,45 @@
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
standalone: false,
})
export class AccountMgmtComponent implements OnInit, AfterViewInit {
protected groups: Group[] = []
users: MatTableDataSource<Omit<User, "pass">>
users: MatTableDataSource<Omit<User, 'pass'>>
loading = false
@ViewChild(MatPaginator) paginator!: MatPaginator
constructor(readonly ac:AdminCommService, private dialog: MatDialog, private sb: MatSnackBar, protected readonly ls: LocalStorageService) {
this.users = new MatTableDataSource<Omit<User, "pass">>();
this.users.filterPredicate = (data: Record<string, any>, filter: string): boolean => {
const dataStr = Object.keys(data).reduce((curr: string, key: string) => {
if (["_id", "admin", "groups", "__v", "locked"].find(v => v == key)) {
constructor(
readonly ac: AdminCommService,
private dialog: MatDialog,
private sb: MatSnackBar,
protected readonly ls: LocalStorageService
) {
this.users = new MatTableDataSource<Omit<User, 'pass'>>()
this.users.filterPredicate = (
data: Record<string, any>,
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()
}, '')
.toLowerCase()
const filternew = filter.trim().toLowerCase()
return dataStr.indexOf(filternew) != -1
}
@@ -43,7 +51,7 @@ export class AccountMgmtComponent implements OnInit, AfterViewInit {
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,7 +64,16 @@ export class AccountMgmtComponent implements OnInit, AfterViewInit {
}
openUserCard(id?: string) {
this.dialog.open<UserEditComponent, UserEditComponent.InputData, UserEditComponent.ReturnData>(UserEditComponent, {data: {id: id, type: id ? "edit" : "new", groups: this.groups}}).afterClosed().subscribe(r => {
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()
})
}

View File

@@ -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<UserDeleteComponent>;
let component: UserDeleteComponent
let fixture: ComponentFixture<UserDeleteComponent>
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()
})
})

View File

@@ -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
standalone: false,
})
export class UserDeleteComponent {
}
export class UserDeleteComponent {}

View File

@@ -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<UserEditComponent>;
let component: UserEditComponent
let fixture: ComponentFixture<UserEditComponent>
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()
})
})

View File

@@ -1,17 +1,21 @@
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
}
@@ -19,24 +23,24 @@ export namespace UserEditComponent {
selector: 'app-user-edit',
templateUrl: './user-edit.component.html',
styleUrls: ['./user-edit.component.scss'],
standalone: false
standalone: false,
})
export class UserEditComponent {
lockout = false;
locked = false;
loading = false;
lockout = false
locked = false
loading = false
form: FormGroup = new FormGroup({
fname: new FormControl<string>(""),
surname: new FormControl<string>(""),
room: new FormControl<string>(""),
uname: new FormControl<string>(""),
fname: new FormControl<string>(''),
surname: new FormControl<string>(''),
room: new FormControl<string>(''),
uname: new FormControl<string>(''),
groups: new FormControl<Array<string>>([]),
flags: new FormControl<Array<number>>([]),
})
groups: Group[]
id?: string
regDate?: DateTime;
constructor (
regDate?: DateTime
constructor(
public dialogRef: MatDialogRef<UserEditComponent>,
@Inject(MAT_DIALOG_DATA) public data: UserEditComponent.InputData,
readonly ls: LocalStorageService,
@@ -45,9 +49,9 @@ export class UserEditComponent {
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<number> = []
if (r.admin) {
@@ -62,41 +66,55 @@ 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 (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.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.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)=> {
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.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.sb.open('Wystąpił błąd. Skontaktuj się z obsługą programu.')
this.loading = false
}
})
@@ -105,15 +123,20 @@ export class UserEditComponent {
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) => {
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.sb.open('Wystąpił błąd. Skontaktuj się z obsługą programu.')
this.loading = false
}
})
@@ -127,26 +150,33 @@ 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 => {
this.dialog
.open(UserDeleteComponent)
.afterClosed()
.subscribe(reply => {
if (reply) {
this.acu.accs.deleteAcc(this.id!).subscribe((res) => {
this.acu.accs.deleteAcc(this.id!).subscribe(res => {
if (res.status == 200) {
this.sb.open("Użytkownik został usunięty.", undefined, {duration: 2500})
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.sb.open('Wystąpił błąd. Skontaktuj się z obsługą programu.')
console.error(res)
}
})
}
@@ -155,11 +185,16 @@ export class UserEditComponent {
protected resetPass() {
this.loading = true
this.dialog.open(UserResetComponent).afterClosed().subscribe((res) => {
this.dialog
.open(UserResetComponent)
.afterClosed()
.subscribe(res => {
if (res == true) {
this.acu.accs.resetPass(this.id!).subscribe((patch)=>{
this.acu.accs.resetPass(this.id!).subscribe(patch => {
if (patch.status == 200) {
this.sb.open("Hasło zostało zresetowane", undefined, {duration: 2500})
this.sb.open('Hasło zostało zresetowane', undefined, {
duration: 2500,
})
this.loading = false
}
})
@@ -168,7 +203,7 @@ export class UserEditComponent {
}
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
}

View File

@@ -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<UserResetComponent>;
let component: UserResetComponent
let fixture: ComponentFixture<UserResetComponent>
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()
})
})

View File

@@ -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
standalone: false,
})
export class UserResetComponent {
}
export class UserResetComponent {}

View File

@@ -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);
});
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()
})
})

View File

@@ -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<Menu, "day"> & {day: string})[]>(environment.apiEndpoint+"/admin/menu", {withCredentials: true, params: body})
const body = { start: start.toString(), end: end.toString() }
return this.http.get<(Omit<Menu, 'day'> & { day: string })[]>(
environment.apiEndpoint + '/admin/menu',
{ withCredentials: true, params: body }
)
}
return
},
getOpts: () => {
return this.http.get<any>(environment.apiEndpoint+`/admin/menu/opts`, {withCredentials: true})
return this.http.get<any>(environment.apiEndpoint + `/admin/menu/opts`, {
withCredentials: true,
})
},
postMenu: (file: File) => {
if (file) {
const formData = new FormData();
formData.append("menu", file)
return this.http.post<Status>(environment.apiEndpoint+"/admin/menu/upload", formData, {withCredentials: true})
const formData = new FormData()
formData.append('menu', file)
return this.http.post<Status>(
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<Status>(environment.apiEndpoint+`/admin/menu/${day.toISO()}`, null, {withCredentials: true})
return this.http.post<Status>(
environment.apiEndpoint + `/admin/menu/${day.toISO()}`,
null,
{ withCredentials: true }
)
},
range: (start: DateTime, count: number) => {
return this.http.post<Status>(environment.apiEndpoint+`/admin/menu/${start.toISO()}/${count}/`, null, {withCredentials: true})
}
return this.http.post<Status>(
environment.apiEndpoint + `/admin/menu/${start.toISO()}/${count}/`,
null,
{ withCredentials: true }
)
},
},
rm: (id: string) => {
return this.http.delete<Status>(environment.apiEndpoint+`/admin/menu/${id}`, {withCredentials: true})
}
return this.http.delete<Status>(
environment.apiEndpoint + `/admin/menu/${id}`,
{ withCredentials: true }
)
},
}
private putMenu(id: string, update: Partial<Menu>) {
return this.http.put<Status>(environment.apiEndpoint+`/admin/menu/${id}`, update, {withCredentials: true})
return this.http.put<Status>(
environment.apiEndpoint + `/admin/menu/${id}`,
update,
{ withCredentials: true }
)
}
//#endregion
//#region News
news = {
getNews: () => {
return this.http.get<News[]>(environment.apiEndpoint+`/admin/news`, {withCredentials: true})
return this.http.get<News[]>(environment.apiEndpoint + `/admin/news`, {
withCredentials: true,
})
},
postNews: (title: string, content: string) => {
return this.http.post<any>(environment.apiEndpoint+`/admin/news`, {title: title, content: content}, {withCredentials: true})
return this.http.post<any>(
environment.apiEndpoint + `/admin/news`,
{ title: title, content: content },
{ withCredentials: true }
)
},
deleteNews: (id: string) => {
return this.http.delete<any>(environment.apiEndpoint+`/admin/news/${id}`, {withCredentials: true})
return this.http.delete<any>(
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<any>(environment.apiEndpoint+`/admin/news/${id}`, update, {withCredentials: true})
return this.http.put<any>(
environment.apiEndpoint + `/admin/news/${id}`,
update,
{ withCredentials: true }
)
}
//#endregion
//#region amgmt
accs = {
getAccs: () => {
return this.http.get<{
users: Omit<User, "pass">[],
users: Omit<User, 'pass'>[]
groups: Group[]
}>(environment.apiEndpoint+`/admin/accs`, {withCredentials: true})
}>(environment.apiEndpoint + `/admin/accs`, { withCredentials: true })
},
postAcc: (item: any) => {
return this.http.post<Status>(environment.apiEndpoint+`/admin/accs`, item, {withCredentials: true})
return this.http.post<Status>(
environment.apiEndpoint + `/admin/accs`,
item,
{ withCredentials: true }
)
},
putAcc: (id: string, update: Partial<User>) => {
return this.http.put<Status>(environment.apiEndpoint+`/admin/accs/${id}`, update, {withCredentials: true})
return this.http.put<Status>(
environment.apiEndpoint + `/admin/accs/${id}`,
update,
{ withCredentials: true }
)
},
resetPass: (id: string) => {
return this.http.patch<Status>(environment.apiEndpoint+`/admin/accs/${id}/reset`, {}, {withCredentials: true})
return this.http.patch<Status>(
environment.apiEndpoint + `/admin/accs/${id}/reset`,
{},
{ withCredentials: true }
)
},
deleteAcc: (id: string) => {
return this.http.delete<Status>(environment.apiEndpoint+`/admin/accs/${id}`, {withCredentials: true})
return this.http.delete<Status>(
environment.apiEndpoint + `/admin/accs/${id}`,
{ withCredentials: true }
)
},
getUser: (id: string) => {
return this.http.get<Omit<User, "pass" | "regDate"> & {lockout: boolean, regDate: string}>(environment.apiEndpoint+`/admin/accs/${id}`, {withCredentials: true})
return this.http.get<
Omit<User, 'pass' | 'regDate'> & { lockout: boolean; regDate: string }
>(environment.apiEndpoint + `/admin/accs/${id}`, {
withCredentials: true,
})
},
clearLockout: (id: string) => {
return this.http.delete<Status>(environment.apiEndpoint+`/admin/accs/${id}/lockout`, {withCredentials: true})
}
return this.http.delete<Status>(
environment.apiEndpoint + `/admin/accs/${id}/lockout`,
{ withCredentials: true }
)
},
}
//#endregion
//#region Groups
groups = {
getGroups: () => {
return this.http.get<Group[]>(environment.apiEndpoint+`/admin/groups`, {withCredentials: true})
return this.http.get<Group[]>(environment.apiEndpoint + `/admin/groups`, {
withCredentials: true,
})
},
newGroup: (name: string) => {
return this.http.post<Status>(environment.apiEndpoint+`/admin/groups`, {name: name}, {withCredentials: true})
return this.http.post<Status>(
environment.apiEndpoint + `/admin/groups`,
{ name: name },
{ withCredentials: true }
)
},
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<Status>(environment.apiEndpoint+`/admin/groups/${id}`, {withCredentials: true})
}
return this.http.delete<Status>(
environment.apiEndpoint + `/admin/groups/${id}`,
{ withCredentials: true }
)
},
}
private putGroups(id: string, update: Partial<Group>) {
return this.http.put<Status>(environment.apiEndpoint+`/admin/groups/${id}`, update, {withCredentials: true})
return this.http.put<Status>(
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<Group[]>(environment.apiEndpoint+"/admin/notif/groups", {withCredentials: true})
return this.http.get<Group[]>(
environment.apiEndpoint + '/admin/notif/groups',
{ withCredentials: true }
)
},
outbox: {
getSent: () => {
return this.http.get<{_id: string, sentDate: string, title: string}[]>(environment.apiEndpoint+"/admin/notif/outbox", {withCredentials: true}).pipe(map(v => v.map(i => ({
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)
}))))
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<AKey, "borrow" | "tb"> & {borrow: string, tb?: string})[]>(environment.apiEndpoint+`/admin/keys`, {withCredentials: true}).pipe(map((v) => {
return v.map((r) => {
let newkey: any = {...r}
return this.http
.get<
(Omit<AKey, 'borrow' | 'tb'> & { 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<string[]>(environment.apiEndpoint+`/admin/keys/available`, {withCredentials: true})
return this.http.get<string[]>(
environment.apiEndpoint + `/admin/keys/available`,
{ withCredentials: true }
)
},
postKey: (room: string, uname: string) => {
return this.http.post<Status>(environment.apiEndpoint+`/admin/keys/`, {room: room, whom: uname}, {withCredentials: true})
return this.http.post<Status>(
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<AKey>) {
return this.http.put<Status>(environment.apiEndpoint+`/admin/keys/${id}`, update, {withCredentials: true})
return this.http.put<Status>(
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<Status>(environment.apiEndpoint+`/admin/clean/`, obj, {withCredentials: true})
return this.http.post<Status>(
environment.apiEndpoint + `/admin/clean/`,
obj,
{ withCredentials: true }
)
},
delete: (id: string) => {
return this.http.delete<Status>(environment.apiEndpoint+`/admin/clean/${id}`, {withCredentials: true})
return this.http.delete<Status>(
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<Status>(environment.apiEndpoint+`/admin/clean/attendence/${room}`, attendence, {withCredentials: true})
postAttendence: (
room: string,
attendence: { auto: { id: string; hour?: string }[]; notes: string }
) => {
return this.http.post<Status>(
environment.apiEndpoint + `/admin/clean/attendence/${room}`,
attendence,
{ withCredentials: true }
)
},
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<Status>(environment.apiEndpoint+`/admin/clean/attendence/${room}`, {withCredentials: true})
}
}
return this.http.delete<Status>(
environment.apiEndpoint + `/admin/clean/attendence/${room}`,
{ withCredentials: true }
)
},
},
}
//#endregion
//#region Settings
settings = {
getAll: () => {
return this.http.get<IUSettings>(environment.apiEndpoint+`/admin/settings/`, {withCredentials: true})
return this.http.get<IUSettings>(
environment.apiEndpoint + `/admin/settings/`,
{ withCredentials: true }
)
},
post: (settings: IUSettings) => {
return this.http.post<Status>(environment.apiEndpoint+`/admin/settings/`, settings, {withCredentials: true})
return this.http.post<Status>(
environment.apiEndpoint + `/admin/settings/`,
settings,
{ withCredentials: true }
)
},
reload: () => {
return this.http.get<Status>(environment.apiEndpoint+`/admin/settings/reload/`, {withCredentials: true})
}
return this.http.get<Status>(
environment.apiEndpoint + `/admin/settings/reload/`,
{ withCredentials: true }
)
},
}
//#endregion
//#region misc
userFilter = (query: string) => {
return this.http.get<any[]>(environment.apiEndpoint+`/admin/usearch`, {params: {q: query}, withCredentials: true})
return this.http.get<any[]>(environment.apiEndpoint + `/admin/usearch`, {
params: { q: query },
withCredentials: true,
})
}
//#endregion
}

View File

@@ -5,8 +5,9 @@
flex-direction: column;
}
mat-sidenav, mat-toolbar {
padding: 8pt
mat-sidenav,
mat-toolbar {
padding: 8pt;
}
mat-sidenav-container {

View File

@@ -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<AdminViewComponent>;
let component: AdminViewComponent
let fixture: ComponentFixture<AdminViewComponent>
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()
})
})

View File

@@ -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')
}

View File

@@ -1,7 +1,7 @@
@use 'sass:list';
@use "sass:list";
#guide {
margin: 1em
margin: 1em;
}
#legend {

View File

@@ -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<AttendenceSummaryComponent>;
let component: AttendenceSummaryComponent
let fixture: ComponentFixture<AttendenceSummaryComponent>
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();
imports: [RouterModule.forRoot([]), MatTableModule],
providers: [{ provide: AdminCommService, useValue: acMock }],
}).compileComponents()
fixture = TestBed.createComponent(AttendenceSummaryComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(AttendenceSummaryComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -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
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 })
}
}

View File

@@ -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<HourDisplayComponent>;
let component: HourDisplayComponent
let fixture: ComponentFixture<HourDisplayComponent>
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [HourDisplayComponent]
})
.compileComponents();
declarations: [HourDisplayComponent],
}).compileComponents()
fixture = TestBed.createComponent(HourDisplayComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(HourDisplayComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -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
standalone: false,
})
export class HourDisplayComponent {
@Input() value = "";
@Input() value = ''
style () {
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' }
}
}
}

View File

@@ -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<AttendenceComponent>;
let component: AttendenceComponent
let fixture: ComponentFixture<AttendenceComponent>
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();
NoopAnimationsModule,
],
}).compileComponents()
fixture = TestBed.createComponent(AttendenceComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(AttendenceComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -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
standalone: false,
})
export class AttendenceComponent implements OnInit {
constructor(private fb: FormBuilder, @Inject(MAT_DIALOG_DATA) public data: { room: string }, public dialogRef: MatDialogRef<AttendenceComponent>, private ac: AdminCommService) { }
constructor(
private fb: FormBuilder,
@Inject(MAT_DIALOG_DATA) public data: { room: string },
public dialogRef: MatDialogRef<AttendenceComponent>,
private ac: AdminCommService
) {}
ngOnInit(): void {
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({
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 : ""),
}))
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() {

View File

@@ -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<string>();
@Input() date: string = DateTime.now().toISODate()
@Output() dateChange = new EventEmitter<string>()
@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<string> = new EventEmitter<string>();
@Output() room: EventEmitter<string> = new EventEmitter<string>()
}
describe('GradesComponent', () => {
let component: GradesComponent;
let fixture: ComponentFixture<GradesComponent>;
let component: GradesComponent
let fixture: ComponentFixture<GradesComponent>
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();
NoopAnimationsModule,
],
}).compileComponents()
fixture = TestBed.createComponent(GradesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(GradesComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -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
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) => {
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({
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)
})))
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}) => {
this.dialog
.open(AttendenceComponent, { data: { room: this.room } })
.afterClosed()
.subscribe(
(v: {
room: string
users: { att: boolean; id: string; hour: string }[]
notes: string
}) => {
if (!v) return
let x: {room: string, users: {id: string, hour?: string}[]} = {
let x: { room: string; users: { id: string; hour?: string }[] } = {
room: v.room,
users: []
users: [],
}
v.users.forEach(i => {
if (i.att && i.hour) {
x.users.push({id: i.id, hour: i.hour})
x.users.push({ id: i.id, hour: i.hour })
}
})
this.ac.clean.attendence.postAttendence(x.room, {auto: x.users, notes: v.notes}).subscribe((s) => {
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.sb.open('Zapisano obecność!', undefined, {
duration: 1500,
})
}
})
})
}
)
}
}

View File

@@ -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<SummaryComponent>;
let component: SummaryComponent
let fixture: ComponentFixture<SummaryComponent>
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()
})
})

View File

@@ -1,38 +1,44 @@
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
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()
})
}
@@ -41,18 +47,22 @@ export class SummaryComponent implements OnInit, OnDestroy {
}
download() {
this.ac.clean.summary.getSummary(this.dateSelector.get('start')?.value!.startOf('day')!, this.dateSelector.get('end')?.value!.endOf('day')!).subscribe((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
}
}

View File

@@ -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<GroupsComponent>;
let component: GroupsComponent
let fixture: ComponentFixture<GroupsComponent>
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()
})
})

View File

@@ -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
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,35 +29,40 @@ 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) => {
this.dialog
.open(RemoveConfirmComponent)
.afterClosed()
.subscribe(v => {
if (v) {
this.acs.groups.remove(id).subscribe((s) => this.refreshIfGood(s))
this.acs.groups.remove(id).subscribe(s => this.refreshIfGood(s))
}
})
}

View File

@@ -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<RemoveConfirmComponent>;
let component: RemoveConfirmComponent
let fixture: ComponentFixture<RemoveConfirmComponent>
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()
})
})

View File

@@ -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
standalone: false,
})
export class RemoveConfirmComponent {
}
export class RemoveConfirmComponent {}

View File

@@ -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<AdminKeyComponent>;
let component: AdminKeyComponent
let fixture: ComponentFixture<AdminKeyComponent>
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();
}).compileComponents()
fixture = TestBed.createComponent(AdminKeyComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(AdminKeyComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -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
standalone: false,
})
export class AdminKeyComponent implements AfterViewInit, OnInit {
keys: MatTableDataSource<AKey> = new MatTableDataSource<AKey>();
keys: MatTableDataSource<AKey> = new MatTableDataSource<AKey>()
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,7 +53,8 @@ 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
}
@@ -70,14 +75,24 @@ export class AdminKeyComponent implements AfterViewInit, OnInit {
}
new() {
this.dialog.open(NewKeyComponent).afterClosed().subscribe(v => {
this.dialog
.open(NewKeyComponent)
.afterClosed()
.subscribe(v => {
if (v) {
this.ac.keys.postKey(v.room, v.user).pipe(catchError((err,caught)=>{
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})
this.sb.open('Nie znaleziono użytkownika', undefined, {
duration: 2500,
})
}
return throwError(() => new Error(err.message))
})).subscribe((s) => {
})
)
.subscribe(s => {
if (s.status == 201) {
this.fetchData()
}
@@ -87,7 +102,7 @@ export class AdminKeyComponent implements AfterViewInit, OnInit {
}
tb(id: string) {
this.ac.keys.returnKey(id).subscribe((r) => {
this.ac.keys.returnKey(id).subscribe(r => {
if (r.status == 200) {
this.fetchData()
}

View File

@@ -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: [{
selector: 'app-user-search',
template: '',
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => UserSearchStub),
multi: true,
},
{
provide: MatFormFieldControl,
useExisting: UserSearchStub
}],
standalone: false
useExisting: UserSearchStub,
},
],
standalone: false,
})
class UserSearchStub implements ControlValueAccessor, MatFormFieldControl<never> {
value: null = null;
stateChanges: Observable<void> = 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<never>
{
value: null = null
stateChanges: Observable<void> = 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<never>
}
describe('NewKeyComponent', () => {
let component: NewKeyComponent;
let fixture: ComponentFixture<NewKeyComponent>;
let component: NewKeyComponent
let fixture: ComponentFixture<NewKeyComponent>
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()
})
})

View File

@@ -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
standalone: false,
})
export class NewKeyComponent implements OnInit {
rooms: string[] = []
form = new FormGroup({
room: new FormControl<string>(""),
user: new FormControl<UserSearchResult | null>(null)
room: new FormControl<string>(''),
user: new FormControl<UserSearchResult | null>(null),
})
unames: any[] = []
constructor ( private ac: AdminCommService, public dialogRef: MatDialogRef<NewKeyComponent> ) {}
constructor(
private ac: AdminCommService,
public dialogRef: MatDialogRef<NewKeyComponent>
) {}
ngOnInit(): void {
this.ac.keys.avalKeys().subscribe((v) => {
this.ac.keys.avalKeys().subscribe(v => {
this.rooms = v
})
}
@@ -30,5 +33,4 @@ export class NewKeyComponent implements OnInit {
this.dialogRef.close(this.form.value)
}
}
}

View File

@@ -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<MenuAddComponent>;
let component: MenuAddComponent
let fixture: ComponentFixture<MenuAddComponent>
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();
FormsModule,
],
}).compileComponents()
fixture = TestBed.createComponent(MenuAddComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(MenuAddComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -1,50 +1,59 @@
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 }
{ provide: MAT_DATE_RANGE_SELECTION_STRATEGY, useClass: FDSelection },
],
standalone: false
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<DateTime|null>(null),
end: new FormControl<DateTime|null>(null),
start: new FormControl<DateTime | null>(null),
end: new FormControl<DateTime | null>(null),
})
constructor (public dialogRef: MatDialogRef<MenuAddComponent>, private dialog: MatDialog) { }
constructor(
public dialogRef: MatDialogRef<MenuAddComponent>,
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) => {
this.dialog
.open(MenuUploadComponent)
.afterClosed()
.subscribe(data => {
if (data) {
this.dialogRef.close({type: "file", ...data});
this.dialogRef.close({ type: 'file', ...data })
}
})
}

View File

@@ -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<MenuNewComponent>;
let component: MenuNewComponent
let fixture: ComponentFixture<MenuNewComponent>
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()
})
})

View File

@@ -1,43 +1,54 @@
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 }
{ provide: MAT_DATE_RANGE_SELECTION_STRATEGY, useClass: FDSelection },
],
standalone: false
standalone: false,
})
export class MenuNewComponent {
dcols: string[] = ['day', 'sn', 'ob', 'kol']
dataSource: MatTableDataSource<Menu> = new MatTableDataSource<Menu>()
range = new FormGroup({
start: new FormControl<DateTime|null>(null),
end: new FormControl<DateTime|null>(null),
start: new FormControl<DateTime | null>(null),
end: new FormControl<DateTime | null>(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) => {
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')
var mywindow = window.open(
undefined,
'Drukowanie',
'height=400,width=400'
)
mywindow?.document.write(r)
mywindow?.print()
mywindow?.close()
@@ -46,20 +57,27 @@ export class MenuNewComponent {
}
addDate() {
this.dialog.open(MenuAddComponent).afterClosed().subscribe((data) => {
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":
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;
break
default:
break;
break
}
}
})
@@ -67,15 +85,17 @@ export class MenuNewComponent {
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.ac.menu
.getMenu(this.range.value.start, this.range.value.end)
?.subscribe(data => {
this.loading = false
this.dataSource.data = data.map((v) => {
this.dataSource.data = data.map(v => {
let newMenu: Menu = {
...v,
day: DateTime.fromISO(v.day)
day: DateTime.fromISO(v.day),
}
return newMenu
})
@@ -89,7 +109,10 @@ export class MenuNewComponent {
}
activateUpload() {
this.dialog.open(MenuUploadComponent).afterClosed().subscribe((data) => {
this.dialog
.open(MenuUploadComponent)
.afterClosed()
.subscribe(data => {
if (data) {
this.requestData()
}
@@ -97,23 +120,39 @@ export class MenuNewComponent {
}
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) {

View File

@@ -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<MenuUploadComponent>;
let component: MenuUploadComponent
let fixture: ComponentFixture<MenuUploadComponent>
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()
})
})

View File

@@ -1,18 +1,21 @@
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
standalone: false,
})
export class MenuUploadComponent {
constructor(private ac:AdminCommService, public dialogRef: MatDialogRef<MenuUploadComponent>) {}
protected file: File | undefined;
constructor(
private ac: AdminCommService,
public dialogRef: MatDialogRef<MenuUploadComponent>
) {}
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 {
@@ -21,7 +24,7 @@ export class MenuUploadComponent {
}
submit() {
this.ac.menu.postMenu(this.file!)?.subscribe((value) => {
this.ac.menu.postMenu(this.file!)?.subscribe(value => {
this.dialogRef.close(value)
})
}

View File

@@ -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<NewPostComponent>;
let component: NewPostComponent
let fixture: ComponentFixture<NewPostComponent>
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()
})
})

View File

@@ -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
standalone: false,
})
export class NewPostComponent {
form: FormGroup;
constructor (public dialogRef: MatDialogRef<NewPostComponent>, @Inject(MAT_DIALOG_DATA) public data: any) {
form: FormGroup
constructor(
public dialogRef: MatDialogRef<NewPostComponent>,
@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,
})
}
}

View File

@@ -14,7 +14,7 @@ mat-card-footer p {
margin-bottom: 0;
text-align: end;
@media (prefers-color-scheme: dark) {
color: #999999
color: #999999;
}
}

View File

@@ -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<NewsEditComponent>;
let component: NewsEditComponent
let fixture: ComponentFixture<NewsEditComponent>
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()
})
})

View File

@@ -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
standalone: false,
})
export class NewsEditComponent implements OnInit {
news:Array<News & {formatted: string}> = new Array<News & {formatted: string}>
news: Array<News & { formatted: string }> = 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,32 +40,48 @@ export class NewsEditComponent implements OnInit {
}
newPost() {
this.dialog.open(NewPostComponent, {width: "90vw"}).afterClosed().subscribe(result=> {
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.")
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)=>{
})
)
.subscribe(data => {
if (data.status == 201) {
this.ngOnInit()
} else {
this.sb.open("Wystąpił błąd. Skontaktuj się z obsługą programu.")
this.sb.open('Wystąpił błąd. Skontaktuj się z obsługą programu.')
}
})
})
}
editPost(item: any) {
this.dialog.open(NewPostComponent, {data: item, width: "90vh"}).afterClosed().subscribe(result=>{
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)=> {
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.sb.open('Wystąpił błąd. Skontaktuj się z obsługą programu.')
}
})
})
@@ -74,28 +96,38 @@ 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)=> {
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.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)=> {
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.sb.open('Wystąpił błąd. Skontaktuj się z obsługą programu.')
}
})
}

View File

@@ -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: [{
selector: 'app-user-search',
template: '',
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => UserSearchStub),
multi: true,
},
{
provide: MatFormFieldControl,
useExisting: UserSearchStub
}],
standalone: false
useExisting: UserSearchStub,
},
],
standalone: false,
})
class UserSearchStub implements ControlValueAccessor, MatFormFieldControl<never> {
value: null = null;
stateChanges: Observable<void> = 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<never>
{
value: null = null
stateChanges: Observable<void> = 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<never>
}
describe('NotificationsComponent', () => {
let component: NotificationsComponent;
let fixture: ComponentFixture<NotificationsComponent>;
let component: NotificationsComponent
let fixture: ComponentFixture<NotificationsComponent>
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()
})
})

View File

@@ -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
standalone: false,
})
export class NotificationsComponent implements OnInit, OnDestroy {
groups!: Group[]
form = this.fb.group({
recp: this.fb.group({
uid: this.fb.control<UserSearchResult | null>(null),
room: this.fb.control<string|null>(null),
room: this.fb.control<string | null>(null),
group: this.fb.control<string>(''),
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,15 +56,20 @@ 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.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
})
}

View File

@@ -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<MessageComponent>;
let component: MessageComponent
let fixture: ComponentFixture<MessageComponent>
beforeEach(async () => {
const acMock = {
}
const acMock = {}
await TestBed.configureTestingModule({
declarations: [MessageComponent],
providers: [
{provide: AdminCommService, useValue: acMock}
],
imports: [
MatCardModule
]
})
.compileComponents();
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();
});
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()
})
})

View File

@@ -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
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

View File

@@ -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<OutboxComponent>;
let component: OutboxComponent
let fixture: ComponentFixture<OutboxComponent>
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();
providers: [{ provide: AdminCommService, useValue: acMock }],
imports: [RouterModule.forRoot([])],
}).compileComponents()
fixture = TestBed.createComponent(OutboxComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(OutboxComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -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
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
})
}
}

View File

@@ -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<SettingsComponent>;
let component: SettingsComponent
let fixture: ComponentFixture<SettingsComponent>
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();
MatInputModule,
],
}).compileComponents()
fixture = TestBed.createComponent(SettingsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(SettingsComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -1,19 +1,29 @@
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
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),
@@ -22,7 +32,7 @@ export class SettingsComponent implements OnInit {
})
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[];
sn: string[]
kol: string[]
}
}
};
security: {
loginTimeout: {
attempts: number;
time: number;
lockout: number;
attempts: number
time: number
lockout: number
}
}
}

View File

@@ -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<StartAdminComponent>;
let component: StartAdminComponent
let fixture: ComponentFixture<StartAdminComponent>
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [StartAdminComponent],
imports: [
MatIconModule
]
})
.compileComponents();
imports: [MatIconModule],
}).compileComponents()
fixture = TestBed.createComponent(StartAdminComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(StartAdminComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -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
standalone: false,
})
export class StartAdminComponent {
}
export class StartAdminComponent {}

View File

@@ -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<ToolbarComponent>;
let component: ToolbarComponent
let fixture: ComponentFixture<ToolbarComponent>
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ToolbarComponent],
imports: [MatToolbarModule, MatIconModule, MatMenuModule]
})
.compileComponents();
imports: [MatToolbarModule, MatIconModule, MatMenuModule],
}).compileComponents()
fixture = TestBed.createComponent(ToolbarComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(ToolbarComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -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
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()
}

View File

@@ -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()
})
})

View File

@@ -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 }[]
}

View File

@@ -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));
TestBed.runInInjectionContext(() => adminGuard(...guardParameters))
beforeEach(() => {
TestBed.configureTestingModule({});
});
TestBed.configureTestingModule({})
})
it('should be created', () => {
expect(executeGuard).toBeTruthy();
});
});
expect(executeGuard).toBeTruthy()
})
})

View File

@@ -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
};
}

View File

@@ -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 {}

View File

@@ -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<AppViewComponent>;
let component: AppViewComponent
let fixture: ComponentFixture<AppViewComponent>
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()
})
})

View File

@@ -1,34 +1,44 @@
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
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 (
constructor(
private ac: AuthClient,
readonly swPush: SwPush,
private us: UpdatesService,
@@ -39,9 +49,11 @@ export class AppViewComponent implements OnInit {
subscribeToNotif() {
if (this.swPush.isEnabled && this.ls.capCheck(4)) {
this.swPush.requestSubscription({
serverPublicKey: this.ls.vapid
}).then(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',
})
}
})
}

View File

@@ -1,3 +1,3 @@
ol>li::marker {
ol > li::marker {
font-weight: bold;
}

View File

@@ -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<AllergensComponent>;
let component: AllergensComponent
let fixture: ComponentFixture<AllergensComponent>
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()
})
})

View File

@@ -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
standalone: false,
})
export class AllergensComponent {
}
export class AllergensComponent {}

View File

@@ -28,7 +28,7 @@ mat-card {
#no-data {
color: #777;
@media (prefers-color-scheme: dark) {
color: #AAA
color: #aaa;
}
}

View File

@@ -1,34 +1,34 @@
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<MenuComponent>;
let component: MenuComponent
let fixture: ComponentFixture<MenuComponent>
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,
@@ -39,17 +39,16 @@ describe('MenuComponent', () => {
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()
})
})

View File

@@ -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)
})
}

View File

@@ -22,7 +22,7 @@ mat-card-footer p {
margin-bottom: 0;
text-align: end;
@media (prefers-color-scheme: dark) {
color: #999999
color: #999999;
}
}

View File

@@ -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<NewsComponent>;
let component: NewsComponent
let fixture: ComponentFixture<NewsComponent>
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()
})
})

View File

@@ -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
standalone: false,
})
export class NewsComponent implements OnInit {
news:Array<News> = new Array<News>
news: Array<News> = new Array<News>()
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
})
}

View File

@@ -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<NotifDialogComponent>;
let component: NotifDialogComponent
let fixture: ComponentFixture<NotifDialogComponent>
beforeEach(async () => {
const uMock = jasmine.createSpyObj<UpdatesService>("UpdatesService", {
postInfoAck: of()
const uMock = jasmine.createSpyObj<UpdatesService>('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();
imports: [MatDialogModule],
}).compileComponents()
fixture = TestBed.createComponent(NotifDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(NotifDialogComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -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
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<NotifDialogComponent>,
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()
})
}
}

View File

@@ -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<AboutComponent>;
let component: AboutComponent
let fixture: ComponentFixture<AboutComponent>
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [AboutComponent],
imports: [
MatDialogModule,
MatListModule
]
})
.compileComponents();
imports: [MatDialogModule, MatListModule],
}).compileComponents()
fixture = TestBed.createComponent(AboutComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(AboutComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -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
standalone: false,
})
export class AboutComponent {
LINKS: { title: string, info: string, icon: string, link: string }[] = [
LINKS: { title: string; info: string; icon: string; link: string }[] = [
{
title: "Autor",
info: "Jan Szumotalski",
icon: "person",
link: "https://github.com/Slasherss1/"
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',
},
]
}

View File

@@ -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<ChangePasswordDialogComponent>;
let component: ChangePasswordDialogComponent
let fixture: ComponentFixture<ChangePasswordDialogComponent>
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()
})
})

View File

@@ -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
standalone: false,
})
export class ChangePasswordDialogComponent {
error: string | null = null;
form: FormGroup;
constructor (private ac: AuthClient, public dr: MatDialogRef<ChangePasswordDialogComponent>, private router: Router, private ls: LocalStorageService) {
this.form = new FormGroup({
error: string | null = null
form: FormGroup
constructor(
private ac: AuthClient,
public dr: MatDialogRef<ChangePasswordDialogComponent>,
private router: Router,
private ls: LocalStorageService
) {
this.form = new FormGroup(
{
oldPass: new FormControl(),
newPass: new FormControl(),
newPassRepeat: new FormControl(),
}, {validators: [this.matchpass(), Validators.required]})
},
{ 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,20 +55,25 @@ 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)=>{
this.ac
.chpass(this.form.get('oldPass')?.value, this.form.get('newPass')?.value)
.pipe(
catchError(err => {
if (err.status == 401) {
this.error = "Niepoprawne dane"
this.error = 'Niepoprawne dane'
return throwError(() => new Error(err.message))
}
this.error = "Nieznany błąd"
this.error = 'Nieznany błąd'
return throwError(() => new Error(err.message))
})).subscribe((data) => {
})
)
.subscribe(data => {
if (this.error == null) {
this.dr.close()
this.ls.logOut()
this.router.navigateByUrl("/login")
this.router.navigateByUrl('/login')
}
})
}

View File

@@ -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<string>();
@Input() date: string = DateTime.now().toISODate()
@Output() dateChange = new EventEmitter<string>()
@Input() filter: (date: DateTime | null) => boolean = () => true
}
describe('CleanComponent', () => {
let component: CleanComponent;
let fixture: ComponentFixture<CleanComponent>;
let component: CleanComponent
let fixture: ComponentFixture<CleanComponent>
let updates: jasmine.SpyObj<UpdatesService>
beforeEach(async () => {
updates = jasmine.createSpyObj<UpdatesService>("UpdatesService", {
getClean: of()
updates = jasmine.createSpyObj<UpdatesService>('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();
}).compileComponents()
fixture = TestBed.createComponent(CleanComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(CleanComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -1,23 +1,23 @@
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
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()
}
@@ -26,7 +26,7 @@ export class CleanComponent implements OnInit {
}
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' }
}
}
}

View File

@@ -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<ExtraComponent>;
let component: ExtraComponent
let fixture: ComponentFixture<ExtraComponent>
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ExtraComponent],
imports: [
MatDialogModule,
MatListModule
]
})
.compileComponents();
imports: [MatDialogModule, MatListModule],
}).compileComponents()
fixture = TestBed.createComponent(ExtraComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(ExtraComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -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
standalone: false,
})
export class ExtraComponent {
constructor(private dialog: MatDialog) {}
constructor (private dialog: MatDialog) {}
private readonly _LINKS: (Omit<Link, "href"> & {component: ComponentType<any>})[] = [
{ title: "Domyślna strona po logowaniu", component: RedirectComponent, enabled: true, icon: "home" }
private readonly _LINKS: (Omit<Link, 'href'> & {
component: ComponentType<any>
})[] = [
{
title: 'Domyślna strona po logowaniu',
component: RedirectComponent,
enabled: true,
icon: 'home',
},
]
public get LINKS() {
return this._LINKS.filter((v) => {
return this._LINKS.filter(v => {
return v.enabled
});
})
}
open(component: ComponentType<any>) {

View File

@@ -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<RedirectComponent>;
let component: RedirectComponent
let fixture: ComponentFixture<RedirectComponent>
let loader: HarnessLoader
let authMock
beforeEach(async () => {
authMock = jasmine.createSpyObj<AuthClient>("AuthClient", {}, {redirect: ''})
authMock = jasmine.createSpyObj<AuthClient>(
'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();
imports: [
MatDialogModule,
MatFormFieldModule,
MatInputModule,
FormsModule,
NoopAnimationsModule,
],
}).compileComponents()
fixture = TestBed.createComponent(RedirectComponent);
component = fixture.componentInstance;
fixture.detectChanges();
fixture = TestBed.createComponent(RedirectComponent)
component = fixture.componentInstance
fixture.detectChanges()
loader = TestbedHarnessEnvironment.loader(fixture)
});
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -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
standalone: false,
})
export class RedirectComponent {
protected redirect = ""
constructor (public dialogRef: MatDialogRef<RedirectComponent>, private ac: AuthClient) {
protected redirect = ''
constructor(
public dialogRef: MatDialogRef<RedirectComponent>,
private ac: AuthClient
) {
this.redirect = ac.redirect
}

View File

@@ -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<KeyComponent>;
let component: KeyComponent
let fixture: ComponentFixture<KeyComponent>
let uMock: jasmine.SpyObj<UpdatesService>
beforeEach(async () => {
uMock = jasmine.createSpyObj<UpdatesService>("UpdatesService", {
getKeys: of()
uMock = jasmine.createSpyObj<UpdatesService>('UpdatesService', {
getKeys: of(),
})
await TestBed.configureTestingModule({
declarations: [KeyComponent],
providers: [
{provide: UpdatesService, useValue: uMock}
],
imports: [MatDialogModule, MatIconModule]
})
.compileComponents();
providers: [{ provide: UpdatesService, useValue: uMock }],
imports: [MatDialogModule, MatIconModule],
}).compileComponents()
fixture = TestBed.createComponent(KeyComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(KeyComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -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
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
})
}

View File

@@ -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<LogoutConfirmationComponent>;
let component: LogoutConfirmationComponent
let fixture: ComponentFixture<LogoutConfirmationComponent>
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()
})
})

View File

@@ -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
standalone: false,
})
export class LogoutConfirmationComponent {
}
export class LogoutConfirmationComponent {}

View File

@@ -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<PersonalComponent>;
let component: PersonalComponent
let fixture: ComponentFixture<PersonalComponent>
let auMock: jasmine.SpyObj<AppUpdateService>
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()
})
})

View File

@@ -1,34 +1,40 @@
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
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.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()
}

View File

@@ -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<StartComponent>;
let component: StartComponent
let fixture: ComponentFixture<StartComponent>
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [StartComponent],
imports: [
RouterModule.forRoot([]),
MatListModule
]
})
.compileComponents();
imports: [RouterModule.forRoot([]), MatListModule],
}).compileComponents()
fixture = TestBed.createComponent(StartComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
fixture = TestBed.createComponent(StartComponent)
component = fixture.componentInstance
fixture.detectChanges()
})
it('should create', () => {
expect(component).toBeTruthy();
});
});
expect(component).toBeTruthy()
})
})

View File

@@ -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
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 })
}

View File

@@ -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')
})
})

View File

@@ -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
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'
}

View File

@@ -1,93 +1,94 @@
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: [
@NgModule({
declarations: [
AppComponent,
NewsComponent,
MenuComponent,
@@ -177,10 +178,13 @@ import { provideLuxonDateAdapter } from "@angular/material-luxon-adapter";
enabled: environment.production,
// Register the ServiceWorker as soon as the application is stable
// or after 30 seconds (whichever comes first).
registrationStrategy: 'registerWhenStable:30000'
})], providers: [
registrationStrategy: 'registerWhenStable:30000',
}),
],
providers: [
provideLuxonDateAdapter(),
FDSelection,
provideHttpClient(withInterceptorsFromDi()),
] })
export class AppModule { }
],
})
export class AppModule {}

View File

@@ -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));
TestBed.runInInjectionContext(() => authGuard(...guardParameters))
beforeEach(() => {
TestBed.configureTestingModule({});
});
TestBed.configureTestingModule({})
})
it('should be created', () => {
expect(executeGuard).toBeTruthy();
});
});
expect(executeGuard).toBeTruthy()
})
})

View File

@@ -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
};
}

Some files were not shown because too many files have changed in this diff Show More