Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion lib/Controller/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ public function getNotesAndCategories(
?string $category = null,
int $chunkSize = 0,
?string $chunkCursorStr = null,
?bool $showHidden = null,
) : array {
$userId = $this->getUID();
$chunkCursor = $chunkCursorStr ? ChunkCursor::fromString($chunkCursorStr) : null;
$lastUpdate = $chunkCursor->timeStart ?? new \DateTime();
$data = $this->notesService->getAll($userId, true); // auto-create notes folder if not exists
$data = $this->notesService->getAll($userId, true, $showHidden); // auto-create notes folder if not exists
$metaNotes = $this->metaService->getAll($userId, $data['notes']);

// if a category is requested, then ignore all other notes
Expand Down
4 changes: 3 additions & 1 deletion lib/Controller/NotesApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public function index(
$this->settingsService->getAll($userId, true);
// load notes and categories
$exclude = explode(',', $exclude);
$data = $this->helper->getNotesAndCategories($pruneBefore, $exclude, $category, $chunkSize, $chunkCursor);
// show hidden folders by default, ignoring settings, so clients can handle them at will
$showHidden = true;
$data = $this->helper->getNotesAndCategories($pruneBefore, $exclude, $category, $chunkSize, $chunkCursor, $showHidden);
$notesData = $data['notesData'];
if (!$data['chunkCursor']) {
// if last chunk, then send all notes (pruned)
Expand Down
17 changes: 13 additions & 4 deletions lib/Service/NotesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@
$this->noteUtil = $noteUtil;
}

public function getAll(string $userId, bool $autoCreateNotesFolder = false) : array {
public function getAll(string $userId, bool $autoCreateNotesFolder = false, ?bool $showHidden = null) : array {
$customExtension = $this->getCustomExtension($userId);
try {
$notesFolder = $this->getNotesFolder($userId, $autoCreateNotesFolder);
$data = self::gatherNoteFiles($customExtension, $notesFolder);
if ($showHidden === null) {
$showHidden = $this->settings->get($userId, 'showHidden');
}
$data = self::gatherNoteFiles($customExtension, $notesFolder, $showHidden);

Check failure on line 40 in lib/Service/NotesService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable31

PossiblyInvalidArgument

lib/Service/NotesService.php:40:66: PossiblyInvalidArgument: Argument 3 of OCA\Notes\Service\NotesService::gatherNoteFiles expects bool, but possibly different type bool|string provided (see https://psalm.dev/092)

Check failure on line 40 in lib/Service/NotesService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

PossiblyInvalidArgument

lib/Service/NotesService.php:40:66: PossiblyInvalidArgument: Argument 3 of OCA\Notes\Service\NotesService::gatherNoteFiles expects bool, but possibly different type bool|string provided (see https://psalm.dev/092)

Check failure on line 40 in lib/Service/NotesService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

PossiblyInvalidArgument

lib/Service/NotesService.php:40:66: PossiblyInvalidArgument: Argument 3 of OCA\Notes\Service\NotesService::gatherNoteFiles expects bool, but possibly different type bool|string provided (see https://psalm.dev/092)

Check failure on line 40 in lib/Service/NotesService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

PossiblyInvalidArgument

lib/Service/NotesService.php:40:66: PossiblyInvalidArgument: Argument 3 of OCA\Notes\Service\NotesService::gatherNoteFiles expects bool, but possibly different type bool|string provided (see https://psalm.dev/092)
$fileIds = array_keys($data['files']);
// pre-load tags for all notes (performance improvement)
$this->noteUtil->getTagService()->loadTags($fileIds);
Expand Down Expand Up @@ -66,7 +69,8 @@
$customExtension = $this->getCustomExtension($userId);
try {
$notesFolder = $this->getNotesFolder($userId, false);
$data = self::gatherNoteFiles($customExtension, $notesFolder);
$showHidden = $this->settings->get($userId, 'showHidden');
$data = self::gatherNoteFiles($customExtension, $notesFolder, $showHidden);

Check failure on line 73 in lib/Service/NotesService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable31

PossiblyInvalidArgument

lib/Service/NotesService.php:73:66: PossiblyInvalidArgument: Argument 3 of OCA\Notes\Service\NotesService::gatherNoteFiles expects bool, but possibly different type bool|string provided (see https://psalm.dev/092)

Check failure on line 73 in lib/Service/NotesService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

PossiblyInvalidArgument

lib/Service/NotesService.php:73:66: PossiblyInvalidArgument: Argument 3 of OCA\Notes\Service\NotesService::gatherNoteFiles expects bool, but possibly different type bool|string provided (see https://psalm.dev/092)

Check failure on line 73 in lib/Service/NotesService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

PossiblyInvalidArgument

lib/Service/NotesService.php:73:66: PossiblyInvalidArgument: Argument 3 of OCA\Notes\Service\NotesService::gatherNoteFiles expects bool, but possibly different type bool|string provided (see https://psalm.dev/092)

Check failure on line 73 in lib/Service/NotesService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

PossiblyInvalidArgument

lib/Service/NotesService.php:73:66: PossiblyInvalidArgument: Argument 3 of OCA\Notes\Service\NotesService::gatherNoteFiles expects bool, but possibly different type bool|string provided (see https://psalm.dev/092)
return count($data['files']);
} catch (NotesFolderException $e) {
return 0;
Expand Down Expand Up @@ -132,7 +136,7 @@
if ($fileSuffix === 'custom') {
$fileSuffix = $this->settings->get($userId, 'customSuffix');
}
$filename = $this->noteUtil->generateFileName($folder, $title, $fileSuffix, -1);

Check failure on line 139 in lib/Service/NotesService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable31

PossiblyInvalidArgument

lib/Service/NotesService.php:139:66: PossiblyInvalidArgument: Argument 3 of OCA\Notes\Service\NoteUtil::generateFileName expects string, but possibly different type bool|string provided (see https://psalm.dev/092)

Check failure on line 139 in lib/Service/NotesService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

PossiblyInvalidArgument

lib/Service/NotesService.php:139:66: PossiblyInvalidArgument: Argument 3 of OCA\Notes\Service\NoteUtil::generateFileName expects string, but possibly different type bool|string provided (see https://psalm.dev/092)

Check failure on line 139 in lib/Service/NotesService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

PossiblyInvalidArgument

lib/Service/NotesService.php:139:66: PossiblyInvalidArgument: Argument 3 of OCA\Notes\Service\NoteUtil::generateFileName expects string, but possibly different type bool|string provided (see https://psalm.dev/092)

Check failure on line 139 in lib/Service/NotesService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

PossiblyInvalidArgument

lib/Service/NotesService.php:139:66: PossiblyInvalidArgument: Argument 3 of OCA\Notes\Service\NoteUtil::generateFileName expects string, but possibly different type bool|string provided (see https://psalm.dev/092)
// create file
$file = $folder->newFile($filename);

Expand Down Expand Up @@ -168,6 +172,7 @@
private static function gatherNoteFiles(
string $customExtension,
Folder $folder,
bool $showHidden,
string $categoryPrefix = '',
) : array {
$data = [
Expand All @@ -176,10 +181,14 @@
];
$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 @@ -203,7 +212,7 @@
*/
private function getCustomExtension(string $userId) {
$suffix = $this->settings->get($userId, 'customSuffix');
return ltrim($suffix, '.');

Check failure on line 215 in lib/Service/NotesService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable31

PossiblyInvalidArgument

lib/Service/NotesService.php:215:16: PossiblyInvalidArgument: Argument 1 of ltrim expects string, but possibly different type bool|string provided (see https://psalm.dev/092)

Check failure on line 215 in lib/Service/NotesService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

PossiblyInvalidArgument

lib/Service/NotesService.php:215:16: PossiblyInvalidArgument: Argument 1 of ltrim expects string, but possibly different type bool|string provided (see https://psalm.dev/092)

Check failure on line 215 in lib/Service/NotesService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

PossiblyInvalidArgument

lib/Service/NotesService.php:215:16: PossiblyInvalidArgument: Argument 1 of ltrim expects string, but possibly different type bool|string provided (see https://psalm.dev/092)

Check failure on line 215 in lib/Service/NotesService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

PossiblyInvalidArgument

lib/Service/NotesService.php:215:16: PossiblyInvalidArgument: Argument 1 of ltrim expects string, but possibly different type bool|string provided (see https://psalm.dev/092)
}

/**
Expand Down
8 changes: 7 additions & 1 deletion lib/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
return '.' . $out;
},
],
'showHidden' => [
'default' => true,
'validate' => function ($value) {

Check failure on line 73 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable31

MissingClosureReturnType

lib/Service/SettingsService.php:73:19: MissingClosureReturnType: Closure does not have a return type, expecting bool (see https://psalm.dev/068)

Check failure on line 73 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

MissingClosureReturnType

lib/Service/SettingsService.php:73:19: MissingClosureReturnType: Closure does not have a return type, expecting bool (see https://psalm.dev/068)

Check failure on line 73 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

MissingClosureReturnType

lib/Service/SettingsService.php:73:19: MissingClosureReturnType: Closure does not have a return type, expecting bool (see https://psalm.dev/068)

Check failure on line 73 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

MissingClosureReturnType

lib/Service/SettingsService.php:73:19: MissingClosureReturnType: Closure does not have a return type, expecting bool (see https://psalm.dev/068)
return (bool)$value;
}
],
];
}

Expand All @@ -76,7 +82,7 @@

return [
'default' => $default,
'validate' => function ($value) use ($values, $default) {

Check failure on line 85 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable31

MissingClosureParamType

lib/Service/SettingsService.php:85:28: MissingClosureParamType: Parameter $value has no provided type (see https://psalm.dev/153)

Check failure on line 85 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable29

MissingClosureParamType

lib/Service/SettingsService.php:85:28: MissingClosureParamType: Parameter $value has no provided type (see https://psalm.dev/153)

Check failure on line 85 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

MissingClosureParamType

lib/Service/SettingsService.php:85:28: MissingClosureParamType: Parameter $value has no provided type (see https://psalm.dev/153)

Check failure on line 85 in lib/Service/SettingsService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

MissingClosureParamType

lib/Service/SettingsService.php:85:28: MissingClosureParamType: Parameter $value has no provided type (see https://psalm.dev/153)
if (in_array($value, $values)) {
return $value;
} else {
Expand Down Expand Up @@ -169,7 +175,7 @@
/**
* @throws \OCP\PreConditionNotMetException
*/
public function get(string $uid, string $name) : string {
public function get(string $uid, string $name) : string|bool {
$settings = $this->getAll($uid);
if (property_exists($settings, $name)) {
return $settings->{$name};
Expand Down
24 changes: 23 additions & 1 deletion src/components/AppSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,26 @@
{{ t('notes', 'Organize your notes in categories.') }}
</div>
</NcAppSettingsSection>
<NcAppSettingsSection id="notes-path-section" :name="t('notes', 'Notes path')">
<NcAppSettingsSection id="notes-path-section" :name="t('notes', 'Notes folder')">
<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>
Loading