Merge pull request #863 from getredash/fix/filters_datetime

Fix: properly show date/time in filters
This commit is contained in:
Arik Fraimovich 2016-02-28 11:06:02 +02:00
commit 3328de3462
3 changed files with 32 additions and 8 deletions

View File

@ -327,13 +327,15 @@
QueryResult.prototype.prepareFilters = function () {
var filters = [];
var filterTypes = ['filter', 'multi-filter', 'multiFilter'];
_.each(this.getColumnNames(), function (col) {
var type = col.split('::')[1] || col.split('__')[1];
_.each(this.getColumns(), function (col) {
var name = col.name;
var type = name.split('::')[1] || name.split('__')[1];
if (_.contains(filterTypes, type)) {
// filter found
var filter = {
name: col,
friendlyName: this.getColumnFriendlyName(col),
name: name,
friendlyName: this.getColumnFriendlyName(name),
column: col,
values: [],
multiple: (type=='multiFilter') || (type=='multi-filter')
}

View File

@ -107,6 +107,27 @@
};
};
var FilterValueFilter = function() {
return function(value, filter) {
if (_.isArray(value)) {
value = value[0];
}
// TODO: deduplicate code with table.js:
if (filter.column.type === 'date') {
if (value && moment.isMoment(value)) {
return value.format(clientConfig.dateFormat);
}
} else if (filter.column.type === 'datetime') {
if (value && moment.isMoment(value)) {
return value.format(clientConfig.dateTimeFormat);
}
}
return value;
};
};
var EditVisualizationForm = function (Events, Visualization, growl) {
return {
restrict: 'E',
@ -219,5 +240,6 @@
.directive('visualizationName', ['Visualization', VisualizationName])
.directive('embedCode', EmbedCode)
.directive('filters', Filters)
.filter('filterValue', FilterValueFilter)
.directive('editVisulatizationForm', ['Events', 'Visualization', 'growl', EditVisualizationForm]);
})();

View File

@ -1,16 +1,16 @@
<div class="well well-sm filters-container" ng-show="filters">
<div class="filter" ng-repeat="filter in filters">
<ui-select ng-model="filter.current" ng-if="!filter.multiple">
<ui-select-match placeholder="Select value for {{filter.friendlyName}}...">{{filter.friendlyName}}: {{$select.selected}}</ui-select-match>
<ui-select-match placeholder="Select value for {{filter.friendlyName}}...">{{filter.friendlyName}}: {{$select.selected | filterValue:filter}}</ui-select-match>
<ui-select-choices repeat="value in filter.values | filter: $select.search">
{{value}}
{{value | filterValue:filter }}
</ui-select-choices>
</ui-select>
<ui-select ng-model="filter.current" multiple ng-if="filter.multiple">
<ui-select-match placeholder="Select value for {{filter.friendlyName}}...">{{filter.friendlyName}}: {{$item}}</ui-select-match>
<ui-select-match placeholder="Select value for {{filter.friendlyName}}...">{{filter.friendlyName}}: {{$item | filterValue:filter}}</ui-select-match>
<ui-select-choices repeat="value in filter.values | filter: $select.search">
{{value}}
{{value | filterValue:filter }}
</ui-select-choices>
</ui-select>
</div>