Skip to content

Commit

Permalink
Merge pull request getredash#47 from EverythingMe/fed-issue1
Browse files Browse the repository at this point in the history
FED issue #1 [r=arikfr]
  • Loading branch information
arikfr committed Dec 31, 2013
2 parents 9794f12 + 6c48017 commit e746805
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 18 deletions.
67 changes: 53 additions & 14 deletions rd_ui/app/scripts/app.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,58 @@
angular.module('redash', ['redash.directives', 'redash.admin_controllers', 'redash.controllers', 'redash.filters', 'redash.services',
'redash.renderers',
'ui.codemirror', 'highchart', 'angular-growl', 'angularMoment', 'ui.bootstrap', 'smartTable.table', 'ngResource']).
config(['$routeProvider', '$locationProvider', '$compileProvider', function ($routeProvider, $locationProvider, $compileProvider) {
angular.module('redash', [
'redash.directives',
'redash.admin_controllers',
'redash.controllers',
'redash.filters',
'redash.services',
'redash.renderers',
'ui.codemirror',
'highchart',
'angular-growl',
'angularMoment',
'ui.bootstrap',
'smartTable.table',
'ngResource'
]).config(['$routeProvider', '$locationProvider', '$compileProvider', 'growlProvider',
function($routeProvider, $locationProvider, $compileProvider, growlProvider) {

$compileProvider.urlSanitizationWhitelist(/^\s*(https?|http|data):/);

$locationProvider.html5Mode(true);
$routeProvider.when('/dashboard/:dashboardSlug', {templateUrl: '/views/dashboard.html', controller: 'DashboardCtrl'});
$routeProvider.when('/queries', {templateUrl: '/views/queries.html', controller: 'QueriesCtrl', reloadOnSearch: false});
$routeProvider.when('/queries/new', {templateUrl: '/views/queryfiddle.html', controller: 'QueryFiddleCtrl', reloadOnSearch: false});
$routeProvider.when('/queries/:queryId', {templateUrl: '/views/queryfiddle.html', controller: 'QueryFiddleCtrl', reloadOnSearch: false});
$routeProvider.when('/admin/status', {templateUrl: '/views/admin_status.html', controller: 'AdminStatusCtrl'});
$routeProvider.when('/', {templateUrl: '/views/index.html', controller: 'IndexCtrl'});
$routeProvider.otherwise({redirectTo: '/'});
growlProvider.globalTimeToLive(2000);

Highcharts.setOptions({colors: ["#4572A7", "#AA4643", "#89A54E", "#80699B", "#3D96AE", "#DB843D", "#92A8CD", "#A47D7C", "#B5CA92"]});
}]);
$routeProvider.when('/dashboard/:dashboardSlug', {
templateUrl: '/views/dashboard.html',
controller: 'DashboardCtrl'
});
$routeProvider.when('/queries', {
templateUrl: '/views/queries.html',
controller: 'QueriesCtrl',
reloadOnSearch: false
});
$routeProvider.when('/queries/new', {
templateUrl: '/views/queryfiddle.html',
controller: 'QueryFiddleCtrl',
reloadOnSearch: false
});
$routeProvider.when('/queries/:queryId', {
templateUrl: '/views/queryfiddle.html',
controller: 'QueryFiddleCtrl',
reloadOnSearch: false
});
$routeProvider.when('/admin/status', {
templateUrl: '/views/admin_status.html',
controller: 'AdminStatusCtrl'
});
$routeProvider.when('/', {
templateUrl: '/views/index.html',
controller: 'IndexCtrl'
});
$routeProvider.otherwise({
redirectTo: '/'
});

Highcharts.setOptions({
colors: ["#4572A7", "#AA4643", "#89A54E", "#80699B", "#3D96AE",
"#DB843D", "#92A8CD", "#A47D7C", "#B5CA92"]
});
}
]);
33 changes: 30 additions & 3 deletions rd_ui/app/scripts/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,23 @@
$scope.updateTime = '';
}

