Skip to content

Commit

Permalink
Merge pull request #16 from AndreVarandas/create-history-events
Browse files Browse the repository at this point in the history
feat(history): adds history page
  • Loading branch information
AndreVarandas committed Oct 7, 2018
2 parents ef3cc0f + af44e1f commit f42d46a
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
];

}
Expand Down
13 changes: 13 additions & 0 deletions src/models/HistoryEvent.ts
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
}
}
26 changes: 26 additions & 0 deletions src/pages/history/history.html
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>
13 changes: 13 additions & 0 deletions src/pages/history/history.module.ts
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 {}
3 changes: 3 additions & 0 deletions src/pages/history/history.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
page-history {

}
56 changes: 56 additions & 0 deletions src/pages/history/history.ts
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();
}
}

}
6 changes: 6 additions & 0 deletions src/providers/space-x/space-x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -51,4 +52,9 @@ export class SpaceXProvider {
.pipe(map((resp: Response) => <Mission[]>resp.json()));
}

getHistoryEvents(): Observable<HistoryEvent[]> {
return this.http.get(this.BASE_URL + 'history')
.pipe(map((resp: Response) => <HistoryEvent[]>resp.json()));
}

}

0 comments on commit f42d46a

Please sign in to comment.