Skip to content

feat: setting to show/hide hidden files #1541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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 @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/NotesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/NoteUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 13 additions & 6 deletions lib/Service/NotesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand All @@ -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)) {
Expand All @@ -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, '.');
}

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

Expand Down Expand Up @@ -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 {
Expand All @@ -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 . '.');
}
}

}
22 changes: 22 additions & 0 deletions src/components/AppSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@
<p class="app-settings-section__desc">
{{ t('notes', 'Folder to store your notes') }}
</p>

<input id="notesPath"
v-model="settings.notesPath"
type="text"
name="notesPath"
:placeholder="t('notes', 'Root directory')"
@click="onChangeNotePath"
>
<div>
<NcCheckboxRadioSwitch
v-model="settings.showHidden"
@update:checked="onChangeSettings"
>
{{ t('notes', 'Show hidden folders') }}
</NcCheckboxRadioSwitch>
</div>
</NcAppSettingsSection>
<NcAppSettingsSection id="file-suffix-section" :name="t('notes', 'File extension')">
<p class="app-settings-section__desc">
Expand Down Expand Up @@ -87,6 +96,7 @@
import {
NcAppSettingsDialog,
NcAppSettingsSection,
NcCheckboxRadioSwitch,
} from '@nextcloud/vue'

import { getFilePickerBuilder } from '@nextcloud/dialogs'
Expand All @@ -101,6 +111,7 @@ export default {
components: {
NcAppSettingsDialog,
NcAppSettingsSection,
NcCheckboxRadioSwitch,
HelpMobile,
},

Expand Down Expand Up @@ -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),
}
},

Expand Down Expand Up @@ -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')
}
Comment on lines +211 to +215
Copy link
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
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 @@ -211,4 +229,8 @@ export default {
.settings-block form {
display: inline-flex;
}

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