formgen-react
Version:
Formula generator with JSON for react. UI Fabric controls are used for rendering
88 lines (76 loc) • 2.89 kB
text/typescript
import { IDataProviderService, IDataProviderCollection } from '../../formBaseInput/FormBaseInput.types';
import { Control } from '../..';
import { IDropdownOption } from 'office-ui-fabric-react';
import { injectable } from 'inversify';
export class MockDataProviderService implements IDataProviderService {
providerServiceKey = "mockDataService";
/**
* Retrieve data from the store
* @param configKey Config Key from the control. This will use the by the provider to finde the correct configuration for this request
* @param formData The Current complete Form Model. Here the config should be found.
* @param controlConfig The control that calls the request.
* @param lang The current language to use.
*/
public retrieveListData(configKey:string, controlConfig: Control, lang:string):Promise<any[]> {
return new Promise<any[]>((resolve, reject) => {
let dropDonwEntries:IDropdownOption[] = [{
key: 1,
text: "Test 1"
},
{
key: 2,
text: "Test2"
}];
setTimeout(() => resolve(dropDonwEntries), 5000);
});
}
public initialize() {}
public retrieveSingleData(configKey:string, senderControl: Control, receiverControl: Control, lang:string):Promise<any> {
return new Promise<any>((resolve, reject) => {
if (senderControl && senderControl.Value == "11:00:01"){
resolve("nothing else");
return;
}
if (configKey == "testA") {
resolve("Test A");
return;
}
else {
resolve("");
return;
}
});
}
public addFile(configKey:string, controlConfig: Control, fileName:string, fileContent: any) : string {
return "http://test/" + fileName
}
public removeFile(configKey:string, controlConfig: Control, fileName:string) {
}
public retrieveFilteredListData?(configKey:string, controlConfig: Control, lang:string, filter: string, limitResults?: number):Promise<any[]> {
return new Promise<any[]>((resolve, reject) => {
let dropDonwEntries:IDropdownOption[] = [];
if (filter == "1") {
dropDonwEntries.push({
key: 1,
text: "Test 1"
})
}
if (filter == "2") {
dropDonwEntries.push({
key: 2,
text: "Test2"
})
}
setTimeout(() => resolve(dropDonwEntries), 1000);
});
}
}
()
export class MockDataProviderCollection implements IDataProviderCollection {
constructor() {
let mockProvider = new MockDataProviderService();
mockProvider.providerServiceKey
this.providers.push(mockProvider);
}
providers:IDataProviderService[] = [];
}