16
16
span( v-if ="_class.rule.type === 'regex'" ) Rule ({{_class.rule.type}}): #[ code {{_class.rule.regex }}]
17
17
span( v-else , style ="color: #888" ) No rule
18
18
span.float-right
19
- b-btn.ml-1 ( size ="sm" , variant ="outline-secondary" , @click ="showEditModal()" style ="border: 0;" pill )
19
+ b-btn.ml-1 ( size ="sm" , variant ="outline-secondary" , @click ="showEditModal(_class.id )" style ="border: 0;" pill )
20
20
icon( name ="edit" )
21
21
b-btn.ml-1 ( size ="sm" , variant ="outline-success" , @click ="addSubclass(_class); expanded = true" style ="border: 0;" pill )
22
22
icon( name ="plus" )
23
23
div
24
24
div.pa-2 ( v-for ="child in _class.children" , style ="background: rgba(0, 0, 0, 0);" , v-show ="expanded" )
25
25
CategoryEditTree( :_class ="child" , :depth ="depth+1" )
26
26
27
- b-modal( id ="edit" ref ="edit" title ="Edit category" @show ="resetModal" @hidden ="resetModal" @ok ="handleOk" )
28
- div.my-1
29
- b-input-group.my-1 ( prepend ="Name" )
30
- b-form-input( v-model ="editing.name" )
31
- b-input-group( prepend ="Parent" )
32
- b-select( v-model ="editing.parent" , :options ="allCategories" )
33
-
34
- hr
35
-
36
- div.my-1
37
- b Rule
38
- b-input-group.my-1 ( prepend ="Type" )
39
- b-select( v-model ="editing.rule.type" , :options ="allRuleTypes" )
40
- div( v-if ="editing.rule.type === 'regex'" )
41
- b-input-group.my-1 ( prepend ="Pattern" )
42
- b-form-input( v-model ="editing.rule.regex" )
43
- b-form-checkbox( v-model ="editing.rule.ignore_case" switch )
44
- | Ignore case
45
-
46
- hr
47
-
48
- div.my-1
49
- b Color
50
-
51
- b-form-checkbox( v-model ="editing.inherit_color" switch )
52
- | Inherit parent color
53
- div.mt-1 ( v-show ="!editing.inherit_color" )
54
- color-picker( v-model ="editing.color" )
55
-
56
- //
57
- div.my-1
58
- b Productivity score
59
- b-input-group.my-1(prepend="Points")
60
- b-form-input(v-model="editing.productivity")
61
-
62
- hr
63
-
64
- div.my-1
65
- b-btn( variant ="danger" , @click ="removeClass(_class); $refs.edit.hide()" )
66
- icon( name ="trash" )
67
- | Remove category
27
+ div( v-if ="editingId !== null" )
28
+ CategoryEditModal( :categoryId ='editingId' , @hidden ="hideEditModal()" )
68
29
</template >
69
30
70
31
<script >
@@ -76,14 +37,14 @@ import 'vue-awesome/icons/trash';
76
37
import ' vue-awesome/icons/plus' ;
77
38
import ' vue-awesome/icons/edit' ;
78
39
79
- import ColorPicker from ' ~/components/ColorPicker ' ;
40
+ import CategoryEditModal from ' ./CategoryEditModal.vue ' ;
80
41
81
42
import _ from ' lodash' ;
82
43
83
44
export default {
84
45
name: ' CategoryEditTree' ,
85
46
components: {
86
- ' color-picker ' : ColorPicker ,
47
+ CategoryEditModal : CategoryEditModal ,
87
48
},
88
49
props: {
89
50
_class: Object ,
@@ -95,32 +56,10 @@ export default {
95
56
data : function () {
96
57
return {
97
58
expanded: this .depth < 1 ,
98
- color_focused: false ,
99
- editing: {
100
- id: 0 , // FIXME: Use ID assigned to category in vuex store, in order for saves to be uniquely targeted
101
- name: null ,
102
- rule: {},
103
- parent: [],
104
- inherit_color: true ,
105
- color: null ,
106
- },
59
+ editingId: null ,
107
60
};
108
61
},
109
62
computed: {
110
- allCategories : function () {
111
- const categories = this .$store .getters [' categories/all_categories' ];
112
- const entries = categories .map (c => {
113
- return { text: c .join (' ->' ), value: c };
114
- });
115
- return [{ value: [], text: ' None' }].concat (entries);
116
- },
117
- allRuleTypes : function () {
118
- return [
119
- { value: null , text: ' None' },
120
- { value: ' regex' , text: ' Regular Expression' },
121
- // { value: 'glob', text: 'Glob pattern' },
122
- ];
123
- },
124
63
totalChildren : function () {
125
64
function countChildren (node ) {
126
65
return node .children .length + _ .sum (_ .map (node .children , countChildren));
@@ -134,58 +73,16 @@ export default {
134
73
name: parent .name .concat ([' New class' ]),
135
74
rule: { type: ' regex' , regex: ' FILL ME' },
136
75
});
137
- },
138
- removeClass : function (_class ) {
139
- // TODO: Show a confirmation dialog
140
- // TODO: Remove children as well?
141
- // TODO: Move button to edit modal?
142
- this .$store .commit (' categories/removeClass' , _class);
143
- },
144
- showEditModal () {
145
- this .$refs .edit .show ();
146
- },
147
- checkFormValidity () {
148
- // FIXME
149
- return true ;
150
- },
151
- handleOk (event ) {
152
- // Prevent modal from closing
153
- event .preventDefault ();
154
- // Trigger submit handler
155
- this .handleSubmit ();
156
- },
157
- handleSubmit () {
158
- // Exit when the form isn't valid
159
- if (! this .checkFormValidity ()) {
160
- return ;
161
- }
162
-
163
- // Save the category
164
- const new_class = {
165
- id: this .editing .id ,
166
- name: this .editing .parent .concat (this .editing .name ),
167
- rule: this .editing .rule .type !== null ? this .editing .rule : { type: null },
168
- data: { color: this .editing .inherit_color === true ? undefined : this .editing .color },
169
- };
170
- this .$store .commit (' categories/updateClass' , new_class);
171
76
172
- // Hide the modal manually
173
- this .$nextTick (() => {
174
- this .$refs .edit .hide ();
175
- });
77
+ // Find the category with the max ID, and open an editor for it
78
+ const lastId = _ .max (_ .map (this .$store .state .categories .classes , ' id' ));
79
+ this .editingId = lastId;
80
+ },
81
+ showEditModal : function () {
82
+ this .editingId = this ._class .id ;
176
83
},
177
- resetModal () {
178
- const color = this ._class .data ? this ._class .data .color : undefined ;
179
- const inherit_color = ! color;
180
- this .editing = {
181
- id: this ._class .id ,
182
- name: this ._class .subname ,
183
- rule: _ .cloneDeep (this ._class .rule ),
184
- color,
185
- inherit_color,
186
- parent: this ._class .parent ? this ._class .parent : [],
187
- };
188
- // console.log(this.editing);
84
+ hideEditModal : function () {
85
+ this .editingId = null ;
189
86
},
190
87
},
191
88
};
0 commit comments