Skip to content

Commit 2bc6f22

Browse files
committed
AppSettings: Add FilePicker for notesPath including workaround
for NCAppNavigationSettings excludeClickOutsideSelectors Signed-off-by: Jonathan Pagel <jonny_tischbein@systemli.org>
1 parent 28400c3 commit 2bc6f22

File tree

1 file changed

+47
-10
lines changed

1 file changed

+47
-10
lines changed

src/components/AppSettings.vue

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
<template>
2-
<NcAppNavigationSettings :title="t('notes', 'Notes settings')" :class="{ loading: saving }">
2+
<NcAppNavigationSettings :title="t('notes', 'Notes settings')" :class="{ loading: saving }" :exclude-click-outside-selectors="['div.oc-dialog']">
33
<div class="settings-block">
44
<p class="settings-hint">
55
<label for="notesPath">{{ t('notes', 'Folder to store your notes') }}</label>
66
</p>
7-
<form @submit.prevent="onChangeSettingsReload">
8-
<input id="notesPath"
9-
v-model="settings.notesPath"
10-
type="text"
11-
name="notesPath"
12-
:placeholder="t('notes', 'Root directory')"
13-
@change="onChangeSettingsReload"
14-
><input type="submit" class="icon-confirm" value="">
15-
</form>
7+
<input id="notesPath"
8+
v-model="settings.notesPath"
9+
type="text"
10+
name="notesPath"
11+
:placeholder="t('notes', 'Root directory')"
12+
@click="onChangeNotePath"
13+
>
1614
</div>
1715
<div class="settings-block">
1816
<p class="settings-hint">
@@ -51,8 +49,23 @@ import {
5149
} from '@nextcloud/vue'
5250
5351
import { setSettings } from '../NotesService.js'
52+
import { FilePicker, FilePickerType } from '@nextcloud/dialogs'
5453
import store from '../store.js'
5554
55+
/*
56+
* Workaround until excludeClickOutsideSelectors will work and does nott close the menu while
57+
* clicking in the filePicker
58+
*/
59+
const callback = (mutationList, observer) => {
60+
for (const mutation of mutationList) {
61+
if (mutation.target.id === 'app-settings__content' && mutation.type === 'attributes' && mutation.attributeName === 'style') {
62+
mutation.target.style = 'display: block;'
63+
document.getElementById('app-settings').classList.add('open')
64+
observer.disconnect()
65+
}
66+
}
67+
}
68+
5669
export default {
5770
name: 'AppSettings',
5871
@@ -89,6 +102,30 @@ export default {
89102
},
90103
91104
methods: {
105+
onChangeNotePath(event) {
106+
// Obeserver for the workaround
107+
const observer = new MutationObserver(callback)
108+
observer.observe(document.querySelector('#app-settings__content'), { attributes: true })
109+
110+
// Code Example from: https://github.com/nextcloud/text/blob/main/src/components/Menu/ActionInsertLink.vue#L130-L155
111+
const filePicker = new FilePicker(
112+
t('text', 'Select folder to link to'),
113+
false, // multiselect
114+
['text/directory'], // mime filter
115+
true, // modal
116+
FilePickerType.Choose, // type
117+
true, // directories
118+
event.target.value === '' ? '/' : event.target.value // path
119+
)
120+
filePicker.pick().then((file) => {
121+
const client = OC.Files.getClient()
122+
client.getFileInfo(file).then((_status, fileInfo) => {
123+
this.settings.notesPath = fileInfo.path === '/' ? `/${fileInfo.name}` : `${fileInfo.path}/${fileInfo.name}`
124+
125+
this.onChangeSettingsReload()
126+
})
127+
})
128+
},
92129
onChangeSettings() {
93130
this.saving = true
94131
return setSettings(this.settings)

0 commit comments

Comments
 (0)