From ffc10b4a24edfd75e6121a2bb1dc71ea46d59df1 Mon Sep 17 00:00:00 2001 From: Adriano Markovic Date: Sun, 24 May 2020 17:20:32 +0200 Subject: [PATCH] Refactored the weather-forecast web component and cleaned up main project. --- .../src/app/app.module.ts | 6 +- .../weather-forecast-today.component.html | 97 +++++++++++-------- .../weather-forecast-today.component.scss | 16 ++- .../weather-forecast-today.component.ts | 70 ++++++------- .../weather-forecast-today/src/index.html | 4 +- web-angular/src/app/app.module.ts | 7 +- web-angular/src/app/app.routing.ts | 6 +- .../src/app/services/resource.service.ts | 16 +++ .../weather-summary.component.html | 33 ++++--- .../weather-summary.component.ts | 1 + 10 files changed, 140 insertions(+), 116 deletions(-) diff --git a/web-angular/projects/weather-forecast-today/src/app/app.module.ts b/web-angular/projects/weather-forecast-today/src/app/app.module.ts index 910780ad..4d7e5981 100644 --- a/web-angular/projects/weather-forecast-today/src/app/app.module.ts +++ b/web-angular/projects/weather-forecast-today/src/app/app.module.ts @@ -20,7 +20,7 @@ import { ResourceService } from '../../../../src/app/services/resource.service import { CityForecastService } from '../../../../src/app/services/city-forecast.service'; import { DefaultService } from '../../../../src/api/api/default.service'; import { Configuration } from '../../../../src/api/configuration'; -import { LocalDatePipe, LocalTimePipe } from '../../../../src/app/pipes/location.pipes'; +import { LocalDatePipe, LocalTimePipe, LocalNamePipe } from '../../../../src/app/pipes/location.pipes'; import { CloudPipe, DirectionIconPipe, @@ -63,6 +63,7 @@ const apidomain = (): { http: string, ws: string } => {     ConditionsDialogComponent,     LocalDatePipe, LocalTimePipe, + LocalNamePipe, CloudPipe, DirectionIconPipe, DirectionPipe, @@ -90,11 +91,10 @@ const apidomain = (): { http: string, ws: string } => { // injection token for http client { provide: Configuration, useValue: new Configuration({ basePath: apidomain().http }) }, { provide: 'wsdomain', useValue: apidomain().ws }, -    ResourceService, -    CityForecastService,     DefaultService,     LocalDatePipe, LocalTimePipe, + LocalNamePipe, CloudPipe, DirectionIconPipe, DirectionPipe, diff --git a/web-angular/projects/weather-forecast-today/src/app/web-component/weather-forecast-today.component.html b/web-angular/projects/weather-forecast-today/src/app/web-component/weather-forecast-today.component.html index 58698b47..b78953d2 100644 --- a/web-angular/projects/weather-forecast-today/src/app/web-component/weather-forecast-today.component.html +++ b/web-angular/projects/weather-forecast-today/src/app/web-component/weather-forecast-today.component.html @@ -1,49 +1,64 @@ + +
-

{{ errorMsg }}

+ + + {{ res.strings('web_comp_err_title') }} + + +

{{ errorMsg }}

+
+
-
-
- place -
-

{{ city }}

-

{{ country }}

+
+
+
+ place +
+

{{ city }}

+

{{ country }}

