Skip to content

Commit

Permalink
AppSettings: Add FilePicker for notesPath like in nextcloud#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 26, 2023
1 parent 53dcee3 commit 8982461
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
2 changes: 0 additions & 2 deletions src/App.vue
Expand Up @@ -57,7 +57,6 @@ import { loadState } from '@nextcloud/initial-state'
import { showSuccess, TOAST_UNDO_TIMEOUT, TOAST_PERMANENT_TIMEOUT } from '@nextcloud/dialogs'
import '@nextcloud/dialogs/dist/index.css'
import InfoIcon from 'vue-material-design-icons/Information.vue'
import PlusIcon from 'vue-material-design-icons/Plus.vue'
import CogIcon from 'vue-material-design-icons/Cog.vue'
Expand All @@ -75,7 +74,6 @@ export default {
components: {
AppSettings,
EditorHint,
InfoIcon,
NavigationList,
NcAppContent,
NcAppNavigation,
Expand Down
55 changes: 37 additions & 18 deletions src/components/AppSettings.vue
Expand Up @@ -7,29 +7,27 @@
@update:open="setSettingsOpen($event)"
>
<NcAppSettingsSection id="help-basics" :title="t('notes', 'Basics')">
<div class="feature icon-add">
{{ t('notes', 'Start writing a note by clicking on “{newnote}” in the app navigation.', { newnote: t('notes', 'New note') }) }}
</div>
<div class="feature icon-fullscreen">
{{ t('notes', 'Write down your thoughts without any distractions.') }}
</div>
<div class="feature icon-files-dark">
{{ t('notes', 'Organize your notes in categories.') }}
</div>
<div class="feature icon-add">
{{ t('notes', 'Start writing a note by clicking on “{newnote}” in the app navigation.', { newnote: t('notes', 'New note') }) }}
</div>
<div class="feature icon-fullscreen">
{{ t('notes', 'Write down your thoughts without any distractions.') }}
</div>
<div class="feature icon-files-dark">
{{ t('notes', 'Organize your notes in categories.') }}
</div>
</NcAppSettingsSection>
<NcAppSettingsSection id="notes-path-section" :title="t('notes', 'Notes path')">
<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 8982461

Please sign in to comment.