Skip to content

Commit 2a7fc3c

Browse files
author
Dave Conway-Jones
committed
Merge branch 'Hide-Tabs'
2 parents 866d28d + 2459760 commit 2a7fc3c

File tree

12 files changed

+148
-30
lines changed

12 files changed

+148
-30
lines changed

dist/css/app.min.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,10 @@ md-select-menu md-option:focus:not([disabled]):not([selected]) {
427427
md-list {
428428
padding: unset;
429429
}
430+
md-list-item[disabled] {
431+
color: #808080;
432+
// text-decoration: line-through;
433+
}
430434
md-list-item {
431435
min-height: @nrUnitHeight * 2;
432436
height: @nrUnitHeight * 2;

dist/dashboard.appcache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ weather-icons-lite/fonts/weather-icons-lite.woff2
1919
NETWORK:
2020
*
2121

22-
# hash: d32b62bc0f3d82d84d13550bca84c7402ad2b017381da5561a2a98cd0e45aaff
22+
# hash: 84582e1a4998226b40219d89c869226f8828f92fb9ba5abb104ebd5d6c8f9b28

dist/js/app.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodes/locales/en-US/ui_tab.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@
44
"home" : "Home",
55
"tab" : "Tab",
66
"name" : "Name",
7-
"icon" : "Icon"
7+
"icon" : "Icon",
8+
"state" : "State",
9+
"navmenu" : "Nav. Menu",
10+
"enabled" : "Enabled",
11+
"disabled" : "Disabled",
12+
"visible" : "Visible",
13+
"hidden" : "Hidden"
814
},
9-
"tip" : "The <b>Icon</b> field can be either a <a href=\"https://design.google.com/icons/\" target=\"_blank\">Material Design icon</a> <i>(e.g. 'check', 'close')</i> or a <a href=\"https://fontawesome.com/v4.7.0/icons/\" target=\"_blank\">Font Awesome icon</a> <i>(e.g. 'fa-fire')</i>, or a <a href=\"https://github.com/Paul-Reed/weather-icons-lite/blob/master/css/weather-icons-lite.css\" target=\"_blank\">Weather icon</a> <i>(e.g. 'wi-wu-sunny')</i>.</p>"
15+
"info": {
16+
"disabled": " Tab is inactive in Dashboard.",
17+
"hidden": " Tab is not shown in Navigation Menu."
18+
},
19+
"tip" : "The <b>Icon</b> field can be either a <a href=\"https://design.google.com/icons/\" target=\"_blank\">Material Design icon</a> <i>(e.g. 'check', 'close')</i> or a <a href=\"https://fontawesome.com/v4.7.0/icons/\" target=\"_blank\">Font Awesome icon</a> <i>(e.g. 'fa-fire')</i>, or a <a href=\"https://github.com/Paul-Reed/weather-icons-lite/blob/master/css/weather-icons-lite.css\" target=\"_blank\">Weather icon</a> <i>(e.g. 'wi-wu-sunny')</i>.</p>"
1020
}
1121
}