+
+
+ + + +
+
+ + + + +
+
+ + + + +
- - - -
-
- - - - -
-
- - - - -
-
-
+
diff --git a/web-angular/projects/weather-forecast-today/src/app/web-component/weather-forecast-today.component.scss b/web-angular/projects/weather-forecast-today/src/app/web-component/weather-forecast-today.component.scss index b025ff11..0497eba9 100644 --- a/web-angular/projects/weather-forecast-today/src/app/web-component/weather-forecast-today.component.scss +++ b/web-angular/projects/weather-forecast-today/src/app/web-component/weather-forecast-today.component.scss @@ -1,7 +1,7 @@ @import "styles.scss"; div { padding: 0; } -.mws-error { color: tomato; } +.mws-inline { display: inline-block; } .mws-outer-container { display: flex; flex-flow: row nowrap; @@ -9,7 +9,7 @@ div { padding: 0; } align-items: center; } .mws-inner-container { - display: inline-flex; + display: flex; flex-flow: column nowrap; justify-content: center; align-items: center; @@ -28,8 +28,8 @@ div { padding: 0; } } } } -.mws-content { background: #00695c; } -.mws-summary-box { padding-right: .3rem; padding-left: .3rem; } +//.mws-content { background: #00695c; } +.mws-side-padding { padding-right: .3rem; padding-left: .3rem; } .mws-flexbox { display: inline-flex; flex-flow: row wrap; @@ -37,6 +37,12 @@ div { padding: 0; } } .mws-footer { width: 100%; - background-color: #f9a825; text-align: center; + margin-top: 5px; +} +.mws-footer-link { + color: #003b7a; + &:hover { + text-decoration: underline; + } } diff --git a/web-angular/projects/weather-forecast-today/src/app/web-component/weather-forecast-today.component.ts b/web-angular/projects/weather-forecast-today/src/app/web-component/weather-forecast-today.component.ts index 8689a2f8..c45d7a84 100644 --- a/web-angular/projects/weather-forecast-today/src/app/web-component/weather-forecast-today.component.ts +++ b/web-angular/projects/weather-forecast-today/src/app/web-component/weather-forecast-today.component.ts @@ -17,6 +17,7 @@ import { WeatherConditionSummary } from '../../../../../src/app/services/city-forecast.service'; import {City, DefaultService} from '../../../../../src/app/api'; +import {LocalNamePipe} from "../../../../../src/app/pipes"; /** * Shows the current day forecast for a particular city. The main use is @@ -37,8 +38,8 @@ export class WeatherForecastTodayComponent implements OnInit, AfterViewChecked, @Input() dayTime?: boolean; @Input() noHeader?: boolean; @Input() noFooter?: boolean; - @Input() noBorder?: boolean; - @Input() noBackground?: boolean; + // TODO: Filterung von den Kacheldaten implementieren. + @Input() verbose?: boolean; @ViewChild('outerContainer') outer: ElementRef; @ViewChild('innerContainer') inner: ElementRef; @@ -54,19 +55,20 @@ export class WeatherForecastTodayComponent implements OnInit, AfterViewChecked, private cityReqSubscr: Subscription; private forecastReqErrorSubscr: Subscription; // Fixed values for component width. - private readonly outerBrkPt1 = 1257; - private readonly outerBrkPt2 = 639; + private readonly outerBrkPt1 = 1245; + private readonly outerBrkPt2 = 625; private readonly innerDefault = '1241px'; private readonly innerHeadDef = ''; private readonly innerMedium = '622px'; private readonly innerHeadMd = '450px'; - private readonly innerSmall = '311px'; + private readonly innerSmall = '300px'; private readonly innerHeadSm = '250px'; constructor( public readonly res: ResourceService, private readonly apiClientService: DefaultService, - private readonly cityForecastService: CityForecastService + private readonly cityForecastService: CityForecastService, + private readonly localNamePipe: LocalNamePipe ) { } ngOnInit(): void { @@ -75,21 +77,21 @@ export class WeatherForecastTodayComponent implements OnInit, AfterViewChecked, this.res.setLanguage(this.langCode); this.goToMowestaHandler = () => window .open(`https://www.mowesta.com/app/${this.res.getLanguage()}/weather/cities/${this.cityId}`, '_blank'); - this.cityReqSubscr = this.apiClientService.getCity(this.cityId).subscribe( - (city: City) => { + this.cityReqSubscr = this.apiClientService.getCity(this.cityId).subscribe({ + next: (city: City) => { if (!this.noHeader) { this.setHeaderInfos(city); } const date = new Date(); const period = this.tomorrow ? ForecastPeriod.TOMORROW : ForecastPeriod.TODAY; const { dayForecasts, daytimeForecasts, error } = this.cityForecastService.fetchForecasts(city, date, period); this.forecast$ = this.dayTime ? daytimeForecasts : dayForecasts; this.forecastReqErrorSubscr = error.subscribe( - (forecastErr: any) => this.handleErrorMsg(forecastErr, 'An Error occured while fetching forecast information.') + (forecastErr: any) => this.handleErrorMsg(forecastErr, this.res.strings('web_comp_err_fetch_forecast')) ); }, - (cityErr: any) => this.handleErrorMsg(cityErr, 'An Error occured while fetching city information.') - ); + error: (cityErr: any) => this.handleErrorMsg(cityErr, this.res.strings('web_comp_err_fetch_city')) + }); } else { - this.errorMsg = 'You have to specify a city id!'; + this.errorMsg = this.res.strings('web_comp_err_no_city_id'); } } @@ -113,14 +115,13 @@ export class WeatherForecastTodayComponent implements OnInit, AfterViewChecked, this.dayTime = this.dayTime !== undefined; this.noHeader = this.noHeader !== undefined; this.noFooter = this.noFooter !== undefined; - this.noBorder = this.noBorder !== undefined; - this.noBackground = this.noBackground !== undefined; + this.verbose = this.verbose !== undefined; } private setHeaderInfos(city: City): void { - this.city = this.getLocationName(city.names); - const stateName = this.getLocationName(city.state?.names); - const countryName = this.getLocationName(city.country?.names); + this.city = this.localNamePipe.transform(city.names); + const stateName = this.localNamePipe.transform(city.state?.names, true); + const countryName = this.localNamePipe.transform(city.country?.names, true); if (stateName && countryName) { this.country = `${stateName}, ${countryName}`; } else if (stateName || countryName) { @@ -130,12 +131,6 @@ export class WeatherForecastTodayComponent implements OnInit, AfterViewChecked, : `${this.city}, ${this.country}`; } - private getLocationName(locationNames?: any): string { - let name = locationNames[this.langCode] as string; - if (!name) { name = locationNames.local as string; } - return name; - } - private handleErrorMsg(error: any, errorMsg: string): void { if (error) { this.errorMsg = errorMsg; } } @@ -144,32 +139,29 @@ export class WeatherForecastTodayComponent implements OnInit, AfterViewChecked, const outerDiv: HTMLDivElement = this.outer?.nativeElement; const innerDiv: HTMLDivElement = this.inner?.nativeElement; if (!outerDiv || !innerDiv) { return; } + let headerTextSize: string; + let innerDivMaxWidth: string; if (this.dayTime) { // Needs to check container size due to multiple tiles. if (this.outerBrkPt2 < outerDiv.clientWidth && outerDiv.clientWidth <= this.outerBrkPt1) { - this.setHeaderTextSize(this.innerHeadMd); - if (innerDiv.style.maxWidth !== this.innerMedium) { - innerDiv.style.maxWidth = this.innerMedium; - } + headerTextSize = this.innerHeadMd; + innerDivMaxWidth = this.innerMedium; } else if (outerDiv.clientWidth <= this.outerBrkPt2) { - this.setHeaderTextSize(this.innerHeadSm); - if (innerDiv.style.maxWidth !== this.innerSmall) { - innerDiv.style.maxWidth = this.innerSmall; - } + headerTextSize = this.innerHeadSm; + innerDivMaxWidth = this.innerSmall; } else { - this.setHeaderTextSize(this.innerHeadDef); - if (innerDiv.style.maxWidth !== this.innerDefault) { - innerDiv.style.maxWidth = this.innerDefault; - } + headerTextSize = this.innerHeadDef; + innerDivMaxWidth = this.innerDefault; } } else { // Container size always set to small because there is only one tile. - this.setHeaderTextSize(this.innerHeadSm); - if (innerDiv.style.maxWidth !== this.innerSmall) { - innerDiv.style.maxWidth = this.innerSmall; - } + headerTextSize = this.innerHeadSm; + innerDivMaxWidth = this.innerSmall; } + + this.setHeaderTextSize(headerTextSize); + if (innerDiv.style.maxWidth !== innerDivMaxWidth) { innerDiv.style.maxWidth = innerDivMaxWidth; } } private setHeaderTextSize(newSize: string): void { diff --git a/web-angular/projects/weather-forecast-today/src/index.html b/web-angular/projects/weather-forecast-today/src/index.html index 27f15d56..0e0b7ec1 100644 --- a/web-angular/projects/weather-forecast-today/src/index.html +++ b/web-angular/projects/weather-forecast-today/src/index.html @@ -7,6 +7,8 @@ - + + + diff --git a/web-angular/src/app/app.module.ts b/web-angular/src/app/app.module.ts index bbd2a390..78f14257 100644 --- a/web-angular/src/app/app.module.ts +++ b/web-angular/src/app/app.module.ts @@ -46,7 +46,7 @@ import { ToolbarButtonComponent, DecisionPanelComponent, EmailFieldComponent, La import { CitiesListComponent, WeatherConditionComponent, WeatherVideoComponent, WeatherVideoBarComponent, WeatherVideoListComponent, WeatherStationsListComponent, WeatherReportsListComponent, WeatherReportComponent, WeatherSummaryComponent, WeatherDiagramComponent } from './widgets-weather'; -import { LoginComponent, ActivateComponent, ChangeComponent, RegisterComponent, ResetComponent, +import { LoginComponent, ActivateComponent, ChangeComponent, RegisterComponent, ResetComponent, LoadingComponent } from './views-common'; import { CitiesComponent, CityComponent, CountryComponent, StateComponent, VideosComponent, StationsComponent, StationComponent } from './views-weather'; @@ -71,9 +71,6 @@ import { HumidityPipe, CloudPipe, PressurePipe, TemperaturePipe, SpeedPipe, Snow GoogleMapsPipe, WikipediaPipe, CityTypePipe, VideoSourcePipe, VideoTypePipe, LocationIconPipe, WeatherIconPipe, DirectionIconPipe, MeasurementTypePipe, MeasurementTypeIconPipe, OsIconPipe } from './pipes'; -// TODO: Remove -import { TestSiteComponent } from './test-site/test-site.component'; - /** * Computes the api domain from the browser location. @@ -120,8 +117,6 @@ registerLocaleData(LocaleDE); UseParentFormDirective, ClickButtonComponent, CodeDialogComponent, - // TODO: Remove - TestSiteComponent ], imports: [ BrowserModule, BrowserAnimationsModule, diff --git a/web-angular/src/app/app.routing.ts b/web-angular/src/app/app.routing.ts index 6e9f3120..2e742cf4 100644 --- a/web-angular/src/app/app.routing.ts +++ b/web-angular/src/app/app.routing.ts @@ -8,16 +8,12 @@ import { CityComponent, StateComponent, CountryComponent, CitiesComponent, Video StationsComponent, StationComponent } from './views-weather'; import { UserDevicesComponent, UserAccountComponent, UserFavoritesComponent, UserDeviceComponent } from './views-user'; import { ManageLogComponent, ManageSystemComponent, ManageUsersComponent } from './views-manage'; -import { CityResolver, StateResolver, CountryResolver, UserResolver, StationResolver, LanguageResolver, +import { CityResolver, StateResolver, CountryResolver, UserResolver, StationResolver, LanguageResolver, BootstrapResolver, DeviceResolver} from './resolvers'; -// TODO: Remove -import { TestSiteComponent } from './test-site/test-site.component'; export const routes: Routes = [ - // TODO: Remove - { path: 'web-test', component: TestSiteComponent }, // backwards compatibility { path: 'activate/:token', resolve: { bs: BootstrapResolver}, component: LoadingComponent }, { path: 'reset/:token', resolve: { bs: BootstrapResolver}, component: LoadingComponent }, diff --git a/web-angular/src/app/services/resource.service.ts b/web-angular/src/app/services/resource.service.ts index ec9361bb..a1762f7a 100644 --- a/web-angular/src/app/services/resource.service.ts +++ b/web-angular/src/app/services/resource.service.ts @@ -117,6 +117,7 @@ export class ResourceService { 'label_yesterday' : 'Gestern', 'label_today' : 'Heute', 'label_tomorrow' : 'Morgen', + 'city_code_dialog_title': 'Wettervorhersagen einbetten', 'city_code_dialog_stylesheet': 'Das Stylesheet verlinken.', 'city_code_dialog_scripts': 'Die Skripte einbetten.', @@ -125,6 +126,13 @@ export class ResourceService { 'city_code_dialog_example': 'Beispiel', 'city_code_dialog_default_lang': 'Standard: lang-code="de"', + 'web_comp_err_title': 'Fehler', + 'web_comp_err_no_city_id': 'Das Attribut "city-id" darf nicht leer sein!', + 'web_comp_err_fetch_city': 'Dienst momentan nicht erreichbar! Stadt kann nicht abgerufen werden.', + 'web_comp_err_fetch_forecast': 'Dienst momentan nicht erreichbar! Wettervorhersage kann nicht abgerufen werden.', + 'web_comp_footer_computed': 'Vorhersage berechnet vom ', + 'web_comp_footer_provided': ' und bereitgestellt von ', + 'station_title': 'Station', 'station_latest_report' : 'Letzte Messung', @@ -545,6 +553,7 @@ export class ResourceService { 'label_yesterday' : 'Yesterday', 'label_today' : 'Today', 'label_tomorrow' : 'Tomorrow', + 'city_code_dialog_title': 'Embed Weather Forecasts', 'city_code_dialog_stylesheet': 'Link the stylesheet.', 'city_code_dialog_scripts': 'Embed the scripts.', @@ -553,6 +562,13 @@ export class ResourceService { 'city_code_dialog_example': 'Example', 'city_code_dialog_default_lang': 'Default: lang-code="de"', + 'web_comp_err_title': 'Error', + 'web_comp_err_no_city_id': 'The Attribute "city-id" must not be empty!', + 'web_comp_err_fetch_city': 'Service currently not available! Cannot fetch city data.', + 'web_comp_err_fetch_forecast': 'Service currently not available! Cannot fetch any forecast data.', + 'web_comp_footer_computed': 'Forecast computed by ', + 'web_comp_footer_provided': ' and provided by ', + 'station_title': 'Station', 'station_latest_report' : 'Latest Measurement', diff --git a/web-angular/src/app/widgets-weather/weather-summary.component.html b/web-angular/src/app/widgets-weather/weather-summary.component.html index 1d158b2c..594a5128 100644 --- a/web-angular/src/app/widgets-weather/weather-summary.component.html +++ b/web-angular/src/app/widgets-weather/weather-summary.component.html @@ -1,48 +1,49 @@ - +
-
{{ displayTitle }}
+
{{ displayTitle }}
{{ displaySubtitle }}
{{ max.type | weather }}
-
{{ min.temperature | temperature }}
-
{{ max.temperature | temperature }}
+
{{ min.temperature | temperature }}
+
{{ max.temperature | temperature }}
-
{{ min.precipitation | precipitation }}
-
{{ max.precipitation | precipitation }}
+
{{ min.precipitation | precipitation }}
+
{{ max.precipitation | precipitation }}
-
{{ min.windSpeed | speed }}
-
{{ max.windSpeed | speed }}
+
{{ min.windSpeed | speed }}
+
{{ max.windSpeed | speed }}
-
{{ min.cloudCoverage | cloud }}
-
{{ max.cloudCoverage | cloud }}
+
{{ min.cloudCoverage | cloud }}
+
{{ max.cloudCoverage | cloud }}
-
{{ min.humidity | humidity }}
-
{{ max.humidity | humidity }}
+
{{ min.humidity | humidity }}
+
{{ max.humidity | humidity }}
-
{{ min.snowDepth | snow }}
-
{{ max.snowDepth | snow }}
+
{{ min.snowDepth | snow }}
+
{{ max.snowDepth | snow }}
-
{{ min.pressure | pressure }}
-
{{ max.pressure | pressure }}
+
{{ min.pressure | pressure }}
+
{{ max.pressure | pressure }}
diff --git a/web-angular/src/app/widgets-weather/weather-summary.component.ts b/web-angular/src/app/widgets-weather/weather-summary.component.ts index c2da9703..3e988b93 100644 --- a/web-angular/src/app/widgets-weather/weather-summary.component.ts +++ b/web-angular/src/app/widgets-weather/weather-summary.component.ts @@ -20,6 +20,7 @@ export class WeatherSummaryComponent implements OnInit, OnChanges { @Input() title: string; @Input() subtitle: string; @Input() clickHandler: () => void; + @Input() noMargin: boolean; min: WeatherCondition = null; max: WeatherCondition = null;