-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathCategoriesList.vue
More file actions
157 lines (138 loc) · 3.85 KB
/
CategoriesList.vue
File metadata and controls
157 lines (138 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<template>
<Fragment>
<FolderIcon slot="icon" :size="20" />
<NcAppNavigationItem
:title="t('notes', 'All notes')"
:class="{ active: selectedCategory === null }"
@click.prevent.stop="onSelectCategory(null)"
>
<HistoryIcon slot="icon" :size="20" />
<NcAppNavigationCounter slot="counter">
{{ numNotes }}
</NcAppNavigationCounter>
</NcAppNavigationItem>
<NcAppNavigationCaption :title="t('notes', 'Categories')">
<template #actionsTriggerIcon>
<AddIcon slot="icon" :size="20" />
</template>
<template #actions>
<NcActionText>
<template #icon>
<ErrorIcon v-if="createCategoryError" :size="20" />
<AddIcon v-else-if="!createCategoryError" :size="20" />
</template>
{{ createCategoryError ? createCategoryError : t('notes', 'Create a new category') }}
</NcActionText>
<NcActionInput
icon=""
:value="t('notes', 'Category name')"
@submit.prevent.stop="createNewCategory"
>
<template #icon>
<FolderIcon :size="20" />
</template>
</NcActionInput>
</template>
</NcAppNavigationCaption>
<NcAppNavigationItem v-for="category in categories"
:key="category.name"
:title="categoryTitle(category.name)"
:icon="category.name === '' ? 'icon-emptyfolder' : 'icon-files'"
:class="{ active: category.name === selectedCategory }"
@click.prevent.stop="onSelectCategory(category.name)"
>
<FolderOutlineIcon v-if="category.name === ''" slot="icon" :size="20" />
<FolderIcon v-else slot="icon" :size="20" />
<NcAppNavigationCounter slot="counter">
{{ category.count }}
</NcAppNavigationCounter>
</NcAppNavigationItem>
</Fragment>
</template>
<script>
import {
NcActionInput,
NcActionText,
NcAppNavigationItem,
NcAppNavigationCaption,
NcAppNavigationCounter,
} from '@nextcloud/vue'
import { Fragment } from 'vue-fragment'
import FolderIcon from 'vue-material-design-icons/Folder.vue'
import FolderOutlineIcon from 'vue-material-design-icons/FolderOutline.vue'
import HistoryIcon from 'vue-material-design-icons/History.vue'
import AddIcon from 'vue-material-design-icons/Plus.vue'
import ErrorIcon from 'vue-material-design-icons/AlertCircle.vue'
import { createCategory, findCategory, getCategories } from '../NotesService.js'
import { categoryLabel } from '../Util.js'
import store from '../store.js'
export default {
name: 'CategoriesList',
components: {
Fragment,
NcAppNavigationItem,
NcAppNavigationCaption,
NcAppNavigationCounter,
FolderIcon,
FolderOutlineIcon,
HistoryIcon,
AddIcon,
ErrorIcon,
NcActionInput,
NcActionText,
},
data() {
return {
open: false,
menuOpen: false,
createCategoryError: null,
}
},
computed: {
numNotes() {
return store.getters.numNotes()
},
categories() {
return getCategories(1, true)
},
selectedCategory() {
return store.getters.getSelectedCategory()
},
},
methods: {
categoryTitle(category) {
return categoryLabel(category)
},
onToggleCategories() {
this.open = !this.open
},
onToggleNewCategory() {
this.menuOpen = !this.menuOpen
},
onSelectCategory(category) {
store.commit('setSelectedCategory', category)
},
createNewCategory(event) {
const input = event.target.querySelector('input[type=text]')
const categoryName = input.value.trim()
// Check if already exists
findCategory(categoryName).then(data => {
if (data !== false) {
this.createCategoryError = t('notes', 'This category already exists')
return
}
// Create new directory for category in current notes path defined in settings
createCategory(categoryName)
this.createCategoryError = null
this.onToggleNewCategory()
this.onSelectCategory(categoryName)
})
},
},
}
</script>
<style scoped>
.app-navigation-entry-wrapper.active:deep(.app-navigation-entry) {
background-color: var(--color-primary-element-light) !important;
}
</style>