From af44e1fd3e2627f4cd7c53214da223da62ffe68a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Varandas?= Date: Sun, 7 Oct 2018 23:09:04 +0100 Subject: [PATCH] feat(history): adds history page provides a page to read all the history events fixes #15 --- src/app/app.component.ts | 1 + src/models/HistoryEvent.ts | 13 +++++++ src/pages/history/history.html | 26 ++++++++++++++ src/pages/history/history.module.ts | 13 +++++++ src/pages/history/history.scss | 3 ++ src/pages/history/history.ts | 56 +++++++++++++++++++++++++++++ src/providers/space-x/space-x.ts | 6 ++++ 7 files changed, 118 insertions(+) create mode 100644 src/models/HistoryEvent.ts create mode 100644 src/pages/history/history.html create mode 100644 src/pages/history/history.module.ts create mode 100644 src/pages/history/history.scss create mode 100644 src/pages/history/history.ts diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 2277c76..d75eda4 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -25,6 +25,7 @@ export class MyApp { { title: 'Cores', component: 'CoresPage' }, { title: 'Dragons', component: 'DragonsPage' }, { title: 'Upcoming Launches', component: 'FutureLaunchesPage' }, + { title: 'History Events', component: 'HistoryPage' }, ]; } diff --git a/src/models/HistoryEvent.ts b/src/models/HistoryEvent.ts new file mode 100644 index 0000000..a71ec1f --- /dev/null +++ b/src/models/HistoryEvent.ts @@ -0,0 +1,13 @@ +export interface HistoryEvent { + id: number, + title: string, + event_date_utc: Date, + event_date_unix: number, + flight_number: number, + details: string, + links: { + reddit?: string, + article: string, + wikipedia: string + } +} \ No newline at end of file diff --git a/src/pages/history/history.html b/src/pages/history/history.html new file mode 100644 index 0000000..4c0d6ca --- /dev/null +++ b/src/pages/history/history.html @@ -0,0 +1,26 @@ + + + + + History Events + + + + + + + + + + \ No newline at end of file diff --git a/src/pages/history/history.module.ts b/src/pages/history/history.module.ts new file mode 100644 index 0000000..91802c3 --- /dev/null +++ b/src/pages/history/history.module.ts @@ -0,0 +1,13 @@ +import { NgModule } from '@angular/core'; +import { IonicPageModule } from 'ionic-angular'; +import { HistoryPage } from './history'; + +@NgModule({ + declarations: [ + HistoryPage, + ], + imports: [ + IonicPageModule.forChild(HistoryPage), + ], +}) +export class HistoryPageModule {} diff --git a/src/pages/history/history.scss b/src/pages/history/history.scss new file mode 100644 index 0000000..6e8bec8 --- /dev/null +++ b/src/pages/history/history.scss @@ -0,0 +1,3 @@ +page-history { + +} diff --git a/src/pages/history/history.ts b/src/pages/history/history.ts new file mode 100644 index 0000000..8f10375 --- /dev/null +++ b/src/pages/history/history.ts @@ -0,0 +1,56 @@ +import { Component } from '@angular/core'; +import { IonicPage, NavController, NavParams } from 'ionic-angular'; +import { CacheService, Cache } from 'ionic-cache-observable'; +import { InAppBrowser, InAppBrowserOptions } from '@ionic-native/in-app-browser'; + +import { SpaceXProvider } from '../../providers/space-x/space-x'; +import { HistoryEvent } from '../../models/HistoryEvent'; +import { Observable } from 'rxjs/Observable'; + + +/** + * Generated class for the HistoryPage page. + * + * See https://ionicframework.com/docs/components/#navigation for more info on + * Ionic pages and navigation. + */ + +@IonicPage() +@Component({ + selector: 'page-history', + templateUrl: 'history.html', +}) +export class HistoryPage { + + histories: Array + + constructor(public navCtrl: NavController, + public navParams: NavParams, + private spaceXProvider: SpaceXProvider, + private cacheService: CacheService, + private iab: InAppBrowser) { } + + ionViewWillEnter() { + + const historyEventsObservable: Observable = this.spaceXProvider.getHistoryEvents(); + this.cacheService.register('history-events', historyEventsObservable) + .mergeMap((cache: Cache) => cache.get()) + .subscribe((historyEvents) => this.histories = historyEvents); + + } + + openArticle(event, url) { + + if (url) { + const options: InAppBrowserOptions = { + location: 'no', + zoom: 'no', + hideurlbar: 'yes', + }; + + const browser = this.iab.create(url, '_self', options); + browser.show(); + } + } + +} diff --git a/src/providers/space-x/space-x.ts b/src/providers/space-x/space-x.ts index 99366d8..a194c54 100644 --- a/src/providers/space-x/space-x.ts +++ b/src/providers/space-x/space-x.ts @@ -8,6 +8,7 @@ import { Core } from '../../models/Core'; import { Dragon } from '../../models/Dragon'; import { Mission } from '../../models/Mission'; import { Launch } from '../../models/Launch'; +import { HistoryEvent } from '../../models/HistoryEvent'; @Injectable() export class SpaceXProvider { @@ -51,4 +52,9 @@ export class SpaceXProvider { .pipe(map((resp: Response) => resp.json())); } + getHistoryEvents(): Observable { + return this.http.get(this.BASE_URL + 'history') + .pipe(map((resp: Response) => resp.json())); + } + }