Example #1
0
        internal static string RenderListWithContext(DynamicEntity parent, string fieldName, IInPageEditingSystem edit = null)
        {
            var innerBuilder = new StringBuilder();
            var found        = parent.TryGetMember(fieldName, out var objFound);

            if (found)
            {
                if (objFound is IList <DynamicEntity> itms)
                {
                    foreach (var cb in itms)
                    {
                        innerBuilder.Append(Render(cb.SxcInstance.ContentBlock, cb.Entity, parent.SxcInstance.Log));
                    }
                }
            }

            // create edit object if missing...to re-use in the wh
            if (edit == null)
            {
                edit = new InPageEditingHelper(parent.SxcInstance, parent.SxcInstance.Log);
            }

            return(string.Format(WrapperTemplate, new object[]
            {
                edit.Enabled?WrapperMultiItems: "",
                edit.ContextAttributes(parent, field: fieldName),
                innerBuilder
            }));
        }
Example #2
0
        public AppAndDataHelpers(SxcInstance sexy, ModuleInfo module, Log parentLog) : base("Sxc.AppHlp", parentLog ?? sexy?.Log)
        {
            // ModuleInfo module = sexy.ModuleInfo;
            // Init things than require module-info or similar, but not 2sxc
            Dnn  = new DnnHelper(module);
            Link = new DnnLinkHelper(Dnn);

            // todo: maybe init App & App.Data, as they don't really require a working 2sxc

            if (sexy == null)
            {
                return;
            }

            ViewDataSource data = sexy.Data;

            _sxcInstance = sexy;
            App          = sexy.App;  // app;
            Data         = sexy.Data; // data;
            Sxc          = new SxcHelper(sexy);
            Edit         = new InPageEditingHelper(sexy);

            // If PortalSettings is null - for example, while search index runs - HasEditPermission would fail
            // But in search mode, it shouldn't show drafts, so this is ok.
            // Note that app could be null, if a user is in admin-ui of a module which hasn't actually be configured yet
            App?.InitData(PortalSettings.Current != null && sexy.Environment.Permissions.UserMayEditContent, sexy.Environment.PagePublishing /*new Environment.Dnn7.PagePublishing(Log)*/.IsEnabled(module.ModuleID), data.ConfigurationProvider);

            #region Assemble the mapping of the data-stream "default"/Presentation to the List object and the "ListContent" too
            List = new List <Element>();
            if (data != null && sexy.Template != null)
            {
                if (data.Out.ContainsKey("Default"))
                {
                    var entities = data.List.Select(e => e.Value);
                    var elements = entities.Select(GetElementFromEntity).ToList();
                    List = elements;

                    if (elements.Any())
                    {
                        Content = elements.First().Content;
                        //Presentation = elements.First().Presentation;
                    }
                }

                if (data.Out.ContainsKey(AppConstants.ListContent))
                {
                    var listEntity  = data[AppConstants.ListContent].List.Select(e => e.Value).FirstOrDefault();
                    var listElement = listEntity != null?GetElementFromEntity(listEntity) : null;

                    if (listElement != null)
                    {
                        ListContent = listElement.Content;
                        // ListPresentation = listElement.Presentation;
                    }
                }
            }
            #endregion
        }
Example #3
0
        private const string WrapperSingleItem = WrapperMultiItems + " show-placeholder single-item"; // enables a placeholder when empty, and limits one entry


        internal static string RenderWithEditContext(DynamicEntity dynParent, IDynamicEntity subItem, string cbFieldName,  Guid? newGuid = null, IInPageEditingSystem edit = null)
        {
            if (edit == null)
                edit = new InPageEditingHelper(dynParent.Block);

            var attribs = edit.ContextAttributes(dynParent, field: cbFieldName, newGuid: newGuid);
            var inner = subItem == null ? "": Render(dynParent.Block, subItem.Entity).ToString();
            var cbClasses = edit.Enabled ? WrapperSingleItem : "";
            return string.Format(WrapperTemplate, new object[] { cbClasses, attribs, inner});
        }
        protected AppAndDataHelpersBase(SxcInstance sxcInstance, ITenant tenant, Log parentLog) : base("Sxc.AppHlp", parentLog ?? sxcInstance?.Log)
        {
            if (sxcInstance == null)
            {
                return;
            }

            SxcInstance = sxcInstance;
            _tenant     = tenant;
            App         = sxcInstance.App;
            Data        = sxcInstance.Data;
            Sxc         = new SxcHelper(sxcInstance);
            Edit        = new InPageEditingHelper(sxcInstance, Log);
        }
Example #5
0
        protected DynamicCodeRoot(IBlockBuilder blockBuilder, ITenant tenant, int compatibility, ILog parentLog) : base("Sxc.AppHlp", parentLog ?? blockBuilder?.Log)
        {
            if (blockBuilder == null)
            {
                return;
            }

            BlockBuilder       = blockBuilder;
            _tenant            = tenant;
            CompatibilityLevel = compatibility;
            App  = blockBuilder.App;
            Data = blockBuilder.Block.Data;
            Edit = new InPageEditingHelper(blockBuilder, Log);
        }
Example #6
0
        public DynamicCodeRoot Init(IBlock block, int compatibility, ILog parentLog)
        {
            Log.LinkTo(parentLog ?? block?.Log);
            if (block == null)
            {
                return(this);
            }

            CompatibilityLevel = compatibility;
            Block = block;
            App   = Block.App;
            Data  = Block.Data;
            Edit  = new InPageEditingHelper(Block, Log);
            return(this);
        }
Example #7
0
        public AppAndDataHelpers(SxcInstance sexy)
        {
            ModuleInfo     module = sexy.ModuleInfo;
            ViewDataSource data   = sexy.Data;

            _sxcInstance = sexy;
            App          = sexy.App;  // app;
            Data         = sexy.Data; // data;
            Dnn          = new DnnHelper(module);
            Link         = new DnnLinkHelper(Dnn);
            Sxc          = new SxcHelper(sexy);
            Edit         = new InPageEditingHelper(sexy);

            // If PortalSettings is null - for example, while search index runs - HasEditPermission would fail
            // But in search mode, it shouldn't show drafts, so this is ok.
            App.InitData(PortalSettings.Current != null && sexy.Environment.Permissions.UserMayEditContent /*SecurityHelpers.HasEditPermission(module)*/, data.ConfigurationProvider);

            #region Assemble the mapping of the data-stream "default"/Presentation to the List object and the "ListContent" too
            List = new List <Element>();
            if (data != null && sexy.Template != null)
            {
                if (data.Out.ContainsKey("Default"))
                {
                    var entities = data.List.Select(e => e.Value);
                    var elements = entities.Select(GetElementFromEntity).ToList();
                    List = elements;

                    if (elements.Any())
                    {
                        Content      = elements.First().Content;
                        Presentation = elements.First().Presentation;
                    }
                }

                if (data.Out.ContainsKey("ListContent"))
                {
                    var listEntity  = data["ListContent"].List.Select(e => e.Value).FirstOrDefault();
                    var listElement = listEntity != null?GetElementFromEntity(listEntity) : null;

                    if (listElement != null)
                    {
                        ListContent      = listElement.Content;
                        ListPresentation = listElement.Presentation;
                    }
                }
            }
            #endregion
        }
Example #8
0
        internal static string RenderListWithContext(DynamicEntity dynParent, string fieldName, string apps = null, int max = 100)
        {
            var innerBuilder = new StringBuilder();
            var found = dynParent.TryGetMember(fieldName, out var objFound);
            if (found && objFound is IList<DynamicEntity> items)
                foreach (var cb in items)
                    innerBuilder.Append(Render(cb.Block, cb.Entity));

            // create edit object if missing...to re-use of the parent
            //if (edit == null)
            IInPageEditingSystem edit = new InPageEditingHelper(dynParent.Block);

            return string.Format(WrapperTemplate, new object[]
            {
                edit.Enabled ? WrapperMultiItems : "",
                edit.ContextAttributes(dynParent, field: fieldName, apps: apps, max: max),
                innerBuilder
            });
        }
Example #9
0
        public AppAndDataHelpers(SxcInstance sexy, ModuleInfo module, Log parentLog) : base("Sxc.AppHlp", parentLog ?? sexy?.Log)
        {
            // Init things than require module-info or similar, but not 2sxc
            Dnn  = new DnnHelper(module);
            Link = new DnnLinkHelper(Dnn);

            if (sexy == null)
            {
                return;
            }

            _sxcInstance = sexy;
            App          = sexy.App;
            Data         = sexy.Data;
            Sxc          = new SxcHelper(sexy);
            Edit         = new InPageEditingHelper(sexy);

            // If PortalSettings is null - for example, while search index runs - HasEditPermission would fail
            // But in search mode, it shouldn't show drafts, so this is ok.
            // Note that app could be null, if a user is in admin-ui of a module which hasn't actually be configured yet
            App?.InitData(PortalSettings.Current != null && sexy.Environment.Permissions.UserMayEditContent,
                          PortalSettings.Current != null && sexy.Environment.PagePublishing.IsEnabled(module.ModuleID),
                          Data.ConfigurationProvider);
        }
Example #10
0
        internal static string Render(DynamicEntity parent, string entityField, string textTemplate)
        {
            // do basic checking
            if (!InlineCbDetector.IsMatch(textTemplate))
            {
                return(textTemplate);
            }

            var result       = new StringBuilder();
            var charProgress = 0;

            var matches = InlineCbDetector.Matches(textTemplate);

            if (matches.Count == 0)
            {
                return(textTemplate);
            }

            // create edit-object which is necessary for context attributes
            var edit = new InPageEditingHelper(parent.SxcInstance);

            foreach (Match curMatch in matches)
            {
                // Get characters before the first match
                if (curMatch.Index > charProgress)
                {
                    result.Append(textTemplate.Substring(charProgress, curMatch.Index - charProgress));
                }
                charProgress = curMatch.Index + curMatch.Length;

                // get the infos we need to retrieve the value, get it.
                var marker = curMatch.Value.Replace("\'", "\"");

                if (marker.IndexOf("sxc=\"sxc-content-block\"", StringComparison.Ordinal) == 0)
                {
                    continue;
                }

                var guidMatch  = GuidExtractor.Match(marker);
                var likelyGuid = guidMatch.Groups[1].Value;

                // check if guid is valid
                Guid guid;
                if (!Guid.TryParse(likelyGuid, out guid))
                {
                    continue;
                }

                object        objFound;
                DynamicEntity subitem = null;
                var           found   = parent.TryGetMember(entityField, out objFound);

                if (found)
                {
                    var itms = (IList <DynamicEntity>)objFound;
                    if (itms?.Count > 0)
                    {
                        subitem = itms.FirstOrDefault(i => i.EntityGuid == guid);
                    }
                }

                result.Append(Simple.RenderWithEditContext(parent, subitem, entityField, guid, edit));
            }

            // attach the rest of the text (after the last match)
            result.Append(textTemplate.Substring(charProgress));

            // Ready to finish, but first, ensure repeating if desired
            var finalResult = result.ToString();

            return(finalResult);
        }