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

Allow committer details to be set per-user

This commit is contained in:
Nick O'Leary 2017-12-04 11:42:44 +00:00
parent 14c48253f6
commit 94eeaeb8d3
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
16 changed files with 639 additions and 366 deletions

View File

@ -68,7 +68,7 @@
console.log(msg); console.log(msg);
var project = RED.projects.getActiveProject(); var project = RED.projects.getActiveProject();
var message = { var message = {
"change-branch":"Change to local branch '"+project.branches.local+"'", "change-branch":"Change to local branch '"+project.git.branches.local+"'",
"abort-merge":"Git merge aborted", "abort-merge":"Git merge aborted",
"loaded":"Project '"+msg.project+"' loaded", "loaded":"Project '"+msg.project+"' loaded",
"updated":"Project '"+msg.project+"' updated", "updated":"Project '"+msg.project+"' updated",

View File

@ -75,7 +75,7 @@
addLabel = 'add'; addLabel = 'add';
} }
} }
$('<a href="#" class="editor-button editor-button-small" style="margin-top: 4px;"><i class="fa fa-plus"></i> '+addLabel+'</a>') $('<a href="#" class="editor-button editor-button-small red-ui-editableList-addButton" style="margin-top: 4px;"><i class="fa fa-plus"></i> '+addLabel+'</a>')
.appendTo(this.topContainer) .appendTo(this.topContainer)
.click(function(evt) { .click(function(evt) {
evt.preventDefault(); evt.preventDefault();

View File

@ -60,6 +60,7 @@ RED.projects.settings = (function() {
}, },
open: function(tray) { open: function(tray) {
var project = RED.projects.getActiveProject(); var project = RED.projects.getActiveProject();
var trayBody = tray.find('.editor-tray-body'); var trayBody = tray.find('.editor-tray-body');
var settingsContent = $('<div></div>').appendTo(trayBody); var settingsContent = $('<div></div>').appendTo(trayBody);
var tabContainer = $('<div></div>',{id:"user-settings-tabs-container"}).appendTo(settingsContent); var tabContainer = $('<div></div>',{id:"user-settings-tabs-container"}).appendTo(settingsContent);
@ -148,7 +149,12 @@ RED.projects.settings = (function() {
} }
function updateProjectDescription(activeProject, container) { function updateProjectDescription(activeProject, container) {
container.empty(); container.empty();
var desc = marked(activeProject.description||""); var desc;
if (activeProject.description) {
desc = marked(activeProject.description);
} else {
desc = '<span class="node-info-none">'+'No description available'+'</span>';
}
var description = addTargetToExternalLinks($('<span class="bidiAware" dir=\"'+RED.text.bidi.resolveBaseTextDir(desc)+'">'+desc+'</span>')).appendTo(container); var description = addTargetToExternalLinks($('<span class="bidiAware" dir=\"'+RED.text.bidi.resolveBaseTextDir(desc)+'">'+desc+'</span>')).appendTo(container);
description.find(".bidiAware").contents().filter(function() { return this.nodeType === 3 && this.textContent.trim() !== "" }).wrap( "<span></span>" ); description.find(".bidiAware").contents().filter(function() { return this.nodeType === 3 && this.textContent.trim() !== "" }).wrap( "<span></span>" );
} }
@ -280,7 +286,7 @@ RED.projects.settings = (function() {
} }
} }
if (unknownCount > 0) { if (unknownCount > 0) {
depsList.editableList('addItem',{index:1, label:"Unknown Dependencies"}); // TODO: nls depsList.editableList('addItem',{index:1, label:"Unlisted dependencies"}); // TODO: nls
} }
if (unusedCount > 0) { if (unusedCount > 0) {
depsList.editableList('addItem',{index:3, label:"Unused dependencies"}); // TODO: nls depsList.editableList('addItem',{index:3, label:"Unused dependencies"}); // TODO: nls
@ -418,15 +424,18 @@ RED.projects.settings = (function() {
} }
function showProjectFileListing(row,activeProject,current,done) { function showProjectFileListing(row,activeProject,current,filter,done) {
var dialog; var dialog;
var dialogBody; var dialogBody;
var filesList; var filesList;
var selected; var selected;
var container = $('<div class="project-file-listing-container"></div>',{style:"position: relative; min-height: 175px; height: 175px;"}).hide().appendTo(row); var container = $('<div class="project-file-listing-container"></div>',{style:"position: relative; min-height: 175px; height: 175px;"}).hide().appendTo(row);
var spinner = utils.addSpinnerOverlay(container); var spinner = utils.addSpinnerOverlay(container);
$.getJSON("/projects/"+activeProject.name+"/files",function(result) { $.getJSON("projects/"+activeProject.name+"/files",function(result) {
var fileNames = Object.keys(result); var fileNames = Object.keys(result);
fileNames = fileNames.filter(function(fn) {
return !result[fn].status || !/D/.test(result[fn].status);
})
var files = {}; var files = {};
fileNames.sort(); fileNames.sort();
fileNames.forEach(function(file) { fileNames.forEach(function(file) {
@ -459,13 +468,13 @@ RED.projects.settings = (function() {
return result; return result;
} }
var files = sortFiles("",files,""); var files = sortFiles("",files,"");
createFileSubList(container,files.children,current,done,"height: 175px"); createFileSubList(container,files.children,current,filter,done,"height: 175px");
spinner.remove(); spinner.remove();
}); });
return container; return container;
} }
function createFileSubList(container, files, current, onselect, style) { function createFileSubList(container, files, current, filter, onselect, style) {
style = style || ""; style = style || "";
var list = $('<ol>',{class:"projects-dialog-file-list", style:style}).appendTo(container).editableList({ var list = $('<ol>',{class:"projects-dialog-file-list", style:style}).appendTo(container).editableList({
addButton: false, addButton: false,
@ -481,7 +490,7 @@ RED.projects.settings = (function() {
} else { } else {
children.hide(); children.hide();
} }
createFileSubList(children,entry.children,current,onselect); createFileSubList(children,entry.children,current,filter,onselect);
header.addClass("selectable"); header.addClass("selectable");
header.click(function(e) { header.click(function(e) {
if ($(this).hasClass("expanded")) { if ($(this).hasClass("expanded")) {
@ -507,6 +516,7 @@ RED.projects.settings = (function() {
header.addClass("projects-dialog-file-list-entry-file-type-git"); header.addClass("projects-dialog-file-list-entry-file-type-git");
} }
$('<span class="projects-dialog-file-list-entry-file"> <i class="fa '+fileIcon+'"></i></span>').appendTo(header); $('<span class="projects-dialog-file-list-entry-file"> <i class="fa '+fileIcon+'"></i></span>').appendTo(header);
if (filter.test(entry.name)) {
header.addClass("selectable"); header.addClass("selectable");
if (entry.path === current) { if (entry.path === current) {
header.addClass("selected"); header.addClass("selected");
@ -520,6 +530,9 @@ RED.projects.settings = (function() {
e.preventDefault(); e.preventDefault();
onselect(entry.path,true); onselect(entry.path,true);
}) })
} else {
header.addClass("unselectable");
}
} }
$('<span class="projects-dialog-file-list-entry-name" style=""></span>').text(entry.name).appendTo(header); $('<span class="projects-dialog-file-list-entry-name" style=""></span>').text(entry.name).appendTo(header);
} }
@ -657,7 +670,7 @@ RED.projects.settings = (function() {
} else { } else {
$(this).addClass('selected'); $(this).addClass('selected');
flowFileLabel.css('color','inherit'); flowFileLabel.css('color','inherit');
var fileList = showProjectFileListing(flowFileLabel,activeProject,flowFileInput.val(),function(result,isDblClick) { var fileList = showProjectFileListing(flowFileLabel,activeProject,flowFileInput.val(), /.*\.json$/,function(result,isDblClick) {
if (result) { if (result) {
flowFileInput.val(result); flowFileInput.val(result);
} }
@ -887,7 +900,6 @@ RED.projects.settings = (function() {
}, },
200: function(data) { 200: function(data) {
activeProject = data; activeProject = data;
console.log("updating form");
updateForm(); updateForm();
done(); done();
}, },
@ -935,191 +947,218 @@ RED.projects.settings = (function() {
updateForm(); updateForm();
} }
function createLocalRepositorySection(activeProject,pane) {
var title = $('<h3></h3>').text("Local Repository").appendTo(pane);
var repoContainer = $('<div class="user-settings-section"></div>').appendTo(pane);
var editRepoButton = $('<button class="editor-button editor-button-small" style="float: right;">edit</button>')
.appendTo(title)
.click(function(evt) {
editRepoButton.hide();
localRepoSearch.show();
formButtons.show();
});
var row = $('<div class="user-settings-row"></div>').appendTo(repoContainer);
$('<label for=""></label>').text('Branch').appendTo(row);
var localRepoLabel = $('<div class="uneditable-input" style="padding:0">').appendTo(row);
var hideLocalRepoBranchList = function() {
localRepoSearch.removeClass('selected');
localRepoLabel.css('height','');
localRepoBranchListRow.slideUp(100);
}
var localRepoText = $('<span style="display:inline-block; padding: 6px">').text(activeProject.branches.local).appendTo(localRepoLabel);
var localRepoSearch = $('<button class="editor-button" style="border-top-right-radius: 4px; border-bottom-right-radius: 4px; width: 36px; height: 34px; position: absolute; top: -1px; right: -1px;"><i class="fa fa-code-fork"></i></button>')
.hide()
.appendTo(localRepoLabel)
.click(function(e) {
e.preventDefault();
if ($(this).hasClass('selected')) {
hideLocalRepoBranchList();
} else {
$(this).addClass('selected');
localRepoLabel.css('height','auto');
localRepoBranchListRow.slideDown(100);
localRepoBranchList.refresh("/projects/"+activeProject.name+"/branches");
localRepoBranchList.focus();
}
});
var localRepoBranchListRow = $('<div>').hide().appendTo(localRepoLabel);
var localRepoBranchList = utils.createBranchList({
current: function() {
return activeProject.branches.local
},
placeholder: "Find or create a branch",
container: localRepoBranchListRow,
onselect: function(body) {
localRepoText.text(body.name);
hideLocalRepoBranchList();
}
})
var hideEditForm = function() {
editRepoButton.show();
localRepoSearch.hide();
formButtons.hide();
localRepoBranchListRow.slideUp(100);
localRepoSearch.removeClass('selected');
}
var formButtons = $('<span class="button-group" style="position: relative; float: right; margin-right:0;"></span>').hide().appendTo(repoContainer);
$('<button class="editor-button">Cancel</button>')
.appendTo(formButtons)
.click(function(evt) {
evt.preventDefault();
hideEditForm();
});
var saveButton = $('<button class="editor-button">Save</button>')
.appendTo(formButtons)
.click(function(evt) {
evt.preventDefault();
hideEditForm();
});
var updateForm = function() {
// if (activeProject.settings.credentialSecretInvalid) {
// credentialStateLabel.find(".user-settings-credentials-state-icon").removeClass().addClass("user-settings-credentials-state-icon fa fa-warning");
// credentialStateLabel.find(".user-settings-credentials-state").text("Invalid encryption key");
// } else if (activeProject.settings.credentialsEncrypted) {
// credentialStateLabel.find(".user-settings-credentials-state-icon").removeClass().addClass("user-settings-credentials-state-icon fa fa-lock");
// credentialStateLabel.find(".user-settings-credentials-state").text("Encryption enabled");
// } else {
// credentialStateLabel.find(".user-settings-credentials-state-icon").removeClass().addClass("user-settings-credentials-state-icon fa fa-unlock");
// credentialStateLabel.find(".user-settings-credentials-state").text("Encryption disabled");
// }
// credentialSecretResetButton.toggleClass('disabled',!activeProject.settings.credentialsEncrypted);
// credentialSecretResetButton.prop('disabled',!activeProject.settings.credentialsEncrypted);
}
}
function createRemoteRepositorySection(activeProject,pane) { function createRemoteRepositorySection(activeProject,pane) {
var title = $('<h3></h3>').text("Git Remotes").appendTo(pane); var title = $('<h3></h3>').text("Version Control").appendTo(pane);
var repoContainer = $('<div class="user-settings-section"></div>').appendTo(pane);
var editRepoButton = $('<button class="editor-button editor-button-small" style="float: right;">edit</button>') var editRepoButton = $('<button class="editor-button editor-button-small" style="float: right;">edit</button>')
.appendTo(title) .appendTo(title)
.click(function(evt) { .click(function(evt) {
editRepoButton.hide(); editRepoButton.hide();
formButtons.show(); formButtons.show();
$('.projects-dialog-remote-list-entry-delete').show();
remoteListAddButton.show();
gitUsernameLabel.hide();
gitUsernameInput.show();
gitEmailLabel.hide();
gitEmailInput.show();
}); });
var repoContainer = $('<div class="user-settings-section"></div>').appendTo(pane);
var subtitle = $('<h4></h4>').text("Committer Details").appendTo(repoContainer);
$('<div style="display: inline-block; margin-left: 20px;"><small style="color:#aaa;"></small></div>').appendTo(subtitle).find('small').text("Leave blank to use system default");
var row = $('<div class="user-settings-row"></div>').appendTo(repoContainer); var row = $('<div class="user-settings-row"></div>').appendTo(repoContainer);
$('<label for=""></label>').text('Username').appendTo(row);
var gitUsernameLabel = $('<div class="uneditable-input">').appendTo(row);
var gitUsernameInput = $('<input type="text">').hide().appendTo(row);
row = $('<div class="user-settings-row"></div>').appendTo(repoContainer);
$('<label for=""></label>').text('Email').appendTo(row);
var gitEmailLabel = $('<div class="uneditable-input">').appendTo(row);
var gitEmailInput = $('<input type="text">').hide().appendTo(row);
if (activeProject.git.user) {
gitUsernameLabel.text(activeProject.git.user.name);
gitUsernameInput.val(activeProject.git.user.name);
gitEmailLabel.text(activeProject.git.user.email);
gitEmailInput.val(activeProject.git.user.email);
}
var remotesList = $("<ol>",{style:"height: 320px"}).appendTo(row); var grTitle = $('<h4></h4>').text("Git remotes").appendTo(repoContainer);
row = $('<div class="user-settings-row projects-dialog-remote-list"></div>').appendTo(repoContainer);
var remotesList = $('<ol>').appendTo(row);
remotesList.editableList({ remotesList.editableList({
addButton: "remote", addButton: 'add remote repository',
height: 'auto',
addItem: function(outer,index,entry) { addItem: function(outer,index,entry) {
var row = $('<div class="user-settings-row"></div>').appendTo(outer);
$('<label for=""></label>').text('Name').appendTo(row); var header = $('<div class="projects-dialog-remote-list-entry-header"></div>').appendTo(outer);
$('<div class="uneditable-input">').text(entry.name).appendTo(row); entry.header = $('<span>').text(entry.name||"Add new remote").appendTo(header);
row = $('<div class="user-settings-row"></div>').appendTo(outer); var body = $('<div>').appendTo(outer);
entry.body = body;
if (entry.name) {
entry.removeButton = $('<button class="editor-button editor-button-small projects-dialog-remote-list-entry-delete">remove</button>')
.hide()
.appendTo(header)
.click(function(e) {
entry.removed = true;
body.fadeOut(100);
entry.header.css("text-decoration","line-through")
entry.header.css("font-style","italic")
$(this).hide();
});
if (entry.urls.fetch === entry.urls.push) {
row = $('<div class="user-settings-row"></div>').appendTo(body);
$('<label for=""></label>').text('URL').appendTo(row);
$('<div class="uneditable-input">').text(entry.urls.fetch).appendTo(row);
} else {
row = $('<div class="user-settings-row"></div>').appendTo(body);
$('<label for=""></label>').text('Fetch URL').appendTo(row); $('<label for=""></label>').text('Fetch URL').appendTo(row);
$('<div class="uneditable-input">').text(entry.urls.fetch).appendTo(row); $('<div class="uneditable-input">').text(entry.urls.fetch).appendTo(row);
row = $('<div class="user-settings-row"></div>').appendTo(outer); row = $('<div class="user-settings-row"></div>').appendTo(body);
$('<label for=""></label>').text('Push URL').appendTo(row); $('<label for=""></label>').text('Push URL').appendTo(row);
$('<div class="uneditable-input">').text(entry.urls.push).appendTo(row); $('<div class="uneditable-input">').text(entry.urls.push).appendTo(row);
} }
} else {
row = $('<div class="user-settings-row"></div>').appendTo(body);
$('<label for=""></label>').text('Remote name').appendTo(row);
entry.nameInput = $('<input type="text">').appendTo(row);
row = $('<div class="user-settings-row"></div>').appendTo(body);
var fetchLabel = $('<label for=""></label>').text('URL').appendTo(row);
entry.urlInput = $('<input type="text">').appendTo(row);
}
}
}); });
if (activeProject.hasOwnProperty('remotes')) {
for (var name in activeProject.remotes) {
if (activeProject.remotes.hasOwnProperty(name)) {
remotesList.editableList('addItem',{name:name,urls:activeProject.remotes[name]});
}
}
}
var remoteListAddButton = row.find(".red-ui-editableList-addButton").hide();
// row = $('<div class="user-settings-row"></div>').appendTo(repoContainer);
// if (activeProject.hasOwnProperty('remotes')) {
// $('<label for=""></label>').text('URL').appendTo(row);
// for (var name in activeProject.remotes) {
// if (activeProject.remotes.hasOwnProperty(name)) {
// var repos = activeProject.remotes[name];
// if (repos.fetch === repos.push) {
// $('<div class="uneditable-input">').text(repos.fetch).appendTo(row);
// $('<div class="projects-edit-form-sublabel"><small></small></div>').appendTo(row).find('small').text(name+" fetch/push");
// } else {
// $('<div class="uneditable-input">').text(repos.fetch).appendTo(row);
// $('<div class="projects-edit-form-sublabel"><small></small></div>').appendTo(row).find('small').text(name+" fetch");
// $('<label for=""></label>').appendTo(row);
// $('<div class="uneditable-input">').text(repos.push).appendTo(row);
// $('<div class="projects-edit-form-sublabel"><small></small></div>').appendTo(row).find('small').text(name+" push");
// // $('<span>').text(repos.fetch+" (fetch)").appendTo(repoRow);
// // $('<span>').text(repos.push+" (push)").appendTo(repoRow);
// }
// }
// }
// if (activeProject.branches.hasOwnProperty('remote')) {
// row = $('<div class="user-settings-row"></div>').appendTo(repoContainer);
// $('<label for="" style="text-align: right;box-sizing: border-box; padding-right: 25px;">Branch</label>').appendTo(row);
// $('<div class="uneditable-input">').text(activeProject.branches.remote).appendTo(row);
//
// row = $('<div class="user-settings-row"></div>').appendTo(repoContainer);
// $('<label for="" style="text-align: right;box-sizing: border-box; padding-right: 25px;">Username</label>').appendTo(row);
// $('<div class="uneditable-input">').appendTo(row);
//
// row = $('<div class="user-settings-row"></div>').appendTo(repoContainer);
// $('<label for="" style="text-align: right;box-sizing: border-box; padding-right: 25px;">Password</label>').appendTo(row);
// $('<div class="uneditable-input">').html("&bull; &bull; &bull; &bull; &bull; &bull; &bull; &bull;").appendTo(row);
// }
// } else {
//
//
// }
var hideEditForm = function() { var hideEditForm = function() {
editRepoButton.show(); editRepoButton.show();
formButtons.hide(); formButtons.hide();
$('.projects-dialog-remote-list-entry-delete').hide();
remoteListAddButton.hide();
gitUsernameLabel.show();
gitUsernameInput.hide();
gitEmailLabel.show();
gitEmailInput.hide();
} }
var formButtons = $('<span class="button-group" style="position: relative; float: right; margin-right:0;"></span>').hide().appendTo(repoContainer); var formButtons = $('<span class="button-group" style="position: relative; float: right; margin-right:0;"></span>')
.hide().appendTo(repoContainer);
$('<button class="editor-button">Cancel</button>') $('<button class="editor-button">Cancel</button>')
.appendTo(formButtons) .appendTo(formButtons)
.click(function(evt) { .click(function(evt) {
evt.preventDefault(); evt.preventDefault();
var items = remotesList.editableList('items');
items.each(function() {
var data = $(this).data('data');
if (!data.name) {
remotesList.editableList('removeItem',data);
} else if (data.removed) {
delete data.removed;
data.body.show();
data.header.css("text-decoration","");
data.header.css("font-style","");
}
})
hideEditForm(); hideEditForm();
}); });
var saveButton = $('<button class="editor-button">Save</button>') var saveButton = $('<button class="editor-button">Save</button>')
.appendTo(formButtons) .appendTo(formButtons)
.click(function(evt) { .click(function(evt) {
evt.preventDefault(); evt.preventDefault();
var spinner = utils.addSpinnerOverlay(repoContainer);
var body = {
user: {
name: gitUsernameInput.val(),
email: gitEmailInput.val()
},
remotes: {}
}
var items = remotesList.editableList('items');
items.each(function() {
var data = $(this).data('data');
if (!data.name) {
body.remotes[data.nameInput.val()] = {
url: data.urlInput.val()
};
remotesList.editableList('removeItem',data);
} else if (data.removed) {
body.remotes[data.name] = {
removed: true
};
delete data.removed;
data.body.show();
data.header.css("text-decoration","");
data.header.css("font-style","");
}
})
var done = function(err) {
spinner.remove();
if (err) {
console.log(err);
return;
}
hideEditForm(); hideEditForm();
}
var payload = { git: body };
// console.log(JSON.stringify(payload,null,4));
RED.deploy.setDeployInflight(true);
utils.sendRequest({
url: "projects/"+activeProject.name,
type: "PUT",
responses: {
0: function(error) {
done(error);
},
200: function(data) {
activeProject.git.remotes = data.git.remotes;
activeProject.git.user = data.git.user;
if (activeProject.git.user) {
gitUsernameLabel.text(activeProject.git.user.name);
gitUsernameInput.val(activeProject.git.user.name);
gitEmailLabel.text(activeProject.git.user.email);
gitEmailInput.val(activeProject.git.user.email);
}
updateForm();
done();
},
400: {
'unexpected_error': function(error) {
console.log(error);
done(error);
}
},
}
},payload);
}); });
var updateForm = function() { } var updateForm = function() {
remotesList.editableList('empty');
if (activeProject.git.hasOwnProperty('remotes')) {
for (var name in activeProject.git.remotes) {
if (activeProject.git.remotes.hasOwnProperty(name)) {
remotesList.editableList('addItem',{name:name,urls:activeProject.git.remotes[name]});
}
}
}
}
updateForm();
} }

View File

@ -397,14 +397,16 @@ RED.projects = (function() {
projectData.copy = copyProject.name; projectData.copy = copyProject.name;
} else if (projectType === 'clone') { } else if (projectType === 'clone') {
// projectData.credentialSecret = projectSecretInput.val(); // projectData.credentialSecret = projectSecretInput.val();
projectData.remote = { projectData.git = {
// name: projectRepoRemoteName.val()||'origin', remotes: {
// branch: projectRepoBranch.val()||'master', 'origin': {
url: projectRepoInput.val(), url: projectRepoInput.val(),
username: projectRepoUserInput.val(), username: projectRepoUserInput.val(),
password: projectRepoPasswordInput.val() password: projectRepoPasswordInput.val()
} }
} }
}
}
RED.deploy.setDeployInflight(true); RED.deploy.setDeployInflight(true);
RED.projects.settings.switchProject(projectData.name); RED.projects.settings.switchProject(projectData.name);
@ -632,7 +634,7 @@ RED.projects = (function() {
function sendRequest(options,body) { function sendRequest(options,body) {
// dialogBody.hide(); // dialogBody.hide();
console.log(options.url); console.log(options.url,body);
if (options.requireCleanWorkspace && RED.nodes.dirty()) { if (options.requireCleanWorkspace && RED.nodes.dirty()) {
var message = 'You have undeployed changes that will be lost. Do you want to continue?'; var message = 'You have undeployed changes that will be lost. Do you want to continue?';
@ -698,7 +700,7 @@ RED.projects = (function() {
resultCallbackArgs = {error:responses.statusText}; resultCallbackArgs = {error:responses.statusText};
return; return;
} else if (options.handleAuthFail !== false && xhr.responseJSON.error === 'git_auth_failed') { } else if (options.handleAuthFail !== false && xhr.responseJSON.error === 'git_auth_failed') {
var url = activeProject.remotes.origin.fetch; var url = activeProject.git.remotes.origin.fetch;
var message = $('<div>'+ var message = $('<div>'+
'<div class="form-row">Authentication required for repository:</div>'+ '<div class="form-row">Authentication required for repository:</div>'+
'<div class="form-row"><div style="margin-left: 20px;">'+url+'</div></div>'+ '<div class="form-row"><div style="margin-left: 20px;">'+url+'</div></div>'+
@ -723,6 +725,11 @@ RED.projects = (function() {
var username = $('#projects-user-auth-username').val(); var username = $('#projects-user-auth-username').val();
var password = $('#projects-user-auth-password').val(); var password = $('#projects-user-auth-password').val();
body = body || {}; body = body || {};
var authBody = {git:{remotes:{}}};
authBody.git.remotes[options.remote||'origin'] = {
username: username,
password: password
};
var done = function(err) { var done = function(err) {
if (err) { if (err) {
console.log("Failed to update auth"); console.log("Failed to update auth");
@ -749,14 +756,7 @@ RED.projects = (function() {
} }
}, },
} }
},{ },authBody);
remote: {
origin: {
username: username,
password: password
}
}
});
} }
} }
] ]
@ -858,7 +858,17 @@ RED.projects = (function() {
}, },
filter: function(data) { filter: function(data) {
var isCreateEntry = (typeof data !=="string"); var isCreateEntry = (typeof data !=="string");
return (isCreateEntry && (branchFilterTerm !== "" && branches.indexOf(branchPrefix+branchFilterTerm) === -1) ) || (!isCreateEntry && data.indexOf(branchPrefix+branchFilterTerm) !== -1); return (
isCreateEntry &&
(
branchFilterTerm !== "" &&
branches.indexOf(branchPrefix+branchFilterTerm) === -1
)
) ||
(
!isCreateEntry &&
data.indexOf(branchFilterTerm) !== -1
);
} }
}); });
return { return {

View File

@ -226,7 +226,7 @@ RED.sidebar.versionControl = (function() {
stagedChangesList.editableList('empty'); stagedChangesList.editableList('empty');
unmergedChangesList.editableList('empty'); unmergedChangesList.editableList('empty');
$.getJSON("/projects/"+activeProject.name+"/status",function(result) { $.getJSON("projects/"+activeProject.name+"/status",function(result) {
refreshFiles(result); refreshFiles(result);
}); });
} }
@ -471,7 +471,7 @@ RED.sidebar.versionControl = (function() {
localCommitListShade.show(); localCommitListShade.show();
$(this).addClass('selected'); $(this).addClass('selected');
var activeProject = RED.projects.getActiveProject(); var activeProject = RED.projects.getActiveProject();
localBranchList.refresh("/projects/"+activeProject.name+"/branches"); localBranchList.refresh("projects/"+activeProject.name+"/branches");
localBranchBox.show(); localBranchBox.show();
setTimeout(function() { setTimeout(function() {
localBranchBox.css("height","215px"); localBranchBox.css("height","215px");
@ -523,7 +523,7 @@ RED.sidebar.versionControl = (function() {
row.click(function(e) { row.click(function(e) {
var activeProject = RED.projects.getActiveProject(); var activeProject = RED.projects.getActiveProject();
if (activeProject) { if (activeProject) {
$.getJSON("/projects/"+activeProject.name+"/commits/"+entry.sha,function(result) { $.getJSON("projects/"+activeProject.name+"/commits/"+entry.sha,function(result) {
result.project = activeProject; result.project = activeProject;
result.parents = entry.parents; result.parents = entry.parents;
result.oldRev = entry.sha+"~1"; result.oldRev = entry.sha+"~1";
@ -572,7 +572,7 @@ RED.sidebar.versionControl = (function() {
var localBranchList = utils.createBranchList({ var localBranchList = utils.createBranchList({
current: function() { current: function() {
return RED.projects.getActiveProject().branches.local return RED.projects.getActiveProject().git.branches.local
}, },
placeholder: "Find or create a branch", placeholder: "Find or create a branch",
container: localBranchBox, container: localBranchBox,
@ -653,7 +653,7 @@ RED.sidebar.versionControl = (function() {
} else { } else {
$(this).addClass('selected'); $(this).addClass('selected');
var activeProject = RED.projects.getActiveProject(); var activeProject = RED.projects.getActiveProject();
remoteBranchList.refresh("/projects/"+activeProject.name+"/branches/remote"); remoteBranchList.refresh("projects/"+activeProject.name+"/branches/remote");
remoteBranchSubRow.show(); remoteBranchSubRow.show();
setTimeout(function() { setTimeout(function() {
remoteBranchSubRow.height(180); remoteBranchSubRow.height(180);
@ -676,7 +676,7 @@ RED.sidebar.versionControl = (function() {
var activeProject = RED.projects.getActiveProject(); var activeProject = RED.projects.getActiveProject();
var spinner = utils.addSpinnerOverlay(remoteBox).addClass("projects-dialog-spinner-contain"); var spinner = utils.addSpinnerOverlay(remoteBox).addClass("projects-dialog-spinner-contain");
utils.sendRequest({ utils.sendRequest({
url: "/projects/"+activeProject.name+"/branches/remote", url: "projects/"+activeProject.name+"/branches/remote",
type: "GET", type: "GET",
responses: { responses: {
0: function(error) { 0: function(error) {
@ -706,13 +706,13 @@ RED.sidebar.versionControl = (function() {
var remoteBranchSubRow = $('<div style="height: 0;overflow:hidden; transition: height 0.2s ease-in-out;"></div>').hide().appendTo(remoteBranchRow); var remoteBranchSubRow = $('<div style="height: 0;overflow:hidden; transition: height 0.2s ease-in-out;"></div>').hide().appendTo(remoteBranchRow);
var remoteBranchList = utils.createBranchList({ var remoteBranchList = utils.createBranchList({
current: function() { current: function() {
return RED.projects.getActiveProject().branches.remote return RED.projects.getActiveProject().git.branches.remote
}, },
placeholder: "Find or create a remote branch", placeholder: "Find or create a remote branch",
currentLabel: "upstream", currentLabel: "upstream",
remote: function() { remote: function() {
var project = RED.projects.getActiveProject(); var project = RED.projects.getActiveProject();
var remotes = Object.keys(project.remotes); var remotes = Object.keys(project.git.remotes);
return remotes[0]; return remotes[0];
}, },
container: remoteBranchSubRow, container: remoteBranchSubRow,
@ -721,12 +721,12 @@ RED.sidebar.versionControl = (function() {
$("#sidebar-version-control-repo-toolbar-set-upstream").prop('disabled',false); $("#sidebar-version-control-repo-toolbar-set-upstream").prop('disabled',false);
$("#sidebar-version-control-remote-branch").text(body.name+(body.create?" *":"")); $("#sidebar-version-control-remote-branch").text(body.name+(body.create?" *":""));
var activeProject = RED.projects.getActiveProject(); var activeProject = RED.projects.getActiveProject();
if (activeProject.branches.remote === body.name) { if (activeProject.git.branches.remote === body.name) {
delete activeProject.branches.remoteAlt; delete activeProject.git.branches.remoteAlt;
} else { } else {
activeProject.branches.remoteAlt = body.name; activeProject.git.branches.remoteAlt = body.name;
} }
$("#sidebar-version-control-repo-toolbar-set-upstream-row").toggle(!!activeProject.branches.remoteAlt); $("#sidebar-version-control-repo-toolbar-set-upstream-row").toggle(!!activeProject.git.branches.remoteAlt);
closeRemoteBranchBox(function() { closeRemoteBranchBox(function() {
if (!body.create) { if (!body.create) {
var start = Date.now(); var start = Date.now();
@ -738,7 +738,7 @@ RED.sidebar.versionControl = (function() {
},Math.max(400-(Date.now() - start),0)); },Math.max(400-(Date.now() - start),0));
}) })
} else { } else {
if (!activeProject.branches.remote) { if (!activeProject.git.branches.remote) {
$('#sidebar-version-control-repo-toolbar-message').text("The created branch will be set as the tracked upstream branch."); $('#sidebar-version-control-repo-toolbar-message').text("The created branch will be set as the tracked upstream branch.");
$("#sidebar-version-control-repo-toolbar-set-upstream").prop('checked',true); $("#sidebar-version-control-repo-toolbar-set-upstream").prop('checked',true);
$("#sidebar-version-control-repo-toolbar-set-upstream").prop('disabled',true); $("#sidebar-version-control-repo-toolbar-set-upstream").prop('disabled',true);
@ -762,8 +762,8 @@ RED.sidebar.versionControl = (function() {
var spinner = utils.addSpinnerOverlay(remoteBox).addClass("projects-dialog-spinner-contain"); var spinner = utils.addSpinnerOverlay(remoteBox).addClass("projects-dialog-spinner-contain");
var activeProject = RED.projects.getActiveProject(); var activeProject = RED.projects.getActiveProject();
var url = "projects/"+activeProject.name+"/push"; var url = "projects/"+activeProject.name+"/push";
if (activeProject.branches.remoteAlt) { if (activeProject.git.branches.remoteAlt) {
url+="/"+activeProject.branches.remoteAlt; url+="/"+activeProject.git.branches.remoteAlt;
} }
if ($("#sidebar-version-control-repo-toolbar-set-upstream").prop('checked')) { if ($("#sidebar-version-control-repo-toolbar-set-upstream").prop('checked')) {
url+="?u=true" url+="?u=true"
@ -803,8 +803,8 @@ RED.sidebar.versionControl = (function() {
var spinner = utils.addSpinnerOverlay(remoteBox).addClass("projects-dialog-spinner-contain"); var spinner = utils.addSpinnerOverlay(remoteBox).addClass("projects-dialog-spinner-contain");
var activeProject = RED.projects.getActiveProject(); var activeProject = RED.projects.getActiveProject();
var url = "projects/"+activeProject.name+"/pull"; var url = "projects/"+activeProject.name+"/pull";
if (activeProject.branches.remoteAlt) { if (activeProject.git.branches.remoteAlt) {
url+="/"+activeProject.branches.remoteAlt; url+="/"+activeProject.git.branches.remoteAlt;
} }
if ($("#sidebar-version-control-repo-toolbar-set-upstream").prop('checked')) { if ($("#sidebar-version-control-repo-toolbar-set-upstream").prop('checked')) {
url+="?u=true" url+="?u=true"
@ -965,7 +965,7 @@ RED.sidebar.versionControl = (function() {
localCommitList.editableList('empty'); localCommitList.editableList('empty');
var activeProject = RED.projects.getActiveProject(); var activeProject = RED.projects.getActiveProject();
if (activeProject) { if (activeProject) {
getCommits("/projects/"+activeProject.name+"/commits",localCommitList,localCommitList.parent()); getCommits("projects/"+activeProject.name+"/commits",localCommitList,localCommitList.parent());
} }
} }
// function refreshRemoteCommits() { // function refreshRemoteCommits() {
@ -973,7 +973,7 @@ RED.sidebar.versionControl = (function() {
// var spinner = utils.addSpinnerOverlay(remoteCommitList); // var spinner = utils.addSpinnerOverlay(remoteCommitList);
// var activeProject = RED.projects.getActiveProject(); // var activeProject = RED.projects.getActiveProject();
// if (activeProject) { // if (activeProject) {
// getCommits("/projects/"+activeProject.name+"/commits/origin",remoteCommitList,remoteCommitList.parent()); // getCommits("projects/"+activeProject.name+"/commits/origin",remoteCommitList,remoteCommitList.parent());
// } // }
// } // }
@ -1127,7 +1127,7 @@ RED.sidebar.versionControl = (function() {
var activeProject = RED.projects.getActiveProject(); var activeProject = RED.projects.getActiveProject();
if (activeProject) { if (activeProject) {
$.getJSON("/projects/"+activeProject.name+"/status",function(result) { $.getJSON("projects/"+activeProject.name+"/status",function(result) {
refreshFiles(result); refreshFiles(result);
$('#sidebar-version-control-local-branch').text(result.branches.local); $('#sidebar-version-control-local-branch').text(result.branches.local);
@ -1136,7 +1136,7 @@ RED.sidebar.versionControl = (function() {
var commitsAhead = result.commits.ahead || 0; var commitsAhead = result.commits.ahead || 0;
var commitsBehind = result.commits.behind || 0; var commitsBehind = result.commits.behind || 0;
if (activeProject.hasOwnProperty('remotes')) { if (activeProject.git.hasOwnProperty('remotes')) {
if (result.branches.hasOwnProperty("remoteError")) { if (result.branches.hasOwnProperty("remoteError")) {
$("#sidebar-version-control-repo-status-auth-issue").show(); $("#sidebar-version-control-repo-status-auth-issue").show();
$("#sidebar-version-control-repo-status-stats").hide(); $("#sidebar-version-control-repo-status-stats").hide();

View File

@ -2766,7 +2766,7 @@ RED.view = (function() {
if (v === undefined) { if (v === undefined) {
return gridSize; return gridSize;
} else { } else {
gridSize = v; gridSize = Math.max(5,v);
updateGrid(); updateGrid();
} }
} }

View File

@ -79,6 +79,7 @@
font-size: 14px; font-size: 14px;
padding: 6px 14px; padding: 6px 14px;
margin-right: 8px; margin-right: 8px;
border-radius: 2px;
color: $editor-button-color; color: $editor-button-color;
background: $editor-button-background; background: $editor-button-background;

View File

@ -180,7 +180,6 @@
border-right-color: #aaa; border-right-color: #aaa;
} }
} }
i { i {
color: #ccc; color: #ccc;
font-size: 2em; font-size: 2em;
@ -592,6 +591,9 @@
border-right-color:#999; border-right-color:#999;
} }
} }
&.unselectable {
color: #ccc;
}
i { i {
color: #999; color: #999;
@ -627,3 +629,47 @@
} }
} }
.projects-dialog-file-list-entry-file-type-git { color: #999 } .projects-dialog-file-list-entry-file-type-git { color: #999 }
.projects-dialog-remote-list {
.red-ui-editableList-container {
padding: 0;
li {
padding: 0;
border: none;
border-radius: 4px;
overflow: hidden;
}
}
}
.projects-dialog-remote-list-entry-header {
padding: 8px 10px;
background: #f6f6f6;
margin-bottom: 8px;
}
.projects-dialog-remote-list-entry-delete {
float: right;
}
/*
.expandable-list-entry {
.exandable-list-entry-header {
padding: 15px 0;
cursor: pointer;
&:hover {
background: #f3f3f3;
}
i {
width: 16px;
text-align: center;
}
.fa-angle-right {
color: #333;
transition: all 0.2s ease-in-out;
}
}
&.expanded .fa-angle-right {
transform: rotate(90deg);
}
}
*/

View File

@ -54,6 +54,10 @@
input[type='number'] { input[type='number'] {
width: 60px; width: 60px;
} }
h4 {
margin-top: 20px;
margin-bottom: 10px;
}
} }
#user-settings-tab-view { #user-settings-tab-view {

View File

@ -17,6 +17,7 @@
var express = require("express"); var express = require("express");
var runtime; var runtime;
var settings; var settings;
var needsPermission = require("../../auth").needsPermission;
module.exports = { module.exports = {
init: function(_runtime) { init: function(_runtime) {
@ -29,9 +30,10 @@ module.exports = {
// Projects // Projects
// List all projects // List all projects
app.get("/", function(req,res) { app.get("/", needsPermission("projects.read"), function(req,res) {
runtime.storage.projects.listProjects().then(function(list) { console.log(req.user);
var active = runtime.storage.projects.getActiveProject(); runtime.storage.projects.listProjects(req.user, req.user).then(function(list) {
var active = runtime.storage.projects.getActiveProject(req.user);
var response = { var response = {
active: active.name, active: active.name,
projects: list projects: list
@ -48,8 +50,8 @@ module.exports = {
}); });
// Create project // Create project
app.post("/", function(req,res) { app.post("/", needsPermission("projects.write"), function(req,res) {
runtime.storage.projects.createProject(req.body).then(function(data) { runtime.storage.projects.createProject(req.user, req.body).then(function(data) {
res.json(data); res.json(data);
}).catch(function(err) { }).catch(function(err) {
console.log(err.stack); console.log(err.stack);
@ -62,12 +64,12 @@ module.exports = {
}); });
// Update a project // Update a project
app.put("/:id", function(req,res) { app.put("/:id", needsPermission("projects.write"), function(req,res) {
//TODO: validate the payload properly //TODO: validate the payload properly
if (req.body.active) { if (req.body.active) {
var currentProject = runtime.storage.projects.getActiveProject(); var currentProject = runtime.storage.projects.getActiveProject(req.user);
if (req.params.id !== currentProject.name) { if (req.params.id !== currentProject.name) {
runtime.storage.projects.setActiveProject(req.params.id).then(function() { runtime.storage.projects.setActiveProject(req.user, req.params.id).then(function() {
res.redirect(303,req.baseUrl + '/'); res.redirect(303,req.baseUrl + '/');
}).catch(function(err) { }).catch(function(err) {
if (err.code) { if (err.code) {
@ -84,8 +86,8 @@ module.exports = {
req.body.hasOwnProperty('dependencies')|| req.body.hasOwnProperty('dependencies')||
req.body.hasOwnProperty('summary') || req.body.hasOwnProperty('summary') ||
req.body.hasOwnProperty('files') || req.body.hasOwnProperty('files') ||
req.body.hasOwnProperty('remote')) { req.body.hasOwnProperty('git')) {
runtime.storage.projects.updateProject(req.params.id, req.body).then(function() { runtime.storage.projects.updateProject(req.user, req.params.id, req.body).then(function() {
res.redirect(303,req.baseUrl + '/'+ req.params.id); res.redirect(303,req.baseUrl + '/'+ req.params.id);
}).catch(function(err) { }).catch(function(err) {
if (err.code) { if (err.code) {
@ -100,8 +102,8 @@ module.exports = {
}); });
// Get project metadata // Get project metadata
app.get("/:id", function(req,res) { app.get("/:id", needsPermission("projects.read"), function(req,res) {
runtime.storage.projects.getProject(req.params.id).then(function(data) { runtime.storage.projects.getProject(req.user, req.params.id).then(function(data) {
if (data) { if (data) {
res.json(data); res.json(data);
} else { } else {
@ -114,13 +116,13 @@ module.exports = {
}); });
// Delete project - tbd // Delete project - tbd
app.delete("/:id", function(req,res) { app.delete("/:id", needsPermission("projects.write"), function(req,res) {
}); });
// Get project status - files, commit counts, branch info // Get project status - files, commit counts, branch info
app.get("/:id/status", function(req,res) { app.get("/:id/status", needsPermission("projects.read"), function(req,res) {
runtime.storage.projects.getStatus(req.params.id).then(function(data) { runtime.storage.projects.getStatus(req.user, req.params.id).then(function(data) {
if (data) { if (data) {
res.json(data); res.json(data);
} else { } else {
@ -134,8 +136,8 @@ module.exports = {
// Project file listing // Project file listing
app.get("/:id/files", function(req,res) { app.get("/:id/files", needsPermission("projects.read"), function(req,res) {
runtime.storage.projects.getFiles(req.params.id).then(function(data) { runtime.storage.projects.getFiles(req.user, req.params.id).then(function(data) {
console.log("TODO: REMOVE /:id/files as /:id/status is better!") console.log("TODO: REMOVE /:id/files as /:id/status is better!")
res.json(data); res.json(data);
}) })
@ -147,12 +149,12 @@ module.exports = {
// Get file content in a given tree (index/stage) // Get file content in a given tree (index/stage)
app.get("/:id/files/:treeish/*", function(req,res) { app.get("/:id/files/:treeish/*", needsPermission("projects.read"), function(req,res) {
var projectId = req.params.id; var projectId = req.params.id;
var treeish = req.params.treeish; var treeish = req.params.treeish;
var filePath = req.params[0]; var filePath = req.params[0];
runtime.storage.projects.getFile(projectId,filePath,treeish).then(function(data) { runtime.storage.projects.getFile(req.user, projectId,filePath,treeish).then(function(data) {
res.json({content:data}); res.json({content:data});
}) })
.catch(function(err) { .catch(function(err) {
@ -162,11 +164,11 @@ module.exports = {
}); });
// Stage a file // Stage a file
app.post("/:id/stage/*", function(req,res) { app.post("/:id/stage/*", needsPermission("projects.write"), function(req,res) {
var projectName = req.params.id; var projectName = req.params.id;
var file = req.params[0]; var file = req.params[0];
runtime.storage.projects.stageFile(projectName,file).then(function(data) { runtime.storage.projects.stageFile(req.user, projectName,file).then(function(data) {
res.redirect(303,req.baseUrl+"/"+projectName+"/status"); res.redirect(303,req.baseUrl+"/"+projectName+"/status");
}) })
.catch(function(err) { .catch(function(err) {
@ -176,11 +178,11 @@ module.exports = {
}); });
// Stage multiple files // Stage multiple files
app.post("/:id/stage", function(req,res) { app.post("/:id/stage", needsPermission("projects.write"), function(req,res) {
var projectName = req.params.id; var projectName = req.params.id;
var files = req.body.files; var files = req.body.files;
runtime.storage.projects.stageFile(projectName,files).then(function(data) { runtime.storage.projects.stageFile(req.user, projectName,files).then(function(data) {
res.redirect(303,req.baseUrl+"/"+projectName+"/status"); res.redirect(303,req.baseUrl+"/"+projectName+"/status");
}) })
.catch(function(err) { .catch(function(err) {
@ -190,10 +192,10 @@ module.exports = {
}); });
// Commit changes // Commit changes
app.post("/:id/commit", function(req,res) { app.post("/:id/commit", needsPermission("projects.write"), function(req,res) {
var projectName = req.params.id; var projectName = req.params.id;
runtime.storage.projects.commit(projectName,req.body).then(function(data) { runtime.storage.projects.commit(req.user, projectName,req.body).then(function(data) {
res.redirect(303,req.baseUrl+"/"+projectName+"/status"); res.redirect(303,req.baseUrl+"/"+projectName+"/status");
}) })
.catch(function(err) { .catch(function(err) {
@ -203,11 +205,11 @@ module.exports = {
}); });
// Unstage a file // Unstage a file
app.delete("/:id/stage/*", function(req,res) { app.delete("/:id/stage/*", needsPermission("projects.write"), function(req,res) {
var projectName = req.params.id; var projectName = req.params.id;
var file = req.params[0]; var file = req.params[0];
runtime.storage.projects.unstageFile(projectName,file).then(function(data) { runtime.storage.projects.unstageFile(req.user, projectName,file).then(function(data) {
res.redirect(303,req.baseUrl+"/"+projectName+"/status"); res.redirect(303,req.baseUrl+"/"+projectName+"/status");
}) })
.catch(function(err) { .catch(function(err) {
@ -217,9 +219,9 @@ module.exports = {
}); });
// Unstage multiple files // Unstage multiple files
app.delete("/:id/stage", function(req, res) { app.delete("/:id/stage", needsPermission("projects.write"), function(req, res) {
var projectName = req.params.id; var projectName = req.params.id;
runtime.storage.projects.unstageFile(projectName).then(function(data) { runtime.storage.projects.unstageFile(req.user, projectName).then(function(data) {
res.redirect(303,req.baseUrl+"/"+projectName+"/status"); res.redirect(303,req.baseUrl+"/"+projectName+"/status");
}) })
.catch(function(err) { .catch(function(err) {
@ -229,11 +231,11 @@ module.exports = {
}); });
// Get a file diff // Get a file diff
app.get("/:id/diff/:type/*", function(req,res) { app.get("/:id/diff/:type/*", needsPermission("projects.read"), function(req,res) {
var projectName = req.params.id; var projectName = req.params.id;
var type = req.params.type; var type = req.params.type;
var file = req.params[0]; var file = req.params[0];
runtime.storage.projects.getFileDiff(projectName,file,type).then(function(data) { runtime.storage.projects.getFileDiff(req.user, projectName,file,type).then(function(data) {
res.json({ res.json({
diff: data diff: data
}) })
@ -245,13 +247,13 @@ module.exports = {
}); });
// Get a list of commits // Get a list of commits
app.get("/:id/commits", function(req, res) { app.get("/:id/commits", needsPermission("projects.read"), function(req, res) {
var projectName = req.params.id; var projectName = req.params.id;
var options = { var options = {
limit: req.query.limit||20, limit: req.query.limit||20,
before: req.query.before before: req.query.before
}; };
runtime.storage.projects.getCommits(projectName,options).then(function(data) { runtime.storage.projects.getCommits(req.user, projectName,options).then(function(data) {
res.json(data); res.json(data);
}) })
.catch(function(err) { .catch(function(err) {
@ -265,11 +267,11 @@ module.exports = {
}); });
// Get an individual commit details // Get an individual commit details
app.get("/:id/commits/:sha", function(req, res) { app.get("/:id/commits/:sha", needsPermission("projects.read"), function(req, res) {
var projectName = req.params.id; var projectName = req.params.id;
var sha = req.params.sha; var sha = req.params.sha;
runtime.storage.projects.getCommit(projectName,sha).then(function(data) { runtime.storage.projects.getCommit(req.user, projectName,sha).then(function(data) {
res.json({commit:data}); res.json({commit:data});
}) })
.catch(function(err) { .catch(function(err) {
@ -279,11 +281,11 @@ module.exports = {
}); });
// Push local commits to remote // Push local commits to remote
app.post("/:id/push/?*", function(req,res) { app.post("/:id/push/?*", needsPermission("projects.write"), function(req,res) {
var projectName = req.params.id; var projectName = req.params.id;
var remoteBranchName = req.params[0] var remoteBranchName = req.params[0]
var setRemote = req.query.u; var setRemote = req.query.u;
runtime.storage.projects.push(projectName,remoteBranchName,setRemote).then(function(data) { runtime.storage.projects.push(req.user, projectName,remoteBranchName,setRemote).then(function(data) {
res.status(204).end(); res.status(204).end();
}) })
.catch(function(err) { .catch(function(err) {
@ -297,11 +299,11 @@ module.exports = {
}); });
// Pull remote commits // Pull remote commits
app.post("/:id/pull/?*", function(req,res) { app.post("/:id/pull/?*", needsPermission("projects.write"), function(req,res) {
var projectName = req.params.id; var projectName = req.params.id;
var remoteBranchName = req.params[0]; var remoteBranchName = req.params[0];
var setRemote = req.query.u; var setRemote = req.query.u;
runtime.storage.projects.pull(projectName,remoteBranchName,setRemote).then(function(data) { runtime.storage.projects.pull(req.user, projectName,remoteBranchName,setRemote).then(function(data) {
res.status(204).end(); res.status(204).end();
}) })
.catch(function(err) { .catch(function(err) {
@ -315,9 +317,9 @@ module.exports = {
}); });
// Abort an ongoing merge // Abort an ongoing merge
app.delete("/:id/merge", function(req, res) { app.delete("/:id/merge", needsPermission("projects.write"), function(req, res) {
var projectName = req.params.id; var projectName = req.params.id;
runtime.storage.projects.abortMerge(projectName).then(function(data) { runtime.storage.projects.abortMerge(req.user, projectName).then(function(data) {
res.status(204).end(); res.status(204).end();
}) })
.catch(function(err) { .catch(function(err) {
@ -331,11 +333,11 @@ module.exports = {
}); });
// Resolve a merge // Resolve a merge
app.post("/:id/resolve/*", function(req, res) { app.post("/:id/resolve/*", needsPermission("projects.write"), function(req, res) {
var projectName = req.params.id; var projectName = req.params.id;
var file = req.params[0]; var file = req.params[0];
var resolution = req.body.resolutions; var resolution = req.body.resolutions;
runtime.storage.projects.resolveMerge(projectName,file,resolution).then(function(data) { runtime.storage.projects.resolveMerge(req.user, projectName,file,resolution).then(function(data) {
res.status(204).end(); res.status(204).end();
}) })
.catch(function(err) { .catch(function(err) {
@ -349,9 +351,9 @@ module.exports = {
}); });
// Get a list of local branches // Get a list of local branches
app.get("/:id/branches", function(req, res) { app.get("/:id/branches", needsPermission("projects.read"), function(req, res) {
var projectName = req.params.id; var projectName = req.params.id;
runtime.storage.projects.getBranches(projectName,false).then(function(data) { runtime.storage.projects.getBranches(req.user, projectName,false).then(function(data) {
res.json(data); res.json(data);
}) })
.catch(function(err) { .catch(function(err) {
@ -365,12 +367,13 @@ module.exports = {
}); });
// Get a list of remote branches // Get a list of remote branches
app.get("/:id/branches/remote", function(req, res) { app.get("/:id/branches/remote", needsPermission("projects.read"), function(req, res) {
var projectName = req.params.id; var projectName = req.params.id;
runtime.storage.projects.getBranches(projectName,true).then(function(data) { runtime.storage.projects.getBranches(req.user, projectName,true).then(function(data) {
res.json(data); res.json(data);
}) })
.catch(function(err) { .catch(function(err) {
console.log(err.stack);
if (err.code) { if (err.code) {
res.status(400).json({error:err.code, message: err.message}); res.status(400).json({error:err.code, message: err.message});
} else { } else {
@ -380,10 +383,10 @@ module.exports = {
}); });
// Get branch status - commit counts/ahead/behind // Get branch status - commit counts/ahead/behind
app.get("/:id/branches/remote/*/status", function(req, res) { app.get("/:id/branches/remote/*/status", needsPermission("projects.read"), function(req, res) {
var projectName = req.params.id; var projectName = req.params.id;
var branch = req.params[0]; var branch = req.params[0];
runtime.storage.projects.getBranchStatus(projectName,branch).then(function(data) { runtime.storage.projects.getBranchStatus(req.user, projectName,branch).then(function(data) {
res.json(data); res.json(data);
}) })
.catch(function(err) { .catch(function(err) {
@ -397,11 +400,11 @@ module.exports = {
}); });
// Set the active local branch // Set the active local branch
app.post("/:id/branches", function(req, res) { app.post("/:id/branches", needsPermission("projects.write"), function(req, res) {
var projectName = req.params.id; var projectName = req.params.id;
var branchName = req.body.name; var branchName = req.body.name;
var isCreate = req.body.create; var isCreate = req.body.create;
runtime.storage.projects.setBranch(projectName,branchName,isCreate).then(function(data) { runtime.storage.projects.setBranch(req.user, projectName,branchName,isCreate).then(function(data) {
res.json(data); res.json(data);
}) })
.catch(function(err) { .catch(function(err) {

View File

@ -46,13 +46,6 @@ function init(_server,_runtime) {
adminApp.use(bodyParser.json({limit:maxApiRequestSize})); adminApp.use(bodyParser.json({limit:maxApiRequestSize}));
adminApp.use(bodyParser.urlencoded({limit:maxApiRequestSize,extended:true})); adminApp.use(bodyParser.urlencoded({limit:maxApiRequestSize,extended:true}));
// Editor
if (!settings.disableEditor) {
editor = require("./editor");
var editorApp = editor.init(server, runtime);
adminApp.use(editorApp);
}
adminApp.get("/auth/login",auth.login,apiUtil.errorHandler); adminApp.get("/auth/login",auth.login,apiUtil.errorHandler);
if (settings.adminAuth) { if (settings.adminAuth) {
if (settings.adminAuth.type === "strategy") { if (settings.adminAuth.type === "strategy") {
@ -69,6 +62,13 @@ function init(_server,_runtime) {
adminApp.post("/auth/revoke",auth.needsPermission(""),auth.revoke,apiUtil.errorHandler); adminApp.post("/auth/revoke",auth.needsPermission(""),auth.revoke,apiUtil.errorHandler);
} }
// Editor
if (!settings.disableEditor) {
editor = require("./editor");
var editorApp = editor.init(server, runtime);
adminApp.use(editorApp);
}
if (settings.httpAdminCors) { if (settings.httpAdminCors) {
var corsHandler = cors(settings.httpAdminCors); var corsHandler = cors(settings.httpAdminCors);
adminApp.use(corsHandler); adminApp.use(corsHandler);

View File

@ -51,9 +51,9 @@ Project.prototype.load = function () {
} }
this.credentialSecret = projectSettings.credentialSecret; this.credentialSecret = projectSettings.credentialSecret;
this.git = projectSettings.git || { user:{} };
this.remote = projectSettings.remote; console.log("LOADED",this.git);
// this.paths.flowFile = fspath.join(this.path,"flow.json"); // this.paths.flowFile = fspath.join(this.path,"flow.json");
// this.paths.credentialsFile = fspath.join(this.path,"flow_cred.json"); // this.paths.credentialsFile = fspath.join(this.path,"flow_cred.json");
@ -103,12 +103,7 @@ Project.prototype.load = function () {
// project.paths.credentialsFile = fspath.join(project.path,"flow_cred.json"); // project.paths.credentialsFile = fspath.join(project.path,"flow_cred.json");
// } // }
promises.push(gitTools.getRemotes(project.path).then(function(remotes) { promises.push(project.loadRemotes());
project.remotes = remotes;
}));
promises.push(gitTools.getBranchInfo(project.path).then(function(branches) {
project.branches = branches;
}));
return when.settle(promises).then(function() { return when.settle(promises).then(function() {
return project; return project;
@ -116,7 +111,51 @@ Project.prototype.load = function () {
}); });
}; };
Project.prototype.update = function (data) { Project.prototype.loadRemotes = function() {
var project = this;
return gitTools.getRemotes(project.path).then(function(remotes) {
project.remotes = remotes;
}).then(function() {
return project.loadBranches();
}).then(function() {
var allRemotes = Object.keys(project.remotes);
var match = "";
allRemotes.forEach(function(remote) {
if (project.branches.remote.indexOf(remote) === 0 && match.length < remote.length) {
match = remote;
}
});
project.currentRemote = project.parseRemoteBranch(project.branches.remote).remote;
});
}
Project.prototype.parseRemoteBranch = function (remoteBranch) {
if (!remoteBranch) {
return {}
}
var project = this;
var allRemotes = Object.keys(project.remotes);
var match = "";
allRemotes.forEach(function(remote) {
if (remoteBranch.indexOf(remote) === 0 && match.length < remote.length) {
match = remote;
}
});
return {
remote: match,
branch: remoteBranch.substring(match.length+1)
}
};
Project.prototype.loadBranches = function() {
var project = this;
return gitTools.getBranchInfo(project.path).then(function(branches) {
project.branches = branches;
});
}
Project.prototype.update = function (user, data) {
var promises = []; var promises = [];
var project = this; var project = this;
@ -172,13 +211,63 @@ Project.prototype.update = function (data) {
savePackage = true; savePackage = true;
this.package.description = data.summary; this.package.description = data.summary;
} }
if (data.hasOwnProperty('remote')) { // if (data.hasOwnProperty('remote')) {
for (var remote in data.remote) { // // TODO: this MUST move under 'git'
if (data.remote.hasOwnProperty(remote)) { // for (var remote in data.remote) {
authCache.set(project.name,remote,data.remote[remote]); // if (data.remote.hasOwnProperty(remote)) {
// authCache.set(project.name,remote,data.remote[remote]);
// }
// }
// }
if (data.hasOwnProperty('git')) {
if (data.git.hasOwnProperty('user')) {
var username;
if (!user) {
username = "_";
} else {
username = user.username;
}
globalProjectSettings.projects[this.name].git = globalProjectSettings.projects[this.name].git || {};
globalProjectSettings.projects[this.name].git.user = globalProjectSettings.projects[this.name].git.user || {};
globalProjectSettings.projects[this.name].git.user[username] = {
name: data.git.user.name,
email: data.git.user.email
}
this.git.user[username] = {
name: data.git.user.name,
email: data.git.user.email
}
saveSettings = true;
}
if (data.git.hasOwnProperty('remotes')) {
var remoteNames = Object.keys(data.git.remotes);
var remotesChanged = false;
var modifyRemotesPromise = when.resolve();
remoteNames.forEach(function(name) {
if (data.git.remotes[name].removed) {
remotesChanged = true;
modifyRemotesPromise = modifyRemotesPromise.then(function() { gitTools.removeRemote(project.path,name) });
} else {
if (data.git.remotes[name].url) {
remotesChanged = true;
modifyRemotesPromise = modifyRemotesPromise.then(function() { gitTools.addRemote(project.path,name,data.git.remotes[name])});
}
if (data.git.remotes[name].username && data.git.remotes[name].password) {
var url = data.git.remotes[name].url || project.remotes[name].fetch;
authCache.set(project.name,url,data.git.remotes[name]);
}
}
})
if (remotesChanged) {
modifyRemotesPromise = modifyRemotesPromise.then(function() {
return project.loadRemotes();
});
promises.push(modifyRemotesPromise);
} }
} }
} }
if (data.hasOwnProperty('files')) { if (data.hasOwnProperty('files')) {
this.package['node-red'] = this.package['node-red'] || { settings: {}}; this.package['node-red'] = this.package['node-red'] || { settings: {}};
if (data.files.hasOwnProperty('flow') && this.package['node-red'].settings.flowFile !== data.files.flow) { if (data.files.hasOwnProperty('flow') && this.package['node-red'].settings.flowFile !== data.files.flow) {
@ -223,8 +312,15 @@ Project.prototype.stageFile = function(file) {
Project.prototype.unstageFile = function(file) { Project.prototype.unstageFile = function(file) {
return gitTools.unstageFile(this.path,file); return gitTools.unstageFile(this.path,file);
} }
Project.prototype.commit = function(options) { Project.prototype.commit = function(user, options) {
return gitTools.commit(this.path,options.message); var username;
if (!user) {
username = "_";
} else {
username = user.username;
}
var gitUser = this.git.user[username];
return gitTools.commit(this.path,options.message,gitUser);
} }
Project.prototype.getFileDiff = function(file,type) { Project.prototype.getFileDiff = function(file,type) {
return gitTools.getFileDiff(this.path,file,type); return gitTools.getFileDiff(this.path,file,type);
@ -247,8 +343,17 @@ Project.prototype.status = function() {
var self = this; var self = this;
var fetchPromise; var fetchPromise;
if (this.remote) { if (this.remotes) {
fetchPromise = gitTools.fetch(this.path,authCache.get(this.name,'origin')); fetchPromise = gitTools.getRemoteBranch(self.path).then(function(remoteBranch) {
var allRemotes = Object.keys(self.remotes);
var match = "";
allRemotes.forEach(function(remote) {
if (remoteBranch.indexOf(remote) === 0 && match.length < remote.length) {
match = remote;
}
})
return self.fetch(match);
});
} else { } else {
fetchPromise = when.resolve(); fetchPromise = when.resolve();
} }
@ -267,6 +372,7 @@ Project.prototype.status = function() {
self.branches.remote = result.branches.remote; self.branches.remote = result.branches.remote;
if (fetchError) { if (fetchError) {
result.branches.remoteError = { result.branches.remoteError = {
remote: fetchError.remote,
code: fetchError.code code: fetchError.code
} }
} }
@ -283,17 +389,19 @@ Project.prototype.status = function() {
}; };
Project.prototype.push = function (remoteBranchName,setRemote) { Project.prototype.push = function (remoteBranchName,setRemote) {
return gitTools.push(this.path, remoteBranchName, setRemote, authCache.get(this.name,'origin')); var remote = this.parseRemoteBranch(remoteBranchName);
return gitTools.push(this.path, remote.remote || this.currentRemote,remote.branch, setRemote, authCache.get(this.name,this.remotes[this.currentRemote].fetch));
}; };
Project.prototype.pull = function (remoteBranchName,setRemote) { Project.prototype.pull = function (remoteBranchName,setRemote) {
var self = this; var self = this;
if (setRemote) { if (setRemote) {
return gitTools.setUpstream(this.path, remoteBranchName).then(function() { return gitTools.setUpstream(this.path, remoteBranchName).then(function() {
return gitTools.pull(self.path, null, authCache.get(self.name,'origin')); return gitTools.pull(self.path, null, null, authCache.get(self.name,this.remotes[this.currentRemote].fetch));
}) })
} else { } else {
return gitTools.pull(this.path, remoteBranchName, authCache.get(this.name,'origin')); var remote = this.parseRemoteBranch(remoteBranchName);
return gitTools.pull(this.path, remote.remote, remote.branch, authCache.get(this.name,this.remotes[this.currentRemote].fetch));
} }
}; };
@ -342,18 +450,41 @@ Project.prototype.abortMerge = function () {
return gitTools.abortMerge(this.path); return gitTools.abortMerge(this.path);
}; };
Project.prototype.getBranches = function (remote) { Project.prototype.getBranches = function (isRemote) {
var self = this; var self = this;
var fetchPromise; var fetchPromise;
if (remote) { if (isRemote) {
fetchPromise = gitTools.fetch(this.path,authCache.get(this.name,'origin')) fetchPromise = self.fetch();
} else { } else {
fetchPromise = when.resolve(); fetchPromise = when.resolve();
} }
return fetchPromise.then(function() { return fetchPromise.then(function() {
return gitTools.getBranches(self.path,remote); return gitTools.getBranches(self.path,isRemote);
}); });
}; };
Project.prototype.fetch = function(remoteName) {
var project = this;
if (remoteName) {
return gitTools.fetch(project.path,remoteName,authCache.get(project.name,project.remotes[remoteName].fetch)).catch(function(err) {
err.remote = remoteName;
throw err;
})
} else {
var remotes = Object.keys(this.remotes);
var promise = when.resolve();
remotes.forEach(function(remote) {
promise = promise.then(function() {
return gitTools.fetch(project.path,remote,authCache.get(project.name,project.remotes[remote].fetch))
}).catch(function(err) {
err.remote = remote;
throw err;
})
});
return promise;
}
}
Project.prototype.setBranch = function (branchName, isCreate) { Project.prototype.setBranch = function (branchName, isCreate) {
var self = this; var self = this;
return gitTools.checkoutBranch(this.path, branchName, isCreate).then(function() { return gitTools.checkoutBranch(this.path, branchName, isCreate).then(function() {
@ -402,9 +533,11 @@ Project.prototype.toJSON = function () {
flow: this.paths.flowFile, flow: this.paths.flowFile,
credentials: this.paths.credentialsFile credentials: this.paths.credentialsFile
}, },
git: {
remotes: this.remotes, remotes: this.remotes,
branches: this.branches branches: this.branches
} }
}
}; };
@ -438,7 +571,7 @@ function createProjectDirectory(project) {
return fs.ensureDir(projectPath); return fs.ensureDir(projectPath);
} }
function createDefaultProject(project) { function createDefaultProject(user, project) {
var projectPath = fspath.join(projectsDir,project.name); var projectPath = fspath.join(projectsDir,project.name);
// Create a basic skeleton of a project // Create a basic skeleton of a project
return gitTools.initRepo(projectPath).then(function() { return gitTools.initRepo(projectPath).then(function() {
@ -502,7 +635,7 @@ function checkProjectFiles(project) {
}); });
} }
function createProject(metadata) { function createProject(user, metadata) {
var project = metadata.name; var project = metadata.name;
return when.promise(function(resolve,reject) { return when.promise(function(resolve,reject) {
var projectPath = fspath.join(projectsDir,project); var projectPath = fspath.join(projectsDir,project);
@ -518,23 +651,20 @@ function createProject(metadata) {
if (metadata.hasOwnProperty('credentialSecret')) { if (metadata.hasOwnProperty('credentialSecret')) {
projects.projects[project].credentialSecret = metadata.credentialSecret; projects.projects[project].credentialSecret = metadata.credentialSecret;
} }
if (metadata.remote) {
projects.projects[project].remote = metadata.remote;
}
return settings.set('projects',projects); return settings.set('projects',projects);
}).then(function() { }).then(function() {
if (metadata.remote) { if (metadata.git && metadata.git.remotes && metadata.git.remotes.origin) {
var originRemote = metadata.git.remotes.origin;
var auth; var auth;
if (metadata.remote.hasOwnProperty("username") && metadata.remote.hasOwnProperty("password")) { if (originRemote.hasOwnProperty("username") && originRemote.hasOwnProperty("password")) {
authCache.set(project,'origin',{ // TODO: hardcoded remote name authCache.set(project,originRemote.url,{ // TODO: hardcoded remote name
username: metadata.remote.username, username: originRemote.username,
password: metadata.remote.password password: originRemote.password
} }
); );
auth = authCache.get(project,'origin'); auth = authCache.get(project,originRemote.url);
} }
return gitTools.clone(originRemote,auth,projectPath).then(function(result) {
return gitTools.clone(metadata.remote,auth,projectPath).then(function(result) {
// Check this is a valid project // Check this is a valid project
// If it is empty // If it is empty
// - if 'populate' flag is set, call populateProject // - if 'populate' flag is set, call populateProject
@ -554,7 +684,7 @@ function createProject(metadata) {
}); });
}) })
} else { } else {
createDefaultProject(metadata).then(function() { resolve(getProject(project))}).catch(reject); createDefaultProject(user, metadata).then(function() { resolve(getProject(project))}).catch(reject);
} }
}).catch(reject); }).catch(reject);
}) })

View File

@ -25,15 +25,13 @@ module.exports = {
delete authCache[project]; delete authCache[project];
}, },
set: function(project,remote,auth) { set: function(project,remote,auth) {
if (authCache.hasOwnProperty(project)) { console.log("AuthCache.set",remote,auth);
authCache[project] = authCache[project]||{};
authCache[project][remote] = auth; authCache[project][remote] = auth;
} else { // console.log(JSON.stringify(authCache,'',4));
authCache[project] = {
remote: auth
}
}
}, },
get: function(project,remote) { get: function(project,remote) {
console.log("AuthCache.get",remote,authCache[project]&&authCache[project][remote]);
if (authCache.hasOwnProperty(project)) { if (authCache.hasOwnProperty(project)) {
return authCache[project][remote]; return authCache[project][remote];
} }

View File

@ -37,7 +37,6 @@ function getListenPath() {
var ResponseServer = function(auth) { var ResponseServer = function(auth) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
server = net.createServer(function(connection) { server = net.createServer(function(connection) {
// Stop accepting new connections
connection.setEncoding('utf8'); connection.setEncoding('utf8');
var parts = []; var parts = [];
connection.on('data', function(data) { connection.on('data', function(data) {
@ -46,6 +45,7 @@ var ResponseServer = function(auth) {
parts.push(data.substring(0, m)); parts.push(data.substring(0, m));
data = data.substring(m); data = data.substring(m);
var line = parts.join(""); var line = parts.join("");
console.log("LINE",line);
parts = []; parts = [];
if (line==='Username') { if (line==='Username') {
connection.end(auth.username); connection.end(auth.username);

View File

@ -311,6 +311,15 @@ function getBranchStatus(cwd,remoteBranch) {
}) })
} }
function addRemote(cwd,name,options) {
var args = ["remote","add",name,options.url]
return runGitCommand(args,cwd);
}
function removeRemote(cwd,name) {
var args = ["remote","remove",name];
return runGitCommand(args,cwd);
}
module.exports = { module.exports = {
init: function(_settings,_runtime) { init: function(_settings,_runtime) {
log = _runtime.log log = _runtime.log
@ -322,12 +331,11 @@ module.exports = {
var args = ["branch","--set-upstream-to",remoteBranch]; var args = ["branch","--set-upstream-to",remoteBranch];
return runGitCommand(args,cwd); return runGitCommand(args,cwd);
}, },
pull: function(cwd,remoteBranch,auth) { pull: function(cwd,remote,branch,auth) {
var args = ["pull"]; var args = ["pull"];
var m = /^(.*?)\/(.*)$/.exec(remoteBranch); if (remote && branch) {
if (m) { args.push(remote);
args.push(m[1]); args.push(branch);
args.push(m[2])
} }
var promise; var promise;
if (auth) { if (auth) {
@ -348,17 +356,16 @@ module.exports = {
throw err; throw err;
}); });
}, },
push: function(cwd,remoteBranch,setUpstream, auth) { push: function(cwd,remote,branch,setUpstream, auth) {
var args = ["push"]; var args = ["push"];
var m = /^(.*?)\/(.*)$/.exec(remoteBranch); if (branch) {
if (m) {
if (setUpstream) { if (setUpstream) {
args.push("-u"); args.push("-u");
} }
args.push(m[1]); args.push(remote);
args.push("HEAD:"+m[2]); args.push("HEAD:"+branch);
} else { } else {
args.push("origin"); args.push(remote);
} }
args.push("--porcelain"); args.push("--porcelain");
var promise; var promise;
@ -419,9 +426,16 @@ module.exports = {
} }
return runGitCommand(args,cwd); return runGitCommand(args,cwd);
}, },
commit: function(cwd, message) { commit: function(cwd, message, gitUser) {
var args = ["commit","-m",message]; var args = ["commit","-m",message];
return runGitCommand(args,cwd); var env;
if (gitUser && gitUser['name'] && gitUser['email']) {
args.unshift('user.name="'+gitUser['name']+'"');
args.unshift('-c');
args.unshift('user.email="'+gitUser['email']+'"');
args.unshift('-c');
}
return runGitCommand(args,cwd,env);
}, },
getFileDiff(cwd,file,type) { getFileDiff(cwd,file,type) {
var args = ["diff"]; var args = ["diff"];
@ -433,8 +447,8 @@ module.exports = {
args.push(file); args.push(file);
return runGitCommand(args,cwd); return runGitCommand(args,cwd);
}, },
fetch: function(cwd,auth) { fetch: function(cwd,remote,auth) {
var args = ["fetch"]; var args = ["fetch",remote];
if (auth) { if (auth) {
return runGitCommandWithAuth(args,cwd,auth); return runGitCommandWithAuth(args,cwd,auth);
} else { } else {
@ -474,6 +488,9 @@ module.exports = {
return runGitCommand(['merge','--abort'],cwd); return runGitCommand(['merge','--abort'],cwd);
}, },
getRemotes: getRemotes, getRemotes: getRemotes,
getRemoteBranch: function(cwd) {
return runGitCommand(['rev-parse','--abbrev-ref','--symbolic-full-name','@{u}'],cwd)
},
getBranches: getBranches, getBranches: getBranches,
getBranchInfo: getBranchInfo, getBranchInfo: getBranchInfo,
checkoutBranch: function(cwd, branchName, isCreate) { checkoutBranch: function(cwd, branchName, isCreate) {
@ -484,5 +501,7 @@ module.exports = {
args.push(branchName); args.push(branchName);
return runGitCommand(args,cwd); return runGitCommand(args,cwd);
}, },
getBranchStatus: getBranchStatus getBranchStatus: getBranchStatus,
addRemote: addRemote,
removeRemote: removeRemote
} }

View File

@ -96,6 +96,11 @@ function init(_settings, _runtime) {
} }
} }
function getUserGitSettings(user) {
var userSettings = settings.getUserSettings(user)||{};
return userSettings.git;
}
function getBackupFilename(filename) { function getBackupFilename(filename) {
var ffName = fspath.basename(filename); var ffName = fspath.basename(filename);
var ffDir = fspath.dirname(filename); var ffDir = fspath.dirname(filename);
@ -113,10 +118,27 @@ function loadProject(name) {
}) })
} }
function getProject(name) { function listProjects(user) {
return Projects.list();
}
function getProject(user, name) {
checkActiveProject(name); checkActiveProject(name);
//return when.resolve(activeProject.info); //return when.resolve(activeProject.info);
return Projects.get(name); var username;
if (!user) {
username = "_";
} else {
username = user.username;
}
return Projects.get(name).then(function(project) {
var result = project.toJSON();
var projectSettings = settings.get("projects").projects;
if (projectSettings[name].git && projectSettings[name].git.user[username]) {
result.git.user = projectSettings[name].git.user[username];
}
return result;
});
} }
function checkActiveProject(project) { function checkActiveProject(project) {
@ -125,78 +147,78 @@ function checkActiveProject(project) {
throw new Error("Cannot operate on inactive project wanted:"+project+" current:"+(activeProject&&activeProject.name)); throw new Error("Cannot operate on inactive project wanted:"+project+" current:"+(activeProject&&activeProject.name));
} }
} }
function getFiles(project) { function getFiles(user, project) {
checkActiveProject(project); checkActiveProject(project);
return activeProject.getFiles(); return activeProject.getFiles();
} }
function stageFile(project,file) { function stageFile(user, project,file) {
checkActiveProject(project); checkActiveProject(project);
return activeProject.stageFile(file); return activeProject.stageFile(file);
} }
function unstageFile(project,file) { function unstageFile(user, project,file) {
checkActiveProject(project); checkActiveProject(project);
return activeProject.unstageFile(file); return activeProject.unstageFile(file);
} }
function commit(project,options) { function commit(user, project,options) {
checkActiveProject(project); checkActiveProject(project);
return activeProject.commit(options); return activeProject.commit(user, options);
} }
function getFileDiff(project,file,type) { function getFileDiff(user, project,file,type) {
checkActiveProject(project); checkActiveProject(project);
return activeProject.getFileDiff(file,type); return activeProject.getFileDiff(file,type);
} }
function getCommits(project,options) { function getCommits(user, project,options) {
checkActiveProject(project); checkActiveProject(project);
return activeProject.getCommits(options); return activeProject.getCommits(options);
} }
function getCommit(project,sha) { function getCommit(user, project,sha) {
checkActiveProject(project); checkActiveProject(project);
return activeProject.getCommit(sha); return activeProject.getCommit(sha);
} }
function getFile(project,filePath,sha) { function getFile(user, project,filePath,sha) {
checkActiveProject(project); checkActiveProject(project);
return activeProject.getFile(filePath,sha); return activeProject.getFile(filePath,sha);
} }
function push(project,remoteBranchName,setRemote) { function push(user, project,remoteBranchName,setRemote) {
checkActiveProject(project); checkActiveProject(project);
return activeProject.push(remoteBranchName,setRemote); return activeProject.push(remoteBranchName,setRemote);
} }
function pull(project,remoteBranchName,setRemote) { function pull(user, project,remoteBranchName,setRemote) {
checkActiveProject(project); checkActiveProject(project);
return activeProject.pull(remoteBranchName,setRemote).then(function() { return activeProject.pull(remoteBranchName,setRemote).then(function() {
return reloadActiveProject("pull"); return reloadActiveProject("pull");
}); });
} }
function getStatus(project) { function getStatus(user, project) {
checkActiveProject(project); checkActiveProject(project);
return activeProject.status(); return activeProject.status();
} }
function resolveMerge(project,file,resolution) { function resolveMerge(user, project,file,resolution) {
checkActiveProject(project); checkActiveProject(project);
return activeProject.resolveMerge(file,resolution); return activeProject.resolveMerge(file,resolution);
} }
function abortMerge(project) { function abortMerge(user, project) {
checkActiveProject(project); checkActiveProject(project);
return activeProject.abortMerge().then(function() { return activeProject.abortMerge().then(function() {
return reloadActiveProject("abort-merge") return reloadActiveProject("abort-merge")
}); });
} }
function getBranches(project,remote) { function getBranches(user, project,isRemote) {
checkActiveProject(project); checkActiveProject(project);
return activeProject.getBranches(remote); return activeProject.getBranches(isRemote);
} }
function setBranch(project,branchName,isCreate) { function setBranch(user, project,branchName,isCreate) {
checkActiveProject(project); checkActiveProject(project);
return activeProject.setBranch(branchName,isCreate).then(function() { return activeProject.setBranch(branchName,isCreate).then(function() {
return reloadActiveProject("change-branch"); return reloadActiveProject("change-branch");
}); });
} }
function getBranchStatus(project,branchName) { function getBranchStatus(user, project,branchName) {
checkActiveProject(project); checkActiveProject(project);
return activeProject.getBranchStatus(branchName); return activeProject.getBranchStatus(branchName);
} }
function getActiveProject() { function getActiveProject(user) {
return activeProject; return activeProject;
} }
@ -212,14 +234,15 @@ function reloadActiveProject(action) {
}); });
}); });
} }
function createProject(metadata) { function createProject(user, metadata) {
return Projects.create(metadata).then(function(p) { // var userSettings = getUserGitSettings(user);
return setActiveProject(p.name); return Projects.create(null,metadata).then(function(p) {
return setActiveProject(user, p.name);
}).then(function() { }).then(function() {
return getProject(metadata.name); return getProject(user, metadata.name);
}) })
} }
function setActiveProject(projectName) { function setActiveProject(user, projectName) {
return loadProject(projectName).then(function(project) { return loadProject(projectName).then(function(project) {
var globalProjectSettings = settings.get("projects"); var globalProjectSettings = settings.get("projects");
globalProjectSettings.activeProject = project.name; globalProjectSettings.activeProject = project.name;
@ -234,7 +257,7 @@ function setActiveProject(projectName) {
}) })
}); });
} }
function updateProject(project,data) { function updateProject(user, project, data) {
if (!activeProject || activeProject.name !== project) { if (!activeProject || activeProject.name !== project) {
// TODO standardise // TODO standardise
throw new Error("Cannot update inactive project"); throw new Error("Cannot update inactive project");
@ -243,7 +266,7 @@ function updateProject(project,data) {
var isReset = data.resetCredentialSecret; var isReset = data.resetCredentialSecret;
var wasInvalid = activeProject.credentialSecretInvalid; var wasInvalid = activeProject.credentialSecretInvalid;
return activeProject.update(data).then(function(result) { return activeProject.update(user,data).then(function(result) {
if (result.flowFilesChanged) { if (result.flowFilesChanged) {
flowsFullPath = activeProject.getFlowFile(); flowsFullPath = activeProject.getFlowFile();
@ -371,7 +394,7 @@ function saveCredentials(credentials) {
module.exports = { module.exports = {
init: init, init: init,
listProjects: Projects.list, listProjects: listProjects,
getActiveProject: getActiveProject, getActiveProject: getActiveProject,
setActiveProject: setActiveProject, setActiveProject: setActiveProject,
getProject: getProject, getProject: getProject,