Skip to content

Commit

Permalink
fix error of gui editor
Browse files Browse the repository at this point in the history
  • Loading branch information
xBourner committed Nov 29, 2024
1 parent b34b8dd commit efd2cbc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 38 deletions.
4 changes: 2 additions & 2 deletions dist/status-card.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "status-card",
"version": "2.3.0",
"version": "2.3.1",
"description": "A card that will show certain entities when active grouped by domain/device class",
"main": "status-card.js",
"author": "xBourner",
Expand Down
78 changes: 43 additions & 35 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ class StatusCardEditor extends LitElement {
}

toggleSetting(type, checked) {
if (['showPerson', 'bulkMode', 'showPersonName', 'showBadgeName'].includes(type)) {
this.config[type] = checked;
this.configChanged(this.config);
}
const updatedConfig = { ...this.config, [type]: checked };
this.configChanged(updatedConfig);
}

showMoreHiddenItems() {
Expand All @@ -91,21 +89,24 @@ class StatusCardEditor extends LitElement {


updateConfig(property, domain, deviceClassName, value) {
this.config[property] = this.config[property] || {};
this.config[property][domain] = this.config[property][domain] || {};
const updatedConfig = { ...this.config };
updatedConfig[property] = { ...this.config[property] };
updatedConfig[property][domain] = { ...this.config[property]?.[domain] };

deviceClassName ?
(this.config[property][domain][deviceClassName] = value) :
(this.config[property][domain] = value);

this.configChanged(this.config);
this.requestUpdate();
}
if (deviceClassName) {
updatedConfig[property][domain][deviceClassName] = value;
} else {
updatedConfig[property][domain] = value;
}

this.configChanged(updatedConfig);
this.requestUpdate();
}


updateSortOrder(domain, deviceClassName, newSortOrder) {
this.updateConfig('newSortOrder', domain, deviceClassName, newSortOrder);
}
updateSortOrder(domain, deviceClassName, newSortOrder) {
this.updateConfig('newSortOrder', domain, deviceClassName, newSortOrder);
}

updateIcons(domain, deviceClassName, icon) {
this.updateConfig('icons', domain, deviceClassName, icon);
Expand All @@ -116,7 +117,10 @@ class StatusCardEditor extends LitElement {
}

updateColors(domain, deviceClassName, color) {
this.updateConfig('colors', domain, deviceClassName, color);
const updatedConfig = { ...this.config };
updatedConfig.colors = { ...this.config.colors };
updatedConfig.colors[domain] = color;
this.configChanged(updatedConfig);
}

updateVisibility(domain, deviceClassName, visible) {
Expand All @@ -125,36 +129,39 @@ class StatusCardEditor extends LitElement {


manageExtraEntity(action, index = null, field = null, value = null) {
this.config.extra_entities = this.config.extra_entities || [];

const updatedConfig = { ...this.config };
updatedConfig.extra_entities = updatedConfig.extra_entities ? updatedConfig.extra_entities.map(entity => ({ ...entity })) : [];

if (action === 'add') {
this.config.extra_entities.push({ entity: '', status: '', icon: '', color: '' });
updatedConfig.extra_entities.push({ entity: '', status: '', icon: '', color: '' });
} else if (action === 'update' && index !== null && field !== null) {
this.config.extra_entities[index][field] = value;
const updatedEntity = { ...updatedConfig.extra_entities[index] };
updatedEntity[field] = value;
updatedConfig.extra_entities[index] = updatedEntity;
} else if (action === 'remove' && index !== null) {
this.config.extra_entities.splice(index, 1);
updatedConfig.extra_entities.splice(index, 1);
}

this.configChanged(this.config);
this.configChanged(updatedConfig);
setTimeout(() => {this.requestUpdate();}, 100);
}


manageHiddenItem(type, item, action) {
const validTypes = ["hidden_entities", "hidden_labels"];
if (!validTypes.includes(type)) {
throw new Error(`Invalid type: ${type}. Expected one of ${validTypes.join(", ")}`);
}
if (!this.config[type]) {
this.config[type] = [];
}

const list = this.config[type];

const updatedConfig = { ...this.config };
updatedConfig[type] = updatedConfig[type] ? [...updatedConfig[type]] : [];

const list = updatedConfig[type];

const cleanedItem = typeof item === "string" ? item.trim() : item;
if (!cleanedItem || (typeof cleanedItem === "string" && cleanedItem === "")) {
return;
return;
}

if (action === "add" && !list.includes(cleanedItem)) {
list.push(cleanedItem);
} else if (action === "remove") {
Expand All @@ -164,10 +171,11 @@ class StatusCardEditor extends LitElement {
}
}

this.config = { ...this.config, [type]: list };
this.configChanged(this.config);
this.configChanged(updatedConfig);
this.requestUpdate();
}



updateAreaFloorSelection(type, value) {
this.config = {
Expand Down

0 comments on commit efd2cbc

Please sign in to comment.