diff --git a/dev/Common/UtilsUser.js b/dev/Common/UtilsUser.js index 7e563a417..b4ae1182f 100644 --- a/dev/Common/UtilsUser.js +++ b/dev/Common/UtilsUser.js @@ -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); + } }, /** diff --git a/dev/Model/FolderCollection.js b/dev/Model/FolderCollection.js index 30421ed92..ee8559552 100644 --- a/dev/Model/FolderCollection.js +++ b/dev/Model/FolderCollection.js @@ -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({ diff --git a/dev/Settings/User/Folders.js b/dev/Settings/User/Folders.js index cb8fc6642..05ecffd5c 100644 --- a/dev/Settings/User/Folders.js +++ b/dev/Settings/User/Folders.js @@ -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 => { diff --git a/dev/View/Popup/FolderCreate.js b/dev/View/Popup/FolderCreate.js index 1f3213d62..83e63c5e7 100644 --- a/dev/View/Popup/FolderCreate.js +++ b/dev/View/Popup/FolderCreate.js @@ -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));