Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to hide folders on predicate. #113

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public abstract class FluidityContainerTreeItemConfig : FluidityTreeItemConfig
protected ConcurrentDictionary<string, FluidityTreeItemConfig> _treeItems;
internal IReadOnlyDictionary<string, FluidityTreeItemConfig> TreeItems => _treeItems;

protected Func<bool> _isVisibleInTree;
internal Func<bool> IsVisibleInTree => _isVisibleInTree;

/// <summary>
/// Initializes a new instance of the <see cref="FluidityContainerTreeItemConfig"/> class.
/// </summary>
Expand All @@ -36,8 +39,8 @@ protected FluidityContainerTreeItemConfig(string name, string icon = null)
_alias = name.ToSafeAlias(true);
_name = name;
_icon = icon ?? "icon-folder";

_treeItems = new ConcurrentDictionary<string, FluidityTreeItemConfig>();
_isVisibleInTree = () => true;
}

/// <summary>
Expand Down
12 changes: 12 additions & 0 deletions src/Fluidity/Configuration/FluidityFolderConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// </copyright>

using System;
using System.Linq.Expressions;

namespace Fluidity.Configuration
{
Expand Down Expand Up @@ -49,5 +50,16 @@ public FluidityFolderConfig SetIconColor(string color)
_iconColor = color;
return this;
}

/// <summary>
/// Hides the folder from the section tree.
/// </summary>
/// <param name="whereClause"></param>
/// <returns>The folder configuration.</returns>
public FluidityFolderConfig HideFromTree(Func<bool> whereClause)
{
_isVisibleInTree = whereClause;
return this;
}
}
}
2 changes: 1 addition & 1 deletion src/Fluidity/Web/Trees/FluidityTreeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection
foreach (var treeItem in currentFolderConfig.TreeItems.Values.OrderBy(x => x.Ordinal))
{
var folderTreeItem = treeItem as FluidityFolderConfig;
if (folderTreeItem != null)
if (folderTreeItem != null && folderTreeItem.IsVisibleInTree.Invoke())
{
// Render folder
var node = CreateTreeNode(
Expand Down