/// <summary>
        /// Gets the data that identifies this Crex template and action data.
        /// </summary>
        /// <param name="isPreview">if set to <c>true</c> then this is for a preview.</param>
        /// <returns>A CrexAction object.</returns>
        public override CrexAction GetCrexAction(bool isPreview)
        {
            var mergeFields  = GetCommonMergeFields();
            var layout       = GetAttributeValue("Layout");
            var lavaTemplate = GetAttributeValue("Template");

            using (var rockContext = new RockContext())
            {
                var contentChannel            = new ContentChannelService(rockContext).Get(GetAttributeValue("ContentChannel").AsGuid());
                var errorMessages             = new List <string>();
                var contentChannelItemService = new ContentChannelItemService(rockContext);
                var contentChannelItems       = GetContent(errorMessages);

                mergeFields.AddOrReplace("ContentChannel", contentChannel);
                mergeFields.AddOrReplace("Items", contentChannelItems.ToList());
                var detailPage  = Rock.Web.Cache.PageCache.Get(GetAttributeValue("DetailPage").AsGuid());
                var linkedPages = new Dictionary <string, object>
                {
                    { "DetailPageId", detailPage != null?detailPage.Id.ToString() : string.Empty }
                };
                mergeFields.Add("LinkedPages", linkedPages);

                var json = lavaTemplate.ResolveMergeFields(mergeFields, CurrentPerson, GetAttributeValue("EnabledLavaCommands"));

                if (layout == "Menu")
                {
                    var menuData = new com.blueboxmoon.Crex.Rest.Menu
                    {
                        BackgroundImage = GetUrlSetFromAttributes("BackgroundImage", "BackgroundImageUrl", mergeFields)
                    };

                    menuData.Buttons = json.FromJsonOrNull <List <MenuButton> >();

                    return(new CrexAction(layout, menuData));
                }
                else if (layout == "PosterList")
                {
                    var posterListData = new PosterList
                    {
                        BackgroundImage = GetUrlSetFromAttributes("BackgroundImage", "BackgroundImageUrl", mergeFields),
                        Title           = PageCache.PageTitle
                    };

                    posterListData.Items = json.FromJsonOrNull <List <PosterListItem> >();

                    return(new CrexAction(layout, posterListData));
                }
            }

            return(new CrexAction());
        }
        /// <summary>
        /// Gets the data that identifies this Crex template and action data.
        /// </summary>
        /// <param name="isPreview">if set to <c>true</c> then this is for a preview.</param>
        /// <returns>A CrexAction object.</returns>
        public override CrexAction GetCrexAction(bool isPreview)
        {
            var mergeFields  = GetCommonMergeFields();
            var layout       = GetAttributeValue("Layout");
            var lavaTemplate = GetAttributeValue("Template");

            using (var rockContext = new RockContext())
            {
                var pageCache = PageCache.Get(BlockCache.PageId.Value, rockContext);

                mergeFields.AddOrReplace("Pages", pageCache.GetPages(rockContext));

                //
                // Process the template to generate the JSON data.
                //
                var json = lavaTemplate.ResolveMergeFields(mergeFields, CurrentPerson, GetAttributeValue("EnabledLavaCommands"));

                if (layout == "Menu")
                {
                    var menuData = new com.blueboxmoon.Crex.Rest.Menu
                    {
                        BackgroundImage = GetUrlSetFromAttributes("BackgroundImage", "BackgroundImageUrl", mergeFields),
                        Notifications   = GetNotifications(rockContext, mergeFields)
                    };

                    menuData.Buttons = json.FromJsonOrNull <List <MenuButton> >();

                    return(new CrexAction(layout, menuData));
                }
                else if (layout == "PosterList")
                {
                    var posterListData = new PosterList
                    {
                        BackgroundImage = GetUrlSetFromAttributes("BackgroundImage", "BackgroundImageUrl", mergeFields),
                        Title           = PageCache.PageTitle
                    };

                    posterListData.Items = json.FromJsonOrNull <List <PosterListItem> >();

                    return(new CrexAction(layout, posterListData));
                }
            }

            return(new CrexAction());
        }
Example #3
0
        /// <summary>
        /// Gets the data that identifies this Crex template and action data.
        /// </summary>
        /// <param name="isPreview">if set to <c>true</c> then this is for a preview.</param>
        /// <returns>A CrexAction object.</returns>
        public override CrexAction GetCrexAction(bool isPreview)
        {
            var mergeFields         = GetCommonMergeFields();
            var layout              = GetAttributeValue("Layout");
            var lavaTemplate        = GetAttributeValue("Template");
            var allowedChannelTypes = GetAttributeValues("AllowedChannelTypes").AsGuidList();
            int?contentItemId       = HttpContext.Current.Request.QueryString["ContentItemId"].AsIntegerOrNull();

            if (!contentItemId.HasValue)
            {
                return(new CrexAction());
            }

            var detailPage  = Rock.Web.Cache.PageCache.Get(GetAttributeValue("DetailPage").AsGuid());
            var linkedPages = new Dictionary <string, object>
            {
                { "DetailPageId", detailPage != null?detailPage.Id.ToString() : string.Empty }
            };

            mergeFields.Add("LinkedPages", linkedPages);

            using (var rockContext = new RockContext())
            {
                var contentItem = new ContentChannelItemService(rockContext).Get(contentItemId.Value);

                //
                // Verify the content item is one we can display.
                //
                if (allowedChannelTypes.Any() && !allowedChannelTypes.Contains(contentItem.ContentChannelType.Guid))
                {
                    throw new Exception("Content channel item is not in an allowed channel type.");
                }

                //
                // Perform sorting on the content item.
                //
                var contentChannelItems = GetContentItems(contentItem);

                //
                // Get the JSON from the lava template.
                //
                mergeFields.AddOrReplace("ParentItem", contentItem);
                mergeFields.AddOrReplace("Items", contentChannelItems.ToList());
                var json = lavaTemplate.ResolveMergeFields(mergeFields, CurrentPerson, GetAttributeValue("EnabledLavaCommands"));

                //
                // Get the background image.
                //
                UrlSet backgroundImage = GetUrlSetFromAttributes("BackgroundImage", "BackgroundImageUrl", mergeFields);

                //
                // Final layout configuration.
                //
                if (layout == "Menu")
                {
                    var menuData = new com.blueboxmoon.Crex.Rest.Menu
                    {
                        BackgroundImage = backgroundImage
                    };

                    menuData.Buttons = json.FromJsonOrNull <List <MenuButton> >();

                    return(new CrexAction(layout, menuData));
                }
                else if (layout == "PosterList")
                {
                    var posterListData = new PosterList
                    {
                        BackgroundImage = backgroundImage,
                        Title           = contentItem.Title
                    };

                    posterListData.Items = json.FromJsonOrNull <List <PosterListItem> >();

                    return(new CrexAction(layout, posterListData));
                }
            }

            return(new CrexAction());
        }