luci-app-statistics: fix process graph tab captions
authorJo-Philipp Wich <[email protected]>
Fri, 22 Oct 2021 22:29:52 +0000 (00:29 +0200)
committerJo-Philipp Wich <[email protected]>
Fri, 22 Oct 2021 22:33:54 +0000 (00:33 +0200)
Plugins that provide both detail and non-detail instances led to a mismatch
between the instance list to render and the plugin instance list, causing
tab captions to be wrongly assigned.

Fixes: #5387
Signed-off-by: Jo-Philipp Wich <[email protected]>
applications/luci-app-statistics/htdocs/luci-static/resources/view/statistics/graphs.js

index 838af8c6613674d8bb9479bdd088db814a351089..a3189143ebbe0dd07ac0325345fab3e7f3cecd47 100644 (file)
@@ -31,15 +31,24 @@ return view.extend({
                        ])
                ]);
 
-               for (var i = 0; i < plugin_instances.length; i++)
-                       if (rrdtool.hasInstanceDetails(host.value, plugin, plugin_instances[i]))
-                               render_instances.push(plugin_instances[i]);
+               for (var i = 0; i < plugin_instances.length; i++) {
+                       if (rrdtool.hasInstanceDetails(host.value, plugin, plugin_instances[i])) {
+                               render_instances.push([
+                                       plugin_instances[i],
+                                       plugin_instances[i] ? '%s: %s'.format(rrdtool.pluginTitle(plugin), plugin_instances[i]) : rrdtool.pluginTitle(plugin)
+                               ]);
+                       }
+               }
 
-               if (render_instances.length == 0 || render_instances.length > 1)
-                       render_instances.unshift('-');
+               if (render_instances.length == 0 || render_instances.length > 1) {
+                       render_instances.unshift([
+                               '-',
+                               '%s: %s'.format(rrdtool.pluginTitle(plugin), _('Overview'))
+                       ]);
+               }
 
                Promise.all(render_instances.map(function(instance) {
-                       if (instance == '-') {
+                       if (instance[0] == '-') {
                                var tasks = [];
 
                                for (var i = 0; i < plugin_instances.length; i++)
@@ -50,14 +59,14 @@ return view.extend({
                                });
                        }
                        else {
-                               return rrdtool.render(plugin, instance, false, host.value, span.value, width, null, cache);
+                               return rrdtool.render(plugin, instance[0], false, host.value, span.value, width, null, cache);
                        }
                })).then(function(blobs) {
                        var multiple = blobs.length > 1;
 
                        dom.content(container, E('div', {}, blobs.map(function(blobs, i) {
-                               var plugin_instance = i ? plugin_instances[i-1] : plugin_instances.join('|'),
-                                   title = '%s: %s'.format(rrdtool.pluginTitle(plugin), i ? plugin_instance : _('Overview'));
+                               var plugin_instance = i ? render_instances[i][0] : plugin_instances.join('|'),
+                                   title = render_instances[i][1];
 
                                return E('div', {
                                        'class': 'center',