Skip to content

Commit

Permalink
6.4.0 editorState fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PhaedrusTheGreek committed Aug 30, 2018
1 parent e4b62ff commit a5530a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
9 changes: 4 additions & 5 deletions public/options_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
<div class="form-group">
<label> Index Pattern </label>
<select name="indexPattern" class="form-control ng-pristine ng-untouched"
ng-model="vis.params.indexpattern" required
ng-model="editorState.params.indexpattern" required
ng-options="option.id as option.attributes.title for option in indexPatternOptions"></select>
</div>

<div class="form-group">
<label> Query DSL </label>
<div ui-ace="{ onLoad: aceLoaded, mode: 'json' }" ng-model="vis.params.querydsl"
<div ui-ace="{ onLoad: aceLoaded, mode: 'json' }" ng-model="editorState.params.querydsl"
class="template-editor form-control ng-pristine ng-untouched ng-valid ng-scope ace_editor ace-tm"/>
</div>

<div ng-if="options.allow_unsafe" class="form-group">
<label> Javascript </label>
<div ui-ace="{ onLoad: aceLoaded, mode: 'javascript' }" ng-model="vis.params.meta"
<div ui-ace="{ onLoad: aceLoaded, mode: 'javascript' }" ng-model="editorState.params.meta"
class="template-editor form-control ng-pristine ng-untouched ng-valid ng-scope ace_editor ace-tm"/>
</div>

<div class="form-group">
<label> Template </label>
<div ui-ace="{ onLoad: aceLoaded, mode: 'html' }" ng-model="vis.params.formula"
<div ui-ace="{ onLoad: aceLoaded, mode: 'html' }" ng-model="editorState.params.formula"
class="template-editor form-control ng-pristine ng-untouched ng-valid ng-scope ace_editor ace-tm"/>
</div>

Expand Down
19 changes: 16 additions & 3 deletions public/request_handler.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import chrome from 'ui/chrome';
import { dashboardContextProvider } from 'plugins/kibana/dashboard/dashboard_context'
import { timefilter } from 'ui/timefilter';

const Mustache = require('mustache');

export const createRequestHandler = function(Private, es, indexPatterns, $sanitize) {

const myRequestHandler = (vis, appState, uiState, searchSource) => {
const myRequestHandler = (vis, state) => {

var { appState, uiState, query, filters, timeRange, searchSource } = state;

/* As per https://github.com/elastic/kibana/issues/17722 dashboard_context will go away soon.
The proper way to read the dashboard context is to use `filters` and `query` from the above
object, however as of 6.4, these variables are coming up undefined */

const dashboardContext = Private(dashboardContextProvider);
const options = chrome.getInjected('transformVisOptions');

Expand All @@ -29,12 +34,20 @@ export const createRequestHandler = function(Private, es, indexPatterns, $saniti

if (indexPattern.timeFieldName) {
const timefilterdsl = {range: {}};
timefilterdsl.range[indexPattern.timeFieldName] = {gte: timefilter.time.from, lte: timefilter.time.to};
timefilterdsl.range[indexPattern.timeFieldName] = {gte: timeRange.from, lte: timeRange.to};
context.bool.must.push(timefilterdsl);
}

const body = JSON.parse(vis.params.querydsl.replace('"_DASHBOARD_CONTEXT_"', JSON.stringify(context)));

// Can be used for testing the above commented future change //
// console.log("context", JSON.stringify(context));
// console.log("searchSource", searchSource);
// console.log("state", state);
// console.log("query", query);
// console.log("filters", filters);
// console.log("body", body);

es.search({
index: indexPattern.title,
body: body
Expand Down

0 comments on commit a5530a5

Please sign in to comment.