Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discover interval #3290

Merged
merged 9 commits into from
Apr 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 51 additions & 23 deletions src/kibana/plugins/discover/controllers/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ define(function (require) {
location: 'Discover'
});

$scope.intervalOptions = Private(require('components/agg_types/buckets/_interval_options'));
$scope.showInterval = false;

$scope.intervalEnabled = function (interval) {
return interval.val !== 'custom';
};

$scope.toggleInterval = function () {
$scope.showInterval = !$scope.showInterval;
};

// config panel templates
$scope.configTemplate = new ConfigTemplate({
load: require('text!plugins/discover/partials/load_search.html'),
Expand Down Expand Up @@ -200,6 +211,23 @@ define(function (require) {
timefilter.enabled = !!timefield;
});

$scope.$watch('state.interval', function (interval, oldInterval) {
if (interval !== oldInterval && interval === 'auto') {
$scope.showInterval = false;
}
$scope.fetch();
});

$scope.$watch('vis.aggs', function (aggs) {
var buckets = $scope.vis.aggs.bySchemaGroup.buckets;

if (buckets && buckets.length === 1) {
$scope.intervalName = 'by ' + buckets[0].buckets.getInterval().description;
} else {
$scope.intervalName = 'auto';
}
});

$scope.$watchMulti([
'rows',
'fetchStatus'
Expand Down Expand Up @@ -526,17 +554,31 @@ define(function (require) {
if (!$scope.opts.timefield) return Promise.resolve();
if (loadingVis) return loadingVis;

var visStateAggs = [
{
type: 'count',
schema: 'metric'
},
{
type: 'date_histogram',
schema: 'segment',
params: {
field: $scope.opts.timefield,
interval: $state.interval,
min_doc_count: 0
}
}
];

// we have a vis, just modify the aggs
if ($scope.vis) {
var visState = $scope.vis.getState();
visState.aggs = visStateAggs;

// we shouldn't have a vis, delete it
if (!$scope.opts.timefield && $scope.vis) {
$scope.vis.destroy();
$scope.searchSource.set('aggs', undefined);
delete $scope.vis;
$scope.vis.setState(visState);
return Promise.resolve($scope.vis);
}

// we shouldn't have one, or already do, return whatever we already have
if (!$scope.opts.timefield || $scope.vis) return Promise.resolve($scope.vis);

// TODO: a legit way to update the index pattern
$scope.vis = new Vis($scope.indexPattern, {
type: 'histogram',
Expand All @@ -552,21 +594,7 @@ define(function (require) {
},
brush: brushEvent
},
aggs: [
{
type: 'count',
schema: 'metric'
},
{
type: 'date_histogram',
schema: 'segment',
params: {
field: $scope.opts.timefield,
interval: 'auto',
min_doc_count: 0
}
}
]
aggs: visStateAggs
});

$scope.searchSource.aggs(function () {
Expand Down
36 changes: 25 additions & 11 deletions src/kibana/plugins/discover/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<span bindonce bo-bind="opts.savedSearch.title"></span>
<i aria-label="Reload saved query" tooltip="Reload saved query" ng-click="resetQuery();" class="fa fa-undo small"></i>
</span>

<strong class="discover-info-hits">{{(hits || 0) | number:0}}</strong>
<ng-pluralize count="hits" when="{'1':'hit', 'other':'hits'}"></ng-pluralize>
</div>
Expand Down Expand Up @@ -148,17 +149,30 @@ <h2>Searching</h2>
<!-- result -->
<div class="results" ng-show="resultState === 'ready'">
<div class="discover-timechart" ng-if="opts.timefield">
<center class="small">
<span tooltip="To change the time, click the clock icon in the navigation bar">{{timeRange.from | moment}} - {{timeRange.to | moment}}</span>
<!-- TODO: Currently no way to apply this setting to the visualization -->
<!-- <select
class="form-control"
ng-model="state.interval"
ng-options="interval as interval for interval in intervalOptions"
ng-change="setupVisualization();fetch()"
>
</select> -->
</center>
<header>
<center class="small">
<span tooltip="To change the time, click the clock icon in the navigation bar">{{timeRange.from | moment}} - {{timeRange.to | moment}}</span>

&mdash;

<span class="results-interval" ng-hide="showInterval">
<a
ng-click="toggleInterval()">
{{ intervalName }}
</a>
</span>

<span ng-show="showInterval" class="results-interval form-inline">
<select
class="form-control"
ng-model="state.interval"
ng-options="interval.val as interval.display for interval in intervalOptions | filter: intervalEnabled"
>
</select>
</span>
</center>

</header>

<div ng-show="fetchStatus.hitCount === 0" class="discover-overlay vis-overlay">
<div class="spinner large"> </div>
Expand Down
16 changes: 16 additions & 0 deletions src/kibana/plugins/discover/styles/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
display: block;
position: relative;

header {
min-height: @input-height-base + 8px;
padding: 4px 0;
}

visualize {
height: 200px;
max-height: 600px;
Expand Down Expand Up @@ -248,4 +253,15 @@ disc-field-chooser {
margin: -20px 0 10px 0;
text-align: center;
}

&-interval {
a {
text-decoration: underline;;
}

select {
display: inline-block;
width: auto;
}
}
}