Skip to content

Commit

Permalink
AppSettings: Add FilePicker for notesPath like in #990
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Pagel <jonny_tischbein@systemli.org>
  • Loading branch information
theatischbein committed Apr 15, 2023
1 parent 030db82 commit ea80bce
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/components/AppSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
<p class="app-settings-section__desc">
{{ t('notes', 'Folder to store your notes') }}
</p>
<form @submit.prevent="onChangeSettingsReload">
<input id="notesPath"
v-model="settings.notesPath"
type="text"
name="notesPath"
:placeholder="t('notes', 'Root directory')"
@change="onChangeSettingsReload"
><input type="submit" class="icon-confirm" value="">
</form>
<input id="notesPath"
v-model="settings.notesPath"
type="text"
name="notesPath"
:placeholder="t('notes', 'Root directory')"
@click="onChangeNotePath"
>
</NcAppSettingsSection>
<NcAppSettingsSection id="file-suffix-section" :title="t('notes', 'File extension')">
<p class="app-settings-section__desc">
Expand Down Expand Up @@ -86,6 +84,8 @@ import {
NcAppSettingsSection,
} from '@nextcloud/vue'
import { FilePicker, FilePickerType } from '@nextcloud/dialogs'
import { setSettings } from '../NotesService.js'
import store from '../store.js'
import HelpMobile from './HelpMobile.vue'
Expand Down Expand Up @@ -153,6 +153,25 @@ export default {
},
methods: {
onChangeNotePath(event) {
// Code Example from: https://github.com/nextcloud/text/blob/main/src/components/Menu/ActionInsertLink.vue#L130-L155
const filePicker = new FilePicker(
t('text', 'Select folder to link to'),
false, // multiselect
['text/directory'], // mime filter
true, // modal
FilePickerType.Choose, // type
true, // directories
event.target.value === '' ? '/' : event.target.value // path
)
filePicker.pick().then((file) => {
const client = OC.Files.getClient()
client.getFileInfo(file).then((_status, fileInfo) => {
this.settings.notesPath = fileInfo.path === '/' ? `/${fileInfo.name}` : `${fileInfo.path}/${fileInfo.name}`
this.onChangeSettingsReload()
})
})
},
onChangeSettings() {
this.saving = true
return setSettings(this.settings)
Expand Down

0 comments on commit ea80bce

Please sign in to comment.