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 {
|
class FoldersScreenUtils {
|
||||||
|
|
||||||
static async refreshFolders() {
|
static async allForDisplay(options = {}) {
|
||||||
const orderDir = Setting.value('folders.sortOrder.reverse') ? 'DESC' : 'ASC';
|
const orderDir = Setting.value('folders.sortOrder.reverse') ? 'DESC' : 'ASC';
|
||||||
|
|
||||||
let folders = await Folder.all({
|
const folderOptions = Object.assign({}, {
|
||||||
includeConflictFolder: true,
|
|
||||||
caseInsensitive: true,
|
caseInsensitive: true,
|
||||||
order: [{
|
order: [{
|
||||||
by: 'title',
|
by: 'title',
|
||||||
dir: orderDir,
|
dir: orderDir,
|
||||||
}]
|
}]
|
||||||
});
|
}, options);
|
||||||
|
|
||||||
|
let folders = await Folder.all(folderOptions);
|
||||||
|
|
||||||
if (Setting.value('folders.sortOrder.field') === 'last_note_user_updated_time') {
|
if (Setting.value('folders.sortOrder.field') === 'last_note_user_updated_time') {
|
||||||
folders = await Folder.orderByLastModified(folders, orderDir);
|
folders = await Folder.orderByLastModified(folders, orderDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return folders;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async refreshFolders() {
|
||||||
|
const folders = await this.allForDisplay({ includeConflictFolder: true });
|
||||||
|
|
||||||
this.dispatch({
|
this.dispatch({
|
||||||
type: 'FOLDER_UPDATE_ALL',
|
type: 'FOLDER_UPDATE_ALL',
|
||||||
items: folders,
|
items: folders,
|
||||||
|
@ -189,8 +189,8 @@ class Folder extends BaseItem {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async allAsTree(options = null) {
|
static async allAsTree(folders = null, options = null) {
|
||||||
const all = await this.all(options);
|
const all = folders ? folders : await this.all(options);
|
||||||
|
|
||||||
// https://stackoverflow.com/a/49387427/561309
|
// https://stackoverflow.com/a/49387427/561309
|
||||||
function getNestedChildren(models, parentId) {
|
function getNestedChildren(models, parentId) {
|
||||||
|
@ -14,6 +14,7 @@ const HtmlToMd = require('lib/HtmlToMd');
|
|||||||
const { fileExtension, safeFileExtension, safeFilename, filename } = require('lib/path-utils');
|
const { fileExtension, safeFileExtension, safeFilename, filename } = require('lib/path-utils');
|
||||||
const ApiResponse = require('lib/services/rest/ApiResponse');
|
const ApiResponse = require('lib/services/rest/ApiResponse');
|
||||||
const SearchEngineUtils = require('lib/services/SearchEngineUtils');
|
const SearchEngineUtils = require('lib/services/SearchEngineUtils');
|
||||||
|
const { FoldersScreenUtils } = require('lib/folders-screen-utils.js');
|
||||||
|
|
||||||
class ApiError extends Error {
|
class ApiError extends Error {
|
||||||
|
|
||||||
@ -221,7 +222,9 @@ class Api {
|
|||||||
|
|
||||||
async action_folders(request, id = null, link = null) {
|
async action_folders(request, id = null, link = null) {
|
||||||
if (request.method === 'GET' && !id) {
|
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) {
|
if (request.method === 'GET' && id) {
|
||||||
|
Loading…
Reference in New Issue
Block a user