From 7effd5badba36f1f002cd8d89ffe2a4662f2ec20 Mon Sep 17 00:00:00 2001 From: Erick Blanco Date: Wed, 19 Aug 2020 12:47:20 -0600 Subject: [PATCH 1/2] Statistics service removed from StatsCards component --- .../core/stats-cards/stats-cards.component.ts | 32 +++---------------- .../country-page/country-page.component.html | 2 +- .../country-page/country-page.component.ts | 19 +++++++++-- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/src/app/components/core/stats-cards/stats-cards.component.ts b/src/app/components/core/stats-cards/stats-cards.component.ts index 099fa97..46f7516 100644 --- a/src/app/components/core/stats-cards/stats-cards.component.ts +++ b/src/app/components/core/stats-cards/stats-cards.component.ts @@ -1,40 +1,16 @@ -import { Subscription } from 'rxjs'; -import { Component, OnInit, HostBinding, OnDestroy, Input } from '@angular/core'; -import { StatisticsService } from '@pk-services/statistics/statistics.service'; +import { Component, OnInit, HostBinding, Input } from '@angular/core'; @Component({ selector: 'pk-stats-cards', templateUrl: './stats-cards.component.html', styleUrls: ['./stats-cards.component.sass'] }) -export class StatsCardsComponent implements OnInit, OnDestroy { +export class StatsCardsComponent implements OnInit { @HostBinding() class = 'row mt-3'; - stats: any[]; - sub: Subscription = new Subscription(); - @Input('country') country: string; + @Input('stats') stats: any[]; - constructor(private statsService: StatisticsService) { } + constructor() { } ngOnInit(): void { - this.onDataLoad(); - } - - onDataLoad() { - if (this.country) { - this.sub.add( - this.statsService.getCountryStatistics(this.country).subscribe((stats) => { - this.stats = stats; - }) - ); - } else { - this.sub.add(this.statsService.getStatistics().subscribe((stats) => { - this.stats = stats; - console.log('dev', stats); - })); - } - } - - ngOnDestroy() { - this.sub.unsubscribe(); } } diff --git a/src/app/components/pages/country-page/country-page.component.html b/src/app/components/pages/country-page/country-page.component.html index ce5ffb5..cdf4421 100644 --- a/src/app/components/pages/country-page/country-page.component.html +++ b/src/app/components/pages/country-page/country-page.component.html @@ -1,4 +1,4 @@

{{ countryName }}'s Statistics

- +
\ No newline at end of file diff --git a/src/app/components/pages/country-page/country-page.component.ts b/src/app/components/pages/country-page/country-page.component.ts index 71565ae..8fe1089 100644 --- a/src/app/components/pages/country-page/country-page.component.ts +++ b/src/app/components/pages/country-page/country-page.component.ts @@ -1,21 +1,34 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, OnDestroy } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; +import { StatisticsService } from '@pk-services/statistics/statistics.service'; +import { Subscription } from 'rxjs'; @Component({ selector: 'app-country-page', templateUrl: './country-page.component.html', styleUrls: ['./country-page.component.sass'] }) -export class CountryPageComponent implements OnInit { +export class CountryPageComponent implements OnInit, OnDestroy { + stats: any[]; countryName: string; + subscription: Subscription; constructor( - private route: ActivatedRoute + private route: ActivatedRoute, + private statistics: StatisticsService ) { } ngOnInit(): void { this.countryName = this.route.snapshot.params.country; + this.subscription = this.statistics.getCountryStatistics(this.countryName) + .subscribe(stats => this.stats = stats); } + ngOnDestroy(): void { + if (this.subscription) { + this.subscription.unsubscribe(); + } + } + } From 57596c0ed6bdcf9053edf6ffb6dd0f2645d5c872 Mon Sep 17 00:00:00 2001 From: Erick Blanco Date: Wed, 19 Aug 2020 14:52:24 -0600 Subject: [PATCH 2/2] Infection rates cards --- src/app/app.module.ts | 4 +- .../rates-cards/rates-cards.component.html | 12 +++++ .../rates-cards/rates-cards.component.sass | 14 ++++++ .../rates-cards/rates-cards.component.spec.ts | 25 ++++++++++ .../core/rates-cards/rates-cards.component.ts | 46 +++++++++++++++++++ .../country-page/country-page.component.html | 18 ++++++++ .../country-page/country-page.component.sass | 5 +- .../country-page/country-page.component.ts | 13 ++++-- 8 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 src/app/components/core/rates-cards/rates-cards.component.html create mode 100644 src/app/components/core/rates-cards/rates-cards.component.sass create mode 100644 src/app/components/core/rates-cards/rates-cards.component.spec.ts create mode 100644 src/app/components/core/rates-cards/rates-cards.component.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 6d9ba28..6a52d06 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -23,6 +23,7 @@ import { ChipComponent } from './components/common/chip/chip.component'; import { ThemeService } from '@pk-services/theme/theme.service'; import { FilterPipe } from './pipes/filter.pipe'; import { StatsCardsComponent } from './components/core/stats-cards/stats-cards.component'; +import { RatesCardsComponent } from './components/core/rates-cards/rates-cards.component'; export function themeFactory(themeService: ThemeService) { return () => themeService.setInitialTheme(); @@ -40,7 +41,8 @@ export function themeFactory(themeService: ThemeService) { ChipComponent, GlobalStatsCardsComponent, FilterPipe, - StatsCardsComponent + StatsCardsComponent, + RatesCardsComponent ], imports: [ BrowserModule, diff --git a/src/app/components/core/rates-cards/rates-cards.component.html b/src/app/components/core/rates-cards/rates-cards.component.html new file mode 100644 index 0000000..df4bd0e --- /dev/null +++ b/src/app/components/core/rates-cards/rates-cards.component.html @@ -0,0 +1,12 @@ +
+
+
+

{{ rate.title }}

+
+
+ {{ rate.rate | percent : '1.2-2' }} +
+
+
+
+
\ No newline at end of file diff --git a/src/app/components/core/rates-cards/rates-cards.component.sass b/src/app/components/core/rates-cards/rates-cards.component.sass new file mode 100644 index 0000000..cf223bc --- /dev/null +++ b/src/app/components/core/rates-cards/rates-cards.component.sass @@ -0,0 +1,14 @@ +@import 'variables' + +.rate-text + font-weight: bolder + font-size: 2.5em + font-family: $font-raleway + &.infections + color: $color-blue + &.deaths + color: $color-red + &.recoveries + color: $color-green + &.critical + color: $color-yellow \ No newline at end of file diff --git a/src/app/components/core/rates-cards/rates-cards.component.spec.ts b/src/app/components/core/rates-cards/rates-cards.component.spec.ts new file mode 100644 index 0000000..92b33c5 --- /dev/null +++ b/src/app/components/core/rates-cards/rates-cards.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { RatesCardsComponent } from './rates-cards.component'; + +describe('RatesCardsComponent', () => { + let component: RatesCardsComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ RatesCardsComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(RatesCardsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/components/core/rates-cards/rates-cards.component.ts b/src/app/components/core/rates-cards/rates-cards.component.ts new file mode 100644 index 0000000..2b295df --- /dev/null +++ b/src/app/components/core/rates-cards/rates-cards.component.ts @@ -0,0 +1,46 @@ +import { Component, OnInit, Input } from '@angular/core'; + +@Component({ + selector: 'pk-rates-cards', + templateUrl: './rates-cards.component.html', + styleUrls: ['./rates-cards.component.sass'] +}) +export class RatesCardsComponent implements OnInit { + + @Input('rates') set rates(rates: any) { + if (rates) + this._rates = this.getRates(rates); + }; + _rates: any[]; + + constructor() { } + + ngOnInit(): void { + } + + getRates(rates: any) { + return [ + { + title: 'Recovery Rate', + class: 'recoveries', + rate: rates.recoveryRate + }, + { + title: 'Death Rate', + class: 'deaths', + rate: rates.deathRate + }, + { + title: 'Critical Rate', + class: 'critical', + rate: rates.criticalRate + }, + { + title: 'Non-Critical Rate', + class: 'infections', + rate: 1 - rates.criticalRate + }, + ] + } + +} diff --git a/src/app/components/pages/country-page/country-page.component.html b/src/app/components/pages/country-page/country-page.component.html index cdf4421..c3f3fef 100644 --- a/src/app/components/pages/country-page/country-page.component.html +++ b/src/app/components/pages/country-page/country-page.component.html @@ -1,4 +1,22 @@

{{ countryName }}'s Statistics

+ +
+
+
+ +
+
+ +
+
+

Infection Rates

+
+ +
+
+
+
+
\ No newline at end of file diff --git a/src/app/components/pages/country-page/country-page.component.sass b/src/app/components/pages/country-page/country-page.component.sass index 0d8fd91..41d2cdc 100644 --- a/src/app/components/pages/country-page/country-page.component.sass +++ b/src/app/components/pages/country-page/country-page.component.sass @@ -4,4 +4,7 @@ min-height: calc(100vh - 55px) .title margin: 0 - font-size: 7em \ No newline at end of file + font-size: 7em + + .rates-container + padding: 19px \ No newline at end of file diff --git a/src/app/components/pages/country-page/country-page.component.ts b/src/app/components/pages/country-page/country-page.component.ts index 8fe1089..5d6bac0 100644 --- a/src/app/components/pages/country-page/country-page.component.ts +++ b/src/app/components/pages/country-page/country-page.component.ts @@ -11,6 +11,7 @@ import { Subscription } from 'rxjs'; export class CountryPageComponent implements OnInit, OnDestroy { stats: any[]; + rates: any; countryName: string; subscription: Subscription; @@ -22,13 +23,19 @@ export class CountryPageComponent implements OnInit, OnDestroy { ngOnInit(): void { this.countryName = this.route.snapshot.params.country; this.subscription = this.statistics.getCountryStatistics(this.countryName) - .subscribe(stats => this.stats = stats); + .subscribe(stats => { + this.stats = stats + this.rates = { + deathRate: stats[1].rate, + recoveryRate: stats[2].rate, + criticalRate: stats[3].rate + } + }); } ngOnDestroy(): void { - if (this.subscription) { + if (this.subscription) this.subscription.unsubscribe(); - } } }