forked from MapComplete/MapComplete
New question system
This commit is contained in:
parent
1738fc4252
commit
d1f8080c24
45 changed files with 1391 additions and 689 deletions
|
|
@ -1,14 +1,15 @@
|
|||
import {UIElement} from "./UIElement";
|
||||
import {TagMapping, TagMappingOptions} from "./TagMapping";
|
||||
import {Question, QuestionDefinition} from "../Logic/Question";
|
||||
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";
|
||||
import {CommonTagMappings} from "../Layers/CommonTagMappings";
|
||||
import {VerticalCombine} from "./Base/VerticalCombine";
|
||||
import {TagRendering, TagRenderingOptions} from "../Customizations/TagRendering";
|
||||
import {OsmLink} from "../Customizations/Questions/OsmLink";
|
||||
import {WikipediaLink} from "../Customizations/Questions/WikipediaLink";
|
||||
import {And} from "../Logic/TagsFilter";
|
||||
|
||||
export class FeatureInfoBox extends UIElement {
|
||||
|
||||
|
|
@ -17,7 +18,6 @@ export class FeatureInfoBox extends UIElement {
|
|||
|
||||
private _title: UIElement;
|
||||
private _osmLink: UIElement;
|
||||
private _infoElements: UIElement[]
|
||||
|
||||
|
||||
private _questions: QuestionPicker;
|
||||
|
|
@ -27,15 +27,16 @@ export class FeatureInfoBox extends UIElement {
|
|||
private _imageElement: ImageCarousel;
|
||||
private _pictureUploader: UIElement;
|
||||
private _wikipedialink: UIElement;
|
||||
private _infoboxes: TagRendering[];
|
||||
|
||||
|
||||
constructor(
|
||||
tagsES: UIEventSource<any>,
|
||||
elementsToShow: (TagMappingOptions | QuestionDefinition | UIElement)[],
|
||||
questions: QuestionDefinition[],
|
||||
title: TagRenderingOptions,
|
||||
elementsToShow: TagRenderingOptions[],
|
||||
changes: Changes,
|
||||
userDetails: UIEventSource<UserDetails>,
|
||||
preferedPictureLicense : UIEventSource<string>
|
||||
preferedPictureLicense: UIEventSource<string>
|
||||
) {
|
||||
super(tagsES);
|
||||
this._tagsES = tagsES;
|
||||
|
|
@ -45,48 +46,66 @@ export class FeatureInfoBox extends UIElement {
|
|||
|
||||
this._imageElement = new ImageCarousel(this._tagsES);
|
||||
|
||||
this._questions = new QuestionPicker(
|
||||
this._changes.asQuestions(questions), this._tagsES);
|
||||
|
||||
var infoboxes: UIElement[] = [];
|
||||
for (const uiElement of elementsToShow) {
|
||||
if (uiElement instanceof QuestionDefinition) {
|
||||
const questionDef = uiElement as QuestionDefinition;
|
||||
const question = new Question(this._changes, questionDef);
|
||||
infoboxes.push(question.CreateHtml(this._tagsES));
|
||||
} else if (uiElement instanceof TagMappingOptions) {
|
||||
const tagMappingOpt = uiElement as TagMappingOptions;
|
||||
infoboxes.push(new TagMapping(tagMappingOpt, this._tagsES))
|
||||
} else {
|
||||
const ui = uiElement as UIElement;
|
||||
infoboxes.push(ui);
|
||||
this._infoboxes = [];
|
||||
for (const tagRenderingOption of elementsToShow) {
|
||||
if (tagRenderingOption.options === undefined) {
|
||||
throw "Tagrendering.options not defined"
|
||||
}
|
||||
|
||||
this._infoboxes.push(new TagRendering(this._tagsES, this._changes, tagRenderingOption.options))
|
||||
}
|
||||
|
||||
this._title = infoboxes.shift();
|
||||
this._infoElements = infoboxes;
|
||||
title = title ?? new TagRenderingOptions(
|
||||
{
|
||||
mappings: [{k: new And([]), txt: ""}]
|
||||
}
|
||||
)
|
||||
|
||||
this._osmLink = new TagMapping(CommonTagMappings.osmLink, this._tagsES);
|
||||
this._wikipedialink = new TagMapping(CommonTagMappings.wikipediaLink, this._tagsES);
|
||||
this._title = new TagRendering(this._tagsES, this._changes, title.options);
|
||||
|
||||
this._osmLink = new TagRendering(this._tagsES, this._changes, new OsmLink().options);
|
||||
this._wikipedialink = new TagRendering(this._tagsES, this._changes, new WikipediaLink().options);
|
||||
this._pictureUploader = new OsmImageUploadHandler(tagsES, userDetails, preferedPictureLicense,
|
||||
changes, this._imageElement.slideshow).getUI();
|
||||
|
||||
|
||||
}
|
||||
|
||||
InnerRender(): string {
|
||||
|
||||
let questions = "";
|
||||
|
||||
if (this._userDetails.data.loggedIn) {
|
||||
// Questions is embedded in a span, because it'll hide the parent when the questions dissappear
|
||||
questions = "<span>"+this._questions.HideOnEmpty(true).Render()+"</span>";
|
||||
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();
|
||||
}
|
||||
|
||||
return "<div class='featureinfobox'>" +
|
||||
"<div class='featureinfoboxtitle'>" +
|
||||
"<span>" + this._title.Render() + "</span>" +
|
||||
"<span>" +
|
||||
this._title.Render() +
|
||||
"</span>" +
|
||||
this._wikipedialink.Render() +
|
||||
this._osmLink.Render() +
|
||||
"</div>" +
|
||||
|
|
@ -96,9 +115,9 @@ export class FeatureInfoBox extends UIElement {
|
|||
this._imageElement.Render() +
|
||||
this._pictureUploader.Render() +
|
||||
|
||||
new VerticalCombine(this._infoElements, 'infobox-information').HideOnEmpty(true).Render() +
|
||||
new VerticalCombine(info, "infobox-information ").Render() +
|
||||
|
||||
questions +
|
||||
questionsHtml +
|
||||
|
||||
|
||||
"</div>" +
|
||||
|
|
@ -110,11 +129,18 @@ export class FeatureInfoBox extends UIElement {
|
|||
super.Activate();
|
||||
this._imageElement.Activate();
|
||||
this._pictureUploader.Activate();
|
||||
for (const infobox of this._infoboxes) {
|
||||
infobox.Activate();
|
||||
}
|
||||
}
|
||||
|
||||
Update() {
|
||||
super.Update();
|
||||
this._imageElement.Update();
|
||||
this._pictureUploader.Update();
|
||||
this._title.Update();
|
||||
for (const infobox of this._infoboxes) {
|
||||
infobox.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue