This commit is contained in:
Amir Nissim 2014-03-10 14:24:16 +02:00
parent d4287558f9
commit 54c5a7dcb3
3 changed files with 29 additions and 32 deletions

View File

@ -17,10 +17,16 @@ angular.module('redash', [
]).config(['$routeProvider', '$locationProvider', '$compileProvider', 'growlProvider',
function($routeProvider, $locationProvider, $compileProvider, growlProvider) {
function getQuery(Query, $route) {
return Query.get({
function getQuery(Query, $q, $route) {
var defer = $q.defer();
Query.get({
'id': $route.current.params.queryId
}, function(query) {
defer.resolve(query);
});
return defer.promise;
}
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|http|data):/);
@ -41,15 +47,14 @@ angular.module('redash', [
controller: 'QueryFiddleCtrl',
reloadOnSearch: false
});
// TODO
// we should have 2 controllers: queryViewCtrl and queryEditCtrl
$routeProvider.when('/queries/:queryId', {
templateUrl: '/views/queryview.html',
controller: 'QueryViewCtrl',
reloadOnSearch: false,
resolve: {
'query': getQuery,
'viewSource': function isViewSource() {
return false;
}
'query': getQuery
}
});
$routeProvider.when('/queries/:queryId/fiddle', {

View File

@ -10,8 +10,7 @@
$scope.dirty = undefined;
$scope.canEdit = false;
$scope.isEditing = false;
$scope.isSourceVisible = false;
$scope.isSourceVisible = route.locals.viewSource;
$scope.queryExecuting = false;
$scope.queryResultStatus = null;
@ -56,14 +55,6 @@
$scope.selectedTab = hash || DEFAULT_TAB;
});
$scope.toggleEdit = function (state) {
$scope.isEditing = $scope.isSourceVisible =
(state !== undefined) ? state : !$scope.isEditing;
};
$scope.toggleSource = function() {
$scope.isSourceVisible = !$scope.isSourceVisible;
};
$scope.lockButton = function(lock) {
$scope.queryExecuting = lock;
};
@ -203,16 +194,18 @@
}
});
// view or source pages: controller is instantiated with a query
if (route.locals.query) {
$scope.query = route.locals.query;
pristineHash = $scope.query.getHash();
$scope.dirty = false;
$scope.queryResult = $scope.query.getQueryResult();
var isViewSource = route.locals.viewSource === true;
$scope.canEdit = currentUser.canEdit($scope.query) && isViewSource;
$scope.toggleEdit(isViewSource);
$scope.canEdit =
$scope.isSourceVisible && currentUser.canEdit($scope.query);
} else {
// new query
$scope.query = new Query({
query: "",
name: "New Query",
@ -232,6 +225,11 @@
$scope.dirty = (newHash !== pristineHash);
});
$scope.toggleSource = function() {
var url = $location.url();
$location.path($scope.isSourceVisible ? url.replace('src', '') : url + '/src');
};
$scope.executeQuery = function() {
$scope.queryResult = $scope.query.getQueryResult(0);
$scope.lockButton(true);

View File

@ -3,20 +3,14 @@
<div class="row">
<div class="col-lg-12">
<h2>
<edit-in-place editable="isEditing" ignore-blanks='true' value="query.name"></edit-in-place>
<edit-in-place editable="canEdit" ignore-blanks='true' value="query.name"></edit-in-place>
<span class="pull-right">
<button class="btn btn-default" ng-click="toggleSource()" ng-class="{active: isSourceVisible}">View Source</button>
<!-- <button class="btn btn-default rd-hidden-xs" ng-show="canEdit" ng-click="toggleEdit()">
<span class="glyphicon glyphicon-edit"></span>
<span ng-show="isEditing"> Done</span>
<span ng-show="!isEditing"> Edit</span>
</button>
-->
<button ng-click="toggleSource()" class="btn btn-default" ng-class="{active: isSourceVisible}">Source</button>
</span>
</h2>
<em>
<edit-in-place editable="isEditing" editor="textarea" placeholder="No description" ignore-blanks='false' value="query.description"></edit-in-place>
<edit-in-place editable="canEdit" editor="textarea" placeholder="No description" ignore-blanks='false' value="query.description"></edit-in-place>
</em>
@ -55,7 +49,7 @@
<span class="glyphicon glyphicon-indent-left"></span> Format SQL
</button>
<span class="pull-right">
<button class="btn btn-success btn-xs" ng-show="canEdit" ng-click="saveQuery() && toggleEdit(false)">
<button class="btn btn-success btn-xs" ng-show="canEdit" ng-click="saveQuery()">
<span class="glyphicon glyphicon-floppy-disk"> </span> Save<span ng-show="dirty">&#42;</span>
</button>
<button class="btn btn-default btn-xs rd-hidden-xs" ng-show="!canEdit" ng-click="duplicateQuery()">
@ -134,7 +128,7 @@
<rd-tab tab-id="{{vis.id}}" name="{{vis.name}}" ng-hide="vis.type=='TABLE'" ng-repeat="vis in query.visualizations">
<span class="remove" ng-click="deleteVisualization($event, vis)" ng-show="canEdit"> &times;</span>
</rd-tab>
<rd-tab tab-id="add" name="&plus; New" removeable="true" ng-show="canEdit && isEditing"></rd-tab>
<rd-tab tab-id="add" name="&plus; New" removeable="true" ng-show="canEdit"></rd-tab>
</ul>
</div>
</div>
@ -145,12 +139,12 @@
<div ng-show="selectedTab == vis.id" ng-repeat="vis in query.visualizations">
<visualization-renderer visualization="vis" query-result="queryResult"></visualization-renderer>
<edit-visulatization-form visualization="vis" query="query" query-result="queryResult" ng-show="isEditing"></edit-visulatization-form>
<edit-visulatization-form visualization="vis" query="query" query-result="queryResult" ng-show="canEdit"></edit-visulatization-form>
</div>
<div ng-show="selectedTab == 'add'">
<visualization-renderer visualization="newVisualization" query-result="queryResult"></visualization-renderer>
<edit-visulatization-form visualization="newVisualization" query="query" ng-show="isEditing"></edit-visulatization-form>
<edit-visulatization-form visualization="newVisualization" query="query" ng-show="canEdit"></edit-visulatization-form>
</div>
</div>
</div>