Пример #1
0
        public List <Field> GetFields(int Id, string fieldAlias)
        {
            List <Field> fields      = new List <Field>();
            var          currentNode = contentService.GetById(Id);

            if (currentNode != null)
            {
                var currentForm = currentNode.ContentType.Alias == NodeAlias.FormNode ? currentNode:
                                  contentService.GetAncestors(currentNode).Where(x => x.ContentType.Alias == NodeAlias.FormNode).FirstOrDefault();

                if (currentForm != null)
                {
                    GridDataModel formGrid = GridDataModel.Deserialize(currentForm.GetValue(PropertyAlias.FormGrid).ToString());
                    if (formGrid != null)
                    {
                        fieldAlias = String.IsNullOrEmpty(fieldAlias) ? string.Empty : fieldAlias;
                        var filterField   = !String.IsNullOrWhiteSpace(fieldAlias) ? fieldAlias.Split(',') : null;
                        var allFields     = fieldService.GridControlsAsFields(formGrid.GetAllControls());
                        var filedControls = filterField != null?allFields.Where(f => filterField.Contains(f.FieldType.Type, StringComparer.OrdinalIgnoreCase)) : allFields;

                        fields = filedControls.ToList();
                    }
                }
            }
            return(fields);
        }
        private void OnExamineGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            try {
                string nodeTypeAlias = e.Fields["nodeTypeAlias"];

                if (nodeTypeAlias == "Home" || nodeTypeAlias == "LandingPage" || nodeTypeAlias == "TextPage" || nodeTypeAlias == "BlogPost")
                {
                    string value;

                    // Just return now if the "content" field wasn't found
                    if (!e.Fields.TryGetValue("content", out value))
                    {
                        return;
                    }

                    // Parse the raw JSON into an instance of "GridDataModel"
                    GridDataModel grid = GridDataModel.Deserialize(e.Fields["content"]);

                    // Get the searchable text (based on each control in the grid model)
                    e.Fields["content"] = grid.GetSearchableText();
                }
            } catch (Exception ex) {
                // Remember to change the message added to the log. My colleagues typically doesn't,
                // so I occasionally see "MAYDAY! MAYDAY! MAYDAY!" in our logs :(
                LogHelper.Error <SkriftGridExamineIndexer>("MAYDAY! MAYDAY! MAYDAY!", ex);
            }
        }
        public void TestSample1()
        {
            // Load the JSON
            string json = File.ReadAllText(PathResolver.MapPath("~/Samples/Sample1.json"));

            // Get the Grid model
            GridDataModel model = GridDataModel.Deserialize(json);

            Assert.IsNotNull(model);

            Assert.AreEqual(1, model.Sections.Length);
            Assert.AreEqual(7, model.Sections[0].Rows.Length);

            GridControl[] controls = model.GetAllControls();

            Assert.AreEqual(14, controls.Length);

            Hest(controls[0], "headline", typeof(GridControlTextValue), typeof(GridEditorTextConfig));
            Hest(controls[1], "quote", typeof(GridControlTextValue), typeof(GridEditorTextConfig));
            Hest(controls[2], "banner_headline", typeof(GridControlTextValue), typeof(GridEditorTextConfig));
            Hest(controls[3], "banner_tagline", typeof(GridControlTextValue), typeof(GridEditorTextConfig));
            Hest(controls[4], "rte", typeof(GridControlRichTextValue));
            Hest(controls[5], "rte", typeof(GridControlRichTextValue));
            Hest(controls[6], "rte", typeof(GridControlRichTextValue));
            Hest(controls[7], "rte", typeof(GridControlRichTextValue));
            Hest(controls[8], "rte", typeof(GridControlRichTextValue));
            Hest(controls[9], "media_wide", typeof(GridControlMediaValue), typeof(GridEditorMediaConfig));
            Hest(controls[10], "rte", typeof(GridControlRichTextValue));
            Hest(controls[11], "rte", typeof(GridControlRichTextValue));
            Hest(controls[12], "rte", typeof(GridControlRichTextValue));
            Hest(controls[13], "media", typeof(GridControlMediaValue), typeof(GridEditorMediaConfig));
        }
