From 8684ff8f066b77d422ac4dc8faf28672329d3b90 Mon Sep 17 00:00:00 2001 From: Joshua Clark Date: Sat, 9 Mar 2024 18:11:41 -0700 Subject: [PATCH] feat: add default picture, add meal description, fix meal name wrap - Add default photo when a photo is not available for a meal plan - Default photo is the Mealie icon - Add `defaultPicture` option to change the image - Add recipe description or meal note, default is hidden - Add `showDescription` to toggle the description - Wrap meal name to single line Closes #2 --- MMM-MealieMenu.css | 12 +++++++++++- MMM-MealieMenu.js | 21 ++++++++++++++++----- MMM-MealieMenu.njk | 11 +++++++++-- README.md | 2 ++ mealie.png | Bin 0 -> 2679 bytes 5 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 mealie.png diff --git a/MMM-MealieMenu.css b/MMM-MealieMenu.css index 89d8cd2..1e5d0ce 100644 --- a/MMM-MealieMenu.css +++ b/MMM-MealieMenu.css @@ -44,7 +44,8 @@ grid: min-content min-content / auto; grid-template-areas: "meal-header" - "meal-name"; + "meal-name" + "meal-description"; gap: 0 0; grid-area: meal-info; text-align: left; @@ -61,6 +62,15 @@ font-size: var(--font-size-small); text-overflow: ellipsis; overflow: hidden; + white-space: nowrap; +} + +.MMM-MealieMenu .meal-description { + grid-area: meal-description; + font-size: var(--font-size-xsmall); + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; } .MMM-MealieMenu .meal-item.today .meal-header { diff --git a/MMM-MealieMenu.js b/MMM-MealieMenu.js index 383c7ab..1b5609d 100644 --- a/MMM-MealieMenu.js +++ b/MMM-MealieMenu.js @@ -22,6 +22,8 @@ Module.register("MMM-MealieMenu", { fadePriorEntries: true, // Fade previous days in the current week. showPictures: true, // Show pictures corresponding to that days meal. roundPictureCorners: false, // Round the meal picture corners. + defaultPicture: "mealie.png", // Default image to display for missing recipe images or meal notes. + showDescription: false, // Show the recipe/meal description. dateFormat: "dddd", // Display format for the date; uses moment.js format string dateMealSeperator: " - ", // Set the separator between the date and meal type. mealSortOrder: ["breakfast", "lunch", "dinner", "side"], // An array determining the order and visibility of the meal type headers. @@ -50,8 +52,6 @@ Module.register("MMM-MealieMenu", { this.dataRefreshTimestamp = null; this.dataRefreshDisplayTime = null; - this.sanitzeConfig(); - // Validate host. if (!this.config.host || !this.isValidURL(this.config.host)) { Log.error(this.translate("ERROR_INVALID", {value: "host"})); @@ -60,9 +60,6 @@ Module.register("MMM-MealieMenu", { return; } - // Strip trailing slashes. - this.config.host = this.config.host.replace(/\/$/u, ""); - // Validate API key or username/password. if (!this.config.apiKey) { Log.info(this.translate("ERROR_INVALID", {value: "apiKey"})); @@ -93,6 +90,8 @@ Module.register("MMM-MealieMenu", { return; } + this.sanitzeConfig(); + this.sendSocketNotification("MEALIE_INIT", { identifier: this.identifier, host: this.config.host, @@ -277,6 +276,7 @@ Module.register("MMM-MealieMenu", { for (const meal of meals) { formatted.push({ name: meal.recipe?.name || meal.title, + description: meal.recipe?.description || meal.text, rawDate: meal.date, date: moment(meal.date).format(this.config.dateFormat), meal: this.typeToMealDisplay(meal.entryType), @@ -352,6 +352,17 @@ Module.register("MMM-MealieMenu", { * Assert values for configuration. */ sanitzeConfig () { + // Strip trailing slashes. + this.config.host = this.config.host.replace(/\/$/u, ""); + + // Check for an external default image. + if ( + !this.config.defaultPicture.startsWith("http") && + !this.config.defaultPicture.includes("/") + ) { + this.config.defaultPicture = this.file(this.config.defaultPicture); + } + if (this.config.priorDayLimit < 0) { this.config.priorDayLimit = 0; Log.warn("priorDayLimit should be 0 or greater. Setting to 0."); diff --git a/MMM-MealieMenu.njk b/MMM-MealieMenu.njk index de89a66..fa36fb9 100644 --- a/MMM-MealieMenu.njk +++ b/MMM-MealieMenu.njk @@ -9,9 +9,11 @@
{% for meal in menu.meals %}
- {% if config.showPictures and meal.photoUrl %} + {% if config.showPictures %}
- +
{% endif %}
@@ -21,6 +23,11 @@
{{ meal.name }}
+ {% if config.showDescription %} +
+ {{ meal.description }} +
+ {% endif %}
{% endfor %} diff --git a/README.md b/README.md index 0a1767b..4efb3fb 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,8 @@ These are the possible options: | `fadePriorEntries` |

Fade previous days in the current week.

**Type:** `boolean`
**Default value:** `true`
**Possible values:** `true` and `false`| | `showPictures` |

Show pictures corresponding to that days meal.

**Type:** `boolean`
**Default value:** `true`
**Possible values:** `true` and `false`| | `roundPictureCorners` |

Round the meal picture corners.

**Type:** `boolean`
**Default value:** `false`
**Possible values:** `true` and `false`| +| `defaultPicture` |

Picture to display for missing recipe images or meal notes.

**Type:** `string`
**Example:** `"https://img.icons8.com/nolan/64/meal.png"`
**Default value:** `"mealie.png"`

**Note:** If the image does not have `http` or `/` in the name, the `MMM-MealieMenu` module path will be prepended to the name.

| +| `showDescription` |

Show the recipe description or meal note.

**Type:** `boolean`
**Default value:** `false`
**Possible values:** `true` and `false`| | `dateFormat` |

Display format for the date; uses [moment.js format string](https://momentjs.com/docs/#/displaying/format/)

**Type:** `string`
**Example:** `"ddd DD"`
**Default value:** `"dddd"`

| | `dateMealSeperator` |

Set the separator between the date and meal type.

**Type:** `string`
**Example:** `" \| "`
**Default value:** `" - "`

**Note:** Above each menu item, the date and meal type are displayed. For example, by default you'll see "Tuesday - Dinner". This setting controls the characters separating `dateFormat` and the meal display.

| | `mealSortOrder` |

An array determining the order of the meal type headers.

**Type:** `array`
**Example:** `[ "lunch", "dinner" ]`
**Default value:** `[ "breakfast", "lunch", "dinner", "side" ]`
**Possible values:** `[ "breakfast", "lunch", "dinner", "side" ]`

**Note 1:** You can remove a meal type here by removing the value.

**Note 2:** The vaules MUST match the possible values above. You can change what is displayed using the `display` options below.

| diff --git a/mealie.png b/mealie.png new file mode 100644 index 0000000000000000000000000000000000000000..338f2db17ce7e4312ebb07ab769733d42aa27920 GIT binary patch literal 2679 zcmV--3W)WIP)_eDm|!Z_fG7cb44v(d-2B;x1379k^GN2knybpj}cPv`f0@K?{M0 zTe-n=vWg8Acn%~658J-fW*FbJR0OFbcT8fW`5bW+mEcjn;{p)}xC|&b? z%Etl%&3hr$Hga={wZ!TM$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