Пример #1
0
        public ConvertResponse Convert(RenderContext context, JObject result)
        {
            var page = context.GetItem <Page>();

            if (page == null || string.IsNullOrEmpty(page.Body) || page.Dom == null)
            {
                return(null);
            }

            string converttype = Lib.Helper.JsonHelper.GetString(result, "ConvertToType");
            string convertname = Lib.Helper.JsonHelper.GetString(result, "Name");

            var name = ConvertManager.GetUniqueName(context, converttype, convertname);

            View view = new View();

            view.Name = name;
            view.Body = Lib.Helper.JsonHelper.GetString(result, "HtmlBody");

            context.WebSite.SiteDb().Views.AddOrUpdate(view);

            return(new ConvertResponse
            {
                ComponentNameOrId = view.Name,
                Tag = "<view id='" + view.Name.ToString() + "'></view>",
            });
        }
Пример #2
0
        public ConvertResponse Convert(RenderContext context, JObject result)
        {
            var sitedb = context.WebSite.SiteDb();

            string resultname = Lib.Helper.JsonHelper.GetString(result, "Name");

            if (string.IsNullOrEmpty(resultname))
            {
                resultname = "contentlist";
            }
            string type = Lib.Helper.JsonHelper.GetString(result, "ConvertToType");
            var    name = ConvertManager.GetUniqueName(context, type, resultname);
            var    data = Lib.Helper.JsonHelper.GetObject(result, "data");

            var res = DataManager.AddData(sitedb, name, data);

            View view = new View();

            view.Name = name;

            string viewbody = Lib.Helper.JsonHelper.GetString(result, "HtmlBody");

            view.Body = UpdateViewTemplate(viewbody, res);

            sitedb.Views.AddOrUpdate(view);

            DataManager.AddGetContentListDataMethod(sitedb, view.Id, res.contentFolder.Id, "List");

            return(new ConvertResponse()
            {
                IsSuccess = true,
                ComponentNameOrId = view.Name,
                Tag = "<view id='" + view.Name.ToString() + "'></view>"
            });
        }
Пример #3
0
        public ConvertResponse Convert(RenderContext context, JObject ConvertResult)
        {
            var page = context.GetItem <Page>();

            if (page == null || string.IsNullOrEmpty(page.Body) || page.Dom == null)
            {
                return(null);
            }
            string convertname = Lib.Helper.JsonHelper.GetString(ConvertResult, "name");
            string converttype = Lib.Helper.JsonHelper.GetString(ConvertResult, "ConvertToType");

            var name = ConvertManager.GetUniqueName(context, converttype, convertname);

            Sites.Contents.Models.HtmlBlock block = new Contents.Models.HtmlBlock();
            block.Name = name;
            string convertvalue = Lib.Helper.JsonHelper.GetString(ConvertResult, "HtmlBody");
            var    culture      = string.IsNullOrEmpty(context.Culture) ? string.Empty : context.Culture;

            block.SetValue(culture, convertvalue);

            context.WebSite.SiteDb().HtmlBlocks.AddOrUpdate(block);

            return(new ConvertResponse()
            {
                IsSuccess = true,
                ComponentNameOrId = block.Name,
                Tag = "<htmlblock id='" + block.Name.ToString() + "'></htmlblock>"
            });
        }
Пример #4
0
        public static string ConvertLayout(SiteDb SiteDb, Guid PageId, List <LayoutResult> Results)
        {
            var page = SiteDb.Pages.Get(PageId);

            if (page == null)
            {
                return(null);
            }

            var dom = Kooboo.Dom.DomParser.CreateDom(page.Body);

            var updates = new List <SourceUpdate>();

            foreach (var item in Results)
            {
                if (item.KoobooIds == null || item.KoobooIds.Count == 0)
                {
                    continue;
                }

                if (item.IsContainer)
                {
                    var koobooid = item.KoobooIds[0];
                    if (!string.IsNullOrEmpty(koobooid))
                    {
                        var node = Service.DomService.GetElementByKoobooId(dom, koobooid);

                        if (node != null && node.nodeType == enumNodeType.ELEMENT)
                        {
                            var element = node as Element;
                            element.setAttribute(ConstTALAttributes.placeholder, item.Name);

                            string newtag = Service.DomService.ReSerializeElement(element, "");

                            updates.Add(new SourceUpdate {
                                StartIndex = element.location.openTokenStartIndex, EndIndex = element.location.endTokenEndIndex, NewValue = newtag
                            });
                        }
                    }
                }
                else
                {
                    var koobooids  = item.KoobooIds;
                    int startindex = int.MaxValue;
                    int endindex   = int.MinValue;

                    foreach (var id in koobooids)
                    {
                        var node = Service.DomService.GetElementByKoobooId(dom, id);

                        if (node != null && node.nodeType == enumNodeType.ELEMENT)
                        {
                            var element = node as Element;

                            if (element.location.openTokenStartIndex < startindex)
                            {
                                startindex = element.location.openTokenStartIndex;
                            }

                            if (element.location.endTokenEndIndex > endindex)
                            {
                                endindex = element.location.endTokenEndIndex;
                            }
                        }
                    }

                    if (startindex < int.MaxValue && endindex > int.MinValue)
                    {
                        var layouttag = "<div " + ConstTALAttributes.placeholder + "='" + item.Name + "' " + ConstTALAttributes.omitTag + "></div>";

                        var update = new SourceUpdate();
                        update.StartIndex = startindex;
                        update.EndIndex   = endindex;
                        update.NewValue   = layouttag;

                        updates.Add(update);
                    }
                }
            }

            if (updates.Any())
            {
                string layoutbody = ConvertManager.UpdateDomSource(dom, updates);
                var    name       = GetLayoutName(SiteDb);
                Layout layout     = new Layout();
                layout.Name = name;
                layout.Body = layoutbody;
                SiteDb.Layouts.AddOrUpdate(layout);
            }
            return(null);
        }