Skip to content

Commit 57479ed

Browse files
committed
Merge branch 'palette-ui' into 0.15.0
2 parents 4b462ea + eb17562 commit 57479ed

29 files changed

Lines changed: 1474 additions & 154 deletions

Gruntfile.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,26 +110,28 @@ module.exports = function(grunt) {
110110
"editor/js/nodes.js",
111111
"editor/js/history.js",
112112
"editor/js/validators.js",
113+
"editor/js/ui/common/editableList.js",
114+
"editor/js/ui/common/menu.js",
115+
"editor/js/ui/common/popover.js",
116+
"editor/js/ui/common/searchBox.js",
117+
"editor/js/ui/common/tabs.js",
118+
"editor/js/ui/common/typedInput.js",
113119
"editor/js/ui/deploy.js",
114-
"editor/js/ui/menu.js",
115120
"editor/js/ui/keyboard.js",
116-
"editor/js/ui/tabs.js",
117-
"editor/js/ui/popover.js",
118121
"editor/js/ui/workspaces.js",
119122
"editor/js/ui/view.js",
120123
"editor/js/ui/sidebar.js",
121124
"editor/js/ui/palette.js",
122125
"editor/js/ui/tab-info.js",
123126
"editor/js/ui/tab-config.js",
127+
"editor/js/ui/palette-editor.js",
124128
"editor/js/ui/editor.js",
125129
"editor/js/ui/tray.js",
126130
"editor/js/ui/clipboard.js",
127131
"editor/js/ui/library.js",
128132
"editor/js/ui/notifications.js",
129133
"editor/js/ui/subflow.js",
130-
"editor/js/ui/touch/radialMenu.js",
131-
"editor/js/ui/typedInput.js",
132-
"editor/js/ui/editableList.js"
134+
"editor/js/ui/touch/radialMenu.js"
133135
],
134136
dest: "public/red/red.js"
135137
},

editor/js/main.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,9 @@ var RED = (function() {
5656
success: function(data) {
5757
$("body").append(data);
5858
$("body").i18n();
59-
60-
61-
$(".palette-spinner").hide();
62-
$(".palette-scroll").show();
63-
$("#palette-search").show();
59+
$("#palette > .palette-spinner").hide();
60+
$(".palette-scroll").removeClass("hide");
61+
$("#palette-search").removeClass("hide");
6462
loadFlows();
6563
}
6664
});

