Skip to content

Commit

Permalink
Merge pull request #15 from spenceralger/discover_crud
Browse files Browse the repository at this point in the history
On the road to setting up the discover skelly
  • Loading branch information
spenceralger committed Feb 27, 2014
2 parents db91c15 + 8a48e0e commit 14cdb49
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 128 deletions.
11 changes: 6 additions & 5 deletions src/courier/data_source/data_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ define(function (require) {
this._state = state;
this._courier = courier;

// before newListener to prevent unnecessary "emit" when added
this.on('removeListener', function onRemoveListener() {
if (EventEmitter.listenerCount(this, 'results') > 0) return;
courier._closeDataSource(this);
});

this.on('newListener', function (name, listener) {
if (name !== 'results') return;

Expand All @@ -43,11 +49,6 @@ define(function (require) {
}
});

this.on('removeListener', function onRemoveListener() {
if (EventEmitter.listenerCount(this, 'results') > 0) return;
courier._closeDataSource(this);
});

this.extend = function () {
return courier
.createSource(this._getType())
Expand Down
40 changes: 37 additions & 3 deletions src/courier/mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ define(function (require) {
});

cacheFieldsToObject(dataSource, fields);
callback(err, fields);
callback(err, self.getFieldsFromObject(dataSource));
});
} else {
cacheFieldsToObject(dataSource, fields);
callback(err, fields);
callback(err, self.getFieldsFromObject(dataSource));
}
});
}
Expand Down Expand Up @@ -141,8 +141,15 @@ define(function (require) {
_.each(index.mappings, function (type) {
_.each(type, function (field, name) {
if (_.size(field.mapping) === 0 || name[0] === '_') return;
if (!_.isUndefined(fields[name]) && fields[name].type !== field.mapping[_.keys(field.mapping)[0]].type)

var mapping = field.mapping[_.keys(field.mapping)[0]];
mapping.type = castMappingType(mapping.type);

if (fields[name]) {
if (fields[name].type === mapping.type) return;
return courier._error(new Error.MappingConflict(name));
}

fields[name] = field.mapping[_.keys(field.mapping)[0]];
});
});
Expand Down Expand Up @@ -181,6 +188,33 @@ define(function (require) {
return !_.isUndefined(mappings[dataSource._state.index]) ? true : false;
};

/**
* Accepts a mapping type, and converts it into it's js equivilent
* @param {String} type - the type from the mapping's 'type' field
* @return {String} - the most specific type that we care for
*/
var castMappingType = function (type) {
switch (type) {
case 'float':
case 'double':
case 'integer':
case 'long':
case 'short':
case 'byte':
case 'token_count':
return 'number';
case 'date':
case 'boolean':
case 'ip':
case 'attachment':
case 'geo_point':
case 'geo_shape':
return type;
default: // including 'string'
return 'string';
}
};

/**
* Clears mapping caches from elasticsearch and from local object
* @param {dataSource} dataSource
Expand Down
15 changes: 15 additions & 0 deletions src/kibana/apps/discover/field_chooser.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<ul>
<li ng-repeat="field in fields">
<span ng-click="toggle(field.name)">
<i
class="fa"
ng-class="{
'fa-check-square': !field.hidden,
'fa-square-o': field.hidden
}">
</i>
{{field.name}}
</span>
</li>
</ul>
<small class="pull-right"><a ng-click="refresh()">refresh field list</a></small>
16 changes: 16 additions & 0 deletions src/kibana/apps/discover/field_chooser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
define(function (require) {
var app = require('angular').module('app/discover');
var html = require('text!./field_chooser.html');

app.directive('discFieldChooser', function () {
return {
restrict: 'E',
scope: {
fields: '=',
toggle: '=',
refresh: '='
},
template: html
};
});
});
70 changes: 33 additions & 37 deletions src/kibana/apps/discover/index.html
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
<div ng-controller="discover">
<h1>Discover</h1>
<div class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-2">Index</label>
<div class="col-sm-10">
<input class="form-control" ng-model="index">
</div>
</div>
<!-- <div class="form-group">
<label class="control-label col-sm-3">Repeat Interval</label>
<div class="col-sm-9">
<select
<nav class="navbar navbar-default navbar-static-top subnav">
<form class="navbar-form navbar-left form-inline" role="search" ng-submit="fetch()">
<label class="control-label">Index</label>
<input class="form-control" ng-model="index">
<label class="control-label" for="size">Query</label>
<input type="text" class="form-control" ng-model="query" placeholder="search">
<label class="control-label" for="size">Limit</label>
<select
class="form-control"
name="size"
ng-model="size"
ng-options="size.display for size in sizeOptions">
</select>
<label class="control-label" for="sort">Sort</label>
<select
class="form-control"
ng-model="interval"
ng-options="i.display for i in intervalOptions">
name="sort"
ng-model="sort"
ng-options="field.name for field in fields">
</select>
</div>
</div> -->
<form class="form-group" ng-submit="reset()">
<label class="control-label col-sm-2">Query</label>
<div class="col-sm-10">
<div class="input-group">
<input class="form-control" ng-model="query" >
<span class="input-group-btn">
<button type="button" class="btn" ng-click="reset()">
<i class="glyphicon glyphicon-search"></i>
</button>
</span>
</div>
</div>
<button type="submit" class="btn btn-default">
<i class="fa fa-search"></i>
</button>
</form>
</nav>
<div class="row">
<div class="col-md-10">
<kbn-table rows="rows" columns="columns"></kbn-table>
</div>
<div class="col-md-2">
<disc-field-chooser
fields="fields"
toggle="toggleField"
refresh="refreshFieldList">
</disc-field-chooser>
</div>
</div>
<div class="input-group">
<label class="control-label col-sm-2">Limit</label>
<select
class="form-control"
ng-model="size"
ng-options="size.display for size in sizeOptions">
</select>
</div>
<kbn-table rows="rows" columns="columns"></kbn-table>
</div>
Loading

0 comments on commit 14cdb49

Please sign in to comment.