Пример #4
0
        public static bool GridHasContent(IPublishedContent page, string gridAlias)
        {
            var grid = page.GetProperty(gridAlias);

            if (grid != null && grid.HasValue)
            {
                var           content  = grid.DataValue.ToString();
                GridDataModel model    = GridDataModel.Deserialize(content);
                var           controls = model.GetAllControls();

                return(controls != null && controls.Any());
            }

            return(false);
        }
Пример #5
0
        public static string GetGridText(string content)
        {
            GridDataModel grid = GridDataModel.Deserialize(content);

            StringBuilder combined = new StringBuilder();

            foreach (GridControl ctrl in grid.GetAllControls())
            {
                switch (ctrl.Editor.Alias)
                {
                case "rte":
                {
                    // Get the HTML value
                    string html = ctrl.GetValue <GridControlRichTextValue>().Value;

                    // Strip any HTML tags so we only have text
                    string text = Regex.Replace(html, "<.*?>", "");

                    // Extra decoding may be necessary
                    text = HttpUtility.HtmlDecode(text);

                    // Now append the text
                    combined.AppendLine(text);

                    break;
                }

                case "media":
                {
                    GridControlMediaValue media = ctrl.GetValue <GridControlMediaValue>();
                    if (media != null)
                    {
                        combined.AppendLine(media.Caption);
                    }
                    break;
                }

                case "headline":
                case "quote":
                {
                    combined.AppendLine(ctrl.GetValue <GridControlTextValue>().Value);
                    break;
                }
                }
            }

            return(combined.ToString());
        }
Пример #6
0
        private void ContentService_Publishing(IPublishingStrategy sender, PublishEventArgs <IContent> e)
        {
            var domains = container.GetAllInstances <IDomainModel>();

            foreach (var entity in e.PublishedEntities)
            {
                #region validate model in grid
                if (entity.HasProperty(PropertyAlias.GridContent))
                {
                    var json = entity.GetValue <string>(PropertyAlias.GridContent);

                    GridDataModel grid = GridDataModel.Deserialize(json);

                    foreach (var domain in domains)
                    {
                        var gridModels = grid.GetAllControls(domain.GetAliasName());
                        if (gridModels != null && gridModels.Any())
                        {
                            foreach (var gridModel in gridModels)
                            {
                                LeBlenderModel editor = Newtonsoft.Json.JsonConvert.DeserializeObject <LeBlenderModel>(gridModel.JObject.ToString());

                                foreach (var item in editor.Items)
                                {
                                    var model = Mapper.Map(item, domain);
                                    ValidateModel(e, model);
                                }
                            }
                        }
                    }
                }
                #endregion
                #region Validate model
                else
                {
                    var domain = domains.FirstOrDefault(x => x.IsAliasOf(entity.ContentType.Alias));
                    if (domain != null)
                    {
                        var model = Mapper.Map(entity, domain);
                        ValidateModel(e, model);
                    }
                }
                #endregion
            }
        }
Пример #7
0
        static void Main(string[] args)
        {
            string path = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "", "Example.json");

            // Deserialize the grid data
            GridDataModel gridData = GridDataModel.Deserialize(File.ReadAllText(path));

            Console.WriteLine(path);
            Console.WriteLine();


            if (gridData == null)
            {
                Console.WriteLine("WTF?");
                return;
            }



            foreach (var control in gridData.GetAllControls())
            {
                Console.WriteLine(control.Editor.Alias.PadRight(20) + " => " + (control.Value == null ? "NULL" : control.Value.GetType().FullName));

                if (control.Editor.Alias == "rte")
                {
                    Console.WriteLine();
                    Console.WriteLine("RTE as String:".PadRight(20) + " => " + control.GetValue <GridControlRichTextValue>().Value);
                    Console.WriteLine("RTE as HtmlString:".PadRight(20) + " => " + control.GetValue <GridControlRichTextValue>().HtmlValue);
                    Console.WriteLine();
                }
                else if (control.Editor.Alias == "media")
                {
                    var media = control.GetValue <GridControlMediaValue>();

                    Console.WriteLine();
                    Console.WriteLine("Media:".PadRight(20) + " => " + media.Image + " (" + media.Id + ")");
                    Console.WriteLine();
                }

                //Console.WriteLine( JsonConvert.SerializeObject(control, Formatting.Indented) );
            }
        }
