public static IGridColumn <T, IHtmlContent> AddAction <T>(this IGridColumnsOf <T> columns, String action, String iconClass) where T : class { if (!IsAuthorizedFor(columns.Grid.ViewContext !, action)) { return(new GridColumn <T, IHtmlContent>(columns.Grid, model => HtmlString.Empty)); } IUrlHelperFactory?factory = columns.Grid.ViewContext?.HttpContext.RequestServices.GetService <IUrlHelperFactory>(); IUrlHelper? url = factory?.GetUrlHelper(columns.Grid.ViewContext); return(columns .Add(model => GenerateLink(model, url, action, iconClass)) .Css($"action-cell {action.ToLower()}")); }
public IssuesController(IUserAuthHelper userSessionHelper, IProjectManager projectManager, IIssueManager issueManager, ITeamManager teamManager, IUploadHandler uploadHandler, IUploadManager uploadManager, IUrlHelperFactory urlHelperFactory, IActionContextAccessor actionContextAccessor) //: base(repositary) { this._issueManager = issueManager; this._projectManager = projectManager; this._userSessionHelper = userSessionHelper; this._teamManager = teamManager; this._uploadHandler = uploadHandler; this._uploadManager = uploadManager; this._urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext); }
/// <summary> /// Initializes a new instance of the <see cref="RazorPageActivator"/> class. /// </summary> public RazorPageActivator( IModelMetadataProvider metadataProvider, IUrlHelperFactory urlHelperFactory, IJsonHelper jsonHelper, DiagnosticSource diagnosticSource, HtmlEncoder htmlEncoder, IModelExpressionProvider modelExpressionProvider) { _activationInfo = new ConcurrentDictionary<Type, PageActivationInfo>(); _metadataProvider = metadataProvider; _urlHelperAccessor = context => urlHelperFactory.GetUrlHelper(context); _jsonHelperAccessor = context => jsonHelper; _diagnosticSourceAccessor = context => diagnosticSource; _htmlEncoderAccessor = context => htmlEncoder; _modelExpressionProviderAccessor = context => modelExpressionProvider; }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccesor.ActionContext); var id = Guid.NewGuid().ToString(); output.TagName = "div"; output.TagMode = TagMode.StartTagAndEndTag; output.Attributes.Merge("class", "aiplugs-tinymce"); output.Attributes.Add("data-controller", "aiplugs-tinymce"); output.Attributes.Add("data-aiplugs-tinymce-value-from", ValueFrom); output.Attributes.Add("data-aiplugs-tinymce-settings-from", SettingsFrom); var content = await output.GetChildContentAsync(); output.Tag("textarea", () => { output.Attr("id", id); if (Name != null) { output.Attr("name", Name); } output.Attr("data-target", "aiplugs-tinymce.textarea"); }, Value ?? ""); output.Tag("button", () => { output.Attr("type", "button"); output.Attr("class", "aiplugs-tinymce__image"); output.Attr("data-target", "aiplugs-tinymce.insertImage"); output.Attr("ic-target", "body"); output.Attr("ic-swap-style", "append"); if (!string.IsNullOrEmpty(ModalImage)) { var callback = $"_insert_image_{id}"; var from = urlHelper.Content(ModalImage); from += from.Contains("?") ? "&" : "?"; from += $"callback={callback}"; output.Attr("ic-get-from", from); } }); output.Tag("button", () => { output.Attr("type", "button"); output.Attr("class", "aiplugs-tinymce__video"); output.Attr("data-target", "aiplugs-tinymce.insertVideo"); output.Attr("ic-target", "body"); output.Attr("ic-swap-style", "append"); if (!string.IsNullOrEmpty(ModalVideo)) { var callback = $"_insert_video_{id}"; var from = urlHelper.Content(ModalVideo); from += from.Contains("?") ? "&" : "?"; from += $"callback={callback}"; output.Attr("ic-get-from", from); } }); output.Content.AppendHtml(content); }
private async Task <TreeNode <NavigationNode> > BuildTreeInternal(NavigationTreeBuilderService service) { NavigationNode rootNav; var project = await projectService.GetCurrentProjectSettings(); IPage homePage = null; if ( project != null && project.UseDefaultPageAsRootNode && !string.IsNullOrEmpty(project.DefaultPageSlug) ) { //make the home page the "root" which contains all the other pages homePage = await pageService.GetPageBySlug(project.Id, project.DefaultPageSlug); } var urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccesor.ActionContext); var folderPrefix = prefixProvider.GetPrefix(); if ((homePage != null) && project.UseDefaultPageAsRootNode) { rootNav = new NavigationNode(); rootNav.IsRootNode = true; rootNav.Key = homePage.Id; rootNav.Text = homePage.Title; rootNav.Url = pageRouteHelper.ResolveHomeUrl(urlHelper, folderPrefix); // urlHelper.Content("~/" + folderPrefix); } else { rootNav = new NavigationNode(); rootNav.IsRootNode = true; rootNav.Key = "pagesRoot"; rootNav.Title = "Home"; rootNav.Text = "Home"; rootNav.Url = pageRouteHelper.ResolveHomeUrl(urlHelper, folderPrefix); // rootNav.Url = urlHelper.Content("~/" + folderPrefix); //rootNav.ChildContainerOnly = true; } var treeRoot = new TreeNode <NavigationNode>(rootNav); var rootList = await pageService.GetRootPages().ConfigureAwait(false); var rootListCount = rootList.Count(); var blogPosition = project.BlogPagePosition; if (project.AddBlogToPagesTree) { if (blogPosition > rootListCount) { blogPosition = rootListCount; } } var didAddBlog = false; if (rootListCount <= 1) { // if there are no pages we won't hit the loop below so go ahead and add the blog page if (project.AddBlogToPagesTree) { var node = new NavigationNode(); node.Key = project.BlogPageText; node.ParentKey = "RootNode"; node.Text = project.BlogPageText; if (project.BlogMenuLinksToNewestPost) { //node.Action = "MostRecent"; //node.Controller = "Blog"; node.NamedRoute = blogRoutes.MostRecentPostRouteName; node.Url = urlHelper.RouteUrl(blogRoutes.MostRecentPostRouteName); } else { //node.Action = "Index"; //node.Controller = "Blog"; //node.Url = urlHelper.Action("Index", "Blog"); node.NamedRoute = blogRoutes.BlogIndexRouteName; node.Url = urlHelper.RouteUrl(blogRoutes.BlogIndexRouteName); } node.ComponentVisibility = project.BlogPageNavComponentVisibility; var blogNode = treeRoot.AddChild(node); didAddBlog = true; } } //rootList.Insert() var rootPosition = 1; foreach (var page in rootList) { var node = new NavigationNode(); if (!didAddBlog && (project.AddBlogToPagesTree && rootPosition == blogPosition)) { node.Key = project.BlogPageText; node.ParentKey = "RootNode"; node.Text = project.BlogPageText; if (project.BlogMenuLinksToNewestPost) { //node.Action = "MostRecent"; //node.Controller = "Blog"; //node.Url = urlHelper.Action("MostRecent", "Blog"); node.NamedRoute = blogRoutes.MostRecentPostRouteName; node.Url = urlHelper.RouteUrl(blogRoutes.MostRecentPostRouteName); } else { //node.Action = "Index"; //node.Controller = "Blog"; //node.Url = urlHelper.Action("Index", "Blog"); node.NamedRoute = blogRoutes.BlogIndexRouteName; node.Url = urlHelper.RouteUrl(blogRoutes.BlogIndexRouteName); } node.ComponentVisibility = project.BlogPageNavComponentVisibility; var blogNode = treeRoot.AddChild(node); node = new NavigationNode(); // new it up again for use below } if (project.UseDefaultPageAsRootNode && (homePage != null && homePage.Id == page.Id)) { rootPosition += 1; await AddChildNodes(treeRoot, project, folderPrefix).ConfigureAwait(false); continue; } node.Key = page.Id; node.ParentKey = page.ParentId; node.Text = page.Title; node.ViewRoles = page.ViewRoles; if (string.IsNullOrEmpty(folderPrefix)) { node.Url = urlHelper.RouteUrl(pageRouteHelper.PageIndexRouteName, new { slug = page.Slug }); } else { node.Url = urlHelper.RouteUrl(pageRouteHelper.FolderPageIndexRouteName, new { slug = page.Slug }); } // for unpublished pages PagesNavigationNodePermissionResolver // will look for projectid in CustomData and if it exists // filter node from view unless user has edit permissions if (!page.IsPublished) { node.CustomData = project.Id; } var treeNode = treeRoot.AddChild(node); await AddChildNodes(treeNode, project, folderPrefix).ConfigureAwait(false); rootPosition += 1; } return(treeRoot); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (PagingModel == null) { // allow for passing in the settings separately PagingModel = new PaginationSettings(); PagingModel.CurrentPage = PageNumber; PagingModel.ItemsPerPage = PageSize; PagingModel.TotalItems = TotalItems; PagingModel.MaxPagerItems = MaxPagerItems; PagingModel.SuppressEmptyNextPrev = SuppressEmptyNextPrev; PagingModel.SuppressInActiveFirstLast = SuppressInActiveFirstLast; } if (ShowFirstLast) { PagingModel.ShowFirstLast = true; } if (!ShowNumbered) { PagingModel.ShowNumbered = false; } if (UseReverseIncrement) { PagingModel.UseReverseIncrement = true; if (SuppressEmptyNextPrev) { PagingModel.SuppressEmptyNextPrev = true; } } int totalPages = (int)Math.Ceiling(PagingModel.TotalItems / (double)PagingModel.ItemsPerPage); // don't render if only 1 page if (SuppressEmptyPager && (totalPages <= 1)) { output.SuppressOutput(); return; } //change the cs-pager element into a ul output.TagName = "ul"; //prepare things needed by generatpageeurl function urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccesor.ActionContext); List <PaginationLink> links = linkBuilder.BuildPaginationLinks( PagingModel, GeneratePageUrl, FirstPageText, FirstPageTitle, PreviousPageText, PreviousPageTitle, NextPageText, NextPageTitle, LastPageText, LastPageTitle, "..."); foreach (PaginationLink link in links) { var li = new TagBuilder("li"); if (link.IsCurrent) { li.AddCssClass(LiCurrentCssClass); } else { if (!link.Active) { li.AddCssClass(LiNonActiveCssClass); } else { if (!string.IsNullOrWhiteSpace(LiOtherCssClass)) { li.AddCssClass(LiOtherCssClass); } } } if (link.Text == PreviousPageText && !string.IsNullOrWhiteSpace(PreviousPageHtml)) { if (string.IsNullOrEmpty(link.Url)) { li.InnerHtml.AppendHtml(PreviousPageHtml); } else { li.InnerHtml.AppendHtml(PreviousPageHtml.Replace("#", link.Url)); } } else if (link.Text == NextPageText && !string.IsNullOrWhiteSpace(NextPageHtml)) { if (string.IsNullOrEmpty(link.Url)) { li.InnerHtml.AppendHtml(NextPageHtml); } else { li.InnerHtml.AppendHtml(NextPageHtml.Replace("#", link.Url)); } } else { if (!link.IsCurrent && link.Active) { var a = new TagBuilder("a"); if (!string.IsNullOrWhiteSpace(LinkOtherCssClass)) { a.AddCssClass(LinkOtherCssClass); } if (link.Active && (link.Url.Length > 0)) { a.MergeAttribute("href", link.Url); } else { a.MergeAttribute("href", "#"); } if (link.Text == "«") { a.InnerHtml.AppendHtml("«"); } else if (link.Text == "»") { a.InnerHtml.AppendHtml("»"); } else if (link.Text.Contains('<') && link.Text.Contains('>')) { //if text is an html formatted icon and contains a <tag> //ex. <span class='fa fa-chevron-right'></span> a.InnerHtml.AppendHtml(link.Text); } else { // if text should be html encoded a.InnerHtml.Append(link.Text); } if (link.Title.Length > 0) { a.MergeAttribute("title", link.Title); } if (AjaxTarget.Length > 0) { a.MergeAttribute("data-ajax", "true"); a.MergeAttribute("data-ajax-mode", AjaxMode); a.MergeAttribute("data-ajax-update", AjaxTarget); if (AjaxSuccess.Length > 0) { a.MergeAttribute("data-ajax-success", AjaxSuccess); } if (AjaxFailure.Length > 0) { a.MergeAttribute("data-ajax-failure", AjaxFailure); } if (AjaxBegin.Length > 0) { a.MergeAttribute("data-ajax-begin", AjaxBegin); } if (AjaxComplete.Length > 0) { a.MergeAttribute("data-ajax-complete", AjaxComplete); } if (AjaxLoading.Length > 0) { a.MergeAttribute("data-ajax-loading", AjaxLoading); } if (AjaxLoadingDuration.Length > 0) { a.MergeAttribute("data-ajax-loading-duration", AjaxLoadingDuration); } } li.InnerHtml.AppendHtml(a); } else { // current or not active var span = new TagBuilder("span"); if (!string.IsNullOrWhiteSpace(LinkCurrentCssClass)) { span.AddCssClass(LinkCurrentCssClass); } if (link.Text == "«") { span.InnerHtml.AppendHtml("«"); } else if (link.Text == "»") { span.InnerHtml.AppendHtml("»"); } else if (link.Text.Contains('<') && link.Text.Contains('>')) { //if text is an html formatted icon and contains a <tag> //ex. <span class='fa fa-chevron-right'></span> span.InnerHtml.AppendHtml(link.Text); } else { // if text should be html encoded span.InnerHtml.Append(link.Text); } li.InnerHtml.AppendHtml(span); } } output.Content.AppendHtml(li); } output.Attributes.Clear(); output.Attributes.Add("class", UlCssClass); }
public override void Process(TagHelperContext context, TagHelperOutput output) { IUrlHelper urlHelper = urlHelperFactory.GetUrlHelper(ViewContext); string pageLinkClass = "page-link"; TagBuilder result = new TagBuilder("ul"); result.AddCssClass("pagination"); TagBuilder first = new TagBuilder("li"); TagBuilder firstLink = new TagBuilder("a"); TagBuilder previous = new TagBuilder("li"); TagBuilder previousLink = new TagBuilder("a"); first.InnerHtml.AppendHtml(firstLink); first.AddCssClass(PageClass); firstLink.InnerHtml.AppendHtml("<i class=\"fas fa-angle-double-left\"></i>"); firstLink.AddCssClass(pageLinkClass); previous.InnerHtml.AppendHtml(previousLink); previous.AddCssClass(PageClass); previousLink.InnerHtml.AppendHtml("<i class=\"fas fa-angle-left\"></i>"); previousLink.AddCssClass(pageLinkClass); if (PageModel.CurrentPage == 1) { first.AddCssClass(PageClassDisabled); firstLink.Attributes["href"] = "#"; firstLink.Attributes["tabindex"] = "-1"; previous.AddCssClass(PageClassDisabled); previousLink.Attributes["href"] = "#"; previousLink.Attributes["tabindex"] = "-1"; } else { first.AddCssClass(PageClassNormal); PageUrlValues["page"] = 1; firstLink.Attributes["href"] = urlHelper.Action(PageAction, PageUrlValues); previous.AddCssClass(PageClassNormal); PageUrlValues["page"] = PageModel.CurrentPage - 1; previousLink.Attributes["href"] = urlHelper.Action(PageAction, PageUrlValues); } result.InnerHtml.AppendHtml(first); result.InnerHtml.AppendHtml(previous); int totalPages = PageModel.TotalPages; int startPage, endPage; if (totalPages <= PageModel.MaxPageLength) { startPage = 1; endPage = totalPages; } else if (PageModel.CurrentPage <= PageModel.MaxPageLength / 2) { startPage = 1; endPage = PageModel.MaxPageLength; } else { startPage = PageModel.CurrentPage - PageModel.MaxPageLength / 2; endPage = startPage + PageModel.MaxPageLength - 1; if (endPage > totalPages) { endPage = totalPages; startPage = endPage - PageModel.MaxPageLength + 1; } } endPage++; for (int i = startPage; i < endPage; i++) { TagBuilder tag = new TagBuilder("li"); TagBuilder link = new TagBuilder("a"); tag.InnerHtml.AppendHtml(link); tag.AddCssClass(PageClass); link.InnerHtml.Append(i.ToString()); link.AddCssClass(pageLinkClass); PageUrlValues["page"] = i; link.Attributes["href"] = urlHelper.Action(PageAction, PageUrlValues); tag.AddCssClass(i == PageModel.CurrentPage ? PageClassSelected : PageClassNormal); result.InnerHtml.AppendHtml(tag); } TagBuilder next = new TagBuilder("li"); TagBuilder nextLink = new TagBuilder("a"); TagBuilder last = new TagBuilder("li"); TagBuilder lastLink = new TagBuilder("a"); next.InnerHtml.AppendHtml(nextLink); next.AddCssClass(PageClass); nextLink.InnerHtml.AppendHtml("<i class=\"fas fa-angle-right\"></i>"); nextLink.AddCssClass(pageLinkClass); last.InnerHtml.AppendHtml(lastLink); last.AddCssClass(PageClass); lastLink.InnerHtml.AppendHtml("<i class=\"fas fa-angle-double-right\"></i>"); lastLink.AddCssClass(pageLinkClass); if (PageModel.CurrentPage == totalPages) { next.AddCssClass(PageClassDisabled); nextLink.Attributes["href"] = "#"; nextLink.Attributes["tabindex"] = "-1"; last.AddCssClass(PageClassDisabled); lastLink.Attributes["href"] = "#"; lastLink.Attributes["tabindex"] = "-1"; } else { next.AddCssClass(PageClassNormal); PageUrlValues["page"] = PageModel.CurrentPage + 1; nextLink.Attributes["href"] = urlHelper.Action(PageAction, PageUrlValues); last.AddCssClass(PageClassNormal); PageUrlValues["page"] = totalPages; lastLink.Attributes["href"] = urlHelper.Action(PageAction, PageUrlValues); } result.InnerHtml.AppendHtml(next); result.InnerHtml.AppendHtml(last); output.Content.AppendHtml(result); }
/// <summary> /// Handle shopping cart changed event /// </summary> /// <param name="cartItem">Shopping cart item</param> public void HandleShoppingCartChangedEvent(ShoppingCartItem cartItem) { //whether marketing automation is enabled if (!_sendinBlueSettings.UseMarketingAutomation) { return; } var customer = _customerService.GetCustomerById(cartItem.CustomerId); try { //create API client var client = CreateMarketingAutomationClient(); //first, try to identify current customer client.Identify(new Identify(customer.Email)); //get shopping cart GUID var shoppingCartGuid = _genericAttributeService .GetAttribute <Guid?>(customer, SendinBlueDefaults.ShoppingCartGuidAttribute); //create track event object var trackEvent = new TrackEvent(customer.Email, string.Empty); //get current customer's shopping cart var cart = _shoppingCartService .GetShoppingCart(customer, ShoppingCartType.ShoppingCart, _storeContext.CurrentStore.Id); if (cart.Any()) { //get URL helper var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext); //get shopping cart amounts _orderTotalCalculationService.GetShoppingCartSubTotal(cart, _workContext.TaxDisplayType == TaxDisplayType.IncludingTax, out var cartDiscount, out _, out var cartSubtotal, out _); var cartTax = _orderTotalCalculationService.GetTaxTotal(cart, false); var cartShipping = _orderTotalCalculationService.GetShoppingCartShippingTotal(cart); var cartTotal = _orderTotalCalculationService.GetShoppingCartTotal(cart, false, false); //get products data by shopping cart items var itemsData = cart.Where(item => item.ProductId != 0).Select(item => { var product = _productService.GetProductById(item.ProductId); //try to get product attribute combination var combination = _productAttributeParser.FindProductAttributeCombination(product, item.AttributesXml); //get default product picture var picture = _pictureService.GetProductPicture(product, item.AttributesXml); //get product SEO slug name var seName = _urlRecordService.GetSeName(product); //create product data return(new { id = product.Id, name = product.Name, variant_id = combination?.Id ?? product.Id, variant_name = combination?.Sku ?? product.Name, sku = combination?.Sku ?? product.Sku, category = _categoryService.GetProductCategoriesByProductId(item.ProductId).Aggregate(",", (all, pc) => { var res = _categoryService.GetCategoryById(pc.CategoryId).Name; res = all == "," ? res : all + ", " + res; return res; }), url = urlHelper.RouteUrl("Product", new { SeName = seName }, _webHelper.CurrentRequestProtocol), image = _pictureService.GetPictureUrl(ref picture), quantity = item.Quantity, price = _shoppingCartService.GetSubTotal(item) }); }).ToArray(); //prepare cart data var cartData = new { affiliation = _storeContext.CurrentStore.Name, subtotal = cartSubtotal, shipping = cartShipping ?? decimal.Zero, total_before_tax = cartSubtotal + cartShipping ?? decimal.Zero, tax = cartTax, discount = cartDiscount, revenue = cartTotal ?? decimal.Zero, url = urlHelper.RouteUrl("ShoppingCart", null, _webHelper.CurrentRequestProtocol), currency = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId)?.CurrencyCode, //gift_wrapping = string.Empty, //currently we can't get this value items = itemsData }; //if there is a single item in the cart, so the cart is just created if (cart.Count == 1) { shoppingCartGuid = Guid.NewGuid(); } else { //otherwise cart is updated shoppingCartGuid ??= Guid.NewGuid(); } trackEvent.EventName = SendinBlueDefaults.CartUpdatedEventName; trackEvent.EventData = new { id = $"cart:{shoppingCartGuid}", data = cartData }; } else { //there are no items in the cart, so the cart is deleted shoppingCartGuid ??= Guid.NewGuid(); trackEvent.EventName = SendinBlueDefaults.CartDeletedEventName; trackEvent.EventData = new { id = $"cart:{shoppingCartGuid}" }; } //track event client.TrackEvent(trackEvent); //update GUID for the current customer's shopping cart _genericAttributeService.SaveAttribute(customer, SendinBlueDefaults.ShoppingCartGuidAttribute, shoppingCartGuid); } catch (Exception exception) { //log full error _logger.Error($"SendinBlue Marketing Automation error: {exception.Message}.", exception, customer); } }
private IUrlHelper GetUrlHelper() { return(_urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext)); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (PageModel.TotalPages <= 1) { return; } IUrlHelper urlHelper = UrlHelperFactory.GetUrlHelper(ViewContext); TagBuilder result = new TagBuilder("ul"); TagBuilder leftarrow = new TagBuilder("li"); TagBuilder aleftarrow = new TagBuilder("a"); if (PageModel.CurrentPage == 1) { leftarrow.Attributes["class"] = "disabled"; aleftarrow.Attributes["href"] = "#!"; } else { PageUrlValues["postPage"] = PageModel.CurrentPage - 1; PageUrlValues["categoryId"] = PageCategoryId; aleftarrow.Attributes["href"] = urlHelper.Action(PageAction, PageUrlValues); } TagBuilder ileftarrow = new TagBuilder("i"); ileftarrow.Attributes["class"] = "material-icons"; ileftarrow.InnerHtml.Append("chevron_left"); aleftarrow.InnerHtml.AppendHtml(ileftarrow); leftarrow.InnerHtml.AppendHtml(aleftarrow); result.InnerHtml.AppendHtml(leftarrow); for (int i = 1; i <= PageModel.TotalPages; i++) { TagBuilder li = new TagBuilder("li"); if (PageClassesEnable) { li.AddCssClass(i == PageModel.CurrentPage ? PageClassSelected : PageClassNormal); } TagBuilder tag = new TagBuilder("a"); PageUrlValues["postPage"] = i; PageUrlValues["categoryId"] = PageCategoryId; tag.Attributes["href"] = i == PageModel.CurrentPage ? "#!" : urlHelper.Action(PageAction, PageUrlValues); tag.InnerHtml.Append(i.ToString()); li.InnerHtml.AppendHtml(tag); result.InnerHtml.AppendHtml(li); } TagBuilder rightarrow = new TagBuilder("li"); TagBuilder arightarrow = new TagBuilder("a"); if (PageModel.CurrentPage == PageModel.TotalPages) { rightarrow.Attributes["class"] = "disabled"; arightarrow.Attributes["href"] = "#!"; } else { PageUrlValues["postPage"] = PageModel.CurrentPage + 1; PageUrlValues["categoryId"] = PageCategoryId; arightarrow.Attributes["href"] = urlHelper.Action(PageAction, PageUrlValues); } TagBuilder irightarrow = new TagBuilder("i"); irightarrow.Attributes["class"] = "material-icons"; irightarrow.InnerHtml.Append("chevron_right"); arightarrow.InnerHtml.AppendHtml(irightarrow); rightarrow.InnerHtml.AppendHtml(arightarrow); result.InnerHtml.AppendHtml(rightarrow); output.Content.AppendHtml(result.InnerHtml); }
protected CarLinkTagHelperBase(IActionContextAccessor contextAccessor, IUrlHelperFactory urlHelperFactory) { UrlHelper = urlHelperFactory.GetUrlHelper(contextAccessor.ActionContext); }
public PagerTagHelper(IHttpContextAccessor accessor, IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory) { _httpContext = accessor.HttpContext; _urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext); }
/// <summary> /// Synchronously executes the <see cref="TagHelper" /> with the given <paramref name="context" /> and /// <paramref name="output" />. /// </summary> /// <param name="context">Contains information associated with the current HTML tag.</param> /// <param name="output">A stateful HTML element used to generate an HTML tag.</param> public override void Process(TagHelperContext context, TagHelperOutput output) { IUrlHelper urlHelper = urlHelperFactory.GetUrlHelper(ViewContext); TagBuilder result = new TagBuilder("ul"); result.AddCssClass("pagination"); result.AddCssClass("pagination-sm"); if (PageModel.TotalPages < 10) { for (int i = 1; i <= PageModel.TotalPages; i++) { TagBuilder liTag = new TagBuilder("li"); TagBuilder tag = new TagBuilder("a"); PageUrlValues["page"] = i; tag.Attributes["href"] = urlHelper.Action(PageAction, PageUrlValues); if (PageClassesEnabled) { liTag.AddCssClass(PageClass); liTag.AddCssClass(i == PageModel.CurrentPage ? PageClassSelected : PageClassNormal); } tag.InnerHtml.Append(i.ToString()); liTag.InnerHtml.AppendHtml(tag); result.InnerHtml.AppendHtml(liTag); } output.Content.AppendHtml(result); } else { // first page button TagBuilder firstLiTag = new TagBuilder("li"); TagBuilder firstTag = new TagBuilder("a"); TagBuilder firstFaTag = new TagBuilder("i"); firstFaTag.AddCssClass("fa"); firstFaTag.AddCssClass("fa-angle-double-left"); if (PageModel.CurrentPage == 1) { firstLiTag.AddCssClass("disabled"); } else { PageUrlValues["page"] = 1; firstTag.Attributes["href"] = urlHelper.Action(PageAction, PageUrlValues); } firstTag.InnerHtml.AppendHtml(firstFaTag); firstLiTag.InnerHtml.AppendHtml(firstTag); result.InnerHtml.AppendHtml(firstLiTag); // previous page button TagBuilder backLiTag = new TagBuilder("li"); TagBuilder backTag = new TagBuilder("a"); TagBuilder faTag = new TagBuilder("i"); faTag.AddCssClass("fa"); faTag.AddCssClass("fa-angle-left"); if (PageModel.CurrentPage == 1) { backLiTag.AddCssClass("disabled"); } else { PageUrlValues["page"] = PageModel.CurrentPage - 1; backTag.Attributes["href"] = urlHelper.Action(PageAction, PageUrlValues); } backTag.InnerHtml.AppendHtml(faTag); backLiTag.InnerHtml.AppendHtml(backTag); result.InnerHtml.AppendHtml(backLiTag); for (int i = PageModel.CurrentPage - 2; i <= PageModel.CurrentPage + 5; i++) { if (i <= 0) { continue; } else if (i > PageModel.TotalPages) { break; } TagBuilder liTag = new TagBuilder("li"); TagBuilder tag = new TagBuilder("a"); PageUrlValues["page"] = i; tag.Attributes["href"] = urlHelper.Action(PageAction, PageUrlValues); if (PageClassesEnabled) { liTag.AddCssClass(PageClass); liTag.AddCssClass(i == PageModel.CurrentPage ? PageClassSelected : PageClassNormal); } tag.InnerHtml.Append(i.ToString()); liTag.InnerHtml.AppendHtml(tag); result.InnerHtml.AppendHtml(liTag); } // next page button TagBuilder nextLiTag = new TagBuilder("li"); TagBuilder nextTag = new TagBuilder("a"); TagBuilder nextFaTag = new TagBuilder("i"); nextFaTag.AddCssClass("fa"); nextFaTag.AddCssClass("fa-angle-right"); if (PageModel.CurrentPage == PageModel.TotalPages) { nextLiTag.AddCssClass("disabled"); } else { PageUrlValues["page"] = PageModel.CurrentPage + 1; nextTag.Attributes["href"] = urlHelper.Action(PageAction, PageUrlValues); } nextTag.InnerHtml.AppendHtml(nextFaTag); nextLiTag.InnerHtml.AppendHtml(nextTag); result.InnerHtml.AppendHtml(nextLiTag); // last page button TagBuilder lastLiTag = new TagBuilder("li"); TagBuilder lastTag = new TagBuilder("a"); TagBuilder lastFaTag = new TagBuilder("i"); lastFaTag.AddCssClass("fa"); lastFaTag.AddCssClass("fa-angle-double-right"); if (PageModel.CurrentPage == PageModel.TotalPages) { lastLiTag.AddCssClass("disabled"); } else { PageUrlValues["page"] = PageModel.TotalPages; lastTag.Attributes["href"] = urlHelper.Action(PageAction, PageUrlValues); } lastTag.InnerHtml.AppendHtml(lastFaTag); lastLiTag.InnerHtml.AppendHtml(lastTag); result.InnerHtml.AppendHtml(lastLiTag); output.Content.AppendHtml(result); } }
public override void Process(TagHelperContext context, TagHelperOutput output) { var urlHelper = _urlHelperFactory.GetUrlHelper(ViewContext); output.Attributes.SetAttribute("href", urlHelper.Action("Image", "Category", new { id = NorthwindId })); }
public LinkRenderer(IUrlHelperFactory urlHelperFactory, IActionContextAccessor actionContextAccessor, ILogger <LinkRenderer> log) { _actionContextAccessor = actionContextAccessor; _urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext); _log = log; }
public TagTagHelper(IUrlHelperFactory urlHelperFactory, IActionContextAccessor actionContextAccessor) { _urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext); Tag = new TagDto(); }
/// <summary> /// Gets a configuration page URL /// </summary> public override string GetConfigurationPageUrl() { return(_urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext).RouteUrl(AvalaraTaxDefaults.ConfigurationRouteName)); }
public PagerTagHelper(IUrlHelperFactory urlHelperFactory, IActionContextAccessor actionContextAccesor) { this.urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccesor.ActionContext); }
// This is what I am aiming for //<ul class="pagination"> // <li class="previous"><a href = "#" > Previous </a ></li> // <li class="active"><a href = "#" > 1 </a ></li> // <li class=""><a href = "#" > 2 </a></li> // <li class="next"><a href = "#" > Next </a></li> // </ ul > public override void Process(TagHelperContext context, TagHelperOutput output) { IUrlHelper urlHelper = _urlHelperFactory.GetUrlHelper(ViewContext); TagBuilder result = null; TagBuilder tmpTag = null; if (this.PageModel.PageCount() > 1) { result = new TagBuilder("ul"); result.AddCssClass(this.PageClass); // Add the previous button if (this.PageShowPreviousNext == true) { tmpTag = new TagBuilder("li"); if (this.PageModel.CurrentPage <= 1) { tmpTag.AddCssClass("disabled"); tmpTag.Attributes["disabled"] = "disabled"; tmpTag = this.AddLink(ref tmpTag, urlHelper.Action(this.PageModel.PageAction, new { page = 1 }), this.PagePreviousText, string.Empty); } else { tmpTag = this.AddLink(ref tmpTag, urlHelper.Action(this.PageModel.PageAction, new { page = this.PageModel.CurrentPage - 1 }), this.PagePreviousText, string.Empty); } tmpTag.AddCssClass("previous"); // Needs to go at the end because new items are added before the previous entry result.InnerHtml.AppendHtml(tmpTag); } // Add the pages for (int i = 1; i <= this.PageModel.PageCount(); i++) { tmpTag = new TagBuilder("li"); if (this.PageModel.CurrentPage == i) { tmpTag.AddCssClass(this.PageClassSelected); } else { tmpTag.AddCssClass(this.PageClassNormal); } // Create the link tmpTag = this.AddLink(ref tmpTag, urlHelper.Action(this.PageModel.PageAction, new { page = i }), i.ToString(), string.Empty); result.InnerHtml.AppendHtml(tmpTag); } // Add the next button if (this.PageShowPreviousNext == true) { tmpTag = new TagBuilder("li"); if (this.PageModel.CurrentPage >= this.PageModel.PageCount()) { tmpTag.AddCssClass("disabled"); tmpTag.Attributes["disabled"] = "disabled"; tmpTag = this.AddLink(ref tmpTag, urlHelper.Action(this.PageModel.PageAction, new { page = this.PageModel.PageCount().ToString() }), this.PageNextText, string.Empty); } else { tmpTag = this.AddLink(ref tmpTag, urlHelper.Action(this.PageModel.PageAction, new { page = this.PageModel.CurrentPage + 1 }), this.PageNextText, string.Empty); } tmpTag.AddCssClass("next"); result.InnerHtml.AppendHtml(tmpTag); } // finally write the output. if (result != null) { output.Content.AppendHtml(result.InnerHtml); } } // tidy up result = null; tmpTag = null; }
public override void Process(TagHelperContext context, TagHelperOutput output) { IUrlHelper urlHelper = urlHelperFactory.GetUrlHelper(ViewContext); TagBuilder result = new TagBuilder("div"); //Nuevo int startPage; int endPage; int LinksPerPage = 5; if (PageModel.TotalPages > 1) { if (PageModel.TotalPages <= LinksPerPage) { startPage = 1; endPage = PageModel.TotalPages; } else { if (PageModel.PageNumber + LinksPerPage - 1 > PageModel.TotalPages) { startPage = PageModel.PageNumber - ((PageModel.PageNumber + LinksPerPage - 1) - PageModel.TotalPages); endPage = (PageModel.PageNumber + LinksPerPage - 1) - ((PageModel.PageNumber + LinksPerPage - 1) - PageModel.TotalPages); } else { if (LinksPerPage != 2) { startPage = PageModel.PageNumber - (LinksPerPage / 2); if (startPage < 1) { startPage = 1; } endPage = startPage + LinksPerPage - 1; } else { startPage = PageModel.PageNumber; endPage = PageModel.PageNumber + LinksPerPage - 1; } } } //TagBuilder labelDiv; //labelDiv = new TagBuilder("div"); //labelDiv.AddCssClass(PageClassLabel); //labelDiv.InnerHtml.Append($"Showing {PageModel.PageNumber} of {PageModel.TotalPages}"); //result.InnerHtml.AppendHtml(labelDiv); TagBuilder linkDiv = new TagBuilder("div"); linkDiv.InnerHtml.AppendHtml(GeneratePageLinks("First", 1, urlHelper)); if (PageModel.HasPrevious) { linkDiv.InnerHtml.AppendHtml(GeneratePageLinks("Previous", PageModel.PageNumber - 1, urlHelper)); } for (int i = startPage; i <= endPage; i++) { linkDiv.InnerHtml.AppendHtml(GeneratePageLinks(i.ToString(), i, urlHelper)); } if (PageModel.HasNext) { linkDiv.InnerHtml.AppendHtml(GeneratePageLinks("Next", PageModel.PageNumber + 1, urlHelper)); } linkDiv.InnerHtml.AppendHtml(GeneratePageLinks("Last", PageModel.TotalPages, urlHelper)); linkDiv.AddCssClass(PageClassLinks); result.InnerHtml.AppendHtml(linkDiv); output.Content.AppendHtml(result.InnerHtml); } }
/// <summary> /// Get UrlHelper /// </summary> /// <returns>UrlHelper</returns> protected virtual IUrlHelper GetUrlHelper() { return(_urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext)); }
public BreadcrumbTagHelper(BreadcrumbManager breadcrumbManager, IUrlHelperFactory urlHelperFactory, IActionContextAccessor actionContextAccessor) { _breadcrumbManager = breadcrumbManager; _urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext); }
public ValuesController(IActionContextAccessor actionContextAccessor, IUrlHelperFactory helper, IValueService valueService) { _uriHelper = helper.GetUrlHelper(actionContextAccessor.ActionContext); _valueService = valueService; }
/// <summary> /// Prepare the sitemap model /// </summary> /// <param name="pageModel">Sitemap page model</param> /// <returns>Sitemap model</returns> public virtual SitemapModel PrepareSitemapModel(SitemapPageModel pageModel) { var cacheKey = string.Format(ModelCacheEventConsumer.SITEMAP_PAGE_MODEL_KEY, _workContext.WorkingLanguage.Id, string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()), _storeContext.CurrentStore.Id); var cachedModel = _cacheManager.Get(cacheKey, () => { //get URL helper var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext); var model = new SitemapModel(); //prepare common items var commonGroupTitle = _localizationService.GetResource("Sitemap.General"); //home page model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("HomePage"), Url = urlHelper.RouteUrl("HomePage") }); //search model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("Search"), Url = urlHelper.RouteUrl("ProductSearch") }); //news if (_newsSettings.Enabled) { model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("News"), Url = urlHelper.RouteUrl("NewsArchive") }); } //blog if (_blogSettings.Enabled) { model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("Blog"), Url = urlHelper.RouteUrl("Blog") }); } //forums if (_forumSettings.ForumsEnabled) { model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("Forum.Forums"), Url = urlHelper.RouteUrl("Boards") }); } //contact us model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("ContactUs"), Url = urlHelper.RouteUrl("ContactUs") }); //customer info model.Items.Add(new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetResource("Account.MyAccount"), Url = urlHelper.RouteUrl("CustomerInfo") }); //at the moment topics are in general category too var topics = _topicService.GetAllTopics(_storeContext.CurrentStore.Id).Where(topic => topic.IncludeInSitemap); model.Items.AddRange(topics.Select(topic => new SitemapModel.SitemapItemModel { GroupTitle = commonGroupTitle, Name = _localizationService.GetLocalized(topic, x => x.Title), Url = urlHelper.RouteUrl("Topic", new { SeName = _urlRecordService.GetSeName(topic) }) })); //categories if (_commonSettings.SitemapIncludeCategories) { var categoriesGroupTitle = _localizationService.GetResource("Sitemap.Categories"); var categories = _categoryService.GetAllCategories(storeId: _storeContext.CurrentStore.Id); model.Items.AddRange(categories.Select(category => new SitemapModel.SitemapItemModel { GroupTitle = categoriesGroupTitle, Name = _localizationService.GetLocalized(category, x => x.Name), Url = urlHelper.RouteUrl("Category", new { SeName = _urlRecordService.GetSeName(category) }) })); } //manufacturers if (_commonSettings.SitemapIncludeManufacturers) { var manufacturersGroupTitle = _localizationService.GetResource("Sitemap.Manufacturers"); var manufacturers = _manufacturerService.GetAllManufacturers(storeId: _storeContext.CurrentStore.Id); model.Items.AddRange(manufacturers.Select(manufacturer => new SitemapModel.SitemapItemModel { GroupTitle = manufacturersGroupTitle, Name = _localizationService.GetLocalized(manufacturer, x => x.Name), Url = urlHelper.RouteUrl("Manufacturer", new { SeName = _urlRecordService.GetSeName(manufacturer) }) })); } //products if (_commonSettings.SitemapIncludeProducts) { var productsGroupTitle = _localizationService.GetResource("Sitemap.Products"); var products = _productService.SearchProducts(storeId: _storeContext.CurrentStore.Id, visibleIndividuallyOnly: true); model.Items.AddRange(products.Select(product => new SitemapModel.SitemapItemModel { GroupTitle = productsGroupTitle, Name = _localizationService.GetLocalized(product, x => x.Name), Url = urlHelper.RouteUrl("Product", new { SeName = _urlRecordService.GetSeName(product) }) })); } //product tags if (_commonSettings.SitemapIncludeProductTags) { var productTagsGroupTitle = _localizationService.GetResource("Sitemap.ProductTags"); var productTags = _productTagService.GetAllProductTags(); model.Items.AddRange(productTags.Select(productTag => new SitemapModel.SitemapItemModel { GroupTitle = productTagsGroupTitle, Name = _localizationService.GetLocalized(productTag, x => x.Name), Url = urlHelper.RouteUrl("ProductsByTag", new { SeName = _urlRecordService.GetSeName(productTag) }) })); } return(model); }); //prepare model with pagination pageModel.PageSize = Math.Max(pageModel.PageSize, _commonSettings.SitemapPageSize); pageModel.PageNumber = Math.Max(pageModel.PageNumber, 1); var pagedItems = new PagedList <SitemapModel.SitemapItemModel>(cachedModel.Items, pageModel.PageNumber - 1, pageModel.PageSize); var sitemapModel = new SitemapModel { Items = pagedItems }; sitemapModel.PageModel.LoadPagedList(pagedItems); return(sitemapModel); }
/// <summary> /// Prepare paged URL record list model /// </summary> /// <param name="searchModel">URL record search model</param> /// <returns>URL record list model</returns> public virtual UrlRecordListModel PrepareUrlRecordListModel(UrlRecordSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } var isActive = searchModel.IsActiveId == 0 ? null : (bool?)(searchModel.IsActiveId == 1); var languageId = searchModel.LanguageId < 0 ? null : (int?)(searchModel.LanguageId); //get URL records var urlRecords = _urlRecordService.GetAllUrlRecords(slug: searchModel.SeName, languageId: languageId, isActive: isActive, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize); //get URL helper var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext); //prepare list model var model = new UrlRecordListModel().PrepareToGrid(searchModel, urlRecords, () => { return(urlRecords.Select(urlRecord => { //fill in model values from the entity var urlRecordModel = urlRecord.ToModel <UrlRecordModel>(); //fill in additional values (not existing in the entity) urlRecordModel.Name = urlRecord.Slug; urlRecordModel.Language = urlRecord.LanguageId == 0 ? _localizationService.GetResource("Admin.System.SeNames.Language.Standard") : _languageService.GetLanguageById(urlRecord.LanguageId)?.Name ?? "Unknown"; //details URL var detailsUrl = string.Empty; var entityName = urlRecord.EntityName?.ToLowerInvariant() ?? string.Empty; switch (entityName) { case "blogpost": detailsUrl = urlHelper.Action("BlogPostEdit", "Blog", new { id = urlRecord.EntityId }); break; case "category": detailsUrl = urlHelper.Action("Edit", "Category", new { id = urlRecord.EntityId }); break; case "manufacturer": detailsUrl = urlHelper.Action("Edit", "Manufacturer", new { id = urlRecord.EntityId }); break; case "product": detailsUrl = urlHelper.Action("Edit", "Product", new { id = urlRecord.EntityId }); break; case "newsitem": detailsUrl = urlHelper.Action("NewsItemEdit", "News", new { id = urlRecord.EntityId }); break; case "topic": detailsUrl = urlHelper.Action("Edit", "Topic", new { id = urlRecord.EntityId }); break; case "vendor": detailsUrl = urlHelper.Action("Edit", "Vendor", new { id = urlRecord.EntityId }); break; } urlRecordModel.DetailsUrl = detailsUrl; return urlRecordModel; })); }); return(model); }
public override void Process(TagHelperContext context, TagHelperOutput output) { IUrlHelper urlHelper = _urlHelperFactory.GetUrlHelper(ViewContext); output.TagName = "div"; output.TagMode = TagMode.StartTagAndEndTag; var totalPages = (int)Math.Ceiling((double)ItemsCount / ItemsPerPage); // набор ссылок будет представлять список ul TagBuilder tag = new TagBuilder("ul"); tag.AddCssClass($"{Action.ToLower()}-pagination pagination justify-content-center"); var maxCount = 5; // максимальное количество страниц пока нумерация не рвется if (totalPages > 2 + maxCount * 2) { var dotted = new TagBuilder("li"); dotted.AddCssClass("page-item disabled"); var link = new TagBuilder("a"); link.InnerHtml.Append("..."); link.AddCssClass("page-link"); dotted.InnerHtml.AppendHtml(link); tag.InnerHtml.AppendHtml(CreateTag(1, urlHelper)); // всегда есть первый if (CurrentPage - maxCount - 1 > 0) { tag.InnerHtml.AppendHtml(dotted); } for (var i = CurrentPage - maxCount + 1; i < CurrentPage; i++) { if (i <= 1) { continue; } var item = CreateTag(i, urlHelper); tag.InnerHtml.AppendHtml(item); } if (CurrentPage != 1 && CurrentPage != totalPages) // текущая, если она не первая и не последняя { tag.InnerHtml.AppendHtml(CreateTag(CurrentPage, urlHelper)); } for (var i = CurrentPage + 1; i < maxCount + CurrentPage && i < totalPages; i++) { var item = CreateTag(i, urlHelper); tag.InnerHtml.AppendHtml(item); } if (CurrentPage + maxCount < totalPages) { tag.InnerHtml.AppendHtml(dotted); } tag.InnerHtml.AppendHtml(CreateTag(totalPages, urlHelper)); // всегда есть последний } else { for (var i = 1; i <= totalPages; i++) { var item = CreateTag(i, urlHelper); tag.InnerHtml.AppendHtml(item); } } output.PostContent.AppendHtml(tag); }
public Task <CkeditorOptions> GetCkeditorOptions() { var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccesor.ActionContext); _options.CustomConfigPath = urlHelper.Content(_options.CustomConfigPath); if (string.IsNullOrWhiteSpace(_options.FileBrowseUrl)) { _options.FileBrowseUrl = urlHelper.Action("FileDialog", "FileManager", new { type = "file" }); } else { _options.FileBrowseUrl = urlHelper.Content(_options.FileBrowseUrl); } if (string.IsNullOrWhiteSpace(_options.ImageBrowseUrl)) { _options.ImageBrowseUrl = urlHelper.Action("FileDialog", "FileManager", new { type = "image" }); } else { _options.ImageBrowseUrl = urlHelper.Content(_options.ImageBrowseUrl); } if (string.IsNullOrWhiteSpace(_options.VideoBrowseUrl)) { _options.VideoBrowseUrl = urlHelper.Action("FileDialog", "FileManager", new { type = "video" }); } else { _options.VideoBrowseUrl = urlHelper.Content(_options.VideoBrowseUrl); } if (string.IsNullOrWhiteSpace(_options.AudioBrowseUrl)) { _options.AudioBrowseUrl = urlHelper.Action("FileDialog", "FileManager", new { type = "audio" }); } else { _options.AudioBrowseUrl = urlHelper.Content(_options.AudioBrowseUrl); } if (string.IsNullOrWhiteSpace(_options.DropFileUrl)) { _options.DropFileUrl = urlHelper.Action("DropFile", "FileManager"); } else { _options.DropFileUrl = urlHelper.Content(_options.DropFileUrl); } if (string.IsNullOrWhiteSpace(_options.CropFileUrl)) { _options.CropFileUrl = urlHelper.Action("CropServerImage", "FileManager"); } else { _options.CropFileUrl = urlHelper.Content(_options.CropFileUrl); } return(Task.FromResult(_options)); }
public override void Process(TagHelperContext context, TagHelperOutput output) { _urlHelper = _urlHelperFactory.GetUrlHelper(ViewContext); output.AddClass("btn"); if (Raised) { output.AddClass("pmd-btn-raised"); } if (Flat) { output.AddClass("pmd-btn-flat"); } if (Outline) { output.AddClass("pmd-btn-outline"); } if (Floating) { output.AddClass("pmd-btn-fab"); } if (IsLg) { output.AddClass("btn-lg"); } if (IsSm) { output.AddClass("btn-sm"); } if (Block) { output.AddClass("btn-block"); } if (Default) { output.AddClass("btn-default"); } if (Primary) { output.AddClass("btn-primary"); } if (Success) { output.AddClass("btn-success"); } if (Info) { output.AddClass("btn-info"); } if (Warning) { output.AddClass("btn-warning"); } if (Danger) { output.AddClass("btn-danger"); } if (Link) { output.AddClass("btn-link"); } if (!Default && !Primary && !Success && !Info && !Warning && !Danger && !Link) { output.AddClass("btn-primary"); } if (Icon != null) { output.AddClass("btn-icon"); output.PreContent.AppendHtml($"<i class=\"material-icons pmd-sm\">{Icon}</i>"); } if (Text == null) { output.AddClass("no-text"); } if (Action != null || Controller != null) { if (Type == null || (Type != null && Type == "submit")) { var url = _urlHelper.Action(Action, Controller, _routeValues); output.Attributes.SetAttribute("href", url); output.TagName = "a"; } } else if (Type != null && Type == "link") { output.TagName = "a"; } else if (OnClick != null) { output.SetAttribute("onclick", OnClick); output.TagName = "button"; } else { Type = "submit"; output.Attributes.SetAttribute("type", "submit"); output.TagName = "button"; } output.RemoveAttributes( new string[] { "raised", "flat", "outline", "floating", "lg", "sm", "block", "default", "primary", "success", "info", "warning", "danger", "link", "icon", "text" } ); output.TagMode = TagMode.StartTagAndEndTag; output.Content.SetHtmlContent(Text); }
public override void Process(TagHelperContext context, TagHelperOutput output) { output.SetNgFor(AngBind, "ng-bind") .SetNgFor(AngClass, "ng-class") .SetNgFor(AngIf, "ng-if") .SetNgFor(AngShow, "ng-show") .SetNgFor(AngHide, "ng-hide") .SetNgFor(AngIdentifierScope, "target-scope"); if (Swapable != null) { output.Attributes.SetAttribute("swapable", null); } if (SwapIndex != null) { output.Attributes.SetAttribute("Swap-index", SwapIndex); } string loadingUrl = ""; if (LoadRoute != null) { loadingUrl = urlHelperFactory.GetUrlHelper(ViewContext).Content(LoadRoute); } if (LoadKey != null) { loadingUrl += "{{" + LoadKey.GetName() + "}}"; loadingUrl = $"{LoadPrefix}{loadingUrl}{LoadSuffix}"; } if (loadingUrl != "") { output.Attributes.SetAttribute("load-url", loadingUrl); } if (LoadOnSwap != null) { output.Attributes.SetAttribute("load-on-swap", LoadOnSwap.ToString().ToLower()); } if (AngIdentifier != null) { output.Attributes.SetAttribute("listening-root-key", AngIdentifier); } //if (AngRepeatIdentifier != null) // output.Attributes.SetAttribute("listening-root-key", AngRepeatIdentifier + "{{$index}}"); if (AngRepeat != null) { string repStr = AngRepeat.GetName(); if (AngRepeatTo != null) { repStr = $"{AngRepeatTo.GetName()} in {repStr}"; } else if (repStr.EndsWith('s')) { repStr = $"{repStr.Substring(0, repStr.Length - 1)} in {repStr}"; } else { repStr = $"single in {repStr}"; } output.Attributes.SetAttribute("ng-repeat", repStr); } if (AngData != null) { string uid = Guid.NewGuid().ToString("N"); angularService.Pairs.Add(uid, AngData.Model); output.Attributes.SetAttribute("netcore-angular-set", uid); output.Attributes.SetAttribute("set-to-scope", AngData.GetName()); } else { string uid = Guid.NewGuid().ToString("N"); if (AngSource != null) { angularService.Pairs.Add(uid, AngSource); output.Attributes.SetAttribute("netcore-angular-set", uid); } if (AngScopeDest != null) { output.Attributes.SetAttribute("set-to-scope", AngScopeDest); } else if (AngDestination != null) { output.Attributes.SetAttribute("set-to-scope", AngDestination.GetName()); } } }
public override void Process(TagHelperContext context, TagHelperOutput output) { //initialize IUrlHelper, with our private IUrlHelperFactory urlInfo property IUrlHelper urlHelp = urlInfo.GetUrlHelper(ViewContext); //build a div tag TagBuilder finishedTag = new TagBuilder("div"); //build a tag for each page there is for (int i = 1; i <= NumPages; i++) { if (i >= (CurrentPage - 4) && i <= (CurrentPage + 4)) { //pagination take to beginning if (i == CurrentPage - 4) { TagBuilder endTag = new TagBuilder("a"); KeyValuePairs["pageNum"] = 1; //assign href content with routing information endTag.Attributes["href"] = urlHelp.Action(PageAction, KeyValuePairs); //endTag.Attributes["asp-route-pageNum"] = "@(ViewBag.CurrentPage - 1)"; //if we are using page classes, then assign the tag a class appropriately if (PageClassesEnabled) { endTag.AddCssClass(PageClass); //if iterating over the current page, assign the PageClassSelected styling. Otherwise, use PageClassNormal styling endTag.AddCssClass(PageClassNormal); } //append page number to tag innerhtml endTag.InnerHtml.AppendHtml("<<"); //append tag to outer div tag innerhtml finishedTag.InnerHtml.AppendHtml(endTag); } //pagination previous button ------------------ if (i == CurrentPage - 4) { TagBuilder endTag = new TagBuilder("a"); KeyValuePairs["pageNum"] = CurrentPage - 1; //assign href content with routing information endTag.Attributes["href"] = urlHelp.Action(PageAction, KeyValuePairs); //endTag.Attributes["asp-route-pageNum"] = "@(ViewBag.CurrentPage - 1)"; //if we are using page classes, then assign the tag a class appropriately if (PageClassesEnabled) { endTag.AddCssClass(PageClass); //if iterating over the current page, assign the PageClassSelected styling. Otherwise, use PageClassNormal styling endTag.AddCssClass(PageClassNormal); } //append page number to tag innerhtml endTag.InnerHtml.AppendHtml("<"); //append tag to outer div tag innerhtml finishedTag.InnerHtml.AppendHtml(endTag); } TagBuilder individualTag = new TagBuilder("a"); KeyValuePairs["pageNum"] = i; //assign href content with routing information individualTag.Attributes["href"] = urlHelp.Action(PageAction, KeyValuePairs); //if we are using page classes, then assign the tag a class appropriately if (PageClassesEnabled) { individualTag.AddCssClass(PageClass); //if iterating over the current page, assign the PageClassSelected styling. Otherwise, use PageClassNormal styling individualTag.AddCssClass(i == CurrentPage ? PageClassSelected : PageClassNormal); } //append page number to tag innerhtml individualTag.InnerHtml.AppendHtml(i.ToString()); //append tag to outer div tag innerhtml finishedTag.InnerHtml.AppendHtml(individualTag); //pagination forward button --------------- if (i == CurrentPage + 4) { if ((CurrentPage + 4) < NumPages) { TagBuilder endTag = new TagBuilder("a"); KeyValuePairs["pageNum"] = CurrentPage + 1; //assign href content with routing information endTag.Attributes["href"] = urlHelp.Action(PageAction, KeyValuePairs); //endTag.Attributes["asp-route-pageNum"] = "@(ViewBag.CurrentPage - 1)"; //if we are using page classes, then assign the tag a class appropriately if (PageClassesEnabled) { endTag.AddCssClass(PageClass); //if iterating over the current page, assign the PageClassSelected styling. Otherwise, use PageClassNormal styling endTag.AddCssClass(PageClassNormal); } //append page number to tag innerhtml endTag.InnerHtml.AppendHtml(">"); //append tag to outer div tag innerhtml finishedTag.InnerHtml.AppendHtml(endTag); } } //pagination to the end button -------------- if (i == CurrentPage + 4) { if ((CurrentPage + 4) < NumPages) { TagBuilder endTag = new TagBuilder("a"); KeyValuePairs["pageNum"] = NumPages; //assign href content with routing information endTag.Attributes["href"] = urlHelp.Action(PageAction, KeyValuePairs); //endTag.Attributes["asp-route-pageNum"] = "@(ViewBag.CurrentPage - 1)"; //if we are using page classes, then assign the tag a class appropriately if (PageClassesEnabled) { endTag.AddCssClass(PageClass); //if iterating over the current page, assign the PageClassSelected styling. Otherwise, use PageClassNormal styling endTag.AddCssClass(PageClassNormal); } //append page number to tag innerhtml endTag.InnerHtml.AppendHtml(">>"); //append tag to outer div tag innerhtml finishedTag.InnerHtml.AppendHtml(endTag); } } } } //append div's innerhtml to the page content output.Content.AppendHtml(finishedTag.InnerHtml); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (PagingInfo == null || PagingInfo.TotalPages < 2) { return; } IUrlHelper urlHelper = _urlHelperFactory.GetUrlHelper(ViewContext); var div = new TagBuilder("div"); div.Attributes["style"] = "display: flex"; // Получаем данные модели var modelState = urlHelper.ActionContext?.ModelState ?? new ModelStateDictionary(); var models = new Dictionary <string, object>(); var pagePresent = false; foreach (var(key, value) in modelState) { if (string.Compare(key, "page", StringComparison.OrdinalIgnoreCase) == 0) { pagePresent = true; continue; } models.Add(key, value.RawValue); } if (!pagePresent) { models.Add("page", string.Empty); } // Выясняем применяются ли классы стилей bool pageClassesEnabled = PageClassesEnabled(); // Генерируем стрелку <, если она активирована и допустима if (EnableArrows && PagingInfo.CurrentPage > 1) { var a = new TagBuilder("a"); models["page"] = (PagingInfo.CurrentPage - 1).ToString(); a.Attributes["href"] = urlHelper.Action(PageAction, models); a.Attributes["style"] = "font-weight: bold;"; a.InnerHtml.Append("<"); if (pageClassesEnabled) { a.AddCssClass(PageClass); a.AddCssClass(PageClassNormal); } div.InnerHtml.AppendHtml(a); } // Количество страниц в линию не может превышать общее количество страниц if (MaxPagesLine > PagingInfo.TotalPages) { MaxPagesLine = (ushort)PagingInfo.TotalPages; } // Вычисляем верхнюю и нижнюю границу int upperBound = PagingInfo.CurrentPage + MaxPagesLine - MaxPagesLine / 2 - 1; if (upperBound < MaxPagesLine) { upperBound = MaxPagesLine; } if (upperBound > PagingInfo.TotalPages) { upperBound = PagingInfo.TotalPages; } int lowerBound = upperBound - MaxPagesLine + 1; // Генерируем диапазон ссылок на страницы for (int i = lowerBound; i <= upperBound; i++) { var a = new TagBuilder("a"); models["page"] = i.ToString(); a.Attributes["href"] = urlHelper.Action(PageAction, models); if (pageClassesEnabled) { a.AddCssClass(PageClass); string currentClass = i == PagingInfo.CurrentPage ? PageClassSelected : PageClassNormal; a.AddCssClass(currentClass); } a.InnerHtml.Append(i.ToString()); div.InnerHtml.AppendHtml(a); } // Генерируем стрелку >, если она активирована и допустима if (EnableArrows && PagingInfo.CurrentPage < PagingInfo.TotalPages) { var a = new TagBuilder("a"); models["page"] = (PagingInfo.CurrentPage + 1).ToString(); a.Attributes["href"] = urlHelper.Action(PageAction, models); a.Attributes["style"] = "font-weight: bold;"; a.InnerHtml.Append(">"); if (pageClassesEnabled) { a.AddCssClass(PageClass); a.AddCssClass(PageClassNormal); } div.InnerHtml.AppendHtml(a); } // Если общее количество страниц превышает максимальное в линии, // то генерируем форму для навигации if (PagingInfo.TotalPages > MaxPagesLine) { var form = new TagBuilder("form"); form.Attributes["method"] = "get"; form.Attributes["action"] = urlHelper.Action(PageAction); // Генерируем скрытый ввод для данных модели в форме foreach (var(key, value) in models) { if (string.Compare(key, "page", StringComparison.OrdinalIgnoreCase) == 0) { continue; } if (value is IEnumerable <string> stringValues) { foreach (string stringValue in stringValues) { var hidden = new TagBuilder("input"); hidden.Attributes["type"] = "hidden"; hidden.Attributes["id"] = key; hidden.Attributes["name"] = key; hidden.Attributes["value"] = stringValue; form.InnerHtml.AppendHtml(hidden); } } else { var hidden = new TagBuilder("input"); hidden.Attributes["type"] = "hidden"; hidden.Attributes["id"] = key; hidden.Attributes["name"] = key; hidden.Attributes["value"] = value.ToString(); form.InnerHtml.AppendHtml(hidden); } } var inputGroup = new TagBuilder("div"); inputGroup.AddCssClass("input-group"); var inputGroupBtn = new TagBuilder("div"); inputGroupBtn.AddCssClass("input-group-btn"); var input = new TagBuilder("input"); input.Attributes["type"] = "number"; input.Attributes["name"] = "Page"; input.Attributes["id"] = "Page"; input.Attributes["min"] = "1"; input.Attributes["max"] = PagingInfo.TotalPages.ToString(); input.Attributes["class"] = "form-control"; input.Attributes["value"] = PagingInfo.CurrentPage.ToString(); var submit = new TagBuilder("button"); submit.Attributes["type"] = "submit"; submit.InnerHtml.Append(ButtonText); submit.AddCssClass(PageClassSelected); submit.AddCssClass(PageClass); inputGroupBtn.InnerHtml.AppendHtml(submit); inputGroup.InnerHtml.AppendHtml(input); inputGroup.InnerHtml.AppendHtml(inputGroupBtn); form.InnerHtml.AppendHtml(inputGroup); div.InnerHtml.AppendHtml(form); } output.MergeAttributes(div); output.Content.AppendHtml(div.InnerHtml); }
private IUrlHelper GetHelper(IUrlHelperFactory urlHelperFactory, IActionContextAccessor actionContextAccessor) { return(urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext)); }