Skip to content

Commit

Permalink
Update entity-progress-card.js
Browse files Browse the repository at this point in the history
  • Loading branch information
francois-le-ko4la authored Jan 13, 2025
1 parent 17db382 commit 0abf1ce
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions entity-progress-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
* - Error handling for missing or invalid entities.
* - Configuration options for various card elements, including entity picker, color settings, and layout options.
*
* @version 1.0.19
* @version 1.0.20
*/

/** --------------------------------------------------------------------------
* PARAMETERS
*/

const VERSION='1.0.19';
const VERSION='1.0.20';
const CARD = {
typeName: 'entity-progress-card',
name: 'Entity progress card',
Expand All @@ -58,8 +58,8 @@ const CARD = {
color: 'var(--state-icon-color)',
showMoreInfo: true,
decimal: {
percentage: 2,
other: 0
percentage: 0,
other: 2
}
}
};
Expand Down Expand Up @@ -495,9 +495,10 @@ class EntityProgressCard extends HTMLElement {
this._max_value = null;
this._decimal = null;
this._show_more_info = null;
this._navigate_to = null;
this._elements = {};
this._isBuilt = false;
this.addEventListener('click', this._showMoreInfo.bind(this));
this.addEventListener('click', this._navigateToOrShowMoreInfo.bind(this));
}

/**
Expand All @@ -510,8 +511,19 @@ class EntityProgressCard extends HTMLElement {
* - `this._show_more_info` must be true.
* - `this.config.entity` must be defined and contain a valid entity ID.
*/
_showMoreInfo() {
if (this._show_more_info && this.config && this.config.entity) {
_navigateToOrShowMoreInfo() {
if (this._navigate_to) {
window.history.pushState(null, '', this._navigate_to);
this.dispatchEvent(new CustomEvent('location-changed', { bubbles: true, composed: true }));

const anchor = this._navigate_to.split('#')[1];
if (anchor) {
const element = document.querySelector(`#${anchor}`);
if (element) {
element.scrollIntoView({ behavior: 'smooth' });
}
}
} else if (this._show_more_info && this.config && this.config.entity) {
this.dispatchEvent(new CustomEvent('hass-more-info', {
bubbles: true,
composed: true,
Expand Down Expand Up @@ -551,6 +563,7 @@ class EntityProgressCard extends HTMLElement {
this._max_value = this.config.max_value || null;
this._unit = this.config.unit || CARD.config.unit;
this._show_more_info = this.config.show_more_info ?? CARD.config.showMoreInfo;
this._navigate_to = this.config.navigate_to || null;

if (!this._isBuilt) {
this._isBuilt = true;
Expand Down

0 comments on commit 0abf1ce

Please sign in to comment.