From 8ceda1cc5f7e549ccecc65b6469a7195de1022cc Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Tue, 2 Jan 2024 20:19:43 +0100 Subject: [PATCH] Themes: add various services to hackerspaces and makerspaces, add icons, some fixes to make this work with expandRewrite --- assets/layers/hackerspace/3d_printer.svg | 59 ++++++++++ .../layers/hackerspace/3d_printer.svg.license | 2 + assets/layers/hackerspace/bicycle.svg | 57 ++++++++++ assets/layers/hackerspace/bicycle.svg.license | 2 + assets/layers/hackerspace/cnc.svg | 64 +++++++++++ assets/layers/hackerspace/cnc.svg.license | 2 + assets/layers/hackerspace/hackerspace.json | 64 ++++++++++- assets/layers/hackerspace/lasercutter.svg | 57 ++++++++++ .../hackerspace/lasercutter.svg.license | 2 + assets/layers/hackerspace/license_info.json | 82 ++++++++++++++ assets/layers/hackerspace/media_studio.svg | 107 ++++++++++++++++++ .../hackerspace/media_studio.svg.license | 2 + assets/layers/hackerspace/metal.svg | 68 +++++++++++ assets/layers/hackerspace/metal.svg.license | 2 + assets/layers/hackerspace/sewing_machine.svg | 43 +++++++ .../hackerspace/sewing_machine.svg.license | 2 + assets/layers/hackerspace/woodworking.svg | 62 ++++++++++ .../hackerspace/woodworking.svg.license | 2 + public/css/index-tailwind-output.css | 8 -- .../ThemeConfig/Conversion/ExpandRewrite.ts | 13 ++- .../ThemeConfig/Conversion/PrepareLayer.ts | 51 +++++++-- src/Models/ThemeConfig/TagRenderingConfig.ts | 10 +- .../TagRendering/TagRenderingQuestion.svelte | 2 +- src/index.css | 10 -- 24 files changed, 731 insertions(+), 42 deletions(-) create mode 100644 assets/layers/hackerspace/3d_printer.svg create mode 100644 assets/layers/hackerspace/3d_printer.svg.license create mode 100644 assets/layers/hackerspace/bicycle.svg create mode 100644 assets/layers/hackerspace/bicycle.svg.license create mode 100644 assets/layers/hackerspace/cnc.svg create mode 100644 assets/layers/hackerspace/cnc.svg.license create mode 100644 assets/layers/hackerspace/lasercutter.svg create mode 100644 assets/layers/hackerspace/lasercutter.svg.license create mode 100644 assets/layers/hackerspace/license_info.json create mode 100644 assets/layers/hackerspace/media_studio.svg create mode 100644 assets/layers/hackerspace/media_studio.svg.license create mode 100644 assets/layers/hackerspace/metal.svg create mode 100644 assets/layers/hackerspace/metal.svg.license create mode 100644 assets/layers/hackerspace/sewing_machine.svg create mode 100644 assets/layers/hackerspace/sewing_machine.svg.license create mode 100644 assets/layers/hackerspace/woodworking.svg create mode 100644 assets/layers/hackerspace/woodworking.svg.license diff --git a/assets/layers/hackerspace/3d_printer.svg b/assets/layers/hackerspace/3d_printer.svg new file mode 100644 index 000000000..03d282787 --- /dev/null +++ b/assets/layers/hackerspace/3d_printer.svg @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/assets/layers/hackerspace/3d_printer.svg.license b/assets/layers/hackerspace/3d_printer.svg.license new file mode 100644 index 000000000..026c8c663 --- /dev/null +++ b/assets/layers/hackerspace/3d_printer.svg.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: Verbund Offener Werkstätten +SPDX-License-Identifier: CC-By-SA \ No newline at end of file diff --git a/assets/layers/hackerspace/bicycle.svg b/assets/layers/hackerspace/bicycle.svg new file mode 100644 index 000000000..c8ef5198e --- /dev/null +++ b/assets/layers/hackerspace/bicycle.svg @@ -0,0 +1,57 @@ + + + + + + + + + + diff --git a/assets/layers/hackerspace/bicycle.svg.license b/assets/layers/hackerspace/bicycle.svg.license new file mode 100644 index 000000000..026c8c663 --- /dev/null +++ b/assets/layers/hackerspace/bicycle.svg.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: Verbund Offener Werkstätten +SPDX-License-Identifier: CC-By-SA \ No newline at end of file diff --git a/assets/layers/hackerspace/cnc.svg b/assets/layers/hackerspace/cnc.svg new file mode 100644 index 000000000..758df2ad1 --- /dev/null +++ b/assets/layers/hackerspace/cnc.svg @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/layers/hackerspace/cnc.svg.license b/assets/layers/hackerspace/cnc.svg.license new file mode 100644 index 000000000..026c8c663 --- /dev/null +++ b/assets/layers/hackerspace/cnc.svg.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: Verbund Offener Werkstätten +SPDX-License-Identifier: CC-By-SA \ No newline at end of file diff --git a/assets/layers/hackerspace/hackerspace.json b/assets/layers/hackerspace/hackerspace.json index 92ded04d6..1aa000445 100644 --- a/assets/layers/hackerspace/hackerspace.json +++ b/assets/layers/hackerspace/hackerspace.json @@ -243,7 +243,8 @@ "sourceString": [ "device-key", "{device-name}", - "{negative-name}" + "{negative-name}", + "{icon}" ], "into": [ [ @@ -261,7 +262,8 @@ "de": "3D-Drucker", "ca": "Impressora 3D", "cs": "3D-tiskárna" - } + }, + "./assets/layers/hackerspace/3d_printer.svg" ], [ "lasercutter", @@ -278,7 +280,8 @@ "de": "Laserschneider", "ca": "tallador laser", "cs": "laserová řezačka" - } + }, + "./assets/layers/hackerspace/lasercutter.svg" ], [ "cnc_drilling_machine", @@ -295,7 +298,58 @@ "de": "CNC-Fräse", "ca": "trepant CNC", "cs": "CNC vrtačka" - } + }, + "./assets/layers/hackerspace/cnc.svg" + ], + [ + "media_studio", + { + "en": "a multimedia studio" + }, + { + "en": "multimedia studio" + }, + "./assets/layers/hackerspace/media_studio.svg" + ], + [ + "sewing_machine", + { + "en": "a sewing machine" + }, + { + "en": "sewing machine" + }, + "./assets/layers/hackerspace/sewing_machine.svg" + ], + [ + "workshop:wood", + { + "en": "a woodworking workshop" + }, + { + "en": "woodworking workshop" + }, + "./assets/layers/hackerspace/woodworking.svg" + ], + [ + "workshop:metal", + { + "en": "a metal workshop" + }, + { + "en": "meta workshop" + }, + "./assets/layers/hackerspace/metal.svg" + ], + [ + "bicycle:diy", + { + "en": "a bicycle repair workshop" + }, + { + "en": "bicycle repair workshop" + }, + "./assets/layers/hackerspace/bicycle.svg" ] ] }, @@ -308,9 +362,11 @@ "ca": "Hi ha {device-name} disponible a aquest espai hacker?", "cs": "Je {device-name} dostupné v tomto hackerspace?" }, + "#iconsize": "large", "mappings": [ { "if": "service:device-key=yes", + "icon": "{icon}", "then": { "en": "There is {device-name} available at this hackerspace", "nl": "Er is {device-name} beschikbaar in deze hackerspace", diff --git a/assets/layers/hackerspace/lasercutter.svg b/assets/layers/hackerspace/lasercutter.svg new file mode 100644 index 000000000..bbe51d2e0 --- /dev/null +++ b/assets/layers/hackerspace/lasercutter.svg @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + diff --git a/assets/layers/hackerspace/lasercutter.svg.license b/assets/layers/hackerspace/lasercutter.svg.license new file mode 100644 index 000000000..026c8c663 --- /dev/null +++ b/assets/layers/hackerspace/lasercutter.svg.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: Verbund Offener Werkstätten +SPDX-License-Identifier: CC-By-SA \ No newline at end of file diff --git a/assets/layers/hackerspace/license_info.json b/assets/layers/hackerspace/license_info.json new file mode 100644 index 000000000..be50e93df --- /dev/null +++ b/assets/layers/hackerspace/license_info.json @@ -0,0 +1,82 @@ +[ + { + "path": "3d_printer.svg", + "license": "CC-By-SA", + "authors": [ + "Verbund Offener Werkstätten" + ], + "sources": [ + "https://www.offene-werkstaetten.org/de/werkstatt-suche" + ] + }, + { + "path": "bicycle.svg", + "license": "CC-By-SA", + "authors": [ + "Verbund Offener Werkstätten" + ], + "sources": [ + "https://www.offene-werkstaetten.org/de/werkstatt-suche" + ] + }, + { + "path": "cnc.svg", + "license": "CC-By-SA", + "authors": [ + "Verbund Offener Werkstätten" + ], + "sources": [ + "https://www.offene-werkstaetten.org/de/werkstatt-suche" + ] + }, + { + "path": "lasercutter.svg", + "license": "CC-By-SA", + "authors": [ + "Verbund Offener Werkstätten" + ], + "sources": [ + "https://www.offene-werkstaetten.org/de/werkstatt-suche" + ] + }, + { + "path": "media_studio.svg", + "license": "CC-By-SA", + "authors": [ + "Verbund Offener Werkstätten" + ], + "sources": [ + "https://www.offene-werkstaetten.org/de/werkstatt-suche" + ] + }, + { + "path": "metal.svg", + "license": "CC-By-SA", + "authors": [ + "Verbund Offener Werkstätten" + ], + "sources": [ + "https://www.offene-werkstaetten.org/de/werkstatt-suche" + ] + }, + { + "path": "sewing_machine.svg", + "license": "CC-By-SA", + "authors": [ + "Verbund Offener Werkstätten" + ], + "sources": [ + "https://www.offene-werkstaetten.org/de/werkstatt-suche" + ] + }, + { + "path": "woodworking.svg", + "license": "CC-By-SA", + "authors": [ + "Verbund Offener Werkstätten" + ], + "sources": [ + "https://www.offene-werkstaetten.org/de/werkstatt-suche" + ] + } +] \ No newline at end of file diff --git a/assets/layers/hackerspace/media_studio.svg b/assets/layers/hackerspace/media_studio.svg new file mode 100644 index 000000000..6154225cd --- /dev/null +++ b/assets/layers/hackerspace/media_studio.svg @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/layers/hackerspace/media_studio.svg.license b/assets/layers/hackerspace/media_studio.svg.license new file mode 100644 index 000000000..026c8c663 --- /dev/null +++ b/assets/layers/hackerspace/media_studio.svg.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: Verbund Offener Werkstätten +SPDX-License-Identifier: CC-By-SA \ No newline at end of file diff --git a/assets/layers/hackerspace/metal.svg b/assets/layers/hackerspace/metal.svg new file mode 100644 index 000000000..97352cf2c --- /dev/null +++ b/assets/layers/hackerspace/metal.svg @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/layers/hackerspace/metal.svg.license b/assets/layers/hackerspace/metal.svg.license new file mode 100644 index 000000000..026c8c663 --- /dev/null +++ b/assets/layers/hackerspace/metal.svg.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: Verbund Offener Werkstätten +SPDX-License-Identifier: CC-By-SA \ No newline at end of file diff --git a/assets/layers/hackerspace/sewing_machine.svg b/assets/layers/hackerspace/sewing_machine.svg new file mode 100644 index 000000000..aa085f74a --- /dev/null +++ b/assets/layers/hackerspace/sewing_machine.svg @@ -0,0 +1,43 @@ + + + + + + + + + + diff --git a/assets/layers/hackerspace/sewing_machine.svg.license b/assets/layers/hackerspace/sewing_machine.svg.license new file mode 100644 index 000000000..026c8c663 --- /dev/null +++ b/assets/layers/hackerspace/sewing_machine.svg.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: Verbund Offener Werkstätten +SPDX-License-Identifier: CC-By-SA \ No newline at end of file diff --git a/assets/layers/hackerspace/woodworking.svg b/assets/layers/hackerspace/woodworking.svg new file mode 100644 index 000000000..ce21b257a --- /dev/null +++ b/assets/layers/hackerspace/woodworking.svg @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + diff --git a/assets/layers/hackerspace/woodworking.svg.license b/assets/layers/hackerspace/woodworking.svg.license new file mode 100644 index 000000000..026c8c663 --- /dev/null +++ b/assets/layers/hackerspace/woodworking.svg.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: Verbund Offener Werkstätten +SPDX-License-Identifier: CC-By-SA \ No newline at end of file diff --git a/public/css/index-tailwind-output.css b/public/css/index-tailwind-output.css index 754949453..50cced769 100644 --- a/public/css/index-tailwind-output.css +++ b/public/css/index-tailwind-output.css @@ -2318,14 +2318,6 @@ input[type=text] { width: 100%; } -.debug input, .debug textarea { - border: 6px solid red -} - -.debug label input, .debug label textarea { - border: 1px solid grey; -} - /************************* BIG CATEGORIES ********************************/ /** diff --git a/src/Models/ThemeConfig/Conversion/ExpandRewrite.ts b/src/Models/ThemeConfig/Conversion/ExpandRewrite.ts index 4e7be25c2..7b3f11c17 100644 --- a/src/Models/ThemeConfig/Conversion/ExpandRewrite.ts +++ b/src/Models/ThemeConfig/Conversion/ExpandRewrite.ts @@ -55,12 +55,19 @@ export class ExpandRewrite extends Conversion, 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 diff --git a/src/Models/ThemeConfig/Conversion/PrepareLayer.ts b/src/Models/ThemeConfig/Conversion/PrepareLayer.ts index bff690459..32dbd513e 100644 --- a/src/Models/ThemeConfig/Conversion/PrepareLayer.ts +++ b/src/Models/ThemeConfig/Conversion/PrepareLayer.ts @@ -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 { private static readonly predefinedFilters = ExpandFilter.load_filters() @@ -1133,9 +1134,43 @@ export class AutoTitleIcon extends DesugaringStep { ) } + 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 = `` + return { if: m.if, then: img } + }) + if (!mappings || mappings.length === 0) { + return undefined + } + return { + id: "title_icon_auto_" + tr.id, + mappings, + } + } + convert(json: LayerConfigJson, context: ConversionContext): LayerConfigJson { json = { ...json } json.titleIcons = [...json.titleIcons] + + const allAutoIndex = json.titleIcons.indexOf("auto:*") + if (allAutoIndex >= 0) { + const generated = Utils.NoNull( + json.tagRenderings.map((tr) => { + if (typeof tr === "string") { + return undefined + } + return this.createTitleIconsBasedOn(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 { 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 = `` - 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 { ) continue } - json.titleIcons[i] = { - id: "title_icon_auto_" + trId, - mappings, - } + json.titleIcons[i] = generated } return json } diff --git a/src/Models/ThemeConfig/TagRenderingConfig.ts b/src/Models/ThemeConfig/TagRenderingConfig.ts index fa63ac9b5..99312fb19 100644 --- a/src/Models/ThemeConfig/TagRenderingConfig.ts +++ b/src/Models/ThemeConfig/TagRenderingConfig.ts @@ -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 } diff --git a/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte b/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte index 423733418..aeaf3c0da 100644 --- a/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte +++ b/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte @@ -229,7 +229,7 @@
-
+
diff --git a/src/index.css b/src/index.css index 0ea4b8e13..fe4be9045 100644 --- a/src/index.css +++ b/src/index.css @@ -121,16 +121,6 @@ input[type=text] { width: 100%; } -.debug input, .debug textarea { - border: 6px solid red -} - - -.debug label input, .debug label textarea { - border: 1px solid grey; -} - - /************************* BIG CATEGORIES ********************************/ /**