mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-15 11:37:57 +01:00
Add decorator for client
This commit is contained in:
parent
b1d1033f94
commit
b4617580d0
@ -1,5 +1,6 @@
|
||||
import { sessionExpired } from "../../redux/clientSlice";
|
||||
import Client from "../client";
|
||||
import CacheDecoratorClient from "../client/cache-decorator-client";
|
||||
import MockClient from "../client/mock-client";
|
||||
import RestClient from "../client/rest-client";
|
||||
|
||||
@ -60,7 +61,9 @@ class _AppConfig {
|
||||
console.log('Warning:Service using mockservice client');
|
||||
result = new MockClient();
|
||||
}
|
||||
return result;
|
||||
|
||||
// Wrap with a cache decorator ...
|
||||
return new CacheDecoratorClient(result);
|
||||
}
|
||||
}
|
||||
const AppConfig = new _AppConfig();
|
||||
|
@ -0,0 +1,113 @@
|
||||
import Client, {
|
||||
AccountInfo,
|
||||
BasicMapInfo,
|
||||
ChangeHistory,
|
||||
ImportMapInfo,
|
||||
Label,
|
||||
MapInfo,
|
||||
NewUser,
|
||||
Permission,
|
||||
} from '..';
|
||||
import { LocaleCode } from '../../app-i18n';
|
||||
|
||||
class CacheDecoratorClient implements Client {
|
||||
private client: Client;
|
||||
|
||||
constructor(client: Client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
deleteAccount(): Promise<void> {
|
||||
return this.client.deleteAccount();
|
||||
}
|
||||
|
||||
importMap(model: ImportMapInfo): Promise<number> {
|
||||
return this.client.importMap(model);
|
||||
}
|
||||
|
||||
createMap(map: BasicMapInfo): Promise<number> {
|
||||
return this.client.createMap(map);
|
||||
}
|
||||
|
||||
deleteMaps(ids: number[]): Promise<void> {
|
||||
return this.client.deleteMaps(ids);
|
||||
}
|
||||
|
||||
deleteMap(id: number): Promise<void> {
|
||||
return this.client.deleteMap(id);
|
||||
}
|
||||
|
||||
renameMap(id: number, basicInfo: BasicMapInfo): Promise<void> {
|
||||
return this.client.renameMap(id, basicInfo);
|
||||
}
|
||||
|
||||
fetchAllMaps(): Promise<MapInfo[]> {
|
||||
return this.client.fetchAllMaps();
|
||||
}
|
||||
|
||||
fetchMapPermissions(id: number): Promise<Permission[]> {
|
||||
return this.client.fetchMapPermissions(id);
|
||||
}
|
||||
|
||||
addMapPermissions(id: number, message: string, permissions: Permission[]): Promise<void> {
|
||||
return this.client.addMapPermissions(id, message, permissions);
|
||||
}
|
||||
|
||||
deleteMapPermission(id: number, email: string): Promise<void> {
|
||||
return this.client.deleteMapPermission(id, email);
|
||||
}
|
||||
|
||||
duplicateMap(id: number, basicInfo: BasicMapInfo): Promise<number> {
|
||||
return this.client.duplicateMap(id, basicInfo);
|
||||
}
|
||||
|
||||
updateAccountLanguage(locale: LocaleCode): Promise<void> {
|
||||
return this.client.updateAccountLanguage(locale);
|
||||
}
|
||||
|
||||
updateAccountPassword(pasword: string): Promise<void> {
|
||||
return this.client.updateAccountPassword(pasword);
|
||||
}
|
||||
|
||||
updateAccountInfo(firstname: string, lastname: string): Promise<void> {
|
||||
return this.client.updateAccountInfo(firstname, lastname);
|
||||
}
|
||||
|
||||
updateStarred(id: number, starred: boolean): Promise<void> {
|
||||
return this.client.updateStarred(id, starred);
|
||||
}
|
||||
|
||||
updateMapToPublic(id: number, isPublic: boolean): Promise<void> {
|
||||
return this.client.updateMapToPublic(id, isPublic);
|
||||
}
|
||||
|
||||
fetchLabels(): Promise<Label[]> {
|
||||
return this.client.fetchLabels();
|
||||
}
|
||||
|
||||
deleteLabel(id: number): Promise<void> {
|
||||
return this.client.deleteLabel(id);
|
||||
}
|
||||
|
||||
fetchAccountInfo(): Promise<AccountInfo> {
|
||||
return this.client.fetchAccountInfo();
|
||||
}
|
||||
|
||||
registerNewUser(user: NewUser): Promise<void> {
|
||||
return this.client.registerNewUser(user);
|
||||
}
|
||||
|
||||
resetPassword(email: string): Promise<void> {
|
||||
return this.client.resetPassword(email);
|
||||
}
|
||||
|
||||
fetchHistory(id: number): Promise<ChangeHistory[]> {
|
||||
return this.client.fetchHistory(id);
|
||||
}
|
||||
|
||||
revertHistory(id: number, cid: number): Promise<void> {
|
||||
return this.client.revertHistory(id,cid);
|
||||
}
|
||||
}
|
||||
|
||||
export default CacheDecoratorClient;
|
@ -92,7 +92,7 @@ interface Client {
|
||||
updateAccountInfo(firstname: string, lastname: string): Promise<void>;
|
||||
|
||||
updateStarred(id: number, starred: boolean): Promise<void>;
|
||||
updateMapToPublic(id: number, starred: boolean): Promise<void>;
|
||||
updateMapToPublic(id: number, isPublic: boolean): Promise<void>;
|
||||
|
||||
fetchLabels(): Promise<Label[]>;
|
||||
deleteLabel(id: number): Promise<void>;
|
||||
|
@ -235,11 +235,10 @@ export default class RestClient implements Client {
|
||||
updateMapToPublic(id: number, isPublic: boolean): Promise<void> {
|
||||
const handler = (success: () => void, reject: (error: ErrorInfo) => void) => {
|
||||
axios
|
||||
.put(`${this.baseUrl}/c/restful/maps/${id}/publish`, isPublic, {
|
||||
.put(`${this.baseUrl}/c/restful/maps/${id}/publish`, isPublic.toString(), {
|
||||
headers: { 'Content-Type': 'text/plain' },
|
||||
})
|
||||
.then(() => {
|
||||
// All was ok, let's sent to success page ...;
|
||||
success();
|
||||
})
|
||||
.catch((error) => {
|
||||
|
Loading…
Reference in New Issue
Block a user