protected override DriverResult Editor(ProductListPart part, dynamic shapeHelper)
 {
     return(this.ContentShape(
                "Parts_ProductList_Edit",
                () => shapeHelper.EditorTemplate(
                    Prefix: this.Prefix,
                    TemplateName: "Parts/ProductList",
                    Model: new ProductListEditViewModel
     {
         Part = part,
         CatalogHierarchies = this._orchardServices.ContentManager.Query <CatalogHierarchyPart>(VersionOptions.Latest)
                              .List()
                              .Where(chp => !chp.GenerateUrls)
                              .Select(
             chp =>
         {
             ContentItemMetadata metadata = this._orchardServices.ContentManager.GetItemMetadata(chp);
             return new SelectListItem {
                 Text = String.IsNullOrEmpty(metadata.DisplayText) ? chp.TypeDefinition.DisplayName : metadata.DisplayText, Value = chp.Id.ToString(), Selected = chp.Id == part.CatalogHierarchyId
             };
         }
             )
                              .OrderBy(sli => sli.Text)
                              .ToList()
     }
                    )
                ));
 }
Exemplo n.º 2
0
        private async Task BuildMenuLevels(NavigationItemBuilder urlTreeRoot, List <Level> levels)
        {
            foreach (var level in levels)
            {
                ContentItemMetadata cim = null;
                // Not all segments will have a content item associated with them.
                if (level.ContentItem != null)
                {
                    cim = await _contentManager.PopulateAspectAsync <ContentItemMetadata>(level.ContentItem);
                }
                // TODO fix for list, which by default uses display. Hmm is this fixed?
                if (cim != null)
                {
                    cim.AdminRouteValues["Action"] = "Edit";
                }

                await urlTreeRoot.AddAsync(level.DisplayText, level.DisplayText, async menuLevel =>
                {
                    if (level.ContentItem != null)
                    {
                        menuLevel.Action(cim.AdminRouteValues["Action"] as string, cim.AdminRouteValues["Controller"] as string, cim.AdminRouteValues);
                        menuLevel.Resource(level.ContentItem);
                        var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(level.ContentItem.ContentType);
                        menuLevel.Permission(ContentTypePermissions.CreateDynamicPermission(
                                                 ContentTypePermissions.PermissionTemplates[global::OrchardCore.Contents.Permissions.EditContent.Name], contentTypeDefinition));
                    }
                    await BuildMenuLevels(menuLevel, level.SubLevels);
                });
            }
        }
Exemplo n.º 3
0
        private string GetBaseUrlForCreate()
        {
            var dummyContent             = services.ContentManager.New("DataReportDashboard");
            ContentItemMetadata metadata = services.ContentManager.GetItemMetadata(dummyContent);

            return(Url.RouteUrl(metadata.CreateRouteValues).Replace("DataReportDashboard", ""));
        }
        public async Task <ActionResult> Index(string shoppingCartId = null)
        {
            ShoppingCart cart = await _shoppingCartPersistence.Retrieve(shoppingCartId);

            IDictionary <string, ProductPart> products =
                await _productService.GetProductDictionary(cart.Items.Select(line => line.ProductSku));

            var items = await _priceService.AddPrices(cart.Items);

            ShoppingCartLineViewModel[] lines = await Task.WhenAll(items.Select(async item =>
            {
                ProductPart product          = products[item.ProductSku];
                Amount price                 = _priceStrategy.SelectPrice(item.Prices);
                ContentItemMetadata metaData = await _contentManager.GetContentItemMetadataAsync(product);
                return(new ShoppingCartLineViewModel
                {
                    Quantity = item.Quantity,
                    ProductSku = item.ProductSku,
                    ProductName = product.ContentItem.DisplayText,
                    UnitPrice = price,
                    LinePrice = item.Quantity *price,
                    ProductUrl = Url.RouteUrl(metaData.DisplayRouteValues),
                    Attributes = item.Attributes.ToDictionary(attr => attr.AttributeName)
                });
            }));

            var model = new ShoppingCartViewModel
            {
                Id     = shoppingCartId,
                Lines  = lines,
                Totals = lines.GroupBy(l => l.LinePrice.Currency).Select(g => new Amount(g.Sum(l => l.LinePrice.Value), g.Key))
            };

            return(View(model));
        }
Exemplo n.º 5
0
 public ItemInspector(IContent item, ContentItemMetadata metadata, IEnumerable <IHtmlFilter> htmlFilters)
 {
     _item        = item;
     _metadata    = metadata;
     _htmlFilters = htmlFilters;
     _common      = item.Get <ICommonPart>();
     _titleAspect = item.Get <ITitleAspect>();
     _body        = item.Get <BodyPart>();
 }
        public async Task <TAspect> PopulateAspectAsync <TAspect>(IContent content, TAspect aspect)
        {
            if (typeof(TAspect) != typeof(ContentItemMetadata))
            {
                throw new NotImplementedException();
            }
            var metadata = new ContentItemMetadata
            {
                DisplayRouteValues = new RouteValueDictionary()
            };

            return(await Task.FromResult((TAspect)(object)metadata));
        }