Пример #8
0
        private void IndexGridDataModel(IndexingNodeDataEventArgs e, string propertyValue)
        {
            try
            {
                // Just return/exit now if the value doesn't look like JSON
                if (!propertyValue.StartsWith("{"))
                {
                    return;
                }

                // Parse/deserialize the grid value
                GridDataModel grid = GridDataModel.Deserialize(propertyValue);

                // StringBuilder used for building the new grid value optimized for searching
                var combined = ExamineHelper.GetStringFromGridModel(grid);

                e.Fields[Constants.SkyConstants.Properties.ContentGrid] = combined;
            }
            catch (Exception ex)
            {
                LogHelper.Error <ExamineIndexer>("Exeption in IndexGridDataModel method", ex);
            }
        }
Пример #9
0
        public void TestSample1()
        {
            // Remove the converter for the Fanoe starter kit
            GridContext.Current.Converters.Remove <FanoeGridConverter>();

            Assert.AreEqual(1, GridContext.Current.Converters.Count);

            // Load the JSON
            string json = File.ReadAllText(PathResolver.MapPath("~/Samples/Sample1.json"));

            // Get the Grid model
            GridDataModel model = GridDataModel.Deserialize(json);

            Assert.IsNotNull(model);

            Assert.AreEqual(1, model.Sections.Length);
            Assert.AreEqual(7, model.Sections[0].Rows.Length);

            GridControl[] controls = model.GetAllControls();

            Assert.AreEqual(14, controls.Length);

            Hest(controls[0], "headline", typeof(GridControlTextValue), typeof(GridEditorTextConfig));
            Hest(controls[1], "quote", typeof(GridControlTextValue), typeof(GridEditorTextConfig));
            Hest(controls[2], "banner_headline");
            Hest(controls[3], "banner_tagline");
            Hest(controls[4], "rte", typeof(GridControlRichTextValue));
            Hest(controls[5], "rte", typeof(GridControlRichTextValue));
            Hest(controls[6], "rte", typeof(GridControlRichTextValue));
            Hest(controls[7], "rte", typeof(GridControlRichTextValue));
            Hest(controls[8], "rte", typeof(GridControlRichTextValue));
            Hest(controls[9], "media_wide");
            Hest(controls[10], "rte", typeof(GridControlRichTextValue));
            Hest(controls[11], "rte", typeof(GridControlRichTextValue));
            Hest(controls[12], "rte", typeof(GridControlRichTextValue));
            Hest(controls[13], "media", typeof(GridControlMediaValue), typeof(GridEditorMediaConfig));

            {
                Assert.AreEqual(JsonConvert.SerializeObject(model, Formatting.None), model.JObject.ToString(Formatting.None));
                Assert.AreEqual(JsonConvert.SerializeObject(model.Sections[0], Formatting.None), model.Sections[0].JObject.ToString(Formatting.None));

                GridRow row = model.Sections[0].Rows[6];
                Assert.AreEqual("Hest", row.Name);
                Assert.AreEqual(2, row.Areas.Length);
                Assert.AreEqual(true, row.HasAreas);
                Assert.AreEqual(0, row.Styles.Count);
                Assert.AreEqual(1, row.Config.Count);
                Assert.AreEqual("dark", row.Config["class"]);
                Assert.AreEqual(JsonConvert.SerializeObject(row, Formatting.None), row.JObject.ToString(Formatting.None));

                GridArea area1 = model.Sections[0].Rows[6].Areas[0];
                Assert.AreEqual(4, area1.Grid);
                Assert.AreEqual(1, area1.Controls.Length);
                Assert.AreEqual("Hest", area1.Row.Name);
                Assert.AreEqual(4, area1.Grid);
                Assert.AreEqual(1, area1.Config.Count);
                Assert.AreEqual(1, area1.Styles.Count);
                Assert.AreEqual("yellow", area1.Config["class"]);
                Assert.AreEqual("150px", area1.Styles["margin-bottom"]);
                Assert.AreEqual(JsonConvert.SerializeObject(area1, Formatting.None), area1.JObject.ToString(Formatting.None));

                GridArea area2 = model.Sections[0].Rows[6].Areas[1];
                Assert.AreEqual(8, area2.Grid);
                Assert.AreEqual(0, area2.Controls.Length);
                Assert.AreEqual(JsonConvert.SerializeObject(area2, Formatting.None), area2.JObject.ToString(Formatting.None));
            }
        }