From 54fa61c77c0eaf87844d6a514469cb55d3680d9a Mon Sep 17 00:00:00 2001 From: Ezequiel Holzweissig Date: Fri, 16 Apr 2021 20:37:51 -0300 Subject: [PATCH] Classes handler change #259 Manage_Classes it's now handled inside node_helper --- API/api.js | 2 +- CHANGELOG.md | 3 +++ node_helper.js | 24 ++++++++++++++++++------ remote.js | 2 +- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/API/api.js b/API/api.js index 7695e21..082263f 100644 --- a/API/api.js +++ b/API/api.js @@ -189,7 +189,7 @@ module.exports = { var classes = self.getConfig().modules.find(m => m.module === "MMM-Remote-Control").config || {}; const val = decodeURIComponent(req.params.value) if(classes.classes && classes.classes[val]) { - self.executeQuery({ action: "MANAGE_CLASSES", payload: { classes: classes.classes[val]} }, res); + self.executeQuery({ action: "MANAGE_CLASSES", payload: { classes: req.params.value} }, res); } else { res.status(400).json({ success: false, message: `Invalid value ${val} provided in request. Use /api/classes to see actual values` }); } diff --git a/CHANGELOG.md b/CHANGELOG.md index 2687345..9f43fcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [2.3.4] - Unreleased +### Added +- Now you can use MANAGE_CLASSES to use them between modules, instead of just the API + ### Fixed - Classes now detects when you're using identifiers and names in the same action (#259) diff --git a/node_helper.js b/node_helper.js index ebbbc22..b6e0b33 100644 --- a/node_helper.js +++ b/node_helper.js @@ -796,12 +796,24 @@ module.exports = NodeHelper.create(Object.assign({ } } if (query.action === "MANAGE_CLASSES") { - if (!query.payload || !query.payload.classes) return; - for(const act in query.payload.classes) { - if (["SHOW","HIDE","TOGGLE"].includes(act.toUpperCase())) { - this.sendSocketNotification(act.toUpperCase(),{ module: query.payload.classes[act]}); - } - } + if (!query.payload || !query.payload.classes || !this.thisConfig || !this.thisConfig.classes) return; + let classes = []; + switch (typeof query.payload.classes) { + case 'string': classes.push(this.thisConfig.classes[query.payload.classes]); break; + case 'object': query.payload.classes.forEach((t)=>classes.push(this.thisConfig.classes[t])) + } + classes.forEach((cl)=>{ + for(const act in cl) { + if (["SHOW","HIDE","TOGGLE"].includes(act.toUpperCase())) { + if(typeof cl[act] == 'string') this.sendSocketNotification(act.toUpperCase(),{ module: cl[act]}); + else { + cl[act].forEach((t)=>{ + this.sendSocketNotification(act.toUpperCase(),{ module: t}); + }) + } + } + } + }) this.sendResponse(res); return; } diff --git a/remote.js b/remote.js index 4032177..beae2a9 100644 --- a/remote.js +++ b/remote.js @@ -1226,7 +1226,7 @@ var Remote = { },{ content: { payload: { - classes: classes[i] + classes: i } } })