fix option sources (#12387)

This commit is contained in:
Charles Gagnon
2020-09-16 23:00:50 -07:00
committed by GitHub
parent be1e0b3c8d
commit fca8b85a72
4 changed files with 18 additions and 27 deletions

View File

@@ -11,15 +11,12 @@ import { apiService } from '../services/apiService';
import { throwUnless } from '../utils';
import { CacheManager } from './cacheManager';
export enum OptionsSourceType {
ArcControllersOptionsSource = 'ArcControllersOptionsSource'
}
export type OptionsSourceType = 'ArcControllersOptionsSource';
const OptionsSources = new Map<OptionsSourceType, new () => OptionsSource>();
export abstract class OptionsSource implements IOptionsSource {
private _variableNames!: { [index: string]: string; };
private _type!: OptionsSourceType;
get type(): OptionsSourceType { return this._type; }
get variableNames(): { [index: string]: string; } { return this._variableNames; }
@@ -27,24 +24,12 @@ export abstract class OptionsSource implements IOptionsSource {
abstract async getVariableValue(variableName: string, input: string): Promise<string>;
abstract getIsPassword(variableName: string): boolean;
protected constructor() {
}
static construct(optionsSourceType: OptionsSourceType, variableNames: { [index: string]: string }): OptionsSource {
const sourceConstructor = OptionsSources.get(optionsSourceType);
throwUnless(sourceConstructor !== undefined, loc.noOptionsSourceDefined(optionsSourceType));
const obj = new sourceConstructor();
obj._type = optionsSourceType;
obj._variableNames = variableNames;
return obj;
constructor(private _variableNames: { [index: string]: string }, private _type: OptionsSourceType) {
}
}
export class ArcControllersOptionsSource extends OptionsSource {
private _cacheManager = new CacheManager<string, string>();
constructor() {
super();
}
async getOptions(): Promise<string[] | CategoryValue[]> {
const controllers = await apiService.arcApi.getRegisteredDataControllers();
@@ -97,4 +82,3 @@ export class ArcControllersOptionsSource extends OptionsSource {
}
}
}
OptionsSources.set(<OptionsSourceType>ArcControllersOptionsSource.name, ArcControllersOptionsSource);