From 16468ba950ba36fed841545fd8edcddecc4e20c5 Mon Sep 17 00:00:00 2001 From: tim-herbst Date: Sat, 2 Jan 2021 16:28:43 +0100 Subject: [PATCH] refactor miniMap to component --- .../project-3/frontend/src/app/app.module.ts | 4 ++- .../app/dashboard/dashboard.component.html | 8 +---- .../src/app/dashboard/dashboard.component.ts | 34 ++---------------- .../mini-map/mini-map.component.html | 7 ++++ .../mini-map/mini-map.component.scss | 4 +++ .../mini-map/mini-map.component.spec.ts | 25 +++++++++++++ .../dashboard/mini-map/mini-map.component.ts | 36 +++++++++++++++++++ .../user-input/user-input.component.ts | 1 + 8 files changed, 80 insertions(+), 39 deletions(-) create mode 100644 projects/project-3/frontend/src/app/dashboard/mini-map/mini-map.component.html create mode 100644 projects/project-3/frontend/src/app/dashboard/mini-map/mini-map.component.scss create mode 100644 projects/project-3/frontend/src/app/dashboard/mini-map/mini-map.component.spec.ts create mode 100644 projects/project-3/frontend/src/app/dashboard/mini-map/mini-map.component.ts diff --git a/projects/project-3/frontend/src/app/app.module.ts b/projects/project-3/frontend/src/app/app.module.ts index 735ee4c..31ef684 100644 --- a/projects/project-3/frontend/src/app/app.module.ts +++ b/projects/project-3/frontend/src/app/app.module.ts @@ -33,6 +33,7 @@ import { TableComponent } from './dashboard/table/table.component'; import { RentDurationChartComponent } from './dashboard/rent-duration-chart/rent-duration-chart.component'; import { RentTimeChartComponent } from './dashboard/rent-time-chart/rent-time-chart.component'; import { UserInputComponent } from './dashboard/user-input/user-input.component'; +import { MiniMapComponent } from './dashboard/mini-map/mini-map.component'; @NgModule({ declarations: [ @@ -44,7 +45,8 @@ import { UserInputComponent } from './dashboard/user-input/user-input.component' TableComponent, RentDurationChartComponent, RentTimeChartComponent, - UserInputComponent + UserInputComponent, + MiniMapComponent ], imports: [ BrowserModule, diff --git a/projects/project-3/frontend/src/app/dashboard/dashboard.component.html b/projects/project-3/frontend/src/app/dashboard/dashboard.component.html index 42ec912..e10fb12 100644 --- a/projects/project-3/frontend/src/app/dashboard/dashboard.component.html +++ b/projects/project-3/frontend/src/app/dashboard/dashboard.component.html @@ -24,13 +24,7 @@ (startEndDate)="onSubmit($event)" > - -
-
-
-
-
-
+
diff --git a/projects/project-3/frontend/src/app/dashboard/dashboard.component.ts b/projects/project-3/frontend/src/app/dashboard/dashboard.component.ts index 50b22f7..f654e13 100644 --- a/projects/project-3/frontend/src/app/dashboard/dashboard.component.ts +++ b/projects/project-3/frontend/src/app/dashboard/dashboard.component.ts @@ -1,8 +1,5 @@ -import {ChangeDetectionStrategy, Component, Injectable, OnInit, ViewChild} from '@angular/core'; -import {ActivatedRoute, Router} from '@angular/router'; -import {DashboardService} from '../service/dashboard.service'; +import {ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/core'; import {IDashboardCommonBikePoint} from '../service/domain/dashboard-common-bike-point'; -import {MapService} from '../service/map.service'; import { @@ -19,8 +16,6 @@ import { ApexXAxis, ApexYAxis } from 'ng-apexcharts'; -import {DateAdapter, MAT_DATE_FORMATS, NativeDateAdapter} from '@angular/material/core'; -import {formatDate} from '@angular/common'; import {TableComponent} from './table/table.component'; import {RentDurationChartComponent} from './rent-duration-chart/rent-duration-chart.component'; import {RentTimeChartComponent} from './rent-time-chart/rent-time-chart.component'; @@ -52,38 +47,15 @@ const chartHeight = 460; changeDetection: ChangeDetectionStrategy.Default, }) export class DashboardComponent implements OnInit { + @ViewChild(TableComponent) table: TableComponent; @ViewChild(RentDurationChartComponent) durationChart: RentDurationChartComponent; @ViewChild(RentTimeChartComponent) timeChart: RentTimeChartComponent; - public bikePointChartOptions: Partial; - - station: IDashboardCommonBikePoint; - maxStartDate: Date; - maxEndDate: Date; - - constructor( - private route: ActivatedRoute, - private router: Router, - private service: DashboardService, - private map: MapService, - ) { + constructor() { } ngOnInit(): void { - this.route.params.subscribe(params => { - this.service.fetchDashboardInit(params.id).then(data => { - this.station = data; - this.maxStartDate = new Date(data.maxStartDate); - this.maxEndDate = new Date(data.maxEndDate); - this.initDashboard(); - }); - }); - } - - async initDashboard(): Promise { - this.map.initDashboardMap(this.station.lat, this.station.lon, 17); - this.map.drawDashboardStationMarker(this.station); } async onSubmit(startEndDate: StartEndDate): Promise { diff --git a/projects/project-3/frontend/src/app/dashboard/mini-map/mini-map.component.html b/projects/project-3/frontend/src/app/dashboard/mini-map/mini-map.component.html new file mode 100644 index 0000000..5b03655 --- /dev/null +++ b/projects/project-3/frontend/src/app/dashboard/mini-map/mini-map.component.html @@ -0,0 +1,7 @@ + +
+
+
+
+
+
diff --git a/projects/project-3/frontend/src/app/dashboard/mini-map/mini-map.component.scss b/projects/project-3/frontend/src/app/dashboard/mini-map/mini-map.component.scss new file mode 100644 index 0000000..b0bd2eb --- /dev/null +++ b/projects/project-3/frontend/src/app/dashboard/mini-map/mini-map.component.scss @@ -0,0 +1,4 @@ +.mat-card { + padding: 1px 1px 1px; + margin: 10px; +} diff --git a/projects/project-3/frontend/src/app/dashboard/mini-map/mini-map.component.spec.ts b/projects/project-3/frontend/src/app/dashboard/mini-map/mini-map.component.spec.ts new file mode 100644 index 0000000..33dd02b --- /dev/null +++ b/projects/project-3/frontend/src/app/dashboard/mini-map/mini-map.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { MiniMapComponent } from './mini-map.component'; + +describe('MiniMapComponent', () => { + let component: MiniMapComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ MiniMapComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(MiniMapComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/projects/project-3/frontend/src/app/dashboard/mini-map/mini-map.component.ts b/projects/project-3/frontend/src/app/dashboard/mini-map/mini-map.component.ts new file mode 100644 index 0000000..fe20e69 --- /dev/null +++ b/projects/project-3/frontend/src/app/dashboard/mini-map/mini-map.component.ts @@ -0,0 +1,36 @@ +import { Component, OnInit } from '@angular/core'; +import {IDashboardCommonBikePoint} from '../../service/domain/dashboard-common-bike-point'; +import {ActivatedRoute} from '@angular/router'; +import {DashboardService} from '../../service/dashboard.service'; +import {MapService} from '../../service/map.service'; + +@Component({ + selector: 'app-mini-map', + templateUrl: './mini-map.component.html', + styleUrls: ['./mini-map.component.scss'] +}) +export class MiniMapComponent implements OnInit { + + bikePoint: IDashboardCommonBikePoint; + + constructor( + private route: ActivatedRoute, + private service: DashboardService, + private map: MapService + ) { } + + ngOnInit(): void { + this.route.params.subscribe(params => { + this.service.fetchDashboardInit(params.id).then(data => { + this.bikePoint = data; + this.initMap(); + }); + }); + } + + initMap(): void { + this.map.initDashboardMap(this.bikePoint.lat, this.bikePoint.lon, 17); + this.map.drawDashboardStationMarker(this.bikePoint); + } + +} diff --git a/projects/project-3/frontend/src/app/dashboard/user-input/user-input.component.ts b/projects/project-3/frontend/src/app/dashboard/user-input/user-input.component.ts index 481bfb4..1f7f7f7 100644 --- a/projects/project-3/frontend/src/app/dashboard/user-input/user-input.component.ts +++ b/projects/project-3/frontend/src/app/dashboard/user-input/user-input.component.ts @@ -74,6 +74,7 @@ export interface StartEndDate { ] }) export class UserInputComponent implements OnInit { + @Output() startEndDate: EventEmitter = new EventEmitter(); chartOptions: Partial;