1616 span( v-if ="_class.rule.type === 'regex'" ) Rule ({{_class.rule.type}}): #[ code {{_class.rule.regex }}]
1717 span( v-else , style ="color: #888" ) No rule
1818 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 )
2020 icon( name ="edit" )
2121 b-btn.ml-1 ( size ="sm" , variant ="outline-success" , @click ="addSubclass(_class); expanded = true" style ="border: 0;" pill )
2222 icon( name ="plus" )
2323 div
2424 div.pa-2 ( v-for ="child in _class.children" , style ="background: rgba(0, 0, 0, 0);" , v-show ="expanded" )
2525 CategoryEditTree( :_class ="child" , :depth ="depth+1" )
2626
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()" )
6829</template >
6930
7031<script >
@@ -76,14 +37,14 @@ import 'vue-awesome/icons/trash';
7637import ' vue-awesome/icons/plus' ;
7738import ' vue-awesome/icons/edit' ;
7839
79- import ColorPicker from ' ~/components/ColorPicker ' ;
40+ import CategoryEditModal from ' ./CategoryEditModal.vue ' ;
8041
8142import _ from ' lodash' ;
8243
8344export default {
8445 name: ' CategoryEditTree' ,
8546 components: {
86- ' color-picker ' : ColorPicker ,
47+ CategoryEditModal : CategoryEditModal ,
8748 },
8849 props: {
8950 _class: Object ,
@@ -95,32 +56,10 @@ export default {
9556 data : function () {
9657 return {
9758 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 ,
10760 };
10861 },
10962 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- },
12463 totalChildren : function () {
12564 function countChildren (node ) {
12665 return node .children .length + _ .sum (_ .map (node .children , countChildren));
@@ -134,58 +73,16 @@ export default {
13473 name: parent .name .concat ([' New class' ]),
13574 rule: { type: ' regex' , regex: ' FILL ME' },
13675 });
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);
17176
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 ;
17683 },
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 ;
18986 },
19087 },
19188};
0 commit comments