Little tweaks to make it work... In a devcontainer anyway....
This commit is contained in:
@@ -1,20 +1,18 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Http } from '@angular/http';
|
||||
import 'rxjs/add/operator/map';
|
||||
import { Injectable } from "@angular/core";
|
||||
import { Http } from "@angular/http";
|
||||
import "rxjs/add/operator/map";
|
||||
|
||||
@Injectable()
|
||||
export class ProfileService {
|
||||
|
||||
endpoint: string = 'https://api.fitz.guru/urnings/profiles';
|
||||
fallback: string = 'assets/data/profiles.json';
|
||||
epSubmitted: string = '/submitted';
|
||||
epVerified: string = '/verified';
|
||||
endpoint: string = "http://localhost:27017/urnings/profiles";
|
||||
fallback: string = "assets/data/profiles.json";
|
||||
epSubmitted: string = "/submitted";
|
||||
epVerified: string = "/verified";
|
||||
idMap: any = { all: {}, submitted: {}, verified: {} };
|
||||
profiles: any;
|
||||
|
||||
|
||||
constructor(private http: Http) {
|
||||
this.idMap = {};
|
||||
this.idMap = { all: {}, submitted: {}, verified: {} };
|
||||
this.profiles = null;
|
||||
}
|
||||
|
||||
@@ -23,7 +21,7 @@ export class ProfileService {
|
||||
return Promise.resolve(this.profiles);
|
||||
}
|
||||
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve) => {
|
||||
this.doGetRequest(this.endpoint, resolve);
|
||||
});
|
||||
}
|
||||
@@ -33,8 +31,8 @@ export class ProfileService {
|
||||
return Promise.resolve(this.profiles.submitted);
|
||||
}
|
||||
|
||||
return new Promise(resolve => {
|
||||
this.doGetRequest(this.endpoint + this.epSubmitted, resolve, 'submitted');
|
||||
return new Promise((resolve) => {
|
||||
this.doGetRequest(this.endpoint + this.epSubmitted, resolve, "submitted");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -43,39 +41,42 @@ export class ProfileService {
|
||||
return Promise.resolve(this.profiles.verified);
|
||||
}
|
||||
|
||||
return new Promise(resolve => {
|
||||
this.doGetRequest(this.endpoint + this.epVerified, resolve, 'verified');
|
||||
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())
|
||||
doGetRequest(endpoint, resolve, type = "all") {
|
||||
this.http
|
||||
.get(endpoint)
|
||||
.map((res) => res.json())
|
||||
.subscribe(
|
||||
data => {
|
||||
(data) => {
|
||||
this.profiles = this.profiles || {};
|
||||
this.profiles[type] = data;
|
||||
this.profiles[type].reduce((map, profile, i) => {
|
||||
console.log("profile: ", { map, profile, i });
|
||||
map[profile._id] = i;
|
||||
return map;
|
||||
}, this.idMap[type]);
|
||||
resolve(this.profiles[type]);
|
||||
},
|
||||
error => {
|
||||
(error) => {
|
||||
this.doGetRequest(this.fallback, resolve, type);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
getNextProfile(id, type = 'all') {
|
||||
getNextProfile(id, type = "all") {
|
||||
var nextIdIndex = this.idMap[type][id] + 1;
|
||||
nextIdIndex = nextIdIndex >= this.profiles[type].length ? 0 : nextIdIndex;
|
||||
return this.profiles[type][nextIdIndex];
|
||||
}
|
||||
|
||||
getPreviousProfile(id, type = 'all') {
|
||||
getPreviousProfile(id, type = "all") {
|
||||
var prevIdIndex = this.idMap[type][id] - 1;
|
||||
prevIdIndex = prevIdIndex < 0 ? (this.profiles[type].length - 1) : prevIdIndex;
|
||||
prevIdIndex =
|
||||
prevIdIndex < 0 ? this.profiles[type].length - 1 : prevIdIndex;
|
||||
return this.profiles[type][prevIdIndex];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user