2020-06-27 03:06:51 +02:00
|
|
|
import {UIElement} from "./UIElement";
|
2020-06-29 03:12:44 +02:00
|
|
|
import {VerticalCombine} from "./Base/VerticalCombine";
|
2020-07-05 18:59:47 +02:00
|
|
|
import {OsmLink} from "../Customizations/Questions/OsmLink";
|
|
|
|
import {WikipediaLink} from "../Customizations/Questions/WikipediaLink";
|
2020-08-30 01:13:18 +02:00
|
|
|
import {And} from "../Logic/Tags";
|
2020-07-21 00:07:04 +02:00
|
|
|
import {TagDependantUIElement, TagDependantUIElementConstructor} from "../Customizations/UIElementConstructor";
|
2020-07-22 00:18:07 +02:00
|
|
|
import Translations from "./i18n/Translations";
|
2020-07-30 00:59:08 +02:00
|
|
|
import {Changes} from "../Logic/Osm/Changes";
|
2020-07-30 09:59:30 +02:00
|
|
|
import {FixedUiElement} from "./Base/FixedUiElement";
|
2020-07-31 01:45:54 +02:00
|
|
|
import {State} from "../State";
|
2020-07-31 17:38:03 +02:00
|
|
|
import {TagRenderingOptions} from "../Customizations/TagRenderingOptions";
|
2020-08-22 02:12:46 +02:00
|
|
|
import {UIEventSource} from "../Logic/UIEventSource";
|
|
|
|
import Combine from "./Base/Combine";
|
2020-06-27 03:06:51 +02:00
|
|
|
|
|
|
|
export class FeatureInfoBox extends UIElement {
|
|
|
|
|
2020-07-22 01:07:32 +02:00
|
|
|
/**
|
|
|
|
* The actual GEOJSON-object, with geometry and stuff
|
|
|
|
*/
|
|
|
|
private _feature: any;
|
|
|
|
/**
|
|
|
|
* The tags, wrapped in a global event source
|
|
|
|
*/
|
2020-08-30 01:13:18 +02:00
|
|
|
private readonly _tagsES: UIEventSource<any>;
|
|
|
|
private readonly _changes: Changes;
|
|
|
|
private readonly _title: UIElement;
|
2020-09-03 16:44:48 +02:00
|
|
|
private readonly _infoboxes: TagDependantUIElement[];
|
2020-06-27 03:06:51 +02:00
|
|
|
|
2020-09-03 16:44:48 +02:00
|
|
|
private readonly _oneSkipped = Translations.t.general.oneSkippedQuestion.Clone();
|
|
|
|
private readonly _someSkipped = Translations.t.general.skippedQuestions.Clone();
|
2020-07-22 00:18:07 +02:00
|
|
|
|
2020-06-27 03:06:51 +02:00
|
|
|
constructor(
|
2020-07-22 01:07:32 +02:00
|
|
|
feature: any,
|
2020-06-27 03:06:51 +02:00
|
|
|
tagsES: UIEventSource<any>,
|
2020-08-22 02:12:46 +02:00
|
|
|
title: TagDependantUIElementConstructor | UIElement | string,
|
2020-07-21 00:07:04 +02:00
|
|
|
elementsToShow: TagDependantUIElementConstructor[],
|
2020-06-27 03:06:51 +02:00
|
|
|
) {
|
|
|
|
super(tagsES);
|
2020-07-22 01:07:32 +02:00
|
|
|
this._feature = feature;
|
2020-06-27 03:06:51 +02:00
|
|
|
this._tagsES = tagsES;
|
2020-07-31 01:45:54 +02:00
|
|
|
this.ListenTo(State.state.osmConnection.userDetails);
|
2020-09-14 20:16:03 +02:00
|
|
|
this.SetClass("featureinfobox");
|
2020-07-22 00:18:07 +02:00
|
|
|
const deps = {tags: this._tagsES, changes: this._changes}
|
|
|
|
|
2020-07-05 18:59:47 +02:00
|
|
|
this._infoboxes = [];
|
2020-07-14 20:18:44 +02:00
|
|
|
elementsToShow = elementsToShow ?? []
|
2020-07-22 00:18:07 +02:00
|
|
|
|
|
|
|
const self = this;
|
2020-07-05 18:59:47 +02:00
|
|
|
for (const tagRenderingOption of elementsToShow) {
|
2020-07-22 00:18:07 +02:00
|
|
|
self._infoboxes.push(
|
2020-07-17 14:24:31 +02:00
|
|
|
tagRenderingOption.construct(deps));
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|
2020-07-22 00:18:07 +02:00
|
|
|
function initTags() {
|
2020-09-03 16:44:48 +02:00
|
|
|
self._infoboxes.splice(0, self._infoboxes.length);
|
2020-07-22 00:18:07 +02:00
|
|
|
for (const tagRenderingOption of elementsToShow) {
|
|
|
|
self._infoboxes.push(
|
|
|
|
tagRenderingOption.construct(deps));
|
|
|
|
}
|
|
|
|
self.Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
this._someSkipped.onClick(initTags)
|
|
|
|
this._oneSkipped.onClick(initTags)
|
|
|
|
|
2020-06-27 03:06:51 +02:00
|
|
|
|
2020-09-13 00:53:24 +02:00
|
|
|
let renderedTitle: UIElement;
|
2020-07-05 18:59:47 +02:00
|
|
|
title = title ?? new TagRenderingOptions(
|
|
|
|
{
|
|
|
|
mappings: [{k: new And([]), txt: ""}]
|
|
|
|
}
|
|
|
|
)
|
2020-07-30 09:59:30 +02:00
|
|
|
if (typeof (title) == "string") {
|
2020-09-13 00:53:24 +02:00
|
|
|
renderedTitle = new FixedUiElement(title);
|
2020-07-30 09:59:30 +02:00
|
|
|
} else if (title instanceof UIElement) {
|
2020-09-13 00:53:24 +02:00
|
|
|
renderedTitle = title;
|
2020-07-21 01:13:51 +02:00
|
|
|
} else {
|
2020-09-13 00:53:24 +02:00
|
|
|
renderedTitle = title.construct(deps);
|
2020-07-21 01:13:51 +02:00
|
|
|
}
|
2020-06-27 03:06:51 +02:00
|
|
|
|
2020-09-13 00:53:24 +02:00
|
|
|
|
|
|
|
renderedTitle
|
|
|
|
.SetStyle("width: calc(100% - 50px - 0.2em);")
|
|
|
|
.SetClass("title-font")
|
|
|
|
|
|
|
|
const osmLink = new OsmLink()
|
|
|
|
.construct(deps)
|
|
|
|
.SetStyle("width: 24px; display:block;")
|
|
|
|
const wikipedialink = new WikipediaLink()
|
|
|
|
.construct(deps)
|
|
|
|
.SetStyle("width: 24px; display:block;")
|
|
|
|
|
|
|
|
this._title = new Combine([
|
|
|
|
renderedTitle,
|
|
|
|
wikipedialink,
|
|
|
|
osmLink]).SetStyle("display:flex;");
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
InnerRender(): string {
|
|
|
|
|
2020-06-28 00:06:23 +02:00
|
|
|
|
2020-07-05 18:59:47 +02:00
|
|
|
const info = [];
|
2020-07-22 00:18:07 +02:00
|
|
|
const questions: TagDependantUIElement[] = [];
|
|
|
|
let skippedQuestions = 0;
|
2020-07-05 18:59:47 +02:00
|
|
|
for (const infobox of this._infoboxes) {
|
|
|
|
if (infobox.IsKnown()) {
|
|
|
|
info.push(infobox);
|
|
|
|
} else if (infobox.IsQuestioning()) {
|
|
|
|
questions.push(infobox);
|
2020-08-22 18:57:27 +02:00
|
|
|
} else if (infobox.IsSkipped()) {
|
2020-07-22 00:18:07 +02:00
|
|
|
// This question is neither known nor questioning -> it was skipped
|
|
|
|
skippedQuestions++;
|
2020-07-05 18:59:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-09-03 16:44:48 +02:00
|
|
|
let questionElement: UIElement;
|
2020-07-05 18:59:47 +02:00
|
|
|
|
2020-09-17 13:13:02 +02:00
|
|
|
if (questions.length > 0) {
|
2020-07-05 18:59:47 +02:00
|
|
|
// We select the most important question and render that one
|
|
|
|
let mostImportantQuestion;
|
|
|
|
for (const question of questions) {
|
|
|
|
|
2020-09-17 13:13:02 +02:00
|
|
|
if (mostImportantQuestion === undefined) {
|
2020-07-05 18:59:47 +02:00
|
|
|
mostImportantQuestion = question;
|
2020-09-17 13:13:02 +02:00
|
|
|
break;
|
2020-07-05 18:59:47 +02:00
|
|
|
}
|
|
|
|
}
|
2020-09-03 16:44:48 +02:00
|
|
|
questionElement = mostImportantQuestion;
|
2020-07-22 00:18:07 +02:00
|
|
|
} else if (skippedQuestions == 1) {
|
2020-09-03 16:44:48 +02:00
|
|
|
questionElement = this._oneSkipped;
|
2020-07-22 00:18:07 +02:00
|
|
|
} else if (skippedQuestions > 0) {
|
2020-09-03 16:44:48 +02:00
|
|
|
questionElement = this._someSkipped;
|
2020-06-28 00:06:23 +02:00
|
|
|
}
|
2020-06-27 03:06:51 +02:00
|
|
|
|
2020-08-22 02:12:46 +02:00
|
|
|
const infoboxcontents = new Combine(
|
2020-09-13 00:53:24 +02:00
|
|
|
[new VerticalCombine(info, "infobox-information "), questionElement ?? ""]);
|
|
|
|
|
|
|
|
return new Combine([
|
|
|
|
this._title,
|
|
|
|
"<div class='infoboxcontents'>",
|
|
|
|
infoboxcontents,
|
2020-09-14 20:16:03 +02:00
|
|
|
"</div>"])
|
2020-09-13 00:53:24 +02:00
|
|
|
.Render();
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|
2020-07-20 09:57:19 +02:00
|
|
|
|
2020-07-20 15:54:50 +02:00
|
|
|
|
|
|
|
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|