mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
tar import will sort notes if there is no meta file
This commit is contained in:
parent
516277a478
commit
d23e9f1bc4
@ -840,7 +840,7 @@ a.external:not(.no-arrow):after, a[href^="http://"]:not(.no-arrow):after, a[href
|
|||||||
}
|
}
|
||||||
|
|
||||||
.note-book-auto-message {
|
.note-book-auto-message {
|
||||||
background-color: var(--more-accented-background-color);
|
background-color: var(--accented-background-color);
|
||||||
text-align: center;
|
text-align: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
|
@ -14,6 +14,7 @@ const commonmark = require('commonmark');
|
|||||||
const ImportContext = require('../import_context');
|
const ImportContext = require('../import_context');
|
||||||
const protectedSessionService = require('../protected_session');
|
const protectedSessionService = require('../protected_session');
|
||||||
const mimeService = require("./mime");
|
const mimeService = require("./mime");
|
||||||
|
const treeService = require("../tree");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ImportContext} importContext
|
* @param {ImportContext} importContext
|
||||||
@ -426,6 +427,12 @@ async function importTar(importContext, fileBuffer, importRootNote) {
|
|||||||
for (const noteId in createdNoteIds) { // now the noteIds are unique
|
for (const noteId in createdNoteIds) { // now the noteIds are unique
|
||||||
await noteService.scanForLinks(noteId);
|
await noteService.scanForLinks(noteId);
|
||||||
|
|
||||||
|
if (!metaFile) {
|
||||||
|
// if there's no meta file then the notes are created based on the order in that tar file but that
|
||||||
|
// is usually quite random so we sort the notes in the way they would appear in the file manager
|
||||||
|
await treeService.sortNotesAlphabetically(noteId, true);
|
||||||
|
}
|
||||||
|
|
||||||
importContext.increaseProgressCount();
|
importContext.increaseProgressCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,15 +87,28 @@ async function loadSubtreeNoteIds(parentNoteId, subtreeNoteIds) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sortNotesAlphabetically(parentNoteId) {
|
async function sortNotesAlphabetically(parentNoteId, directoriesFirst = false) {
|
||||||
await sql.transactional(async () => {
|
await sql.transactional(async () => {
|
||||||
const notes = await sql.getRows(`SELECT branchId, noteId, title, isProtected
|
const notes = await sql.getRows(
|
||||||
FROM notes JOIN branches USING(noteId)
|
`SELECT branches.branchId, notes.noteId, title, isProtected,
|
||||||
WHERE branches.isDeleted = 0 AND parentNoteId = ?`, [parentNoteId]);
|
CASE WHEN COUNT(childBranches.noteId) > 0 THEN 1 ELSE 0 END AS hasChildren
|
||||||
|
FROM notes
|
||||||
|
JOIN branches ON branches.noteId = notes.noteId
|
||||||
|
LEFT JOIN branches childBranches ON childBranches.parentNoteId = notes.noteId AND childBranches.isDeleted = 0
|
||||||
|
WHERE branches.isDeleted = 0 AND branches.parentNoteId = ?
|
||||||
|
GROUP BY notes.noteId`, [parentNoteId]);
|
||||||
|
|
||||||
protectedSessionService.decryptNotes(notes);
|
protectedSessionService.decryptNotes(notes);
|
||||||
|
|
||||||
notes.sort((a, b) => a.title.toLowerCase() < b.title.toLowerCase() ? -1 : 1);
|
notes.sort((a, b) => {
|
||||||
|
if (directoriesFirst && ((a.hasChildren && !b.hasChildren) || (!a.hasChildren && b.hasChildren))) {
|
||||||
|
// exactly one note of the two is a directory so the sorting will be done based on this status
|
||||||
|
return a.hasChildren ? -1 : 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return a.title.toLowerCase() < b.title.toLowerCase() ? -1 : 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let position = 1;
|
let position = 1;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user