feat: Completed migration from moment to luxon

This commit is contained in:
2025-06-09 21:52:20 +02:00
parent 8ad18e8670
commit 76de91349d
34 changed files with 424 additions and 238 deletions

View File

@@ -23,7 +23,7 @@
</mat-select>
</mat-form-field>
@if (data.type == 'edit') {
<span>Data rejestracji:<br>{{regDate?.format('DD.MM.YYYY')}}</span>
<span>Data rejestracji:<br>{{regDate?.toFormat('D')}}</span>
}
</div>
<div>

View File

@@ -8,8 +8,7 @@ import { UserDeleteComponent } from '../user-delete/user-delete.component';
import { MatSnackBar } from '@angular/material/snack-bar';
import { UserResetComponent } from '../user-reset/user-reset.component';
import { catchError, throwError } from 'rxjs';
import { Moment } from 'moment';
import moment from 'moment';
import { DateTime } from 'luxon';
export namespace UserEditComponent {
export type InputData = {type: "new" | "edit", id?: string, groups: Group[]}
@@ -36,7 +35,7 @@ export class UserEditComponent {
})
groups: Group[]
id?: string
regDate?: Moment;
regDate?: DateTime;
constructor (
public dialogRef: MatDialogRef<UserEditComponent>,
@Inject(MAT_DIALOG_DATA) public data: UserEditComponent.InputData,
@@ -49,7 +48,7 @@ export class UserEditComponent {
if (data.type == "edit") {
this.id = data.id
this.acu.accs.getUser(data.id!).subscribe((r) => {
this.regDate = moment(r.regDate)
this.regDate = DateTime.fromISO(r.regDate)
var flags: Array<number> = []
if (r.admin) {
if ((r.admin & 1) == 1) flags.push(1)

View File

@@ -1,17 +1,16 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Moment } from 'moment';
import { environment } from 'src/environments/environment';
import { Menu } from '../types/menu';
import { Status } from '../types/status';
import { Group } from '../types/group';
import { map, of } from 'rxjs';
import { map } from 'rxjs';
import { Notification } from '../types/notification';
import { News } from '../types/news';
import { AKey } from '../types/key';
import moment from 'moment';
import { IUSettings } from './settings/settings.component';
import User from '../types/user';
import { DateTime } from 'luxon';
@Injectable({
providedIn: 'root'
@@ -22,10 +21,10 @@ export class AdminCommService {
//#region Menu
menu = {
getMenu: (start?: Moment | null, end?: Moment | null) => {
getMenu: (start?: DateTime | null, end?: DateTime | null) => {
if (start && end) {
const body = {start: start.toString(), end: end.toString()}
return this.http.get<Menu[]>(environment.apiEndpoint+"/admin/menu", {withCredentials: true, params: body})
return this.http.get<(Omit<Menu, "day"> & {day: string})[]>(environment.apiEndpoint+"/admin/menu", {withCredentials: true, params: body})
}
return
},
@@ -59,7 +58,7 @@ export class AdminCommService {
return this.putMenu(id, {dayTitle: content})
},
print: (start?: Moment | null, end?: Moment | null) => {
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"})
@@ -67,15 +66,15 @@ export class AdminCommService {
return
},
stat: (day: Moment, m: "ob" | "kol") => {
return this.http.get<{y: number, n: number}>(environment.apiEndpoint+`/admin/menu/${day.toISOString()}/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: Moment) => {
return this.http.post<Status>(environment.apiEndpoint+`/admin/menu/${day.toISOString()}`, null, {withCredentials: true})
single: (day: DateTime) => {
return this.http.post<Status>(environment.apiEndpoint+`/admin/menu/${day.toISO()}`, null, {withCredentials: true})
},
range: (start: Moment, count: number) => {
return this.http.post<Status>(environment.apiEndpoint+`/admin/menu/${start.toISOString()}/${count}/`, null, {withCredentials: true})
range: (start: DateTime, count: number) => {
return this.http.post<Status>(environment.apiEndpoint+`/admin/menu/${start.toISO()}/${count}/`, null, {withCredentials: true})
}
},
rm: (id: string) => {
@@ -144,7 +143,7 @@ export class AdminCommService {
},
getUser: (id: string) => {
return this.http.get<Omit<User, "pass"> & {lockout: boolean}>(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) => {
@@ -185,7 +184,10 @@ export class AdminCommService {
},
outbox: {
getSent: () => {
return this.http.get<{_id: string, sentDate: moment.Moment, title: string}[]>(environment.apiEndpoint+"/admin/notif/outbox", {withCredentials: true})
return this.http.get<{_id: string, sentDate: string, title: string}[]>(environment.apiEndpoint+"/admin/notif/outbox", {withCredentials: true}).pipe(map(v => v.map(i => ({
...i,
sentDate: DateTime.fromISO(i.sentDate)
}))))
},
getBody: (id: string) => {
return this.http.get(environment.apiEndpoint+`/admin/notif/outbox/${id}/message`, {withCredentials: true, responseType: "text"})
@@ -199,11 +201,12 @@ export class AdminCommService {
//#region Keys
keys = {
getKeys: () => {
return this.http.get<AKey[]>(environment.apiEndpoint+`/admin/keys`, {withCredentials: true}).pipe(map((v) => {
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) => {
r.borrow = moment(r.borrow)
if (r.tb) r.tb = moment(r.tb)
return r
let newkey: any = {...r}
newkey.borrow = DateTime.fromISO(r.borrow!)
if (newkey.tb) newkey.tb = DateTime.fromISO(r.tb!)
return newkey as AKey
})
}))
},
@@ -217,7 +220,7 @@ export class AdminCommService {
},
returnKey: (id: string) => {
return this.putKeys(id, {tb: moment.utc()})
return this.putKeys(id, {tb: DateTime.now()})
}
}
@@ -230,8 +233,8 @@ export class AdminCommService {
getConfig: () => {
return this.http.get<{rooms: string[], things: string[]}>(environment.apiEndpoint+`/admin/clean/config`, {withCredentials: true})
},
getClean: (date: moment.Moment, 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.toISOString()}/${room}`, {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})
},
postClean: (obj: Object) => {
return this.http.post<Status>(environment.apiEndpoint+`/admin/clean/`, obj, {withCredentials: true})
@@ -240,8 +243,8 @@ export class AdminCommService {
return this.http.delete<Status>(environment.apiEndpoint+`/admin/clean/${id}`, {withCredentials: true})
},
summary: {
getSummary: (start: moment.Moment, end: moment.Moment) => {
return this.http.get<{room: string, avg: number}[]>(environment.apiEndpoint+`/admin/clean/summary/${start.toISOString()}/${end.toISOString()}`, {withCredentials: true})
getSummary: (start: DateTime, end: DateTime) => {
return this.http.get<{room: string, avg: number}[]>(environment.apiEndpoint+`/admin/clean/summary/${start.toISO()}/${end.toISO()}`, {withCredentials: true})
}
},
attendence: {

View File

@@ -1,7 +1,7 @@
<app-date-selector [(date)]="date" [filter]="filter" (dateChange)="downloadData()"></app-date-selector>
<app-room-chooser [rooms]="rooms" (room)="roomNumber($event)"/>
<form [formGroup]="form">
<p>Czystość pokoju {{room}} na dzień {{date.format("dddd")}}</p>
<p>Czystość pokoju {{room}} na {{_date.toFormat("cccc, D")}}</p>
<p>Ocena: {{grade}}</p>
<div id="buttons">
<button mat-mini-fab (click)="downloadData()" color="accent"><mat-icon>cancel</mat-icon></button>

View File

@@ -4,20 +4,20 @@ 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 * as moment from 'moment';
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
})
class DateSelectorStub {
@Input() date: moment.Moment = moment.utc().startOf('day');
@Input() date: string = DateTime.now().toISODate();
@Output() dateChange = new EventEmitter<moment.Moment>();
@Input() filter: (date: moment.Moment | null) => boolean = () => true
}

View File

@@ -1,6 +1,5 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { AdminCommService } from '../admin-comm.service';
import moment from 'moment';
import { FormArray, FormBuilder } from '@angular/forms';
import { weekendFilter } from 'src/app/fd.da';
import { MatSnackBar } from '@angular/material/snack-bar';
@@ -8,6 +7,7 @@ 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',
@@ -18,9 +18,15 @@ import { AttendenceComponent } from './attendence/attendence.component';
export class GradesComponent implements OnInit, OnDestroy {
rooms!: string[]
room: string = "0";
date: moment.Moment;
protected _date: DateTime;
public get date(): string {
return this._date.toISODate()!;
}
public set date(value: string) {
this._date = DateTime.fromISO(value);
}
grade: number = 6
gradeDate?: moment.Moment;
gradeDate?: DateTime;
id?: string
filter = weekendFilter
@@ -46,8 +52,8 @@ 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) {
this.date = moment.utc().startOf('day')
if (!this.filter(this.date)) this.date.isoWeekday(8);
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"},
@@ -95,7 +101,7 @@ export class GradesComponent implements OnInit, OnDestroy {
this.ac.clean.getClean(this.date, this.room).subscribe((v) => {
if (v) {
this.notes = v.notes
this.gradeDate = moment(v.gradeDate)
this.gradeDate = DateTime.fromISO(v.gradeDate)
this.grade = v.grade
this.id = v._id
this.form.get("tips")?.setValue(v.tips)
@@ -140,7 +146,7 @@ export class GradesComponent implements OnInit, OnDestroy {
this.calculate()
var obj = {
grade: this.grade,
date: this.date.toDate(),
date: this.date,
room: this.room,
notes: this.notes,
tips: this.form.get("tips")?.value

View File

@@ -2,10 +2,10 @@ 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 * as moment from 'moment';
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',
@@ -19,8 +19,8 @@ export class SummaryComponent implements OnInit, OnDestroy {
collumns = ['room', 'avg']
dateSelector = this.fb.group({
start: this.fb.control(moment.utc().startOf('day')),
end: this.fb.control(moment.utc().endOf('day'))
start: this.fb.control(DateTime.utc().startOf('day')),
end: this.fb.control(DateTime.utc().endOf('day'))
})
@ViewChild(MatSort, {static: false}) set content(sort: MatSort) {

View File

@@ -1,10 +1,8 @@
import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core';
import { MatPaginator } from '@angular/material/paginator';
import { MatTableDataSource } from '@angular/material/table';
import * as moment from 'moment';
import { AKey } from 'src/app/types/key';
import { AdminCommService } from '../admin-comm.service';
import { FormControl } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { NewKeyComponent } from './new-key/new-key.component';
import { catchError, throwError } from 'rxjs';

View File

@@ -3,9 +3,8 @@ 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 { Moment } from 'moment';
import { MAT_DATE_RANGE_SELECTION_STRATEGY } from '@angular/material/datepicker';
import * as moment from 'moment';
import { DateTime } from 'luxon';
@Component({
selector: 'app-menu-add',
@@ -20,11 +19,11 @@ export class MenuAddComponent {
type: string | undefined;
filter = weekendFilter
day: Moment = moment.utc();
day: string = DateTime.now().toISODate();
range = new FormGroup({
start: new FormControl<Moment|null>(null),
end: new FormControl<Moment|null>(null),
start: new FormControl<DateTime|null>(null),
end: new FormControl<DateTime|null>(null),
})
constructor (public dialogRef: MatDialogRef<MenuAddComponent>, private dialog: MatDialog) { }
@@ -32,10 +31,10 @@ export class MenuAddComponent {
submit() {
switch (this.type) {
case "day":
this.dialogRef.close({type: "day", value: this.day.utc().startOf('day')})
this.dialogRef.close({type: "day", value: this.day})
break;
case "week":
this.dialogRef.close({type: "week", value: {start: this.range.value.start?.utc().hours(24), count: 5}})
this.dialogRef.close({type: "week", value: {start: this.range.value.start?.toISODate(), count: 5}})
break;
default:
break;

View File

@@ -19,8 +19,8 @@
<div matColumnDef="day">
<th mat-header-cell *matHeaderCellDef>Dzień</th>
<td mat-cell *matCellDef="let element">
<span>{{element.day.format('DD.MM.YYYY')}}r.</span>
<p>{{element.day.format('dddd')}}</p>
<span>{{element.day.toFormat('dd.LL.yyyy')}}r.</span>
<p>{{element.day.toFormat('cccc') | titlecase }}</p>
<app-field-editor category="Nazwa" [(word)]="element.dayTitle" (wordChange)="editTitle(element._id)"/><br><hr>
<button (click)="remove(element._id)">Usuń dzień</button>
</td>
@@ -61,7 +61,7 @@
<th mat-header-cell *matHeaderCellDef>Kolacja</th>
<td mat-cell *matCellDef="let element">
<div>
@switch (element.day.isoWeekday()) {
@switch (element.day.weekday) {
@default {
<div>
<ul class="non-editable">

View File

@@ -1,18 +1,17 @@
import { Component } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { MAT_DATE_RANGE_SELECTION_STRATEGY } from '@angular/material/datepicker';
import { Moment } from 'moment';
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 * as moment from 'moment';
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',
@@ -27,17 +26,13 @@ export class MenuNewComponent {
dcols: string[] = ['day', 'sn', 'ob', 'kol']
dataSource: MatTableDataSource<Menu> = new MatTableDataSource<Menu>()
range = new FormGroup({
start: new FormControl<Moment|null>(null),
end: new FormControl<Moment|null>(null),
start: new FormControl<DateTime|null>(null),
end: new FormControl<DateTime|null>(null),
})
loading = false
public options: any;
constructor (private ac: AdminCommService, private dialog: MatDialog, private sb: MatSnackBar, readonly ls: LocalStorageService) {
moment.updateLocale('pl', {
weekdays: ["Niedziela", "Poniedziałek", "Wtorek", "Środa", "Czwartek", "Piątek", "Sobota"]
})
}
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) => {
@@ -80,7 +75,7 @@ export class MenuNewComponent {
this.dataSource.data = data.map((v) => {
let newMenu: Menu = {
...v,
day: moment.utc(v.day)
day: DateTime.fromISO(v.day)
}
return newMenu
})
@@ -117,7 +112,7 @@ export class MenuNewComponent {
this.ac.menu.editTitle(id, this.dataSource.data.find(v => v._id == id)?.dayTitle).subscribe(s => this.refreshIfGood(s))
}
getStat(day: moment.Moment, m: "ob" | "kol") {
getStat(day: 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}))
}

View File

@@ -4,7 +4,7 @@
<mat-card-title>
{{item.title}}
</mat-card-title>
<mat-card-subtitle>{{item.sentDate.format('[Wysłano] dddd DD MMMM YYYYr. o HH:mm')}}</mat-card-subtitle>
<mat-card-subtitle>Wysłano {{item.sentDate.toFormat("cccc dd LLLL yyyyr. 'o' HH:mm")}}</mat-card-subtitle>
</mat-card-title-group>
</mat-card-header>
<mat-card-content>

View File

@@ -1,9 +1,8 @@
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 moment from 'moment';
import { DateTime } from 'luxon';
describe('MessageComponent', () => {
let component: MessageComponent;
@@ -26,7 +25,7 @@ describe('MessageComponent', () => {
fixture = TestBed.createComponent(MessageComponent);
component = fixture.componentInstance;
component.item = {_id: "test", sentDate: moment(), title: "Test"}
component.item = {_id: "test", sentDate: DateTime.now(), title: "Test"}
fixture.detectChanges();
});

View File

@@ -1,4 +1,5 @@
import { Component, Input } from '@angular/core';
import { DateTime } from 'luxon';
import { AdminCommService } from 'src/app/admin-view/admin-comm.service';
@Component({
@@ -8,7 +9,7 @@ import { AdminCommService } from 'src/app/admin-view/admin-comm.service';
standalone: false
})
export class MessageComponent {
@Input() item!: {_id: string, sentDate: moment.Moment, title: string}
@Input() item!: {_id: string, sentDate: DateTime, title: string}
body?: string
rcpts?: {_id: string, uname: string, room?: string, fname?: string, surname?: string}[]
loading: boolean = false

View File

@@ -2,7 +2,7 @@ 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 moment from 'moment';
import { DateTime } from 'luxon';
@Component({
selector: 'app-outbox',
@@ -14,7 +14,7 @@ export class OutboxComponent implements OnInit {
messages!: {
_id: string;
sentDate: moment.Moment;
sentDate: DateTime;
title: string;
}[]
@@ -31,12 +31,7 @@ export class OutboxComponent implements OnInit {
ngOnInit(): void {
this.acs.notif.outbox.getSent().subscribe((v) => {
this.messages = v.map(i => {
return {
...i,
sentDate: moment(i.sentDate)
}
})
this.messages = v
})
}

View File

@@ -1,83 +1,80 @@
import { Component, OnInit } from '@angular/core';
import { UpdatesService } from '../../services/updates.service';
import { Menu } from '../../types/menu';
import * as moment from 'moment';
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
selector: 'app-menu',
templateUrl: './menu.component.html',
styleUrls: ['./menu.component.scss'],
standalone: false
})
export class MenuComponent {
constructor(private uc:UpdatesService, readonly bs: MatBottomSheet, readonly ls: LocalStorageService) {
this.day = moment.utc()
}
loading = true
constructor(private uc: UpdatesService, readonly bs: MatBottomSheet, readonly ls: LocalStorageService) {
this._day = DateTime.now().toISODate()
}
loading = true
public filter = weekendFilter
private _day!: moment.Moment;
public get day(): moment.Moment {
return this._day;
}
public set day(value: moment.Moment) {
// if (value.isAfter(moment.utc("19:15:00", "HH:mm:ss"))) value.add(1, "day")
if (!this.filter(value)) value.isoWeekday(8);
this._day = moment.utc(value).startOf('day');
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}
private checkIfAnyProperty(obj: { [x: string]: string | string[];}) {
for (let i in obj) {
if (Array.isArray(obj[i])) {
if (obj[i].length > 0) return true
} else {
if (!!obj[i]) return true
}
public filter = weekendFilter
private _day: string;
public get day(): string {
return this._day;
}
public set day(value: string) {
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 }
private checkIfAnyProperty(obj: { [x: string]: string | string[]; }) {
for (let i in obj) {
if (Array.isArray(obj[i])) {
if (obj[i].length > 0) return true
} else {
if (!!obj[i]) return true
}
return false
}
return false
}
capitalize(str: string) {
return str.charAt(0).toUpperCase()+str.substring(1)
}
capitalize(str: string) {
return str.charAt(0).toUpperCase() + str.substring(1)
}
updateMenu(silent?: boolean) {
this.loading = !silent
if (!silent) this.menu = undefined
this.uc.getMenu(this.day).subscribe(m => {
this.loading = false
this.menu = m
console.log(m);
})
}
updateMenu(silent?: boolean) {
this.loading = !silent
if (!silent) this.menu = undefined
this.uc.getMenu(this.day).subscribe(m => {
this.loading = false
this.menu = m
console.log(m);
})
}
alrg() {
this.bs.open(AllergensComponent)
}
alrg() {
this.bs.open(AllergensComponent)
}
protected vegeColor(text: string) {
if (text.startsWith("V: ")) {
return "#43A047"
}
return "inherit"
protected vegeColor(text: string) {
if (text.startsWith("V: ")) {
return "#43A047"
}
return "inherit"
}
vote(type: "ob" | "kol", vote: "-" | "+" | "n") {
this.uc.postVote(this.menu!.day, type, vote).subscribe((data) => {
this.updateMenu(true)
})
}
vote(type: "ob" | "kol", vote: "-" | "+" | "n") {
this.uc.postVote(this.menu!.day.toISO()!, type, vote).subscribe((data) => {
this.updateMenu(true)
})
}
}

View File

@@ -3,7 +3,7 @@
<p>
{{data.message.body}}
</p>
<div>{{data.sentDate.format("[Wysłano] dddd DD MMMM YYYYr. o HH:mm")}}</div>
<div>{{date.toFormat("[Wysłano] dddd DD MMMM YYYYr. o HH:mm")}}</div>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button mat-raised-button color="primary" (click)="ack()">Odczytano</button>

View File

@@ -1,6 +1,6 @@
import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import moment from 'moment';
import { DateTime } from 'luxon';
import { UpdatesService } from 'src/app/services/updates.service';
@Component({
@@ -11,12 +11,14 @@ import { UpdatesService } from 'src/app/services/updates.service';
})
export class NotifDialogComponent {
date: DateTime
constructor (
@Inject(MAT_DIALOG_DATA) public data: {_id: string, message: {title: string, body: string}, sentDate: moment.Moment},
@Inject(MAT_DIALOG_DATA) public data: {_id: string, message: {title: string, body: string}, sentDate: string},
public dialogRef: MatDialogRef<NotifDialogComponent>,
private uc: UpdatesService
) {
data.sentDate = moment(data.sentDate)
this.date = DateTime.fromISO(data.sentDate)
}
ack () {

View File

@@ -8,14 +8,14 @@ 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 * as moment from 'moment';
import { DateTime } from 'luxon';
@Component({
selector: "app-date-selector", template: '',
standalone: false
})
class DateSelectorStub {
@Input() date: moment.Moment = moment.utc().startOf('day');
@Input() date: string = DateTime.now().toISODate();
@Output() dateChange = new EventEmitter<moment.Moment>();
@Input() filter: (date: moment.Moment | null) => boolean = () => true
}

View File

@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import moment from 'moment';
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';
@@ -11,22 +11,14 @@ import { CleanNote } from 'src/app/types/clean-note';
standalone: false
})
export class CleanComponent implements OnInit {
private _day: moment.Moment = moment()
public get day(): moment.Moment {
return this._day;
}
public set day(value: moment.Moment) {
if (!this.filter(value)) value.isoWeekday(5);
this._day = moment.utc(value).startOf('day');
this.update()
}
protected day: string
grade: number | null = null
notes: CleanNote[] = []
tips: string = ""
filter = weekendFilter
constructor (private updates: UpdatesService) {
this.day = moment.utc();
this.day = DateTime.now().toISODate()
}
ngOnInit(): void {

View File

@@ -1,7 +1,7 @@
import { Component } from '@angular/core';
import { Component, Inject, LOCALE_ID } from '@angular/core';
import { AppUpdateService } from './services/app-update.service';
import { MatIconRegistry } from '@angular/material/icon';
import * as moment from 'moment';
import { Settings } from 'luxon';
@Component({
selector: 'app-root',
@@ -10,12 +10,9 @@ import * as moment from 'moment';
standalone: false
})
export class AppComponent {
constructor (readonly updates: AppUpdateService, mir: MatIconRegistry) {
constructor (readonly updates: AppUpdateService, mir: MatIconRegistry, @Inject(LOCALE_ID) lang: string) {
mir.setDefaultFontSetClass("material-symbols-rounded")
moment.updateLocale('pl', {
weekdays: ["Niedziela", "Poniedziałek", "Wtorek", "Środa", "Czwartek", "Piątek", "Sobota"]
})
moment.locale('pl')
Settings.defaultLocale = lang
}
title = 'Internat';
}

View File

@@ -3,10 +3,8 @@ import { BrowserModule } from '@angular/platform-browser';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MAT_MOMENT_DATE_ADAPTER_OPTIONS, MAT_MOMENT_DATE_FORMATS, MomentDateAdapter } from '@angular/material-moment-adapter';
import { MatButtonModule } from "@angular/material/button";
import { MatCardModule } from "@angular/material/card";
import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE, MatNativeDateModule } from '@angular/material/core';
import { MatDatepickerModule } from "@angular/material/datepicker";
import { MatDialogModule } from '@angular/material/dialog';
import { MatIconModule } from "@angular/material/icon";
@@ -87,6 +85,7 @@ import { MessageComponent } from './admin-view/notifications/outbox/message/mess
import { NotifDialogComponent } from './app-view/notif-dialog/notif-dialog.component';
import { UserSearchComponent } from './commonComponents/user-search/user-search.component';
import { StartAdminComponent } from './admin-view/start/start.component';
import { provideLuxonDateAdapter } from "@angular/material-luxon-adapter";
@NgModule({ declarations: [
AppComponent,
@@ -138,7 +137,9 @@ import { StartAdminComponent } from './admin-view/start/start.component';
UserSearchComponent,
StartAdminComponent,
],
bootstrap: [AppComponent], imports: [BrowserModule,
bootstrap: [AppComponent],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
MatTabsModule,
@@ -146,7 +147,6 @@ import { StartAdminComponent } from './admin-view/start/start.component';
MatButtonModule,
MatIconModule,
MatDatepickerModule,
MatNativeDateModule,
MatInputModule,
ReactiveFormsModule,
FormsModule,
@@ -179,10 +179,7 @@ import { StartAdminComponent } from './admin-view/start/start.component';
// or after 30 seconds (whichever comes first).
registrationStrategy: 'registerWhenStable:30000'
})], providers: [
{ provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE, MAT_DATE_FORMATS, MAT_MOMENT_DATE_ADAPTER_OPTIONS] },
{ provide: MAT_DATE_LOCALE, useValue: "pl-PL" },
{ provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS },
{ provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS, useValue: { useUtc: true } },
provideLuxonDateAdapter(),
FDSelection,
provideHttpClient(withInterceptorsFromDi()),
] })

View File

@@ -1,5 +1,5 @@
<button mat-icon-button (click)="prevDay()"><mat-icon>chevron_left</mat-icon></button>
<p (click)="picker.open()">{{date.format('dddd, D.MM')}}</p>
<p (click)="picker.open()">{{_date_1.toFormat('cccc, d.LL') | titlecase }}</p>
<mat-form-field style="display: none;">
<input #dateinput matInput [matDatepicker]="picker" [formControl]="dateInput" [matDatepickerFilter]="filter">
<mat-datepicker touchUi #picker></mat-datepicker>

View File

@@ -1,6 +1,7 @@
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
import { FormControl } from '@angular/forms';
import moment from 'moment';
import { DateFilterFn } from '@angular/material/datepicker';
import { DateTime } from 'luxon';
@Component({
selector: 'app-date-selector',
@@ -9,40 +10,47 @@ import moment from 'moment';
standalone: false
})
export class DateSelectorComponent implements OnChanges {
@Input() date: moment.Moment = moment.utc().startOf('day');
@Output() dateChange = new EventEmitter<moment.Moment>();
@Input() filter: (date: moment.Moment | null) => boolean = () => true
protected dateInput: FormControl<moment.Moment>
protected _date_1: DateTime = DateTime.now();
protected set _date(value: DateTime) {
this._date_1 = value;
this.date = value.toISODate()!
}
@Input()
public set date(value: string) {
this._date_1 = DateTime.fromISO(value);
}
@Output() dateChange = new EventEmitter<string>();
@Input() filter: DateFilterFn<DateTime | null> = () => true
protected dateInput: FormControl<DateTime>
constructor () {
this.dateInput = new FormControl(this.date, {nonNullable: true});
this.dateInput = new FormControl(this._date_1, {nonNullable: true});
this.dateInput.valueChanges.subscribe((v) => {
v.utc(true).startOf('day')
this.dateChange.emit(v)
this.dateChange.emit(v.toISODate()!)
})
}
ngOnChanges(changes: SimpleChanges): void {
if (changes['date']) {
this.dateInput.setValue(this.date, {emitEvent: false})
this.dateInput.setValue(this._date_1), {emitEvent: false}
}
}
prevDay(): void {
let newDay = moment(this.date);
if (this.filter(newDay.add({days: -1}))) {
this.dateInput.setValue(this.date.add({days: -1}))
let yesterday = this._date_1.minus({day: 1})
if (this.filter(yesterday)) {
this.dateInput.setValue(yesterday)
} else {
this.dateInput.setValue(this.date.isoWeekday(-2))
this.dateInput.setValue(this._date.set({weekday: 5}).minus({week: 1}))
}
}
nextDay(): void {
let newDay = moment(this.date);
if (this.filter(newDay.add({days: 1}))) {
this.dateInput.setValue(this.date.add({days: 1}))
let tomorrow = this._date_1.plus({day: 1})
if (this.filter(tomorrow)) {
this.dateInput.setValue(tomorrow)
} else {
this.dateInput.setValue(this.date.isoWeekday(8))
this.dateInput.setValue(this._date.set({weekday: 1}).plus({week: 1}))
}
}
}

View File

@@ -1,28 +1,28 @@
import { Injectable } from "@angular/core";
import { DateRange, MatDateRangeSelectionStrategy } from "@angular/material/datepicker";
import moment from "moment";
import { DateFilterFn, DateRange, MatDateRangeSelectionStrategy } from "@angular/material/datepicker";
import { DateTime } from "luxon";
@Injectable()
export class FDSelection implements MatDateRangeSelectionStrategy<moment.Moment> {
selectionFinished(date: moment.Moment | null): DateRange<moment.Moment> {
export class FDSelection implements MatDateRangeSelectionStrategy<DateTime> {
selectionFinished(date: DateTime | null): DateRange<DateTime> {
return this._cr(date)
}
createPreview(activeDate: moment.Moment | null): DateRange<moment.Moment> {
createPreview(activeDate: DateTime | null): DateRange<DateTime> {
return this._cr(activeDate)
}
private _cr(date: moment.Moment | null) {
private _cr(date: DateTime | null) {
if (date) {
const start = moment(date).startOf('week')
const end = moment(date).isoWeekday(5).endOf('day')
return new DateRange<moment.Moment>(start, end)
const start = date.toUTC().startOf('week')
const end = date.toUTC().set({weekday: 5}).endOf('day')
return new DateRange<DateTime>(start, end)
}
return new DateRange<moment.Moment>(null, null)
return new DateRange<DateTime>(null, null)
}
}
export const weekendFilter = (date: moment.Moment | null): boolean => {
const day = date?.isoWeekday()
export const weekendFilter: DateFilterFn<DateTime | null> = (date: DateTime | null): boolean => {
const day = date?.weekday
return day !== 6 && day !== 7
}

View File

@@ -3,11 +3,10 @@ import { HttpClient } from '@angular/common/http'
import { Menu } from '../types/menu';
import { environment } from 'src/environments/environment';
import { News } from '../types/news';
import moment from 'moment';
import { map } from 'rxjs';
import { UKey } from '../types/key';
import { CleanNote } from '../types/clean-note';
import { Status } from '../types/status';
import { DateTime } from 'luxon';
@Injectable({
providedIn: 'root'
@@ -27,16 +26,16 @@ export class UpdatesService {
return this.http.get<{ hash: string; count: number; }>(environment.apiEndpoint+`/app/news/check`, {withCredentials: true})
}
getMenu(dom: moment.Moment) {
getMenu(dom: string) {
const headers = {
'Content-Type': 'application/json',
}
return this.http.get<Menu>(environment.apiEndpoint+`/app/menu/${dom.valueOf()}`, {headers: headers, withCredentials: true})
return this.http.get<Menu>(environment.apiEndpoint+`/app/menu/${dom}`, {headers: headers, withCredentials: true})
}
postVote(date: moment.Moment, type: "ob" | "kol", vote: "-" | "+" | "n") {
return this.http.post(environment.apiEndpoint+`/app/menu/${date.valueOf()}`, {
doc: moment().toISOString(true),
postVote(date: string, type: "ob" | "kol", vote: "-" | "+" | "n") {
return this.http.post(environment.apiEndpoint+`/app/menu/${date}`, {
doc: DateTime.now(),
tom: type,
vote: vote
}, {withCredentials: true})
@@ -53,12 +52,12 @@ export class UpdatesService {
return this.http.get<UKey[]>(environment.apiEndpoint+`/app/keys`, {withCredentials: true})
}
getClean(date: moment.Moment) {
return this.http.get<{grade: number, notes: CleanNote[], tips: string}>(environment.apiEndpoint+`/app/clean/${date.toISOString()}`, {withCredentials: true})
getClean(date: string) {
return this.http.get<{grade: number, notes: CleanNote[], tips: string}>(environment.apiEndpoint+`/app/clean/${date}`, {withCredentials: true})
}
getNotifCheck() {
return this.http.get<{_id: string, message: {title: string, body: string}, sentDate: moment.Moment}[]>(environment.apiEndpoint+`/app/notif/check`, {withCredentials: true})
return this.http.get<{_id: string, message: {title: string, body: string}, sentDate: string}[]>(environment.apiEndpoint+`/app/notif/check`, {withCredentials: true})
}
postInfoAck(id: string) {

View File

@@ -1,3 +1,5 @@
import { DateTime } from "luxon";
interface UKey {
room: string;
taken: boolean;
@@ -6,8 +8,8 @@ interface UKey {
interface AKey {
room: string;
whom?: {_id: string, uname: string, room: string};
borrow?: moment.Moment;
tb?: moment.Moment;
borrow: DateTime;
tb?: DateTime;
}
export { UKey, AKey }

View File

@@ -1,8 +1,8 @@
import { Moment } from "moment";
import { DateTime } from "luxon";
export interface Menu {
_id: string;
day: Moment;
day: DateTime;
sn: {
fancy: string[];
second: string;

View File

@@ -1,4 +1,4 @@
import { Moment } from "moment";
import { DateTime } from "luxon";
export default interface User {
_id: string;
@@ -10,6 +10,6 @@ export default interface User {
fname?: string;
surname?: string;
groups: string[];
regDate: Moment;
regDate: DateTime;
defaultPage?: string;
}

View File

@@ -1,5 +1,5 @@
export const environment = {
apiEndpoint: "http://localhost:12230",
apiEndpoint: `http://${window.location.hostname}:12230`,
version: "testing",
production: false
};