Skip to content

Commit f3f24f8

Browse files
committed
feat: improved the category edit tree (now collapsible, fixed icons, only expand one level, show number of subcategories)
1 parent b6cc444 commit f3f24f8

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

src/components/CategoryEditTree.vue

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
div
33
div.row.py-2.class
44
div.col-8.col-md-4
5-
span(:style="{ marginLeft: (2 * depth) + 'em'}")
6-
//| {{ _class.name.join(" ➤ ")}}
7-
| #[span(v-if="depth > 0")] {{ _class.name.slice(depth).join(" ➤ ")}}
5+
span(:style="{ marginLeft: (1.5 * depth) + 'em', cursor: _class.children.length > 0 ? 'pointer' : null}" @click="expanded = !expanded")
6+
span(v-if="_class.children.length > 0" style="opacity: 0.8")
7+
icon(:name="expanded ? 'regular/minus-square' : 'regular/plus-square'" scale="0.8")
8+
span(v-else style="opacity: 0.6")
9+
icon(name="circle" scale="0.4" style="margin-left: 1em; margin-right: 1.22em;")
10+
| {{ _class.name.slice(depth).join(" ➤ ")}}
11+
span.ml-1(v-if="_class.children.length > 0" style="opacity: 0.5") ({{totalChildren}})
12+
813
div.col-4.col-md-8
9-
//span.d-none.d-sm-inline.d-md-none(:style="{ marginLeft: (2 * depth) + 'em'}")
1014
span.d-none.d-md-inline
1115
span(v-if="_class.rule.type === 'regex'") Rule ({{_class.rule.type}}): #[code {{_class.rule.regex}}]
1216
span(v-else, style="color: #888") No rule
@@ -47,8 +51,9 @@ div
4751
</template>
4852

4953
<script>
50-
import 'vue-awesome/icons/plus-square';
51-
import 'vue-awesome/icons/minus-square';
54+
import 'vue-awesome/icons/regular/plus-square';
55+
import 'vue-awesome/icons/regular/minus-square';
56+
import 'vue-awesome/icons/circle';
5257
import 'vue-awesome/icons/caret-right';
5358
import 'vue-awesome/icons/trash';
5459
import 'vue-awesome/icons/plus';
@@ -65,9 +70,9 @@ export default {
6570
default: 0,
6671
},
6772
},
68-
data: () => {
73+
data: function () {
6974
return {
70-
expanded: true,
75+
expanded: this.depth < 1,
7176
editing: {
7277
id: 0, // FIXME: Use ID assigned to category in vuex store, in order for saves to be uniquely targeted
7378
name: null,
@@ -91,6 +96,12 @@ export default {
9196
//{ value: 'glob', text: 'Glob pattern' },
9297
];
9398
},
99+
totalChildren: function () {
100+
function countChildren(node) {
101+
return node.children.length + _.sum(_.map(node.children, countChildren));
102+
}
103+
return countChildren(this._class);
104+
},
94105
},
95106
methods: {
96107
addSubclass: function (parent) {

0 commit comments

Comments
 (0)