Skip to content

Commit

Permalink
Fixed lint errors, now IE11 compatible.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Carter committed Jul 21, 2018
1 parent 5ab32d3 commit 9bf4c79
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 97 deletions.
14 changes: 7 additions & 7 deletions public/common/lodash-mixins/get_pluck.js
@@ -1,7 +1,7 @@
export function lodashGetPluckMixin(_) {

let toPath = require('lodash/internal/toPath');
let toObject = require('lodash/internal/toObject');
const toPath = require('lodash/internal/toPath');
const toObject = require('lodash/internal/toObject');

/**
* The base implementation of `get` without support for string paths
Expand All @@ -24,21 +24,21 @@ export function lodashGetPluckMixin(_) {
}

let index = 0;
let length = path.length;
const length = path.length;

while (object != null && index < length) {
let key = path[index++];
const key = path[index++];

if (_.isArray(object) && !_.has(object, key)) {
object = _.map(object, _.property(_.slice(path, index-1)));
object = _.map(object, _.property(_.slice(path, index - 1)));
index = length;
}
else {
object = object[key];
}
}

return (index && index == length) ? object : undefined;
return (index && index === length) ? object : undefined;
}

_.mixin(_, {
Expand Down Expand Up @@ -72,7 +72,7 @@ export function lodashGetPluckMixin(_) {
* // => 'default'
*/
getPluck: function (object, path, defaultValue) {
let result = object == null ? undefined : baseGetWithPluck(object, toPath(path), path + '');
const result = object == null ? undefined : baseGetWithPluck(object, toPath(path), path + '');
return result === undefined ? defaultValue : result;
}
});
Expand Down
78 changes: 39 additions & 39 deletions public/field_formats/object/object.js
Expand Up @@ -17,11 +17,11 @@ import { lodashGetPluckMixin } from '../../common/lodash-mixins/get_pluck';
lodashOopMixin(_);
lodashGetPluckMixin(_);

const vis_template = _.template(format_html)
const image_template = _.template(image_html)
const link_template = _.template(link_html)
const text_template = _.template(text_html)
const empty_template = _.template(empty_html)
const vis_template = _.template(format_html);
const image_template = _.template(image_html);
const link_template = _.template(link_html);
const text_template = _.template(text_html);
const empty_template = _.template(empty_html);

const DEFAULT_VALUES = {
label: null, // Optional data label
Expand Down Expand Up @@ -57,32 +57,32 @@ export function createObjectFormat(FieldFormat) {
};
}

_get_field_models(value, field, hit, basePath, objectFields) {
_getFieldModels(value, field, hit, basePath, objectFields) {

let filtered = false;
let fields = [];
const fields = [];

// Apply each field configured for the formatter to the value
_.forEach(objectFields, _.bind(function(objectField) {
_.forEach(objectFields, _.bind(function (objectField) {
let label = '';
let fieldPath = '';

if (objectField.label) label = objectField.label + ": ";
if (objectField.label) label = objectField.label + ': ';
if (objectField.path) fieldPath = objectField.path;
if (objectField.filtered) filtered = objectField.filtered;

// Get the value from the field path
let fieldValues = _.getPluck(value, fieldPath);

if (objectField.type == 'text') {
if (objectField.type === 'text') {
// We generate a nice comma delimited list, like the built in String does.
if (_.isArray(fieldValues)) {
if (objectField.limit) {
fieldValues = _.slice(fieldValues, 0, objectField.limit);
}

fieldValues = _(fieldValues)
.map( item => ( _.isObject(item) ? JSON.stringify(item) : item) )
.map(item => (_.isObject(item) ? JSON.stringify(item) : item))
.join(', ');
}
else if (_.isObject(fieldValues)) {
Expand All @@ -99,13 +99,13 @@ export function createObjectFormat(FieldFormat) {
fieldValues = _.slice(fieldValues, 0, objectField.limit);
}

let fullPath = this._get_full_path(basePath, field, objectField.path, null);
let filterPath = this._get_full_path(basePath, field, objectField.path, objectField.filterField);
let valueModels = [];
const fullPath = this._getFullPath(basePath, field, objectField.path, null);
const filterPath = this._getFullPath(basePath, field, objectField.path, objectField.filterField);
const valueModels = [];

_.forEach(fieldValues, _.bind(function(fieldValue) {
_.forEach(fieldValues, _.bind(function (fieldValue) {

let valueModel = {
const valueModel = {
value: fieldValue,
display: _.escape(fieldValue)
};
Expand All @@ -120,7 +120,7 @@ export function createObjectFormat(FieldFormat) {
valueModels.push(valueModel);
}, this));

let fieldHtml = this._field_to_html({
const fieldHtml = this._fieldToHtml({
label: label,
formatType: objectField.type,
values: valueModels,
Expand All @@ -136,34 +136,34 @@ export function createObjectFormat(FieldFormat) {
});
}, this));

return {filtered: filtered, fields: fields};
};
return { filtered: filtered, fields: fields };
}

_field_to_html(fieldModel) {
_fieldToHtml(fieldModel) {

let html = null;

switch (fieldModel.formatType) {
case 'image':
html = image_template({field: fieldModel})
html = image_template({ field: fieldModel });
break;

case 'link':
html = link_template({field: fieldModel})
html = link_template({ field: fieldModel });
break;

case 'text':
default:
html = text_template({field: fieldModel})
html = text_template({ field: fieldModel });
break;
}

return html;
};
}

_get_full_path(basePath, field, valuePath, filterField) {
_getFullPath(basePath, field, valuePath, filterField) {

let parts = [field.name];
const parts = [field.name];

if (basePath) {
parts.push(basePath);
Expand All @@ -176,7 +176,7 @@ export function createObjectFormat(FieldFormat) {
}

return parts.join('.');
};
}

asPrettyString(val) {
if (val === null || val === undefined) return ' - ';
Expand All @@ -185,17 +185,17 @@ export function createObjectFormat(FieldFormat) {
case 'object': return JSON.stringify(val, null, ' ');
default: return '' + val;
}
};
}
}

ObjectFormat.prototype._convert = {
text(val) {
return this.asPrettyString(val);
},
html(val, field, hit) {
let basePath = this.param('basePath');
let objectFields = this.param('fields');
let limit = this.param('limit');
const basePath = this.param('basePath');
const objectFields = this.param('fields');
const limit = this.param('limit');

if (basePath) {
val = _.get(val, basePath);
Expand All @@ -206,22 +206,22 @@ export function createObjectFormat(FieldFormat) {
}

// Filter out any null or empty entries
val = $.grep(val, function(n){ return n == 0 || n });
val = $.grep(val, function (n) { return n === 0 || n });

// If we have a limit on this list, impose it now
if (limit) {
val = _.slice(val, 0, limit);
}

if (val.length > 0) {
let htmlSnippets = [];
const htmlSnippets = [];

_.forEach(val, _.bind(function(value){
_.forEach(val, _.bind(function (value) {
if (value) {
let fieldModels = this._get_field_models(value, field, hit, basePath, objectFields);
htmlSnippets.push(vis_template({filtered: fieldModels.filtered,
fields: fieldModels.fields,
uid: Math.floor((Math.random() * 1000000) + 1)}));
const fieldModels = this._getFieldModels(value, field, hit, basePath, objectFields);
htmlSnippets.push(vis_template({ filtered: fieldModels.filtered,
fields: fieldModels.fields,
uid: Math.floor((Math.random() * 1000000) + 1) }));
}
}, this));

Expand All @@ -241,7 +241,7 @@ export function objectEditor() {
formatId: 'ist-object',
template: objectTemplate,
controllerAs: 'object',
controller: function ($scope, chrome) {
controller: function ($scope) {

this.formatTypes = [
{ id: 'text', name: 'Text' },
Expand Down
8 changes: 4 additions & 4 deletions public/field_formats/object/templates/object_format.html
Expand Up @@ -23,7 +23,7 @@
<!-- [object field formatter] Change the 'white-space' css attribute of our containing div, and remove the warning icon -->
<script>
// Run this after angular has done it's thing
setTimeout(() => {
setTimeout((function () {
// Discover table row
// Only set nowrap if parent is td.discover-table-datafield, do nothing if td.discover-table-sourcefield
$(".<%= uid %>")
Expand All @@ -34,12 +34,12 @@
// Discover table expanded row
$(".<%= uid %>").closest("div.doc-viewer-value").css("white-space", "nowrap");
$(".<%= uid %>").closest("div.doc-viewer-value").siblings("i.fa-warning").remove();
}, 0);
} ), 0);
</script>
<!-- [object field formatter] Hide the filter buttons if this formatter doesn't have filtering enabled -->
<script>
// Run this after angular has done it's thing
setTimeout(() => {
setTimeout((function () {
// Discover table row
$(".object-table-no-filter.<%= uid %>")
.closest("td.discover-table-datafield")
Expand All @@ -58,5 +58,5 @@
"<span><i class=\"fa fa-search-plus text-muted\" style=\"padding-right: 7px;\"></i><i class=\"fa fa-search-minus text-muted\"></span>"
);
}
}, 0);
} ), 0);
</script>
54 changes: 27 additions & 27 deletions public/hacks/field_mapper_hack.js
@@ -1,56 +1,56 @@
import _ from 'lodash';
import angular from 'angular';
import 'ui/courier';
import 'ui/index_patterns';
import 'ui/modals/confirm_modal_promise';
import { uiModules } from 'ui/modules';

let app = uiModules.get('app/kibana-object-formatter', [
'kibana/index_patterns'
]);
const app = uiModules.get('app/kibana-object-formatter', [
'kibana/index_patterns'
]);

/**
* Patch 'fieldsFetcher.fetch' to allow us to insert additional fields.
*/
app.run(['indexPatterns', 'config', function(indexPatterns, config) {
app.run(['indexPatterns', 'config', function (indexPatterns, config) {

let fieldsFetcher = indexPatterns.fieldsFetcher;
let fieldsFunc = fieldsFetcher.fetch;
const fieldsFetcher = indexPatterns.fieldsFetcher;
const fieldsFunc = fieldsFetcher.fetch;

(function(fieldsFunc) { // Cache the original method
fieldsFetcher.fetch = function() { // Wrap the method
(function (fieldsFunc) { // Cache the original method
fieldsFetcher.fetch = function () { // Wrap the method

let indexPattern = arguments[0]
const indexPattern = arguments[0];

let promise = fieldsFunc.apply(this, arguments);
const promise = fieldsFunc.apply(this, arguments);

return promise.then(fields => {

let paths = [];
let mappingNames = [];
const mappingNames = [];

// 1) Iterate the field names, identify the "parent" paths
_.forEach(fields, function(field) {
_.forEach(fields, function (field) {

let fieldName = field["name"];
const fieldName = field.name;
mappingNames.push(fieldName);

let parts = fieldName.split(".");
const parts = fieldName.split('.');

while (parts.length > 1) {
parts.pop();
paths.push(parts.join("."));
paths.push(parts.join('.'));
}
});

paths = _.uniq(_.difference(paths, mappingNames));

// 2) Test the discovered field names against the configuration
let defaultConfig = "{\n \"index_pattern\": {\n \"*\": {\n \"include\": [],\n \"exclude\": [\".*\"]\n }\n }\n}"
const defaultConfig = '{\n \"index_pattern\": {\n \"*\": {\n' +
'\"include\": [],\n \"exclude\": [\".*\"]\n }\n }\n}';
let settings = config.get('fieldMapperHack:fields', defaultConfig);
settings = settings['index_pattern'];
settings = settings.index_pattern;

let match = { includes: [], excludes: []};
let match = { includes: [], excludes: [] };

if (_.has(settings, indexPattern.id)) {
match = settings[indexPattern.id];
Expand All @@ -59,35 +59,35 @@ app.run(['indexPatterns', 'config', function(indexPatterns, config) {
match = settings['*'];
}

let included = []
let excluded = []
const included = [];
const excluded = [];

_.forEach(match['include'], function(expression){
_.forEach(paths, function(path){
_.forEach(match.include, function (expression) {
_.forEach(paths, function (path) {
if (path.match(expression)) {
included.push(path);
}
});
});

_.forEach(match['exclude'], function(expression){
_.forEach(included, function(path){
_.forEach(match.exclude, function (expression) {
_.forEach(included, function (path) {
if (path.match(expression)) {
excluded.push(path);
}
});
});

// 3) Add a field mapping for the missing parents
_.forEach(_.difference(included, excluded), function(path){
_.forEach(_.difference(included, excluded), function (path) {
fields.push({
name: path,
aggregatable: false,
searchable: true,
analyzed: false,
doc_values: false,
indexed: true,
type: "string"
type: 'string'
});
});

Expand Down

0 comments on commit 9bf4c79

Please sign in to comment.