From fa4258f75c19e8e2df71580703a401eefca127e8 Mon Sep 17 00:00:00 2001
From: Amir Nissim
Date: Tue, 11 Mar 2014 17:16:58 +0200
Subject: [PATCH] #121 fixes: * fork your own query * better redirect after
saving new query * UI fixes
---
rd_ui/app/scripts/controllers/query_view.js | 34 +++++++++------------
rd_ui/app/styles/redash.css | 2 +-
rd_ui/app/views/queryview.html | 9 +++---
3 files changed, 21 insertions(+), 24 deletions(-)
diff --git a/rd_ui/app/scripts/controllers/query_view.js b/rd_ui/app/scripts/controllers/query_view.js
index 85652679b..344a5301c 100644
--- a/rd_ui/app/scripts/controllers/query_view.js
+++ b/rd_ui/app/scripts/controllers/query_view.js
@@ -8,8 +8,10 @@
var route = $route.current;
$scope.dirty = undefined;
+ $scope.isNewQuery = false;
$scope.isOwner = false;
$scope.canEdit = false;
+ $scope.canFork = false;
$scope.isSourceVisible = route.locals.viewSource;
@@ -26,8 +28,14 @@
}
function updateSourceHref() {
- $scope.sourceHref = $scope.isSourceVisible ?
- $location.url().replace('source', '') : $location.path() + '/source#' + $location.hash();
+ if ($scope.query && $scope.query.id) {
+ $scope.sourceHref = $scope.isSourceVisible ?
+ $location.url().replace('source', '') : getQuerySourceUrl($scope.query.id);
+ }
+ };
+
+ function getQuerySourceUrl(queryId) {
+ return '/queries/' + queryId + '/source#' + $location.hash();
};
Mousetrap.bindGlobal("meta+s", function(e) {
@@ -54,8 +62,6 @@
}
});
- $scope.$parent.pageTitle = "Query Fiddle";
-
$scope.$watch(function() {
return $location.hash()
}, function(hash) {
@@ -89,25 +95,13 @@
$scope.dirty = false;
if (duplicate) {
- growl.addInfoMessage("Query duplicated.", {
- ttl: 2000
- });
+ growl.addSuccessMessage("Query forked");
} else {
- growl.addSuccessMessage("Query saved.", {
- ttl: 2000
- });
+ growl.addSuccessMessage("Query saved");
}
if (oldId != q.id) {
- if (oldId == undefined) {
- $location.path($location.path().replace('new', q.id)).replace();
- } else {
- // TODO: replace this with a safer method
- $location.path($location.path().replace(oldId, q.id)).replace();
-
- // Reset visualizations tab to table after duplicating a query:
- $location.hash(DEFAULT_TAB);
- }
+ $location.url(getQuerySourceUrl(q.id)).replace();
}
}, function(httpResponse) {
growl.addErrorMessage("Query could not be saved");
@@ -209,6 +203,7 @@
$scope.isOwner = currentUser.canEdit($scope.query);
$scope.canEdit = $scope.isSourceVisible && $scope.isOwner;
+ $scope.canFork = true;
} else {
// new query
@@ -220,6 +215,7 @@
});
$scope.lockButton(false);
$scope.isOwner = $scope.canEdit = true;
+ $scope.isNewQuery = true;
}
$scope.$watch('query.name', function() {
diff --git a/rd_ui/app/styles/redash.css b/rd_ui/app/styles/redash.css
index e022784fe..4dedc34ab 100644
--- a/rd_ui/app/styles/redash.css
+++ b/rd_ui/app/styles/redash.css
@@ -233,7 +233,7 @@ to add those CSS styles here. */
-webkit-transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
transition: border-color ease-in-out 0.15s, box-shadow ease-in-out 0.15s;
}
-textarea.rd-form-control {
+.rd-form-control {
width: 100%;
}
visualization-renderer > div {
diff --git a/rd_ui/app/views/queryview.html b/rd_ui/app/views/queryview.html
index 2aba539df..c6e98a9cc 100644
--- a/rd_ui/app/views/queryview.html
+++ b/rd_ui/app/views/queryview.html
@@ -13,7 +13,7 @@
-