forked from MapComplete/MapComplete
Fix tests, fix long load by offloading minimap detection to generateLayerOverview
This commit is contained in:
parent
d7f8ff01d5
commit
cbc7fa6553
6 changed files with 56 additions and 33 deletions
|
@ -2,7 +2,7 @@ import {Utils} from "../Utils";
|
||||||
|
|
||||||
export default class Constants {
|
export default class Constants {
|
||||||
|
|
||||||
public static vNumber = "0.15.0-alpha";
|
public static vNumber = "0.14.1-alpha";
|
||||||
public static ImgurApiKey = '7070e7167f0a25a'
|
public static ImgurApiKey = '7070e7167f0a25a'
|
||||||
public static readonly mapillary_client_token_v4 = "MLY|4441509239301885|b40ad2d3ea105435bd40c7e76993ae85"
|
public static readonly mapillary_client_token_v4 = "MLY|4441509239301885|b40ad2d3ea105435bd40c7e76993ae85"
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import LineRenderingConfigJson from "../Json/LineRenderingConfigJson";
|
||||||
import {LayerConfigJson} from "../Json/LayerConfigJson";
|
import {LayerConfigJson} from "../Json/LayerConfigJson";
|
||||||
import Constants from "../../Constants";
|
import Constants from "../../Constants";
|
||||||
import {AllKnownLayouts} from "../../../Customizations/AllKnownLayouts";
|
import {AllKnownLayouts} from "../../../Customizations/AllKnownLayouts";
|
||||||
|
import {SubstitutedTranslation} from "../../../UI/SubstitutedTranslation";
|
||||||
|
|
||||||
export interface DesugaringContext {
|
export interface DesugaringContext {
|
||||||
tagRenderings: Map<string, TagRenderingConfigJson>
|
tagRenderings: Map<string, TagRenderingConfigJson>
|
||||||
|
@ -153,6 +154,52 @@ class Fuse<T> extends DesugaringStep<T> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AddMiniMap extends DesugaringStep<LayerConfigJson> {
|
||||||
|
constructor() {
|
||||||
|
super("Adds a default 'minimap'-element to the tagrenderings if none of the elements define such a minimap", ["tagRenderings"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if this tag rendering has a minimap in some language.
|
||||||
|
* Note: this minimap can be hidden by conditions
|
||||||
|
*/
|
||||||
|
private static hasMinimap(renderingConfig: TagRenderingConfigJson): boolean {
|
||||||
|
const translations: Translation[] = Utils.NoNull([renderingConfig.render, ...(renderingConfig.mappings ?? []).map(m => m.then)]);
|
||||||
|
for (const translation of translations) {
|
||||||
|
for (const key in translation.translations) {
|
||||||
|
if (!translation.translations.hasOwnProperty(key)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const template = translation.translations[key]
|
||||||
|
const parts = SubstitutedTranslation.ExtractSpecialComponents(template)
|
||||||
|
const hasMiniMap = parts.filter(part => part.special !== undefined).some(special => special.special.func.funcName === "minimap")
|
||||||
|
if (hasMiniMap) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
convert(state: DesugaringContext, layerConfig: LayerConfigJson, context: string): { result: LayerConfigJson; errors: string[]; warnings: string[] } {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const hasMinimap = layerConfig.tagRenderings?.some(tr => AddMiniMap.hasMinimap(<TagRenderingConfigJson> tr)) ?? true
|
||||||
|
if (!hasMinimap) {
|
||||||
|
layerConfig = {...layerConfig}
|
||||||
|
layerConfig.tagRenderings = [...layerConfig.tagRenderings]
|
||||||
|
layerConfig.tagRenderings.push(state.tagRenderings.get("minimap"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
errors:[],
|
||||||
|
warnings: [],
|
||||||
|
result: layerConfig
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ExpandTagRendering extends Conversion<string | TagRenderingConfigJson | { builtin: string | string[], override: any }, TagRenderingConfigJson[]> {
|
class ExpandTagRendering extends Conversion<string | TagRenderingConfigJson | { builtin: string | string[], override: any }, TagRenderingConfigJson[]> {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("Converts a tagRenderingSpec into the full tagRendering", []);
|
super("Converts a tagRenderingSpec into the full tagRendering", []);
|
||||||
|
@ -1000,6 +1047,7 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> {
|
||||||
new AddDefaultLayers(),
|
new AddDefaultLayers(),
|
||||||
new AddDependencyLayersToTheme(),
|
new AddDependencyLayersToTheme(),
|
||||||
new OnEvery("layers", new PrepareLayer()),
|
new OnEvery("layers", new PrepareLayer()),
|
||||||
|
new OnEvery("layers", new AddMiniMap())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -235,13 +235,13 @@ export default class LayerConfig extends WithContextLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const missingIds = json.tagRenderings?.filter(tr => typeof tr !== "string" && tr["builtin"] === undefined && tr["id"] === undefined && tr["rewrite"] === undefined) ?? [];
|
const missingIds = Utils.NoNull(json.tagRenderings)?.filter(tr => typeof tr !== "string" && tr["builtin"] === undefined && tr["id"] === undefined && tr["rewrite"] === undefined) ?? [];
|
||||||
if (missingIds?.length > 0 && official) {
|
if (missingIds?.length > 0 && official) {
|
||||||
console.error("Some tagRenderings of", this.id, "are missing an id:", missingIds)
|
console.error("Some tagRenderings of", this.id, "are missing an id:", missingIds)
|
||||||
throw "Missing ids in tagrenderings"
|
throw "Missing ids in tagrenderings"
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tagRenderings = (json.tagRenderings ?? []).map((tr, i) => new TagRenderingConfig(<TagRenderingConfigJson>tr, this.id + ".tagRenderings[" + i + "]"))
|
this.tagRenderings = (Utils.NoNull(json.tagRenderings) ?? []).map((tr, i) => new TagRenderingConfig(<TagRenderingConfigJson>tr, this.id + ".tagRenderings[" + i + "]"))
|
||||||
|
|
||||||
this.filters = (json.filter ?? []).map((option, i) => {
|
this.filters = (json.filter ?? []).map((option, i) => {
|
||||||
return new FilterConfig(option, `${context}.filter-[${i}]`)
|
return new FilterConfig(option, `${context}.filter-[${i}]`)
|
||||||
|
|
|
@ -13,9 +13,7 @@ import DeleteWizard from "./DeleteWizard";
|
||||||
import SplitRoadWizard from "./SplitRoadWizard";
|
import SplitRoadWizard from "./SplitRoadWizard";
|
||||||
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
|
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
|
||||||
import LayerConfig from "../../Models/ThemeConfig/LayerConfig";
|
import LayerConfig from "../../Models/ThemeConfig/LayerConfig";
|
||||||
import {Translation} from "../i18n/Translation";
|
|
||||||
import {Utils} from "../../Utils";
|
import {Utils} from "../../Utils";
|
||||||
import {SubstitutedTranslation} from "../SubstitutedTranslation";
|
|
||||||
import MoveWizard from "./MoveWizard";
|
import MoveWizard from "./MoveWizard";
|
||||||
import Toggle from "../Input/Toggle";
|
import Toggle from "../Input/Toggle";
|
||||||
|
|
||||||
|
@ -162,11 +160,6 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const hasMinimap = layerConfig.tagRenderings.some(tr => FeatureInfoBox.hasMinimap(tr))
|
|
||||||
if (!hasMinimap) {
|
|
||||||
allRenderings.push(new TagRenderingAnswer(tags, SharedTagRenderings.SharedTagRendering.get("minimap"), State.state))
|
|
||||||
}
|
|
||||||
|
|
||||||
editElements.push(
|
editElements.push(
|
||||||
new VariableUiElement(
|
new VariableUiElement(
|
||||||
State.state.osmConnection.userDetails
|
State.state.osmConnection.userDetails
|
||||||
|
@ -214,27 +207,7 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
|
||||||
return new Combine(allRenderings).SetClass("block")
|
return new Combine(allRenderings).SetClass("block")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if this tag rendering has a minimap in some language.
|
|
||||||
* Note: this minimap can be hidden by conditions
|
|
||||||
*/
|
|
||||||
private static hasMinimap(renderingConfig: TagRenderingConfig): boolean {
|
|
||||||
const translations: Translation[] = Utils.NoNull([renderingConfig.render, ...(renderingConfig.mappings ?? []).map(m => m.then)]);
|
|
||||||
for (const translation of translations) {
|
|
||||||
for (const key in translation.translations) {
|
|
||||||
if (!translation.translations.hasOwnProperty(key)) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
const template = translation.translations[key]
|
|
||||||
const parts = SubstitutedTranslation.ExtractSpecialComponents(template)
|
|
||||||
const hasMiniMap = parts.filter(part => part.special !== undefined).some(special => special.special.func.funcName === "minimap")
|
|
||||||
if (hasMiniMap) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
2
Utils.ts
2
Utils.ts
|
@ -137,7 +137,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NoNull<T>(array: T[]): T[] {
|
public static NoNull<T>(array: T[]): T[] {
|
||||||
return array.filter(o => o !== undefined && o !== null)
|
return array?.filter(o => o !== undefined && o !== null)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Hist(array: string[]): Map<string, number> {
|
public static Hist(array: string[]): Map<string, number> {
|
||||||
|
|
|
@ -15,7 +15,7 @@ npm run test &&
|
||||||
npm run generate:layouts
|
npm run generate:layouts
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "ERROR"
|
echo "ERROR - stopping the build"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -23,6 +23,8 @@ fi
|
||||||
cp -r assets/layers/ dist/assets/layers/
|
cp -r assets/layers/ dist/assets/layers/
|
||||||
cp -r assets/themes/ dist/assets/themes/
|
cp -r assets/themes/ dist/assets/themes/
|
||||||
cp -r assets/svg/ dist/assets/svg/
|
cp -r assets/svg/ dist/assets/svg/
|
||||||
|
cp assets/*.png dist/assets/
|
||||||
|
cp assets/*.svg dist/assets/
|
||||||
|
|
||||||
SRC_MAPS="--no-source-maps"
|
SRC_MAPS="--no-source-maps"
|
||||||
BRANCH=`git rev-parse --abbrev-ref HEAD`
|
BRANCH=`git rev-parse --abbrev-ref HEAD`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue