1
0
mirror of https://github.com/bitwarden/server synced 2026-01-05 18:13:31 +00:00

active page status, org customer select filter

This commit is contained in:
Kyle Spearrin
2018-03-21 21:58:14 -04:00
parent 6e16581fe8
commit ab3b3c6e40
8 changed files with 136 additions and 14 deletions

View File

@@ -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());
}
}
}

View File

@@ -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");
}
}
}
}