Exemple #1
0
        public object ToEditorModel(Element element, DescribeElementsContext describeContext) {
            var map = GetMapFor(element);
            var node = new JObject();
            var container = element as Container;

            // We want to convert any null value being added to this node to an empty string,
            // so that we can perform a JSON string comparison on the client side editor to detect if the user changed anything.
            // If the initial state would contain null values, these would become empty strings after the user made a change
            // (e.g. setting some HtmlID property from empty to "my-id" and then clearing out that field).
            node.PropertyChanged += (sender, args) => {
                var value = node[args.PropertyName] as JValue;

                if (value != null && value.Value == null)
                    node[args.PropertyName] = "";
            };

            map.FromElement(element, describeContext, node);
            node["type"] = map.LayoutElementType;

            if (container != null)
                node["children"] = new JArray(container.Elements.Select(x => ToEditorModel(x, describeContext)).ToList());

            // Would be nicer if we could turn JObject into an anonymous object directly, but this seems to be the only way.
            return JsonConvert.DeserializeObject(node.ToString());
        }
        private void Displaying(ElementDisplayContext context, Element element) {
            var drivers = _elementManager.Value.GetDrivers(element);

            foreach (var driver in drivers) {
                driver.Displaying(context);
            }
        }
        public dynamic DisplayElement(
            Element element,
            IContent content,
            string displayType = null,
            IUpdateModel updater = null,
            string renderEventName = null,
            string renderEventArgs = null) {

            var createShapeContext = new ElementCreatingDisplayShapeContext {
                Element = element,
                DisplayType = displayType,
                Content = content,
            };

            element.Descriptor.CreatingDisplay(createShapeContext);

            var typeName = element.GetType().Name;
            var category = element.Category.ToSafeName();
            var drivers = element.Descriptor.GetDrivers();
            var elementShapeArguments = CreateArguments(element, content);
            var elementShape = (dynamic)_shapeFactory.Create("Element", elementShapeArguments, () => new ZoneHolding(() => _shapeFactory.Create("ElementZone")));
            

            elementShape.Metadata.DisplayType = displayType;
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}", typeName));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}_{1}", typeName, displayType));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}__{1}", typeName, category));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}_{1}__{2}", typeName, displayType, category));

            var displayContext = new ElementDisplayContext {
                Element = element,
                ElementShape = elementShape,
                DisplayType = displayType,
                Content = content,
                Updater = updater,
                RenderEventName = renderEventName,
                RenderEventArgs = renderEventArgs
            };

            _elementEventHandlerHandler.Displaying(displayContext);
            InvokeDrivers(drivers, driver => driver.Displaying(displayContext));
            element.Descriptor.Display(displayContext);

            var container = element as Container;

            if (container != null) {
                if (container.Elements.Any()) {
                    foreach (var child in container.Elements) {
                        var childShape = DisplayElement(child, content, displayType: displayType, updater: updater);
                        childShape.Parent = elementShape;
                        elementShape.Add(childShape);
                    }
                }
            }

            return elementShape;
        }
        public ElementBlueprint CreateBlueprint(Element baseElement, string elementTypeName, string elementDisplayName, string elementDescription, string elementCategory) {
            var blueprint = new ElementBlueprint {
                BaseElementTypeName = baseElement.Descriptor.TypeName,
                ElementTypeName = elementTypeName,
                ElementDisplayName = elementDisplayName,
                ElementDescription = elementDescription,
                ElementCategory = elementCategory
            };

            _blueprintRepository.Create(blueprint);
            return blueprint;
        }
        private static void Flatten(ICollection<Element> list, Element element, int currentLevel, int? levels = null) {
            list.Add(element);
            var container = element as Container;

            if (container == null)
                return;

            if (levels != null && currentLevel == levels)
                return;

            foreach (var child in container.Elements) {
                Flatten(list, child, currentLevel + 1, levels);
            }
        }
 public object ToDto(Element element, int index = 0) {
     var container = element as Container;
     var dto = new {
         typeName = element.Descriptor.TypeName,
         data = element.Data.Serialize(),
         exportableData = element.ExportableData.Serialize(),
         index = index,
         elements = container != null ? container.Elements.Select(ToDto).ToList() : new List<object>(),
         isTemplated = element.IsTemplated,
         htmlId = element.HtmlId,
         htmlClass = element.HtmlClass,
         htmlStyle = element.HtmlStyle
     };
     return dto;
 }
 public string Serialize(Element element) {
     var dto = ToDto(element);
     return JToken.FromObject(dto).ToString(Formatting.None);
 }
Exemple #8
0
 public ILayoutModelMap GetMapFor(Element element) {
     return SelectMap(x => x.CanMap(element));
 }
 public ElementRemovingContext(Element element, IEnumerable<Element> elements, IEnumerable<Element> removedElements, IContent content) {
     Element = element;
     Elements = elements;
     RemovedElements = removedElements;
     Content = content;
 }
        private static INamedEnumerable<object> CreateArguments(Element element, IContent content) {
            var children = new List<dynamic>();
            var dictionary = new Dictionary<string, object> {
                {"Element", element},
                {"Elements", children},
                {"ContentItem", content != null ? content.ContentItem : default(ContentItem)}
            };

            return Arguments.From(dictionary);
        }
 private void InvokeDrivers(Element element, Action<IElementDriver> action)
 {
     var drivers = _elementManager.GetDrivers(element.Descriptor);
     drivers.Invoke(action, Logger);
 }
Exemple #12
0
 public ImportElementContext(Element element, ILayoutAspect layout, ElementDataDictionary exportableData, IContentImportSession session) {
     Element = element;
     Layout = layout;
     ExportableData = exportableData;
     Session = session;
 }
Exemple #13
0
        public dynamic DisplayElement(
            Element element,
            IContent content,
            string displayType = null,
            IUpdateModel updater = null)
        {
            var typeName = element.GetType().Name;
            var category = element.Category.ToSafeName();
            var drivers = element.Descriptor.GetDrivers().ToList();
            var createShapeContext = new ElementCreatingDisplayShapeContext {
                Element = element,
                DisplayType = displayType,
                Content = content,
            };

            _elementEventHandlerHandler.CreatingDisplay(createShapeContext);
            drivers.Invoke(driver => driver.CreatingDisplay(createShapeContext), Logger);
            if (element.Descriptor.CreatingDisplay != null)
                element.Descriptor.CreatingDisplay(createShapeContext);

            if (createShapeContext.Cancel)
                return null;

            var elementShapeArguments = CreateArguments(element, content);
            var elementShape = (dynamic)_shapeFactory.Create("Element", elementShapeArguments, () => new ZoneHolding(() => _shapeFactory.Create("ElementZone")));

            elementShape.Metadata.DisplayType = displayType;
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}", typeName));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}_{1}", typeName, displayType));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}__{1}", typeName, category));
            elementShape.Metadata.Alternates.Add(String.Format("Elements_{0}_{1}__{2}", typeName, displayType, category));

            var displayingContext = new ElementDisplayingContext {
                Element = element,
                ElementShape = elementShape,
                DisplayType = displayType,
                Content = content,
                Updater = updater
            };

            _elementEventHandlerHandler.Displaying(displayingContext);
            drivers.Invoke(driver => driver.Displaying(displayingContext), Logger);

            if (element.Descriptor.Displaying != null)
                element.Descriptor.Displaying(displayingContext);

            var container = element as Container;

            if (container != null) {
                if (container.Elements.Any()) {
                    var childIndex = 0;
                    foreach (var child in container.Elements) {
                        var childShape = DisplayElement(child, content, displayType: displayType, updater: updater);

                        if (childShape != null) {
                            childShape.Parent = elementShape;
                            elementShape.Add(childShape, childIndex++.ToString());
                        }
                    }
                }
            }

            var displayedContext = new ElementDisplayedContext {
                Element = element,
                ElementShape = elementShape,
                DisplayType = displayType,
                Content = content,
                Updater = updater
            };

            _elementEventHandlerHandler.Displayed(displayedContext);
            drivers.Invoke(driver => driver.Displayed(displayedContext), Logger);

            if (element.Descriptor.Displayed != null)
                element.Descriptor.Displayed(displayedContext);

            return elementShape;
        }
Exemple #14
0
 private string RenderElement(Element element, DescribeElementsContext describeContext, string displayType = "Design") {
     return _shapeDisplay.Display(_elementDisplay.DisplayElement(element, describeContext.Content, displayType));
 }
 public ExportElementContext(Element element, ILayoutAspect layout, ElementDataDictionary exportableData)
 {
     Element = element;
     Layout = layout;
     ExportableData = exportableData;
 }