mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-22 06:37:56 +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>;
|
||||
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' });
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ export default class RestClient extends MockClient {
|
||||
super();
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
|
||||
private parseResponseOnError = (response: any): ErrorInfo => {
|
||||
|
||||
let result: ErrorInfo | undefined;
|
||||
@ -184,7 +184,7 @@ export default class RestClient extends MockClient {
|
||||
changeStarred(id: number, starred: boolean): Promise<void> {
|
||||
const handler = (success: () => void, reject: (error: ErrorInfo) => void) => {
|
||||
axios.put(this.baseUrl + `/c/restful/maps/${id}/starred`,
|
||||
starred,
|
||||
starred,
|
||||
{ headers: { 'Content-Type': 'text/plain' } }
|
||||
).then(() => {
|
||||
success();
|
||||
@ -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