luci-app-dawn: error message when service not running 6679/head
authorDaniel Vijge <danielvijge@gmail.com>
Mon, 6 Nov 2023 21:37:32 +0000 (22:37 +0100)
committerDaniel Vijge <danielvijge@gmail.com>
Tue, 7 Nov 2023 19:12:15 +0000 (20:12 +0100)
Display a nicer error message when the DAWN service is not running

Signed-off-by: Daniel Vijge <danielvijge@gmail.com>
applications/luci-app-dawn/htdocs/luci-static/resources/dawn/dawn-common.js
applications/luci-app-dawn/htdocs/luci-static/resources/view/dawn/hearing_map.js
applications/luci-app-dawn/htdocs/luci-static/resources/view/dawn/network_overview.js

index 79f37a7d63a20110fb541994575e11eb602ae9bd..9dec2c6ec1553b487ce6ae505171e953440178c3 100644 (file)
@@ -7,13 +7,13 @@ let callDawnGetNetwork, callDawnGetHearingMap, callHostHints;
 callDawnGetNetwork = rpc.declare({
        object: 'dawn',
        method: 'get_network',
-       expect: {  }
+       expect: { }
 });
 
 callDawnGetHearingMap = rpc.declare({
        object: 'dawn',
        method: 'get_hearing_map',
-       expect: {  }
+       expect: { }
 });
 
 callHostHints = rpc.declare({
@@ -22,6 +22,12 @@ callHostHints = rpc.declare({
        expect: { }
 });
 
+function isDawnRPCAvailable() {
+    return rpc.list("dawn").then(function(signatures) {
+        return 'dawn' in signatures && 'get_network' in signatures.dawn && 'get_hearing_map' in signatures.dawn;
+    });
+}
+
 function getAvailableText(available) {
        return ( available ? _('Available') : _('Not available') );
 }
@@ -59,16 +65,26 @@ function getFormattedNumber(num, decimals, divider = 1) {
 }
 
 function getHostnameFromMAC(hosthints, mac) {
-       return ( hosthints[mac] && hosthints[mac].name ? hosthints[mac].name + ' (' + mac + ')' : mac);
+       return ( hosthints[mac] && hosthints[mac].name ? hosthints[mac].name + ' (' + mac + ')' : mac );
+}
+
+function getDawnServiceNotRunningErrorMessage() {
+       return E('div', { 'class': 'alert-message fade-in warning' }, [
+               E('h4', _('DAWN service unavailable')),
+               E('p', _('Unable to query the DAWN service via ubus, the service appears to be stopped.')),
+               E('a', { 'href': L.url('admin/system/startup') }, _('Check Startup services'))
+       ]);
 }
 
 return L.Class.extend({
        callDawnGetNetwork: callDawnGetNetwork, 
        callDawnGetHearingMap: callDawnGetHearingMap,
        callHostHints: callHostHints,
+       isDawnRPCAvailable: isDawnRPCAvailable,
        getAvailableText: getAvailableText,
        getYesText: getYesText,
        getChannelFromFrequency: getChannelFromFrequency,
        getFormattedNumber: getFormattedNumber,
-       getHostnameFromMAC: getHostnameFromMAC
+       getHostnameFromMAC: getHostnameFromMAC,
+       getDawnServiceNotRunningErrorMessage: getDawnServiceNotRunningErrorMessage
 });
index a5b59519ce7a5050ce71dc1064f7b824e7d66e97..8b93fbfd6d09e54c4d507c1070bac5c22fe85df9 100644 (file)
@@ -10,8 +10,12 @@ return view.extend({
 
        load: function() {
                return Promise.all([
-                       dawn.callDawnGetHearingMap(),
-                       dawn.callDawnGetNetwork(),
+                       dawn.isDawnRPCAvailable().then(function(isAvailable) {
+                               return ( isAvailable ? dawn.callDawnGetHearingMap() : null )
+                       }),
+                       dawn.isDawnRPCAvailable().then(function(isAvailable) {
+                               return ( isAvailable ? dawn.callDawnGetNetwork() : null )
+                       }),
                        dawn.callHostHints()
                ]);
        },
@@ -37,6 +41,10 @@ return view.extend({
                        });
                }
 
+               if (!dawnHearingMapData || !dawnNetworkData) {
+                       return dawn.getDawnServiceNotRunningErrorMessage();
+               }
+
                const body = E([
                        E('h2', _('Hearing Map'))
                ]);
index 71133991ab71f4b259c8932cc42311346a910ed9..a605858eca412dfb8d08860d37960a7f9195ea81 100644 (file)
@@ -10,7 +10,9 @@ return view.extend({
 
        load: function() {
                return Promise.all([
-                       dawn.callDawnGetNetwork(),
+                       dawn.isDawnRPCAvailable().then(function(isAvailable) {
+                               return ( isAvailable ? dawn.callDawnGetNetwork() : null );
+                       }),
                        dawn.callHostHints()
                ]);
        },
@@ -20,6 +22,10 @@ return view.extend({
                const dawnNetworkData = data[0];
                const hostHintsData = data[1];
 
+               if (!dawnNetworkData) {
+                       return dawn.getDawnServiceNotRunningErrorMessage();
+               }
+
                const body = E([
                        E('h2', _('Network Overview'))
                ]);