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:
parent
7515b745b5
commit
e4f67df2a1
@ -424,6 +424,8 @@
|
||||
"updated": "updated",
|
||||
"install": "install",
|
||||
"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...",
|
||||
"tab-nodes": "Nodes",
|
||||
"tab-install": "Install",
|
||||
|
@ -321,7 +321,7 @@ RED.palette.editor = (function() {
|
||||
var catalogueLoadStart;
|
||||
var catalogueLoadErrors = false;
|
||||
|
||||
var activeSort = sortModulesAZ;
|
||||
var activeSort = sortModulesRelevance;
|
||||
|
||||
function handleCatalogResponse(err,catalog,index,v) {
|
||||
catalogueLoadStatus.push(err||v);
|
||||
@ -333,6 +333,9 @@ RED.palette.editor = (function() {
|
||||
if (m.keywords) {
|
||||
m.index = m.index.concat(m.keywords);
|
||||
}
|
||||
if (m.types) {
|
||||
m.index = m.index.concat(m.types);
|
||||
}
|
||||
if (m.updated_at) {
|
||||
m.timestamp = new Date(m.updated_at).getTime();
|
||||
} else {
|
||||
@ -413,6 +416,17 @@ RED.palette.editor = (function() {
|
||||
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) {
|
||||
return A.info.id.localeCompare(B.info.id);
|
||||
}
|
||||
@ -747,32 +761,29 @@ RED.palette.editor = (function() {
|
||||
|
||||
$('<span>').text(RED._("palette.editor.sort")+' ').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 sortRecent = $('<a href="#" class="sidebar-header-button-toggle" data-i18n="palette.editor.sortRecent"></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 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) {
|
||||
|
||||
var sortOpts = [
|
||||
{button: sortRelevance, func: sortModulesRelevance},
|
||||
{button: sortAZ, func: sortModulesAZ},
|
||||
{button: sortRecent, func: sortModulesRecent}
|
||||
]
|
||||
sortOpts.forEach(function(opt) {
|
||||
opt.button.click(function(e) {
|
||||
e.preventDefault();
|
||||
if ($(this).hasClass("selected")) {
|
||||
return;
|
||||
}
|
||||
$(".palette-editor-install-sort-option").removeClass("selected");
|
||||
$(this).addClass("selected");
|
||||
sortRecent.removeClass("selected");
|
||||
activeSort = sortModulesAZ;
|
||||
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 refreshButton = $('<a href="#" class="sidebar-header-button"><i class="fa fa-refresh"></i></a>').appendTo(refreshSpan);
|
||||
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);
|
||||
var descRow = $('<div class="palette-module-meta"></div>').appendTo(headerRow);
|
||||
$('<div>',{class:"palette-module-description"}).text(entry.description).appendTo(descRow);
|
||||
|
||||
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-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 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);
|
||||
@ -830,6 +854,16 @@ RED.palette.editor = (function() {
|
||||
if (nodeEntries.hasOwnProperty(entry.id)) {
|
||||
installButton.addClass('disabled');
|
||||
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 = {
|
||||
|
@ -159,3 +159,8 @@
|
||||
border-color: #666 !important;
|
||||
}
|
||||
}
|
||||
.red-ui-popover code {
|
||||
border: none;
|
||||
background: none;
|
||||
color: #ccc;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user