nodes/ui_base.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
.nr-db-sb-list-header:hover {
4747
color: #333;
4848
}
49+
.nr-db-sb-title-hidden {
50+
text-decoration: line-through;
51+
}
52+
.nr-db-sb-title-disabled {
53+
color: #999;
54+
}
4955
.nr-db-sb-tab-list-header {
5056
background: #f3f3f3;
5157
padding:5px;
@@ -1222,8 +1228,12 @@
12221228
container.addClass("nr-db-sb-tab-list-item");
12231229
$('<i class="nr-db-sb-list-handle nr-db-sb-tab-list-handle fa fa-bars"></i>').appendTo(titleRow);
12241230
var chevron = $('<i class="fa fa-angle-down nr-db-sb-list-chevron">',{style:"width:10px;"}).appendTo(titleRow);
1225-
$('<i class="nr-db-sb-icon nr-db-sb-tab-icon fa fa-file-o"></i>').appendTo(titleRow);
1226-
var title = $('<span class="nr-db-sb-title">').html(item.node.name||"").appendTo(titleRow);
1231+
var tabicon = "fa-object-group";
1232+
//var tabicon = item.node.disabled ? "fa-window-close-o" : item.node.hidden ? "fa-eye-slash" : "fa-object-group";
1233+
$('<i>',{class:"nr-db-sb-icon nr-db-sb-tab-icon fa "+tabicon}).appendTo(titleRow);
1234+
var tabhide = item.node.hidden ? " nr-db-sb-title-hidden" : "";
1235+
var tabable = item.node.disabled ? " nr-db-sb-title-disabled" : "";
1236+
$('<span>',{class:"nr-db-sb-title"+tabhide+tabable}).html(item.node.name||"").appendTo(titleRow);
12271237
break;
12281238
}
12291239
case 'ui_link': {
@@ -1974,6 +1984,12 @@
19741984
if (node.type === "ui_group") {
19751985
refresh();
19761986
}
1987+
else {
1988+
if (node.hidden === true) { listElements[node.id].children(".nr-db-sb-list-header").find(".nr-db-sb-title").addClass('nr-db-sb-title-hidden'); }
1989+
else { listElements[node.id].children(".nr-db-sb-list-header").find(".nr-db-sb-title").removeClass('nr-db-sb-title-hidden'); }
1990+
if (node.disabled === true) { listElements[node.id].children(".nr-db-sb-list-header").find(".nr-db-sb-title").addClass('nr-db-sb-title-disabled'); }
1991+
else { listElements[node.id].children(".nr-db-sb-list-header").find(".nr-db-sb-title").removeClass('nr-db-sb-title-disabled'); }
1992+
}
19771993
}
19781994
else if (node.type === "ui_tab") {
19791995
// Adding a tab

nodes/ui_group.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
<script type="text/javascript">
22
// convert to i18 text
3-
function c_(x) {
3+
function c_ui_group(x) {
44
return RED._("node-red-dashboard/ui_group:ui_group."+x);
55
}
66

77
RED.nodes.registerType('ui_group',{
88
category: 'config',
99
defaults: {
10-
name: {value: c_("label.default")},
10+
name: {value: c_ui_group("label.default")},
1111
tab: {type:"ui_tab", required: true },
1212
order: {value: 0},
1313
disp: {value: true},
1414
width: {value: 6},
15-
collapse: {value: false}
15+
collapse: {value: false},
16+
disabled: {value: false},
17+
hidden: {value: false}
1618
},
1719
sort: function(A,B) {
1820
if (A.tab !== B.tab) {
@@ -34,9 +36,9 @@
3436
label: function() {
3537
var tabNode = RED.nodes.node(this.tab);
3638
if (tabNode) {
37-
return "["+(tabNode.name||c_("label.tab"))+"] " + (this.name || c_("label.group"));
39+
return "["+(tabNode.name||c_ui_group("label.tab"))+"] " + (this.name || c_ui_group("label.group"));
3840
}
39-
return "["+c_("label.unassigned")+"] " + (this.name || c_("label.group"));
41+
return "["+c_ui_group("label.unassigned")+"] " + (this.name || c_ui_group("label.group"));
4042
},
4143
oneditprepare: function() {
4244
$("#node-input-size").elementSizer({

nodes/ui_tab.html

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,67 @@
11
<script type="text/javascript">
22
// convert to i18 text
3-
function c_(x) {
3+
function c_ui_tab(x) {
44
return RED._("node-red-dashboard/ui_tab:ui_tab."+x);
55
}
66

77
RED.nodes.registerType('ui_tab',{
88
category: 'config',
99
defaults: {
10-
name: {value: c_("label.home")},
10+
name: {value: c_ui_tab("label.home")},
1111
icon: {value: 'dashboard'},
12-
order: {value: 0}
12+
order: {value: 0},
13+
disabled: {value: false},
14+
hidden: {value: false}
1315
},
1416
paletteLabel: 'dashboard tab',
15-
label: function() { return this.name || c_("label.tab"); },
17+
label: function() { return this.name || c_ui_tab("label.tab"); },
1618
sort: function(A,B) {
1719
return A.order - B.order;
20+
},
21+
oneditprepare: function() {
22+
$("#node-config-input-disabled-btn").on("click", function(e) {
23+
var i = $(this).find("i");
24+
var active = i.hasClass("fa-toggle-on");
25+
var newCls = "fa fa-toggle-" + (active ? "off" : "on");
26+
i.attr("class", newCls);
27+
$("#node-config-input-disabled").prop('checked',active);
28+
29+
var newTxt = c_ui_tab(active ? "label.disabled" : "label.enabled");
30+
$("#node-config-input-disabled-label").text(newTxt);
31+
32+
var info = $("#node-config-input-disabled-info");
33+
var done = active ? info.show() : info.hide();
34+
});
35+
if (this.disabled) {
36+
$("#node-config-input-disabled-btn").click();
37+
}
38+
else {
39+
$("#node-config-input-disabled-label").text(c_ui_tab("label.enabled"));
40+
}
41+
42+
$("#node-config-input-hidden-btn").on("click", function(e) {
43+
var i = $(this).find("i");
44+
var active = i.hasClass("fa-toggle-on");
45+
var newCls = "fa fa-toggle-" + (active ? "off" : "on");
46+
i.attr("class", newCls);
47+
$("#node-config-input-hidden").prop('checked',active);
48+
49+
var newTxt = c_ui_tab(active ? "label.hidden" : "label.visible");
50+
$("#node-config-input-hidden-label").text(newTxt);
51+
52+
var info = $("#node-config-input-hidden-info");
53+
var done = active ? info.show() : info.hide();
54+
});
55+
if (this.hidden) {
56+
$("#node-config-input-hidden-btn").click();
57+
}
58+
else {
59+
$("#node-config-input-hidden-label").text(c_ui_tab("label.visible"));
60+
}
61+
},
62+
oneditsave: function() {
63+
this.disabled = $("#node-config-input-disabled").prop("checked");
64+
this.hidden = $("#node-config-input-hidden").prop("checked");
1865
}
1966
});
2067
</script>
@@ -28,11 +75,29 @@
2875
<label for="node-config-input-icon"><i class="fa fa-file-image-o"></i> <span data-i18n="ui_tab.label.icon"></span></label>
2976
<input type="text" id="node-config-input-icon">
3077
</div>
78+
<div class="form-row">
79+
<label for="node-config-input-disabled-btn"><i class="fa fa-ban"></i> <span data-i18n="ui_tab.label.state"></span></label>
80+
<button id="node-config-input-disabled-btn" class="editor-button" style="width:100px; margin-right:6px;"><i class="fa fa-toggle-on"></i> <span id="node-config-input-disabled-label"></span></button>
81+
<input type="checkbox" id="node-config-input-disabled" style="display:none;"/>
82+
<span id="node-config-input-disabled-info" data-i18n="[html]ui_tab.info.disabled" style="display:none;"></span>
83+
</div>
84+
<div class="form-row">
85+
<label for="node-config-input-hidden-btn"><i class="fa fa-eye-slash"></i> <span data-i18n="ui_tab.label.navmenu"></span></label>
86+
<button id="node-config-input-hidden-btn" class="editor-button" style="width:100px; margin-right:6px;"><i class="fa fa-toggle-on"></i> <span id="node-config-input-hidden-label"></span></button>
87+
<input type="checkbox" id="node-config-input-hidden" style="display:none;"/>
88+
<span id="node-config-input-hidden-info" data-i18n="[html]ui_tab.info.hidden" style="display:none;"></span>
89+
</div>
3190
<div class="form-tips" data-i18n="[html]ui_tab.tip"></div>
3291
</script>
3392

3493
<script type="text/x-red" data-help-name="ui_tab">
3594
<p>Tab configuration for Dashboard</p>
95+
<p><b>Disabled</b> pages are not included in the Dashboard app, and are therefore not functional.
96+
The tab name still appears in the Navigation Menu (unless it is also hidden).
97+
</p>
98+
<p><b>Hidden</b> pages are not listed in the Left-hand Navigation Menu.
99+
However, they are still active in the Dashboard, and can be shown by using a `ui_control` msg.
100+
</p>
36101
<p>The <b>Icon</b> field can be either
37102
<a href="https://design.google.com/icons/" target="_blank">Material Design icons</a> <i>(e.g. 'check', 'close')</i>
38103
or <a href="https://fontawesome.com/v4.7.0/icons/" target="_blank">Font Awesome icons</a> <i>(e.g. 'fa-fire')</i>,

nodes/ui_tab.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ module.exports = function(RED) {
55
this.config = {
66
name: config.name,
77
order: config.order || 0,
8-
icon: config.icon || ''
8+
icon: config.icon || '',
9+
disabled: config.disabled || false,
10+
hidden: config.hidden || false
911
};
1012
}
1113

src/main.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,15 @@ app.controller('MainController', ['$mdSidenav', '$window', 'UiEvents', '$locatio
8282
var len = main.menu.length;
8383
if (len > 1) {
8484
//var i = parseInt($location.path().substr(1));
85-
var i = tabId;
86-
i = (i + d) % len;
87-
if (i < 0) { i += len; }
88-
main.open(main.menu[i], i);
89-
tabId = i;
85+
for (var i = tabId + d; i != tabId; i += d) {
86+
i = i % len;
87+
if (i < 0) { i += len; }
88+
if (!main.menu[i].disabled && !main.menu[i].hidden) {
89+
main.select(i);
90+
tabId = i;
91+
return;
92+
}
93+
}
9094
}
9195
}
9296

@@ -341,18 +345,23 @@ app.controller('MainController', ['$mdSidenav', '$window', 'UiEvents', '$locatio
341345
hideGroups();
342346
done();
343347
}
344-
if (!isNaN(prevTabIndex) && prevTabIndex < main.menu.length) {
348+
if (!isNaN(prevTabIndex) && prevTabIndex < main.menu.length && !main.menu[prevTabIndex].disabled) {
345349
main.selectedTab = main.menu[prevTabIndex];
346350
finishLoading();
347351
}
348352
else {
349353
$timeout( function() {
350-
// open first menu, which is not new tab link
354+
// open first menu, which is not new tab link, and is not disabled
351355
var indexToOpen = null;
352356
main.menu.some(function (menu, i) {
353357
if (menu.target === undefined || menu.target === 'iframe') {
354-
indexToOpen = i;
355-
return true;
358+
if (!menu.disabled) {
359+
indexToOpen = i;
360+
return true;
361+
}
362+
else {
363+
return false;
364+
}
356365
}
357366
})
358367
if (indexToOpen !== null) {
@@ -508,20 +517,23 @@ app.controller('MainController', ['$mdSidenav', '$window', 'UiEvents', '$locatio
508517
for (var i in main.menu) {
509518
// is it the name of a tab ?
510519
if (msg.tab == main.menu[i].header) {
511-
main.select(i);
520+
if (!main.menu[i].disabled) { main.select(i); }
512521
return;
513522
}
514523
// or the name of a link ?
515524
else if (msg.tab == main.menu[i].name) {
516-
main.open(main.menu[i], i);
525+
if (!main.menu[i].disabled) { main.open(main.menu[i], i); }
517526
return;
518527
}
519528
}
520529
}
521530
// or is it a valid index number ?
522531
var index = parseInt(msg.tab);
523532
if (Number.isNaN(index) || index < 0) { return; }
524-
if (index < main.menu.length) { main.open(main.menu[index], index); }
533+
if (index < main.menu.length) {
534+
if (!main.menu[index].disabled) { main.open(main.menu[index], index); }
535+
return;
536+
}
525537
}
526538
if (msg.hasOwnProperty("group")) { // it's to control a group item
527539
if (typeof msg.group === 'object') {

src/partials/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h1 ng-show="!main.lockMenu && main.loaded">{{main.selectedTab.header || main.se
1111
<section layout="row" flex>
1212
<md-sidenav ng-hide="main.len <= 1" class="md-sidenav-left" md-component-id="left" md-is-locked-open="main.lockMenu">
1313
<md-list>
14-
<md-list-item ng-repeat="obj in main.menu" ng-click="main.open(obj, $index)" ng-class="{ 'nr-menu-item-active': obj.id == main.selectedTab.id }">
14+
<md-list-item ng-repeat="obj in main.menu" ng-disabled="obj.disabled" ng-if="!obj.hidden" ng-click="main.open(obj, $index)">
1515
<ui-icon icon="{{obj.icon}}" style="margin:5px"></ui-icon>
1616
<p>{{main.getMenuName(obj)}}</p>
1717
</md-list-item>

0 commit comments

Comments
 (0)