mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Keep version sidebar in sync with project
This commit is contained in:
parent
57533fd831
commit
3745504107
@ -61,15 +61,15 @@
|
||||
RED.nodes.clear();
|
||||
RED.history.clear();
|
||||
RED.view.redraw(true);
|
||||
RED.projects.refresh();
|
||||
RED.projects.refresh(function() {
|
||||
loadFlows(function() {
|
||||
RED.notify("NLS: Project changed to "+msg.project);
|
||||
RED.sidebar.info.refresh()
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (msg.text) {
|
||||
console.log(msg);
|
||||
var text = RED._(msg.text,{default:msg.text});
|
||||
if (notificationId === "runtime-state") {
|
||||
if (msg.error === "credentials_load_failed") {
|
||||
|
@ -584,424 +584,8 @@ RED.projects = (function() {
|
||||
// initSidebar();
|
||||
}
|
||||
|
||||
// function getRepoAuthDetails(req) {
|
||||
// var container = $('<div></div>');
|
||||
//
|
||||
// var row = $('<div class="form-row"></div>').appendTo(container);
|
||||
// $('<label>Username</label>').appendTo(row);
|
||||
// var usernameInput = $('<input type="text"></input>').appendTo(row);
|
||||
//
|
||||
// row = $('<div class="form-row"></div>').appendTo(container);
|
||||
// $('<label>Password</label>').appendTo(row);
|
||||
// var passwordInput = $('<input type="password"></input>').appendTo(row);
|
||||
//
|
||||
// dialogBody.empty();
|
||||
// dialogBody.append(container);
|
||||
// dialog.dialog('option','buttons',[
|
||||
// {
|
||||
// // id: "clipboard-dialog-cancel",
|
||||
// text: RED._("common.label.cancel"),
|
||||
// click: function() {
|
||||
// // $( this ).dialog( "close" );
|
||||
// }
|
||||
// },
|
||||
// {
|
||||
// id: "projects-dialog-create",
|
||||
// text: "Create project", // TODO: nls
|
||||
// class: "primary",
|
||||
// // disabled: true,
|
||||
// click: function() {
|
||||
// var username = usernameInput.val();
|
||||
// var password = passwordInput.val();
|
||||
//
|
||||
// req.remote = parts[1]+username+":"+password+"@"+parts[3];
|
||||
// sendRequest({
|
||||
// url: "projects",
|
||||
// type: "POST",
|
||||
// responses: {
|
||||
// 200: function(data) {
|
||||
// console.log("Success!",data);
|
||||
// },
|
||||
// 400: {
|
||||
// 'project_exists': function(error) {
|
||||
// console.log("already exists");
|
||||
// },
|
||||
// 'git_error': function(error) {
|
||||
// console.log("git error",error);
|
||||
// },
|
||||
// 'git_auth_failed': function(error) {
|
||||
// console.log("git auth error",error);
|
||||
// },
|
||||
// 'unexpected_error': function(error) {
|
||||
// console.log("unexpected_error",error)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// },req)
|
||||
// }
|
||||
// }
|
||||
// ])
|
||||
// }
|
||||
|
||||
/*
|
||||
|
||||
var sidebarContent;
|
||||
var sidebarSections;
|
||||
var sidebarSectionsInfo;
|
||||
var sidebarSectionsDesc;
|
||||
var sidebarSectionsDeps;
|
||||
var sidebarSectionsDepsList;
|
||||
var sidebarSectionsSettings;
|
||||
var modulesInUse = {};
|
||||
|
||||
function initSidebar() {
|
||||
sidebarContent = $('<div>', {class:"sidebar-projects"});
|
||||
var infoStackContainer = $("<div>",{class:"sidebar-projects-stack-info"}).appendTo(sidebarContent);
|
||||
var stackContainer = $("<div>",{class:"sidebar-projects-stack"}).appendTo(sidebarContent);
|
||||
|
||||
RED.actions.add("core:show-projects-tab",showSidebar);
|
||||
|
||||
|
||||
outerSections = RED.stack.create({
|
||||
container: infoStackContainer,
|
||||
fill: true
|
||||
});
|
||||
|
||||
var a = outerSections.add({
|
||||
title: "Project",
|
||||
collapsible: false
|
||||
})
|
||||
|
||||
sidebarSectionsInfo = $("<div>",{class:"node-help"}).appendTo(a.content);
|
||||
|
||||
sidebarSections = RED.stack.create({
|
||||
container: stackContainer,
|
||||
singleExpanded: true,
|
||||
fill: true
|
||||
});
|
||||
|
||||
sidebarSectionsDesc = sidebarSections.add({
|
||||
title: RED._("sidebar.project.description"),
|
||||
expanded: true
|
||||
});
|
||||
sidebarSectionsDesc.content.css({padding:"6px"});
|
||||
|
||||
var editDescription = $('<button style="position: absolute; top: 8px; right: 8px;" class="editor-button editor-button-small">edit</button>').appendTo(sidebarSectionsDesc.header);
|
||||
var editDescriptionFunc = function() {
|
||||
RED.editor.editMarkdown({
|
||||
title: RED._('sidebar.project.editDescription'),
|
||||
value: activeProject.description,
|
||||
complete: function(v) {
|
||||
var spinner = addSpinnerOverlay(sidebarSectionsDesc.content);
|
||||
editDescription.addClass('disabled');
|
||||
var done = function(err,res) {
|
||||
if (err) {
|
||||
editDescriptionFunc();
|
||||
}
|
||||
activeProject.description = v;
|
||||
updateProjectDescription();
|
||||
}
|
||||
sendRequest({
|
||||
url: "projects/"+activeProject.name,
|
||||
type: "PUT",
|
||||
responses: {
|
||||
0: function(error) {
|
||||
done(error,null);
|
||||
},
|
||||
200: function(data) {
|
||||
done(null,data);
|
||||
},
|
||||
400: {
|
||||
'unexpected_error': function(error) {
|
||||
done(error,null);
|
||||
}
|
||||
},
|
||||
}
|
||||
},{description:v}).always(function() {
|
||||
spinner.remove();
|
||||
editDescription.removeClass('disabled');
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
editDescription.click(function(evt) {
|
||||
evt.preventDefault();
|
||||
if ($(this).hasClass('disabled')) {
|
||||
return;
|
||||
}
|
||||
editDescriptionFunc();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
sidebarSectionsDeps = sidebarSections.add({
|
||||
title:RED._("sidebar.project.dependencies")
|
||||
});
|
||||
sidebarSectionsDeps.content.addClass("sidebar-projects-dependencies");
|
||||
|
||||
var editDependencies = $('<button style="position: absolute; top: 8px; right: 8px;" class="editor-button editor-button-small">edit</button>').appendTo(sidebarSectionsDeps.header);
|
||||
var editDependenciesFunc = function(depsJSON) {
|
||||
|
||||
RED.editor.editJSON({
|
||||
title: RED._('sidebar.project.editDependencies'),
|
||||
value: JSON.stringify(depsJSON||activeProject.dependencies||{},"",4),
|
||||
complete: function(v) {
|
||||
try {
|
||||
var parsed = JSON.parse(v);
|
||||
var spinner = addSpinnerOverlay(sidebarSectionsDeps.content);
|
||||
|
||||
editDependencies.addClass('disabled');
|
||||
var done = function(err,res) {
|
||||
if (err) {
|
||||
editDependenciesFunc(depsJSON);
|
||||
}
|
||||
activeProject.dependencies = parsed;
|
||||
updateProjectDependencies();
|
||||
}
|
||||
sendRequest({
|
||||
url: "projects/"+activeProject.name,
|
||||
type: "PUT",
|
||||
responses: {
|
||||
0: function(error) {
|
||||
done(error,null);
|
||||
},
|
||||
200: function(data) {
|
||||
done(null,data);
|
||||
},
|
||||
400: {
|
||||
'unexpected_error': function(error) {
|
||||
done(error,null);
|
||||
}
|
||||
},
|
||||
}
|
||||
},{dependencies:parsed}).always(function() {
|
||||
spinner.remove();
|
||||
editDependencies.removeClass('disabled');
|
||||
});
|
||||
} catch(err) {
|
||||
editDependenciesFunc(depsJSON);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
editDependencies.click(function(evt) {
|
||||
evt.preventDefault();
|
||||
editDependenciesFunc();
|
||||
});
|
||||
|
||||
sidebarSectionsDepsList = $("<ol>",{style:"position: absolute;top: 0;bottom: 0;left: 0;right: 0;"}).appendTo(sidebarSectionsDeps.content);
|
||||
sidebarSectionsDepsList.editableList({
|
||||
addButton: false,
|
||||
addItem: function(row,index,entry) {
|
||||
// console.log(entry);
|
||||
var headerRow = $('<div>',{class:"palette-module-header"}).appendTo(row);
|
||||
if (entry.label) {
|
||||
row.parent().addClass("palette-module-section");
|
||||
headerRow.text(entry.label);
|
||||
if (entry.index === 1) {
|
||||
var addButton = $('<button class="editor-button editor-button-small palette-module-button">add to project</button>').appendTo(headerRow).click(function(evt) {
|
||||
evt.preventDefault();
|
||||
var deps = $.extend(true, {}, activeProject.dependencies);
|
||||
for (var m in modulesInUse) {
|
||||
if (modulesInUse.hasOwnProperty(m) && !modulesInUse[m].known) {
|
||||
deps[m] = modulesInUse[m].version;
|
||||
}
|
||||
}
|
||||
editDependenciesFunc(deps);
|
||||
});
|
||||
} else if (entry.index === 3) {
|
||||
var removeButton = $('<button class="editor-button editor-button-small palette-module-button">remove from project</button>').appendTo(headerRow).click(function(evt) {
|
||||
evt.preventDefault();
|
||||
var deps = $.extend(true, {}, activeProject.dependencies);
|
||||
for (var m in modulesInUse) {
|
||||
if (modulesInUse.hasOwnProperty(m) && modulesInUse[m].known && modulesInUse[m].count === 0) {
|
||||
delete deps[m];
|
||||
}
|
||||
}
|
||||
editDependenciesFunc(deps);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
headerRow.toggleClass("palette-module-unused",entry.count === 0);
|
||||
entry.element = headerRow;
|
||||
var titleRow = $('<div class="palette-module-meta palette-module-name"></div>').appendTo(headerRow);
|
||||
var icon = $('<i class="fa fa-'+(entry.known?'cube':'warning')+'"></i>').appendTo(titleRow);
|
||||
entry.icon = icon;
|
||||
$('<span>').html(entry.module).appendTo(titleRow);
|
||||
var metaRow = $('<div class="palette-module-meta palette-module-version"><i class="fa fa-tag"></i></div>').appendTo(headerRow);
|
||||
var versionSpan = $('<span>').html(entry.version).appendTo(metaRow);
|
||||
if (!entry.known) {
|
||||
headerRow.addClass("palette-module-unknown");
|
||||
} else if (entry.known && entry.count === 0) {
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
sort: function(A,B) {
|
||||
if (A.index && B.index) {
|
||||
return A.index - B.index;
|
||||
}
|
||||
var Acategory = A.index?A.index:(A.known?(A.count>0?0:4):2);
|
||||
var Bcategory = B.index?B.index:(B.known?(B.count>0?0:4):2);
|
||||
if (Acategory === Bcategory) {
|
||||
return A.module.localeCompare(B.module);
|
||||
} else {
|
||||
return Acategory - Bcategory;
|
||||
}
|
||||
}
|
||||
});
|
||||
sidebarSectionsDeps.container.css("border-bottom","none");
|
||||
|
||||
// sidebarSectionsSettings = sidebarSections.add({
|
||||
// title: RED._("sidebar.project.settings")
|
||||
// });
|
||||
// sidebarSectionsSettings.container.css("border-bottom","none");
|
||||
|
||||
RED.sidebar.addTab({
|
||||
id: "project",
|
||||
label: RED._("sidebar.project.label"),
|
||||
name: RED._("sidebar.project.name"),
|
||||
content: sidebarContent,
|
||||
onchange: function() {
|
||||
setTimeout(function() {
|
||||
sidebarSections.resize();
|
||||
},10);
|
||||
}
|
||||
});
|
||||
|
||||
RED.events.on('nodes:add', function(n) {
|
||||
if (!/^subflow:/.test(n.type)) {
|
||||
var module = RED.nodes.registry.getNodeSetForType(n.type).module;
|
||||
if (module !== 'node-red') {
|
||||
if (!modulesInUse.hasOwnProperty(module)) {
|
||||
modulesInUse[module] = {
|
||||
module: module,
|
||||
version: RED.nodes.registry.getModule(module).version,
|
||||
count: 0,
|
||||
known: false
|
||||
}
|
||||
}
|
||||
modulesInUse[module].count++;
|
||||
if (modulesInUse[module].count === 1 && !modulesInUse[module].known) {
|
||||
sidebarSectionsDepsList.editableList('addItem',modulesInUse[module]);
|
||||
} else {
|
||||
sidebarSectionsDepsList.editableList('sort');
|
||||
if (modulesInUse[module].element) {
|
||||
modulesInUse[module].element.removeClass("palette-module-unused");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
RED.events.on('nodes:remove', function(n) {
|
||||
if (!/^subflow:/.test(n.type)) {
|
||||
var module = RED.nodes.registry.getNodeSetForType(n.type).module;
|
||||
if (module !== 'node-red' && modulesInUse.hasOwnProperty(module)) {
|
||||
modulesInUse[module].count--;
|
||||
if (modulesInUse[module].count === 0) {
|
||||
if (!modulesInUse[module].known) {
|
||||
sidebarSectionsDepsList.editableList('removeItem',modulesInUse[module]);
|
||||
delete modulesInUse[module];
|
||||
} else {
|
||||
// TODO: a known dependency is now unused by the flow
|
||||
sidebarSectionsDepsList.editableList('sort');
|
||||
modulesInUse[module].element.addClass("palette-module-unused");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
function showSidebar() {
|
||||
RED.sidebar.show("project");
|
||||
}
|
||||
function addSpinnerOverlay(container) {
|
||||
var spinner = $('<div class="projects-dialog-spinner projects-dialog-spinner-sidebar"><img src="red/images/spin.svg"/></div>').appendTo(container);
|
||||
return spinner;
|
||||
}
|
||||
function updateProjectSummary() {
|
||||
sidebarSectionsInfo.empty();
|
||||
if (activeProject) {
|
||||
var table = $('<table class="node-info"></table>').appendTo(sidebarSectionsInfo);
|
||||
var tableBody = $('<tbody>').appendTo(table);
|
||||
var propRow;
|
||||
propRow = $('<tr class="node-info-node-row"><td>Project</td><td></td></tr>').appendTo(tableBody);
|
||||
$(propRow.children()[1]).html(' '+(activeProject.name||""))
|
||||
}
|
||||
}
|
||||
function updateProjectDescription() {
|
||||
sidebarSectionsDesc.content.empty();
|
||||
if (activeProject) {
|
||||
var div = $('<div class="node-help"></div>').appendTo(sidebarSectionsDesc.content);
|
||||
var desc = marked(activeProject.description||"");
|
||||
var description = addTargetToExternalLinks($('<div class="node-help"><span class="bidiAware" dir=\"'+RED.text.bidi.resolveBaseTextDir(desc)+'">'+desc+'</span></div>')).appendTo(div);
|
||||
description.find(".bidiAware").contents().filter(function() { return this.nodeType === 3 && this.textContent.trim() !== "" }).wrap( "<span></span>" );
|
||||
}
|
||||
}
|
||||
function updateProjectDependencies() {
|
||||
if (activeProject) {
|
||||
sidebarSectionsDepsList.editableList('empty');
|
||||
sidebarSectionsDepsList.editableList('addItem',{index:1, label:"Unknown Dependencies"});
|
||||
sidebarSectionsDepsList.editableList('addItem',{index:3, label:"Unused dependencies"});
|
||||
var dependencies = activeProject.dependencies||{};
|
||||
var moduleList = Object.keys(dependencies);
|
||||
if (moduleList.length > 0) {
|
||||
moduleList.sort();
|
||||
moduleList.forEach(function(module) {
|
||||
if (modulesInUse.hasOwnProperty(module)) {
|
||||
// TODO: this module is used by not currently 'known'
|
||||
modulesInUse[module].known = true;
|
||||
} else {
|
||||
modulesInUse[module] = {module:module,version:dependencies[module], known: true, count:0};
|
||||
}
|
||||
})
|
||||
}
|
||||
for (var module in modulesInUse) {
|
||||
if (modulesInUse.hasOwnProperty(module)) {
|
||||
var m = modulesInUse[module];
|
||||
if (!dependencies.hasOwnProperty(module) && m.count === 0) {
|
||||
delete modulesInUse[module];
|
||||
} else {
|
||||
sidebarSectionsDepsList.editableList('addItem',modulesInUse[module]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// function getUsedModules() {
|
||||
// var inuseModules = {};
|
||||
// var inuseTypes = {};
|
||||
// var getNodeModule = function(node) {
|
||||
// if (inuseTypes[node.type]) {
|
||||
// return;
|
||||
// }
|
||||
// inuseTypes[node.type] = true;
|
||||
// inuseModules[RED.nodes.registry.getNodeSetForType(node.type).module] = true;
|
||||
// }
|
||||
// RED.nodes.eachNode(getNodeModule);
|
||||
// RED.nodes.eachConfig(getNodeModule);
|
||||
// console.log(Object.keys(inuseModules));
|
||||
// }
|
||||
|
||||
// TODO: DRY - tab-info.js
|
||||
function addTargetToExternalLinks(el) {
|
||||
$(el).find("a").each(function(el) {
|
||||
var href = $(this).attr('href');
|
||||
if (/^https?:/.test(href)) {
|
||||
$(this).attr('target','_blank');
|
||||
}
|
||||
});
|
||||
return el;
|
||||
}
|
||||
*/
|
||||
|
||||
function refresh() {
|
||||
function refresh(done) {
|
||||
$.getJSON("projects",function(data) {
|
||||
if (data.active) {
|
||||
$.getJSON("projects/"+data.active, function(project) {
|
||||
@ -1009,11 +593,14 @@ function refresh() {
|
||||
// updateProjectSummary();
|
||||
// updateProjectDescription();
|
||||
// updateProjectDependencies();
|
||||
RED.sidebar.info.refresh();
|
||||
RED.sidebar.versionControl.refresh(true);
|
||||
if (done) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -306,6 +306,7 @@ RED.sidebar.versionControl = (function() {
|
||||
spinner.remove();
|
||||
cancelCommitButton.click();
|
||||
refreshFiles(data);
|
||||
refreshLocalCommits();
|
||||
},
|
||||
400: {
|
||||
'unexpected_error': function(error) {
|
||||
@ -550,6 +551,7 @@ RED.sidebar.versionControl = (function() {
|
||||
}
|
||||
|
||||
refreshInProgress = true;
|
||||
refreshLocalCommits();
|
||||
|
||||
var activeProject = RED.projects.getActiveProject();
|
||||
if (activeProject) {
|
||||
|
Loading…
Reference in New Issue
Block a user