',{style:"margin-top:10px"}).hide().appendTo(credentialStateLabel);
var credentialSetLabel = $('
Set the encryption key:
').hide().appendTo(credentialFormRows);
var credentialChangeLabel = $('
Change the encryption key:
').hide().appendTo(credentialFormRows);
var credentialResetLabel = $('
Reset the encryption key:
').hide().appendTo(credentialFormRows);
var credentialSecretExistingRow = $('
').appendTo(credentialFormRows);
$('
').text('Current key').appendTo(credentialSecretExistingRow);
var credentialSecretExistingInput = $('
').appendTo(credentialSecretExistingRow)
.on("change keyup paste",function() {
if (popover) {
popover.close();
popover = null;
}
checkFiles();
});
var credentialSecretNewRow = $('
').appendTo(credentialFormRows);
$('
').text('New key').appendTo(credentialSecretNewRow);
var credentialSecretNewInput = $('
').appendTo(credentialSecretNewRow).on("change keyup paste",checkFiles);
var credentialResetWarning = $('
This will delete all existing credentials
').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);
$('
Cancel ')
.appendTo(formButtons)
.click(function(evt) {
evt.preventDefault();
hideEditForm();
});
var saveButton = $('
Save ')
.appendTo(formButtons)
.click(function(evt) {
evt.preventDefault();
var spinner = utils.addSpinnerOverlay(filesContainer);
var done = function(err) {
spinner.remove();
if (err) {
console.log(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);
},
'unexpected_error': function(error) {
console.log(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);
}
},
}
},payload).always(function() {
RED.deploy.setDeployInflight(false);
});
});
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);
}
checkFiles();
updateForm();
}
function createLocalBranchListSection(activeProject,pane) {
var localBranchContainer = $('
').appendTo(pane);
$('
').text("Branches").appendTo(localBranchContainer);
var row = $('
').appendTo(localBranchContainer);
var branchList = $('
').appendTo(row).editableList({
addButton: false,
scrollOnAdd: false,
addItem: function(row,index,entry) {
var container = $('').appendTo(row);
$('
').appendTo(container);
$('
').text(entry.name).appendTo(container);
// if (entry.commit) {
// $('').text(entry.commit.sha).appendTo(container);
// }
if (entry.remote) {
$('').text(entry.remote||"").appendTo(container);
if (entry.status.ahead+entry.status.behind > 0) {
$(''+
' '+entry.status.ahead+' '+
' '+entry.status.behind+' '+
' ').appendTo(container);
}
}
var tools = $('').appendTo(container);
if (entry.current) {
tools.text('current');
} else {
$('delete ')
.appendTo(tools)
.click(function(e) {
e.preventDefault();
var spinner = utils.addSpinnerOverlay(row).addClass('projects-dialog-spinner-contain');
var notification = RED.notify("Are you sure you want to delete the local branch '"+entry.name+"'? This cannot be undone.", {
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("The local branch '"+entry.name+"' has unmerged changes that will be lost. Are you sure you want to delete it?", {
type: "warning",
modal: true,
fixed: true,
buttons: [
{
text: RED._("common.label.cancel"),
click: function() {
spinner.remove();
notification.close();
}
},{
text: 'Delete unmerged branch',
click: function() {
options.url += "?force=true";
notification.close();
utils.sendRequest(options);
}
}
]
});
},
'unexpected_error': function(error) {
console.log(error);
spinner.remove();
}
},
}
}
utils.sendRequest(options);
}
}
]
})
})
}
}
});
$.getJSON("projects/"+activeProject.name+"/branches",function(result) {
if (result.branches) {
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);
})
}
})
}
function createRemoteRepositorySection(activeProject,pane) {
$(' ').text("Version Control").appendTo(pane);
createLocalBranchListSection(activeProject,pane);
var repoContainer = $('
').appendTo(pane);
var title = $(' ').text("Git remotes").appendTo(repoContainer);
var editRepoButton = $('edit ')
.appendTo(title)
.click(function(evt) {
editRepoButton.hide();
formButtons.show();
$('.projects-dialog-remote-list-entry-delete').show();
remoteListAddButton.show();
});
row = $('
').appendTo(repoContainer);
var remotesList = $('').appendTo(row);
remotesList.editableList({
addButton: 'add remote repository',
height: 'auto',
addItem: function(outer,index,entry) {
var header = $('').appendTo(outer);
entry.header = $('').text(entry.name||"Add new remote").appendTo(header);
var body = $('').appendTo(outer);
entry.body = body;
if (entry.name) {
entry.removeButton = $('
remove ')
.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 = $('
').appendTo(body);
$('
').text('URL').appendTo(row);
$('