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

github.com/nextcloud/notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/App.vue17
-rw-r--r--src/NotesService.js412
-rw-r--r--src/components/AppSettings.vue7
-rw-r--r--src/components/NavigationCategoriesItem.vue10
-rw-r--r--src/components/NavigationList.vue7
-rw-r--r--src/components/NavigationNoteItem.vue17
-rw-r--r--src/components/Note.vue13
-rw-r--r--src/components/Sidebar.vue17
-rw-r--r--src/main.js2
9 files changed, 253 insertions, 249 deletions
diff --git a/src/App.vue b/src/App.vue
index 5e998c51..b3a7f569 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -40,11 +40,12 @@ import {
AppNavigationNew,
Content,
} from '@nextcloud/vue'
+
+import { fetchNotes, noteExists, createNote } from './NotesService'
+import { openNavbar } from './nextcloud'
import AppSettings from './components/AppSettings'
import NavigationList from './components/NavigationList'
-import NotesService from './NotesService'
import store from './store'
-import { openNavbar } from './nextcloud'
export default {
name: 'App',
@@ -128,7 +129,7 @@ export default {
methods: {
loadNotes() {
this.loading.notes = true
- NotesService.fetchNotes()
+ fetchNotes()
.then(data => {
if (data.notes !== null) {
this.error = false
@@ -140,7 +141,7 @@ export default {
.catch(() => {
this.error = true
})
- .finally(() => {
+ .then(() => {
this.loading.notes = false
})
},
@@ -154,8 +155,8 @@ export default {
},
routeDefault(defaultNoteId) {
- if (this.$route.name !== 'note' || !NotesService.noteExists(this.$route.params.noteId)) {
- if (NotesService.noteExists(defaultNoteId)) {
+ if (this.$route.name !== 'note' || !noteExists(this.$route.params.noteId)) {
+ if (noteExists(defaultNoteId)) {
this.routeToNote(defaultNoteId)
} else {
this.routeFirst()
@@ -194,13 +195,13 @@ export default {
return
}
this.loading.create = true
- NotesService.createNote(this.filter.category)
+ createNote(this.filter.category)
.then(note => {
this.routeToNote(note.id)
})
.catch(() => {
})
- .finally(() => {
+ .then(() => {
this.loading.create = false
})
},
diff --git a/src/NotesService.js b/src/NotesService.js
index 6ee0fca3..7c7786ae 100644
--- a/src/NotesService.js
+++ b/src/NotesService.js
@@ -2,214 +2,212 @@ import AppGlobal from './mixins/AppGlobal'
import store from './store'
import axios from '@nextcloud/axios'
-export default {
-
- t: AppGlobal.methods.t,
-
- url(url) {
- url = `/apps/notes${url}`
- return OC.generateUrl(url)
- },
-
- handleSyncError(message) {
- OC.Notification.showTemporary(message + ' ' + this.t('notes', 'See JavaScript console for details.'))
- },
-
- handleInsufficientStorage() {
- OC.Notification.showTemporary(this.t('notes', 'Saving the note has failed due to insufficient storage.'))
- },
-
- setSettings(settings) {
- return axios
- .put(this.url('/settings'), settings)
- .then(response => {
- const settings = response.data
- store.commit('setSettings', settings)
- return settings
- })
- .catch(err => {
- console.error(err)
- this.handleSyncError(this.t('notes', 'Updating settings has failed.'))
- throw err
- })
- },
-
- fetchNotes() {
- return axios
- .get(this.url('/notes'))
- .then(response => {
- store.commit('setSettings', response.data.settings)
- if (response.data.notes !== null) {
- store.dispatch('addAll', response.data.notes)
- }
- if (response.data.errorMessage) {
- OC.Notification.showTemporary(response.data.errorMessage)
- }
- return response.data
- })
- .catch(err => {
- console.error(err)
- this.handleSyncError(this.t('notes', 'Fetching notes has failed.'))
- throw err
- })
- },
-
- fetchNote(noteId) {
- return axios
- .get(this.url('/notes/' + noteId))
- .then(response => {
- const localNote = store.getters.getNote(parseInt(noteId))
- // only overwrite if there are no unsaved changes
- if (!localNote || !localNote.unsaved) {
- store.commit('add', response.data)
- }
- return response.data
- })
- .catch(err => {
- if (err.response.status === 404) {
- throw err
- } else {
- console.error(err)
- const msg = this.t('notes', 'Fetching note {id} has failed.', { id: noteId })
- store.commit('setNoteAttribute', { noteId: noteId, attribute: 'error', value: true })
- store.commit('setNoteAttribute', { noteId: noteId, attribute: 'errorMessage', value: msg })
- return store.getter.getNote(noteId)
- }
- })
- },
-
- createNote(category) {
- return axios
- .post(this.url('/notes'), { category: category })
- .then(response => {
+const t = AppGlobal.methods.t
+
+function url(url) {
+ url = `/apps/notes${url}`
+ return OC.generateUrl(url)
+}
+
+function handleSyncError(message) {
+ OC.Notification.showTemporary(message + ' ' + t('notes', 'See JavaScript console for details.'))
+}
+
+function handleInsufficientStorage() {
+ OC.Notification.showTemporary(t('notes', 'Saving the note has failed due to insufficient storage.'))
+}
+
+export const setSettings = settings => {
+ return axios
+ .put(url('/settings'), settings)
+ .then(response => {
+ const settings = response.data
+ store.commit('setSettings', settings)
+ return settings
+ })
+ .catch(err => {
+ console.error(err)
+ handleSyncError(t('notes', 'Updating settings has failed.'))
+ throw err
+ })
+}
+
+export const fetchNotes = () => {
+ return axios
+ .get(url('/notes'))
+ .then(response => {
+ store.commit('setSettings', response.data.settings)
+ if (response.data.notes !== null) {
+ store.dispatch('addAll', response.data.notes)
+ }
+ if (response.data.errorMessage) {
+ OC.Notification.showTemporary(response.data.errorMessage)
+ }
+ return response.data
+ })
+ .catch(err => {
+ console.error(err)
+ handleSyncError(t('notes', 'Fetching notes has failed.'))
+ throw err
+ })
+}
+
+export const fetchNote = noteId => {
+ return axios
+ .get(url('/notes/' + noteId))
+ .then(response => {
+ const localNote = store.getters.getNote(parseInt(noteId))
+ // only overwrite if there are no unsaved changes
+ if (!localNote || !localNote.unsaved) {
store.commit('add', response.data)
- return response.data
- })
- .catch(err => {
- console.error(err)
- if (err.response.status === 507) {
- this.handleInsufficientStorage()
- } else {
- this.handleSyncError(this.t('notes', 'Creating new note has failed.'))
- }
- throw err
- })
- },
-
- _updateNote(note) {
- return axios
- .put(this.url('/notes/' + note.id), { content: note.content })
- .then(response => {
- const updated = response.data
- note.saveError = false
- note.title = updated.title
- note.modified = updated.modified
- if (updated.content === note.content) {
- note.unsaved = false
- }
- store.commit('add', note)
- return note
- })
- .catch(err => {
- store.commit('setNoteAttribute', { noteId: note.id, attribute: 'saveError', value: true })
- console.error(err)
- if (err.response.status === 507) {
- this.handleInsufficientStorage()
- } else {
- this.handleSyncError(this.t('notes', 'Updating note {id} has failed.', { id: note.id }))
- }
- })
- },
-
- prepareDeleteNote(noteId) {
- store.commit('setNoteAttribute', { noteId: noteId, attribute: 'deleting', value: 'prepare' })
- },
-
- undoDeleteNote(noteId) {
- store.commit('setNoteAttribute', { noteId: noteId, attribute: 'deleting', value: null })
- },
-
- deleteNote(noteId) {
- store.commit('setNoteAttribute', { noteId: noteId, attribute: 'deleting', value: 'deleting' })
- return axios
- .delete(this.url('/notes/' + noteId))
- .then(() => {
- store.commit('remove', noteId)
- })
- .catch(err => {
- console.error(err)
- this.handleSyncError(this.t('notes', 'Deleting note {id} has failed.', { id: noteId }))
- this.undoDeleteNote(noteId)
- throw err
- })
- },
-
- setFavorite(noteId, favorite) {
- return axios
- .put(this.url('/notes/' + noteId + '/favorite'), { favorite: favorite })
- .then(response => {
- store.commit('setNoteAttribute', { noteId: noteId, attribute: 'favorite', value: response.data })
- })
- .catch(err => {
- console.error(err)
- this.handleSyncError(this.t('notes', 'Toggling favorite for note {id} has failed.', { id: noteId }))
+ }
+ return response.data
+ })
+ .catch(err => {
+ if (err.response.status === 404) {
throw err
- })
- },
-
- setCategory(noteId, category) {
- return axios
- .put(this.url('/notes/' + noteId + '/category'), { category: category })
- .then(response => {
- const realCategory = response.data
- if (category !== realCategory) {
- this.handleSyncError(this.t('notes', 'Updating the note\'s category has failed. Is the target directory writable?'))
- }
- store.commit('setNoteAttribute', { noteId: noteId, attribute: 'category', value: realCategory })
- })
- .catch(err => {
+ } else {
console.error(err)
- this.handleSyncError(this.t('notes', 'Updating the category for note {id} has failed.', { id: noteId }))
- throw err
- })
- },
-
- saveNote(noteId, manualSave = false) {
- store.commit('addUnsaved', noteId)
- if (manualSave) {
- store.commit('setManualSave', true)
- }
- this._saveNotes()
- },
- _saveNotes() {
- const unsavedNotes = Object.values(store.state.unsaved)
- if (store.state.isSaving || unsavedNotes.length === 0) {
- return
- }
- store.commit('setSaving', true)
- const promises = unsavedNotes.map(note => this._updateNote(note))
- store.commit('clearUnsaved')
- Promise.all(promises).finally(() => {
- store.commit('setSaving', false)
- store.commit('setManualSave', false)
- this._saveNotes()
- })
- },
-
- saveNoteManually(noteId) {
- store.commit('setNoteAttribute', { noteId: noteId, attribute: 'saveError', value: false })
- this.saveNote(noteId, true)
- },
-
- noteExists(noteId) {
- return store.getters.noteExists(noteId)
- },
-
- getCategories(maxLevel, details) {
- return store.getters.getCategories(maxLevel, details)
- },
-
- categoryLabel(category) {
- return category === '' ? this.t('notes', 'Uncategorized') : category.replace(/\//g, ' / ')
- },
+ const msg = t('notes', 'Fetching note {id} has failed.', { id: noteId })
+ store.commit('setNoteAttribute', { noteId: noteId, attribute: 'error', value: true })
+ store.commit('setNoteAttribute', { noteId: noteId, attribute: 'errorMessage', value: msg })
+ return store.getter.getNote(noteId)
+ }
+ })
+}
+
+export const createNote = category => {
+ return axios
+ .post(url('/notes'), { category: category })
+ .then(response => {
+ store.commit('add', response.data)
+ return response.data
+ })
+ .catch(err => {
+ console.error(err)
+ if (err.response.status === 507) {
+ handleInsufficientStorage()
+ } else {
+ handleSyncError(t('notes', 'Creating new note has failed.'))
+ }
+ throw err
+ })
+}
+
+function _updateNote(note) {
+ return axios
+ .put(url('/notes/' + note.id), { content: note.content })
+ .then(response => {
+ const updated = response.data
+ note.saveError = false
+ note.title = updated.title
+ note.modified = updated.modified
+ if (updated.content === note.content) {
+ note.unsaved = false
+ }
+ store.commit('add', note)
+ return note
+ })
+ .catch(err => {
+ store.commit('setNoteAttribute', { noteId: note.id, attribute: 'saveError', value: true })
+ console.error(err)
+ if (err.response.status === 507) {
+ handleInsufficientStorage()
+ } else {
+ handleSyncError(t('notes', 'Updating note {id} has failed.', { id: note.id }))
+ }
+ })
+}
+
+export const prepareDeleteNote = noteId => {
+ store.commit('setNoteAttribute', { noteId: noteId, attribute: 'deleting', value: 'prepare' })
+}
+
+export const undoDeleteNote = noteId => {
+ store.commit('setNoteAttribute', { noteId: noteId, attribute: 'deleting', value: null })
+}
+
+export const deleteNote = noteId => {
+ store.commit('setNoteAttribute', { noteId: noteId, attribute: 'deleting', value: 'deleting' })
+ return axios
+ .delete(url('/notes/' + noteId))
+ .then(() => {
+ store.commit('remove', noteId)
+ })
+ .catch(err => {
+ console.error(err)
+ handleSyncError(t('notes', 'Deleting note {id} has failed.', { id: noteId }))
+ undoDeleteNote(noteId)
+ throw err
+ })
+}
+
+export const setFavorite = (noteId, favorite) => {
+ return axios
+ .put(url('/notes/' + noteId + '/favorite'), { favorite: favorite })
+ .then(response => {
+ store.commit('setNoteAttribute', { noteId: noteId, attribute: 'favorite', value: response.data })
+ })
+ .catch(err => {
+ console.error(err)
+ handleSyncError(t('notes', 'Toggling favorite for note {id} has failed.', { id: noteId }))
+ throw err
+ })
+}
+
+export const setCategory = (noteId, category) => {
+ return axios
+ .put(url('/notes/' + noteId + '/category'), { category: category })
+ .then(response => {
+ const realCategory = response.data
+ if (category !== realCategory) {
+ handleSyncError(t('notes', 'Updating the note\'s category has failed. Is the target directory writable?'))
+ }
+ store.commit('setNoteAttribute', { noteId: noteId, attribute: 'category', value: realCategory })
+ })
+ .catch(err => {
+ console.error(err)
+ handleSyncError(t('notes', 'Updating the category for note {id} has failed.', { id: noteId }))
+ throw err
+ })
+}
+
+export const saveNote = (noteId, manualSave = false) => {
+ store.commit('addUnsaved', noteId)
+ if (manualSave) {
+ store.commit('setManualSave', true)
+ }
+ _saveNotes()
+}
+
+function _saveNotes() {
+ const unsavedNotes = Object.values(store.state.unsaved)
+ if (store.state.isSaving || unsavedNotes.length === 0) {
+ return
+ }
+ store.commit('setSaving', true)
+ const promises = unsavedNotes.map(note => _updateNote(note))
+ store.commit('clearUnsaved')
+ Promise.all(promises).then(() => {
+ store.commit('setSaving', false)
+ store.commit('setManualSave', false)
+ _saveNotes()
+ })
+}
+
+export const saveNoteManually = (noteId) => {
+ store.commit('setNoteAttribute', { noteId: noteId, attribute: 'saveError', value: false })
+ saveNote(noteId, true)
+}
+
+export const noteExists = (noteId) => {
+ return store.getters.noteExists(noteId)
+}
+
+export const getCategories = (maxLevel, details) => {
+ return store.getters.getCategories(maxLevel, details)
+}
+
+export const categoryLabel = (category) => {
+ return category === '' ? t('notes', 'Uncategorized') : category.replace(/\//g, ' / ')
}
diff --git a/src/components/AppSettings.vue b/src/components/AppSettings.vue
index 74e9c003..d0318026 100644
--- a/src/components/AppSettings.vue
+++ b/src/components/AppSettings.vue
@@ -31,7 +31,8 @@
import {
AppNavigationSettings,
} from '@nextcloud/vue'
-import NotesService from '../NotesService'
+
+import { setSettings } from '../NotesService'
import store from '../store'
export default {
@@ -60,10 +61,10 @@ export default {
methods: {
onChangeSettings() {
this.saving = true
- return NotesService.setSettings(this.settings)
+ return setSettings(this.settings)
.catch(() => {
})
- .finally(() => {
+ .then(() => {
this.saving = false
})
},
diff --git a/src/components/NavigationCategoriesItem.vue b/src/components/NavigationCategoriesItem.vue
index c40cd1aa..013a3aa2 100644
--- a/src/components/NavigationCategoriesItem.vue
+++ b/src/components/NavigationCategoriesItem.vue
@@ -38,7 +38,9 @@ import {
AppNavigationItem,
AppNavigationCounter,
} from '@nextcloud/vue'
-import NotesService from '../NotesService'
+
+import { getCategories, categoryLabel } from '../NotesService'
+
import store from '../store'
export default {
@@ -68,17 +70,17 @@ export default {
},
categories() {
- return NotesService.getCategories(1, true)
+ return getCategories(1, true)
},
title() {
- return this.selectedCategory === null ? this.t('notes', 'Categories') : NotesService.categoryLabel(this.selectedCategory)
+ return this.selectedCategory === null ? this.t('notes', 'Categories') : categoryLabel(this.selectedCategory)
},
},
methods: {
categoryTitle(category) {
- return NotesService.categoryLabel(category)
+ return categoryLabel(category)
},
onToggleCategories() {
diff --git a/src/components/NavigationList.vue b/src/components/NavigationList.vue
index a9c4ec79..8ca9ff06 100644
--- a/src/components/NavigationList.vue
+++ b/src/components/NavigationList.vue
@@ -59,9 +59,10 @@ import {
AppNavigationCaption,
AppNavigationItem,
} from '@nextcloud/vue'
+
+import { categoryLabel } from '../NotesService'
import NavigationCategoriesItem from './NavigationCategoriesItem'
import NavigationNoteItem from './NavigationNoteItem'
-import NotesService from '../NotesService'
import store from '../store'
import { ObserveVisibility } from 'vue-observe-visibility'
@@ -176,11 +177,11 @@ export default {
},
categoryTitle(category) {
- return NotesService.categoryLabel(category)
+ return categoryLabel(category)
},
categoryToLabel(category) {
- return NotesService.categoryLabel(category.substring(this.category.length + 1))
+ return categoryLabel(category.substring(this.category.length + 1))
},
getTimeslotFromNote(note) {
diff --git a/src/components/NavigationNoteItem.vue b/src/components/NavigationNoteItem.vue
index 691ce9a8..e8e7858e 100644
--- a/src/components/NavigationNoteItem.vue
+++ b/src/components/NavigationNoteItem.vue
@@ -27,7 +27,8 @@ import {
ActionButton,
AppNavigationItem,
} from '@nextcloud/vue'
-import NotesService from '../NotesService'
+
+import { categoryLabel, setFavorite, prepareDeleteNote, undoDeleteNote, deleteNote } from '../NotesService'
export default {
name: 'NavigationNoteItem',
@@ -91,7 +92,7 @@ export default {
},
actionCategoryText() {
- return NotesService.categoryLabel(this.note.category)
+ return categoryLabel(this.note.category)
},
actionDeleteIcon() {
@@ -102,10 +103,10 @@ export default {
methods: {
onToggleFavorite() {
this.loading.favorite = true
- NotesService.setFavorite(this.note.id, !this.note.favorite)
+ setFavorite(this.note.id, !this.note.favorite)
.catch(() => {
})
- .finally(() => {
+ .then(() => {
this.loading.favorite = false
this.actionsOpen = false
})
@@ -118,24 +119,24 @@ export default {
onDeleteNote() {
this.actionsOpen = false
- NotesService.prepareDeleteNote(this.note.id)
+ prepareDeleteNote(this.note.id)
this.undoTimer = setTimeout(this.onDeleteNoteFinally, 7000)
this.$emit('note-deleted')
},
onUndoDeleteNote() {
clearTimeout(this.undoTimer)
- NotesService.undoDeleteNote(this.note.id)
+ undoDeleteNote(this.note.id)
},
onDeleteNoteFinally() {
this.loading.delete = true
- NotesService.deleteNote(this.note.id)
+ deleteNote(this.note.id)
.then(() => {
})
.catch(() => {
})
- .finally(() => {
+ .then(() => {
this.loading.delete = false
})
},
diff --git a/src/components/Note.vue b/src/components/Note.vue
index 49d2bf3f..cab58fee 100644
--- a/src/components/Note.vue
+++ b/src/components/Note.vue
@@ -57,11 +57,12 @@ import {
AppContent,
Tooltip,
} from '@nextcloud/vue'
+
+import { fetchNote, saveNote, saveNoteManually } from '../NotesService'
+import { closeNavbar } from '../nextcloud'
import TheEditor from './EditorEasyMDE'
import ThePreview from './EditorMarkdownIt'
-import NotesService from '../NotesService'
import store from '../store'
-import { closeNavbar } from '../nextcloud'
export default {
name: 'Note',
@@ -137,7 +138,7 @@ export default {
this.onUpdateTitle(this.title)
this.loading = true
this.preview = false
- NotesService.fetchNote(this.noteId)
+ fetchNote(this.noteId)
.then((note) => {
if (note.errorMessage) {
OC.Notification.showTemporary(note.errorMessage)
@@ -146,7 +147,7 @@ export default {
.catch(() => {
// note not found
})
- .finally(() => {
+ .then(() => {
this.loading = false
})
},
@@ -213,7 +214,7 @@ export default {
unsaved: true,
}
store.commit('add', note)
- setTimeout(NotesService.saveNote.bind(NotesService, note.id), 1000)
+ setTimeout(saveNote.bind(this, note.id), 1000)
}
},
@@ -229,7 +230,7 @@ export default {
},
onManualSave() {
- NotesService.saveNoteManually(this.note.id)
+ saveNoteManually(this.note.id)
},
},
}
diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue
index 028e2db6..906b5b32 100644
--- a/src/components/Sidebar.vue
+++ b/src/components/Sidebar.vue
@@ -59,7 +59,8 @@ import {
Multiselect,
Tooltip,
} from '@nextcloud/vue'
-import NotesService from '../NotesService'
+
+import { categoryLabel, getCategories, setFavorite, setCategory, saveNoteManually } from '../NotesService'
import store from '../store'
export default {
@@ -77,7 +78,7 @@ export default {
filters: {
categoryOptionLabel: function(obj) {
const category = obj.isTag ? obj.label : obj
- return NotesService.categoryLabel(category)
+ return categoryLabel(category)
},
},
@@ -128,7 +129,7 @@ export default {
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 [ '', ...NotesService.getCategories(0, false) ]
+ return [ '', ...getCategories(0, false) ]
},
sidebarOpen() {
return store.state.sidebarOpen
@@ -152,10 +153,10 @@ export default {
onSetFavorite(favorite) {
this.loading.favorite = true
- NotesService.setFavorite(this.note.id, favorite)
+ setFavorite(this.note.id, favorite)
.catch(() => {
})
- .finally(() => {
+ .then(() => {
this.loading.favorite = false
})
},
@@ -165,17 +166,17 @@ export default {
if (category !== null && this.note.category !== category) {
this.loading.category = true
this.note.category = category
- NotesService.setCategory(this.note.id, category)
+ setCategory(this.note.id, category)
.catch(() => {
})
- .finally(() => {
+ .then(() => {
this.loading.category = false
})
}
},
onManualSave() {
- NotesService.saveNoteManually(this.note.id)
+ saveNoteManually(this.note.id)
},
},
diff --git a/src/main.js b/src/main.js
index 9c780398..1fbe1855 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,5 +1,3 @@
-import '@babel/polyfill'
-
import Vue from 'vue'
import App from './App'
import router from './router'