',{style:"margin-top:10px"}).hide().appendTo(credentialStateLabel);
var credentialSetLabel = $('
' + RED._("sidebar.project.projectSettings.setTheEncryptionKey") + '
').hide().appendTo(credentialFormRows);
var credentialChangeLabel = $('
' + RED._("sidebar.project.projectSettings.changeTheEncryptionKey") + '
').hide().appendTo(credentialFormRows);
var credentialResetLabel = $('
' + RED._("sidebar.project.projectSettings.resetTheEncryptionKey") + '
').hide().appendTo(credentialFormRows);
var credentialSecretExistingRow = $('
').appendTo(credentialFormRows);
$('
').text(RED._("sidebar.project.projectSettings.currentKey")).appendTo(credentialSecretExistingRow);
var credentialSecretExistingInput = $('
').appendTo(credentialSecretExistingRow)
.on("change keyup paste",function() {
if (popover) {
popover.close();
popover = null;
}
checkFiles();
});
var credentialSecretNewRow = $('
').appendTo(credentialFormRows);
$('
').text(RED._("sidebar.project.projectSettings.newKey")).appendTo(credentialSecretNewRow);
var credentialSecretNewInput = $('
').appendTo(credentialSecretNewRow).on("change keyup paste",checkFiles);
var credentialResetWarning = $('
' + RED._("sidebar.project.projectSettings.credentialsAlert") + '
').hide().appendTo(credentialFormRows);
var hideEditForm = function() {
editFilesButton.show();
formButtons.hide();
flowFileLabelText.show();
flowFileInput.hide();
flowFileInputSearch.hide();
credFileLabel.show();
credFileInput.hide();
// credentialStateLabel.parent().show();
credentialStateLabel.removeClass("uneditable-input");
credentialStateLabel.css('height','');
flowFileInputSearch.removeClass('selected');
flowFileLabel.find('.project-file-listing-container').remove();
flowFileLabel.css('height','');
flowFileLabel.css('color','');
$(".user-settings-row-credentials").hide();
credentialFormRows.hide();
credentialSecretButtons.hide();
credentialSecretResetButton.removeClass("selected");
credentialSecretEditButton.removeClass("selected");
}
var formButtons = $('
').hide().appendTo(filesContainer);
$('
' + RED._("common.label.cancel") + ' ')
.appendTo(formButtons)
.click(function(evt) {
evt.preventDefault();
hideEditForm();
});
var saveButton = $('
' + RED._("common.label.save") + ' ')
.appendTo(formButtons)
.click(function(evt) {
evt.preventDefault();
var spinner = utils.addSpinnerOverlay(filesContainer);
var done = function(err) {
spinner.remove();
if (err) {
utils.reportUnexpectedError(err);
return;
}
flowFileLabelText.text(flowFileInput.val());
credFileLabel.text(credFileInput.text());
hideEditForm();
}
var payload = {
files: {
flow: flowFileInput.val(),
credentials: credFileInput.text()
}
}
if (credentialSecretResetButton.hasClass('selected')) {
payload.resetCredentialSecret = true;
}
if (credentialSecretResetButton.hasClass('selected') || credentialSecretEditButton.hasClass('selected')) {
payload.credentialSecret = credentialSecretNewInput.val();
if (credentialSecretExistingInput.is(":visible")) {
payload.currentCredentialSecret = credentialSecretExistingInput.val();
}
}
// 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 = data;
RED.sidebar.versionControl.refresh(true);
updateForm();
done();
},
400: {
'credentials_load_failed': function(error) {
done(error);
},
'missing_current_credential_key': function(error) {
credentialSecretExistingInput.addClass("input-error");
popover = RED.popover.create({
target: credentialSecretExistingInput,
direction: 'right',
size: 'small',
content: "Incorrect key",
autoClose: 3000
}).open();
done(error);
},
'*': function(error) {
done(error);
}
},
}
},payload).always(function() {
setTimeout(function() {
RED.deploy.setDeployInflight(false);
},500);
});
});
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(RED._("sidebar.project.projectSettings.invalidEncryptionKey"));
} 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(RED._("sidebar.project.projectSettings.encryptionEnabled"));
} 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(RED._("sidebar.project.projectSettings.encryptionDisabled"));
}
credentialSecretResetButton.toggleClass('disabled',!activeProject.settings.credentialSecretInvalid && !activeProject.settings.credentialsEncrypted);
credentialSecretResetButton.prop('disabled',!activeProject.settings.credentialSecretInvalid && !activeProject.settings.credentialsEncrypted);
}
checkFiles();
updateForm();
}
function createLocalBranchListSection(activeProject,pane) {
var localBranchContainer = $('
').appendTo(pane);
$('
').text(RED._("sidebar.project.projectSettings.branches")).appendTo(localBranchContainer);
var row = $('
').appendTo(localBranchContainer);
var branchList = $('
').appendTo(row).editableList({
height: 'auto',
addButton: false,
scrollOnAdd: false,
addItem: function(row,index,entry) {
var container = $('').appendTo(row);
if (entry.empty) {
container.addClass('red-ui-search-empty');
container.text(RED._("sidebar.project.projectSettings.noBranches"));
return;
}
if (entry.current) {
container.addClass("current");
}
$('
').appendTo(container);
var content = $('
').appendTo(container);
var topRow = $('').appendTo(content);
$('
').text(entry.name).appendTo(topRow);
if (entry.commit) {
$('').text(entry.commit.sha).appendTo(topRow);
}
if (entry.remote) {
var bottomRow = $('').appendTo(content);
$('
').text(entry.remote||"").appendTo(bottomRow);
if (entry.status.ahead+entry.status.behind > 0) {
$(''+
' '+entry.status.ahead+' '+
' '+entry.status.behind+' '+
' ').appendTo(bottomRow);
}
}
if (!entry.current) {
var tools = $('').appendTo(container);
$(' ')
.appendTo(tools)
.click(function(e) {
e.preventDefault();
var spinner = utils.addSpinnerOverlay(row).addClass('projects-dialog-spinner-contain');
var notification = RED.notify(RED._("sidebar.project.projectSettings.deleteConfirm", { name: entry.name }), {
type: "warning",
modal: true,
fixed: true,
buttons: [
{
text: RED._("common.label.cancel"),
click: function() {
spinner.remove();
notification.close();
}
},{
text: 'Delete branch',
click: function() {
notification.close();
var url = "projects/"+activeProject.name+"/branches/"+entry.name;
var options = {
url: url,
type: "DELETE",
responses: {
200: function(data) {
row.fadeOut(200,function() {
branchList.editableList('removeItem',entry);
spinner.remove();
});
},
400: {
'git_delete_branch_unmerged': function(error) {
notification = RED.notify(RED._("sidebar.project.projectSettings.unmergedConfirm", { name: entry.name }), {
type: "warning",
modal: true,
fixed: true,
buttons: [
{
text: RED._("common.label.cancel"),
click: function() {
spinner.remove();
notification.close();
}
},{
text: RED._("sidebar.project.projectSettings.deleteUnmergedBranch"),
click: function() {
options.url += "?force=true";
notification.close();
utils.sendRequest(options);
}
}
]
});
},
'*': function(error) {
utils.reportUnexpectedError(error);
spinner.remove();
}
},
}
}
utils.sendRequest(options);
}
}
]
})
})
}
}
});
$.getJSON("projects/"+activeProject.name+"/branches",function(result) {
if (result.branches) {
if (result.branches.length > 0) {
result.branches.sort(function(A,B) {
if (A.current) { return -1 }
if (B.current) { return 1 }
return A.name.localeCompare(B.name);
});
result.branches.forEach(function(branch) {
branchList.editableList('addItem',branch);
})
} else {
branchList.editableList('addItem',{empty:true});
}
}
})
}
function createRemoteRepositorySection(activeProject,pane) {
$(' ').text(RED._("sidebar.project.projectSettings.versionControl")).appendTo(pane);
createLocalBranchListSection(activeProject,pane);
var repoContainer = $('
').appendTo(pane);
var title = $(' ').text(RED._("sidebar.project.projectSettings.gitRemotes")).appendTo(repoContainer);
var editRepoButton = $('' + RED._("sidebar.project.projectSettings.addRemote") + ' ')
.appendTo(title)
.click(function(evt) {
editRepoButton.attr('disabled',true);
addRemoteDialog.slideDown(200, function() {
addRemoteDialog[0].scrollIntoView();
if (isEmpty) {
remoteNameInput.val('origin');
remoteURLInput.focus();
} else {
remoteNameInput.focus();
}
validateForm();
});
});
var emptyItem = { empty: true };
var isEmpty = true;
var row = $('
').appendTo(repoContainer);
var addRemoteDialog = $('
').hide().appendTo(row);
row = $('
').appendTo(repoContainer);
var remotesList = $('').appendTo(row);
remotesList.editableList({
addButton: false,
height: 'auto',
addItem: function(row,index,entry) {
var container = $('').appendTo(row);
if (entry.empty) {
container.addClass('red-ui-search-empty');
container.text(RED._("sidebar.project.projectSettings.noRemotes"));
return;
} else {
$('
').appendTo(container);
var content = $('
').appendTo(container);
$('').text(entry.name).appendTo(content);
if (entry.urls.fetch === entry.urls.push) {
$('
').text(entry.urls.fetch).appendTo(content);
} else {
$('
').text("fetch: "+entry.urls.fetch).appendTo(content);
$('
').text("push: "+entry.urls.push).appendTo(content);
}
var tools = $('').appendTo(container);
$(' ')
.appendTo(tools)
.click(function(e) {
e.preventDefault();
var spinner = utils.addSpinnerOverlay(row).addClass('projects-dialog-spinner-contain');
var notification = RED.notify(RED._("sidebar.project.projectSettings.deleteRemoteConfrim", { name: entry.name }), {
type: "warning",
modal: true,
fixed: true,
buttons: [
{
text: RED._("common.label.cancel"),
click: function() {
spinner.remove();
notification.close();
}
},{
text: RED._("sidebar.project.projectSettings.deleteRemote"),
click: function() {
notification.close();
if (activeProject.git.branches.remote && activeProject.git.branches.remote.indexOf(entry.name+"/") === 0) {
delete activeProject.git.branches.remote;
}
if (activeProject.git.branches.remoteAlt && activeProject.git.branches.remoteAlt.indexOf(entry.name+"/") === 0) {
delete activeProject.git.branches.remoteAlt;
}
var url = "projects/"+activeProject.name+"/remotes/"+entry.name;
var options = {
url: url,
type: "DELETE",
responses: {
200: function(data) {
row.fadeOut(200,function() {
remotesList.editableList('removeItem',entry);
setTimeout(spinner.remove, 100);
if (data.remotes.length === 0) {
delete activeProject.git.remotes;
isEmpty = true;
remotesList.editableList('addItem',emptyItem);
} else {
activeProject.git.remotes = {};
data.remotes.forEach(function(remote) {
var name = remote.name;
delete remote.name;
activeProject.git.remotes[name] = remote;
});
}
delete activeProject.git.branches.remoteAlt;
RED.sidebar.versionControl.refresh();
});
},
400: {
'*': function(error) {
utils.reportUnexpectedError(error);
spinner.remove();
}
},
}
}
utils.sendRequest(options);
}
}
]
})
});
}
}
});
var validateForm = function() {
var validName = /^[a-zA-Z0-9\-_]+$/.test(remoteNameInput.val());
var repo = remoteURLInput.val();
// var validRepo = /^(?:file|git|ssh|https?|[\d\w\.\-_]+@[\w\.]+):(?:\/\/)?[\w\.@:\/~_-]+(?:\.git)?(?:\/?|\#[\d\w\.\-_]+?)$/.test(remoteURLInput.val());
var validRepo = repo.length > 0 && !/\s/.test(repo);
if (/^https?:\/\/[^/]+@/i.test(repo)) {
remoteURLLabel.text(RED._("sidebar.project.projectSettings.urlRule2"));
validRepo = false;
} else {
remoteURLLabel.text(RED._("sidebar.project.projectSettings.urlRule"));
}
saveButton.attr('disabled',(!validName || !validRepo))
remoteNameInput.toggleClass('input-error',remoteNameInputChanged&&!validName);
remoteURLInput.toggleClass('input-error',remoteURLInputChanged&&!validRepo);
if (popover) {
popover.close();
popover = null;
}
};
var popover;
var remoteNameInputChanged = false;
var remoteURLInputChanged = false;
$('