Skip to content

Commit

Permalink
Merge pull request #97 from SirStepheno/master
Browse files Browse the repository at this point in the history
Added colors to the module
  • Loading branch information
timdows authored Jul 16, 2024
2 parents 99c8790 + 61e0683 commit e311e74
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
22 changes: 19 additions & 3 deletions MMM-JsonTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,31 @@ Module.register("MMM-JsonTable", {
const cell = document.createElement("td");

let valueToDisplay = "";
let cellValue = "";

if (value.constructor === Object) {
if ("value" in value) {
cellValue = value.value;
} else {
cellValue = "";
}

if ("color" in value) {
cell.style.color = value.color;
}
} else {
cellValue = value;
}

if (key === "icon") {
cell.classList.add("fa", value);
cell.classList.add("fa", cellValue);
} else if (this.config.tryFormatDate) {
valueToDisplay = this.getFormattedValue(value);
valueToDisplay = this.getFormattedValue(cellValue);
} else if (
this.config.keepColumns.length === 0 ||
this.config.keepColumns.indexOf(key) >= 0
) {
valueToDisplay = value;
valueToDisplay = cellValue;
}

const cellText = document.createTextNode(valueToDisplay);
Expand Down
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,66 @@ Configuration:
}
```

## Example 5 (with font awesome icons, colors and descriptive row)

![Example 5](example5.png)

Raw json response:

```json
{
"trash": [
{
"icon": "fa-trash",
"za-type": "Paper",
"zb-date": "15 July"
},
{
"icon": {
"color": "#FF6E00",
"value": "fa-trash"
},
"za-type": {
"color": "#FF6E00",
"value": "Plastic"
},
"zb-date": {
"color": "#FF6E00",
"value": "25 July"
}
},
{
"icon": {
"color": "red",
"value": "fa-trash"
},
"za-type": {
"value": "GFT"
},
"zb-date": {
"color": "yellow"
}
}
]
}
```

Configuration:

```javascript
{
module: 'MMM-JsonTable',
position: 'top_left',
header: 'Trash calendar',
config: {
url: 'https://xyz/abc/get.json',
arrayName: 'trash',
descriptiveRow: '<tr><td></td><td>Type</td><td>Day</td></tr>',
updateInterval: 60000
}
}
```

## Developer hints

Please use `npm run test` before doing a PR.
Binary file added example5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e311e74

Please sign in to comment.