-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from AndreVarandas/create-history-events
feat(history): adds history page
- Loading branch information
Showing
7 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!-- | ||
Generated template for the HistoryPage page. | ||
See http://ionicframework.com/docs/components/#navigation for more info on | ||
Ionic pages and navigation. | ||
--> | ||
<ion-header> | ||
<ion-navbar> | ||
<button ion-button menuToggle> | ||
<ion-icon name="menu"></ion-icon> | ||
</button> | ||
<ion-title>History Events</ion-title> | ||
</ion-navbar> | ||
</ion-header> | ||
|
||
<ion-content> | ||
|
||
<ion-list no-lines> | ||
<button ion-item *ngFor="let history of histories" (click)="openArticle($event, history.links.article)"> | ||
<h2>{{ history.title }}</h2> | ||
<p item-end>{{ history.event_date_utc | date: 'dd/MM/yy @ h:mma' }}</p> | ||
<p>{{ history.details }}</p> | ||
</button> | ||
</ion-list> | ||
|
||
</ion-content> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
page-history { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<HistoryEvent> | ||
|
||
constructor(public navCtrl: NavController, | ||
public navParams: NavParams, | ||
private spaceXProvider: SpaceXProvider, | ||
private cacheService: CacheService, | ||
private iab: InAppBrowser) { } | ||
|
||
ionViewWillEnter() { | ||
|
||
const historyEventsObservable: Observable<HistoryEvent[]> = this.spaceXProvider.getHistoryEvents(); | ||
this.cacheService.register('history-events', historyEventsObservable) | ||
.mergeMap((cache: Cache<HistoryEvent[]>) => 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(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters