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

Scripted fields interface #2076

Merged
merged 39 commits into from
Dec 4, 2014
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3cdb638
break indexed fields into its own directive
w33ble Nov 25, 2014
347d908
break scripted fields into its own directive, with mock data
w33ble Nov 25, 2014
8ed489f
allow columns to not be sortable
w33ble Nov 25, 2014
e204020
prepare for listing sripted fields, with controls
w33ble Nov 26, 2014
d53b37f
add control, and create/edit routes
w33ble Nov 26, 2014
d520b37
consolidate router, add real title
w33ble Nov 26, 2014
fce9b2f
create form, with name checking and mock button handlers
w33ble Dec 1, 2014
97fc109
add method to save scripted fields, save on submit, use indexedArray …
w33ble Dec 1, 2014
1b5eff5
change the path to scripted fields
w33ble Dec 1, 2014
aa2f93b
fix the display of scripted fields, tweak styling
w33ble Dec 1, 2014
9a32d08
don't re-index, save does this automatically
w33ble Dec 1, 2014
963884e
don't redirect, just go back
w33ble Dec 1, 2014
35864b8
read exiting fields from the indexPattern, for editing
w33ble Dec 1, 2014
57ebe14
allow scripted field removal
w33ble Dec 1, 2014
7d6d176
make sure scriptedFields is set on the index pattern
w33ble Dec 2, 2014
79393f3
add warning message about scripted fields
w33ble Dec 3, 2014
0195fa6
right-align instead of pulling right
w33ble Dec 3, 2014
c9f61f1
clear the rowScopes array
w33ble Dec 3, 2014
bf28fa8
be more explicit about the paths used
w33ble Dec 3, 2014
c787074
change how tabs and item counts work
w33ble Dec 3, 2014
867d6cd
Merge branch 'master' into scripted-interface
w33ble Dec 3, 2014
acf302d
streamline deleting scripted fields a bit
w33ble Dec 3, 2014
6eecaff
filter field list to scripted and unscripted fields
w33ble Dec 3, 2014
8822028
remove scriptedFields from the index pattern
w33ble Dec 4, 2014
690055a
back out the lodash remove stuff, doesn't appear to work on IndexedArray
w33ble Dec 4, 2014
529bb4f
change the indexedFields tab name, for consistency
w33ble Dec 4, 2014
645571a
append scripted fields when refreshing indexed fields, make propertie…
w33ble Dec 4, 2014
872c4d0
fix naming conflict check
w33ble Dec 4, 2014
8ea2d43
fix tabbed interface index
w33ble Dec 4, 2014
3a17105
add getFields helper, use it to fetch scripted and indexed fields
w33ble Dec 4, 2014
cf1f8f7
expose type maps on the CastMappingType function
w33ble Dec 4, 2014
99a0e3b
add type for scripted fields, show it in the list
w33ble Dec 4, 2014
fb78e46
fix field name conflict check
w33ble Dec 4, 2014
b95365b
assign default field type to skirt weird angular issue
w33ble Dec 4, 2014
f303e2d
boolean check on getFields, use getFields to fetch scripted fields wh…
w33ble Dec 4, 2014
6c21106
make mapping types an indexedarray, use it in scripted field type list
w33ble Dec 4, 2014
b605131
fieldTypes is not a class
w33ble Dec 4, 2014
40b0a00
fix field type options syntax
w33ble Dec 4, 2014
250ed8d
add groups to input types, use in result type select
w33ble Dec 4, 2014
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
25 changes: 22 additions & 3 deletions src/kibana/components/index_patterns/_index_pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ define(function (require) {
return self.refreshFields();
} else {
setIndexedValue('fields');
setIndexedValue('scriptedFields');
}
}

Expand Down Expand Up @@ -116,6 +117,22 @@ define(function (require) {
});
}

self.addScriptedField = function (name, script) {
var scriptedField = self.scriptedFields.push({
name: name,
script: script
});
self.save();
};

self.removeScriptedField = function (name) {
var index = _.findIndex(self.scriptedFields, { name: name });
if (index !== -1) {
self.scriptedFields.splice(index, 1);
self.save();
}
};

