Handle adding/removing grep-container properly

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
This commit is contained in:
Kenji Okimoto 2018-09-12 14:37:42 +09:00
parent 85b0ff71fc
commit dceed5493d
No known key found for this signature in database
GPG Key ID: F9E3E329A5C5E4A1
2 changed files with 22 additions and 17 deletions

View File

@ -1,4 +1,6 @@
/* global _ */
"use strict"; "use strict";
import "lodash/lodash";
import GrepContainer from "./grep_container"; import GrepContainer from "./grep_container";
@ -10,7 +12,10 @@ $(document).ready(() => {
}, },
data: function() { data: function() {
return { return {
index: 0 containers: {
and: [true],
or: [true]
}
}; };
}, },
mounted: function() { mounted: function() {
@ -19,10 +24,16 @@ $(document).ready(() => {
}, },
methods: { methods: {
addGrepContainer: function(containerType, index) { addGrepContainer: function(containerType, index) {
this.index += 1; let found = this.containers[containerType].indexOf(false);
if (found < 0) {
this.$set(this.containers[containerType], this.containers[containerType].length, true);
} else {
this.$set(this.containers[containerType], found, true);
}
}, },
removeGrepContainer: function(containerType, index) { removeGrepContainer: function(containerType, index) {
this.index -= 1; this.$set(this.containers[containerType], index, false);
} }
} }
}); });

View File

@ -3,21 +3,15 @@
= render "shared/vue/grep_container" = render "shared/vue/grep_container"
#filter-grep-setting #filter-grep-setting
%grep-container{"v-bind:container-type" => '"and"', %template{"v-for" => "(enabled, i) in containers.and"}
"v-bind:index" => "0", %grep-container{"v-if" => "enabled",
"v-bind:container-type" => '"and"',
"v-bind:index" => "i",
"v-on:add-grep-container" => "addGrepContainer", "v-on:add-grep-container" => "addGrepContainer",
"v-on:remove-grep-container" => "removeGrepContainer"} "v-on:remove-grep-container" => "removeGrepContainer"}
%template{"v-for" => "n in index"} %template{"v-for" => "(enabled, i) in containers.or"}
%grep-container{"v-bind:container-type" => '"and"', %grep-container{"v-if" => "enabled",
"v-bind:index" => "n", "v-bind:container-type" => '"or"',
"v-on:add-grep-container" => "addGrepContainer", "v-bind:index" => "i",
"v-on:remove-grep-container" => "removeGrepContainer"}
%grep-container{"v-bind:container-type" => '"or"',
"v-bind:index" => "0",
"v-on:add-grep-container" => "addGrepContainer",
"v-on:remove-grep-container" => "removeGrepContainer"}
%template{"v-for" => "n in index"}
%grep-container{"v-bind:container-type" => '"or"',
"v-bind:index" => "n",
"v-on:add-grep-container" => "addGrepContainer", "v-on:add-grep-container" => "addGrepContainer",
"v-on:remove-grep-container" => "removeGrepContainer"} "v-on:remove-grep-container" => "removeGrepContainer"}