From 650e962fdf7271434459ca7c395603b320e3f896 Mon Sep 17 00:00:00 2001 From: djmaze Date: Tue, 23 Mar 2021 22:45:30 +0100 Subject: [PATCH] Cleanup function folderListOptionsBuilder() --- dev/Common/UtilsUser.js | 62 ++++++++++++++-------------------- dev/Stores/User/Folder.js | 6 +--- dev/View/Popup/FolderCreate.js | 22 ++++++------ dev/View/Popup/FolderSystem.js | 2 -- 4 files changed, 37 insertions(+), 55 deletions(-) diff --git a/dev/Common/UtilsUser.js b/dev/Common/UtilsUser.js index b10a583f2..48493219a 100644 --- a/dev/Common/UtilsUser.js +++ b/dev/Common/UtilsUser.js @@ -216,9 +216,7 @@ rl.Utils = { * @param {Array} aList * @param {Array=} aDisabled * @param {Array=} aHeaderLines - * @param {?number=} iUnDeep * @param {Function=} fDisableCallback - * @param {Function=} fVisibleCallback * @param {Function=} fRenameCallback * @param {boolean=} bSystem * @param {boolean=} bBuildUnvisible @@ -229,9 +227,7 @@ export function folderListOptionsBuilder( aList, aDisabled, aHeaderLines, - iUnDeep, fDisableCallback, - fVisibleCallback, fRenameCallback, bSystem, bBuildUnvisible @@ -246,9 +242,7 @@ export function folderListOptionsBuilder( bBuildUnvisible = undefined === bBuildUnvisible ? false : !!bBuildUnvisible; bSystem = null == bSystem ? 0 < aSystem.length : bSystem; - iUnDeep = null == iUnDeep ? 0 : iUnDeep; fDisableCallback = null != fDisableCallback ? fDisableCallback : null; - fVisibleCallback = null != fVisibleCallback ? fVisibleCallback : null; fRenameCallback = null != fRenameCallback ? fRenameCallback : null; if (!isArray(aDisabled)) { @@ -271,19 +265,17 @@ export function folderListOptionsBuilder( bSep = true; aSystem.forEach(oItem => { - if (fVisibleCallback ? fVisibleCallback(oItem) : true) { - aResult.push({ - id: oItem.fullNameRaw, - name: fRenameCallback ? fRenameCallback(oItem) : oItem.name(), - system: true, - dividerbar: bSep, - disabled: - !oItem.selectable || - aDisabled.includes(oItem.fullNameRaw) || - (fDisableCallback ? fDisableCallback(oItem) : false) - }); - bSep = false; - } + aResult.push({ + id: oItem.fullNameRaw, + name: fRenameCallback ? fRenameCallback(oItem) : oItem.name(), + system: true, + dividerbar: bSep, + disabled: + !oItem.selectable || + aDisabled.includes(oItem.fullNameRaw) || + (fDisableCallback ? fDisableCallback(oItem) : false) + }); + bSep = false; }); bSep = true; @@ -293,22 +285,20 @@ export function folderListOptionsBuilder( (oItem.subscribed() || !oItem.exists || bBuildUnvisible) && (oItem.selectable || oItem.hasSubscribedSubfolders()) ) { - if (fVisibleCallback ? fVisibleCallback(oItem) : true) { - if (FolderType.User === oItem.type() || !bSystem || oItem.hasSubscribedSubfolders()) { - aResult.push({ - id: oItem.fullNameRaw, - name: - new Array(oItem.deep + 1 - iUnDeep).join(sDeepPrefix) + - (fRenameCallback ? fRenameCallback(oItem) : oItem.name()), - system: false, - dividerbar: bSep, - disabled: - !oItem.selectable || - aDisabled.includes(oItem.fullNameRaw) || - (fDisableCallback ? fDisableCallback(oItem) : false) - }); - bSep = false; - } + if (FolderType.User === oItem.type() || !bSystem || oItem.hasSubscribedSubfolders()) { + aResult.push({ + id: oItem.fullNameRaw, + name: + sDeepPrefix.repeat(oItem.deep + 1) + + (fRenameCallback ? fRenameCallback(oItem) : oItem.name()), + system: false, + dividerbar: bSep, + disabled: + !oItem.selectable || + aDisabled.includes(oItem.fullNameRaw) || + (fDisableCallback ? fDisableCallback(oItem) : false) + }); + bSep = false; } } @@ -319,9 +309,7 @@ export function folderListOptionsBuilder( oItem.subFolders(), aDisabled, [], - iUnDeep, fDisableCallback, - fVisibleCallback, fRenameCallback, bSystem, bBuildUnvisible diff --git a/dev/Stores/User/Folder.js b/dev/Stores/User/Folder.js index 1c1a94e0f..0cc19c389 100644 --- a/dev/Stores/User/Folder.js +++ b/dev/Stores/User/Folder.js @@ -104,9 +104,7 @@ export const FolderUserStore = new class { this.folderListSystem(), this.folderList(), [this.currentFolderFullNameRaw()], - null, - null, - null, + [], null, (item) => (item ? item.localName() : '') ) @@ -119,8 +117,6 @@ export const FolderUserStore = new class { [this.sieveAllowFileintoInbox ? '' : 'INBOX'], [['', '']], null, - null, - null, (item) => (item ? item.localName() : '') ) ); diff --git a/dev/View/Popup/FolderCreate.js b/dev/View/Popup/FolderCreate.js index bef43e523..c80371b76 100644 --- a/dev/View/Popup/FolderCreate.js +++ b/dev/View/Popup/FolderCreate.js @@ -23,19 +23,19 @@ class FolderCreatePopupView extends AbstractViewPopup { selectedParentValue: UNUSED_OPTION_VALUE }); - this.parentFolderSelectList = ko.computed(() => { - const top = [], - list = FolderUserStore.folderList(), - fDisableCallback = FolderUserStore.namespace + this.parentFolderSelectList = ko.computed(() => + folderListOptionsBuilder( + [], + FolderUserStore.folderList(), + [], + [['', '']], + FolderUserStore.namespace ? item => FolderUserStore.namespace !== item.fullNameRaw.substr(0, FolderUserStore.namespace.length) : null, - fRenameCallback = oItem => - oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : ''; - - top.push(['', '']); - - return folderListOptionsBuilder([], list, [], top, null, fDisableCallback, null, fRenameCallback); - }); + oItem => + oItem ? (oItem.isSystemFolder() ? oItem.name() + ' ' + oItem.manageFolderSystemName() : oItem.name()) : '' + ) + ); this.defaultOptionsAfterRender = defaultOptionsAfterRender; diff --git a/dev/View/Popup/FolderSystem.js b/dev/View/Popup/FolderSystem.js index d6563d329..04a56def1 100644 --- a/dev/View/Popup/FolderSystem.js +++ b/dev/View/Popup/FolderSystem.js @@ -39,8 +39,6 @@ class FolderSystemPopupView extends AbstractViewPopup { null, null, null, - null, - null, true ) );