Added cruising pages support
This commit is contained in:
44
src/services/cruises.ts
Normal file
44
src/services/cruises.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Http } from '@angular/http';
|
||||
import 'rxjs/add/operator/map';
|
||||
|
||||
@Injectable()
|
||||
export class CruiseService {
|
||||
|
||||
//endpoint: string = '/assets/data/cruises.json';
|
||||
endpoint: string = 'https://api.fitz.guru/urge/cruises';
|
||||
idMap: any;
|
||||
cruises: any;
|
||||
|
||||
constructor(private http: Http) {
|
||||
this.idMap = {};
|
||||
this.cruises = null;
|
||||
}
|
||||
|
||||
load() {
|
||||
if (this.cruises) {
|
||||
return Promise.resolve(this.cruises);
|
||||
}
|
||||
|
||||
return new Promise(resolve => {
|
||||
this.http.get(this.endpoint)
|
||||
.map(res => res.json())
|
||||
.subscribe(data => {
|
||||
this.cruises = data;
|
||||
this.cruises.reduce((map, cruise, i) => {
|
||||
map[cruise._id] = i;
|
||||
return map;
|
||||
}, this.idMap);
|
||||
resolve(this.cruises);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getCruises() {
|
||||
return this.cruises;
|
||||
}
|
||||
|
||||
getCruiseById(id) {
|
||||
return this.cruises[this.idMap[id]];
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import 'rxjs/add/operator/map';
|
||||
@Injectable()
|
||||
export class ProfileService {
|
||||
|
||||
endpoint: string = 'https://api.fitz.guru/urge/profiles'; //'assets/data/profiles.json';
|
||||
idMap: any;
|
||||
profiles: any;
|
||||
|
||||
@@ -19,7 +20,7 @@ export class ProfileService {
|
||||
}
|
||||
|
||||
return new Promise(resolve => {
|
||||
this.http.get('https://api.fitz.guru/urge/profiles')
|
||||
this.http.get(this.endpoint)
|
||||
.map(res => res.json())
|
||||
.subscribe(data => {
|
||||
this.profiles = data;
|
||||
|
||||
Reference in New Issue
Block a user