1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-26 12:55:17 +01: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

@ -19,7 +19,7 @@ namespace Bit.Admin.Controllers
_organizationRepository = organizationRepository;
}
public async Task<IActionResult> Index(string name = null, string userEmail = null, bool paid = false,
public async Task<IActionResult> 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<Organization>,

View File

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

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

View File

@ -5,15 +5,17 @@
<h1>Organizations</h1>
<form class="form-inline mb-3" method="get">
<form class="form-inline mb-2" method="get">
<label class="sr-only" asp-for="Name">Name</label>
<input type="text" class="form-control mb-2 mr-2" placeholder="Name" asp-for="Name" name="name">
<label class="sr-only" asp-for="UserEmail">User email</label>
<input type="text" class="form-control mb-2 mr-2" placeholder="User email" asp-for="UserEmail" name="userEmail">
<div class="form-check mr-2 mb-2">
<input class="form-check-input" type="checkbox" asp-for="Paid" name="paid">
<label class="form-check-label" asp-for="Paid">Paid</label>
</div>
<label class="sr-only" asp-for="Paid">Customer</label>
<select class="form-control mb-2 mr-2" asp-for="Paid" name="paid">
<option asp-selected="!Model.Paid.HasValue" value="">-- Customer --</option>
<option asp-selected="Model.Paid.GetValueOrDefault(false)" value="true">Paid</option>
<option asp-selected="!Model.Paid.GetValueOrDefault(true)" value="false">Freeloader</option>
</select>
<button type="submit" class="btn btn-primary mb-2" title="Search"><i class="fa fa-search"></i> Search</button>
</form>

View File

@ -27,13 +27,13 @@
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" asp-controller="Home">Home <span class="sr-only">(current)</span></a>
<li class="nav-item" active-controller="Home">
<a class="nav-link" asp-controller="Home">Home</a>
</li>
<li class="nav-item">
<li class="nav-item" active-controller="Users">
<a class="nav-link" asp-controller="Users">Users</a>
</li>
<li class="nav-item">
<li class="nav-item" active-controller="Organizations">
<a class="nav-link" asp-controller="Organizations">Organizations</a>
</li>
</ul>

View File

@ -5,7 +5,7 @@
<h1>Users</h1>
<form class="form-inline mb-3" method="get">
<form class="form-inline mb-2" method="get">
<label class="sr-only" asp-for="Email">Email</label>
<input type="text" class="form-control mb-2 mr-2" placeholder="Email" asp-for="Email" name="email">
<button type="submit" class="btn btn-primary mb-2" title="Search"><i class="fa fa-search"></i> Search</button>

View File

@ -1,3 +1,4 @@
@using Bit.Admin
@using Bit.Admin.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper "*, Admin"