mapcomplete/UI/FeatureInfoBox.ts

121 lines
3.6 KiB
TypeScript
Raw Normal View History

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 01:12:44 +00:00
import {VerticalCombine} from "./Base/VerticalCombine";
2020-07-12 21:19:05 +00:00
import {TagRenderingOptions} from "../Customizations/TagRendering";
2020-07-05 16:59:47 +00:00
import {OsmLink} from "../Customizations/Questions/OsmLink";
import {WikipediaLink} from "../Customizations/Questions/WikipediaLink";
import {And} from "../Logic/TagsFilter";
2020-07-20 22:07:04 +00:00
import {TagDependantUIElement, TagDependantUIElementConstructor} from "../Customizations/UIElementConstructor";
export class FeatureInfoBox extends UIElement {
private _tagsES: UIEventSource<any>;
private _changes: Changes;
private _userDetails: UIEventSource<UserDetails>;
private _title: UIElement;
private _osmLink: UIElement;
private _wikipedialink: UIElement;
2020-07-12 21:19:05 +00:00
private _infoboxes: TagDependantUIElement[];
private _questions: QuestionPicker;
constructor(
tagsES: UIEventSource<any>,
2020-07-05 16:59:47 +00:00
title: TagRenderingOptions,
2020-07-20 22:07:04 +00:00
elementsToShow: TagDependantUIElementConstructor[],
changes: Changes,
userDetails: UIEventSource<UserDetails>
) {
super(tagsES);
this._tagsES = tagsES;
this._changes = changes;
this._userDetails = userDetails;
2020-06-29 14:21:36 +00:00
this.ListenTo(userDetails);
const deps = {tags:this._tagsES , changes:this._changes}
2020-07-05 16:59:47 +00:00
this._infoboxes = [];
elementsToShow = elementsToShow ?? []
2020-07-05 16:59:47 +00:00
for (const tagRenderingOption of elementsToShow) {
2020-07-12 21:19:05 +00:00
this._infoboxes.push(
tagRenderingOption.construct(deps));
}
2020-07-05 16:59:47 +00:00
title = title ?? new TagRenderingOptions(
{
mappings: [{k: new And([]), txt: ""}]
}
)
this._title = new TagRenderingOptions(title.options).construct(deps);
this._osmLink =new OsmLink().construct(deps);
this._wikipedialink = new WikipediaLink().construct(deps);
}
InnerRender(): string {
2020-07-05 16:59:47 +00:00
const info = [];
2020-07-12 21:19:05 +00:00
const questions : TagDependantUIElement[] = [];
2020-07-05 16:59:47 +00: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 21:19:05 +00:00
if (mostImportantQuestion === undefined || question.Priority() > score) {
2020-07-05 16:59:47 +00:00
mostImportantQuestion = question;
2020-07-12 21:19:05 +00:00
score = question.Priority();
2020-07-05 16:59:47 +00:00
}
}
questionsHtml = mostImportantQuestion.Render();
}
return "<div class='featureinfobox'>" +
"<div class='featureinfoboxtitle'>" +
2020-07-05 16:59:47 +00:00
"<span>" +
this._title.Render() +
"</span>" +
this._wikipedialink.Render() +
this._osmLink.Render() +
"</div>" +
"<div class='infoboxcontents'>" +
2020-07-05 16:59:47 +00:00
new VerticalCombine(info, "infobox-information ").Render() +
2020-07-05 16:59:47 +00:00
questionsHtml +
"</div>" +
"" +
"</div>";
}
2020-07-20 07:57:19 +00:00
2020-07-20 13:54:50 +00:00
}