diff --git a/src/Admin/Controllers/OrganizationsController.cs b/src/Admin/Controllers/OrganizationsController.cs index ea0b38f13..68e923724 100644 --- a/src/Admin/Controllers/OrganizationsController.cs +++ b/src/Admin/Controllers/OrganizationsController.cs @@ -19,7 +19,7 @@ namespace Bit.Admin.Controllers _organizationRepository = organizationRepository; } - public async Task Index(string name = null, string userEmail = null, bool paid = false, + public async Task Index(string name = null, string userEmail = null, bool? paid = null, int page = 1, int count = 25) { if(page < 1) @@ -33,8 +33,7 @@ namespace Bit.Admin.Controllers } var skip = (page - 1) * count; - var organizations = await _organizationRepository.SearchAsync(name, userEmail, paid ? (bool?)true : null, - skip, count); + var organizations = await _organizationRepository.SearchAsync(name, userEmail, paid, skip, count); return View(new OrganizationsModel { Items = organizations as List, diff --git a/src/Admin/Models/OrganizationsModel.cs b/src/Admin/Models/OrganizationsModel.cs index f03a065b2..a5d9dc241 100644 --- a/src/Admin/Models/OrganizationsModel.cs +++ b/src/Admin/Models/OrganizationsModel.cs @@ -6,6 +6,6 @@ namespace Bit.Admin.Models { public string Name { get; set; } public string UserEmail { get; set; } - public bool Paid { get; set; } + public bool? Paid { get; set; } } } diff --git a/src/Admin/TagHelpers/ActivePageTagHelper.cs b/src/Admin/TagHelpers/ActivePageTagHelper.cs new file mode 100644 index 000000000..9ba30ab1f --- /dev/null +++ b/src/Admin/TagHelpers/ActivePageTagHelper.cs @@ -0,0 +1,76 @@ +using System; +using System.Linq; +using Microsoft.AspNetCore.Mvc.Controllers; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.ViewFeatures; +using Microsoft.AspNetCore.Razor.TagHelpers; + +namespace Bit.Billing.TagHelpers +{ + [HtmlTargetElement("li", Attributes = ActiveControllerName)] + [HtmlTargetElement("li", Attributes = ActiveActionName)] + public class ActivePageTagHelper : TagHelper + { + private const string ActiveControllerName = "active-controller"; + private const string ActiveActionName = "active-action"; + + private readonly IHtmlGenerator _generator; + + public ActivePageTagHelper(IHtmlGenerator generator) + { + _generator = generator; + } + + [HtmlAttributeNotBound] + [ViewContext] + public ViewContext ViewContext { get; set; } + [HtmlAttributeName(ActiveControllerName)] + public string ActiveController { get; set; } + [HtmlAttributeName(ActiveActionName)] + public string ActiveAction { get; set; } + + public override void Process(TagHelperContext context, TagHelperOutput output) + { + if(context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if(output == null) + { + throw new ArgumentNullException(nameof(output)); + } + + if(ActiveAction == null && ActiveController == null) + { + return; + } + + var descriptor = ViewContext.ActionDescriptor as ControllerActionDescriptor; + if(descriptor == null) + { + return; + } + + var controllerMatch = ActiveMatch(ActiveController, descriptor.ControllerName); + var actionMatch = ActiveMatch(ActiveAction, descriptor.ActionName); + if(controllerMatch && actionMatch) + { + var classValue = "active"; + if(output.Attributes["class"] != null) + { + classValue += " " + output.Attributes["class"].Value; + output.Attributes.Remove(output.Attributes["class"]); + } + + output.Attributes.Add("class", classValue); + } + } + + private bool ActiveMatch(string route, string descriptor) + { + return route == null || route == "*" || + route.Split(',').Any(c => c.Trim().ToLower() == descriptor.ToLower()); + } + } +} diff --git a/src/Admin/TagHelpers/OptionsSelectedTagHelper.cs b/src/Admin/TagHelpers/OptionsSelectedTagHelper.cs new file mode 100644 index 000000000..ca28a942c --- /dev/null +++ b/src/Admin/TagHelpers/OptionsSelectedTagHelper.cs @@ -0,0 +1,44 @@ +using System; +using Microsoft.AspNetCore.Mvc.ViewFeatures; +using Microsoft.AspNetCore.Razor.TagHelpers; + +namespace Bit.Billing.TagHelpers +{ + [HtmlTargetElement("option", Attributes = SelectedName)] + public class OptionSelectedTagHelper : TagHelper + { + private const string SelectedName = "asp-selected"; + + private readonly IHtmlGenerator _generator; + + public OptionSelectedTagHelper(IHtmlGenerator generator) + { + _generator = generator; + } + + [HtmlAttributeName(SelectedName)] + public bool Selected { get; set; } + + public override void Process(TagHelperContext context, TagHelperOutput output) + { + if(context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if(output == null) + { + throw new ArgumentNullException(nameof(output)); + } + + if(Selected) + { + output.Attributes.Add("selected", "selected"); + } + else + { + output.Attributes.RemoveAll("selected"); + } + } + } +} diff --git a/src/Admin/Views/Organizations/Index.cshtml b/src/Admin/Views/Organizations/Index.cshtml index 56b03bece..b10c84d52 100644 --- a/src/Admin/Views/Organizations/Index.cshtml +++ b/src/Admin/Views/Organizations/Index.cshtml @@ -5,15 +5,17 @@

Organizations

-
+ -
- - -
+ +
diff --git a/src/Admin/Views/Shared/_Layout.cshtml b/src/Admin/Views/Shared/_Layout.cshtml index a113e3726..7d668d9e4 100644 --- a/src/Admin/Views/Shared/_Layout.cshtml +++ b/src/Admin/Views/Shared/_Layout.cshtml @@ -27,13 +27,13 @@