Exemplo n.º 7
0
 private Task BuildViewModel(OrderPartViewModel model, OrderPart part)
 => Task.Run(async() =>
 {
     model.ContentItem = part.ContentItem;
     IDictionary <string, ProductPart> products =
         await _productService.GetProductDictionary(part.LineItems.Select(line => line.ProductSku));
     OrderLineItemViewModel[] lineItems = await Task.WhenAll(part.LineItems.Select(async lineItem =>
     {
         ProductPart product          = products[lineItem.ProductSku];
         ContentItemMetadata metaData = await _contentManager.GetContentItemMetadataAsync(product);
         return(new OrderLineItemViewModel
         {
             Quantity = lineItem.Quantity,
             ProductSku = lineItem.ProductSku,
             ProductName = product.ContentItem.DisplayText,
             UnitPrice = lineItem.UnitPrice,
             LinePrice = lineItem.LinePrice,
             ProductRouteValues = metaData.DisplayRouteValues,
             Attributes = lineItem.Attributes.ToDictionary(attr => attr.Key, attr => attr.Value)
         });
     }));
     model.LineItems = lineItems;
     model.OrderPart = part;
 });
 protected virtual void GetContentItemMetadata(ContentPart part, TField field, ContentItemMetadata metadata)
 {
 }
Exemplo n.º 9
0
        public override void Process(TagHelperContext tagHelperContext, TagHelperOutput output)
        {
            ContentItemMetadata metadata    = null;
            ContentItem         contentItem = null;

            var urlHelper = _urlHelperFactory.GetUrlHelper(ViewContext);

            if (DisplayFor != null)
            {
                contentItem = DisplayFor;
                metadata    = _contentManager.PopulateAspect(DisplayFor, new ContentItemMetadata());

                if (metadata.DisplayRouteValues == null)
                {
                    return;
                }

                output.Attributes.SetAttribute("href", urlHelper.Action(metadata.DisplayRouteValues["action"].ToString(), metadata.DisplayRouteValues));
            }
            else if (EditFor != null)
            {
                contentItem = EditFor;
                metadata    = _contentManager.PopulateAspect(EditFor, new ContentItemMetadata());

                if (metadata.EditorRouteValues == null)
                {
                    return;
                }

                output.Attributes.SetAttribute("href", urlHelper.Action(metadata.EditorRouteValues["action"].ToString(), metadata.EditorRouteValues));
            }
            else if (AdminFor != null)
            {
                contentItem = AdminFor;
                metadata    = _contentManager.PopulateAspect(AdminFor, new ContentItemMetadata());

                if (metadata.AdminRouteValues == null)
                {
                    return;
                }

                output.Attributes.SetAttribute("href", urlHelper.Action(metadata.AdminRouteValues["action"].ToString(), metadata.AdminRouteValues));
            }
            else if (RemoveFor != null)
            {
                contentItem = RemoveFor;
                metadata    = _contentManager.PopulateAspect(RemoveFor, new ContentItemMetadata());

                if (metadata.RemoveRouteValues == null)
                {
                    return;
                }

                output.Attributes.SetAttribute("href", urlHelper.Action(metadata.RemoveRouteValues["action"].ToString(), metadata.RemoveRouteValues));
            }
            else if (CreateFor != null)
            {
                contentItem = CreateFor;
                metadata    = _contentManager.PopulateAspect(CreateFor, new ContentItemMetadata());

                if (metadata.CreateRouteValues == null)
                {
                    return;
                }

                output.Attributes.SetAttribute("href", urlHelper.Action(metadata.CreateRouteValues["action"].ToString(), metadata.CreateRouteValues));
            }

            // A self closing anchor tag will be rendered using the display text
            if (output.TagMode == TagMode.SelfClosing && metadata != null)
            {
                output.TagMode = TagMode.StartTagAndEndTag;
                if (!string.IsNullOrEmpty(metadata.DisplayText))
                {
                    output.Content.Append(metadata.DisplayText);
                }
                else
                {
                    var typeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType);
                    output.Content.Append(typeDefinition.ToString());
                }
            }

            return;
        }
Exemplo n.º 10
0
 protected virtual void GetContentItemMetadata(TContent context, ContentItemMetadata metadata)
 {
 }
