-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rashid Khan
committed
Jul 31, 2014
1 parent
af9800b
commit 52e873c
Showing
11 changed files
with
173 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
.DS_Store | ||
node_modules | ||
src/bower_components | ||
**/styles/*.css | ||
**/*.css | ||
trash | ||
build | ||
target |
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
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,112 @@ | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
var $ = require('jquery'); | ||
|
||
require('css!components/query_input/query_input.css'); | ||
|
||
require('modules') | ||
.get('kibana') | ||
.directive('queryInput', function (es, $compile, timefilter, configFile) { | ||
return { | ||
restrict: 'A', | ||
require: 'ngModel', | ||
scope: { | ||
'ngModel': '=', | ||
'queryInput': '=?', | ||
}, | ||
link: function ($scope, elem, attr, ngModel) { | ||
|
||
// track request so we can abort it if needed | ||
var request = {}; | ||
|
||
var errorElem = $('<i class="fa fa-ban input-query-error"></i>').hide(); | ||
|
||
var init = function () { | ||
elem.after(errorElem); | ||
validater($scope.ngModel); | ||
}; | ||
|
||
var validater = function (query) { | ||
var index, type; | ||
|
||
var error = function (resp) { | ||
ngModel.$setValidity('queryInput', false); | ||
|
||
errorElem.attr('tooltip', resp.explanations && resp.explanations[0] ? | ||
resp.explanations[0].error : undefined); | ||
|
||
// Compile is needed for the tooltip | ||
$compile(errorElem)($scope); | ||
errorElem.show(); | ||
|
||
return undefined; | ||
}; | ||
|
||
var success = function (resp) { | ||
if (resp.valid) { | ||
ngModel.$setValidity('queryInput', true); | ||
errorElem.hide(); | ||
return query; | ||
} else { | ||
return error(resp); | ||
} | ||
}; | ||
|
||
if ($scope.queryInput) { | ||
index = $scope.queryInput.get('index').toIndexList(); | ||
} else { | ||
index = configFile.kibanaIndex; | ||
type = '__kibanaQueryValidator'; | ||
} | ||
|
||
if (request.abort) request.abort(); | ||
|
||
request = es.indices.validateQuery({ | ||
index: index, | ||
type: type, | ||
explain: true, | ||
ignoreUnavailable: true, | ||
body: { | ||
query: query || { match_all: {} } | ||
} | ||
}).then(success, error); | ||
}; | ||
|
||
var debouncedValidator = _.debounce(validater, 300); | ||
|
||
|
||
// What should I make with the input from the user? | ||
var fromUser = function (text) { | ||
try { | ||
return JSON.parse(text); | ||
} catch (e) { | ||
return { | ||
query_string: { | ||
query: text || '*' | ||
} | ||
}; | ||
} | ||
}; | ||
|
||
// How should I present the data back to the user in the input field? | ||
var toUser = function (text) { | ||
if (_.isString(text)) return text; | ||
if (_.isObject(text)) { | ||
if (text.query_string) return text.query_string.query; | ||
return JSON.stringify(text); | ||
} | ||
return undefined; | ||
}; | ||
|
||
ngModel.$parsers.push(fromUser); | ||
ngModel.$formatters.push(toUser); | ||
|
||
// Use a model watch instead of parser/formatter. Debounced anyway. Parsers require the | ||
// user to actually enter input, which may not happen if the back button is clicked | ||
$scope.$watch('ngModel', debouncedValidator); | ||
|
||
init(); | ||
} | ||
}; | ||
}); | ||
}); |
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,11 @@ | ||
@import (reference) "../../styles/_bootstrap.less"; | ||
@import (reference) "../../styles/theme/_theme.less"; | ||
@import (reference) "../../styles/_variables.less"; | ||
|
||
i.query-input-error { | ||
position: absolute; | ||
margin-left: -25px; | ||
color: @brand-danger; | ||
margin-top: 10px; | ||
z-index: 5; | ||
} |
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