Themes: add various services to hackerspaces and makerspaces, add icons, some fixes to make this work with expandRewrite

This commit is contained in:
Pieter Vander Vennet 2024-01-02 20:19:43 +01:00
parent d144ae9533
commit 8ceda1cc5f
24 changed files with 731 additions and 42 deletions

View file

@ -55,12 +55,19 @@ export class ExpandRewrite<T> extends Conversion<T | RewritableConfigJson<T>, T[
for (const key in obj) {
let subtarget = target
if (isTr && target[key] !== undefined) {
if (isTr) {
// The target is a translation AND the current object is a translation
// This means we should recursively replace with the translated value
subtarget = target[key]
if (target[key]) {
// A translation is available!
subtarget = target[key]
} else if (target["en"]) {
subtarget = target["en"]
} else {
// Take the first
subtarget = target[Object.keys(target)[0]]
}
}
obj[key] = replaceRecursive(obj[key], subtarget)
}
return obj

View file

@ -32,6 +32,7 @@ import { ConfigMeta } from "../../../UI/Studio/configMeta"
import LineRenderingConfigJson from "../Json/LineRenderingConfigJson"
import { ConversionContext } from "./ConversionContext"
import { ExpandRewrite } from "./ExpandRewrite"
import { ALL } from "node:dns"
class ExpandFilter extends DesugaringStep<LayerConfigJson> {
private static readonly predefinedFilters = ExpandFilter.load_filters()
@ -1133,9 +1134,43 @@ export class AutoTitleIcon extends DesugaringStep<LayerConfigJson> {
)
}
private createTitleIconsBasedOn(
tr: QuestionableTagRenderingConfigJson
): TagRenderingConfigJson | undefined {
const mappings: { if: TagConfigJson; then: string }[] = tr.mappings
?.filter((m) => m.icon !== undefined)
.map((m) => {
const path: string = typeof m.icon === "string" ? m.icon : m.icon.path
const img = `<img class="m-1 h-6 w-6 low-interaction rounded" src='${path}'/>`
return { if: m.if, then: img }
})
if (!mappings || mappings.length === 0) {
return undefined
}
return <TagRenderingConfigJson>{
id: "title_icon_auto_" + tr.id,
mappings,
}
}
convert(json: LayerConfigJson, context: ConversionContext): LayerConfigJson {
json = { ...json }
json.titleIcons = [...json.titleIcons]
const allAutoIndex = json.titleIcons.indexOf(<any>"auto:*")
if (allAutoIndex >= 0) {
const generated = Utils.NoNull(
json.tagRenderings.map((tr) => {
if (typeof tr === "string") {
return undefined
}
return this.createTitleIconsBasedOn(<any>tr)
})
)
json.titleIcons.splice(allAutoIndex, 1, ...generated)
return json
}
for (let i = 0; i < json.titleIcons.length; i++) {
const titleIcon = json.titleIcons[i]
if (typeof titleIcon !== "string") {
@ -1152,14 +1187,9 @@ export class AutoTitleIcon extends DesugaringStep<LayerConfigJson> {
context.enters("titleIcons", i).err("TagRendering with id " + trId + " not found")
continue
}
const mappings: { if: TagConfigJson; then: string }[] = tr.mappings
?.filter((m) => m.icon !== undefined)
.map((m) => {
const path: string = typeof m.icon === "string" ? m.icon : m.icon.path
const img = `<img class="m-1 h-6 w-6 low-interaction rounded" src='${path}'/>`
return { if: m.if, then: img }
})
if (mappings.length === 0) {
const generated = this.createTitleIconsBasedOn(tr)
if (!generated) {
context
.enters("titleIcons", i)
.warn(
@ -1169,10 +1199,7 @@ export class AutoTitleIcon extends DesugaringStep<LayerConfigJson> {
)
continue
}
json.titleIcons[i] = <TagRenderingConfigJson>{
id: "title_icon_auto_" + trId,
mappings,
}
json.titleIcons[i] = generated
}
return json
}

View file

@ -236,8 +236,10 @@ export default class TagRenderingConfig {
const commonIconSize =
Utils.NoNull(
json.mappings.map((m) => (m.icon !== undefined ? m.icon["class"] : undefined))
)[0] ?? "small"
json.mappings.map((m) => (!!m.icon ? m.icon["class"] : undefined))
)[0] ??
json["#iconsize"] ??
"small"
this.mappings = json.mappings.map((m, i) =>
TagRenderingConfig.ExtractMapping(
m,
@ -367,7 +369,7 @@ export default class TagRenderingConfig {
let icon = undefined
let iconClass = commonSize
if (mapping.icon !== undefined) {
if (!!mapping.icon) {
if (typeof mapping.icon === "string" && mapping.icon !== "") {
let stripped = mapping.icon
if (stripped.endsWith(".svg")) {
@ -381,7 +383,7 @@ export default class TagRenderingConfig {
} else {
icon = mapping.icon
}
} else {
} else if (mapping.icon["path"]) {
icon = mapping.icon["path"]
iconClass = mapping.icon["class"] ?? iconClass
}