Few extra tweaks

This commit is contained in:
Pieter Vander Vennet 2020-08-08 21:49:39 +02:00
parent 8d3c8ed9d9
commit 7757bb051c
5 changed files with 24 additions and 10 deletions

View file

@ -234,7 +234,7 @@ export class CustomLayoutFromJSON {
name: t(json.title), name: t(json.title),
icon: json.icon, icon: json.icon,
minzoom: json.minzoom, minzoom: json.minzoom,
title: tr(json.title), title: tr(json.title) ,
presets: json.presets.map((preset) => { presets: json.presets.map((preset) => {
return CustomLayoutFromJSON.PresetFromJson(json, preset) return CustomLayoutFromJSON.PresetFromJson(json, preset)
}), }),

View file

@ -126,6 +126,7 @@ export class ShareScreen extends UIElement {
this._options = new VerticalCombine(optionCheckboxes) this._options = new VerticalCombine(optionCheckboxes)
const url = currentLocation.map(() => { const url = currentLocation.map(() => {
let literalText = "https://pietervdvn.github.io/MapComplete/" + layout.name + ".html" let literalText = "https://pietervdvn.github.io/MapComplete/" + layout.name + ".html"
const parts = Utils.NoNull(optionParts.map((eventSource) => eventSource.data)); const parts = Utils.NoNull(optionParts.map((eventSource) => eventSource.data));
@ -133,6 +134,8 @@ export class ShareScreen extends UIElement {
let hash = ""; let hash = "";
if (State.state.layoutDefinition !== undefined) { if (State.state.layoutDefinition !== undefined) {
hash = ("#" + State.state.layoutDefinition) hash = ("#" + State.state.layoutDefinition)
literalText = "https://pietervdvn.github.io/MapComplete/index.html"
parts.push("userlayout=true");
} }
if (parts.length === 0) { if (parts.length === 0) {
@ -160,7 +163,7 @@ export class ShareScreen extends UIElement {
if(State.state.layoutDefinition !== undefined){ if(State.state.layoutDefinition !== undefined){
this._editLayout = this._editLayout =
new FixedUiElement(`<h3>Edit this theme</h3>`+ new FixedUiElement(`<h3>Edit this theme</h3>`+
`<a target='_blank' https://pietervdvn.github.io/MapComplete/customGenerator.html#${State.state.layoutDefinition}'>Click here to edit</a>`) `<a target='_blank' href='https://pietervdvn.github.io/MapComplete/customGenerator.html#${State.state.layoutDefinition}'>Click here to edit</a>`)
} }

View file

@ -17,4 +17,4 @@ new VariableUiElement(connection.userDetails.map<string>((userdetails : UserDeta
const themeGenerator = new ThemeGenerator(connection, window.location.hash?.substr(1)); const themeGenerator = new ThemeGenerator(connection, window.location.hash?.substr(1));
themeGenerator.AttachTo("layoutCreator") themeGenerator.AttachTo("layoutCreator")
new Preview(themeGenerator.url).AttachTo("preview"); new Preview(themeGenerator.url, themeGenerator.themeObject).AttachTo("preview");

View file

@ -88,6 +88,7 @@ TagRendering.injectFunction();
State.state = new State(layoutToUse); State.state = new State(layoutToUse);
if(layoutFromBase64 !== "false"){ if(layoutFromBase64 !== "false"){
State.state.layoutDefinition = hash.substr(1); State.state.layoutDefinition = hash.substr(1);
console.log(State.state.layoutDefinition)
} }
InitUiElements.InitBaseMap(); InitUiElements.InitBaseMap();

View file

@ -33,15 +33,17 @@ function TagsToString(tags: string | string [] | { k: string, v: string }[]) {
export class Preview extends UIElement { export class Preview extends UIElement {
private url: UIEventSource<string>; private url: UIEventSource<string>;
private config: UIEventSource<LayoutConfigJson>;
constructor(url: UIEventSource<string>) { constructor(url: UIEventSource<string>, config: UIEventSource<LayoutConfigJson>) {
super(url); super(url);
this.config = config;
this.url = url; this.url = url;
} }
InnerRender(): string { InnerRender(): string {
const url = this.url.data; const url = this.url.data;
return ""; // `<iframe src="${url}" width="100%" height="100%" title="Test"></iframe>` return JSON.stringify(this.config.data, null, 2)
} }
} }
@ -66,7 +68,6 @@ class MappingGenerator extends UIElement {
{ {
const self = this; const self = this;
this.elements = [ this.elements = [
new FixedUiElement("<h5>Mapping</h5>"),
generateField(fullConfig, "If these tags apply", "if", mapping), generateField(fullConfig, "If these tags apply", "if", mapping),
generateField(fullConfig, "Then: show this text", "then", mapping), generateField(fullConfig, "Then: show this text", "then", mapping),
new Button("Remove this mapping", () => { new Button("Remove this mapping", () => {
@ -123,6 +124,9 @@ class TagRenderingGenerator
generateField) generateField)
}), }),
new Button("Add mapping", () => { new Button("Add mapping", () => {
if(tagRendering.mappings === undefined){
tagRendering.mappings = []
}
tagRendering.mappings.push({if: "", then: ""}); tagRendering.mappings.push({if: "", then: ""});
self.CreateElements(fullConfig, layerConfig, tagRendering, generateField, isTitle); self.CreateElements(fullConfig, layerConfig, tagRendering, generateField, isTitle);
self.Update(); self.Update();
@ -213,8 +217,7 @@ class LayerGenerator extends UIElement {
private CreateElements(fullConfig: UIEventSource<LayoutConfigJson>, layerConfig: LayerConfigJson, generateField: (src: UIEventSource<any>, label: string, key: string, root: any, deflt?: string) => UIElement) { private CreateElements(fullConfig: UIEventSource<LayoutConfigJson>, layerConfig: LayerConfigJson, generateField: (src: UIEventSource<any>, label: string, key: string, root: any, deflt?: string) => UIElement) {
const self = this; const self = this;
this.uielements = [ this.uielements = [
generateField(fullConfig, "id", "id", layerConfig), generateField(fullConfig, "The name of this layer", "id", layerConfig),
generateField(fullConfig, "The title of this layer", "title", layerConfig),
generateField(fullConfig, "A description of objects for this layer", "description", layerConfig), generateField(fullConfig, "A description of objects for this layer", "description", layerConfig),
generateField(fullConfig, "The icon of this layer, either a URL or a base64-encoded svg", "icon", layerConfig), generateField(fullConfig, "The icon of this layer, either a URL or a base64-encoded svg", "icon", layerConfig),
generateField(fullConfig, "The default stroke color", "color", layerConfig), generateField(fullConfig, "The default stroke color", "color", layerConfig),
@ -231,7 +234,14 @@ class LayerGenerator extends UIElement {
self.CreateElements(fullConfig, layerConfig, generateField); self.CreateElements(fullConfig, layerConfig, generateField);
self.Update(); self.Update();
}), }),
new TagRenderingGenerator(fullConfig, layerConfig, layerConfig.title, generateField, true), new TagRenderingGenerator(fullConfig, layerConfig, layerConfig.title ?? {
key: "",
addExtraTags: "",
mappings: [],
question: "",
render: "Title",
type: "text"
}, generateField, true),
...layerConfig.tagRenderings.map(tr => new TagRenderingGenerator(fullConfig, layerConfig, tr, generateField)), ...layerConfig.tagRenderings.map(tr => new TagRenderingGenerator(fullConfig, layerConfig, tr, generateField)),
new Button("Add a tag rendering", () => { new Button("Add a tag rendering", () => {
layerConfig.tagRenderings.push({ layerConfig.tagRenderings.push({
@ -327,7 +337,7 @@ export class ThemeGenerator extends UIElement {
private readonly userDetails: UIEventSource<UserDetails>; private readonly userDetails: UIEventSource<UserDetails>;
private readonly themeObject: UIEventSource<LayoutConfigJson>; public readonly themeObject: UIEventSource<LayoutConfigJson>;
private readonly allQuestionFields: UIElement[]; private readonly allQuestionFields: UIElement[];
public url: UIEventSource<string>; public url: UIEventSource<string>;