Message ID | 20230921110456.102369-2-michael.bella-oss@weidmueller.com |
---|---|
State | Accepted |
Delegated to: | Stefano Babic |
Headers | show |
Series | [1/2] web-app: use enum for status messages | expand |
On 21.09.23 13:04, michael.bella-oss@weidmueller.com wrote: > From: Michael Bella <michael.bella@weidmueller.com> > > When new status messages gets added to the backend of swupdate the > web-app will be more rebust against changes, because we will only > update the ui when a status is inside the enum. > > Signed-off-by: Michael Bella <michael.bella@weidmueller.com> > --- > web-app/js/swupdate.js | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/web-app/js/swupdate.js b/web-app/js/swupdate.js > index 39a613c..9ae31de 100755 > --- a/web-app/js/swupdate.js > +++ b/web-app/js/swupdate.js > @@ -16,6 +16,10 @@ const StatusEnum = { > DONE: 'DONE' > }; > > +function isStatusInEnum(status){ > + return (status in StatusEnum) > +} > + > function restart () { > $.post('restart', {}, function (data) { > showRestart() > @@ -41,6 +45,7 @@ function tryReload () { > } > > function updateStatus (status) { > + if(!isStatusInEnum(status)) return; > $('#swu-idle').hide() > $('#swu-success').hide() > $('#swu-failure').hide() > @@ -73,6 +78,7 @@ var updateProgressBarStatus = (function (status) { > var s = '' > > return function (status) { > + if(!isStatusInEnum(status)) return; > $('#swu-progress-bar') > .removeClass('bg-danger bg-success progress-bar-animated') > $('#swu-progress-spinner') Reviewed-by: Stefano Babic <stefano.babic@swupdate.org>
diff --git a/web-app/js/swupdate.js b/web-app/js/swupdate.js index 39a613c..9ae31de 100755 --- a/web-app/js/swupdate.js +++ b/web-app/js/swupdate.js @@ -16,6 +16,10 @@ const StatusEnum = { DONE: 'DONE' }; +function isStatusInEnum(status){ + return (status in StatusEnum) +} + function restart () { $.post('restart', {}, function (data) { showRestart() @@ -41,6 +45,7 @@ function tryReload () { } function updateStatus (status) { + if(!isStatusInEnum(status)) return; $('#swu-idle').hide() $('#swu-success').hide() $('#swu-failure').hide() @@ -73,6 +78,7 @@ var updateProgressBarStatus = (function (status) { var s = '' return function (status) { + if(!isStatusInEnum(status)) return; $('#swu-progress-bar') .removeClass('bg-danger bg-success progress-bar-animated') $('#swu-progress-spinner')