public ActionResult Index(int?layerId) { ExtensionDescriptor currentTheme = _siteThemeService.GetSiteTheme(); if (currentTheme == null) { Services.Notifier.Error(T("To manage widgets you must have a theme enabled.")); return(RedirectToAction("Index", "Admin", new { area = "Dashboard" })); } IEnumerable <LayerPart> layers = _widgetsService.GetLayers().ToList(); if (!layers.Any()) { Services.Notifier.Error(T("There are no widget layers defined. A layer will need to be added in order to add widgets to any part of the site.")); return(RedirectToAction("AddLayer")); } LayerPart currentLayer = layerId == null ? layers.FirstOrDefault() : layers.FirstOrDefault(layer => layer.Id == layerId); if (currentLayer == null && layerId != null) // Incorrect layer id passed { Services.Notifier.Error(T("Layer not found: {0}", layerId)); return(RedirectToAction("Index")); } IEnumerable <string> allZones = _widgetsService.GetZones(); IEnumerable <string> currentThemesZones = _widgetsService.GetZones(currentTheme); string zonePreviewImagePath = string.Format("{0}/{1}/ThemeZonePreview.png", currentTheme.Location, currentTheme.Id); string zonePreviewImage = _virtualPathProvider.FileExists(zonePreviewImagePath) ? zonePreviewImagePath : null; dynamic viewModel = Shape.ViewModel() .CurrentTheme(currentTheme) .CurrentLayer(currentLayer) .Layers(layers) .Widgets(_widgetsService.GetWidgets()) .Zones(currentThemesZones) .OrphanZones(allZones.Except(currentThemesZones)) .OrphanWidgets(_widgetsService.GetOrphanedWidgets()) .ZonePreviewImage(zonePreviewImage); // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. return(View((object)viewModel)); }
protected override DriverResult Editor(WidgetsContainerPart part, dynamic shapeHelper) { return(ContentShape("Parts_WidgetsContainer", () => { var settings = part.Settings.GetModel <WidgetsContainerSettings>(); var currentTheme = _siteThemeService.GetSiteTheme(); var currentThemesZones = _widgetsService.GetZones(currentTheme).ToList(); var widgetTypes = _widgetsService.GetWidgetTypeNames().ToList(); if (!settings.UseHierarchicalAssociation) { if (!string.IsNullOrWhiteSpace(settings.AllowedZones)) { currentThemesZones = currentThemesZones.Where(x => settings.AllowedZones.Split(',').Contains(x)).ToList(); } if (!string.IsNullOrWhiteSpace(settings.AllowedWidgets)) { widgetTypes = widgetTypes.Where(x => settings.AllowedWidgets.Split(',').Contains(x)).ToList(); } } else if (settings.HierarchicalAssociation != null && settings.HierarchicalAssociation.Count() > 0) { currentThemesZones = currentThemesZones.Where(ctz => settings.HierarchicalAssociation.Select(x => x.ZoneName).Contains(ctz)).ToList(); widgetTypes = widgetTypes.Where(w => settings.HierarchicalAssociation.Any(x => x.Widgets.Any(a => a.WidgetType == w || a.WidgetType == "All"))).ToList(); } var widgets = _widgetManager.GetWidgets(part.Id, false); var zonePreviewImagePath = string.Format("{0}/{1}/ThemeZonePreview.png", currentTheme.Location, currentTheme.Id); var zonePreviewImage = _virtualPathProvider.FileExists(zonePreviewImagePath) ? zonePreviewImagePath : null; var layer = _widgetsService.GetLayers().First(); // recupero i contenuti localizzati una try è necessaria in quanto non è detto che un contenuto sia localizzato dynamic contentLocalizations; try { contentLocalizations = _localizationService .GetLocalizations(part.ContentItem, VersionOptions.Latest) //the other cultures .Where(lp => //as long as a culture has been assigned lp.Culture != null && !string.IsNullOrWhiteSpace(lp.Culture.Culture)) .OrderBy(o => o.Culture.Culture) .ToList(); } catch { contentLocalizations = null; } var viewModel = New.ViewModel() .CurrentTheme(currentTheme) .Zones(currentThemesZones) .ContentLocalizations(contentLocalizations) .ZonePreviewImage(zonePreviewImage) .WidgetTypes(widgetTypes) .Widgets(widgets) .ContentItem(part.ContentItem) .LayerId(layer.Id) .CloneFrom(0); return shapeHelper.EditorTemplate(TemplateName: "Parts.WidgetsContainer", Model: viewModel, Prefix: Prefix); })); }
protected override DriverResult Editor(WidgetPart widgetPart, dynamic shapeHelper) { widgetPart.AvailableZones = _widgetsService.GetZones(); widgetPart.AvailableLayers = _widgetsService.GetLayers(); var results = new List <DriverResult> { ContentShape("Parts_Widgets_WidgetPart", () => shapeHelper.EditorTemplate(TemplateName: "Parts.Widgets.WidgetPart", Model: widgetPart, Prefix: Prefix)) }; if (widgetPart.Id > 0) { results.Add(ContentShape("Widget_DeleteButton", deleteButton => deleteButton)); } return(Combined(results.ToArray())); }
protected override DriverResult Editor(WidgetsContainerPart part, dynamic shapeHelper) { return(ContentShape("Parts_WidgetsContainer", () => { var currentTheme = _siteThemeService.GetSiteTheme(); var currentThemesZones = _widgetsService.GetZones(currentTheme).ToList(); var widgetTypes = _widgetsService.GetWidgetTypeNames().ToList(); var widgets = _widgetManager.GetWidgets(part.Id, VersionOptions.Latest); var zonePreviewImagePath = string.Format("{0}/{1}/ThemeZonePreview.png", currentTheme.Location, currentTheme.Id); var zonePreviewImage = _virtualPathProvider.FileExists(zonePreviewImagePath) ? zonePreviewImagePath : null; var layer = _widgetsService.GetLayers().First(); var viewModel = New.ViewModel() .CurrentTheme(currentTheme) .Zones(currentThemesZones) .ZonePreviewImage(zonePreviewImage) .WidgetTypes(widgetTypes) .Widgets(widgets) .ContentItem(part.ContentItem) .LayerId(layer.Id); return shapeHelper.EditorTemplate(TemplateName: "Parts.WidgetsContainer", Model: viewModel, Prefix: Prefix); })); }
public override IEnumerable <TemplateViewModel> TypePartEditor(ContentTypePartDefinition definition) { if (definition.PartDefinition.Name == "WidgetsContainerPart") { var model = definition.Settings.GetModel <WidgetsContainerSettings>(); var currentTheme = _siteThemeService.GetSiteTheme(); var allowedViewModel = new WidgetsContainerSettingsViewModel(); allowedViewModel.SelectedZones = model.AllowedZones != null?model.AllowedZones.Split(',') : new string[] { }; allowedViewModel.Zones = _widgetsService.GetZones(currentTheme).ToList(); allowedViewModel.SelectedWidgets = model.AllowedWidgets != null?model.AllowedWidgets.Split(',') : new string[] { }; allowedViewModel.Widgets = _widgetsService.GetWidgetTypeNames().OrderBy(o => o).ToList(); allowedViewModel.UseHierarchicalAssociation = model.UseHierarchicalAssociation; allowedViewModel.HierarchicalAssociationJson = model.HierarchicalAssociationJson; yield return(DefinitionTemplate(allowedViewModel)); } }
public ActionResult Index(int?layerId, string culture) { ExtensionDescriptor currentTheme = _siteThemeService.GetSiteTheme(); if (currentTheme == null) { Services.Notifier.Error(T("To manage widgets you must have a theme enabled.")); return(RedirectToAction("Index", "Admin", new { area = "Dashboard" })); } IEnumerable <LayerPart> layers = _widgetsService.GetLayers().OrderBy(x => x.Name).ToList(); if (!layers.Any()) { Services.Notifier.Error(T("There are no widget layers defined. A layer will need to be added in order to add widgets to any part of the site.")); return(RedirectToAction("AddLayer")); } LayerPart currentLayer = layerId == null // look for the "Default" layer, or take the first if it doesn't exist ? layers.FirstOrDefault(x => x.Name == "Default") ?? layers.FirstOrDefault() : layers.FirstOrDefault(layer => layer.Id == layerId); if (currentLayer == null && layerId != null) // Incorrect layer id passed { Services.Notifier.Error(T("Layer not found: {0}", layerId)); return(RedirectToAction("Index")); } IEnumerable <string> allZones = _widgetsService.GetZones(); IEnumerable <string> currentThemesZones = _widgetsService.GetZones(currentTheme); string zonePreviewImagePath = string.Format("{0}/{1}/ThemeZonePreview.png", currentTheme.Location, currentTheme.Id); string zonePreviewImage = _virtualPathProvider.FileExists(zonePreviewImagePath) ? zonePreviewImagePath : null; var widgets = _widgetsService.GetWidgets(); if (!String.IsNullOrWhiteSpace(culture)) { widgets = widgets.Where(x => { if (x.Has <ILocalizableAspect>()) { return(String.Equals(x.As <ILocalizableAspect>().Culture, culture, StringComparison.InvariantCultureIgnoreCase)); } return(false); }).ToList(); } var viewModel = Shape.ViewModel() .CurrentTheme(currentTheme) .CurrentLayer(currentLayer) .CurrentCulture(culture) .Layers(layers) .Widgets(widgets) .Zones(currentThemesZones) .Cultures(_cultureManager.ListCultures()) .OrphanZones(allZones.Except(currentThemesZones)) .OrphanWidgets(_widgetsService.GetOrphanedWidgets()) .ZonePreviewImage(zonePreviewImage); return(View(viewModel)); }