Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #594 from tjwudi/diwu/feature/date-range-selector
Feature: date range selector support for charts
- Loading branch information
Showing
7 changed files
with
153 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
(function (window) { | ||
var module = angular.module('redash.visualization'); | ||
|
||
module.directive('dateRangeSelector', [function () { | ||
return { | ||
restrict: 'E', | ||
scope: { | ||
dateRange: "=" | ||
}, | ||
templateUrl: '/views/visualizations/date_range_selector.html', | ||
replace: true, | ||
controller: ['$scope', function ($scope) { | ||
$scope.dateRangeHuman = { | ||
min: null, | ||
max: null | ||
}; | ||
|
||
$scope.$watch('dateRange', function (dateRange, oldDateRange, scope) { | ||
scope.dateRangeHuman.min = dateRange.min.format('YYYY-MM-DD'); | ||
scope.dateRangeHuman.max = dateRange.max.format('YYYY-MM-DD'); | ||
}); | ||
|
||
$scope.$watch('dateRangeHuman', function (dateRangeHuman, oldDateRangeHuman, scope) { | ||
var newDateRangeMin = moment(dateRangeHuman.min); | ||
var newDateRangeMax = moment(dateRangeHuman.max); | ||
if (!newDateRangeMin || | ||
!newDateRangeMax || | ||
!newDateRangeMin.isValid() || | ||
!newDateRangeMax.isValid() || | ||
newDateRangeMin.isAfter(newDateRangeMax)) { | ||
// Prevent invalid date input | ||
// No need to show up a notification to user here, it will be too noisy. | ||
// Instead, simply preventing changes to the scope silently. | ||
scope.dateRangeHuman = oldDateRangeHuman; | ||
return; | ||
} | ||
scope.dateRange.min = newDateRangeMin; | ||
scope.dateRange.max = newDateRangeMax; | ||
}, true); | ||
}] | ||
} | ||
}]); | ||
})(window); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div> | ||
<section class="clearfix"> | ||
<date-range-selector ng-if="dateRangeEnabled" date-range='dateRange' class='pull-right'></date-range-selector> | ||
</section> | ||
<section> | ||
<chart options='chartOptions' series='chartSeries' class='graph'></chart> | ||
</section> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div> | ||
<span> | ||
From <input type="date" ng-model="dateRangeHuman.min"> | ||
</span> | ||
<span> | ||
To <input type="date" ng-model="dateRangeHuman.max"> | ||
</span> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters