Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
Nabil BENDAFI committed Jun 5, 2017
1 parent 4b14590 commit f638549
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
parser: babel-eslint

plugins:
- mocha

env:
es6: true
amd: true
node: true
mocha: true
browser: true


rules:
block-scoped-var: 2
camelcase: [ 2, { properties: never } ]
comma-dangle: 0
comma-style: [ 2, last ]
consistent-return: 0
curly: [ 2, multi-line ]
dot-location: [ 2, property ]
dot-notation: [ 2, { allowKeywords: true } ]
eqeqeq: [ 2, allow-null ]
guard-for-in: 2
indent: [ 2, 2, { SwitchCase: 1 } ]
key-spacing: [ 0, { align: value } ]
max-len: [ 2, 140, 2, { ignoreComments: true, ignoreUrls: true } ]
new-cap: [ 2, { capIsNewExceptions: [ Private ] } ]
no-bitwise: 0
no-caller: 2
no-cond-assign: 0
no-debugger: 2
no-empty: 2
no-eval: 2
no-extend-native: 2
no-extra-parens: 0
no-irregular-whitespace: 2
no-iterator: 2
no-loop-func: 2
no-multi-spaces: 0
no-multi-str: 2
no-nested-ternary: 2
no-new: 0
no-path-concat: 0
no-proto: 2
no-return-assign: 0
no-script-url: 2
no-sequences: 2
no-shadow: 0
no-trailing-spaces: 2
no-undef: 2
no-underscore-dangle: 0
no-unused-expressions: 0
no-unused-vars: 0
no-use-before-define: [ 2, nofunc ]
no-with: 2
one-var: [ 2, never ]
quotes: [ 2, single ]
semi-spacing: [ 2, { before: false, after: true } ]
semi: [ 2, always ]
space-after-keywords: [ 2, always ]
space-before-blocks: [ 2, always ]
space-before-function-paren: [ 2, { anonymous: always, named: never } ]
space-in-parens: [ 2, never ]
space-infix-ops: [ 2, { int32Hint: false } ]
space-return-throw-case: [ 2 ]
space-unary-ops: [ 2 ]
strict: [ 2, never ]
valid-typeof: 2
wrap-iife: [ 2, outside ]
yoda: 0

mocha/no-exclusive-tests: 2
mocha/handle-done-callback: 2
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Logs
logs
*.log
npm-debug.log*

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/
build/Release

# Dependency directories
node_modules/
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = function (kibana) {
return new kibana.Plugin({
name: 'country-flag-fieldformatters',
require: ['kibana'],
uiExports: {
fieldFormats: ['plugins/country-flag-fieldformatters/country-flag']
}
});
};
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "country-flag-fieldformatters",
"version": "5.2.0",
"description": "Field formatters plugin for Kibana that display country flag based on its 'ISO 3166-1 alpha-2' code.",
"url" : "https://github.com/nabilbendafi/country-flag-fieldformatters/issues",
"author": "Nabil Bendafi <nabil@bendafi.fr>",
"scripts": {
"start": "plugin-helpers start",
"test:server": "plugin-helpers test:server",
"test:browser": "plugin-helpers test:browser",
"build": "plugin-helpers build"
},
"dependencies": {
"flag-icon-css": "2.8.0"
},
"devDependencies": {
"@elastic/eslint-config-kibana": "0.0.2",
"@elastic/plugin-helpers": "^6.0.0",
"babel-eslint": "^4.1.6",
"babel-preset-es2015": "^6.3.13",
"babel-register": "^6.4.3",
"bluebird": "^3.1.5",
"eslint": "^1.10.3",
"eslint-plugin-mocha": "^1.1.0",
"lodash": "^4.0.1"
}
}
56 changes: 56 additions & 0 deletions public/country-flag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function CountryFlagProvider(Private) {

var _ = require('lodash');
var FieldFormat = Private(require('ui/index_patterns/_field_format/field_format'));

// Include CSS file from [flag-icon-css](https://www.npmjs.com/package/flag-icon-css)
require('flag-icon-css/css/flag-icon.css');

// Create a new FieldFormat type and inherit FieldFormat
_.class(CountryFlag).inherits(FieldFormat);
function CountryFlag(params) {
CountryFlag.Super.call(this, params);
}

// The id of this field format
CountryFlag.id = 'country';
// The title of the field format, shown to the user
CountryFlag.title = 'Country Flag';
// An array of types, which this field formatter can be used for.
// You can only apply this field formatter to fields, that have one
// of the here specified types. Possible types are:
// number, boolean, date, ip, attachment, geo_point, geo_shape, string, murmur3
// murmur3 (Murmur3 plugin hashes), unknown (unknown field type),
// conflict (fields that have different types in different indices matched by the index pattern)
CountryFlag.fieldType = [
'string',
];

/*
Will be used to render the field with this formatter.
If you specify a function, the return value will be rendered (without interpreting HTML in it).
If you specify an object, you can have a key html and a key text with a function as
a value. The text function works as if you would have specified only a function. The return value
of the function you applied to the html key, will be interpreted as HTML (as seen below).
The first argument to the function will be the value that should be rendered.
The second argument will be the field, that should be rendered.
The object contains information like the type (`field.type`), that you might want to use
if you want to render differently depending on the field's type.
This can also be undefined, e.g. when formatting the field in a visualization due to the aggregation
this information is lost.
*/
CountryFlag.prototype._convert = {
text: function (value) {
return value;
},
html: function (value) {
var html = '<span class="flag-icon flag-icon-' + value.toLowerCase() + '" tooltip="' + value + '"></span>';
return html;
}
};

return CountryFlag;
}

// Register the provider to the field_formats registry
require('ui/registry/field_formats').register(CountryFlagProvider);

0 comments on commit f638549

Please sign in to comment.