diff --git a/app/assets/javascripts/vue/settings.js b/app/assets/javascripts/vue/settings.js index 4aed4bf..184d3d0 100644 --- a/app/assets/javascripts/vue/settings.js +++ b/app/assets/javascripts/vue/settings.js @@ -19,7 +19,68 @@ }, components: { section: { - template: "#vue-setting-section" + template: "#vue-setting-section", + data: { + mode: "default", + processing: false, + editContent: null + }, + created: function(){ + this.initialState(); + }, + computed: { + endpoint: function(){ + return "/api/settings/" + this.id; + } + }, + methods: { + onCancel: function(ev) { + this.initialState(); + }, + onEdit: function(ev) { + this.mode = "edit"; + }, + onDelete: function(ev) { + if(!confirm("really?")) return; + this.destroy(); + }, + onSubmit: function(ev) { + this.processing = true; + var self = this; + $.ajax({ + url: this.endpoint, + method: "POST", + data: { + _method: "PATCH", + id: this.id, + content: this.editContent + } + }).then(function(data){ + // NOTE: child VM update doesn't effect to parent VM (at least Vue v0.10) + self.$data = data; + self.initialState(); + }).always(function(){ + self.processing = false; + }); + }, + initialState: function(){ + this.mode = "default"; + this.editContent = this.content; + }, + destroy: function(){ + var self = this; + $.ajax({ + url: this.endpoint, + method: "POST", + data: { + _method: "DELETE", + id: this.id + } + }).then(function(){ + self.$destroy(); + }); + } + } } }, methods: { diff --git a/app/assets/stylesheets/common.css.scss b/app/assets/stylesheets/common.css.scss index b60b47f..1cbe18f 100644 --- a/app/assets/stylesheets/common.css.scss +++ b/app/assets/stylesheets/common.css.scss @@ -150,3 +150,9 @@ label { .nav > li > a.section { color: #777; } + + +#vue-setting textarea { + min-height: 12em; + resize: both; +} diff --git a/app/controllers/api/settings_controller.rb b/app/controllers/api/settings_controller.rb index 8a6f68c..467e09a 100644 --- a/app/controllers/api/settings_controller.rb +++ b/app/controllers/api/settings_controller.rb @@ -10,12 +10,12 @@ class Api::SettingsController < ApplicationController end def update - coming = Fluent::Config::V1Parser.parse(params[:body], @fluentd.config_file) + coming = Fluent::Config::V1Parser.parse(params[:content], @fluentd.config_file) current = @section index = @config.elements.index current @config.elements[index] = coming.elements.first @config.write_to_file - head :no_content # 204 + redirect_to api_setting_path(id: element_id(coming.elements.first)) end def destroy diff --git a/app/views/shared/vue/_setting.html.erb b/app/views/shared/vue/_setting.html.erb index 61726ef..ed23cce 100644 --- a/app/views/shared/vue/_setting.html.erb +++ b/app/views/shared/vue/_setting.html.erb @@ -7,7 +7,16 @@
{{ content }}
+ {{ content }}
+ + +
++ + + + +