diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/AbpTagHelperService.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/AbpTagHelperService.cs index cb8366cfb1..0df2041aa2 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/AbpTagHelperService.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/AbpTagHelperService.cs @@ -20,6 +20,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers protected const string TabItems = "TabItems"; protected const string AccordionItems = "AccordionItems"; protected const string BreadcrumbItemsContent = "BreadcrumbItemsContent"; + protected const string CarouselItemsContent = "CarouselItemsContent"; protected const string TabItemsDataTogglePlaceHolder = "{{data_toggle}}"; protected const string TabItemsVerticalPillPlaceHolder = "{{vertical_pill}}"; protected const string TabItemNamePlaceHolder = "{{Tag_Name}}"; @@ -27,6 +28,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers protected const string AbpTabItemActivePlaceholder = "{_Tab_Active_Placeholder_}"; protected const string AbpTabItemShowActivePlaceholder = "{_Tab_Show_Active_Placeholder_}"; protected const string AbpBreadcrumbItemActivePlaceholder = "{_Breadcrumb_Active_Placeholder_}"; + protected const string AbpCarouselItemActivePlaceholder = "{_CarouselItem_Active_Placeholder_}"; protected const string AbpTabItemSelectedPlaceholder = "{_Tab_Selected_Placeholder_}"; protected const string AbpAccordionParentIdPlaceholder = "{_{{Parent_Accordion_Id}}_}"; diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Carousel/AbpCarouselItemTagHelper.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Carousel/AbpCarouselItemTagHelper.cs new file mode 100644 index 0000000000..e8e983b34a --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Carousel/AbpCarouselItemTagHelper.cs @@ -0,0 +1,21 @@ +namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Carousel +{ + public class AbpCarouselItemTagHelper : AbpTagHelper + { + public bool? Active { get; set; } + + public string Src { get; set; } + + public string Alt { get; set; } + + public string CaptionTitle { get; set; } + + public string Caption { get; set; } + + public AbpCarouselItemTagHelper(AbpCarouselItemTagHelperService tagHelperService) + : base(tagHelperService) + { + + } + } +} diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Carousel/AbpCarouselItemTagHelperService.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Carousel/AbpCarouselItemTagHelperService.cs new file mode 100644 index 0000000000..9b44254f17 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Carousel/AbpCarouselItemTagHelperService.cs @@ -0,0 +1,74 @@ +using System.Collections.Generic; +using System.Text; +using System.Text.Encodings.Web; +using Microsoft.AspNetCore.Razor.TagHelpers; +using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHelpers; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Carousel +{ + public class AbpCarouselItemTagHelperService : AbpTagHelperService + { + private readonly HtmlEncoder _encoder; + + public AbpCarouselItemTagHelperService(HtmlEncoder encoder) + { + _encoder = encoder; + } + + public override void Process(TagHelperContext context, TagHelperOutput output) + { + output.TagName = "div"; + output.Attributes.AddClass("carousel-item"); + output.Attributes.AddClass(AbpCarouselItemActivePlaceholder); + + SetInnerImgTag(context, output); + SetActive(context, output); + AddCaption(context, output); + + AddToContext(context, output); + + output.SuppressOutput(); + } + + private void AddToContext(TagHelperContext context, TagHelperOutput output) + { + var getOutputAsHtml = RenderTagHelperOutput(output, _encoder); + + var itemList = GetValueFromContext>(context, CarouselItemsContent); + + itemList.Add(new CarouselItem(getOutputAsHtml, TagHelper.Active ?? false)); + } + + protected virtual void SetInnerImgTag(TagHelperContext context, TagHelperOutput output) + { + var imgTag ="\"""; + output.Content.SetHtmlContent(imgTag); + } + + protected virtual void SetActive(TagHelperContext context, TagHelperOutput output) + { + if (TagHelper.Active??false) + { + output.Attributes.AddClass("active"); + } + } + + protected virtual void AddCaption(TagHelperContext context, TagHelperOutput output) + { + if (string.IsNullOrWhiteSpace(TagHelper.Caption) && string.IsNullOrWhiteSpace(TagHelper.CaptionTitle)) + { + return; + } + + var html = new StringBuilder(""); + + html.AppendLine("
"); + html.AppendLine("
"+TagHelper.CaptionTitle+"
"); + html.AppendLine("

" + TagHelper.Caption + "

"); + html.AppendLine("
"); + + output.PostContent.SetHtmlContent(html.ToString()); + } + + } +} \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Carousel/AbpCarouselTagHelper.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Carousel/AbpCarouselTagHelper.cs new file mode 100644 index 0000000000..becb13ca47 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Carousel/AbpCarouselTagHelper.cs @@ -0,0 +1,19 @@ +namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Carousel +{ + public class AbpCarouselTagHelper : AbpTagHelper + { + public string Id { get; set; } + + public bool? Crossfade { get; set; } + + public bool? Controls { get; set; } + + public bool? Indicators { get; set; } + + public AbpCarouselTagHelper(AbpCarouselTagHelperService tagHelperService) + : base(tagHelperService) + { + + } + } +} diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Carousel/AbpCarouselTagHelperService.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Carousel/AbpCarouselTagHelperService.cs new file mode 100644 index 0000000000..0a9255fc73 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Carousel/AbpCarouselTagHelperService.cs @@ -0,0 +1,135 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.TagHelpers; +using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHelpers; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Carousel +{ + public class AbpCarouselTagHelperService : AbpTagHelperService + { + public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) + { + output.TagName = "div"; + + SetRandomIdIfNotProvided(); + AddBasicAttributes(context, output); + + var itemList = InitilizeCarouselItemsContentsContext(context, output); + + await output.GetChildContentAsync(); + + SetOneItemAsActive(context, output, itemList); + SetItems(context, output, itemList); + SetControls(context, output, itemList); + SetIndicators(context, output, itemList); + } + + + protected virtual List InitilizeCarouselItemsContentsContext(TagHelperContext context, TagHelperOutput output) + { + var items = new List(); + context.Items[CarouselItemsContent] = items; + return items; + } + + protected virtual void SetItems(TagHelperContext context, TagHelperOutput output, List itemList) + { + var itemsHtml = new StringBuilder(""); + + foreach (var carouselItem in itemList) + { + SetActiveIfActive(carouselItem); + + itemsHtml.AppendLine(carouselItem.Html); + } + + output.Content.SetHtmlContent(itemsHtml.ToString()); + } + + protected virtual void SetControls(TagHelperContext context, TagHelperOutput output, List itemList) + { + var html = new StringBuilder(""); + + html.AppendLine(""); + html.AppendLine(""); + html.AppendLine("Previous"); + html.AppendLine(""); + html.AppendLine(""); + html.AppendLine(""); + html.AppendLine("Next"); + html.AppendLine(""); + + output.PostContent.SetHtmlContent(html.ToString()); + } + + protected virtual void SetIndicators(TagHelperContext context, TagHelperOutput output, List itemList) + { + if (TagHelper.Indicators??false) + { + return; + } + + var html = new StringBuilder("
    "); + + for (var i = 0; i < itemList.Count; i++) + { + html.AppendLine( + "
  1. ":"") + + "
  2. "); + } + + html.AppendLine("
"); + output.PreContent.SetHtmlContent(html.ToString()); + } + + protected virtual void SetOneItemAsActive(TagHelperContext context, TagHelperOutput output, List itemList) + { + if (!itemList.Any(it=> it.Active) && itemList.Count > 0) + { + itemList.FirstOrDefault().Active = true; + } + } + + protected virtual void AddBasicAttributes(TagHelperContext context, TagHelperOutput output) + { + output.Attributes.Add("data-ride", "carousel"); + output.Attributes.Add("id", TagHelper.Id); + AddBasicClasses(context, output); + } + + protected virtual void AddBasicClasses(TagHelperContext context, TagHelperOutput output) + { + output.Attributes.AddClass("carousel"); + output.Attributes.AddClass("slide"); + SetFadeAnimation(context, output); + } + + protected virtual void SetFadeAnimation(TagHelperContext context, TagHelperOutput output) + { + if (TagHelper.Crossfade??false) + { + output.Attributes.AddClass("carousel-fade"); + } + } + + protected virtual void SetRandomIdIfNotProvided() + { + if (string.IsNullOrWhiteSpace(TagHelper.Id)) + { + TagHelper.Id = Guid.NewGuid().ToString("N"); + } + } + + protected virtual void SetActiveIfActive(CarouselItem item) + { + item.Html = item.Html.Replace(AbpCarouselItemActivePlaceholder, item.Active ? "active" : ""); + } + + } +} \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Carousel/CarouselItem.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Carousel/CarouselItem.cs new file mode 100644 index 0000000000..fdfe6b07a3 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Carousel/CarouselItem.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Carousel +{ + public class CarouselItem + { + public CarouselItem(string html, bool active) + { + Html = html; + Active = active; + } + + public string Html { get; set; } + + public bool Active { get; set; } + } +}