2020-06-27 03:06:51 +02:00
|
|
|
import {UIElement} from "./UIElement";
|
|
|
|
import {UIEventSource} from "./UIEventSource";
|
|
|
|
import {QuestionPicker} from "./QuestionPicker";
|
|
|
|
import {OsmImageUploadHandler} from "../Logic/OsmImageUploadHandler";
|
|
|
|
import {ImageCarousel} from "./Image/ImageCarousel";
|
|
|
|
import {Changes} from "../Logic/Changes";
|
|
|
|
import {UserDetails} from "../Logic/OsmConnection";
|
2020-06-29 03:12:44 +02:00
|
|
|
import {VerticalCombine} from "./Base/VerticalCombine";
|
2020-07-12 23:19:05 +02:00
|
|
|
import {TagRenderingOptions} from "../Customizations/TagRendering";
|
2020-07-05 18:59:47 +02:00
|
|
|
import {OsmLink} from "../Customizations/Questions/OsmLink";
|
|
|
|
import {WikipediaLink} from "../Customizations/Questions/WikipediaLink";
|
|
|
|
import {And} from "../Logic/TagsFilter";
|
2020-07-12 23:19:05 +02:00
|
|
|
import {TagDependantUIElement} from "../Customizations/UIElementConstructor";
|
2020-06-27 03:06:51 +02:00
|
|
|
|
|
|
|
export class FeatureInfoBox extends UIElement {
|
|
|
|
|
|
|
|
private _tagsES: UIEventSource<any>;
|
2020-07-14 20:18:44 +02:00
|
|
|
private _changes: Changes;
|
|
|
|
private _userDetails: UIEventSource<UserDetails>;
|
2020-06-27 03:06:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
private _title: UIElement;
|
|
|
|
private _osmLink: UIElement;
|
2020-07-14 20:18:44 +02:00
|
|
|
private _wikipedialink: UIElement;
|
2020-06-27 03:06:51 +02:00
|
|
|
|
|
|
|
|
2020-07-14 20:18:44 +02:00
|
|
|
|
2020-07-12 23:19:05 +02:00
|
|
|
private _infoboxes: TagDependantUIElement[];
|
2020-07-14 20:18:44 +02:00
|
|
|
private _questions: QuestionPicker;
|
2020-06-27 03:06:51 +02:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
tagsES: UIEventSource<any>,
|
2020-07-05 18:59:47 +02:00
|
|
|
title: TagRenderingOptions,
|
|
|
|
elementsToShow: TagRenderingOptions[],
|
2020-06-27 03:06:51 +02:00
|
|
|
changes: Changes,
|
2020-07-14 20:18:44 +02:00
|
|
|
userDetails: UIEventSource<UserDetails>
|
2020-06-27 03:06:51 +02:00
|
|
|
) {
|
|
|
|
super(tagsES);
|
|
|
|
this._tagsES = tagsES;
|
|
|
|
this._changes = changes;
|
|
|
|
this._userDetails = userDetails;
|
2020-06-29 16:21:36 +02:00
|
|
|
this.ListenTo(userDetails);
|
2020-06-27 03:06:51 +02:00
|
|
|
|
2020-07-17 14:24:31 +02:00
|
|
|
const deps = {tags:this._tagsES , changes:this._changes}
|
2020-07-14 20:18:44 +02:00
|
|
|
|
2020-07-05 18:59:47 +02:00
|
|
|
this._infoboxes = [];
|
2020-07-14 20:18:44 +02:00
|
|
|
elementsToShow = elementsToShow ?? []
|
2020-07-05 18:59:47 +02:00
|
|
|
for (const tagRenderingOption of elementsToShow) {
|
2020-07-12 23:19:05 +02:00
|
|
|
this._infoboxes.push(
|
2020-07-17 14:24:31 +02:00
|
|
|
tagRenderingOption.construct(deps));
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|
|
|
|
|
2020-07-05 18:59:47 +02:00
|
|
|
title = title ?? new TagRenderingOptions(
|
|
|
|
{
|
|
|
|
mappings: [{k: new And([]), txt: ""}]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-07-17 14:24:31 +02:00
|
|
|
this._title = new TagRenderingOptions(title.options).construct(deps);
|
|
|
|
this._osmLink =new OsmLink().construct(deps);
|
|
|
|
this._wikipedialink = new WikipediaLink().construct(deps);
|
2020-07-14 20:18:44 +02:00
|
|
|
|
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-12 23:19:05 +02:00
|
|
|
const questions : TagDependantUIElement[] = [];
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let questionsHtml = "";
|
|
|
|
|
|
|
|
if (this._userDetails.data.loggedIn && questions.length > 0) {
|
|
|
|
// We select the most important question and render that one
|
|
|
|
let mostImportantQuestion;
|
|
|
|
let score = -1000;
|
|
|
|
for (const question of questions) {
|
|
|
|
|
2020-07-12 23:19:05 +02:00
|
|
|
if (mostImportantQuestion === undefined || question.Priority() > score) {
|
2020-07-05 18:59:47 +02:00
|
|
|
mostImportantQuestion = question;
|
2020-07-12 23:19:05 +02:00
|
|
|
score = question.Priority();
|
2020-07-05 18:59:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
questionsHtml = mostImportantQuestion.Render();
|
2020-06-28 00:06:23 +02:00
|
|
|
}
|
2020-06-27 03:06:51 +02:00
|
|
|
|
|
|
|
return "<div class='featureinfobox'>" +
|
|
|
|
"<div class='featureinfoboxtitle'>" +
|
2020-07-05 18:59:47 +02:00
|
|
|
"<span>" +
|
|
|
|
this._title.Render() +
|
|
|
|
"</span>" +
|
2020-06-28 00:06:23 +02:00
|
|
|
this._wikipedialink.Render() +
|
2020-06-27 03:06:51 +02:00
|
|
|
this._osmLink.Render() +
|
|
|
|
"</div>" +
|
2020-06-28 00:06:23 +02:00
|
|
|
|
2020-06-27 03:06:51 +02:00
|
|
|
"<div class='infoboxcontents'>" +
|
2020-07-05 18:59:47 +02:00
|
|
|
new VerticalCombine(info, "infobox-information ").Render() +
|
2020-06-28 00:06:23 +02:00
|
|
|
|
2020-07-05 18:59:47 +02:00
|
|
|
questionsHtml +
|
2020-06-28 00:06:23 +02:00
|
|
|
|
2020-06-27 03:06:51 +02:00
|
|
|
|
|
|
|
"</div>" +
|
|
|
|
"" +
|
|
|
|
"</div>";
|
|
|
|
}
|
2020-07-20 09:57:19 +02:00
|
|
|
|
2020-07-20 15:54:50 +02:00
|
|
|
|
|
|
|
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|