mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-10 17:33:24 +01:00
Implement load labels
This commit is contained in:
parent
9596852c90
commit
6115eeec26
@ -49,17 +49,18 @@ export type ErrorInfo = {
|
||||
|
||||
interface Client {
|
||||
createMap(map: BasicMapInfo): Promise<number>;
|
||||
registerNewUser(user: NewUser): Promise<void>;
|
||||
resetPassword(email: string): Promise<void>;
|
||||
fetchAllMaps(): Promise<MapInfo[]>;
|
||||
deleteMap(id: number): Promise<void>;
|
||||
renameMap(id: number, basicInfo: BasicMapInfo): Promise<void>;
|
||||
fetchAllMaps(): Promise<MapInfo[]>;
|
||||
duplicateMap(id: number, basicInfo: BasicMapInfo): Promise<number>;
|
||||
loadMapInfo(id: number): Promise<BasicMapInfo>;
|
||||
fetchMapInfo(id: number): Promise<BasicMapInfo>;
|
||||
changeStarred(id: number, starred: boolean): Promise<void>;
|
||||
|
||||
fetchLabels(): Promise<Label[]>;
|
||||
deleteLabel(id: number): Promise<void>;
|
||||
|
||||
registerNewUser(user: NewUser): Promise<void>;
|
||||
resetPassword(email: string): Promise<void>;
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,7 +36,7 @@ class MockClient implements Client {
|
||||
|
||||
this.labels = [
|
||||
{ id: 1, title: "Red Label", iconName: "", color: 'red' },
|
||||
{ id: 1, title: "Blue Label", iconName: "", color: 'blue' }
|
||||
{ id: 2, title: "Blue Label", iconName: "", color: 'blue' }
|
||||
];
|
||||
|
||||
}
|
||||
@ -62,7 +62,7 @@ class MockClient implements Client {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
loadMapInfo(id: number): Promise<BasicMapInfo> {
|
||||
fetchMapInfo(id: number): Promise<BasicMapInfo> {
|
||||
return Promise.resolve({ title: 'My Map', description: 'My Description' });
|
||||
}
|
||||
|
||||
|
@ -197,6 +197,34 @@ export default class RestClient extends MockClient {
|
||||
return new Promise(handler);
|
||||
}
|
||||
|
||||
|
||||
fetchLabels(): Promise<Label[]> {
|
||||
|
||||
const handler = (success: (labels: Label[]) => void, reject: (error: ErrorInfo) => void) => {
|
||||
axios.get(
|
||||
this.baseUrl + '/c/restful/labels/',
|
||||
{
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
}
|
||||
).then(response => {
|
||||
const data = response.data;
|
||||
const maps: Label[] = (data.labels as any[]).map(l => {
|
||||
return {
|
||||
id: l.id,
|
||||
color: l.color,
|
||||
title: l.title,
|
||||
iconName: l.iconName
|
||||
}
|
||||
})
|
||||
success(maps);
|
||||
}).catch(error => {
|
||||
const errorInfo = this.parseResponseOnError(error.response);
|
||||
reject(errorInfo);
|
||||
});
|
||||
}
|
||||
return new Promise(handler);
|
||||
}
|
||||
|
||||
deleteLabel(id: number): Promise<void> {
|
||||
console.log("Fetching labels from server")
|
||||
return Promise.resolve();
|
||||
|
Loading…
Reference in New Issue
Block a user