1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add 'type already registered' check in palette editor

This commit is contained in:
Nick O'Leary 2018-11-13 22:36:56 +00:00
parent 7515b745b5
commit e4f67df2a1
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 66 additions and 25 deletions

View File

@ -424,6 +424,8 @@
"updated": "updated", "updated": "updated",
"install": "install", "install": "install",
"installed": "installed", "installed": "installed",
"conflict": "conflict",
"conflictTip": "<p>The module cannot be installed as it includes a<br/>node type that has already been installed</p><p>Conflicts with <code>__module__</code></p>",
"loading": "Loading catalogues...", "loading": "Loading catalogues...",
"tab-nodes": "Nodes", "tab-nodes": "Nodes",
"tab-install": "Install", "tab-install": "Install",

View File

@ -321,7 +321,7 @@ RED.palette.editor = (function() {
var catalogueLoadStart; var catalogueLoadStart;
var catalogueLoadErrors = false; var catalogueLoadErrors = false;
var activeSort = sortModulesAZ; var activeSort = sortModulesRelevance;
function handleCatalogResponse(err,catalog,index,v) { function handleCatalogResponse(err,catalog,index,v) {
catalogueLoadStatus.push(err||v); catalogueLoadStatus.push(err||v);
@ -333,6 +333,9 @@ RED.palette.editor = (function() {
if (m.keywords) { if (m.keywords) {
m.index = m.index.concat(m.keywords); m.index = m.index.concat(m.keywords);
} }
if (m.types) {
m.index = m.index.concat(m.types);
}
if (m.updated_at) { if (m.updated_at) {
m.timestamp = new Date(m.updated_at).getTime(); m.timestamp = new Date(m.updated_at).getTime();
} else { } else {
@ -413,6 +416,17 @@ RED.palette.editor = (function() {
packageList.editableList('addItem',{start:10,more:filteredList.length-10}) packageList.editableList('addItem',{start:10,more:filteredList.length-10})
} }
} }
function sortModulesRelevance(A,B) {
var currentFilter = searchInput.searchBox('value').trim();
if (currentFilter === "") {
return sortModulesAZ(A,B);
}
var i = A.info.index.indexOf(currentFilter) - B.info.index.indexOf(currentFilter);
if (i === 0) {
return sortModulesAZ(A,B);
}
return i;
}
function sortModulesAZ(A,B) { function sortModulesAZ(A,B) {
return A.info.id.localeCompare(B.info.id); return A.info.id.localeCompare(B.info.id);
} }
@ -747,32 +761,29 @@ RED.palette.editor = (function() {
$('<span>').text(RED._("palette.editor.sort")+' ').appendTo(toolBar); $('<span>').text(RED._("palette.editor.sort")+' ').appendTo(toolBar);
var sortGroup = $('<span class="button-group"></span>').appendTo(toolBar); var sortGroup = $('<span class="button-group"></span>').appendTo(toolBar);
var sortAZ = $('<a href="#" class="sidebar-header-button-toggle selected" data-i18n="palette.editor.sortAZ"></a>').appendTo(sortGroup); var sortRelevance = $('<a href="#" class="palette-editor-install-sort-option sidebar-header-button-toggle selected"><i class="fa fa-sort-amount-desc"></i></a>').appendTo(sortGroup);
var sortRecent = $('<a href="#" class="sidebar-header-button-toggle" data-i18n="palette.editor.sortRecent"></a>').appendTo(sortGroup); var sortAZ = $('<a href="#" class="palette-editor-install-sort-option sidebar-header-button-toggle" data-i18n="palette.editor.sortAZ"></a>').appendTo(sortGroup);
var sortRecent = $('<a href="#" class="palette-editor-install-sort-option sidebar-header-button-toggle" data-i18n="palette.editor.sortRecent"></a>').appendTo(sortGroup);
sortAZ.click(function(e) {
e.preventDefault(); var sortOpts = [
if ($(this).hasClass("selected")) { {button: sortRelevance, func: sortModulesRelevance},
return; {button: sortAZ, func: sortModulesAZ},
} {button: sortRecent, func: sortModulesRecent}
$(this).addClass("selected"); ]
sortRecent.removeClass("selected"); sortOpts.forEach(function(opt) {
activeSort = sortModulesAZ; opt.button.click(function(e) {
refreshFilteredItems(); e.preventDefault();
if ($(this).hasClass("selected")) {
return;
}
$(".palette-editor-install-sort-option").removeClass("selected");
$(this).addClass("selected");
activeSort = opt.func;
refreshFilteredItems();
});
}); });
sortRecent.click(function(e) {
e.preventDefault();
if ($(this).hasClass("selected")) {
return;
}
$(this).addClass("selected");
sortAZ.removeClass("selected");
activeSort = sortModulesRecent;
refreshFilteredItems();
});
var refreshSpan = $('<span>').appendTo(toolBar); var refreshSpan = $('<span>').appendTo(toolBar);
var refreshButton = $('<a href="#" class="sidebar-header-button"><i class="fa fa-refresh"></i></a>').appendTo(refreshSpan); var refreshButton = $('<a href="#" class="sidebar-header-button"><i class="fa fa-refresh"></i></a>').appendTo(refreshSpan);
refreshButton.click(function(e) { refreshButton.click(function(e) {
@ -814,10 +825,23 @@ RED.palette.editor = (function() {
$('<a target="_blank" class="palette-module-link"><i class="fa fa-external-link"></i></a>').attr('href',entry.url).appendTo(titleRow); $('<a target="_blank" class="palette-module-link"><i class="fa fa-external-link"></i></a>').attr('href',entry.url).appendTo(titleRow);
var descRow = $('<div class="palette-module-meta"></div>').appendTo(headerRow); var descRow = $('<div class="palette-module-meta"></div>').appendTo(headerRow);
$('<div>',{class:"palette-module-description"}).text(entry.description).appendTo(descRow); $('<div>',{class:"palette-module-description"}).text(entry.description).appendTo(descRow);
var metaRow = $('<div class="palette-module-meta"></div>').appendTo(headerRow); var metaRow = $('<div class="palette-module-meta"></div>').appendTo(headerRow);
$('<span class="palette-module-version"><i class="fa fa-tag"></i> '+entry.version+'</span>').appendTo(metaRow); $('<span class="palette-module-version"><i class="fa fa-tag"></i> '+entry.version+'</span>').appendTo(metaRow);
$('<span class="palette-module-updated"><i class="fa fa-calendar"></i> '+formatUpdatedAt(entry.updated_at)+'</span>').appendTo(metaRow); $('<span class="palette-module-updated"><i class="fa fa-calendar"></i> '+formatUpdatedAt(entry.updated_at)+'</span>').appendTo(metaRow);
var duplicateType = false;
if (entry.types && entry.types.length > 0) {
for (var i=0;i<entry.types.length;i++) {
var nodeset = RED.nodes.registry.getNodeSetForType(entry.types[i]);
if (nodeset) {
duplicateType = nodeset.module;
break;
}
}
// $('<div>',{class:"palette-module-meta"}).text(entry.types.join(",")).appendTo(headerRow);
}
var buttonRow = $('<div>',{class:"palette-module-meta"}).appendTo(headerRow); var buttonRow = $('<div>',{class:"palette-module-meta"}).appendTo(headerRow);
var buttonGroup = $('<div>',{class:"palette-module-button-group"}).appendTo(buttonRow); var buttonGroup = $('<div>',{class:"palette-module-button-group"}).appendTo(buttonRow);
var installButton = $('<a href="#" class="editor-button editor-button-small"></a>').text(RED._('palette.editor.install')).appendTo(buttonGroup); var installButton = $('<a href="#" class="editor-button editor-button-small"></a>').text(RED._('palette.editor.install')).appendTo(buttonGroup);
@ -830,6 +854,16 @@ RED.palette.editor = (function() {
if (nodeEntries.hasOwnProperty(entry.id)) { if (nodeEntries.hasOwnProperty(entry.id)) {
installButton.addClass('disabled'); installButton.addClass('disabled');
installButton.text(RED._('palette.editor.installed')); installButton.text(RED._('palette.editor.installed'));
} else if (duplicateType) {
installButton.addClass('disabled');
installButton.text(RED._('palette.editor.conflict'));
RED.popover.create({
target:installButton,
content: RED._('palette.editor.conflictTip',{module:duplicateType}),
trigger:"hover",
direction:"bottom",
delay:{show:750,hide:50}
})
} }
object.elements = { object.elements = {

View File

@ -159,3 +159,8 @@
border-color: #666 !important; border-color: #666 !important;
} }
} }
.red-ui-popover code {
border: none;
background: none;
color: #ccc;
}