From 0ddf112b0f55c12b77072fbbeb7e3e6761ba6019 Mon Sep 17 00:00:00 2001 From: Allen Short Date: Wed, 20 Dec 2017 07:08:03 +0000 Subject: [PATCH 1/2] Hard overwrite on conflict for query owners (re #283) --- client/app/pages/queries/view.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/client/app/pages/queries/view.js b/client/app/pages/queries/view.js index b3cfc1b972..9cad62128b 100644 --- a/client/app/pages/queries/view.js +++ b/client/app/pages/queries/view.js @@ -206,6 +206,10 @@ function QueryViewCtrl( customOptions, ); + if (options.force) { + delete request.version; + } + return Query.save( request, (updatedQuery) => { @@ -214,10 +218,16 @@ function QueryViewCtrl( }, (error) => { if (error.status === 409) { + // entirely unpleasant, but there's no good toastr->angular + // communications channel + window._redash_overwriteQuery = () => $scope.$apply(() => { + options.force = true; + $scope.saveQuery(options, data); + }); toastr.error( 'It seems like the query has been modified by another user. ' + - 'Please copy/backup your changes and reload this page.', - { autoDismiss: false }, + ($scope.isQueryOwner ? 'Overwrite anyway' : 'Please copy/backup your changes and reload this page.'), + { autoDismiss: false, allowHtml: true }, ); } else { toastr.error(options.errorMessage); From 5079ca21c2dd9827c3b1cb4537a21462d874f38d Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Wed, 28 Feb 2018 23:55:53 +0100 Subject: [PATCH 2/2] Use AlertDialog instead of custom global function. --- client/app/pages/queries/view.js | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/client/app/pages/queries/view.js b/client/app/pages/queries/view.js index 9cad62128b..c2fae4a227 100644 --- a/client/app/pages/queries/view.js +++ b/client/app/pages/queries/view.js @@ -210,6 +210,11 @@ function QueryViewCtrl( delete request.version; } + function overwrite() { + options.force = true; + $scope.saveQuery(options, data); + } + return Query.save( request, (updatedQuery) => { @@ -218,17 +223,20 @@ function QueryViewCtrl( }, (error) => { if (error.status === 409) { - // entirely unpleasant, but there's no good toastr->angular - // communications channel - window._redash_overwriteQuery = () => $scope.$apply(() => { - options.force = true; - $scope.saveQuery(options, data); - }); - toastr.error( - 'It seems like the query has been modified by another user. ' + - ($scope.isQueryOwner ? 'Overwrite anyway' : 'Please copy/backup your changes and reload this page.'), - { autoDismiss: false, allowHtml: true }, - ); + const errorMessage = 'It seems like the query has been modified by another user.'; + + if ($scope.isQueryOwner) { + const title = 'Overwrite Query'; + const message = errorMessage + '
Are you sure you want to overwrite the query with your version?'; + const confirm = { class: 'btn-warning', title: 'Overwrite' }; + + AlertDialog.open(title, message, confirm).then(overwrite); + } else { + toastr.error( + errorMessage + ' Please copy/backup your changes and reload this page.', + { autoDismiss: false }, + ); + } } else { toastr.error(options.errorMessage); }