Exemplo n.º 11
0
        public override async Task ProcessAsync(TagHelperContext tagHelperContext, TagHelperOutput output)
        {
            ContentItemMetadata metadata    = null;
            ContentItem         contentItem = null;

            var urlHelper = _urlHelperFactory.GetUrlHelper(ViewContext);

            if (DisplayFor != null)
            {
                contentItem = DisplayFor;
                var previewAspect = await _contentManager.PopulateAspectAsync <PreviewAspect>(contentItem);

                if (!string.IsNullOrEmpty(previewAspect.PreviewUrl))
                {
                    var previewUrl = previewAspect.PreviewUrl;
                    if (!previewUrl.StartsWith("~/", StringComparison.OrdinalIgnoreCase))
                    {
                        if (previewUrl.StartsWith('/'))
                        {
                            previewUrl = '~' + previewUrl;
                        }
                        else
                        {
                            previewUrl = "~/" + previewUrl;
                        }
                    }

                    output.Attributes.SetAttribute("href", urlHelper.Content(previewUrl));
                    return;
                }

                metadata = await _contentManager.PopulateAspectAsync <ContentItemMetadata>(DisplayFor);

                if (metadata.DisplayRouteValues == null)
                {
                    return;
                }

                ApplyRouteValues(tagHelperContext, metadata.DisplayRouteValues);

                output.Attributes.SetAttribute("href", urlHelper.Action(metadata.DisplayRouteValues["action"].ToString(), metadata.DisplayRouteValues));
            }
            else if (EditFor != null)
            {
                contentItem = EditFor;
                metadata    = await _contentManager.PopulateAspectAsync <ContentItemMetadata>(EditFor);

                if (metadata.EditorRouteValues == null)
                {
                    return;
                }

                ApplyRouteValues(tagHelperContext, metadata.EditorRouteValues);

                output.Attributes.SetAttribute("href", urlHelper.Action(metadata.EditorRouteValues["action"].ToString(), metadata.EditorRouteValues));
            }
            else if (AdminFor != null)
            {
                contentItem = AdminFor;
                metadata    = await _contentManager.PopulateAspectAsync <ContentItemMetadata>(AdminFor);

                if (metadata.AdminRouteValues == null)
                {
                    return;
                }

                ApplyRouteValues(tagHelperContext, metadata.AdminRouteValues);

                output.Attributes.SetAttribute("href", urlHelper.Action(metadata.AdminRouteValues["action"].ToString(), metadata.AdminRouteValues));
            }
            else if (RemoveFor != null)
            {
                contentItem = RemoveFor;
                metadata    = await _contentManager.PopulateAspectAsync <ContentItemMetadata>(RemoveFor);

                if (metadata.RemoveRouteValues == null)
                {
                    return;
                }

                ApplyRouteValues(tagHelperContext, metadata.RemoveRouteValues);

                output.Attributes.SetAttribute("href", urlHelper.Action(metadata.RemoveRouteValues["action"].ToString(), metadata.RemoveRouteValues));
            }
            else if (CreateFor != null)
            {
                contentItem = CreateFor;
                metadata    = await _contentManager.PopulateAspectAsync <ContentItemMetadata>(CreateFor);

                if (metadata.CreateRouteValues == null)
                {
                    return;
                }

                ApplyRouteValues(tagHelperContext, metadata.CreateRouteValues);

                output.Attributes.SetAttribute("href", urlHelper.Action(metadata.CreateRouteValues["action"].ToString(), metadata.CreateRouteValues));
            }

            // A self closing anchor tag will be rendered using the display text
            if (output.TagMode == TagMode.SelfClosing && metadata != null)
            {
                output.TagMode = TagMode.StartTagAndEndTag;
                if (!string.IsNullOrEmpty(contentItem.DisplayText))
                {
                    output.Content.Append(contentItem.DisplayText);
                }
                else
                {
                    var typeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType);
                    output.Content.Append(typeDefinition.ToString());
                }
            }

            return;
        }
Exemplo n.º 12
0
 public ItemInspector(IContent item, ContentItemMetadata metadata) : this(item, metadata, Enumerable.Empty <IHtmlFilter>())
 {
 }
Exemplo n.º 13
0
        protected override void GetContentItemMetadata(ContentPart part, CoeveryTextField field, ContentItemMetadata metadata)
        {
            var model = field.PartFieldDefinition.Settings.GetModel <CoeveryTextFieldSettings>();

            if (model.IsDispalyField)
            {
                metadata.DisplayText = field.Value;
            }
        }
Exemplo n.º 14
0
 protected virtual void GetContentItemMetadata(SocketsPart part, ContentItemMetadata metadata)
 {
     return;
 }
