2013-08-12 15:06:12 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
|
using Umbraco.Web.Models.ContentEditing;
|
|
|
|
|
|
using Umbraco.Web.Mvc;
|
|
|
|
|
|
using System.Linq;
|
2017-08-10 17:25:16 +10:00
|
|
|
|
using Umbraco.Web.Trees;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Editors
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The API controller used for using the list of sections
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[PluginController("UmbracoApi")]
|
|
|
|
|
|
public class SectionController : UmbracoAuthorizedJsonController
|
|
|
|
|
|
{
|
|
|
|
|
|
public IEnumerable<Section> GetSections()
|
2017-08-17 11:22:05 +02:00
|
|
|
|
{
|
2017-08-10 17:25:16 +10:00
|
|
|
|
|
|
|
|
|
|
var sections = Services.SectionService.GetAllowedSections(Security.GetUserId());
|
|
|
|
|
|
|
2017-08-17 11:22:05 +02:00
|
|
|
|
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.
|
2017-08-10 17:25:16 +10:00
|
|
|
|
var appTreeController = new ApplicationTreeController
|
|
|
|
|
|
{
|
|
|
|
|
|
ControllerContext = ControllerContext
|
|
|
|
|
|
};
|
2017-08-17 11:22:05 +02:00
|
|
|
|
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
|
2017-08-10 17:25:16 +10:00
|
|
|
|
//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;
|
2017-08-17 11:22:05 +02:00
|
|
|
|
section.RoutePath = sectionTrees.IsContainer == false
|
|
|
|
|
|
? sectionTrees.RoutePath
|
2017-08-10 17:25:16 +10:00
|
|
|
|
: sectionTrees.Children[0].RoutePath;
|
|
|
|
|
|
}
|
2017-08-17 11:22:05 +02:00
|
|
|
|
}
|
2017-08-10 17:25:16 +10:00
|
|
|
|
|
|
|
|
|
|
return sectionModels;
|
2017-06-13 15:27:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Section> GetAllSections()
|
|
|
|
|
|
{
|
|
|
|
|
|
var sections = Services.SectionService.GetSections();
|
|
|
|
|
|
return sections.Select(Mapper.Map<Core.Models.Section, Section>);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
}
|
2013-07-01 14:23:56 +10:00
|
|
|
|
}
|