Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
*Fixed slice issue when no `severity` is defined.
  • Loading branch information
Gluwc committed Feb 18, 2020
1 parent 24f3d53 commit 4c4bc5b
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/check-button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class CheckButtonCard extends HTMLElement {
// Set config object.
setConfig(config: config) {

const root = this.shadowRoot;

// Deep copy function.
function deepcopy(value: any): any {
if (!(!!value && typeof value == 'object')) {
Expand All @@ -55,8 +57,6 @@ class CheckButtonCard extends HTMLElement {
return result;
}

const root = this.shadowRoot;

// Avoid card config modifying lovelace config.
config = deepcopy(config);

Expand Down Expand Up @@ -96,21 +96,23 @@ class CheckButtonCard extends HTMLElement {
// Merge default and card config.
config = Object.assign(defaultConfig, config);

// Append seconds to severity array.
let newArray = config.severity.slice();
for (var i = 0; i < newArray.length; i++) {
const value: number = this._convertToSeconds(newArray[i].value);
newArray[i].seconds = value;
}
if (config.severity) {
// Append seconds to severity array.
let newArray = config.severity.slice();
for (var i = 0; i < newArray.length; i++) {
const value: number = this._convertToSeconds(newArray[i].value);
newArray[i].seconds = value;
}

// Sort array by seconds.
newArray.sort(function(a: any,b: any) {
return a.seconds - b.seconds;
});
if (config.due == false) {
newArray = newArray.reverse();
// Sort array by seconds.
newArray.sort(function(a: any,b: any) {
return a.seconds - b.seconds;
});
if (config.due == false) {
newArray = newArray.reverse();
}
config.severity = newArray;
}
config.severity = newArray;

// Set bar width based on title position.
if (config.title_position != 'inside') {
Expand Down

0 comments on commit 4c4bc5b

Please sign in to comment.