- UI Revisions

This commit is contained in:
2018-05-29 00:30:49 -04:00
parent a7833a9314
commit 8f5ec53ac4
33 changed files with 487 additions and 447 deletions

View File

@@ -1,44 +0,0 @@
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]];
}
}

View File

@@ -5,11 +5,14 @@ import 'rxjs/add/operator/map';
@Injectable()
export class ProfileService {
endpoint: string = 'https://api.fitz.guru/urge/profiles';
endpoint: string = 'https://api.fitz.guru/urnings/profiles';
fallback: string = 'assets/data/profiles.json';
idMap: any;
epSubmitted: string = '/submitted';
epVerified: string = '/verified';
idMap: any = { all: {}, submitted: {}, verified: {} };
profiles: any;
constructor(private http: Http) {
this.idMap = {};
this.profiles = null;
@@ -21,29 +24,61 @@ export class ProfileService {
}
return new Promise(resolve => {
this.http.get(this.endpoint)
.map(res => res.json())
.subscribe(
data => {
this.profiles = data;
this.profiles.reduce((map, profile, i) => {
map[profile._id] = i;
return map;
}, this.idMap);
resolve(this.profiles);
},
error => {
this.profiles = this.fallback;
this.profiles.reduce((map, profile, i) => {
map[profile._id] = i;
return map;
}, this.idMap);
resolve(this.profiles);
}
);
this.doGetRequest(this.endpoint, resolve);
});
}
loadSubmitted() {
if (this.profiles) {
return Promise.resolve(this.profiles);
}
return new Promise(resolve => {
this.doGetRequest(this.endpoint + this.epSubmitted, resolve, 'submitted');
});
}
loadVerified() {
if (this.profiles) {
return Promise.resolve(this.profiles);
}
return new Promise(resolve => {
this.doGetRequest(this.endpoint + this.epVerified, resolve, 'verified');
});
}
doGetRequest(endpoint, resolve, type = 'all') {
this.http.get(endpoint)
.map(res => res.json())
.subscribe(
data => {
this.profiles = {};
this.profiles[type] = data;
this.profiles.reduce((map, profile, i) => {
map[profile._id] = i;
return map;
}, this.idMap[type]);
resolve(this.profiles[type]);
},
error => {
this.doGetRequest(this.fallback, resolve);
}
)
}
getNextProfile(id, type) {
var nextIdIndex = this.idMap[id] + 1;
nextIdIndex = nextIdIndex >= this.profiles.length ? 0 : nextIdIndex;
return this.profiles[nextIdIndex];
}
getPreviousProfile(id, type) {
var prevIdIndex = this.idMap[id] + 1;
prevIdIndex = prevIdIndex < 0 ? (this.profiles.length - 1) : prevIdIndex;
return this.profiles[prevIdIndex];
}
getProfiles() {
return this.profiles;
}
@@ -51,4 +86,12 @@ export class ProfileService {
getProfileById(id) {
return this.profiles[this.idMap[id]];
}
getSubmittedProfiles() {
}
getVerifiedProfiles() {
}
}