var QueryFiddleCtrl = function ($scope, $routeParams, $http, $location, growl, notifications, Query) {
var QueryFiddleCtrl = function ($scope, $window, $routeParams, $http, $location, growl, notifications, Query) {
var leavingPageText = "You will lose your changes if you leave";
var pristineQuery = null;

$window.onbeforeunload = function(){
if ($scope.queryChanged) {
return leavingPageText;
}
}

$scope.$on('$locationChangeStart', function(event, next, current) {
if($scope.queryChanged &&
!confirm(leavingPageText + "\n\nAre you sure you want to leave this page?")) {
event.preventDefault();
}
});

$scope.$parent.pageTitle = "Query Fiddle";

$scope.tabs = [{'key': 'table', 'name': 'Table'}, {'key': 'chart', 'name': 'Chart'},
Expand All @@ -54,6 +70,9 @@
}
delete $scope.query.latest_query_data;
$scope.query.$save(function (q) {
pristineQuery = q.query;
$scope.queryChanged = false;

if (duplicate) {
growl.addInfoMessage("Query duplicated.", {ttl: 2000});
} else{
Expand All @@ -68,6 +87,8 @@
$location.path($location.path().replace(oldId, q.id)).replace();
}
}
}, function(httpResponse) {
growl.addErrorMessage("Query could not be saved");
});
};

Expand Down Expand Up @@ -142,7 +163,8 @@
});

if ($routeParams.queryId != undefined) {
$scope.query = Query.get({id: $routeParams.queryId}, function() {
$scope.query = Query.get({id: $routeParams.queryId}, function(q) {
pristineQuery = q.query;
$scope.queryResult = $scope.query.getQueryResult();
});
} else {
Expand All @@ -153,6 +175,11 @@
$scope.$watch('query.name', function() {
$scope.$parent.pageTitle = $scope.query.name;
});
$scope.$watch('query.query', function(q) {
if (q) {
$scope.queryChanged = (q != pristineQuery);
}
});

$scope.executeQuery = function() {
$scope.queryResult = $scope.query.getQueryResult(0);
Expand Down Expand Up @@ -320,7 +347,7 @@
.controller('DashboardCtrl', ['$scope', '$routeParams', '$http', 'Dashboard', DashboardCtrl])
.controller('WidgetCtrl', ['$scope', '$http', 'Query', WidgetCtrl])
.controller('QueriesCtrl', ['$scope', '$http', '$location', '$filter', 'Query', QueriesCtrl])
.controller('QueryFiddleCtrl', ['$scope', '$routeParams', '$http', '$location', 'growl', 'notifications', 'Query', QueryFiddleCtrl])
.controller('QueryFiddleCtrl', ['$scope', '$window', '$routeParams', '$http', '$location', 'growl', 'notifications', 'Query', QueryFiddleCtrl])
.controller('IndexCtrl', ['$scope', 'Dashboard', IndexCtrl])
.controller('MainCtrl', ['$scope', 'Dashboard', 'notifications', MainCtrl]);
})();
1 change: 1 addition & 0 deletions rd_ui/app/styles/redash.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ a.navbar-brand {
right: 10px;
float: right;
width: 250px;
z-index: 10000;
}

.growl-item.ng-enter,
Expand Down
4 changes: 3 additions & 1 deletion rd_ui/app/views/queryfiddle.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ <h3 class="panel-title">

<div class="btn-group pull-right">
<button type="button" class="btn btn-default" ng-click="duplicateQuery()">Duplicate</button>
<button type="button" class="btn btn-default" ng-disabled="currentUser.name != query.user" ng-click="saveQuery()">Save</button>
<button type="button" class="btn btn-default" ng-disabled="currentUser.name != query.user" ng-click="saveQuery()">Save
<span ng-show="queryChanged">&#42;</span>
</button>
<button type="button" class="btn btn-primary" ng-disabled="queryExecuting" ng-click="executeQuery()">Execute</button>
</div>
</div>
Expand Down

0 comments on commit e746805

Please sign in to comment.