Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/AppInfo/BeforeShareCreatedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/NotesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/NoteUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;
Expand Down
19 changes: 13 additions & 6 deletions lib/Service/NotesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand All @@ -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)) {
Expand All @@ -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, '.');
}

Expand Down
39 changes: 32 additions & 7 deletions lib/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public function __construct(
return '.' . $out;
},
],
'showHidden' => [
'default' => false,
'validate' => function (mixed $value) : bool {
return (bool)$value;
}
],
];
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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 . '.');
}
}
}
20 changes: 20 additions & 0 deletions src/components/AppSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
</NcFormBoxButton>
</NcFormBox>
</NcFormGroup>
<NcCheckboxRadioSwitch
v-model="settings.showHidden"
@update:modelValue="onChangeSettings"
>
{{ t('notes', 'Show hidden folders') }}
</NcCheckboxRadioSwitch>
</NcAppSettingsSection>

<NcAppSettingsSection :name="t('notes', 'Mobile apps')">
Expand All @@ -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'
Expand All @@ -113,6 +120,7 @@ export default {
NcTextField,
NcAppSettingsDialog,
NcAppSettingsSection,
NcCheckboxRadioSwitch,
HelpMobile,
NcAppSettingsShortcutsSection,
NcHotkeyList,
Expand Down Expand Up @@ -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),
}
},

Expand Down Expand Up @@ -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')
}
Comment on lines +240 to +244

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting fancy here and trying to avoid full in-place reloads until they're absolutely needed, instead of using onChangeSettingsReload(). I'm not sure it's a good fit for NC's general UX approach.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me. 👍

},
},
}
Expand All @@ -243,4 +259,8 @@ export default {
.settings-block form {
display: inline-flex;
}

#notesPath {
margin-bottom: 1rem;
}
</style>
Loading