Skip to content

Commit e19b79b

Browse files
committed
feat: setting to show/hide hidden files
fixes #1245 Signed-off-by: Roberto Vidal <roberto.vidal@ikumene.com>
1 parent aa48912 commit e19b79b

File tree

5 files changed

+48
-8
lines changed

5 files changed

+48
-8
lines changed

lib/Controller/Helper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ public function getNotesAndCategories(
7575
?string $category = null,
7676
int $chunkSize = 0,
7777
?string $chunkCursorStr = null,
78+
?bool $showHidden = null,
7879
) : array {
7980
$userId = $this->getUID();
8081
$chunkCursor = $chunkCursorStr ? ChunkCursor::fromString($chunkCursorStr) : null;
8182
$lastUpdate = $chunkCursor->timeStart ?? new \DateTime();
82-
$data = $this->notesService->getAll($userId, true); // auto-create notes folder if not exists
83+
$data = $this->notesService->getAll($userId, true, $showHidden); // auto-create notes folder if not exists
8384
$metaNotes = $this->metaService->getAll($userId, $data['notes']);
8485

8586
// if a category is requested, then ignore all other notes

lib/Controller/NotesApiController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public function index(
6666
$this->settingsService->getAll($userId, true);
6767
// load notes and categories
6868
$exclude = explode(',', $exclude);
69-
$data = $this->helper->getNotesAndCategories($pruneBefore, $exclude, $category, $chunkSize, $chunkCursor);
69+
// show hidden folders by default, ignoring settings, so clients can handle them at will
70+
$showHidden = true;
71+
$data = $this->helper->getNotesAndCategories($pruneBefore, $exclude, $category, $chunkSize, $chunkCursor, $showHidden);
7072
$notesData = $data['notesData'];
7173
if (!$data['chunkCursor']) {
7274
// if last chunk, then send all notes (pruned)

lib/Service/NotesService.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ public function __construct(
3030
$this->noteUtil = $noteUtil;
3131
}
3232

33-
public function getAll(string $userId, bool $autoCreateNotesFolder = false) : array {
33+
public function getAll(string $userId, bool $autoCreateNotesFolder = false, ?bool $showHidden = null) : array {
3434
$customExtension = $this->getCustomExtension($userId);
3535
try {
3636
$notesFolder = $this->getNotesFolder($userId, $autoCreateNotesFolder);
37-
$data = self::gatherNoteFiles($customExtension, $notesFolder);
37+
if ($showHidden === null) {
38+
$showHidden = $this->settings->get($userId, 'showHidden');
39+
}
40+
$data = self::gatherNoteFiles($customExtension, $notesFolder, $showHidden);
3841
$fileIds = array_keys($data['files']);
3942
// pre-load tags for all notes (performance improvement)
4043
$this->noteUtil->getTagService()->loadTags($fileIds);
@@ -66,7 +69,8 @@ public function countNotes(string $userId) : int {
6669
$customExtension = $this->getCustomExtension($userId);
6770
try {
6871
$notesFolder = $this->getNotesFolder($userId, false);
69-
$data = self::gatherNoteFiles($customExtension, $notesFolder);
72+
$showHidden = $this->settings->get($userId, 'showHidden');
73+
$data = self::gatherNoteFiles($customExtension, $notesFolder, $showHidden);
7074
return count($data['files']);
7175
} catch (NotesFolderException $e) {
7276
return 0;
@@ -168,6 +172,7 @@ private function getNotesFolder(string $userId, bool $create = true) : Folder {
168172
private static function gatherNoteFiles(
169173
string $customExtension,
170174
Folder $folder,
175+
bool $showHidden,
171176
string $categoryPrefix = '',
172177
) : array {
173178
$data = [
@@ -176,10 +181,14 @@ private static function gatherNoteFiles(
176181
];
177182
$nodes = $folder->getDirectoryListing();
178183
foreach ($nodes as $node) {
184+
$hidden = str_starts_with($node->getName(), '.');
185+
if ($hidden && !$showHidden) {
186+
continue;
187+
}
179188
if ($node->getType() === FileInfo::TYPE_FOLDER && $node instanceof Folder) {
180189
$subCategory = $categoryPrefix . $node->getName();
181190
$data['categories'][] = $subCategory;
182-
$data_sub = self::gatherNoteFiles($customExtension, $node, $subCategory . '/');
191+
$data_sub = self::gatherNoteFiles($customExtension, $node, $showHidden, $subCategory . '/');
183192
$data['files'] = $data['files'] + $data_sub['files'];
184193
$data['categories'] = $data['categories'] + $data_sub['categories'];
185194
} elseif (self::isNote($node, $customExtension)) {

lib/Service/SettingsService.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ public function __construct(
6868
return '.' . $out;
6969
},
7070
],
71+
'showHidden' => [
72+
'default' => true,
73+
'validate' => function ($value) {
74+
return (bool)$value;
75+
}
76+
],
7177
];
7278
}
7379

@@ -169,7 +175,7 @@ public function getAll(string $uid, $saveInitial = false) : \stdClass {
169175
/**
170176
* @throws \OCP\PreConditionNotMetException
171177
*/
172-
public function get(string $uid, string $name) : string {
178+
public function get(string $uid, string $name) : string|bool {
173179
$settings = $this->getAll($uid);
174180
if (property_exists($settings, $name)) {
175181
return $settings->{$name};

src/components/AppSettings.vue

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,26 @@
2222
{{ t('notes', 'Organize your notes in categories.') }}
2323
</div>
2424
</NcAppSettingsSection>
25-
<NcAppSettingsSection id="notes-path-section" :name="t('notes', 'Notes path')">
25+
<NcAppSettingsSection id="notes-path-section" :name="t('notes', 'Notes folder')">
2626
<p class="app-settings-section__desc">
2727
{{ t('notes', 'Folder to store your notes') }}
2828
</p>
29+
2930
<input id="notesPath"
3031
v-model="settings.notesPath"
3132
type="text"
3233
name="notesPath"
3334
:placeholder="t('notes', 'Root directory')"
3435
@click="onChangeNotePath"
3536
>
37+
<div>
38+
<NcCheckboxRadioSwitch
39+
v-model="settings.showHidden"
40+
@update:checked="onChangeSettings"
41+
>
42+
{{ t('notes', 'Show hidden folders') }}
43+
</NcCheckboxRadioSwitch>
44+
</div>
3645
</NcAppSettingsSection>
3746
<NcAppSettingsSection id="file-suffix-section" :name="t('notes', 'File extension')">
3847
<p class="app-settings-section__desc">
@@ -87,6 +96,7 @@
8796
import {
8897
NcAppSettingsDialog,
8998
NcAppSettingsSection,
99+
NcCheckboxRadioSwitch,
90100
} from '@nextcloud/vue'
91101

92102
import { getFilePickerBuilder } from '@nextcloud/dialogs'
@@ -101,6 +111,7 @@ export default {
101111
components: {
102112
NcAppSettingsDialog,
103113
NcAppSettingsSection,
114+
NcCheckboxRadioSwitch,
104115
HelpMobile,
105116
},
106117

@@ -136,6 +147,7 @@ export default {
136147
{ shortcut: t('notes', 'CTRL') + '+' + t('notes', 'ALT') + '+I', action: t('notes', 'Insert image') },
137148
{ shortcut: t('notes', 'CTRL') + '+/', action: t('notes', 'Switch between editor and viewer') },
138149
],
150+
initialShowHidden: Boolean(store.state.app.settings.showHidden),
139151
}
140152
},
141153

@@ -195,6 +207,12 @@ export default {
195207
setSettingsOpen(newValue) {
196208
this.settingsOpen = newValue
197209
this.$emit('update:open', newValue)
210+
211+
if (this.settingsOpen) {
212+
this.$data.initialShowHidden = Boolean(store.state.app.settings.showHidden)
213+
} else if (this.$data.initialShowHidden !== store.state.app.settings.showHidden) {
214+
this.$emit('reload')
215+
}
198216
},
199217
},
200218
}
@@ -211,4 +229,8 @@ export default {
211229
.settings-block form {
212230
display: inline-flex;
213231
}
232+
233+
#notesPath {
234+
margin-bottom: 1rem;
235+
}
214236
</style>

0 commit comments

Comments
 (0)