44 class =" app-navigation-noclose separator-below"
55 :class =" { 'category-header': selectedCategory !== null }"
66 :open.sync =" open"
7+ :menu-open.sync =" menuOpen"
78 :allow-collapse =" true"
89 @click.prevent.stop =" onToggleCategories"
910 >
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+
1033 <FolderIcon slot =" icon" :size =" 20" />
1134 <NcAppNavigationItem
1235 :title =" t('notes', 'All notes')"
3457
3558<script >
3659import {
60+ NcActionInput ,
61+ NcActionText ,
3762 NcAppNavigationItem ,
3863 NcAppNavigationCounter ,
3964} from ' @nextcloud/vue'
4065
4166import FolderIcon from ' vue-material-design-icons/Folder.vue'
4267import FolderOutlineIcon from ' vue-material-design-icons/FolderOutline.vue'
4368import 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'
4471
45- import { getCategories } from ' ../NotesService.js'
72+ import { createCategory , findCategory , getCategories } from ' ../NotesService.js'
4673import { categoryLabel } from ' ../Util.js'
4774import store from ' ../store.js'
4875
@@ -53,6 +80,10 @@ export default {
5380 FolderIcon,
5481 FolderOutlineIcon,
5582 HistoryIcon,
83+ AddIcon,
84+ ErrorIcon,
85+ NcActionInput,
86+ NcActionText,
5687 NcAppNavigationItem,
5788 NcAppNavigationCounter,
5889 },
@@ -67,6 +98,8 @@ export default {
6798 data () {
6899 return {
69100 open: false ,
101+ menuOpen: false ,
102+ createCategoryError: null ,
70103 }
71104 },
72105
@@ -93,10 +126,34 @@ export default {
93126 this .open = ! this .open
94127 },
95128
129+ onToggleNewCategory () {
130+ this .menuOpen = ! this .menuOpen
131+ },
132+
96133 onSelectCategory (category ) {
97134 this .open = false
98135 this .$emit (' category-selected' , category)
99136 },
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+ },
100157 },
101158}
102159 </script >
0 commit comments