public IEnumerable <Section> GetSections() { var sections = Services.SectionService.GetAllowedSections(Security.GetUserId().ResultOr(0)); var sectionModels = sections.Select(Mapper.Map <Core.Models.Section, Section>).ToArray(); // this is a bit nasty since we'll be proxying via the app tree controller but we sort of have to do that // since tree's by nature are controllers and require request contextual data var appTreeController = new ApplicationTreeController { ControllerContext = ControllerContext }; var dashboards = _dashboards.GetDashboards(Security.CurrentUser); //now we can add metadata for each section so that the UI knows if there's actually anything at all to render for //a dashboard for a given section, then the UI can deal with it accordingly (i.e. redirect to the first tree) foreach (var section in sectionModels) { var hasDashboards = dashboards.TryGetValue(section.Alias, out var dashboardsForSection) && dashboardsForSection.Any(); if (hasDashboards) { continue; } // get the first tree in the section and get its root node route path var sectionRoot = appTreeController.GetApplicationTrees(section.Alias, null, null).Result; section.RoutePath = GetRoutePathForFirstTree(sectionRoot); } return(sectionModels); }
public async Task <ActionResult <IEnumerable <Section> > > GetSections() { IEnumerable <ISection> sections = _sectionService.GetAllowedSections(_backofficeSecurityAccessor.BackOfficeSecurity?.GetUserId().Result ?? 0); Section[] sectionModels = sections.Select(_umbracoMapper.Map <Section>).WhereNotNull().ToArray(); // this is a bit nasty since we'll be proxying via the app tree controller but we sort of have to do that // since tree's by nature are controllers and require request contextual data var appTreeController = new ApplicationTreeController(_treeService, _sectionService, _localizedTextService, _controllerFactory, _actionDescriptorCollectionProvider) { ControllerContext = ControllerContext }; IDictionary <string, IEnumerable <Tab <IDashboard> > > dashboards = _dashboardService.GetDashboards(_backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser); //now we can add metadata for each section so that the UI knows if there's actually anything at all to render for //a dashboard for a given section, then the UI can deal with it accordingly (i.e. redirect to the first tree) foreach (Section?section in sectionModels) { var hasDashboards = section?.Alias is not null && dashboards.TryGetValue(section.Alias, out IEnumerable <Tab <IDashboard> >?dashboardsForSection) && dashboardsForSection.Any(); if (hasDashboards) { continue; } // get the first tree in the section and get its root node route path ActionResult <TreeRootNode> sectionRoot = await appTreeController.GetApplicationTrees(section?.Alias, null, null); if (!(sectionRoot.Result is null)) { return(sectionRoot.Result); } if (section is not null) { section.RoutePath = GetRoutePathForFirstTree(sectionRoot.Value !); } } return(sectionModels); }
public IEnumerable <Section> GetSections() { var sections = Services.SectionService.GetAllowedSections(Security.GetUserId()); var sectionModels = sections.Select(Mapper.Map <Core.Models.Section, Section>).ToArray(); //Check if there are empty dashboards or dashboards that will end up empty based on the current user's access //and add the meta data about them var dashboardHelper = new DashboardHelper(Services.SectionService); //this is a bit nasty since we'll be proxying via the app tree controller but we sort of have to do that //since tree's by nature are controllers and require request contextual data. var appTreeController = new ApplicationTreeController { ControllerContext = ControllerContext }; var dashboards = dashboardHelper.GetDashboards(Security.CurrentUser); //now we can add metadata for each section so that the UI knows if there's actually anything at all to render for //a dashboard for a given section, then the UI can deal with it accordingly (i.e. redirect to the first tree) foreach (var section in sectionModels) { var hasDashboards = false; IEnumerable <Tab <DashboardControl> > dashboardsForSection; if (dashboards.TryGetValue(section.Alias, out dashboardsForSection)) { if (dashboardsForSection.Any()) { hasDashboards = true; } } if (hasDashboards == false) { //get the first tree in the section and get it's root node route path var sectionTrees = appTreeController.GetApplicationTrees(section.Alias, null, null).Result; section.RoutePath = sectionTrees.IsContainer == false || sectionTrees.Children.Count == 0 ? sectionTrees.RoutePath : sectionTrees.Children[0].RoutePath; } } return(sectionModels); }