This commit is contained in:
vincowl 2022-02-12 16:43:44 +01:00 коммит произвёл GitHub
Родитель a82246113f
Коммит d67a0f2678
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 54 добавлений и 17 удалений

Просмотреть файл

@ -92,6 +92,7 @@ OC.L10N.register(
"Updating the note's category has failed. Is the target directory writable?" : "Impossible de mettre à jour la catégorie de la note. Vérifiez que vous avez le droit d'écriture dans ce dossier.",
"Updating the category for note {id} has failed." : "La mise à jour de la catégorie pour la note {id} a échoué.",
"Development Mode" : "Mode développeur",
"It looks that the notes app was installed from a development source. Please install it from the official <a href=\"%1$s\">Nextcloud App Store</a> instead. If you want to build the Notes app by yourself, please follow the <a href=\"%2$s\">developer instructions</a>." : "Il semble que l'application Notes a été installée depuis une source de développement. Veuillez plutôt l'installer depuis le <a href=\"%1$s\">Nextcloud App Store</a> officiel. Si vous voulez construire l'application Notes par vous-même, veuillez suivre les <a href=\"%2$s\">instructions pour le développeur</a>."
"It looks that the notes app was installed from a development source. Please install it from the official <a href=\"%1$s\">Nextcloud App Store</a> instead. If you want to build the Notes app by yourself, please follow the <a href=\"%2$s\">developer instructions</a>." : "Il semble que l'application Notes a été installée depuis une source de développement. Veuillez plutôt l'installer depuis le <a href=\"%1$s\">Nextcloud App Store</a> officiel. Si vous voulez construire l'application Notes par vous-même, veuillez suivre les <a href=\"%2$s\">instructions pour le développeur</a>.",
"user defined" : "personnalisé",
},
"nplurals=2; plural=(n > 1);");

Просмотреть файл

@ -91,5 +91,6 @@
"Updating the category for note {id} has failed." : "La mise à jour de la catégorie pour la note {id} a échoué.",
"Development Mode" : "Mode développeur",
"It looks that the notes app was installed from a development source. Please install it from the official <a href=\"%1$s\">Nextcloud App Store</a> instead. If you want to build the Notes app by yourself, please follow the <a href=\"%2$s\">developer instructions</a>." : "Il semble que l'application Notes a été installée depuis une source de développement. Veuillez plutôt l'installer depuis le <a href=\"%1$s\">Nextcloud App Store</a> officiel. Si vous voulez construire l'application Notes par vous-même, veuillez suivre les <a href=\"%2$s\">instructions pour le développeur</a>."
"user defined" : "personnalisé"
},"pluralForm" :"nplurals=2; plural=(n > 1);"
}
}

Просмотреть файл

