Confirm actions that would overwrite dirty workspace

This commit is contained in:
Nick O'Leary
2017-11-24 23:12:35 +00:00
parent e5ff25b92d
commit 14c48253f6
10 changed files with 244 additions and 123 deletions

View File

@@ -59,13 +59,22 @@
// handled below
return;
}
if (notificationId === "project-change") {
if (notificationId === "project-update") {
RED.nodes.clear();
RED.history.clear();
RED.view.redraw(true);
RED.projects.refresh(function() {
loadFlows(function() {
RED.notify("NLS: Project changed to "+msg.project);
console.log(msg);
var project = RED.projects.getActiveProject();
var message = {
"change-branch":"Change to local branch '"+project.branches.local+"'",
"abort-merge":"Git merge aborted",
"loaded":"Project '"+msg.project+"' loaded",
"updated":"Project '"+msg.project+"' updated",
"pull":"Project '"+msg.project+"' reloaded"
}[msg.action]
RED.notify(message);
RED.sidebar.info.refresh()
});
});

View File

@@ -224,24 +224,29 @@ RED.deploy = (function() {
if (currentRev === null || deployInflight || currentRev === msg.revision) {
return;
}
var message = $('<div>'+RED._('deploy.confirm.backgroundUpdate')+
'<br><br><div class="ui-dialog-buttonset">'+
'<button>'+RED._('deploy.confirm.button.ignore')+'</button>'+
'<button class="primary">'+RED._('deploy.confirm.button.review')+'</button>'+
'</div></div>');
$(message.find('button')[0]).click(function(evt) {
evt.preventDefault();
activeNotifyMessage.close();
activeNotifyMessage = null;
})
$(message.find('button')[1]).click(function(evt) {
evt.preventDefault();
activeNotifyMessage.close();
var nns = RED.nodes.createCompleteNodeSet();
resolveConflict(nns,false);
activeNotifyMessage = null;
})
activeNotifyMessage = RED.notify(message,null,true);
var message = $('<div>').text(RED._('deploy.confirm.backgroundUpdate'));
activeNotifyMessage = RED.notify(message,{
fixed: true,
buttons: [
{
text: RED._('deploy.confirm.button.ignore'),
click: function() {
activeNotifyMessage.close();
activeNotifyMessage = null;
}
},
{
text: RED._('deploy.confirm.button.review'),
class: "primary",
click: function() {
activeNotifyMessage.close();
var nns = RED.nodes.createCompleteNodeSet();
resolveConflict(nns,false);
activeNotifyMessage = null;
}
}
]
});
}
});
}

View File

