diff --git a/lib/AppInfo/BeforeShareCreatedListener.php b/lib/AppInfo/BeforeShareCreatedListener.php
index f8d30195b..aab8f34df 100644
--- a/lib/AppInfo/BeforeShareCreatedListener.php
+++ b/lib/AppInfo/BeforeShareCreatedListener.php
@@ -56,11 +56,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 3b3fc1d1c..7de752bb7 100644
--- a/lib/Controller/NotesController.php
+++ b/lib/Controller/NotesController.php
@@ -371,7 +371,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 9b38c1fd2..f2431d229 100644
--- a/lib/Service/NoteUtil.php
+++ b/lib/Service/NoteUtil.php
@@ -192,7 +192,7 @@ public function getOrCreateFolder(string $path, bool $create = true) : Folder {
public function getNotesFolderUserPath(string $userId, bool $saveInitial = false): ?string {
try {
- $notesFolder = $this->settingsService->get($userId, 'notesPath', $saveInitial);
+ $notesFolder = $this->settingsService->getValueString($userId, 'notesPath', $saveInitial);
return $notesFolder;
} catch (NotesFolderException $e) {
$this->util->logger->debug("Failed to get notes folder for user $userId: " . $e->getMessage());
@@ -202,7 +202,7 @@ public function getNotesFolderUserPath(string $userId, bool $saveInitial = false
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');
['path' => $defaultPath, 'folder' => $folder] = $this->settingsService->getDefaultNotesNode($userId);
$allowShared = $notesPath !== $defaultPath;
diff --git a/lib/Service/NotesService.php b/lib/Service/NotesService.php
index 644b61f0c..d4373b575 100644
--- a/lib/Service/NotesService.php
+++ b/lib/Service/NotesService.php
@@ -27,7 +27,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);
@@ -59,7 +60,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;
@@ -122,9 +124,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
@@ -241,6 +243,7 @@ private function getNotesFolder(string $userId, bool $create = true) : Folder {
private static function gatherNoteFiles(
string $customExtension,
Folder $folder,
+ bool $showHidden,
string $categoryPrefix = '',
) : array {
$data = [
@@ -249,10 +252,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)) {
@@ -275,7 +282,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 55e5b7185..020b31dfe 100644
--- a/lib/Service/SettingsService.php
+++ b/lib/Service/SettingsService.php
@@ -69,6 +69,12 @@ public function __construct(
return '.' . $out;
},
],
+ 'showHidden' => [
+ 'default' => false,
+ 'validate' => function (mixed $value) : bool {
+ return (bool)$value;
+ }
+ ],
];
}
@@ -207,13 +213,15 @@ public function getAll(string $uid, $saveInitial = false) : \stdClass {
/**
* @throws \OCP\PreConditionNotMetException
*/
- public function get(string $uid, string $name, bool $saveInitial = false) : string {
- $settings = $this->getAll($uid, $saveInitial);
- 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, bool $saveInitial = false) : string {
+ return $this->get($uid, $name, 'string', $saveInitial);
+ }
+
+ /**
+ * @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 {
@@ -236,4 +244,21 @@ private function getAvailableEditorModes(): array {
? ['rich', 'edit', 'preview']
: ['edit', 'preview'];
}
+
+ /**
+ * @throws \OCP\PreConditionNotMetException
+ */
+ private function get(string $uid, string $name, string $type, bool $saveInitial = false) : mixed {
+ $settings = $this->getAll($uid, $saveInitial);
+ 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 5519d9f36..07cd749f1 100644
--- a/src/components/AppSettings.vue
+++ b/src/components/AppSettings.vue
@@ -67,6 +67,12 @@
+
+ {{ t('notes', 'Show hidden folders') }}
+
@@ -90,6 +96,7 @@ import { getFilePickerBuilder } from '@nextcloud/dialogs'
import NcAppSettingsDialog from '@nextcloud/vue/components/NcAppSettingsDialog'
import NcAppSettingsSection from '@nextcloud/vue/components/NcAppSettingsSection'
import NcAppSettingsShortcutsSection from '@nextcloud/vue/components/NcAppSettingsShortcutsSection'
+import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch'
import NcFormBox from '@nextcloud/vue/components/NcFormBox'
import NcFormBoxButton from '@nextcloud/vue/components/NcFormBoxButton'
import NcFormGroup from '@nextcloud/vue/components/NcFormGroup'
@@ -113,6 +120,7 @@ export default {
NcTextField,
NcAppSettingsDialog,
NcAppSettingsSection,
+ NcCheckboxRadioSwitch,
HelpMobile,
NcAppSettingsShortcutsSection,
NcHotkeyList,
@@ -167,6 +175,8 @@ export default {
{ shortcut: 'Control Alt I', action: t('notes', 'Insert image') },
{ shortcut: 'Control /', action: t('notes', 'Switch between editor and viewer') },
],
+
+ initialShowHidden: Boolean(store.app.settings.showHidden),
}
},
@@ -226,6 +236,12 @@ export default {
setSettingsOpen(newValue) {
this.settingsOpen = newValue
this.$emit('update:open', newValue)
+
+ if (this.settingsOpen) {
+ this.$data.initialShowHidden = Boolean(store.app.settings.showHidden)
+ } else if (this.$data.initialShowHidden !== store.app.settings.showHidden) {
+ this.$emit('reload')
+ }
},
},
}
@@ -243,4 +259,8 @@ export default {
.settings-block form {
display: inline-flex;
}
+
+#notesPath {
+ margin-bottom: 1rem;
+}