- UI Revisions
This commit is contained in:
@@ -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() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user