public ActionResult ListWidgets(int hostId, string zone)
        {
            var widgetTypes = _widgetsService.GetWidgetTypeNames().OrderBy(x => x).ToList();

            var widgetsContainerPart = _contentManager.Get(hostId, VersionOptions.Latest).As <WidgetsContainerPart>();
            var settings             = widgetsContainerPart.Settings.GetModel <WidgetsContainerSettings>();

            if (!settings.UseHierarchicalAssociation)
            {
                if (!string.IsNullOrWhiteSpace(settings.AllowedWidgets))
                {
                    widgetTypes = widgetTypes.Where(x => settings.AllowedWidgets.Split(',').Contains(x)).ToList();
                }
            }
            else
            {
                var allowedWidgetsForZone = settings.HierarchicalAssociation.Where(x => x.ZoneName == zone).SelectMany(z => z.Widgets.Select(w => w.WidgetType));
                widgetTypes = widgetTypes.Where(x => allowedWidgetsForZone.Contains(x) || allowedWidgetsForZone.Contains("All")).ToList();
            }
            var viewModel = _services.New.ViewModel()
                            .WidgetTypes(widgetTypes)
                            .HostId(hostId)
                            .Zone(zone);

            return(View(viewModel));
        }
Beispiel #2
0
        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);
            }));
        }
Beispiel #3
0
        public ActionResult ListWidgets(int hostId, string zone)
        {
            var widgetTypes = _widgetsService.GetWidgetTypeNames().OrderBy(x => x).ToList();

            var viewModel = _services.New.ViewModel()
                            .WidgetTypes(widgetTypes)
                            .HostId(hostId)
                            .Zone(zone);

            return(View(viewModel));
        }
Beispiel #4
0
        public void Create(string type)
        {
            var widgetTypeNames = _widgetsService.GetWidgetTypeNames();

            if (!widgetTypeNames.Contains(type))
            {
                Context.Output.WriteLine(T("Creating widget failed : type {0} was not found. Supported widget types are: {1}.",
                                           type,
                                           widgetTypeNames.Aggregate(String.Empty, (current, widgetType) => current + " " + widgetType)));
                return;
            }

            var layer = GetLayer(Layer);

            if (layer == null)
            {
                Context.Output.WriteLine(T("Creating widget failed : layer {0} was not found.", Layer));
                return;
            }

            var widget = _widgetsService.CreateWidget(layer.ContentItem.Id, type, T(Title).Text, Position, Zone);
            var text   = String.Empty;

            if (widget.Has <BodyPart>())
            {
                if (UseLoremIpsumText)
                {
                    text = T(LoremIpsum).Text;
                }
                else
                {
                    if (!String.IsNullOrEmpty(Text))
                    {
                        text = Text;
                    }
                }
                widget.As <BodyPart>().Text = text;
            }
            if (String.IsNullOrEmpty(Owner))
            {
                Owner = _siteService.GetSiteSettings().SuperUser;
            }
            var owner = _membershipService.GetUser(Owner);

            widget.As <ICommonPart>().Owner = owner;

            if (widget.Has <IdentityPart>() && !String.IsNullOrEmpty(Identity))
            {
                widget.As <IdentityPart>().Identifier = Identity;
            }

            Context.Output.WriteLine(T("Widget created successfully.").Text);
        }
Beispiel #5
0
        private WidgetPart CreateWidget(string type)
        {
            var widgetTypeNames = _widgetsService.GetWidgetTypeNames().ToList();

            var layer = GetLayer(Layer);

            if (layer == null)
            {
                Context.Output.WriteLine(T("Creating widget failed : layer {0} was not found.", Layer));
                return(null);
            }

            var widget = _widgetsService.CreateWidget(layer.ContentItem.Id, type, T(Title).Text, WidgetPosition, Zone);

            if (!String.IsNullOrWhiteSpace(Name))
            {
                widget.Name = Name.Trim();
            }

            widget.RenderTitle = RenderTitle;

            if (widget.Has <MenuWidgetPart>() && !String.IsNullOrWhiteSpace(MenuName))
            {
                var menu = _menuService.GetMenu(MenuName);

                if (menu != null)
                {
                    widget.RenderTitle = false;
                    widget.As <MenuWidgetPart>().MenuContentItemId = menu.ContentItem.Id;
                }
            }

            if (String.IsNullOrEmpty(Owner))
            {
                Owner = _siteService.GetSiteSettings().SuperUser;
            }
            var owner = _membershipService.GetUser(Owner);

            widget.As <ICommonPart>().Owner = owner;

            if (widget.Has <IdentityPart>() && !String.IsNullOrEmpty(Identity))
            {
                widget.As <IdentityPart>().Identifier = Identity;
            }

            return(widget);
        }
