mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Clipper: Fixes #1417: Sort the folders in the same order as the desktop app
This commit is contained in:
parent
c3262aa5f8
commit
4ef05272c4
@ -3,22 +3,29 @@ const Setting = require('lib/models/Setting.js');
|
||||
|
||||
class FoldersScreenUtils {
|
||||
|
||||
static async refreshFolders() {
|
||||
static async allForDisplay(options = {}) {
|
||||
const orderDir = Setting.value('folders.sortOrder.reverse') ? 'DESC' : 'ASC';
|
||||
|
||||
let folders = await Folder.all({
|
||||
includeConflictFolder: true,
|
||||
const folderOptions = Object.assign({}, {
|
||||
caseInsensitive: true,
|
||||
order: [{
|
||||
by: 'title',
|
||||
dir: orderDir,
|
||||
}]
|
||||
});
|
||||
}, options);
|
||||
|
||||
let folders = await Folder.all(folderOptions);
|
||||
|
||||
if (Setting.value('folders.sortOrder.field') === 'last_note_user_updated_time') {
|
||||
folders = await Folder.orderByLastModified(folders, orderDir);
|
||||
}
|
||||
|
||||
return folders;
|
||||
}
|
||||
|
||||
static async refreshFolders() {
|
||||
const folders = await this.allForDisplay({ includeConflictFolder: true });
|
||||
|
||||
this.dispatch({
|
||||
type: 'FOLDER_UPDATE_ALL',
|
||||
items: folders,
|
||||
|
@ -189,8 +189,8 @@ class Folder extends BaseItem {
|
||||
return output;
|
||||
}
|
||||
|
||||
static async allAsTree(options = null) {
|
||||
const all = await this.all(options);
|
||||
static async allAsTree(folders = null, options = null) {
|
||||
const all = folders ? folders : await this.all(options);
|
||||
|
||||
// https://stackoverflow.com/a/49387427/561309
|
||||
function getNestedChildren(models, parentId) {
|
||||
|
@ -14,6 +14,7 @@ const HtmlToMd = require('lib/HtmlToMd');
|
||||
const { fileExtension, safeFileExtension, safeFilename, filename } = require('lib/path-utils');
|
||||
const ApiResponse = require('lib/services/rest/ApiResponse');
|
||||
const SearchEngineUtils = require('lib/services/SearchEngineUtils');
|
||||
const { FoldersScreenUtils } = require('lib/folders-screen-utils.js');
|
||||
|
||||
class ApiError extends Error {
|
||||
|
||||
@ -221,7 +222,9 @@ class Api {
|
||||
|
||||
async action_folders(request, id = null, link = null) {
|
||||
if (request.method === 'GET' && !id) {
|
||||
return await Folder.allAsTree({ fields: this.fields_(request, ['id', 'parent_id', 'title']) });
|
||||
const folders = await FoldersScreenUtils.allForDisplay({ fields: this.fields_(request, ['id', 'parent_id', 'title']) });
|
||||
const output = await Folder.allAsTree(folders);
|
||||
return output;
|
||||
}
|
||||
|
||||
if (request.method === 'GET' && id) {
|
||||
|
Loading…
Reference in New Issue
Block a user