Skip to content

Commit

Permalink
Close #363: Software Update page: Show error message below input fiel…
Browse files Browse the repository at this point in the history
…d for binary input files (#364)
  • Loading branch information
TheSomeMan authored Dec 20, 2023
1 parent 9ef12da commit a88d46e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
8 changes: 5 additions & 3 deletions scripts/ruuvi_gw_http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@
g_content_firmware_update_json2 = '''
{
"latest":{
"version":"v1.15.1",
"url":"https://fwupdate.ruuvi.com/v1.15.1",
"version":"v1.15.1q",
"url":"https://fwupdate2.ruuvi.com/v1.15.1q",
"created_at":"2023-12-10T14:54:34Z"
},
"alpha":{
Expand Down Expand Up @@ -842,10 +842,12 @@ def _do_post_fw_update_json(self):
g_software_update_url = new_dict['url']
if g_software_update_url.startswith('http://'):
content = '{"status": 400, "message": "Invalid URL"}'
else:
elif g_software_update_url.startswith('https://fwupdate.ruuvi.com/'):
g_software_update_stage = SOFTWARE_UPDATE_STAGE_1_DOWNLOAD_MAIN_FW
g_software_update_percentage = 0
content = '{"status": 200, "message": "OK"}'
else:
content = '{"status": 404, "message": "File not found"}'
self._write_json_response(content)

def _do_post_fw_update_url_json(self):
Expand Down
10 changes: 10 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,16 @@ <h2>
</div>
</div>
</div>
<div id="page-software_update-updating-status-error2" class="err-message hidden">
<div class="block-centered">
<div>
<span lang="en">Error when starting the firmware update process.</span>
<span lang="fi">Virhe käynnistettäessä laiteohjelmiston päivitysprosessia.</span>
</div>
</div>
<div id="page-software_update-updating-status-error2-desc" class="block-centered">
</div>
</div>
</div>
</div>

Expand Down
43 changes: 35 additions & 8 deletions src/page_software_update.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class PageSoftwareUpdate {
#div_updating_status_error = new GuiDiv($('#page-software_update-updating-status-error'))
#text_updating_status_error_desc = new GuiText($('#page-software_update-updating-status-error-desc'))

#div_updating_status_error2 = new GuiDiv($('#page-software_update-updating-status-error2'))
#text_updating_status_error2_desc = new GuiText($('#page-software_update-updating-status-error2-desc'))

#sect_advanced = new GuiSectAdvanced($('#page-software_update-advanced-button'))

constructor (gwCfg, auth) {
Expand Down Expand Up @@ -258,6 +261,7 @@ class PageSoftwareUpdate {

#on_change_url_fw_update_binary_files () {
this.#div_updating_status_error.hide()
this.#div_updating_status_error2.hide()
this.#set_software_update_status_empty()
if (this.#checkbox_software_update_set_url_manually.isChecked()) {
this.#div_fw_update_server.slideUp()
Expand Down Expand Up @@ -293,6 +297,7 @@ class PageSoftwareUpdate {

async #on_button_url_fw_update_server_check () {
this.#div_updating_status_error.hide()
this.#div_updating_status_error2.hide()
let fw_update_url_val = this.#input_fw_update_server_url.getVal()
if (fw_update_url_val.indexOf('://') === -1) {
fw_update_url_val = 'https://' + fw_update_url_val
Expand Down Expand Up @@ -339,6 +344,7 @@ class PageSoftwareUpdate {

async #on_button_url_fw_update_server_save () {
this.#div_updating_status_error.hide()
this.#div_updating_status_error2.hide()
let fw_update_url_val = this.#input_fw_update_server_url.getVal()
if (fw_update_url_val.indexOf('://') === -1) {
fw_update_url_val = 'https://' + fw_update_url_val
Expand All @@ -357,6 +363,7 @@ class PageSoftwareUpdate {
await Network.waitWhileInProgress()

this.#div_updating_status_error.hide()
this.#div_updating_status_error2.hide()

const timeout = 8 * 1000
const json_data = { 'url': fw_update_url_val }
Expand All @@ -369,13 +376,23 @@ class PageSoftwareUpdate {
if (status === 200) {
this.#button_fw_update_server_save.disable()
} else {
this.#text_updating_status_error_desc.setVal(`Status: ${status}, Message: ${message}`)
this.#div_updating_status_error.show()
if (this.#checkbox_software_update_set_url_manually.isChecked()) {
this.#text_updating_status_error2_desc.setVal(`Status: ${status}, Message: ${message}`)
this.#div_updating_status_error2.show()
} else {
this.#text_updating_status_error_desc.setVal(`Status: ${status}, Message: ${message}`)
this.#div_updating_status_error.show()
}
}
}).catch((err) => {
console.log(log_wrap(`POST /fw_update_url.json: failure: ${err}`))
this.#text_updating_status_error_desc.setVal(`${err}`)
this.#div_updating_status_error.show()
if (this.#checkbox_software_update_set_url_manually.isChecked()) {
this.#text_updating_status_error2_desc.setVal(`${err}`)
this.#div_updating_status_error2.show()
} else {
this.#text_updating_status_error_desc.setVal(`${err}`)
this.#div_updating_status_error.show()
}
}).finally(() => {
gui_loading.bodyClassLoadingRemove()
GwStatus.startCheckingStatus()
Expand Down Expand Up @@ -416,14 +433,24 @@ class PageSoftwareUpdate {
if (status === 200) {
Navigation.change_url_software_update_progress()
} else {
this.#text_updating_status_error_desc.setVal(`Status: ${status}, Message: ${message}`)
this.#div_updating_status_error.show()
if (this.#checkbox_software_update_set_url_manually.isChecked()) {
this.#text_updating_status_error2_desc.setVal(`Status: ${status}, Message: ${message}`)
this.#div_updating_status_error2.show()
} else {
this.#text_updating_status_error_desc.setVal(`Status: ${status}, Message: ${message}`)
this.#div_updating_status_error.show()
}
this.#input_fw_update_binary_files_url.setInvalid()
}
}).catch((err) => {
console.log(log_wrap(`POST /fw_update.json: failure: ${err}`))
this.#text_updating_status_error_desc.setVal(`${err}`)
this.#div_updating_status_error.show()
if (this.#checkbox_software_update_set_url_manually.isChecked()) {
this.#text_updating_status_error2_desc.setVal(`${err}`)
this.#div_updating_status_error2.show()
} else {
this.#text_updating_status_error_desc.setVal(`${err}`)
this.#div_updating_status_error.show()
}
this.#input_fw_update_binary_files_url.setInvalid()
}).finally(() => {
gui_loading.bodyClassLoadingRemove()
Expand Down

0 comments on commit a88d46e

Please sign in to comment.