Refactored the weather-forecast web component and cleaned up main project.
This commit is contained in:
@@ -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,
|
||||
|
||||
+56
-41
@@ -1,49 +1,64 @@
|
||||
<!-- TODO: Kacheln nebeneinander darstellen. -->
|
||||
<div [ngClass]="!dayTime ? 'mws-inline' : ''">
|
||||
<div #outerContainer class="mws-outer-container">
|
||||
<ng-template #errMsg>
|
||||
<h3 class="mws-error">{{ errorMsg }}</h3>
|
||||
<mat-card>
|
||||
<mat-card-header>
|
||||
<mat-card-title>{{ res.strings('web_comp_err_title') }}</mat-card-title>
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<p>{{ errorMsg }}</p>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
</ng-template>
|
||||
<div #innerContainer *ngIf="!errorMsg; else errMsg"
|
||||
class="mws-inner-container clickable"
|
||||
[ngClass]="noBorder ? '' : 'mws-inner-container-border'"
|
||||
(click)="goToMowestaHandler()">
|
||||
<div *ngIf="city" class="mws-header" [matTooltip]="cityTooltip">
|
||||
<mat-icon class="mws-header-icon">place</mat-icon>
|
||||
<div #headerText class="mws-header-text">
|
||||
<h1 class="ellipsis">{{ city }}</h1>
|
||||
<p *ngIf="country" class="ellipsis">{{ country }}</p>
|
||||
<div #innerContainer
|
||||
*ngIf="!errorMsg; else errMsg"
|
||||
class="mws-inner-container">
|
||||
<div class="mws-inner-container clickable"
|
||||
(click)="goToMowestaHandler()">
|
||||
<div *ngIf="city" class="mws-header" [matTooltip]="cityTooltip">
|
||||
<mat-icon class="mws-header-icon">place</mat-icon>
|
||||
<div #headerText class="mws-header-text">
|
||||
<h1 class="ellipsis">{{ city }}</h1>
|
||||
<p *ngIf="country" class="ellipsis">{{ country }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<ng-template #progressBar>
|
||||
<mat-spinner></mat-spinner>
|
||||
</ng-template>
|
||||
<div *ngIf="forecast$ | async as f; else progressBar"
|
||||
class="mws-flexbox">
|
||||
<div class="mws-flexbox">
|
||||
<ng-container *ngFor="let t of f; let i = index">
|
||||
<app-weather-summary *ngIf="i < 2"
|
||||
[noMargin]="!dayTime"
|
||||
[ngClass]="dayTime ? 'mws-side-padding' : ''"
|
||||
[title]="t.title"
|
||||
[subtitle]="t.subtitle"
|
||||
[conditions]="t.conditions"
|
||||
[clickHandler]="goToMowestaHandler">
|
||||
</app-weather-summary>
|
||||
</ng-container>
|
||||
</div>
|
||||
<div class="mws-flexbox">
|
||||
<ng-container *ngFor="let t of f; let i = index">
|
||||
<app-weather-summary *ngIf="i >= 2"
|
||||
[noMargin]="!dayTime"
|
||||
[ngClass]="dayTime ? 'mws-side-padding' : ''"
|
||||
[title]="t.title"
|
||||
[subtitle]="t.subtitle"
|
||||
[conditions]="t.conditions"
|
||||
[clickHandler]="goToMowestaHandler">
|
||||
</app-weather-summary>
|
||||
</ng-container>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<ng-template #progressBar>
|
||||
<mat-spinner></mat-spinner>
|
||||
</ng-template>
|
||||
<div *ngIf="forecast$ | async as f; else progressBar"
|
||||
class="mws-flexbox"
|
||||
[ngClass]="noBackground ? '' : 'mws-content'">
|
||||
<div class="mws-flexbox">
|
||||
<ng-container *ngFor="let t of f; let i = index">
|
||||
<app-weather-summary *ngIf="i < 2"
|
||||
class="mws-summary-box"
|
||||
[title]="t.title"
|
||||
[subtitle]="t.subtitle"
|
||||
[conditions]="t.conditions"
|
||||
[clickHandler]="goToMowestaHandler">
|
||||
</app-weather-summary>
|
||||
</ng-container>
|
||||
</div>
|
||||
<div class="mws-flexbox">
|
||||
<ng-container *ngFor="let t of f; let i = index">
|
||||
<app-weather-summary *ngIf="i >= 2"
|
||||
class="mws-summary-box"
|
||||
[title]="t.title"
|
||||
[subtitle]="t.subtitle"
|
||||
[conditions]="t.conditions"
|
||||
[clickHandler]="goToMowestaHandler">
|
||||
</app-weather-summary>
|
||||
</ng-container>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="!noFooter" class="mws-footer clickable" (click)="goToMowestaHandler()">
|
||||
<h4>Powered by mowesta.com</h4>
|
||||
<div *ngIf="!noFooter" class="mws-footer">
|
||||
<h4>{{ res.strings('web_comp_footer_computed') }}<a href="https://www.dwd.de" target="_blank" class="mws-footer-link">DWD</a>
|
||||
{{ res.strings('web_comp_footer_provided') }}<a href="https://www.mowesta.com" target="_blank" class="mws-footer-link">MoWeSta</a>.
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+11
-5
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+31
-39
@@ -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 {
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<weather-forecast-today city-id="20549" day-time tomorrow></weather-forecast-today>
|
||||
<weather-forecast-today city-id="20549" ></weather-forecast-today>
|
||||
<weather-forecast-today city-id="47620" tomorrow></weather-forecast-today>
|
||||
<weather-forecast-today city-id="47620" day-time tomorrow></weather-forecast-today>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user