Beispiel #6
0
        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 void Create(string type)
        {
            var widgetTypeNames = _widgetsService.GetWidgetTypeNames().ToList();

            if (!widgetTypeNames.Contains(type))
            {
                Context.Output.WriteLine(T("Creating widget failed : type {0} was not found. Supported widget types are: {1}.",
                                           type,
                                           string.Join(" ", widgetTypeNames)));
                return;
            }

            var layer = GetLayer(Layer);

            if (layer == null)
            {
                Context.Output.WriteLine(T("Creating widget failed : layer {0} was not found.", Layer));
                return;
            }

            var widget = _widgetsService.CreateWidget(layer.ContentItem.Id, type, T(Title).Text, Position, Zone);

            if (!String.IsNullOrWhiteSpace(Name))
            {
                widget.Name = Name.Trim();
            }

            var text = String.Empty;

            if (widget.Has <BodyPart>())
            {
                if (UseLoremIpsumText)
                {
                    text = T(LoremIpsum).Text;
                }
                else
                {
                    if (!String.IsNullOrEmpty(Text))
                    {
                        text = Text;
                    }
                }
                widget.As <BodyPart>().Text = text;
            }

            widget.RenderTitle = RenderTitle;

            if (widget.Has <MenuWidgetPart>() && !String.IsNullOrWhiteSpace(MenuName))
            {
                var menu = _menuService.GetMenu(MenuName);

                if (menu != null)
                {
                    widget.RenderTitle = false;
                    widget.As <MenuWidgetPart>().MenuContentItemId = menu.ContentItem.Id;
                }
            }

            if (String.IsNullOrEmpty(Owner))
            {
                Owner = _siteService.GetSiteSettings().SuperUser;
            }
            var owner = _membershipService.GetUser(Owner);

            widget.As <ICommonPart>().Owner = owner;

            if (widget.Has <IdentityPart>() && !String.IsNullOrEmpty(Identity))
            {
                widget.As <IdentityPart>().Identifier = Identity;
            }

            _contentManager.Publish(widget.ContentItem);
            Context.Output.WriteLine(T("Widget created successfully.").Text);
        }
        public WidgetPart CreateBaseWidget(CommandContext context, string type, string title, string name, string zone, string position, string layer, string identity, bool renderTitle, string owner, string text, bool useLoremIpsumText, string menuName)
        {
            var widgetTypeNames = _widgetsService.GetWidgetTypeNames().ToList();

            if (!widgetTypeNames.Contains(type))
            {
                context.Output.WriteLine(T("Creating widget failed : type {0} was not found. Supported widget types are: {1}.",
                                           type,
                                           string.Join(" ", widgetTypeNames)));
                return(null);
            }

            var layerPart = GetLayer(layer);

            if (layerPart == null)
            {
                context.Output.WriteLine(T("Creating widget failed : layer {0} was not found.", layer));
                return(null);
            }

            var widget = _widgetsService.CreateWidget(layerPart.ContentItem.Id, type, T(title).Text, position, zone);

            if (!String.IsNullOrWhiteSpace(name))
            {
                widget.Name = name.Trim();
            }

            var widgetText = String.Empty;

            if (widget.Has <BodyPart>())
            {
                if (useLoremIpsumText)
                {
                    widgetText = T(LoremIpsum).Text;
                }
                else
                {
                    if (!String.IsNullOrEmpty(text))
                    {
                        widgetText = text;
                    }
                }
                widget.As <BodyPart>().Text = text;
            }

            widget.RenderTitle = renderTitle;

            if (widget.Has <MenuWidgetPart>() && !String.IsNullOrWhiteSpace(menuName))
            {
                var menu = _menuService.GetMenu(menuName);

                if (menu != null)
                {
                    widget.As <MenuWidgetPart>().MenuContentItemId = menu.ContentItem.Id;
                }
            }

            if (String.IsNullOrEmpty(owner))
            {
                owner = _siteService.GetSiteSettings().SuperUser;
            }
            var widgetOwner = _membershipService.GetUser(owner);

            widget.As <ICommonPart>().Owner = widgetOwner;

            if (widget.Has <IdentityPart>() && !String.IsNullOrEmpty(identity))
            {
                widget.As <IdentityPart>().Identifier = identity;
            }

            return(widget);
        }
        public void Create(string type)
        {
            var widgetTypeNames = _widgetsService.GetWidgetTypeNames();

            if (!widgetTypeNames.Contains(type))
            {
                Context.Output.WriteLine(T("Creating widget failed : type {0} was not found. Supported widget types are: {1}.",
                                           type,
                                           widgetTypeNames.Aggregate(String.Empty, (current, widgetType) => current + " " + widgetType)));
                return;
            }

            var layer = GetLayer(Layer);

            if (layer == null)
            {
                Context.Output.WriteLine(T("Creating widget failed : layer {0} was not found.", Layer));
                return;
            }

            var widget = _widgetsService.CreateWidget(layer.ContentItem.Id, type, T(Title).Text, Position, Zone);
            var text   = String.Empty;

            if (widget.Has <BodyPart>())
            {
                if (UseLoremIpsumText)
                {
                    text = T(LoremIpsum).Text;
                }
                else
                {
                    if (!String.IsNullOrEmpty(Text))
                    {
                        text = Text;
                    }
                }
                widget.As <BodyPart>().Text = text;
            }

            widget.RenderTitle = RenderTitle;

            if (widget.Has <MenuWidgetPart>() && !String.IsNullOrWhiteSpace(MenuName))
            {
                // flushes before doing a query in case a previous command created the menu
                _contentManager.Flush();

                var menu = _menuService.GetMenu(MenuName);

                if (menu != null)
                {
                    widget.RenderTitle = false;
                    widget.As <MenuWidgetPart>().Menu = menu.ContentItem.Record;
                }
            }

            if (String.IsNullOrEmpty(Owner))
            {
                Owner = _siteService.GetSiteSettings().SuperUser;
            }
            var owner = _membershipService.GetUser(Owner);

            widget.As <ICommonPart>().Owner = owner;

            if (widget.Has <IdentityPart>() && !String.IsNullOrEmpty(Identity))
            {
                widget.As <IdentityPart>().Identifier = Identity;
            }

            Context.Output.WriteLine(T("Widget created successfully.").Text);
        }