self.popularizeField = function (fieldName, unit) {
if (_.isUndefined(unit)) unit = 1;
if (!(self.fields.byName && self.fields.byName[fieldName])) return;
Expand Down Expand Up @@ -170,7 +187,7 @@ define(function (require) {
return mapper.clearCache(self)
.then(function () {
return self._fetchFields()
.then(self._fetchScriptedFields)
.then(self._setScriptedFields)
.then(self.save);
});
};
Expand All @@ -182,8 +199,10 @@ define(function (require) {
});
};

self._fetchScriptedFields = function () {
setIndexedValue('scriptedFields', []);
self._setScriptedFields = function () {
if (!self.scriptedFields) {
self.scriptedFields = [];
}
};

self.toJSON = function () {
Expand Down
1 change: 1 addition & 0 deletions src/kibana/components/paginated_table/paginated_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<span bo-text="col.title"></span>
<kbn-info ng-if="col.info" info="{{ col.info }}" placement="top"></kbn-info>
<i
ng-if="col.sortable !== false"
class="fa"
ng-class="{
'fa-sort-asc': paginatedTable.sort.columnName === col.title && paginatedTable.sort.direction === 'asc',
Expand Down
1 change: 1 addition & 0 deletions src/kibana/components/paginated_table/paginated_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ define(function (require) {
};

self.sortColumn = function (col) {
if (col.sortable === false) return;
var sortDirection;
var cols = _.pluck($scope.columns, 'title');
var index = cols.indexOf(col.title);
Expand Down
12 changes: 2 additions & 10 deletions src/kibana/plugins/settings/sections/indices/_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,9 @@ <h1>
</li>
</ul>

<div ng-show="state.tab == 'fields'" class="fields">
<paginated-table
columns="fieldColumns"
rows="fieldRows"
per-page="perPage">
</paginated-table>
</div>
<indexed-fields ng-show="state.tab == 'fields'" class="fields"></indexed-fields>

<div ng-show="state.tab == 'scriptedFields'" class="scripted-fields">
No scripted fields defined
</div>
<scripted-fields ng-show="state.tab == 'scriptedFields'" class="scripted-fields"></scripted-fields>

</div>
</kbn-settings-indices>
Expand Down
51 changes: 3 additions & 48 deletions src/kibana/plugins/settings/sections/indices/_edit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
define(function (require) {
var _ = require('lodash');
require('components/paginated_table/paginated_table');
require('plugins/settings/sections/indices/_indexed_fields');
require('plugins/settings/sections/indices/_scripted_fields');

require('routes')
.when('/settings/indices/:id', {
Expand All @@ -14,10 +15,8 @@ define(function (require) {
});

require('modules').get('apps/settings')
.controller('settingsIndicesEdit', function ($scope, $location, $route, $compile,
config, courier, Notifier, Private, AppState) {
.controller('settingsIndicesEdit', function ($scope, $location, $route, config, courier, Notifier, Private, AppState) {

var rowScopes = []; // track row scopes, so they can be destroyed as needed
var notify = new Notifier();
var $state = $scope.state = new AppState();
var popularityHtml = require('text!plugins/settings/sections/indices/_popularity.html');
Expand All @@ -28,50 +27,6 @@ define(function (require) {

$scope.fieldTypes = Private(require('plugins/settings/sections/indices/_field_types'));

$scope.fieldColumns = [{
title: 'name'
}, {
title: 'type'
}, {
title: 'analyzed',
info: 'Analyzed fields may require extra memory to visualize'
}, {
title: 'indexed',
info: 'Fields that are not indexed are unavailable for search'
}, {
title: 'popularity',
info: 'A gauge of how often this field is used',
}];

$scope.showPopularityControls = function (field) {
$scope.popularityHoverState = (field) ? field : null;
};

$scope.$watchCollection('indexPattern.fields', function () {
_.invoke(rowScopes, '$destroy');

$scope.fieldRows = $scope.indexPattern.fields.map(function (field) {
var childScope = $scope.$new();
rowScopes.push(childScope);
childScope.field = field;

// update the active field via object comparison
if (_.isEqual(field, $scope.popularityHoverState)) {
$scope.showPopularityControls(field);
}

return [field.name, field.type, field.analyzed, field.indexed,
{
markup: $compile(popularityHtml)(childScope),
value: field.count
}
];
});
});


$scope.perPage = 25;

$scope.changeTab = function (obj) {
$state.tab = obj.index;
$state.save();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<paginated-table
columns="columns"
rows="rows"
per-page="perPage">
</paginated-table>
60 changes: 60 additions & 0 deletions src/kibana/plugins/settings/sections/indices/_indexed_fields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
define(function (require) {
var _ = require('lodash');
require('components/paginated_table/paginated_table');

require('modules').get('apps/settings')
.directive('indexedFields', function ($compile) {
var popularityHtml = require('text!plugins/settings/sections/indices/_popularity.html');

return {
restrict: 'E',
template: require('text!plugins/settings/sections/indices/_indexed_fields.html'),
scope: true,
link: function ($scope, $el, attr) {
var rowScopes = []; // track row scopes, so they can be destroyed as needed
$scope.perPage = 25;

$scope.columns = [{
title: 'name'
}, {
title: 'type'
}, {
title: 'analyzed',
info: 'Analyzed fields may require extra memory to visualize'
}, {
title: 'indexed',
info: 'Fields that are not indexed are unavailable for search'
}, {
title: 'popularity',
info: 'A gauge of how often this field is used',
}];

$scope.showPopularityControls = function (field) {
$scope.popularityHoverState = (field) ? field : null;
};

$scope.$watchCollection('indexPattern.fields', function () {
_.invoke(rowScopes, '$destroy');

$scope.rows = $scope.indexPattern.fields.map(function (field) {
var childScope = $scope.$new();
rowScopes.push(childScope);
childScope.field = field;

// update the active field via object comparison
if (_.isEqual(field, $scope.popularityHoverState)) {
$scope.showPopularityControls(field);
}

return [field.name, field.type, field.analyzed, field.indexed,
{
markup: $compile(popularityHtml)(childScope),
value: field.count
}
];
});
});
}
};
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="actions pull-right">
<button ng-click="edit(field)" class="btn btn-xs btn-default">
<i class="fa fa-pencil"></i>
</button>

<button
confirm-click="remove(field)"
confirmation="Are you sure want to delete '{{field.name}}'? This action is irreversible!"
class="btn btn-xs btn-danger">
<i class="fa fa-trash"></i>
</button>
</div>
14 changes: 14 additions & 0 deletions src/kibana/plugins/settings/sections/indices/_scripted_fields.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<header>
<button ng-click="create()" class="btn btn-info">
<i class="fa fa-plus"></i>
Add Scripted Field
</button>
</header>

<paginated-table
columns="columns"
rows="rows"
per-page="perPage">
</paginated-table>

<div ng-if="rows.length === 0">No scripted fields</div>
68 changes: 68 additions & 0 deletions src/kibana/plugins/settings/sections/indices/_scripted_fields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
define(function (require) {
var _ = require('lodash');
require('components/paginated_table/paginated_table');

require('modules').get('apps/settings')
.directive('scriptedFields', function ($compile, kbnUrl) {
var rowScopes = []; // track row scopes, so they can be destroyed as needed
var controlsHtml = require('text!plugins/settings/sections/indices/_scripted_field_controls.html');

return {
restrict: 'E',
template: require('text!plugins/settings/sections/indices/_scripted_fields.html'),
scope: true,
link: function ($scope, $el, attr) {
var fieldEditorPath = '/settings/indices/{{ indexPattern }}/scriptedField';
$scope.perPage = 25;

$scope.columns = [{
title: 'name'
}, {
title: 'script'
}, {
title: 'controls',
class: 'pull-right',
sortable: false
}];

$scope.$watch('indexPattern.scriptedFields', function () {
_.invoke(rowScopes, '$destroy');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to clear the rowScopes array too.


$scope.rows = $scope.indexPattern.scriptedFields.map(function (field, i) {
var rowScope = $scope.$new();
var columns = [field.name, field.script];
rowScope.field = field;
rowScopes.push(rowScope);

columns.push({
markup: $compile(controlsHtml)(rowScope)
});

return columns;
});
});

$scope.create = function () {
var params = {
indexPattern: $scope.indexPattern.id
};

kbnUrl.change(fieldEditorPath, params);
};

$scope.edit = function (field) {
var params = {
indexPattern: $scope.indexPattern.id,
fieldName: field.name
};

kbnUrl.change(fieldEditorPath + '/{{ fieldName }}', params);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This path template should probably be defined up by fieldEditorPath with it's own name

};

$scope.remove = function (field) {
$scope.indexPattern.removeScriptedField(field.name);
};
}
};
});
});
1 change: 1 addition & 0 deletions src/kibana/plugins/settings/sections/indices/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ <h5>
</ul>
</div>
</div>

<div class="col-md-10" ng-transclude></div>
1 change: 1 addition & 0 deletions src/kibana/plugins/settings/sections/indices/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
define(function (require) {
var _ = require('lodash');

require('plugins/settings/sections/indices/scripted_fields/index');
require('plugins/settings/sections/indices/_create');
require('plugins/settings/sections/indices/_edit');

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<kbn-settings-app section="indices">
<kbn-settings-indices>

<div ng-controller="scriptedFieldsEdit">
<h1>{{ action }} Scripted Field</h1>

<form name="scriptedFieldForm" ng-submit="submit()">
<div class="form-group">
<label>Name</label>
<input type="text" ng-model="scriptedField.name" class="form-control span12">
</div>
<div class="form-group">
<label>Script</label>
<textarea class="form-control span12" ng-model="scriptedField.script"></textarea>
</div>
</form>
<div ng-if="namingConflict" class="alert alert-danger">
You already have a field with the name {{ scriptedField.name }}. Naming your scripted
field with the same name means you won't be able to query both fields at the same time.
</div>
<div class="form-group">
<button class="btn btn-primary" ng-click="cancel()">Cancel</button>
<button class="btn btn-success" ng-click="submit()" ng-disabled="scriptedFieldForm.$invalid">
Save Scripted Field
</button>
</div>
</div>
</kbn-settings-indices>
</kbn-settings-app>
Loading