fluentd-ui/app/javascript/packs/config_field.js
Kenji Okimoto 2be60eec62
Add updated hook to set expression and time_format
Set expression and timeFormat properly if selected parseType is changed.

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
2018-06-20 10:05:25 +09:00

89 lines
2.0 KiB
JavaScript

'use strict'
import 'lodash/lodash'
const ConfigField = {
template: "#vue-config-field",
props: [
"pluginType",
"option",
"initialExpression",
"initialTimeFormat",
],
data: function() {
return {
expression: null,
timeFormat: null
}
},
filters: {
humanize: function(value) {
return _.capitalize(value.replace("_", " "))
}
},
mounted: function() {
if (this.option.name === "expression") {
this.expression = this.initialExpression
}
if (this.option.name === "time_format") {
this.timeFormat = this.initialTimeFormat
}
this.$on("hook:updated", () => {
this.$nextTick(() => {
console.log("config-field hook:updated")
$("[data-toggle=tooltip]").tooltip("dispose")
$("[data-toggle=tooltip]").tooltip("enable")
})
})
},
updated: function() {
if (this.option.name === "expression") {
this.expression = this.initialExpression
}
if (this.option.name === "time_format") {
this.timeFormat = this.initialTimeFormat
}
this.$nextTick(() => {
console.log("config-field updated")
$("[data-toggle=tooltip]").tooltip("dispose")
$("[data-toggle=tooltip]").tooltip("enable")
})
},
watch: {
"expression": function(newValue, oldValue) {
this.$emit("change-parse-config", {
"expression": this.expression,
"timeFormat": this.timeFormat
})
},
"timeFormat": function(newValue, oldValue) {
this.$emit("change-parse-config", {
"expression": this.expression,
"timeFormat": this.timeFormat
})
}
},
methods: {
inputId: function(pluginType, option) {
return `setting_${pluginType}_0__${option.name}`
},
inputName: function(pluginType, option) {
return `setting[${pluginType}[0]][${option.name}]`
},
checked: function(checked) {
if (checked === true || checked === "true") {
return "checked"
} else {
return ""
}
}
}
}
export { ConfigField as default }