Skip to content

Commit

Permalink
getredash#121: /src url
Browse files Browse the repository at this point in the history
  • Loading branch information
amirnissim committed Mar 11, 2014
1 parent d428755 commit 54c5a7d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
17 changes: 11 additions & 6 deletions rd_ui/app/scripts/app.js
Expand Up @@ -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):/);
Expand All @@ -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', {
Expand Down
24 changes: 11 additions & 13 deletions rd_ui/app/scripts/controllers/query_view.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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",
Expand All @@ -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);
Expand Down
20 changes: 7 additions & 13 deletions rd_ui/app/views/queryview.html
Expand Up @@ -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>


Expand Down Expand Up @@ -55,7 +49,7 @@ <h2>
<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()">
Expand Down Expand Up @@ -134,7 +128,7 @@ <h2>
<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>
Expand All @@ -145,12 +139,12 @@ <h2>

<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>
Expand Down

0 comments on commit 54c5a7d

Please sign in to comment.