diff --git a/app/controllers/api/settings_controller.rb b/app/controllers/api/settings_controller.rb index 3661513..0002c09 100644 --- a/app/controllers/api/settings_controller.rb +++ b/app/controllers/api/settings_controller.rb @@ -12,16 +12,22 @@ class Api::SettingsController < ApplicationController end def update + label_name = params[:label] coming = Fluent::Config::V1Parser.parse(params[:content], @fluentd.config_file) - current = @target_element - index = @config.elements.index current - unless index + coming_element = coming.elements.first + + unless @target_element render_404 return end - @config.elements[index] = coming.elements.first + + @target_element.elements = coming_element.elements + @target_element.merge(coming_element) + @config.write_to_file - redirect_to api_setting_path(id: element_id(coming.elements.first)) + redirect_to api_setting_path(id: element_id(label_name, @target_element), + label: label_name, + pluginType: params[:pluginType]) end def destroy diff --git a/app/javascript/packs/settings.js b/app/javascript/packs/settings.js index 6ba131a..f6150b0 100644 --- a/app/javascript/packs/settings.js +++ b/app/javascript/packs/settings.js @@ -7,7 +7,7 @@ $(document).ready(() => { const SettingSection = { template: "#vue-setting-section", props: [ - "label", + "initialLabel", "initialId", "initialContent", "initialType", @@ -18,6 +18,7 @@ $(document).ready(() => { return { mode: "default", processing: false, + current_label: null, id: null, content: null, type: null, @@ -27,6 +28,7 @@ $(document).ready(() => { }, created: function() { this.initialState(); + this.current_label = this.initialLabel; this.id = this.initialId; this.content = this.initialContent; this.type = this.initialType; @@ -62,6 +64,8 @@ $(document).ready(() => { method: "POST", data: { _method: "PATCH", + label: this.current_label, + pluginType: this.name, id: this.id, content: this.content }, @@ -87,7 +91,7 @@ $(document).ready(() => { method: "POST", data: { _method: "DELETE", - label: this.label, + label: this.current_label, pluginType: this.name, arg: this.arg, id: this.id, diff --git a/app/views/api/settings/show.json.jbuilder b/app/views/api/settings/show.json.jbuilder index a4e3486..5fe9438 100644 --- a/app/views/api/settings/show.json.jbuilder +++ b/app/views/api/settings/show.json.jbuilder @@ -1 +1 @@ -json.partial! "api/settings/element", element: @section +json.partial! "api/settings/element", current_label: params[:label], element: @target_element diff --git a/app/views/fluentd/settings/source_and_output.html.haml b/app/views/fluentd/settings/source_and_output.html.haml index 44fce6c..aab5e70 100644 --- a/app/views/fluentd/settings/source_and_output.html.haml +++ b/app/views/fluentd/settings/source_and_output.html.haml @@ -61,7 +61,7 @@ %setting-section{"v-if" => "loaded && elements.sources && elements.sources.length > 0", "v-for" => "source in elements.sources", "v-bind:key" => "source.id", - "v-bind:label" => "source.current_label", + "v-bind:initial-label" => "source.current_label", "v-bind:initial-id" => "source.id", "v-bind:initial-content" => "source.content", "v-bind:initial-type" => "source.type", @@ -74,7 +74,7 @@ %setting-section{"v-if" => "loaded && elements.filters.length > 0", "v-for" => "filter in elements.filters", "v-bind:key" => "filter.id", - "v-bind:label" => "filter.current_label", + "v-bind:initial-label" => "filter.current_label", "v-bind:initial-id" => "filter.id", "v-bind:initial-content" => "filter.content", "v-bind:initial-type" => "filter.type", @@ -88,7 +88,7 @@ %setting-section{"v-if" => "loaded && elements.matches.length > 0", "v-for" => "match in elements.matches", "v-bind:key" => "match.id", - "v-bind:label" => "match.current_label", + "v-bind:initial-label" => "match.current_label", "v-bind:initial-id" => "match.id", "v-bind:initial-content" => "match.content", "v-bind:initial-type" => "match.type", diff --git a/app/views/shared/vue/_setting.html.erb b/app/views/shared/vue/_setting.html.erb index 71b25c9..0ce8e9b 100644 --- a/app/views/shared/vue/_setting.html.erb +++ b/app/views/shared/vue/_setting.html.erb @@ -11,7 +11,7 @@
{{ content }}

- +