Added: sort Folders on add/rename folder

This commit is contained in:
djmaze 2021-12-09 11:24:30 +01:00
parent 65e192cc54
commit a512759289
4 changed files with 42 additions and 44 deletions

View file

@ -8,13 +8,16 @@ import { SettingsUserStore } from 'Stores/User/Settings';
import * as Local from 'Storage/Client';
export const
/**
* @param {(string|number)} value
* @param {boolean=} includeZero = true
* @returns {boolean}
*/
isPosNumeric = (value) => {
return null != value && /^[0-9]*$/.test(value.toString());
sortFolders = folders => {
try {
let collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
folders.sort((a, b) =>
a.isInbox() ? -1 : (b.isInbox() ? 1 : collator.compare(a.fullName, b.fullName))
);
} catch (e) {
console.error(e);
}
},
/**

View file

@ -15,7 +15,7 @@ import { SettingsUserStore } from 'Stores/User/Settings';
import ko from 'ko';
import { isPosNumeric } from 'Common/UtilsUser';
import { sortFolders } from 'Common/UtilsUser';
import { i18n, trigger as translatorTrigger } from 'Common/Translator';
import { AbstractModel } from 'Knoin/AbstractModel';
@ -23,20 +23,22 @@ import { AbstractModel } from 'Knoin/AbstractModel';
//import { mailBox } from 'Common/Links';
const
normalizeFolder = sFolderFullName => ('' === sFolderFullName
|| UNUSED_OPTION_VALUE === sFolderFullName
|| null !== getFolderFromCacheList(sFolderFullName))
? sFolderFullName
: '';
isPosNumeric = value => null != value && /^[0-9]*$/.test(value.toString()),
const SystemFolders = {
Inbox: 0,
Sent: 0,
Drafts: 0,
Spam: 0,
Trash: 0,
Archive: 0
};
normalizeFolder = sFolderFullName => ('' === sFolderFullName
|| UNUSED_OPTION_VALUE === sFolderFullName
|| null !== getFolderFromCacheList(sFolderFullName))
? sFolderFullName
: '',
SystemFolders = {
Inbox: 0,
Sent: 0,
Drafts: 0,
Spam: 0,
Trash: 0,
Archive: 0
};
export class FolderCollectionModel extends AbstractCollectionModel
{
@ -106,14 +108,7 @@ export class FolderCollectionModel extends AbstractCollectionModel
let i = result.length;
if (i) {
try {
let collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
result.sort((a, b) =>
a.isInbox() ? -1 : (b.isInbox() ? 1 : collator.compare(a.fullName, b.fullName))
);
} catch (e) {
console.error(e);
}
sortFolders(result);
try {
while (i--) {
let folder = result[i], parent = getFolderFromCacheList(folder.parentName);
@ -257,15 +252,16 @@ export class FolderModel extends AbstractModel {
static reviveFromJson(json) {
const folder = super.reviveFromJson(json);
if (folder) {
const path = folder.fullName.split(folder.delimiter);
const path = folder.fullName.split(folder.delimiter),
type = (folder.metadata[FolderMetadataKeys.KolabFolderType]
|| folder.metadata[FolderMetadataKeys.KolabFolderTypeShared]
|| ''
).split('.')[0];
folder.deep = path.length - 1;
path.pop();
folder.parentName = path.join(folder.delimiter);
let type = (folder.metadata[FolderMetadataKeys.KolabFolderType]
|| folder.metadata[FolderMetadataKeys.KolabFolderTypeShared]
|| ''
).split('.')[0];
type && 'mail' != type && folder.kolabType(type);
folder.messageCountAll = ko.computed({

View file

@ -8,6 +8,7 @@ import { getNotification } from 'Common/Translator';
import { setFolder, getFolderFromCacheList, removeFolderFromCacheList } from 'Common/Cache';
import { Capa } from 'Common/Enums';
import { defaultOptionsAfterRender } from 'Common/Utils';
import { sortFolders } from 'Common/UtilsUser';
import { initOnStartOrLangChange, i18n } from 'Common/Translator';
import { FolderUserStore } from 'Stores/User/Folder';
@ -82,14 +83,10 @@ export class FoldersUserSettings /*extends AbstractViewSettings*/ {
// TODO: rename all subfolders with folder.delimiter to prevent reload?
} else {
removeFolderFromCacheList(folder.fullName);
data = data.Result;
folder.fullName = data.FullName;
folder.fullName = data.Result.FullName;
setFolder(folder);
/*
const folder = getFolderFromCacheList(folder.parentName);
var collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
console.log((folder ? folder.subFolders : FolderUserStore.folderList).sort(collator.compare));
*/
const parent = getFolderFromCacheList(folder.parentName);
sortFolders(parent ? parent.subFolders : FolderUserStore.folderList);
}
})
.catch(error => {

View file

@ -3,7 +3,7 @@ import ko from 'ko';
import { Notification } from 'Common/Enums';
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { defaultOptionsAfterRender } from 'Common/Utils';
import { folderListOptionsBuilder } from 'Common/UtilsUser';
import { folderListOptionsBuilder, sortFolders } from 'Common/UtilsUser';
import { getNotification } from 'Common/Translator';
import { FolderUserStore } from 'Stores/User/Folder';
@ -60,9 +60,11 @@ class FolderCreatePopupView extends AbstractViewPopup {
.then(
data => {
const folder = getFolderFromCacheList(parentFolderName),
subFolder = FolderModel.reviveFromJson(data.Result);
subFolder = FolderModel.reviveFromJson(data.Result),
folders = (folder ? folder.subFolders : FolderUserStore.folderList);
setFolder(subFolder);
(folder ? folder.subFolders : FolderUserStore.folderList).push(subFolder);
folders.push(subFolder);
sortFolders(folders);
/*
var collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
console.log((folder ? folder.subFolders : FolderUserStore.folderList).sort(collator.compare));