Skip to content

Commit ad6e55c

Browse files
committed
Allow a user to install missing modules from project settings
1 parent 7e27dd7 commit ad6e55c

11 files changed

Lines changed: 538 additions & 414 deletions

File tree

editor/js/main.js

Lines changed: 198 additions & 180 deletions
Large diffs are not rendered by default.

editor/js/nodes.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,9 @@ RED.nodes = (function() {
714714
if (!$.isArray(newNodes)) {
715715
newNodes = [newNodes];
716716
}
717+
var isInitialLoad = false;
717718
if (!initialLoad) {
719+
isInitialLoad = true;
718720
initialLoad = JSON.parse(JSON.stringify(newNodes));
719721
}
720722
var unknownTypes = [];
@@ -735,7 +737,7 @@ RED.nodes = (function() {
735737
}
736738

737739
}
738-
if (unknownTypes.length > 0) {
740+
if (!isInitialLoad && unknownTypes.length > 0) {
739741
var typeList = "<ul><li>"+unknownTypes.join("</li><li>")+"</li></ul>";
740742
var type = "type"+(unknownTypes.length > 1?"s":"");
741743
RED.notify("<strong>"+RED._("clipboard.importUnrecognised",{count:unknownTypes.length})+"</strong>"+typeList,"error",false,10000);
@@ -1214,7 +1216,7 @@ RED.nodes = (function() {
12141216
RED.workspaces.remove(workspaces[id]);
12151217
});
12161218
defaultWorkspace = null;
1217-
1219+
initialLoad = null;
12181220
RED.nodes.dirty(false);
12191221
RED.view.redraw(true);
12201222
RED.palette.refresh();

editor/js/ui/diff.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,6 @@ RED.diff = (function() {
16781678

16791679
function createUnifiedDiffTable(files,commitOptions) {
16801680
var diffPanel = $('<div></div>');
1681-
console.log(files);
16821681
files.forEach(function(file) {
16831682
var hunks = file.hunks;
16841683
var isBinary = file.binary;

editor/js/ui/palette-editor.js

Lines changed: 96 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,21 @@ RED.palette.editor = (function() {
7575
});
7676
})
7777
}
78-
function installNodeModule(id,version,shade,callback) {
78+
function installNodeModule(id,version,callback) {
7979
var requestBody = {
8080
module: id
8181
};
82-
if (callback === undefined) {
83-
callback = shade;
84-
shade = version;
85-
} else {
82+
if (version) {
8683
requestBody.version = version;
8784
}
88-
shade.show();
8985
$.ajax({
9086
url:"nodes",
9187
type: "POST",
9288
data: JSON.stringify(requestBody),
9389
contentType: "application/json; charset=utf-8"
9490
}).done(function(data,textStatus,xhr) {
95-
shade.hide();
9691
callback();
9792
}).fail(function(xhr,textStatus,err) {
98-
shade.hide();
9993
callback(xhr);
10094
});
10195
}
@@ -604,41 +598,15 @@ RED.palette.editor = (function() {
604598
if ($(this).hasClass('disabled')) {
605599
return;
606600
}
607-
$("#palette-module-install-confirm").data('module',entry.name);
608-
$("#palette-module-install-confirm").data('version',loadedIndex[entry.name].version);
609-
$("#palette-module-install-confirm").data('shade',shade);
610-
611-
$("#palette-module-install-confirm-body").html(entry.local?
612-
RED._("palette.editor.confirm.update.body"):
613-
RED._("palette.editor.confirm.cannotUpdate.body")
614-
);
615-
$(".palette-module-install-confirm-button-install").hide();
616-
$(".palette-module-install-confirm-button-remove").hide();
617-
if (entry.local) {
618-
$(".palette-module-install-confirm-button-update").show();
619-
} else {
620-
$(".palette-module-install-confirm-button-update").hide();
621-
}
622-
$("#palette-module-install-confirm")
623-
.dialog('option', 'title',RED._("palette.editor.confirm.update.title"))
624-
.dialog('open');
601+
update(entry,loadedIndex[entry.name].version,container,function(err){});
625602
})
626603

627604

628605
var removeButton = $('<a href="#" class="editor-button editor-button-small"></a>').html(RED._('palette.editor.remove')).appendTo(buttonGroup);
629606
removeButton.attr('id','up_'+Math.floor(Math.random()*1000000000));
630607
removeButton.click(function(evt) {
631608
evt.preventDefault();
632-
633-
$("#palette-module-install-confirm").data('module',entry.name);
634-
$("#palette-module-install-confirm").data('shade',shade);
635-
$("#palette-module-install-confirm-body").html(RED._("palette.editor.confirm.remove.body"));
636-
$(".palette-module-install-confirm-button-install").hide();
637-
$(".palette-module-install-confirm-button-remove").show();
638-
$(".palette-module-install-confirm-button-update").hide();
639-
$("#palette-module-install-confirm")
640-
.dialog('option', 'title', RED._("palette.editor.confirm.remove.title"))
641-
.dialog('open');
609+
remove(entry,container,function(err){});
642610
})
643611
if (!entry.local) {
644612
removeButton.hide();
@@ -836,22 +804,11 @@ RED.palette.editor = (function() {
836804
$('<span class="palette-module-updated"><i class="fa fa-calendar"></i> '+formatUpdatedAt(entry.updated_at)+'</span>').appendTo(metaRow);
837805
var buttonRow = $('<div>',{class:"palette-module-meta"}).appendTo(headerRow);
838806
var buttonGroup = $('<div>',{class:"palette-module-button-group"}).appendTo(buttonRow);
839-
var shade = $('<div class="palette-module-shade hide"><img src="red/images/spin.svg" class="palette-spinner"/></div>').appendTo(container);
840807
var installButton = $('<a href="#" class="editor-button editor-button-small"></a>').html(RED._('palette.editor.install')).appendTo(buttonGroup);
841808
installButton.click(function(e) {
842809
e.preventDefault();
843810
if (!$(this).hasClass('disabled')) {
844-
$("#palette-module-install-confirm").data('module',entry.id);
845-
$("#palette-module-install-confirm").data('version',entry.version);
846-
$("#palette-module-install-confirm").data('url',entry.url);
847-
$("#palette-module-install-confirm").data('shade',shade);
848-
$("#palette-module-install-confirm-body").html(RED._("palette.editor.confirm.install.body"));
849-
$(".palette-module-install-confirm-button-install").show();
850-
$(".palette-module-install-confirm-button-remove").hide();
851-
$(".palette-module-install-confirm-button-update").hide();
852-
$("#palette-module-install-confirm")
853-
.dialog('option', 'title', RED._("palette.editor.confirm.install.title"))
854-
.dialog('open');
811+
install(entry,container,function(xhr) {});
855812
}
856813
})
857814
if (nodeEntries.hasOwnProperty(entry.id)) {
@@ -869,88 +826,126 @@ RED.palette.editor = (function() {
869826
});
870827

871828
$('<div id="palette-module-install-shade" class="palette-module-shade hide"><div class="palette-module-shade-status"></div><img src="red/images/spin.svg" class="palette-spinner"/></div>').appendTo(installTab);
872-
873-
$('<div id="palette-module-install-confirm" class="hide"><form class="form-horizontal"><div id="palette-module-install-confirm-body" class="node-dialog-confirm-row"></div></form></div>').appendTo(document.body);
874-
$("#palette-module-install-confirm").dialog({
875-
title: RED._('palette.editor.confirm.title'),
829+
}
830+
function update(entry,version,container,done) {
831+
if (RED.settings.theme('palette.editable') === false) {
832+
done(new Error('Palette not editable'));
833+
return;
834+
}
835+
var notification = RED.notify(RED._("palette.editor.confirm.update.body",{module:entry.name}),{
876836
modal: true,
877-
autoOpen: false,
878-
width: 550,
879-
height: "auto",
837+
fixed: true,
880838
buttons: [
881839
{
882840
text: RED._("common.label.cancel"),
883841
click: function() {
884-
$( this ).dialog( "close" );
842+
notification.close();
885843
}
886844
},
887845
{
888-
text: RED._("palette.editor.confirm.button.review"),
889-
class: "primary palette-module-install-confirm-button-install",
846+
text: RED._("palette.editor.confirm.button.update"),
847+
class: "primary palette-module-install-confirm-button-update",
890848
click: function() {
891-
var url = $(this).data('url');
892-
window.open(url);
849+
var spinner = RED.utils.addSpinnerOverlay(container, true);
850+
installNodeModule(entry.name,version,function(xhr) {
851+
spinner.remove();
852+
if (xhr) {
853+
if (xhr.responseJSON) {
854+
RED.notify(RED._('palette.editor.errors.updateFailed',{module: entry.name,message:xhr.responseJSON.message}));
855+
}
856+
}
857+
done(xhr);
858+
});
859+
notification.close();
893860
}
894-
},
861+
}
862+
]
863+
})
864+
}
865+
function remove(entry,container,done) {
866+
if (RED.settings.theme('palette.editable') === false) {
867+
done(new Error('Palette not editable'));
868+
return;
869+
}
870+
var notification = RED.notify(RED._("palette.editor.confirm.remove.body",{module:entry.name}),{
871+
modal: true,
872+
fixed: true,
873+
buttons: [
895874
{
896-
text: RED._("palette.editor.confirm.button.install"),
897-
class: "primary palette-module-install-confirm-button-install",
875+
text: RED._("common.label.cancel"),
898876
click: function() {
899-
var id = $(this).data('module');
900-
var version = $(this).data('version');
901-
var shade = $(this).data('shade');
902-
installNodeModule(id,version,shade,function(xhr) {
903-
if (xhr) {
904-
if (xhr.responseJSON) {
905-
RED.notify(RED._('palette.editor.errors.installFailed',{module: id,message:xhr.responseJSON.message}));
906-
}
907-
}
908-
});
909-
$( this ).dialog( "close" );
877+
notification.close();
910878
}
911879
},
912880
{
913881
text: RED._("palette.editor.confirm.button.remove"),
914882
class: "primary palette-module-install-confirm-button-remove",
915883
click: function() {
916-
var id = $(this).data('module');
917-
var shade = $(this).data('shade');
918-
shade.show();
919-
removeNodeModule(id, function(xhr) {
920-
shade.hide();
884+
var spinner = RED.utils.addSpinnerOverlay(container, true);
885+
removeNodeModule(entry.name, function(xhr) {
886+
spinner.remove();
921887
if (xhr) {
922888
if (xhr.responseJSON) {
923-
RED.notify(RED._('palette.editor.errors.removeFailed',{module: id,message:xhr.responseJSON.message}));
889+
RED.notify(RED._('palette.editor.errors.removeFailed',{module: entry.name,message:xhr.responseJSON.message}));
924890
}
925891
}
926892
})
927-
928-
$( this ).dialog( "close" );
929-
}
930-
},
931-
{
932-
text: RED._("palette.editor.confirm.button.update"),
933-
class: "primary palette-module-install-confirm-button-update",
934-
click: function() {
935-
var id = $(this).data('module');
936-
var version = $(this).data('version');
937-
var shade = $(this).data('shade');
938-
shade.show();
939-
installNodeModule(id,version,shade,function(xhr) {
940-
if (xhr) {
941-
if (xhr.responseJSON) {
942-
RED.notify(RED._('palette.editor.errors.updateFailed',{module: id,message:xhr.responseJSON.message}));
943-
}
944-
}
945-
});
946-
$( this ).dialog( "close" );
893+
notification.close();
947894
}
948895
}
949896
]
950897
})
951898
}
899+
function install(entry,container,done) {
900+
if (RED.settings.theme('palette.editable') === false) {
901+
done(new Error('Palette not editable'));
902+
return;
903+
}
904+
var buttons = [
905+
{
906+
text: RED._("common.label.cancel"),
907+
click: function() {
908+
notification.close();
909+
}
910+
}
911+
];
912+
if (entry.url) {
913+
buttons.push({
914+
text: RED._("palette.editor.confirm.button.review"),
915+
class: "primary palette-module-install-confirm-button-install",
916+
click: function() {
917+
var url = entry.url||"";
918+
window.open(url);
919+
}
920+
});
921+
}
922+
buttons.push({
923+
text: RED._("palette.editor.confirm.button.install"),
924+
class: "primary palette-module-install-confirm-button-install",
925+
click: function() {
926+
var spinner = RED.utils.addSpinnerOverlay(container, true);
927+
installNodeModule(entry.id,entry.version,function(xhr) {
928+
spinner.remove();
929+
if (xhr) {
930+
if (xhr.responseJSON) {
931+
RED.notify(RED._('palette.editor.errors.installFailed',{module: entry.id,message:xhr.responseJSON.message}));
932+
}
933+
}
934+
done(xhr);
935+
});
936+
notification.close();
937+
}
938+
});
939+
940+
var notification = RED.notify(RED._("palette.editor.confirm.install.body",{module:entry.id}),{
941+
modal: true,
942+
fixed: true,
943+
buttons: buttons
944+
})
945+
}
952946

953947
return {
954-
init: init
948+
init: init,
949+
install: install
955950
}
956951
})();

0 commit comments

Comments
 (0)