@ -25,8 +25,9 @@ class NotesService {
}
public function getAll(string $userId) : array {
$customExtension = $this->getCustomExtension($userId);
$notesFolder = $this->getNotesFolder($userId);
$data = $this->gatherNoteFiles($notesFolder);
$data = self::gatherNoteFiles($customExtension, $notesFolder);
$fileIds = array_keys($data['files']);
// pre-load tags for all notes (performance improvement)
$this->noteUtil->getTagService()->loadTags($fileIds);
@ -51,8 +52,9 @@ class NotesService {
}
public function get(string $userId, int $id) : Note {
$customExtension = $this->getCustomExtension($userId);
$notesFolder = $this->getNotesFolder($userId);
$note = new Note($this->getFileById($notesFolder, $id), $notesFolder, $this->noteUtil);
$note = new Note(self::getFileById($customExtension, $notesFolder, $id), $notesFolder, $this->noteUtil);
$this->metaService->update($userId, $note);
return $note;
}
@ -102,8 +104,10 @@ class NotesService {
// get file name
$fileSuffix = $this->settings->get($userId, 'fileSuffix');
if ($fileSuffix === "custom") {
$fileSuffix = $this->settings->get($userId, 'customSuffix');
}
$filename = $this->noteUtil->generateFileName($folder, $title, $fileSuffix, -1);
// create file
$file = $folder->newFile($filename);
@ -115,8 +119,9 @@ class NotesService {
* @throws NoteDoesNotExistException if note does not exist
*/
public function delete(string $userId, int $id) {
$customExtension = $this->getCustomExtension($userId);
$notesFolder = $this->getNotesFolder($userId);
$file = $this->getFileById($notesFolder, $id);
$file = self::getFileById($customExtension, $notesFolder, $id);
$this->noteUtil->ensureNoteIsWritable($file);
$parent = $file->getParent();
$file->delete();
@ -147,7 +152,7 @@ class NotesService {
/**
* gather note files in given directory and all subdirectories
*/
private static function gatherNoteFiles(Folder $folder, string $categoryPrefix = '') : array {
private static function gatherNoteFiles(string $customExtension, Folder $folder, string $categoryPrefix = '') : array {
$data = [
'files' => [],
'categories' => [],
@ -157,10 +162,10 @@ class NotesService {
if ($node->getType() === FileInfo::TYPE_FOLDER && $node instanceof Folder) {
$subCategory = $categoryPrefix . $node->getName();
$data['categories'][] = $subCategory;
$data_sub = self::gatherNoteFiles($node, $subCategory . '/');
$data_sub = self::gatherNoteFiles($customExtension, $node, $subCategory . '/');
$data['files'] = $data['files'] + $data_sub['files'];
$data['categories'] = $data['categories'] + $data_sub['categories'];
} elseif (self::isNote($node)) {
} elseif (self::isNote($node, $customExtension)) {
$data['files'][$node->getId()] = $node;
}
}
@ -170,19 +175,27 @@ class NotesService {
/**
* test if file is a note
*/
private static function isNote(FileInfo $file) : bool {
private static function isNote(FileInfo $file, string $customExtension) : bool {
static $allowedExtensions = ['txt', 'org', 'markdown', 'md', 'note'];
$ext = strtolower(pathinfo($file->getName(), PATHINFO_EXTENSION));
return $file->getType() === 'file' && in_array($ext, $allowedExtensions);
return $file->getType() === 'file' && (in_array($ext, $allowedExtensions) || $ext === $customExtension);
}
/**
* Retrieve the value of user defined files extension
*/
private function getCustomExtension(string $userId) {
$suffix = $this->settings->get($userId, 'customSuffix');
return ltrim($suffix, ".");
}
/**
* @throws NoteDoesNotExistException
*/
private static function getFileById(Folder $folder, int $id) : File {
private static function getFileById(string $customExtension, Folder $folder, int $id) : File {
$file = $folder->getById($id);
if (!array_key_exists(0, $file) || !($file[0] instanceof File) || !self::isNote($file[0])) {
if (!array_key_exists(0, $file) || !($file[0] instanceof File) || !self::isNote($file[0], $customExtension)) {
throw new NoteDoesNotExistException();
}
return $file[0];

Просмотреть файл

@ -27,7 +27,7 @@ class SettingsService {
$this->l10n = $l10n;
$this->root = $root;
$this->attrs = [
'fileSuffix' => $this->getListAttrs('.txt', '.md'),
'fileSuffix' => $this->getListAttrs('.txt', '.md', 'custom'),
'notesPath' => [
'default' => function (string $uid) {
return $this->getDefaultNotesPath($uid);
@ -47,6 +47,16 @@ class SettingsService {
},
],
'noteMode' => $this->getListAttrs('edit', 'preview'),
'customSuffix' => [
'default' => '.txt',
'validate' => function ($value) {
$out = ltrim(preg_replace('/[^A-Za-z0-9.-]/', '', $value), '.');
if (empty($out)) {
$out = 'txt';
}
return '.' . $out;
},
],
];
}

Просмотреть файл

@ -19,10 +19,18 @@
<label for="fileSuffix">{{ t('notes', 'File extension for new notes') }}</label>
</p>
<select id="fileSuffix" v-model="settings.fileSuffix" @change="onChangeSettings">
<option v-for="ext in extensions" :key="ext" :value="ext">
{{ ext }}
<option v-for="extension in extensions" :key="extension.value" :value="extension.value">
{{ extension.label }}
</option>
</select>
<input v-show="settings.fileSuffix === 'custom'"
id="customSuffix"
v-model="settings.customSuffix"
name="customSuffix"
type="text"
placeholder=".txt"
@change="onChangeSettings"
>
</div>
<div class="settings-block">
<p class="settings-hint">
@ -54,7 +62,11 @@ export default {
data() {
return {
extensions: ['.txt', '.md'],
extensions: [
{ value: '.txt', label: '.txt' },
{ value: '.md', label: '.md' },
{ value: 'custom', label: t('notes', 'user defined') },
],
noteModes: [
{ value: 'edit', label: t('notes', 'Open in edit mode') },
{ value: 'preview', label: t('notes', 'Open in preview mode') },