editor/js/nodes.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,22 @@ RED.nodes = (function() {
3232
}
3333

3434
var registry = (function() {
35+
var moduleList = {};
3536
var nodeList = [];
3637
var nodeSets = {};
3738
var typeToId = {};
3839
var nodeDefinitions = {};
3940

4041
var exports = {
42+
getModule: function(module) {
43+
return moduleList[module];
44+
},
45+
getNodeSetForType: function(nodeType) {
46+
return exports.getNodeSet(typeToId[nodeType]);
47+
},
48+
getModuleList: function() {
49+
return moduleList;
50+
},
4151
getNodeList: function() {
4252
return nodeList;
4353
},
@@ -55,27 +65,33 @@ RED.nodes = (function() {
5565
typeToId[ns.types[j]] = ns.id;
5666
}
5767
nodeList.push(ns);
68+
69+
moduleList[ns.module] = moduleList[ns.module] || {
70+
name:ns.module,
71+
version:ns.version,
72+
local:ns.local,
73+
sets:{}
74+
};
75+
moduleList[ns.module].sets[ns.name] = ns;
76+
RED.events.emit("registry:node-set-added",ns);
5877
},
5978
removeNodeSet: function(id) {
6079
var ns = nodeSets[id];
6180
for (var j=0;j<ns.types.length;j++) {
62-
if (ns.added) {
63-
// TODO: too tightly coupled into palette UI
64-
RED.palette.remove(ns.types[j]);
65-
var def = nodeDefinitions[ns.types[j]];
66-
if (def.onpaletteremove && typeof def.onpaletteremove === "function") {
67-
def.onpaletteremove.call(def);
68-
}
69-
}
7081
delete typeToId[ns.types[j]];
7182
}
7283
delete nodeSets[id];
7384
for (var i=0;i<nodeList.length;i++) {
74-
if (nodeList[i].id == id) {
85+
if (nodeList[i].id === id) {
7586
nodeList.splice(i,1);
7687
break;
7788
}
7889
}
90+
delete moduleList[ns.module].sets[ns.name];
91+
if (Object.keys(moduleList[ns.module].sets).length === 0) {
92+
delete moduleList[ns.module];
93+
}
94+
RED.events.emit("registry:node-set-removed",ns);
7995
return ns;
8096
},
8197
getNodeSet: function(id) {
@@ -84,32 +100,19 @@ RED.nodes = (function() {
84100
enableNodeSet: function(id) {
85101
var ns = nodeSets[id];
86102
ns.enabled = true;
87-
for (var j=0;j<ns.types.length;j++) {
88-
// TODO: too tightly coupled into palette UI
89-
RED.palette.show(ns.types[j]);
90-
var def = nodeDefinitions[ns.types[j]];
91-
if (def.onpaletteadd && typeof def.onpaletteadd === "function") {
92-
def.onpaletteadd.call(def);
93-
}
94-
}
103+
RED.events.emit("registry:node-set-enabled",ns);
95104
},
96105
disableNodeSet: function(id) {
97106
var ns = nodeSets[id];
98107
ns.enabled = false;
99-
for (var j=0;j<ns.types.length;j++) {
100-
// TODO: too tightly coupled into palette UI
101-
RED.palette.hide(ns.types[j]);
102-
var def = nodeDefinitions[ns.types[j]];
103-
if (def.onpaletteremove && typeof def.onpaletteremove === "function") {
104-
def.onpaletteremove.call(def);
105-
}
106-
}
108+
RED.events.emit("registry:node-set-disabled",ns);
107109
},
108110
registerNodeType: function(nt,def) {
109111
nodeDefinitions[nt] = def;
110112
if (def.category != "subflows") {
111113
def.set = nodeSets[typeToId[nt]];
112114
nodeSets[typeToId[nt]].added = true;
115+
nodeSets[typeToId[nt]].enabled = true;
113116

114117
var ns;
115118
if (def.set.module === "node-red") {
@@ -127,18 +130,15 @@ RED.nodes = (function() {
127130

128131
// TODO: too tightly coupled into palette UI
129132
}
130-
RED.palette.add(nt,def);
131-
if (def.onpaletteadd && typeof def.onpaletteadd === "function") {
132-
def.onpaletteadd.call(def);
133-
}
133+
RED.events.emit("registry:node-type-added",nt);
134134
},
135135
removeNodeType: function(nt) {
136136
if (nt.substring(0,8) != "subflow:") {
137137
// NON-NLS - internal debug message
138138
throw new Error("this api is subflow only. called with:",nt);
139139
}
140140
delete nodeDefinitions[nt];
141-
RED.palette.remove(nt);
141+
RED.events.emit("registry:node-type-removed",nt);
142142
},
143143
getNodeType: function(nt) {
144144
return nodeDefinitions[nt];
Lines changed: 99 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,27 @@
6767
});
6868
}
6969

70+
if (this.element.css("position") === "absolute") {
71+
this.element.css("position","static");
72+
this.topContainer.css("position","absolute");
73+
this.uiContainer.css("position","absolute");
74+
75+
["top","left","bottom","right"].forEach(function(s) {
76+
var v = that.element.css(s);
77+
if (s!=="auto" && s!=="") {
78+
that.topContainer.css(s,v);
79+
that.uiContainer.css(s,"0");
80+
that.element.css(s,'auto');
81+
}
82+
})
83+
}
7084
this.uiContainer.addClass("red-ui-editableList-container");
7185

7286
this.uiHeight = this.element.height();
7387

88+
this.activeFilter = this.options.filter||null;
89+
this.activeSort = this.options.sort||null;
90+
7491
var minHeight = this.element.css("minHeight");
7592
if (minHeight !== '0px') {
7693
this.uiContainer.css("minHeight",minHeight);
@@ -141,6 +158,42 @@
141158
},
142159
_destroy: function() {
143160
},
161+
_refreshFilter: function() {
162+
var that = this;
163+
var count = 0;
164+
if (!this.activeFilter) {
165+
this.element.children().show();
166+
}
167+
var items = this.items();
168+
items.each(function (i,el) {
169+
var data = el.data('data');
170+
try {
171+
if (that.activeFilter(data)) {
172+
el.parent().show();
173+
count++;
174+
} else {
175+
el.parent().hide();
176+
}
177+
} catch(err) {
178+
console.log(err);
179+
el.parent().show();
180+
count++;
181+
}
182+
});
183+
return count;
184+
},
185+
_refreshSort: function() {
186+
if (this.activeSort) {
187+
var items = this.element.children();
188+
var that = this;
189+
items.sort(function(A,B) {
190+
return that.activeSort($(A).find(".red-ui-editableList-item-content").data('data'),$(B).find(".red-ui-editableList-item-content").data('data'));
191+
});
192+
$.each(items,function(idx,li) {
193+
that.element.append(li);
194+
})
195+
}
196+
},
144197
width: function(desiredWidth) {
145198
this.uiWidth = desiredWidth;
146199
this._resize();
@@ -152,7 +205,23 @@
152205
addItem: function(data) {
153206
var that = this;
154207
data = data || {};
155-
var li = $('<li>').appendTo(this.element);
208+
var li = $('<li>');
209+
var added = false;
210+
if (this.activeSort) {
211+
var items = this.items();
212+
var skip = false;
213+
items.each(function(i,el) {
214+
if (added) { return }
215+
var itemData = el.data('data');
216+
if (that.activeSort(data,itemData) < 0) {
217+
li.insertBefore(el.closest("li"));
218+
added = true;
219+
}
220+
});
221+
}
222+
if (!added) {
223+
li.appendTo(this.element);
224+
}
156225
var row = $('<div/>').addClass("red-ui-editableList-item-content").appendTo(li);
157226
row.data('data',data);
158227
if (this.options.sortable === true) {
@@ -177,9 +246,20 @@
177246
var index = that.element.children().length-1;
178247
setTimeout(function() {
179248
that.options.addItem(row,index,data);
180-
setTimeout(function() {
181-
that.uiContainer.scrollTop(that.element.height());
182-
},0);
249+
if (that.activeFilter) {
250+
try {
251+
if (!that.activeFilter(data)) {
252+
li.hide();
253+
}
254+
} catch(err) {
255+
}
256+
}
257+
258+
if (!that.activeSort) {
259+
setTimeout(function() {
260+
that.uiContainer.scrollTop(that.element.height());
261+
},0);
262+
}
183263
},0);
184264
}
185265
},
@@ -197,6 +277,21 @@
197277
},
198278
empty: function() {
199279
this.element.empty();
280+
},
281+
filter: function(filter) {
282+
if (filter !== undefined) {
283+
this.activeFilter = filter;
284+
}
285+
return this._refreshFilter();
286+
},
287+
sort: function(sort) {
288+
if (sort !== undefined) {
289+
this.activeSort = sort;
290+
}
291+
return this._refreshSort();
292+
},
293+
length: function() {
294+
return this.element.children().length;
200295
}
201296
});
202297
})(jQuery);

0 commit comments

Comments
 (0)