fluentd-ui 1.0.0.alpha.3 → 1.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fluentd-ui might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.eslintrc.js +45 -0
- data/.travis.yml +17 -3
- data/Gemfile +2 -2
- data/Gemfile.lock +62 -63
- data/README.md +11 -0
- data/app/controllers/api/config_definitions_controller.rb +41 -17
- data/app/controllers/concerns/setting_concern.rb +0 -4
- data/app/controllers/fluentd/settings/in_tail_controller.rb +1 -1
- data/app/form_builders/fluentd_form_builder.rb +18 -6
- data/app/javascript/packs/application.js +20 -20
- data/app/javascript/packs/aws_credential.js +61 -0
- data/app/javascript/packs/codemirror.js +33 -37
- data/app/javascript/packs/config_field.js +93 -0
- data/app/javascript/packs/fluent_log.js +10 -9
- data/app/javascript/packs/in_tail_parse.js +77 -76
- data/app/javascript/packs/nested_settings.js +17 -16
- data/app/javascript/packs/notification.js +14 -14
- data/app/javascript/packs/out_forward_setting.js +14 -0
- data/app/javascript/packs/out_s3_setting.js +14 -0
- data/app/javascript/packs/owned_plugin_form.js +60 -57
- data/app/javascript/packs/parser_multiline_form.js +15 -14
- data/app/javascript/packs/plugin_setting.js +13 -13
- data/app/javascript/packs/settings.js +23 -18
- data/app/javascript/packs/transport_config.js +62 -0
- data/app/javascript/packs/transport_section.js +72 -0
- data/app/javascript/packs/treeview.js +11 -10
- data/app/models/concerns/fluentd/setting/configurable.rb +1 -3
- data/app/models/concerns/fluentd/setting/plugin.rb +29 -1
- data/app/models/concerns/fluentd/setting/plugin_config.rb +32 -8
- data/app/models/concerns/fluentd/setting/plugin_parameter.rb +74 -21
- data/app/models/concerns/fluentd/setting/registry_loader.rb +38 -0
- data/app/models/concerns/fluentd/setting/section_config.rb +52 -0
- data/app/models/concerns/fluentd/setting/section_parser.rb +25 -18
- data/app/models/fluentd/setting/in_forward.rb +29 -10
- data/app/models/fluentd/setting/in_syslog.rb +6 -6
- data/app/models/fluentd/setting/out_forward.rb +15 -3
- data/app/models/fluentd/setting/out_mongo.rb +0 -11
- data/app/models/fluentd/setting/out_s3.rb +17 -3
- data/app/models/fluentd/setting/out_tdlog.rb +3 -2
- data/app/models/fluentd/setting/section.rb +4 -0
- data/app/models/fluentd/setting/type/object.rb +17 -0
- data/app/views/fluentd/settings/in_forward/_form.html.haml +5 -3
- data/app/views/fluentd/settings/out_forward/_form.html.haml +18 -0
- data/app/views/fluentd/settings/out_s3/_form.html.haml +18 -0
- data/app/views/shared/settings/_form.html.haml +14 -10
- data/app/views/shared/settings/show.html.haml +2 -2
- data/app/views/shared/vue/_aws_credential.html.haml +22 -0
- data/app/views/shared/vue/_config_field.html.haml +49 -0
- data/app/views/shared/vue/_out_forward_setting.html.haml +13 -0
- data/app/views/shared/vue/_out_s3_setting.html.haml +19 -0
- data/app/views/shared/vue/_owned_plugin_form.html.haml +8 -48
- data/app/views/shared/vue/_transport_config.html.haml +20 -0
- data/app/views/shared/vue/_transport_section.html.haml +30 -0
- data/config/initializers/dig.rb +8 -0
- data/config/initializers/dummy_logger.rb +1 -0
- data/config/initializers/types.rb +2 -1
- data/config/locales/translation_ja.yml +2 -2
- data/fluentd-ui.gemspec +1 -0
- data/gemfiles/ruby2.2.gemfile +28 -0
- data/lib/dummy_logger.rb +13 -0
- data/lib/fluentd-ui/version.rb +1 -1
- data/package.json +5 -0
- data/spec/features/fluentd/setting/in_forward_spec.rb +1 -2
- data/spec/features/fluentd/setting/in_http_spec.rb +1 -2
- data/spec/features/fluentd/setting/in_monitor_agent_spec.rb +1 -2
- data/spec/features/fluentd/setting/out_forward_spec.rb +3 -5
- data/spec/features/fluentd/setting/out_stdout_spec.rb +1 -2
- data/spec/features/out_elasticsearch_spec.rb +3 -3
- data/spec/features/out_forward_spec.rb +6 -5
- data/spec/features/out_tdlog_spec.rb +3 -2
- data/spec/features/shared_examples/configurable_daemon_settings.rb +2 -2
- data/spec/features/source_and_output_spec.rb +2 -0
- data/spec/models/fluentd/setting/in_forward_spec.rb +65 -9
- data/spec/models/fluentd/setting/in_syslog_spec.rb +12 -7
- data/spec/models/fluentd/setting/in_tail_spec.rb +6 -0
- data/spec/models/fluentd/setting/out_mongo_spec.rb +2 -3
- data/spec/models/fluentd/setting/out_tdlog_spec.rb +1 -2
- data/spec/spec_helper.rb +5 -0
- data/yarn.lock +466 -12
- metadata +90 -39
- data/app/helpers/settings_helper.rb +0 -144
- data/app/models/concerns/fluentd/setting/section_validator.rb +0 -21
- data/app/views/fluentd/settings/_form.html.haml +0 -43
@@ -14,15 +14,11 @@ module SettingConcern
|
|
14
14
|
@storage = @setting.create_storage
|
15
15
|
@parser = @setting.create_parser
|
16
16
|
@formatter = @setting.create_formatter
|
17
|
-
@_used_param = {}
|
18
|
-
@_used_section = {}
|
19
17
|
render "shared/settings/show"
|
20
18
|
end
|
21
19
|
|
22
20
|
def finish
|
23
21
|
@setting = target_class.new(setting_params)
|
24
|
-
@_used_param = {}
|
25
|
-
@_used_section = {}
|
26
22
|
unless @setting.valid?
|
27
23
|
return render "shared/settings/show"
|
28
24
|
end
|
@@ -58,7 +58,7 @@ class Fluentd::Settings::InTailController < ApplicationController
|
|
58
58
|
permit_params = target_class._types.keys
|
59
59
|
permit_params << :parse_type
|
60
60
|
section_class = Fluentd::Setting.const_get("parser_#{params.dig(:setting, :parse_type)}".classify)
|
61
|
-
permit_params << { parse: section_class._types.keys }
|
61
|
+
permit_params << { parse: section_class._types.keys + [:type] }
|
62
62
|
params.require(:setting).permit(*permit_params)
|
63
63
|
end
|
64
64
|
|
@@ -24,17 +24,22 @@ class FluentdFormBuilder < ActionView::Helpers::FormBuilder
|
|
24
24
|
when :bool
|
25
25
|
bool_field(key, options)
|
26
26
|
else
|
27
|
-
|
27
|
+
if key.to_sym == :log_level
|
28
|
+
log_level_field(key, options)
|
29
|
+
else
|
30
|
+
other_field(key, options)
|
31
|
+
end
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
31
35
|
def enum_field(key, options)
|
32
36
|
label(key, nil, data: { toggle: "tooltip", placement: "right" }, title: object.desc(key)) +
|
33
|
-
select(key, object.list_of(key), options, { class: "enum" })
|
37
|
+
select(key, object.list_of(key), options, { class: "enum form-control" })
|
34
38
|
end
|
35
39
|
|
36
40
|
def bool_field(key, options)
|
37
|
-
|
41
|
+
return unless object.respond_to?(key)
|
42
|
+
check_box(key, options, true, false) + " " +
|
38
43
|
label(key, nil, data: { toggle: "tooltip", placement: "right" }, title: object.desc(key))
|
39
44
|
end
|
40
45
|
|
@@ -44,13 +49,20 @@ class FluentdFormBuilder < ActionView::Helpers::FormBuilder
|
|
44
49
|
text_field(key, class: "form-control", **options)
|
45
50
|
end
|
46
51
|
|
52
|
+
def log_level_field(key, options)
|
53
|
+
return unless object.respond_to?(key)
|
54
|
+
label(key, nil, data: { toggle: "tooltip", placement: "right" }, title: object.desc(key)) +
|
55
|
+
select(key, Fluent::Log::LEVEL_TEXT, { include_blank: true }, { class: "form-control" })
|
56
|
+
end
|
57
|
+
|
47
58
|
def render_section(key, options)
|
48
59
|
section_class = object.class._sections[key]
|
49
60
|
children = object.__send__(key) || { "0" => {} }
|
50
61
|
html = ""
|
62
|
+
html_class = "js-nested-column #{section_class.multi ? "js-multiple" : ""}"
|
51
63
|
|
52
64
|
children.each do |index, child|
|
53
|
-
html << content_tag("div", class:
|
65
|
+
html << content_tag("div", class: html_class) do
|
54
66
|
_html = ""
|
55
67
|
_html << append_and_remove_links if section_class.multi
|
56
68
|
_html << label(key, nil, data: { toggle: "tooltip", placement: "right" }, title: object.desc(key))
|
@@ -73,8 +85,8 @@ class FluentdFormBuilder < ActionView::Helpers::FormBuilder
|
|
73
85
|
end
|
74
86
|
|
75
87
|
def append_and_remove_links
|
76
|
-
%Q!<a class="btn btn-xs
|
77
|
-
%Q!<a class="btn btn-xs
|
88
|
+
%Q!<a class="btn btn-xs js-append">#{icon('fa-plus')}</a> ! +
|
89
|
+
%Q!<a class="btn btn-xs js-remove" style="display:none">#{icon('fa-minus')}</a> !
|
78
90
|
end
|
79
91
|
|
80
92
|
def icon(classes, inner=nil)
|
@@ -7,34 +7,34 @@
|
|
7
7
|
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
|
8
8
|
// layout file, like app/views/layouts/application.html.erb
|
9
9
|
|
10
|
-
console.log(
|
10
|
+
console.log("Hello World from Webpacker");
|
11
11
|
|
12
|
-
import jQuery from
|
12
|
+
import jQuery from "jquery/dist/jquery";
|
13
13
|
|
14
|
-
window.$ = jQuery
|
15
|
-
window.jQuery = jQuery
|
14
|
+
window.$ = jQuery;
|
15
|
+
window.jQuery = jQuery;
|
16
16
|
|
17
|
-
import Rails from
|
17
|
+
import Rails from "rails-ujs/lib/assets/compiled/rails-ujs.js";
|
18
18
|
|
19
|
-
window.Rails = Rails
|
20
|
-
Rails.start()
|
19
|
+
window.Rails = Rails;
|
20
|
+
Rails.start();
|
21
21
|
|
22
|
-
import
|
23
|
-
import
|
24
|
-
import
|
25
|
-
import
|
26
|
-
import
|
22
|
+
import "popper.js/dist/popper";
|
23
|
+
import "bootstrap/dist/js/bootstrap";
|
24
|
+
import "datatables.net/js/jquery.dataTables";
|
25
|
+
import "startbootstrap-sb-admin/js/sb-admin";
|
26
|
+
import "startbootstrap-sb-admin/js/sb-admin-datatables";
|
27
27
|
|
28
|
-
import Vue from
|
28
|
+
import Vue from "vue/dist/vue.esm";
|
29
29
|
|
30
|
-
Vue.filter(
|
31
|
-
|
32
|
-
})
|
30
|
+
Vue.filter("to_json", function (value) {
|
31
|
+
return JSON.stringify(value);
|
32
|
+
});
|
33
33
|
|
34
|
-
window.Vue = Vue
|
34
|
+
window.Vue = Vue;
|
35
35
|
|
36
|
-
import
|
36
|
+
import "../stylesheets/application.scss";
|
37
37
|
|
38
38
|
$(document).ready(() => {
|
39
|
-
$("[data-toggle=tooltip]").tooltip()
|
40
|
-
})
|
39
|
+
$("[data-toggle=tooltip]").tooltip();
|
40
|
+
});
|
@@ -0,0 +1,61 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
import ConfigField from "./config_field";
|
4
|
+
|
5
|
+
const AwsCredential = {
|
6
|
+
template: "#vue-aws-credential",
|
7
|
+
components: {
|
8
|
+
"config-field": ConfigField,
|
9
|
+
},
|
10
|
+
props: [
|
11
|
+
"id",
|
12
|
+
"pluginType",
|
13
|
+
"pluginName",
|
14
|
+
],
|
15
|
+
data: () => {
|
16
|
+
return {
|
17
|
+
credentialType: null,
|
18
|
+
credentialOptions: [],
|
19
|
+
options: [
|
20
|
+
"simple",
|
21
|
+
"assumeRoleCredentials",
|
22
|
+
"instanceProfileCredentials",
|
23
|
+
"sharedCredentials"
|
24
|
+
]
|
25
|
+
};
|
26
|
+
},
|
27
|
+
|
28
|
+
computed: {
|
29
|
+
token: function() {
|
30
|
+
return Rails.csrfToken();
|
31
|
+
}
|
32
|
+
},
|
33
|
+
|
34
|
+
mounted: function() {
|
35
|
+
|
36
|
+
},
|
37
|
+
|
38
|
+
methods: {
|
39
|
+
onChange: function() {
|
40
|
+
this.updateSection();
|
41
|
+
},
|
42
|
+
|
43
|
+
updateSection: function() {
|
44
|
+
$.ajax({
|
45
|
+
method: "GET",
|
46
|
+
url: "/api/config_definitions",
|
47
|
+
headers: {
|
48
|
+
"X-CSRF-Token": this.token
|
49
|
+
},
|
50
|
+
data: {
|
51
|
+
type: this.pluginType,
|
52
|
+
name: this.pluginName
|
53
|
+
}
|
54
|
+
}).then((data) => {
|
55
|
+
this.credentialOptions = data["awsCredentialOptions"][this.credentialType];
|
56
|
+
});
|
57
|
+
}
|
58
|
+
}
|
59
|
+
};
|
60
|
+
|
61
|
+
export { AwsCredential as default };
|
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
/* global _ */
|
2
|
+
"use strict";
|
3
|
+
import CodeMirror from "codemirror/lib/codemirror";
|
4
|
+
import "lodash/lodash";
|
3
5
|
|
4
6
|
// See: http://codemirror.net/doc/manual.html#modeapi
|
5
7
|
// and sample mode files: https://github.com/codemirror/CodeMirror/tree/master/mode
|
6
8
|
|
7
|
-
CodeMirror.defineMode(
|
9
|
+
CodeMirror.defineMode("fluentd", function(){
|
8
10
|
return {
|
9
11
|
startState: function(aa){
|
10
12
|
return { "context" : null };
|
@@ -21,40 +23,34 @@ CodeMirror.defineMode('fluentd', function(){
|
|
21
23
|
}
|
22
24
|
|
23
25
|
switch(stream.peek()){
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
case "#":
|
27
|
+
stream.skipToEnd();
|
28
|
+
return "comment";
|
29
|
+
case "<":
|
30
|
+
state.context = "inner-bracket";
|
31
|
+
stream.pos += 1;
|
32
|
+
return "keyword";
|
33
|
+
case ">":
|
34
|
+
stream.pos += 1;
|
35
|
+
state.context = "inner-definition";
|
36
|
+
return "keyword";
|
37
|
+
default:
|
38
|
+
switch(state.context){
|
39
|
+
case "inner-bracket":
|
40
|
+
stream.eat(/[^#<>]+/);
|
31
41
|
return "keyword";
|
32
|
-
|
33
|
-
|
34
|
-
|
42
|
+
case "inner-definition":
|
43
|
+
stream.eatWhile(/[^ \t#]/);
|
44
|
+
state.context = "inner-definition-keyword-appeared";
|
45
|
+
return "variable";
|
46
|
+
case "inner-definition-keyword-appeared":
|
47
|
+
stream.eatWhile(/[^#]/);
|
35
48
|
state.context = "inner-definition";
|
36
|
-
return "
|
37
|
-
break;
|
49
|
+
return "builtin";
|
38
50
|
default:
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
return "keyword";
|
43
|
-
break;
|
44
|
-
case "inner-definition":
|
45
|
-
var key = stream.eatWhile(/[^ \t#]/);
|
46
|
-
state.context = "inner-definition-keyword-appeared";
|
47
|
-
return "variable";
|
48
|
-
break;
|
49
|
-
case "inner-definition-keyword-appeared":
|
50
|
-
var key = stream.eatWhile(/[^#]/);
|
51
|
-
state.context = "inner-definition";
|
52
|
-
return "builtin";
|
53
|
-
break;
|
54
|
-
default:
|
55
|
-
stream.eat(/[^<>#]+/);
|
56
|
-
return "string";
|
57
|
-
}
|
51
|
+
stream.eat(/[^<>#]+/);
|
52
|
+
return "string";
|
53
|
+
}
|
58
54
|
}
|
59
55
|
}
|
60
56
|
};
|
@@ -70,18 +66,18 @@ function codemirrorify(el) {
|
|
70
66
|
}
|
71
67
|
|
72
68
|
$(function(){
|
73
|
-
$(
|
69
|
+
$(".js-fluentd-config-editor").each(function(_, el){
|
74
70
|
codemirrorify(el);
|
75
71
|
});
|
76
72
|
});
|
77
73
|
|
78
|
-
Vue.directive(
|
74
|
+
Vue.directive("config-editor", {
|
79
75
|
bind: function(el, binding, vnode, oldVnode){
|
80
76
|
// NOTE: needed delay for waiting CodeMirror setup
|
81
77
|
_.delay(function(textarea){
|
82
78
|
let cm = codemirrorify(textarea);
|
83
79
|
// textarea.codemirror = cm; // for test, but doesn't work for now (working on Chrome, but Poltergeist not)
|
84
|
-
cm.on(
|
80
|
+
cm.on("change", function(code_mirror){
|
85
81
|
// bridge Vue - CodeMirror world
|
86
82
|
el.dataset.content = code_mirror.getValue();
|
87
83
|
});
|
@@ -0,0 +1,93 @@
|
|
1
|
+
/* global _ */
|
2
|
+
"use strict";
|
3
|
+
import "lodash/lodash";
|
4
|
+
|
5
|
+
const ConfigField = {
|
6
|
+
template: "#vue-config-field",
|
7
|
+
props: [
|
8
|
+
"pluginType",
|
9
|
+
"option",
|
10
|
+
"initialExpression",
|
11
|
+
"initialTimeFormat",
|
12
|
+
"initialTextValue",
|
13
|
+
],
|
14
|
+
|
15
|
+
data: function() {
|
16
|
+
return {
|
17
|
+
expression: null,
|
18
|
+
timeFormat: null,
|
19
|
+
textValue: null,
|
20
|
+
};
|
21
|
+
},
|
22
|
+
|
23
|
+
filters: {
|
24
|
+
humanize: function(value) {
|
25
|
+
return _.capitalize(value.replace(/_/g, " "));
|
26
|
+
}
|
27
|
+
},
|
28
|
+
|
29
|
+
mounted: function() {
|
30
|
+
if (this.option.name === "expression") {
|
31
|
+
this.expression = this.initialExpression;
|
32
|
+
} else if (this.option.name === "time_format") {
|
33
|
+
this.timeFormat = this.initialTimeFormat;
|
34
|
+
} else {
|
35
|
+
this.textValue = this.initialTextValue || this.option.default;
|
36
|
+
}
|
37
|
+
},
|
38
|
+
|
39
|
+
updated: function() {
|
40
|
+
if (this.option.name === "expression") {
|
41
|
+
this.expression = this.initialExpression;
|
42
|
+
}
|
43
|
+
if (this.option.name === "time_format") {
|
44
|
+
this.timeFormat = this.initialTimeFormat;
|
45
|
+
}
|
46
|
+
this.$nextTick(() => {
|
47
|
+
console.log("config-field updated");
|
48
|
+
$("[data-toggle=tooltip]").tooltip("dispose");
|
49
|
+
$("[data-toggle=tooltip]").tooltip("enable");
|
50
|
+
});
|
51
|
+
},
|
52
|
+
|
53
|
+
watch: {
|
54
|
+
"expression": function(_newValue, _oldValue) {
|
55
|
+
this.$emit("change-parse-config", {
|
56
|
+
"expression": this.expression,
|
57
|
+
"timeFormat": this.timeFormat
|
58
|
+
});
|
59
|
+
},
|
60
|
+
"timeFormat": function(_newValue, _oldValue) {
|
61
|
+
this.$emit("change-parse-config", {
|
62
|
+
"expression": this.expression,
|
63
|
+
"timeFormat": this.timeFormat
|
64
|
+
});
|
65
|
+
}
|
66
|
+
},
|
67
|
+
|
68
|
+
methods: {
|
69
|
+
inputId: function(pluginType, option) {
|
70
|
+
if (pluginType === "output") {
|
71
|
+
return `setting_${option.name}`;
|
72
|
+
} else {
|
73
|
+
return `setting_${_.snakeCase(pluginType)}_0__${option.name}`;
|
74
|
+
}
|
75
|
+
},
|
76
|
+
inputName: function(pluginType, option) {
|
77
|
+
if (pluginType === "output") {
|
78
|
+
return `setting[${option.name}]`;
|
79
|
+
} else {
|
80
|
+
return `setting[${_.snakeCase(pluginType)}[0]][${option.name}]`;
|
81
|
+
}
|
82
|
+
},
|
83
|
+
checked: function(checked) {
|
84
|
+
if (checked === true || checked === "true") {
|
85
|
+
return "checked";
|
86
|
+
} else {
|
87
|
+
return "";
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
91
|
+
};
|
92
|
+
|
93
|
+
export { ConfigField as default };
|
@@ -1,15 +1,22 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
$(document).ready(()=> {
|
3
3
|
new Vue({
|
4
4
|
el: "#fluent-log",
|
5
|
-
props: ["logUrl", "initialAutoReload"],
|
6
5
|
data: {
|
6
|
+
"logUrl": "",
|
7
|
+
"initialAutoReload": false,
|
7
8
|
"autoFetch": false,
|
8
9
|
"logs": [],
|
9
10
|
"limit": 30,
|
10
11
|
"processing": false
|
11
12
|
},
|
12
13
|
|
14
|
+
computed: {
|
15
|
+
isPresentedLogs: function(){
|
16
|
+
return this.logs.length > 0;
|
17
|
+
}
|
18
|
+
},
|
19
|
+
|
13
20
|
beforeMount: function() {
|
14
21
|
this.logUrl = this.$el.attributes.logUrl.nodeValue;
|
15
22
|
this.initialAutoReload = this.$el.attributes.initialAutoReload.nodeValue;
|
@@ -36,12 +43,6 @@ $(document).ready(()=> {
|
|
36
43
|
}
|
37
44
|
},
|
38
45
|
|
39
|
-
computed: {
|
40
|
-
isPresentedLogs: function(){
|
41
|
-
return this.logs.length > 0;
|
42
|
-
}
|
43
|
-
},
|
44
|
-
|
45
46
|
methods: {
|
46
47
|
fetchLogs: function() {
|
47
48
|
if(this.processing) return;
|
@@ -54,7 +55,7 @@ $(document).ready(()=> {
|
|
54
55
|
setTimeout(function(){
|
55
56
|
self.processing = false;
|
56
57
|
}, 256); // delay to reduce flicking loading icon
|
57
|
-
})["catch"](function(
|
58
|
+
})["catch"](function(_error){
|
58
59
|
self.processing = false;
|
59
60
|
});
|
60
61
|
}
|
@@ -1,136 +1,137 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import
|
1
|
+
/* global _ */
|
2
|
+
"use strict";
|
3
|
+
import "lodash/lodash";
|
4
|
+
import "popper.js/dist/popper";
|
5
|
+
import "bootstrap/dist/js/bootstrap";
|
6
|
+
import OwnedPluginForm from "./owned_plugin_form";
|
6
7
|
|
7
8
|
$(document).ready(() => {
|
8
9
|
new Vue({
|
9
|
-
el:
|
10
|
-
|
11
|
-
"
|
12
|
-
|
13
|
-
],
|
10
|
+
el: "#in-tail-parse",
|
11
|
+
components: {
|
12
|
+
"owned-plugin-form": OwnedPluginForm
|
13
|
+
},
|
14
14
|
data: function() {
|
15
15
|
return {
|
16
|
-
|
17
|
-
|
16
|
+
"path": "",
|
17
|
+
"parseType": "",
|
18
|
+
"highlightedLines": null
|
19
|
+
};
|
18
20
|
},
|
19
21
|
computed: {
|
20
22
|
token: function() {
|
21
|
-
return Rails.csrfToken()
|
23
|
+
return Rails.csrfToken();
|
22
24
|
}
|
23
25
|
},
|
24
|
-
components: {
|
25
|
-
'owned-plugin-form': OwnedPluginForm
|
26
|
-
},
|
27
26
|
watch: {
|
28
|
-
|
29
|
-
console.log(`parse.expression: ${this.parse.expression}`)
|
30
|
-
this.preview()
|
27
|
+
"parse.expression": function() {
|
28
|
+
console.log(`parse.expression: ${this.parse.expression}`);
|
29
|
+
this.preview();
|
31
30
|
},
|
32
|
-
|
33
|
-
console.log(`parse.time_format: ${this.parse.time_format}`)
|
34
|
-
this.preview()
|
31
|
+
"parse.time_format": function() {
|
32
|
+
console.log(`parse.time_format: ${this.parse.time_format}`);
|
33
|
+
this.preview();
|
35
34
|
},
|
36
|
-
|
37
|
-
this.preview()
|
35
|
+
"parseType": function() {
|
36
|
+
this.preview();
|
38
37
|
},
|
39
38
|
},
|
40
39
|
beforeMount: function() {
|
41
40
|
this.path = this.$el.attributes.path.nodeValue;
|
42
41
|
},
|
43
42
|
mounted: function() {
|
44
|
-
this.parse = {}
|
43
|
+
this.parse = {};
|
45
44
|
this.$on("hook:updated", () => {
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
this.$nextTick(() => {
|
46
|
+
$("[data-toggle=tooltip]").tooltip("dispose");
|
47
|
+
$("[data-toggle=tooltip]").tooltip("enable");
|
48
|
+
});
|
49
|
+
});
|
49
50
|
},
|
50
51
|
methods: {
|
51
52
|
onChangePluginName: function(name) {
|
52
|
-
console.log("onChangePluginName")
|
53
|
-
this.parseType = name
|
54
|
-
this.parse = {} // clear parser plugin configuration
|
53
|
+
console.log("#in-tail-parse onChangePluginName", name);
|
54
|
+
this.parseType = name;
|
55
|
+
this.parse = {}; // clear parser plugin configuration
|
55
56
|
},
|
56
57
|
onChangeParseConfig: function(data) {
|
57
|
-
console.log("onChangeParseConfig", data)
|
58
|
-
_.merge(this.parse, data)
|
59
|
-
this.preview()
|
58
|
+
console.log("#in-tail-parse onChangeParseConfig", data);
|
59
|
+
_.merge(this.parse, data);
|
60
|
+
this.preview();
|
60
61
|
},
|
61
62
|
onChangeFormats: function(data) {
|
62
|
-
console.log("in_tail_parse:onChangeFormats", data)
|
63
|
-
_.merge(this.parse, data)
|
64
|
-
this.preview()
|
63
|
+
console.log("in_tail_parse:onChangeFormats", data);
|
64
|
+
_.merge(this.parse, data);
|
65
|
+
this.preview();
|
65
66
|
},
|
66
67
|
updateHighlightedLines: function(matches) {
|
67
68
|
if (!matches) {
|
68
|
-
this.highlightedLines = null
|
69
|
-
return
|
69
|
+
this.highlightedLines = null;
|
70
|
+
return;
|
70
71
|
}
|
71
72
|
|
72
|
-
let $container = $(
|
73
|
+
let $container = $("<div>");
|
73
74
|
_.each(matches, (match) => {
|
74
|
-
const colors = ["#ff9", "#cff", "#fcf", "#dfd"]
|
75
|
-
const whole = match.whole
|
76
|
-
let html = ""
|
77
|
-
let _matches = []
|
78
|
-
let lastPos = 0
|
75
|
+
const colors = ["#ff9", "#cff", "#fcf", "#dfd"];
|
76
|
+
const whole = match.whole;
|
77
|
+
let html = "";
|
78
|
+
let _matches = [];
|
79
|
+
let lastPos = 0;
|
79
80
|
|
80
81
|
_.each(match.matches, (m) => {
|
81
|
-
let matched = m.matched
|
82
|
+
let matched = m.matched;
|
82
83
|
if (!matched) {
|
83
|
-
return
|
84
|
+
return;
|
84
85
|
}
|
85
86
|
// Ignore empty matched with "foobar".match(/foo(.*?)bar/)[1] #=> ""
|
86
87
|
if (matched.length === 0) {
|
87
|
-
return
|
88
|
+
return;
|
88
89
|
}
|
89
90
|
// rotate color
|
90
|
-
let currentColor = colors.shift()
|
91
|
-
colors.push(currentColor)
|
91
|
+
let currentColor = colors.shift();
|
92
|
+
colors.push(currentColor);
|
92
93
|
|
93
94
|
// create highlighted range HTML
|
94
|
-
let $highlighted = $("<span>").text(matched)
|
95
|
+
let $highlighted = $("<span>").text(matched);
|
95
96
|
$highlighted.attr({
|
96
97
|
"class": "regexp-preview",
|
97
98
|
"data-toggle": "tooltip",
|
98
99
|
"data-placement": "top",
|
99
100
|
"title": m.key,
|
100
|
-
|
101
|
-
})
|
102
|
-
let highlightedHtml = $highlighted.wrap("<div>").parent().html()
|
101
|
+
"style": "background-color:" + currentColor
|
102
|
+
});
|
103
|
+
let highlightedHtml = $highlighted.wrap("<div>").parent().html();
|
103
104
|
let pos = {
|
104
105
|
start: m.pos[0],
|
105
106
|
end: m.pos[1]
|
106
|
-
}
|
107
|
+
};
|
107
108
|
if (pos.start > 0) {
|
108
|
-
html += _.escape(whole.substring(lastPos, pos.start))
|
109
|
+
html += _.escape(whole.substring(lastPos, pos.start));
|
109
110
|
}
|
110
|
-
html += highlightedHtml
|
111
|
-
lastPos = pos.end
|
112
|
-
})
|
113
|
-
html += whole.substring(lastPos)
|
111
|
+
html += highlightedHtml;
|
112
|
+
lastPos = pos.end;
|
113
|
+
});
|
114
|
+
html += whole.substring(lastPos);
|
114
115
|
|
115
|
-
$container.append(html)
|
116
|
-
$container.append("<br>")
|
117
|
-
})
|
116
|
+
$container.append(html);
|
117
|
+
$container.append("<br>");
|
118
|
+
});
|
118
119
|
|
119
|
-
this.highlightedLines = $container.html()
|
120
|
-
this.$emit("hook:updated")
|
120
|
+
this.highlightedLines = $container.html();
|
121
|
+
this.$emit("hook:updated");
|
121
122
|
},
|
122
123
|
|
123
124
|
preview: function() {
|
124
|
-
console.log("preview!!!!")
|
125
|
+
console.log("preview!!!!");
|
125
126
|
if (this.previewAjax && this.previewAjax.state() === "pending") {
|
126
|
-
this.previewAjax.abort()
|
127
|
+
this.previewAjax.abort();
|
127
128
|
}
|
128
129
|
|
129
130
|
this.previewAjax = $.ajax({
|
130
131
|
method: "POST",
|
131
132
|
url: "/api/regexp_preview",
|
132
133
|
headers: {
|
133
|
-
|
134
|
+
"X-CSRF-Token": this.token
|
134
135
|
},
|
135
136
|
data: {
|
136
137
|
parse_type: _.isEmpty(this.parseType) ? "regexp" : this.parseType,
|
@@ -140,20 +141,20 @@ $(document).ready(() => {
|
|
140
141
|
}).then(
|
141
142
|
(result) => {
|
142
143
|
if (result.matches) {
|
143
|
-
this.updateHighlightedLines(result.matches)
|
144
|
+
this.updateHighlightedLines(result.matches);
|
144
145
|
} else {
|
145
|
-
console.error(result.error)
|
146
|
-
this.previewError = result.error
|
146
|
+
console.error(result.error);
|
147
|
+
this.previewError = result.error;
|
147
148
|
}
|
148
149
|
},
|
149
150
|
(error) => {
|
150
|
-
this.highlightedLines = null
|
151
|
+
this.highlightedLines = null;
|
151
152
|
// console.error(error.responseText)
|
152
153
|
if (error.stack) {
|
153
|
-
console.error(error.stack)
|
154
|
+
console.error(error.stack);
|
154
155
|
}
|
155
|
-
})
|
156
|
+
});
|
156
157
|
}
|
157
158
|
}
|
158
|
-
})
|
159
|
-
})
|
159
|
+
});
|
160
|
+
});
|