diff mbox series

[3/5] web-app: apply "standard" fixes

Message ID 20240224140031.9888-4-daniel@braunwarth.dev
State Accepted
Delegated to: Stefano Babic
Headers show
Series web-app: update web application | expand

Commit Message

Daniel Braunwarth Feb. 24, 2024, 2 p.m. UTC
Signed-off-by: Daniel Braunwarth <daniel@braunwarth.dev>
---
 web-app/gulpfile.js    | 34 +++++++++++++++++-----------------
 web-app/js/swupdate.js | 36 ++++++++++++++++++++----------------
 2 files changed, 37 insertions(+), 33 deletions(-)
diff mbox series

Patch

diff --git a/web-app/gulpfile.js b/web-app/gulpfile.js
index d8c7380..a698e81 100755
--- a/web-app/gulpfile.js
+++ b/web-app/gulpfile.js
@@ -5,27 +5,27 @@ 
  * SPDX-License-Identifier: MIT
  */
 
-var cleanCSS = require('gulp-clean-css')
-var del = require('del')
-var gulp = require('gulp')
-var gzip = require('gulp-gzip')
-var imagemin = require('gulp-imagemin')
-var filter = require('gulp-filter')
-var htmlmin = require('gulp-htmlmin')
-var minify = require('gulp-minify')
-var rename = require('gulp-rename')
-var replace = require('gulp-replace')
-var sass = require('gulp-sass')(require('sass'))
-var tar = require('gulp-tar')
-var useref = require('gulp-useref')
-var minimist = require('minimist')
+const cleanCSS = require('gulp-clean-css')
+const del = require('del')
+const gulp = require('gulp')
+const gzip = require('gulp-gzip')
+const imagemin = require('gulp-imagemin')
+const filter = require('gulp-filter')
+const htmlmin = require('gulp-htmlmin')
+const minify = require('gulp-minify')
+const rename = require('gulp-rename')
+const replace = require('gulp-replace')
+const sass = require('gulp-sass')(require('sass'))
+const tar = require('gulp-tar')
+const useref = require('gulp-useref')
+const minimist = require('minimist')
 
-var knownOptions = {
+const knownOptions = {
   string: 'output',
   default: { output: 'swupdate-www' }
 }
 
-var options = minimist(process.argv.slice(2), knownOptions)
+const options = minimist(process.argv.slice(2), knownOptions)
 
 gulp.task('sass', async function () {
   return gulp.src('scss/*.scss')
@@ -114,7 +114,7 @@  gulp.task('resize-images', async function () {
 })
 
 gulp.task('package', function () {
-  var name = options.output.replace('.tar', '').replace('.gz', '')
+  const name = options.output.replace('.tar', '').replace('.gz', '')
   return gulp.src('dist/**')
     .pipe(tar(name + '.tar'))
     .pipe(gzip())
diff --git a/web-app/js/swupdate.js b/web-app/js/swupdate.js
index 6661d0a..ae65a1e 100755
--- a/web-app/js/swupdate.js
+++ b/web-app/js/swupdate.js
@@ -14,9 +14,9 @@  const StatusEnum = {
   SUCCESS: 'SUCCESS',
   FAILURE: 'FAILURE',
   DONE: 'DONE'
-};
+}
 
-function isStatusInEnum(status){
+function isStatusInEnum (status) {
   return (status in StatusEnum)
 }
 
@@ -45,7 +45,7 @@  function tryReload () {
 }
 
 function updateStatus (status) {
-  if(!isStatusInEnum(status)) return;
+  if (!isStatusInEnum(status)) return
   $('#swu-idle').hide()
   $('#swu-success').hide()
   $('#swu-failure').hide()
@@ -74,11 +74,11 @@  function updateStatus (status) {
   }
 }
 
-var updateProgressBarStatus = (function (status) {
-  var s = ''
+const updateProgressBarStatus = (function (status) {
+  let s = ''
 
   return function (status) {
-    if(!isStatusInEnum(status)) return;
+    if (!isStatusInEnum(status)) return
     $('#swu-progress-bar')
       .removeClass('bg-danger bg-success progress-bar-animated')
     $('#swu-progress-spinner')
@@ -127,13 +127,13 @@  Dropzone.options.dropzone = {
 }
 
 window.onload = function () {
-  var protocol
+  let protocol
 
   $('#swu-restart').click(restart)
 
   if (window.location.protocol === 'https:') { protocol = 'wss:' } else { protocol = 'ws:' }
 
-  var ws = new WebSocket(protocol + '//' + window.location.host + window.location.pathname.replace(/\/[^/]*$/, '') + '/ws')
+  const ws = new WebSocket(protocol + '//' + window.location.host + window.location.pathname.replace(/\/[^/]*$/, '') + '/ws')
 
   ws.onopen = function (event) {
     updateStatus(StatusEnum.IDLE)
@@ -144,28 +144,32 @@  window.onload = function () {
   }
 
   ws.onmessage = function (event) {
-    var msg = JSON.parse(event.data)
+    const msg = JSON.parse(event.data)
 
     switch (msg.type) {
-      case 'message':
-        var p = $('<p></p>')
+      case 'message': {
+        const p = $('<p></p>')
         p.text(msg.text)
         p.addClass('mb-1')
         if (msg.level <= 3) { p.addClass('text-danger') }
         $('#messages').append(p)
         break
-      case 'status':
+      }
+      case 'status': {
         updateStatus(msg.status)
         updateProgressBarStatus(msg.status)
         break
-      case 'source':
+      }
+      case 'source': {
         break
-      case 'step':
-        var percent = Math.round((100 * (Number(msg.step) - 1) + Number(msg.percent)) / Number(msg.number))
-        var value = percent + '%' + ' (' + msg.step + ' of ' + msg.number + ')'
+      }
+      case 'step': {
+        const percent = Math.round((100 * (Number(msg.step) - 1) + Number(msg.percent)) / Number(msg.number))
+        const value = percent + '%' + ' (' + msg.step + ' of ' + msg.number + ')'
 
         updateProgressBar(percent, msg.name, value)
         break
+      }
     }
   }
 }