Exemplo n.º 15
0
        public void PropertyWrapper(
            dynamic Display,
            TextWriter Output,
            HtmlHelper Html,
            UrlHelper Url,
            dynamic Item,
            ContentItem ContentItem,
            ContentItemMetadata ContentItemMetadata,
            PropertyRecord Property
            )
        {
            // Display will encode any string which is not IHtmlString
            string resultOutput  = Convert.ToString(Display(Item));
            var    resultIsEmpty = String.IsNullOrEmpty(resultOutput) || (resultOutput == "0" && Property.ZeroIsEmpty);

            if (Property.HideEmpty && resultIsEmpty)
            {
                return;
            }

            if (Property.RewriteOutput)
            {
                resultOutput = _tokenizerWork.Value.Replace(Property.RewriteText, new Dictionary <string, object> {
                    { "Text", resultOutput }, { "Content", ContentItem }
                });
            }

            if (Property.StripHtmlTags)
            {
                resultOutput = resultOutput.RemoveTags();
            }

            if (Property.TrimLength)
            {
                var ellipsis = Property.AddEllipsis ? "&#160;&#8230;" : "";
                resultOutput = resultOutput.Ellipsize(Property.MaxLength, ellipsis, Property.TrimOnWordBoundary);
            }

            if (Property.TrimWhiteSpace)
            {
                resultOutput = resultOutput.Trim();
            }

            if (Property.PreserveLines)
            {
                using (var sw = new StringWriter()) {
                    using (var sr = new StringReader(resultOutput)) {
                        string line;
                        while (null != (line = sr.ReadLine()))
                        {
                            sw.WriteLine(line);
                            sw.WriteLine("<br />");
                        }
                    }
                    resultOutput = sw.ToString();
                }
            }

            var wrapperTag = new TagBuilder(Property.CustomizeWrapperHtml && !String.IsNullOrEmpty(Property.CustomWrapperTag) ? Property.CustomWrapperTag : "div");

            if (Property.CustomizeWrapperHtml && !String.IsNullOrEmpty(Property.CustomWrapperCss))
            {
                wrapperTag.AddCssClass(_tokenizerWork.Value.Replace(Property.CustomWrapperCss, new Dictionary <string, object>()));
            }

            if (!(Property.CustomizeWrapperHtml && Property.CustomWrapperTag == "-"))
            {
                Output.Write(wrapperTag.ToString(TagRenderMode.StartTag));
            }

            if (Property.CreateLabel)
            {
                var labelTag = new TagBuilder(Property.CustomizeLabelHtml && !String.IsNullOrEmpty(Property.CustomLabelTag) ? Property.CustomLabelTag : "span");

                if (Property.CustomizeLabelHtml && !String.IsNullOrEmpty(Property.CustomLabelCss))
                {
                    labelTag.AddCssClass(_tokenizerWork.Value.Replace(Property.CustomLabelCss, new Dictionary <string, object>()));
                }

                if (!(Property.CustomizeLabelHtml && Property.CustomLabelTag == "-"))
                {
                    Output.Write(labelTag.ToString(TagRenderMode.StartTag));
                }

                Output.Write(_tokenizerWork.Value.Replace(Property.Label, new Dictionary <string, object>()));

                if (!(Property.CustomizeLabelHtml && Property.CustomLabelTag == "-"))
                {
                    Output.Write(labelTag.ToString(TagRenderMode.EndTag));
                }
            }

            var propertyTag = new TagBuilder(Property.CustomizePropertyHtml && !String.IsNullOrEmpty(Property.CustomPropertyTag) ? Property.CustomPropertyTag : "span");

            if (Property.CustomizePropertyHtml && !String.IsNullOrEmpty(Property.CustomPropertyCss))
            {
                propertyTag.AddCssClass(_tokenizerWork.Value.Replace(Property.CustomPropertyCss, new Dictionary <string, object>()));
            }

            if (!(Property.CustomizePropertyHtml && Property.CustomPropertyTag == "-"))
            {
                Output.Write(propertyTag.ToString(TagRenderMode.StartTag));
            }

            if (!resultIsEmpty)
            {
                if (Property.LinkToContent)
                {
                    var linkTag = new TagBuilder("a");
                    linkTag.Attributes.Add("href", Url.RouteUrl(ContentItemMetadata.DisplayRouteValues));
                    linkTag.InnerHtml = resultOutput;
                    Output.Write(linkTag.ToString());
                }
                else
                {
                    Output.Write(resultOutput);
                }
            }
            else
            {
                Output.Write(_tokenizerWork.Value.Replace(Property.NoResultText, new Dictionary <string, object>()));
            }

            if (!(Property.CustomizePropertyHtml && Property.CustomPropertyTag == "-"))
            {
                Output.Write(propertyTag.ToString(TagRenderMode.EndTag));
            }

            if (!(Property.CustomizeWrapperHtml && Property.CustomWrapperTag == "-"))
            {
                Output.Write(wrapperTag.ToString(TagRenderMode.EndTag));
            }
        }