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-05 18:59:47 +02:00
|
|
|
import {TagRendering, TagRenderingOptions} from "../Customizations/TagRendering";
|
|
|
|
import {OsmLink} from "../Customizations/Questions/OsmLink";
|
|
|
|
import {WikipediaLink} from "../Customizations/Questions/WikipediaLink";
|
|
|
|
import {And} from "../Logic/TagsFilter";
|
2020-06-27 03:06:51 +02:00
|
|
|
|
|
|
|
export class FeatureInfoBox extends UIElement {
|
|
|
|
|
|
|
|
private _tagsES: UIEventSource<any>;
|
|
|
|
|
|
|
|
|
|
|
|
private _title: UIElement;
|
|
|
|
private _osmLink: UIElement;
|
|
|
|
|
|
|
|
|
|
|
|
private _questions: QuestionPicker;
|
|
|
|
|
|
|
|
private _changes: Changes;
|
|
|
|
private _userDetails: UIEventSource<UserDetails>;
|
|
|
|
private _imageElement: ImageCarousel;
|
2020-06-28 00:06:23 +02:00
|
|
|
private _pictureUploader: UIElement;
|
|
|
|
private _wikipedialink: UIElement;
|
2020-07-05 18:59:47 +02:00
|
|
|
private _infoboxes: TagRendering[];
|
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,
|
|
|
|
userDetails: UIEventSource<UserDetails>,
|
2020-07-05 18:59:47 +02:00
|
|
|
preferedPictureLicense: UIEventSource<string>
|
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-07 15:08:52 +02:00
|
|
|
this._imageElement = new ImageCarousel(this._tagsES, changes);
|
2020-06-27 03:06:51 +02:00
|
|
|
|
2020-07-05 18:59:47 +02:00
|
|
|
this._infoboxes = [];
|
|
|
|
for (const tagRenderingOption of elementsToShow) {
|
|
|
|
if (tagRenderingOption.options === undefined) {
|
|
|
|
throw "Tagrendering.options not defined"
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|
2020-07-05 18:59:47 +02:00
|
|
|
this._infoboxes.push(new TagRendering(this._tagsES, this._changes, tagRenderingOption.options))
|
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: ""}]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
this._title = new TagRendering(this._tagsES, this._changes, title.options);
|
2020-06-27 03:06:51 +02:00
|
|
|
|
2020-07-05 18:59:47 +02:00
|
|
|
this._osmLink = new TagRendering(this._tagsES, this._changes, new OsmLink().options);
|
|
|
|
this._wikipedialink = new TagRendering(this._tagsES, this._changes, new WikipediaLink().options);
|
2020-07-01 17:38:48 +02:00
|
|
|
this._pictureUploader = new OsmImageUploadHandler(tagsES, userDetails, preferedPictureLicense,
|
|
|
|
changes, this._imageElement.slideshow).getUI();
|
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 = [];
|
|
|
|
const questions = [];
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
if (mostImportantQuestion === undefined || question.priority > score) {
|
|
|
|
mostImportantQuestion = question;
|
|
|
|
score = question.priority;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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'>" +
|
|
|
|
|
|
|
|
this._imageElement.Render() +
|
2020-06-28 00:06:23 +02:00
|
|
|
this._pictureUploader.Render() +
|
|
|
|
|
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>";
|
|
|
|
}
|
|
|
|
|
|
|
|
Activate() {
|
|
|
|
super.Activate();
|
|
|
|
this._imageElement.Activate();
|
2020-06-28 00:06:23 +02:00
|
|
|
this._pictureUploader.Activate();
|
2020-07-05 18:59:47 +02:00
|
|
|
for (const infobox of this._infoboxes) {
|
|
|
|
infobox.Activate();
|
|
|
|
}
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Update() {
|
|
|
|
super.Update();
|
|
|
|
this._imageElement.Update();
|
2020-06-28 00:06:23 +02:00
|
|
|
this._pictureUploader.Update();
|
2020-07-05 18:59:47 +02:00
|
|
|
this._title.Update();
|
|
|
|
for (const infobox of this._infoboxes) {
|
|
|
|
infobox.Update();
|
|
|
|
}
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|
|
|
|
}
|