Skip to content

Commit

Permalink
Classes for names and identifiers
Browse files Browse the repository at this point in the history
Fixes #259
  • Loading branch information
ezeholz committed Apr 21, 2021
1 parent 99f3523 commit ce07e10
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 25 deletions.
2 changes: 1 addition & 1 deletion API/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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` });
}
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.3.4] - 2021-04-21

### 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)

## [2.3.3] - 2021-04-05

### Changed
Expand Down
28 changes: 12 additions & 16 deletions MMM-Remote-Control.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,18 @@ Module.register("MMM-Remote-Control", {
if (payload.force) { options.force = true; }
let modules = []
if(payload.module !== 'all') {
if (!Array.prototype.find) {
// https://tc39.github.io/ecma262/#sec-array.prototype.find
Object.defineProperty(Array.prototype,"find",{value:function(r){if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),t=e.length>>>0;if("function"!=typeof r)throw new TypeError("predicate must be a function");for(var n=arguments[1],i=0;i<t;){var o=e[i];if(r.call(n,o,i,e))return o;i++}},configurable:!0,writable:!0});
}
let i = MM.getModules().find(m => {
if(m) {
return (payload.module.includes(m.identifier));
}
});
if (!i) {
modules = MM.getModules().filter(m => {
if(m) {
return (payload.module.includes(m.name));
}
});
} else modules.push(i)
let x = payload.module
modules = modules.concat(MM.getModules().filter(m => {
if(m && x.includes(m.identifier)) {
if(typeof x == "object") x = x.filter((t)=>t!=m.identifier)
else x = ''
return true;
}
}),MM.getModules().filter(m => {
if(m) {
return x.includes(m.name);
}
}))
} else {
modules = MM.getModules()
}
Expand Down
24 changes: 18 additions & 6 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Magic-Mirror-Module-Remote-Control",
"version": "2.3.2",
"version": "2.3.4",
"description": "This module for the Magic Mirror allows you to shutdown and configure your mirror through a web browser.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ var Remote = {
},{
content: {
payload: {
classes: classes[i]
classes: i
}
}
})
Expand Down

0 comments on commit ce07e10

Please sign in to comment.