mapcomplete/UI/Popup/TagRenderingAnswer.ts

40 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-10-27 01:01:34 +01:00
import {UIEventSource} from "../../Logic/UIEventSource";
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
import {UIElement} from "../UIElement";
import {SubstitutedTranslation} from "../SpecialVisualizations";
/***
* Displays the correct value for a known tagrendering
*/
export default class TagRenderingAnswer extends UIElement {
private _tags: UIEventSource<any>;
private _configuration: TagRenderingConfig;
private _content: UIElement;
2020-10-27 01:01:34 +01:00
2020-11-02 18:59:21 +01:00
constructor(tags: UIEventSource<any>, configuration: TagRenderingConfig) {
2020-10-27 01:01:34 +01:00
super(tags);
this._tags = tags;
this._configuration = configuration;
}
InnerRender(): string {
2020-11-02 18:59:21 +01:00
if (this._configuration.condition !== undefined) {
if (!this._configuration.condition.matchesProperties(this._tags.data)) {
return "";
}
}
2020-11-13 23:58:11 +01:00
const tags = this._tags.data;
if (tags === undefined) {
return "";
}
const tr = this._configuration.GetRenderValue(tags);
if (tr === undefined) {
2020-10-27 01:01:34 +01:00
return "";
}
// Bit of a hack; remember that the fields are updated
this._content = new SubstitutedTranslation(tr, this._tags);
return this._content.Render();
2020-10-27 01:01:34 +01:00
}
}