File

apps/live-weather/src/app/city-details-container/city-details-container.component.ts

Implements

OnInit

Metadata

selector weather-base-city-details-container
styleUrls ./city-details-container.component.scss
templateUrl ./city-details-container.component.html

Index

Properties
Methods

Constructor

constructor(activatedRoute: ActivatedRoute, dataStoreService: DataStoreService, googlePlacesService: GooglePlacesService, openWeatherService: OpenWeatherService, placesService: PlacesService)

Creates instance of CityDetailsContainerComponent class

Parameters :
Name Type Optional Description
activatedRoute ActivatedRoute No

get access to information a route associated with component

dataStoreService DataStoreService No

instance to store and access data

googlePlacesService GooglePlacesService No

instance to request google place details from google places api

openWeatherService OpenWeatherService No

instance to request weather details from open weather

placesService PlacesService No

instance to request places information

Methods

ngOnInit
ngOnInit()
Returns : void
Public onFavoriteAdd
onFavoriteAdd(place: IPlace)

Add a place to favorite collection

Parameters :
Name Type Optional Description
place IPlace No

to be added to favorite collection

Returns : void

Properties

Public place
Type : IPlace
Public weatherReport
Type : IOpenWeatherReport
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { forkJoin, Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { DataStoreService } from '../core/data-store/data-store.service';

import { GooglePlacesService } from '../core/google-places/google-places.service';
import { OpenWeatherService } from '../core/open-weather/open-weather.service';
import { PlacesService } from '../core/places/places.service';
import { IOpenWeatherReport } from '../shared/models/IOpenWeatherReport';
import { IPlace } from '../shared/models/IPlace';

@Component({
  selector: 'weather-base-city-details-container',
  templateUrl: './city-details-container.component.html',
  styleUrls: ['./city-details-container.component.scss'],
})
/**
 * Provides smart container to display detailed place information
 */
export class CityDetailsContainerComponent implements OnInit {
  public place!: IPlace;

  public weatherReport!: IOpenWeatherReport;

  /**
   * Creates instance of ```CityDetailsContainerComponent``` class
   *
   * @param activatedRoute get access to information a route associated with component
   * @param dataStoreService instance to store and access data
   * @param googlePlacesService instance to request google place details from google places api
   * @param openWeatherService instance to request weather details from open weather
   * @param placesService instance to request places information
   */
  constructor(
    private activatedRoute: ActivatedRoute,

    private dataStoreService: DataStoreService,
    private googlePlacesService: GooglePlacesService,

    private openWeatherService: OpenWeatherService,

    private placesService: PlacesService
  ) { }

  /**
   * @internal
   */
  ngOnInit(): void {
    this.activatedRoute.params.subscribe((params) => {
      this.place = this.placesService.getPlaceById(+params.id);

      const weatherReport = this.openWeatherService.getCurrentWeatherCondition(this.place);
      const placeDetails = this.googlePlacesService.getPlaceImage(this.place);

      forkJoin({
        weatherReport,
        placeDetails,
      })
        .subscribe((results) => {
          if (!results) {
            return;
          }
          this.weatherReport = results.weatherReport || {};
          this.place.photoUrl = results.placeDetails || '';
        });
    });
  }

  /**
   * Add a place to favorite collection
   *
   * @param place to be added to favorite collection
   */
  public onFavoriteAdd(place: IPlace): void {
    this.dataStoreService.addFavoritePlace(place);
  }
}
<div
  fxFill
  class="city-details-container"
  fxLayout="row"
  fxLayout.xs="column"
  fxLayoutAlign="start flex-start"
  fxLayoutAlign.xs="start center"
  fxLayoutGap="2rem"
>
  <weather-base-place-card
    [place]="place"
    [weather]="weatherReport"
    *ngIf="place && weatherReport"
    fxFlex="30%"
    fxFlex.xs="100%"
    (addPlaceToFavorites)="onFavoriteAdd($event)"
  ></weather-base-place-card>

  <weather-base-place-hourly-forecast
    fxFlex="68%"
    fxFlex.xs="100%"
    [place]="place"
    [weather]="weatherReport"
    *ngIf="place && weatherReport"
  ></weather-base-place-hourly-forecast>
  <!-- Place for weeks data-->
</div>

./city-details-container.component.scss

.city-details-container {
  padding: 0.25rem;
  overflow-y: auto;
  height: 100%;
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""