@@ -18,7 +18,7 @@ RED.notify = (function() {
var c = 0;
return function(msg,type,fixed,timeout) {
var options = {};
if (typeof type === 'object') {
if (type !== null && typeof type === 'object') {
options = type;
fixed = options.fixed;
timeout = options.timeout;
@@ -56,6 +56,17 @@ RED.notify = (function() {
} else {
$(n).append(msg);
}
if (options.buttons) {
var buttonSet = $('<div style="margin-top: 20px;" class="ui-dialog-buttonset"></div>').appendTo(n)
options.buttons.forEach(function(buttonDef) {
var b = $('<button>').html(buttonDef.text).click(buttonDef.click).appendTo(buttonSet);
if (buttonDef.class) {
b.addClass(buttonDef.class);
}
})
}
$("#notifications").append(n);
$(n).slideDown(300);
n.close = (function() {

View File

@@ -315,6 +315,7 @@ RED.projects = (function() {
if (projectName === "" || projectName === autoInsertedName) {
autoInsertedName = m[1];
projectNameInput.val(autoInsertedName);
projectNameInput.change();
}
}
validateForm();
@@ -411,6 +412,7 @@ RED.projects = (function() {
sendRequest({
url: "projects",
type: "POST",
requireCleanWorkspace: true,
handleAuthFail: false,
responses: {
200: function(data) {
@@ -423,6 +425,9 @@ RED.projects = (function() {
'git_error': function(error) {
console.log("git error",error);
},
'git_connection_failed': function(error) {
projectRepoInput.addClass("input-error");
},
'git_auth_failed': function(error) {
projectRepoUserInput.addClass("input-error");
projectRepoPasswordInput.addClass("input-error");
@@ -539,6 +544,7 @@ RED.projects = (function() {
sendRequest({
url: "projects/"+name,
type: "PUT",
requireCleanWorkspace: true,
responses: {
200: function(data) {
done(null,data);
@@ -627,6 +633,48 @@ RED.projects = (function() {
function sendRequest(options,body) {
// dialogBody.hide();
console.log(options.url);
if (options.requireCleanWorkspace && RED.nodes.dirty()) {
var message = 'You have undeployed changes that will be lost. Do you want to continue?';
var alwaysCallback;
var cleanNotification = RED.notify(message,{
type:"info",
fixed: true,
modal: true,
buttons: [
{
//id: "node-dialog-delete",
//class: 'leftButton',
text: RED._("common.label.cancel"),
click: function() {
cleanNotification.close();
if (options.cancel) {
options.cancel();
}
if (alwaysCallback) {
alwaysCallback();
}
}
},{
text: 'Continue',
click: function() {
cleanNotification.close();
delete options.requireCleanWorkspace;
sendRequest(options,body).always(function() {
if (alwaysCallback) {
alwaysCallback();
}
})
}
}
]
});
return {
always: function(done) { alwaysCallback = done; }
}
}
var start = Date.now();
// TODO: this is specific to the dialog-based requests
$(".projects-dialog-spinner").show();
@@ -656,61 +704,62 @@ RED.projects = (function() {
'<div class="form-row"><div style="margin-left: 20px;">'+url+'</div></div>'+
'<div class="form-row"><label for="projects-user-auth-username">Username</label><input id="projects-user-auth-username" type="text"></input></div>'+
'<div class="form-row"><label for=projects-user-auth-password">Password</label><input id="projects-user-auth-password" type="password"></input></div>'+
'<hr>'+
'<div class="ui-dialog-buttonset">'+
'<button>'+RED._("common.label.cancel")+'</button>'+
'<button><i class="fa fa-refresh"></i> Retry</button>'+
'</div>'+
'</div>');
$(message.find('button')[0]).click(function(evt) {
evt.preventDefault();
notification.close();
})
$(message.find('button')[1]).click(function(evt) {
evt.preventDefault();
var username = $('#projects-user-auth-username').val();
var password = $('#projects-user-auth-password').val();
body = body || {};
var done = function(err) {
if (err) {
console.log("Failed to update auth");
console.log(err);
} else {
sendRequest(options,body);
notification.close();
}
}
sendRequest({
url: "projects/"+activeProject.name,
type: "PUT",
responses: {
0: function(error) {
done(error,null);
},
200: function(data) {
done(null,data);
},
400: {
'unexpected_error': function(error) {
done(error,null);
}
},
}
},{
remote: {
origin: {
username: username,
password: password
}
}
});
})
var notification = RED.notify(message,{
type:"error",
fixed: true,
modal: true
modal: true,
buttons: [
{
//id: "node-dialog-delete",
//class: 'leftButton',
text: RED._("common.label.cancel"),
click: function() {
notification.close();
}
},{
text: $('<span><i class="fa fa-refresh"></i> Retry</span>'),
click: function() {
var username = $('#projects-user-auth-username').val();
var password = $('#projects-user-auth-password').val();
body = body || {};
var done = function(err) {
if (err) {
console.log("Failed to update auth");
console.log(err);
} else {
sendRequest(options,body);
notification.close();
}
}
sendRequest({
url: "projects/"+activeProject.name,
type: "PUT",
responses: {
0: function(error) {
done(error,null);
},
200: function(data) {
done(null,data);
},
400: {
'unexpected_error': function(error) {
done(error,null);
}
},
}
},{
remote: {
origin: {
username: username,
password: password
}
}
});
}
}
]
});
return;
} else if (responses[xhr.responseJSON.error]) {
@@ -888,7 +937,6 @@ RED.projects = (function() {
$.getJSON("projects",function(data) {
if (data.active) {
$.getJSON("projects/"+data.active, function(project) {
console.log(project.branches);
activeProject = project;
// updateProjectSummary();
// updateProjectDescription();

View File

@@ -582,9 +582,14 @@ RED.sidebar.versionControl = (function() {
}
var spinner = utils.addSpinnerOverlay(localBranchBox);
var activeProject = RED.projects.getActiveProject();
RED.deploy.setDeployInflight(true);
utils.sendRequest({
url: "projects/"+activeProject.name+"/branches",
type: "POST",
requireCleanWorkspace: true,
cancel: function() {
spinner.remove();
},
responses: {
0: function(error) {
spinner.remove();
@@ -606,7 +611,10 @@ RED.sidebar.versionControl = (function() {
}
},
}
},body);
},body).always(function(){
console.log("switch deployinflight to false")
RED.deploy.setDeployInflight(false);
});
}
});
@@ -679,6 +687,9 @@ RED.sidebar.versionControl = (function() {
refresh(true);
},
400: {
'git_connection_failed': function(error) {
RED.notify(error.message);
},
'unexpected_error': function(error) {
console.log(error);
// done(error,null);