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

Query for Tags #71

Open
pollend opened this issue Sep 14, 2020 · 8 comments
Open

Query for Tags #71

pollend opened this issue Sep 14, 2020 · 8 comments

Comments

@pollend
Copy link

pollend commented Sep 14, 2020

so I have these utility methods that I use to tie the navigation bar with the breadcrumb list. should allow for some custom breadcrumbs by iterating over the entries.

public class BreadcrumbHelper : IViewContextAware
{
       private readonly ILogger _logger;
        private BreadcrumbManager _breadcrumbManager;
        private ViewContext _viewContext;

        public BreadcrumbHelper(ILogger<BreadcrumbHelper> logger, BreadcrumbManager breadcrumbManager)
        {
            _logger = logger;
            _breadcrumbManager = breadcrumbManager;

        }

        public void Contextualize(ViewContext viewContext)
        {
            _viewContext = viewContext;
        }

        private String _extractTag(String tag)
        {
            if (tag.Contains("."))
            {
                return tag.Split(".")[1];
            }
            return tag;
        }

        public List<String> GetTags()
        {
            List<String> tags = new List<string>();
            var nodeKey = new NodeKey(_viewContext.ActionDescriptor.RouteValues,
                _viewContext.HttpContext.Request.Method);
            var node = _viewContext.ViewData["BreadcrumbNode"] as BreadcrumbNode ??
                       _breadcrumbManager.GetNode(nodeKey.Value);
            if (node != null)
            {
                tags.Add(_extractTag(node.Title));

                while (node.Parent != null)
                {
                    node = node.Parent;
                    tags.Add(_extractTag(node.Title));
                }
            }
            return tags;
        }


        public bool IsOnRoute(String tag)
        {
            var nodeKey = new NodeKey(_viewContext.ActionDescriptor.RouteValues,
                _viewContext.HttpContext.Request.Method);
            var node = _viewContext.ViewData["BreadcrumbNode"] as BreadcrumbNode ??
                       _breadcrumbManager.GetNode(nodeKey.Value);
            if (node != null)
            {
                if (node.Title.EndsWith(tag))
                {
                    return true;
                }

                while (node.Parent != null)
                {
                    node = node.Parent;
                    if (node.Title.EndsWith(tag))
                    {
                        return true;
                    }
                }
            }
            return false;
        }
@zHaytam
Copy link
Owner

zHaytam commented Sep 20, 2020

Hello,
I'm not sure I understand what the issue (if there is any)?

@pollend
Copy link
Author

pollend commented Sep 20, 2020

Would be nice to have some utility methods to build up the list of tags from cshtml.

@zHaytam
Copy link
Owner

zHaytam commented Sep 20, 2020

If I understand correctly, you want something like a Tag property on breadcrumb nodes so that you do something with it?

@pollend
Copy link
Author

pollend commented Sep 20, 2020

So my understanding is the BreadcrumbManager is a graph of nodes for the different page routes. My basic request would be some kind of utility class with enough functionality to generate a custom breadcrumb. There are some other additional functionality such as what I'm currently using it for which is marking out the location in the page navigation.

I guess these are more of my rough thoughts which could improve the library. there isn't anything particularly actionable. Some kind of functionality like this I think would help a lot.

image

@zHaytam
Copy link
Owner

zHaytam commented Sep 21, 2020

My basic request would be some kind of utility class with enough functionality to generate a custom breadcrumb.

I am very sorry but I still don't get it, especially this part. Can you tell me exactly your use case and how you would like SmartBreadcrumbs to do it? (A sample usage code)

@pollend
Copy link
Author

pollend commented Sep 22, 2020

I was thinking of a class like this so the breadcrumb doesn't need to be defined by the library. I'm not sure how useful this would be. I could also use this to mark out the location in the navigation based off the current breadcrumb path. I was thinking about a more front facing class for general usage. I really like the library, just a couple things that I would like to see that are not necessary. if this is not necessary, then I guess this issue can just be closed out.

example, this is kind of one simple usecase but the api can be up for debate.

<div>
@for(var node : @smartbreadcrumb.path(reverse=true)){
{
<a class="{node.defaultName}" href="{node.path}">{node.name}</p>
}
</div>

@zHaytam
Copy link
Owner

zHaytam commented Sep 22, 2020

If the BreadcrumbManager class made the list of nodes visible, you could do that by injecting it no? (e.g. BreadcrumbManager.Nodes, and then you foreach them)

@pollend
Copy link
Author

pollend commented Sep 22, 2020

you can add a class that is aware of the viewcontext. I'm not sure if a class with IViewContextAware works with a singleton so it might have to be scope. so you can return a list of nodes for the current route. The functionality is there to generate a breadcrumb for the current path. Something like BreadcrumbManager.Nodes could work as well or maybe something that describes the current route.

BreadcrumbManager.currentPath <-- the list of nodes for the current path
BreadcrumbManager.isOnPath <-- if node is on the current path for the breadcrumb
etc ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants