From 8985632779d1ded0a070d259996157b29a7647f5 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 15 Mar 2023 16:52:45 -0700 Subject: [PATCH] Show all boards if boardid is missing instead of erroring --- cpinstaller.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/cpinstaller.js b/cpinstaller.js index 906275b..326460b 100644 --- a/cpinstaller.js +++ b/cpinstaller.js @@ -110,8 +110,16 @@ export class CPInstallButton extends InstallButton { } async connectedCallback() { - // Required - this.boardIds = this.getAttribute("boardid").split(","); + // Load the Board Definitions before the button is ever clicked + const response = await fetch(BOARD_DEFS); + this.boardDefs = await response.json(); + + let boardIds = this.getAttribute("boardid") + if (!boardIds || boardIds.trim().length === 0) { + this.boardIds = Object.keys(this.boardDefs); + } else { + this.boardIds = boardIds.split(","); + } // If there is only one board id, then select it by default if (this.boardIds.length === 1) { @@ -123,10 +131,6 @@ export class CPInstallButton extends InstallButton { this.releaseVersion = this.getAttribute("version"); } - // Load the Board Definitions before the button is ever clicked - const response = await fetch(BOARD_DEFS); - this.boardDefs = await response.json(); - super.connectedCallback(); } @@ -439,6 +443,18 @@ export class CPInstallButton extends InstallButton { for (let boardId of this.boardIds) { options.push({id: boardId, name: this.getBoardName(boardId)}); } + + options.sort((a, b) => { + let boardA = a.name.trim().toLowerCase(); + let boardB = b.name.trim().toLowerCase(); + if (boardA < boardB) { + return -1; + } + if (boardA > boardB) { + return 1; + } + return 0; + }); return options; }