4
4
class =" app-navigation-noclose separator-below"
5
5
:class =" { 'category-header': selectedCategory !== null }"
6
6
:open.sync =" open"
7
+ :menu-open.sync =" menuOpen"
7
8
:allow-collapse =" true"
8
9
@click.prevent.stop =" onToggleCategories"
9
10
>
11
+ <template #menu-icon >
12
+ <AddIcon :size =" 20" @click =" onToggleNewCategory" />
13
+ </template >
14
+ <template #actions >
15
+ <NcActionText >
16
+ <template #icon >
17
+ <ErrorIcon v-if =" createCategoryError" :size =" 20" />
18
+ <AddIcon v-else-if =" !createCategoryError" :size =" 20" />
19
+ </template >
20
+ {{ createCategoryError ? createCategoryError : t('notes', 'Create a new category') }}
21
+ </NcActionText >
22
+ <NcActionInput
23
+ icon =" "
24
+ :value =" t('notes', 'Category name')"
25
+ @submit.prevent.stop =" createNewCategory"
26
+ >
27
+ <template #icon >
28
+ <FolderIcon :size =" 20" />
29
+ </template >
30
+ </NcActionInput >
31
+ </template >
32
+
10
33
<FolderIcon slot =" icon" :size =" 20" />
11
34
<NcAppNavigationItem
12
35
:title =" t('notes', 'All notes')"
34
57
35
58
<script >
36
59
import {
60
+ NcActionInput ,
61
+ NcActionText ,
37
62
NcAppNavigationItem ,
38
63
NcAppNavigationCounter ,
39
64
} from ' @nextcloud/vue'
40
65
41
66
import FolderIcon from ' vue-material-design-icons/Folder.vue'
42
67
import FolderOutlineIcon from ' vue-material-design-icons/FolderOutline.vue'
43
68
import HistoryIcon from ' vue-material-design-icons/History.vue'
69
+ import AddIcon from ' vue-material-design-icons/Plus.vue'
70
+ import ErrorIcon from ' vue-material-design-icons/AlertCircle.vue'
44
71
45
- import { getCategories } from ' ../NotesService.js'
72
+ import { createCategory , findCategory , getCategories } from ' ../NotesService.js'
46
73
import { categoryLabel } from ' ../Util.js'
47
74
import store from ' ../store.js'
48
75
@@ -53,6 +80,10 @@ export default {
53
80
FolderIcon,
54
81
FolderOutlineIcon,
55
82
HistoryIcon,
83
+ AddIcon,
84
+ ErrorIcon,
85
+ NcActionInput,
86
+ NcActionText,
56
87
NcAppNavigationItem,
57
88
NcAppNavigationCounter,
58
89
},
@@ -67,6 +98,8 @@ export default {
67
98
data () {
68
99
return {
69
100
open: false ,
101
+ menuOpen: false ,
102
+ createCategoryError: null ,
70
103
}
71
104
},
72
105
@@ -93,10 +126,34 @@ export default {
93
126
this .open = ! this .open
94
127
},
95
128
129
+ onToggleNewCategory () {
130
+ this .menuOpen = ! this .menuOpen
131
+ },
132
+
96
133
onSelectCategory (category ) {
97
134
this .open = false
98
135
this .$emit (' category-selected' , category)
99
136
},
137
+
138
+ createNewCategory (event ) {
139
+ const input = event .target .querySelector (' input[type=text]' )
140
+ const categoryName = input .value .trim ()
141
+
142
+ // Check if already exists
143
+ findCategory (categoryName).then (data => {
144
+ if (data !== false ) {
145
+ this .createCategoryError = t (' notes' , ' This category already exists' )
146
+ return
147
+ }
148
+
149
+ // Create new directory for category in current notes path defined in settings
150
+ createCategory (categoryName)
151
+ this .createCategoryError = null
152
+ this .onToggleNewCategory ()
153
+ this .onSelectCategory (categoryName)
154
+ })
155
+
156
+ },
100
157
},
101
158
}
102
159
</script >
0 commit comments