Developer forum

Forum » Development » Creating a Section in a Area

Creating a Section in a Area

Aki Ruuskanen
Aki Ruuskanen
Reply

Hi,

I'm play around with creating Areas and Sections but cannot get a section to render. I have looket at the documentation and the examples but something must be missing. 

I have tried with a simple example:

The Area:

    public class CustomArea : AreaBase
    {
        public CustomArea()
        {
            Name = "En area";
            Icon = Icon.Folder;
            Sort = 30;         
        }          
    }

And the Section:

  public class CustomSection : NavigationSection<CustomArea>
  {
        public CustomSection(NavigationContext context) : base(context)
        {
            Name = "En sektion";
            Sort = 30;
            PermissionLevelRequired = Dynamicweb.Security.Permissions.PermissionLevel.All;           
        }

}

Shouldn't that be enough to render the section label "En sektion" in the area?

Is it possbile to provade some working examples of creating an Area, Sections and a simple Screen?

Regards / Aki 

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Aki.

It is documented here: https://doc.dynamicweb.dev/documentation/extending/administration-ui/areatree.html

Your code looks fine - but add a navigationnode provider that can return nodes for the section - then it should show up.

BR Nicolai

 
Aki Ruuskanen
Aki Ruuskanen
Reply

Hi Nicolai,

That is where I have been looking :) 

I have a NavigationNodeProvide with a simple GetRootNodes()

 

        public override IEnumerable<NavigationNode> GetRootNodes()
        {
            var nodes = new List<NavigationNode>();

            nodes.Add(new NavigationNode
            {
                Name = "Översikt",
                Id = "Oversikt",
                Icon = Icon.FileCheckAlt,
                PermissionLevelRequired = PermissionLevel.All,
                HasSubNodes = false,
                ContextActions = GetContextActions(),
                NodeAction = NavigateScreenAction.To<MimOverviewListScreen>()              
            });
            return nodes;
        }
 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

Hi Aki,

You are setting PermissionLevelRequired = PermissionLevel.All, so it will probably only be visible to users which have full permission in this context.
Try to remove the permission stuff and see if it shows up.

 
Aki Ruuskanen
Aki Ruuskanen
Reply

Hi Morten,

Unfortunaly no effect. And if I add it to the Area it still renders. 

        public MimArea()
        {
            Name = "MIM";
            Icon = Icon.Folder;
            Sort = 30;
            PermissionLevelRequired = PermissionLevel.All;
            
            ContextActions.AddRange(GetContextActions());                        
        }

But the Section refuses to show up. 

    public class MimSection : NavigationSection<MimArea>
    {
        public MimSection(NavigationContext context) : base(context)
        {
            Name = "MIM Sektion";
            Sort = 30;            
            
        }

    }

And I have NavigationNodeProvider like this:

    public sealed class MimSectionNodeProvider : NavigationNodeProvider<MimSection>
    {              
        public override IEnumerable<NavigationNode> GetRootNodes()
        {
            var nodes = new List<NavigationNode>();

            nodes.Add(new NavigationNode
            {
                Name = "Översikt",
                Id = "Oversikt",
                Icon = Icon.FileCheckAlt,                
                HasSubNodes = true,
                ContextActions = GetContextActions(),
                NodeAction = NavigateScreenAction.To<MimOverviewListScreen>(),
                Sort = 10,
                Active = true
            });

            nodes.Add(new NavigationNode
            {
                Name = "Fel",
                Id = "Fel",
                Icon = Icon.Wrench,                
                HasSubNodes = false,                
                Sort = 11,
                Active = true
            });

            return nodes;
        }

}
 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Try to add all classes to one cs file and give us all of it. Then we will try to debug it.

Thanks

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

Hi Aki,

The reason your section doesn't appear is because there's been a change in the mechanism that finds sections. It currently requires a NavigationSectionProvider<TArea>. It slipped through our review process that we no longer have the ability to find sections without an explicit provider implementation.

For now, you can implement one that references your area, you shouldn't have to do anything else:

public sealed class MimAreaSectionProvider(NavigationContext ctx) : NavigationSectionProvider<MimArea>(ctx);

I'll try and find a way to restore the behavior where it's not required to implement it.

- Jeppe

Votes for this answer: 1
 
Aki Ruuskanen
Aki Ruuskanen
Reply

Jeppe to the rescue. :)  Now I can move to trying to display some data in a screen. Thanks. 

/Aki

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Glad to hear it :)

Happy coding!

 

You must be logged in to post in the forum