Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1459834 - Don't stop navigation when a user has blocked confirm dialogs #1675

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ angular.extend(window.OPENSHIFT_CONSTANTS, {
// removes the option from the route creation form.
DISABLE_WILDCARD_ROUTES: true,

// true indicates that the web console should not show confirmation prompts
// when users navigate away from a page without saving.
DISABLE_CONFIRM_ON_EXIT: false,

// This blacklist hides certain kinds from the "Other Resources" page because they are unpersisted, disallowed for most end users, or not supported by openshift but exist in kubernetes
AVAILABLE_KINDS_BLACKLIST: [],

Expand Down
31 changes: 29 additions & 2 deletions app/scripts/directives/confirmOnExit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

// http://stackoverflow.com/questions/14852802/detect-unsaved-changes-and-alert-user-using-angularjs
angular.module("openshiftConsole")
.directive("confirmOnExit", function() {
.directive("confirmOnExit", function(Logger) {
return {
scope: {
dirty: '=',
message: '='
},
link: function($scope) {
// If the feature is disabled or the user has asked the browser to
// block dialogs, don't try to prompt.
if (_.get(window, 'OPENSHIFT_CONSTANTS.DISABLE_CONFIRM_ON_EXIT') ||
_.get(window, 'OPENSHIFT_CONSTANTS.CONFIRM_DIALOG_BLOCKED')) {
return;
}

var getMessage = function() {
return $scope.message || "You have unsaved changes. Leave this page anyway?";
};
Expand All @@ -27,7 +34,27 @@ angular.module("openshiftConsole")
return;
}

if(!confirm(getMessage())) {
var start = new Date().getTime();

// Use a native confirm dialog to block code execution since we're in
// the location change listener.
var okToExit = confirm(getMessage());
if (okToExit) {
return;
}

// Workaround "Prevent this page from creating additional dialogs"
//
// If the response took less than 50ms, assume the confirm dialog was
// blocked by the browser. There's no API to detect that the user
// has told the browser to block these dialogs, and the user can't
// navigate away otherwise.
var end = new Date().getTime();
if ((end - start) < 50) {
// Remember that the user is blocking dialogs. This is a per session settings.
_.set(window, 'OPENSHIFT_CONSTANTS.CONFIRM_DIALOG_BLOCKED', true);
Logger.warn("Confirm on exit prompt appears to have been blocked by the browser.");
} else {
event.preventDefault();
}
});
Expand Down
33 changes: 21 additions & 12 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ DEFAULT_HPA_CPU_TARGET_PERCENT:80,
DISABLE_OVERVIEW_METRICS:!1,
DISABLE_CUSTOM_METRICS:!1,
DISABLE_WILDCARD_ROUTES:!0,
DISABLE_CONFIRM_ON_EXIT:!1,
AVAILABLE_KINDS_BLACKLIST:[],
ENABLE_TECH_PREVIEW_FEATURE:{
service_catalog_landing_page:!1,
Expand Down Expand Up @@ -13299,28 +13300,36 @@ e.findReferenceValueForEntries(b.entries, b.valueFromSelectorOptions);
} ]
};
} ]);
}(), angular.module("openshiftConsole").directive("confirmOnExit", function() {
}(), angular.module("openshiftConsole").directive("confirmOnExit", [ "Logger", function(a) {
return {
scope:{
dirty:"=",
message:"="
},
link:function(a) {
var b = function() {
return a.message || "You have unsaved changes. Leave this page anyway?";
}, c = function() {
if (a.dirty) return b();
link:function(b) {
if (!_.get(window, "OPENSHIFT_CONSTANTS.DISABLE_CONFIRM_ON_EXIT") && !_.get(window, "OPENSHIFT_CONSTANTS.CONFIRM_DIALOG_BLOCKED")) {
var c = function() {
return b.message || "You have unsaved changes. Leave this page anyway?";
}, d = function() {
if (b.dirty) return c();
};
$(window).on("beforeunload", c);
var d = a.$on("$locationChangeStart", function(c) {
a.dirty && (confirm(b()) || c.preventDefault());
$(window).on("beforeunload", d);
var e = b.$on("$locationChangeStart", function(d) {
if (b.dirty) {
var e = new Date().getTime(), f = confirm(c());
if (!f) {
var g = new Date().getTime();
g - e < 50 ? (_.set(window, "OPENSHIFT_CONSTANTS.CONFIRM_DIALOG_BLOCKED", !0), a.warn("Confirm on exit prompt appears to have been blocked by the browser.")) :d.preventDefault();
}
}
});
a.$on("$destroy", function() {
$(window).off("beforeunload", c), d && d();
b.$on("$destroy", function() {
$(window).off("beforeunload", d), e && e();
});
}
}
};
}), angular.module("openshiftConsole").filter("duration", function() {
} ]), angular.module("openshiftConsole").filter("duration", function() {
return function(a, b, c, d) {
function e(a, b, d) {
if (0 !== a) return 1 === a ? void (c ? h.push(b) :h.push("1 " + b)) :void h.push(a + " " + d);
Expand Down
37 changes: 22 additions & 15 deletions dist/scripts/vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -60542,9 +60542,8 @@ return a;
var e = {
group:"servicecatalog.k8s.io",
resource:"bindings"
}, f = function(b) {
var c = a("generateName");
return {
}, f = function(b, c) {
var e = a("generateName"), f = e(_.trunc(b, d.maxlength - 6) + "-"), g = {
kind:"Binding",
apiVersion:"servicecatalog.k8s.io/v1alpha1",
metadata:{
Expand All @@ -60554,14 +60553,20 @@ spec:{
instanceRef:{
name:b
},
secretName:c(_.trunc(b, d.maxlength - 6) + "-")
secretName:f
}
};
}, h = _.get(c, "spec.selector");
return h && (h.matchLabels || h.matchExpressions || (h = {
matchLabels:h
}), g.spec.alphaPodPresetTemplate = {
name:f,
selector:h
}), g;
};
return {
bindingResource:e,
bindService:function(a, b, d) {
var g = f(b);
var g = f(b, d);
return c.create(e, null, g, a);
},
isServiceBindable:function(a, b) {
Expand Down Expand Up @@ -64564,7 +64569,9 @@ repository:a.ctrl.repository,
namespace:a.ctrl.selectedProject.metadata.name,
imageStreamTag:b
});
a.createAPIObjects(c), a.ctrl.serviceToBind && a.bindService();
a.createAPIObjects(c), a.ctrl.serviceToBind && a.bindService(e.find(c, {
kind:"DeploymentConfig"
}));
}, function(b) {
a.ctrl.error = b;
});
Expand Down Expand Up @@ -64592,18 +64599,18 @@ a.failure.length ? b.ctrl.error = a :b.ctrl.success = !0;
}, function(a) {
b.ctrl.error = a;
});
}, a.prototype.bindService = function() {
var a = this;
}, a.prototype.bindService = function(a) {
var b = this;
this.ctrl.bindInProgress = !0, this.ctrl.bindError = !1;
var b = {
var c = {
namespace:e.get(this.ctrl.selectedProject, "metadata.name")
};
this.BindingService.bindService(b, this.ctrl.serviceToBind, this.ctrl.name).then(function(c) {
a.ctrl.binding = c, a.ctrl.bindInProgress = !1, a.ctrl.bindComplete = !0, a.ctrl.bindError = null, a.DataService.watchObject(a.BindingService.bindingResource, e.get(a.ctrl.binding, "metadata.name"), b, function(b) {
a.ctrl.binding = b;
this.BindingService.bindService(c, this.ctrl.serviceToBind, a).then(function(a) {
b.ctrl.binding = a, b.ctrl.bindInProgress = !1, b.ctrl.bindComplete = !0, b.ctrl.bindError = null, b.DataService.watchObject(b.BindingService.bindingResource, e.get(b.ctrl.binding, "metadata.name"), c, function(a) {
b.ctrl.binding = a;
});
}, function(b) {
a.ctrl.bindInProgress = !1, a.ctrl.bindComplete = !0, a.ctrl.bindError = b;
}, function(a) {
b.ctrl.bindInProgress = !1, b.ctrl.bindComplete = !0, b.ctrl.bindError = a;
});
}, a.prototype.getServiceClasses = function() {
var a = this, b = {
Expand Down