Skip to content

Commit

Permalink
Added some more validations to the upload to make sure update is not …
Browse files Browse the repository at this point in the history
…triggered accidently.
  • Loading branch information
jeremypoulter committed Oct 6, 2019
1 parent e0cff2c commit b6411eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/home.htm
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,15 @@ <h2>WiFi Firmware</h2>
<p><b>Version: </b><span data-bind="text: config.version"></span></p>
<div data-bind="visible: !updateFetching() && !updateComplete()">
<form action="#" method="post" enctype="multipart/form-data" id="upload_form" data-bind="submit: otaUpdate">
<input type="file" name="update">
<button data-bind="click: otaUpdate, text: (updateFetching() ? 'Updating...' : 'Update')">Update</button>
<input type="file" name="update" data-bind="value: updateFilename">
<button data-bind="click: otaUpdate, text: (updateFetching() ? 'Updating...' : 'Update'), disable: ('' == updateFilename())">Update</button>
</form>
</div>
<div data-bind="visible: updateFetching() && !updateComplete()">
<div data-bind="visible: (updateError() !== '')" class="box error">
<h4>Error:</h4>
<span data-bind="text: updateError"></span>
</div>
<div data-bind="visible: updateFetching() && !updateComplete()">
Updating... <br/>
<div id="progressBack">
<div id="progressBar" data-bind="style: { width: updateProgress()+'%' }"></div>
Expand Down
7 changes: 7 additions & 0 deletions src/view_models/OpenEvseWiFiViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,22 @@ function OpenEvseWiFiViewModel(baseHost, basePort, baseProtocol)
self.updateFetching = ko.observable(false);
self.updateComplete = ko.observable(false);
self.updateError = ko.observable("");
self.updateFilename = ko.observable("");
self.updateLoaded = ko.observable(0);
self.updateTotal = ko.observable(1);
self.updateProgress = ko.pureComputed(function () {
return (self.updateLoaded() / self.updateTotal()) * 100;
});

self.otaUpdate = function() {
if("" === self.updateFilename()) {
self.updateError("Filename not set");
return;
}

self.updateFetching(true);
self.updateError("");

var form = $("#upload_form")[0];
var data = new FormData(form);

Expand Down

0 comments on commit b6411eb

Please sign in to comment.