From 65b5fb8a90d420f9b6442bf3615f33f2128ef8b1 Mon Sep 17 00:00:00 2001 From: Artur Savitskiy Date: Fri, 29 Mar 2024 23:50:14 +0100 Subject: [PATCH] Fix visits routing date time --- frontend/angular.json | 5 ++- frontend/package-lock.json | 12 +++++++ frontend/src/app/app-routing.module.ts | 3 +- .../app/components/visits/visits.component.ts | 36 ++++++++----------- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/frontend/angular.json b/frontend/angular.json index db6a97e..c262ba7 100644 --- a/frontend/angular.json +++ b/frontend/angular.json @@ -91,6 +91,9 @@ } }, "cli": { - "schematicCollections": ["@angular-eslint/schematics"] + "schematicCollections": [ + "@angular-eslint/schematics" + ], + "analytics": false } } diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 9b5aea5..db8618a 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -11087,6 +11087,12 @@ "node": ">=10.17.0" } }, + "node_modules/iban": { + "version": "0.0.14", + "resolved": "https://registry.npmjs.org/iban/-/iban-0.0.14.tgz", + "integrity": "sha512-+rocNKk+Ga9m8Lr9fTMWd+87JnsBrucm0ZsIx5ROOarZlaDLmd+FKdbtvb0XyoBw9GAFOYG2GuLqoNB16d+p3w==", + "peer": true + }, "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -27392,6 +27398,12 @@ "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", "dev": true }, + "iban": { + "version": "0.0.14", + "resolved": "https://registry.npmjs.org/iban/-/iban-0.0.14.tgz", + "integrity": "sha512-+rocNKk+Ga9m8Lr9fTMWd+87JnsBrucm0ZsIx5ROOarZlaDLmd+FKdbtvb0XyoBw9GAFOYG2GuLqoNB16d+p3w==", + "peer": true + }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", diff --git a/frontend/src/app/app-routing.module.ts b/frontend/src/app/app-routing.module.ts index ba8913f..55e1b77 100644 --- a/frontend/src/app/app-routing.module.ts +++ b/frontend/src/app/app-routing.module.ts @@ -1,5 +1,5 @@ import { NgModule } from '@angular/core'; -import { RouterModule, Routes } from '@angular/router'; +import { RouterModule, Routes, provideRouter, withComponentInputBinding } from '@angular/router'; import { StudentListComponent } from './components/students/student-list/student-list.component'; import { VisitsComponent } from './components/visits/visits.component'; import { VisitsDatetimeComponent } from './components/visits/visits-datetime/visits-datetime.component'; @@ -15,5 +15,6 @@ const routes: Routes = [ @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule], + providers: [provideRouter(routes, withComponentInputBinding())] }) export class AppRoutingModule {} diff --git a/frontend/src/app/components/visits/visits.component.ts b/frontend/src/app/components/visits/visits.component.ts index 4d8f298..f843c60 100644 --- a/frontend/src/app/components/visits/visits.component.ts +++ b/frontend/src/app/components/visits/visits.component.ts @@ -1,5 +1,5 @@ import { formatDate } from '@angular/common'; -import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Component, Input, OnDestroy, OnInit } from '@angular/core'; import { MatTableDataSource } from '@angular/material/table'; import { ActivatedRoute } from '@angular/router'; import { Subscription } from 'rxjs'; @@ -16,14 +16,17 @@ import { VisitsService } from 'src/app/services/visits/visits.service'; templateUrl: './visits.component.html', styleUrls: ['./visits.component.scss'], }) -export class VisitsComponent implements OnInit, OnDestroy { +export class VisitsComponent implements OnInit { + @Input() + public date!: string; + @Input() + public time!: string; + public loading: boolean = true; public courseVisit?: CourseVisit; public dataSource = new MatTableDataSource(); - public addedStudent?: Student; - private routerSubscription?: Subscription; private courseDate: Date = new Date(); public constructor( @@ -33,26 +36,17 @@ export class VisitsComponent implements OnInit, OnDestroy { ) {} public ngOnInit() { - this.routerSubscription = this.route.params.subscribe(params => { - const date: string = params['date']; - const time: string = params['time']; + if (this.date?.length == 8 && this.time?.length >= 3) { + const fulltime = this.time.padStart(4, '0'); + const datetime = `${this.date.substring(0, 4)}-${this.date.substring(4, 6)}-${this.date.substring(6, 8)} ${fulltime.substring(0, 2)}:${fulltime.substring(2, 4)}:00`; - if (date?.length == 8 && time?.length >= 3) { - const fulltime = time.padStart(4, '0'); - const datetime = `${date.substring(0, 4)}-${date.substring(4, 6)}-${date.substring(6, 8)} ${fulltime.substring(0, 2)}:${fulltime.substring(2, 4)}:00`; - - const dateobj = new Date(datetime); - if (dateobj) { - this.courseDate = dateobj; - } + const dateobj = new Date(datetime); + if (dateobj) { + this.courseDate = dateobj; } + } - this.getData(); - }); - } - - public ngOnDestroy() { - this.routerSubscription?.unsubscribe(); + this.getData(); } public visit(studentVisit: StudentVisit): void {