mirror of
https://github.com/getredash/redash.git
synced 2025-12-23 11:23:00 -05:00
Auto-refresh button for dashboards.
This commit is contained in:
@@ -1,8 +1,37 @@
|
|||||||
(function () {
|
(function () {
|
||||||
var DashboardCtrl = function ($scope, $routeParams, $http, Dashboard) {
|
var DashboardCtrl = function ($scope, $routeParams, $http, $timeout, Dashboard) {
|
||||||
|
$scope.refreshEnabled = false;
|
||||||
|
$scope.refreshRate = 60;
|
||||||
|
|
||||||
|
var refreshDashboard = function() {
|
||||||
$scope.dashboard = Dashboard.get({slug: $routeParams.dashboardSlug}, function(dashboard) {
|
$scope.dashboard = Dashboard.get({slug: $routeParams.dashboardSlug}, function(dashboard) {
|
||||||
$scope.$parent.pageTitle = dashboard.name;
|
$scope.$parent.pageTitle = dashboard.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
autoRefresh();
|
||||||
|
};
|
||||||
|
|
||||||
|
var autoRefresh = function() {
|
||||||
|
if ($scope.refreshEnabled) {
|
||||||
|
$timeout(refreshDashboard, $scope.refreshRate);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.triggerRefresh = function(){
|
||||||
|
$scope.refreshEnabled = !$scope.refreshEnabled;
|
||||||
|
|
||||||
|
if ($scope.refreshEnabled) {
|
||||||
|
var refreshRate = _.min(_.flatten($scope.dashboard.widgets), function(widget) {
|
||||||
|
return widget.visualization.query.ttl;
|
||||||
|
}).visualization.query.ttl;
|
||||||
|
|
||||||
|
$scope.refreshRate = _.max([120, refreshRate * 2])*1000;
|
||||||
|
|
||||||
|
autoRefresh();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
refreshDashboard();
|
||||||
};
|
};
|
||||||
|
|
||||||
var WidgetCtrl = function ($scope, $http, $location, Query) {
|
var WidgetCtrl = function ($scope, $http, $location, Query) {
|
||||||
@@ -390,7 +419,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
angular.module('redash.controllers', [])
|
angular.module('redash.controllers', [])
|
||||||
.controller('DashboardCtrl', ['$scope', '$routeParams', '$http', 'Dashboard', DashboardCtrl])
|
.controller('DashboardCtrl', ['$scope', '$routeParams', '$http', '$timeout', 'Dashboard', DashboardCtrl])
|
||||||
.controller('WidgetCtrl', ['$scope', '$http', '$location', 'Query', WidgetCtrl])
|
.controller('WidgetCtrl', ['$scope', '$http', '$location', 'Query', WidgetCtrl])
|
||||||
.controller('QueriesCtrl', ['$scope', '$http', '$location', '$filter', 'Query', QueriesCtrl])
|
.controller('QueriesCtrl', ['$scope', '$http', '$location', '$filter', 'Query', QueriesCtrl])
|
||||||
.controller('QueryFiddleCtrl', ['$scope', '$window', '$location', '$routeParams', '$http', '$location', 'growl', 'notifications', 'Query', 'Visualization', QueryFiddleCtrl])
|
.controller('QueryFiddleCtrl', ['$scope', '$window', '$location', '$routeParams', '$http', '$location', 'growl', 'notifications', 'Query', 'Visualization', QueryFiddleCtrl])
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<h2 id="dashboard_title">
|
<h2 id="dashboard_title">
|
||||||
{{dashboard.name}}
|
{{dashboard.name}}
|
||||||
|
|
||||||
|
<button type="button" class="btn btn-default btn-xs" ng-class="{active: refreshEnabled}" tooltip="Enable/Disable Auto Refresh" ng-click="triggerRefresh()"><span class="glyphicon glyphicon-refresh"></span></button>
|
||||||
<span ng-show="dashboard.canEdit()">
|
<span ng-show="dashboard.canEdit()">
|
||||||
<button type="button" class="btn btn-default btn-xs" data-toggle="modal" href="#edit_dashboard_dialog" tooltip="Edit Dashboard (Name/Layout)"><span
|
<button type="button" class="btn btn-default btn-xs" data-toggle="modal" href="#edit_dashboard_dialog" tooltip="Edit Dashboard (Name/Layout)"><span
|
||||||
class="glyphicon glyphicon-cog"></span></button>
|
class="glyphicon glyphicon-cog"></span></button>
|
||||||
|
|||||||
Reference in New Issue
Block a user