From c101bd75fce3d6b3d91fbb66aca3541ab253d579 Mon Sep 17 00:00:00 2001 From: gitolicious Date: Sat, 25 May 2019 23:45:35 +0000 Subject: [PATCH] added download, edit and retry buttons to upload modal --- esphome/dashboard/static/esphome.js | 19 +++++++++++++++++++ esphome/dashboard/templates/index.html | 3 +++ 2 files changed, 22 insertions(+) diff --git a/esphome/dashboard/static/esphome.js b/esphome/dashboard/static/esphome.js index 568537a3c9..39a060feb7 100644 --- a/esphome/dashboard/static/esphome.js +++ b/esphome/dashboard/static/esphome.js @@ -406,16 +406,27 @@ const logsModal = new LogModalElem({ }); logsModal.setup(); +const retryUploadButton = document.querySelector('.retry-upload'); +const editAfterUploadButton = document.querySelector('.edit-after-upload'); +const downloadAfterUploadButton = document.querySelector('.download-after-upload'); const uploadModal = new LogModalElem({ name: 'upload', onPrepare: (modalElem, config) => { + retryUploadButton.setAttribute('data-node', uploadModal.activeConfig); + retryUploadButton.classList.add('hide'); + editAfterUploadButton.setAttribute('data-node', uploadModal.activeConfig); + downloadAfterUploadButton.classList.remove('hide'); + downloadAfterUploadButton.classList.add('disabled'); modalElem.querySelector(".stop-logs").innerHTML = "Stop"; }, onProcessExit: (modalElem, code) => { if (code === 0) { M.toast({html: "Program exited successfully."}); + downloadAfterUploadButton.classList.remove('disabled'); } else { M.toast({html: `Program failed with code ${code}`}); + downloadAfterUploadButton.classList.add('hide'); + retryUploadButton.classList.remove('hide'); } modalElem.querySelector(".stop-logs").innerHTML = "Close"; }, @@ -425,6 +436,14 @@ const uploadModal = new LogModalElem({ dismissible: false, }); uploadModal.setup(); +downloadAfterUploadButton.addEventListener('click', () => { + const link = document.createElement("a"); + link.download = name; + link.href = `./download.bin?configuration=${encodeURIComponent(uploadModal.activeConfig)}`; + document.body.appendChild(link); + link.click(); + link.remove(); +}); const validateModal = new LogModalElem({ name: 'validate', diff --git a/esphome/dashboard/templates/index.html b/esphome/dashboard/templates/index.html index b7df4509cc..a39d56d116 100644 --- a/esphome/dashboard/templates/index.html +++ b/esphome/dashboard/templates/index.html @@ -121,6 +121,9 @@ class="tooltipped" data-position="left" data-tooltip="Flash using esphomeflasher" rel="noreferrer"> help_outline + Download Binary + Edit + Retry Stop