diff --git a/lib/AppInfo/BeforeShareCreatedListener.php b/lib/AppInfo/BeforeShareCreatedListener.php index 454639a04..5cd9aff23 100644 --- a/lib/AppInfo/BeforeShareCreatedListener.php +++ b/lib/AppInfo/BeforeShareCreatedListener.php @@ -50,11 +50,11 @@ public function overwriteShareTarget(IShare $share): void { $itemTarget = $share->getTarget(); $uidOwner = $share->getSharedBy(); $ownerPath = $this->noteUtil->getRoot()->getUserFolder($uidOwner)->getPath(); - $ownerNotesPath = $ownerPath . '/' . $this->settings->get($uidOwner, 'notesPath'); + $ownerNotesPath = $ownerPath . '/' . $this->settings->getValueString($uidOwner, 'notesPath'); $receiver = $share->getSharedWith(); $receiverPath = $this->noteUtil->getRoot()->getUserFolder($receiver)->getPath(); - $receiverNotesInternalPath = $this->settings->get($receiver, 'notesPath'); + $receiverNotesInternalPath = $this->settings->getValueString($receiver, 'notesPath'); $this->noteUtil->getOrCreateNotesFolder($receiver); if ($itemType !== 'file' || strpos($fileSourcePath, $ownerNotesPath) !== 0) { diff --git a/lib/Controller/NotesController.php b/lib/Controller/NotesController.php index c323e8717..7a74194de 100644 --- a/lib/Controller/NotesController.php +++ b/lib/Controller/NotesController.php @@ -359,7 +359,7 @@ public function uploadFile(int $noteid): JSONResponse { } private function inLockScope(Note $note, callable $callback) { - $isRichText = $this->settingsService->get($this->helper->getUID(), 'noteMode') === 'rich'; + $isRichText = $this->settingsService->getValueString($this->helper->getUID(), 'noteMode') === 'rich'; $lockContext = new LockContext( $note->getFile(), $isRichText ? ILock::TYPE_APP : ILock::TYPE_USER, diff --git a/lib/Service/NoteUtil.php b/lib/Service/NoteUtil.php index 8329aa64b..a5dd7941f 100644 --- a/lib/Service/NoteUtil.php +++ b/lib/Service/NoteUtil.php @@ -197,7 +197,7 @@ public function getNotesFolderUserPath(string $userId): ?string { public function getOrCreateNotesFolder(string $userId, bool $create = true) : Folder { $userFolder = $this->getRoot()->getUserFolder($userId); - $notesPath = $this->settingsService->get($userId, 'notesPath'); + $notesPath = $this->settingsService->getValueString($userId, 'notesPath'); $allowShared = $notesPath !== $this->settingsService->getDefaultNotesPath($userId); $folder = null; diff --git a/lib/Service/NotesService.php b/lib/Service/NotesService.php index dca19508f..1e60cf561 100644 --- a/lib/Service/NotesService.php +++ b/lib/Service/NotesService.php @@ -34,7 +34,8 @@ public function getAll(string $userId, bool $autoCreateNotesFolder = false) : ar $customExtension = $this->getCustomExtension($userId); try { $notesFolder = $this->getNotesFolder($userId, $autoCreateNotesFolder); - $data = self::gatherNoteFiles($customExtension, $notesFolder); + $showHidden = $this->settings->getValueBool($userId, 'showHidden'); + $data = self::gatherNoteFiles($customExtension, $notesFolder, $showHidden); $fileIds = array_keys($data['files']); // pre-load tags for all notes (performance improvement) $this->noteUtil->getTagService()->loadTags($fileIds); @@ -66,7 +67,8 @@ public function countNotes(string $userId) : int { $customExtension = $this->getCustomExtension($userId); try { $notesFolder = $this->getNotesFolder($userId, false); - $data = self::gatherNoteFiles($customExtension, $notesFolder); + $showHidden = $this->settings->getValueBool($userId, 'showHidden'); + $data = self::gatherNoteFiles($customExtension, $notesFolder, $showHidden); return count($data['files']); } catch (NotesFolderException $e) { return 0; @@ -128,9 +130,9 @@ public function create(string $userId, string $title, string $category) : Note { $this->noteUtil->ensureSufficientStorage($folder, 1); // get file name - $fileSuffix = $this->settings->get($userId, 'fileSuffix'); + $fileSuffix = $this->settings->getValueString($userId, 'fileSuffix'); if ($fileSuffix === 'custom') { - $fileSuffix = $this->settings->get($userId, 'customSuffix'); + $fileSuffix = $this->settings->getValueString($userId, 'customSuffix'); } $filename = $this->noteUtil->generateFileName($folder, $title, $fileSuffix, -1); // create file @@ -168,6 +170,7 @@ private function getNotesFolder(string $userId, bool $create = true) : Folder { private static function gatherNoteFiles( string $customExtension, Folder $folder, + bool $showHidden, string $categoryPrefix = '', ) : array { $data = [ @@ -176,10 +179,14 @@ private static function gatherNoteFiles( ]; $nodes = $folder->getDirectoryListing(); foreach ($nodes as $node) { + $hidden = str_starts_with($node->getName(), '.'); + if ($hidden && !$showHidden) { + continue; + } if ($node->getType() === FileInfo::TYPE_FOLDER && $node instanceof Folder) { $subCategory = $categoryPrefix . $node->getName(); $data['categories'][] = $subCategory; - $data_sub = self::gatherNoteFiles($customExtension, $node, $subCategory . '/'); + $data_sub = self::gatherNoteFiles($customExtension, $node, $showHidden, $subCategory . '/'); $data['files'] = $data['files'] + $data_sub['files']; $data['categories'] = $data['categories'] + $data_sub['categories']; } elseif (self::isNote($node, $customExtension)) { @@ -202,7 +209,7 @@ private static function isNote(FileInfo $file, string $customExtension) : bool { * Retrieve the value of user defined files extension */ private function getCustomExtension(string $userId) { - $suffix = $this->settings->get($userId, 'customSuffix'); + $suffix = $this->settings->getValueString($userId, 'customSuffix'); return ltrim($suffix, '.'); } diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php index bda763d9f..a1e3dafd2 100644 --- a/lib/Service/SettingsService.php +++ b/lib/Service/SettingsService.php @@ -68,6 +68,12 @@ public function __construct( return '.' . $out; }, ], + 'showHidden' => [ + 'default' => false, + 'validate' => function (mixed $value) : bool { + return (bool)$value; + } + ], ]; } @@ -169,13 +175,15 @@ public function getAll(string $uid, $saveInitial = false) : \stdClass { /** * @throws \OCP\PreConditionNotMetException */ - public function get(string $uid, string $name) : string { - $settings = $this->getAll($uid); - if (property_exists($settings, $name)) { - return $settings->{$name}; - } else { - throw new \OCP\PreConditionNotMetException('Setting ' . $name . ' not found for user ' . $uid . '.'); - } + public function getValueString(string $uid, string $name) : string { + return $this->get($uid, $name, 'string'); + } + + /** + * @throws \OCP\PreConditionNotMetException + */ + public function getValueBool(string $uid, string $name) : bool { + return $this->get($uid, $name, 'boolean'); } public function delete(string $uid, string $name): void { @@ -198,4 +206,22 @@ private function getAvailableEditorModes(): array { ? ['rich', 'edit', 'preview'] : ['edit', 'preview']; } + + /** + * @throws \OCP\PreConditionNotMetException + */ + private function get(string $uid, string $name, string $type) : mixed { + $settings = $this->getAll($uid); + if (property_exists($settings, $name)) { + $value = $settings->{$name}; + if (gettype($value) !== $type) { + throw new \TypeError('Invalid type'); + } + + return $value; + } else { + throw new \OCP\PreConditionNotMetException('Setting ' . $name . ' not found for user ' . $uid . '.'); + } + } + } diff --git a/src/components/AppSettings.vue b/src/components/AppSettings.vue index 4d086dd48..fe61bd347 100644 --- a/src/components/AppSettings.vue +++ b/src/components/AppSettings.vue @@ -26,6 +26,7 @@
{{ t('notes', 'Folder to store your notes') }}
+ +@@ -87,6 +96,7 @@ import { NcAppSettingsDialog, NcAppSettingsSection, + NcCheckboxRadioSwitch, } from '@nextcloud/vue' import { getFilePickerBuilder } from '@nextcloud/dialogs' @@ -101,6 +111,7 @@ export default { components: { NcAppSettingsDialog, NcAppSettingsSection, + NcCheckboxRadioSwitch, HelpMobile, }, @@ -136,6 +147,7 @@ export default { { shortcut: t('notes', 'CTRL') + '+' + t('notes', 'ALT') + '+I', action: t('notes', 'Insert image') }, { shortcut: t('notes', 'CTRL') + '+/', action: t('notes', 'Switch between editor and viewer') }, ], + initialShowHidden: Boolean(store.state.app.settings.showHidden), } }, @@ -195,6 +207,12 @@ export default { setSettingsOpen(newValue) { this.settingsOpen = newValue this.$emit('update:open', newValue) + + if (this.settingsOpen) { + this.$data.initialShowHidden = Boolean(store.state.app.settings.showHidden) + } else if (this.$data.initialShowHidden !== store.state.app.settings.showHidden) { + this.$emit('reload') + } }, }, } @@ -211,4 +229,8 @@ export default { .settings-block form { display: inline-flex; } + +#notesPath { + margin-bottom: 1rem; +}