Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Sidebar.vue « components « src - github.com/nextcloud/notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: df3ffe53a83f19c722a7bb9d310f74a157ffd9cb (plain)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<template>
	<AppSidebar v-if="sidebarOpen"
		:title="title"
		:subtitle="subtitle"
		:star-loading="loading.favorite"
		:starred="note.favorite"
		@update:starred="onSetFavorite"
		@close="onCloseSidebar"
	>
		<div class="sidebar-content-wrapper">
			<div v-if="!note.readonly" class="note-category">
				<h4>
					{{ t('notes', 'Category') }}
					<InfoIcon v-tooltip="categoriesInfo"
						:size="20"
						fill-color="var(--color-main-text)"
						style="display: inline-block; margin-left: 1ex;"
					/>
				</h4>
				<form class="category" @submit.prevent.stop="">
					<Multiselect id="category"
						:value="category"
						:options="categories"
						:placeholder="t('notes', 'Uncategorized')"
						:disabled="loading.category"
						:class="['category-select', {'icon-loading-small': loading.category}]"
						:show-no-results="false"
						:taggable="true"
						:preserve-search="true"
						:title="t('notes', 'Set category')"
						@input="onSaveCategory"
						@close="onFinishEditCategory"
						@search-change="onEditCategory"
					>
						<template #option="{ option }">
							<span :class="{ gray: option==='' }">{{ option | categoryOptionLabel }}</span>
						</template>
					</Multiselect>
					<input
						type="text"
						style="display: none"
					><input
						type="submit"
						value=""
						class="icon-confirm loading"
						:disabled="loading.category"
					>
				</form>
			</div>
			<div class="modified"
				:title="t('notes', 'Click here to save manually')"
				@click="onManualSave"
			>
				<div v-show="note.error" class="note-error">
					{{ t('notes', 'Saving failed!') }}
				</div>
				{{ t('notes', 'Last modified: {date}', { date: formattedDate }) }}
				<span v-show="note.unsaved" :title="t('notes', 'Note has unsaved changes')"> * </span>
			</div>
		</div>
	</AppSidebar>
</template>
<script>

import {
	AppSidebar,
	Multiselect,
	Tooltip,
} from '@nextcloud/vue'
import moment from '@nextcloud/moment'

import InfoIcon from 'vue-material-design-icons/Information.vue'

import { getCategories, setFavorite, setCategory, saveNoteManually } from '../NotesService.js'
import { categoryLabel } from '../Util.js'
import store from '../store.js'

export default {
	name: 'Sidebar',

	components: {
		AppSidebar,
		InfoIcon,
		Multiselect,
	},

	directives: {
		tooltip: Tooltip,
	},

	filters: {
		categoryOptionLabel(obj) {
			const category = obj.isTag ? obj.label : obj
			return categoryLabel(category)
		},
	},

	props: {
		noteId: {
			type: String,
			required: true,
		},
	},

	data() {
		return {
			loading: {
				category: false,
				favorite: false,
			},
			categoryInput: null,
		}
	},

	computed: {
		note() {
			return store.getters.getNote(parseInt(this.noteId))
		},
		title() {
			return this.note ? this.note.title : ''
		},
		category() {
			return this.note ? this.note.category : ''
		},
		formattedDate() {
			return moment(this.note.modified * 1000).format('LLL')
		},
		wordCount() {
			const value = this.note?.content
			if (value && (typeof value === 'string')) {
				const wordCount = value.split(/\s+/).filter(
					// only count words containing
					// at least one alphanumeric character
					value => value.search(/[A-Za-z0-9]/) !== -1
				).length
				const charCount = Array.from(value).length
				return n('notes', '%n word', '%n words', wordCount)
					+ ', ' + n('notes', '%n character', '%n characters', charCount)
			} else {
				return ''
			}
		},
		subtitle() {
			return this.wordCount
		},
		categoriesInfo() {
			return t('notes', 'You can create subcategories by using “/” as delimiter between parent category and subcategory, e.g. “{parent}/{sub}”.', { parent: t('notes', 'Category'), sub: t('notes', 'Subcategory') })
		},
		categories() {
			return ['', ...getCategories(0, false)]
		},
		sidebarOpen() {
			return store.state.app.sidebarOpen
		},
	},

	methods: {
		onCloseSidebar() {
			store.commit('setSidebarOpen', false)
		},

		onEditCategory(text) {
			this.categoryInput = text
		},

		onFinishEditCategory(str) {
			if (this.categoryInput) {
				this.onSaveCategory(this.categoryInput)
			}
		},

		onSetFavorite(favorite) {
			this.loading.favorite = true
			setFavorite(this.note.id, favorite)
				.catch(() => {
				})
				.then(() => {
					this.loading.favorite = false
				})
		},

		onSaveCategory(category) {
			this.categoryInput = null
			if (category !== null && this.note.category !== category) {
				this.loading.category = true
				this.note.category = category
				setCategory(this.note.id, category)
					.catch(() => {
					})
					.then(() => {
						this.loading.category = false
					})
			}
		},

		onManualSave() {
			saveNoteManually(this.note.id)
		},

	},
}
</script>
<style scoped>
.sidebar-content-wrapper {
	padding: 0 10px;
}

.note-error {
	background-color: var(--color-error);
	color: var(--color-primary-text);
	border-radius: 0.5ex;
	padding: 0.5ex 1ex;
}

.note-category {
	margin-top: 1ex;
}

form.category > .multiselect,
form.category > .icon-confirm {
	vertical-align: middle;
}

form.category {
	display: flex;
	align-items: center;
}

.note-category .icon-info {
	padding: 11px 20px;
	vertical-align: super;
}

.category-select {
	flex-grow: 1;
}

.gray {
	opacity: 0.5;
}

.modified {
	position: absolute;
	bottom: 0;
	padding: 1ex 0;
	opacity: 0.5;
}
</style>