Skip to content

Commit

Permalink
Displays list of IUsers as SummaryAdmin (#1055)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Payne authored and sebastienros committed Oct 3, 2017
1 parent e3161ea commit 270d3e0
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Localization;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Localization;
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.ModelBinding;
using OrchardCore.DisplayManagement.Notify;
using OrchardCore.Navigation;
using OrchardCore.Security;
using OrchardCore.Security.Services;
using OrchardCore.Settings;
using OrchardCore.Users.Indexes;
using OrchardCore.Users.Models;
using OrchardCore.Users.Services;
using OrchardCore.Users.ViewModels;
using YesSql;

Expand All @@ -26,35 +22,33 @@ public class AdminController : Controller, IUpdateModel
private readonly UserManager<IUser> _userManager;
private readonly ISession _session;
private readonly IAuthorizationService _authorizationService;
private readonly IHtmlLocalizer TH;
private readonly ISiteService _siteService;
private readonly dynamic New;
private readonly IDisplayManager<User> _userDisplayManager;
private readonly INotifier _notifier;

private readonly dynamic New;
private readonly IHtmlLocalizer TH;

public AdminController(
IDisplayManager<User> userDisplayManager,
IAuthorizationService authorizationService,
ISession session,
UserManager<IUser> userManager,
RoleManager<IRole> roleManager,
IRoleProvider roleProvider,
IStringLocalizer<AdminController> stringLocalizer,
IHtmlLocalizer<AdminController> htmlLocalizer,
INotifier notifier,
ISiteService siteService,
IShapeFactory shapeFactory,
INotifier notifier,
IUserService userService
IHtmlLocalizer<AdminController> htmlLocalizer
)
{
_userDisplayManager = userDisplayManager;
_notifier = notifier;
New = shapeFactory;
_siteService = siteService;
TH = htmlLocalizer;
_authorizationService = authorizationService;
_session = session;
_userManager = userManager;
_notifier = notifier;
_siteService = siteService;

New = shapeFactory;
TH = htmlLocalizer;
}
public async Task<ActionResult> Index(UserIndexOptions options, PagerParameters pagerParameters)
{
Expand Down Expand Up @@ -125,9 +119,9 @@ public async Task<ActionResult> Index(UserIndexOptions options, PagerParameters

var model = new UsersIndexViewModel
{
Users = results
.Select(x => new UserEntry { User = x })
.ToList(),
Users = await Task.WhenAll(
results.Select(async x =>
new UserEntry { Shape = await _userDisplayManager.BuildDisplayAsync(x, this, "SummaryAdmin") })),
Options = options,
Pager = pagerShape
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ public class UserDisplayDriver : DisplayDriver<User>
T = stringLocalizer;
}

public override IDisplayResult Display(User user)
{
return Combine(
Shape<SummaryAdminUserViewModel>("UserFields", model => model.User = user).Location("SummaryAdmin", "Header:1"),
Shape<SummaryAdminUserViewModel>("UserButtons", model => model.User = user).Location("SummaryAdmin", "Actions:1")
);
}

public override IDisplayResult Edit(User user)
{
return Shape<EditUserViewModel>("UserFields_Edit", async model =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
<None Update="Views\UserSaveButtons.Edit.cshtml">
<PackagePath>assets\$(PackageId)\</PackagePath>
</None>
<None Update="Views\UserButtons.cshtml">
<PackagePath>assets\$(PackageId)\</PackagePath>
</None>
<None Update="Views\UserFields.cshtml">
<PackagePath>assets\$(PackageId)\</PackagePath>
</None>
<None Update="Views\UserFields.Edit.cshtml">
<PackagePath>assets\$(PackageId)\</PackagePath>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OrchardCore.Users.ViewModels
{
public class SummaryAdminUserViewModel
{
public IUser User { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using OrchardCore.Security;
using OrchardCore.Users.Models;

namespace OrchardCore.Users.ViewModels
{
Expand All @@ -13,7 +11,7 @@ public class UsersIndexViewModel

public class UserEntry
{
public IUser User { get; set; }
public dynamic Shape { get; set; }
public bool IsChecked { get; set; }
}

Expand Down
12 changes: 2 additions & 10 deletions src/OrchardCore.Modules/OrchardCore.Users/Views/Admin/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@model UsersIndexViewModel
@using OrchardCore.Users.ViewModels;
@inject Microsoft.AspNetCore.Identity.UserManager<OrchardCore.Users.IUser> UserManager


<h1>@RenderTitleSegments(T["Users"])</h1>

Expand Down Expand Up @@ -50,14 +49,7 @@
@foreach (var entry in Model.Users)
{
<li class="list-group-item">
<div class="properties">
<div class="related">
<a asp-action="Edit" asp-route-id="@await UserManager.GetUserIdAsync(entry.User)" class="btn btn-primary btn-sm">@T["Edit"]</a>
<a asp-action="Delete" asp-route-id="@await UserManager.GetUserIdAsync(entry.User)" class="btn btn-danger btn-sm" itemprop="RemoveUrl UnsafeUrl">@T["Delete"]</a>
</div>

@await UserManager.GetUserNameAsync(entry.User)
</div>
@await DisplayAsync(entry.Shape)
</li>
}
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div class="properties">
@if (Model.Actions != null)
{
<div class="related float-right">
@await DisplayAsync(Model.Actions)
</div>
}

@if (Model.Header != null)
{
<div class="header">@await DisplayAsync(Model.Header)</div>
}

@if (Model.Meta != null)
{
<div class="metadata">
@await DisplayAsync(Model.Meta)
</div>
}
</div>

@if (Model.Content != null)
{
<div class="primary">@await DisplayAsync(Model.Content)</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@model SummaryAdminUserViewModel
@inject Microsoft.AspNetCore.Identity.UserManager<OrchardCore.Users.IUser> UserManager

<a asp-action="Edit" asp-route-id="@await UserManager.GetUserIdAsync(Model.User)" class="btn btn-primary btn-sm">@T["Edit"]</a>
<a asp-action="Delete" asp-route-id="@await UserManager.GetUserIdAsync(Model.User)" class="btn btn-danger btn-sm" itemprop="RemoveUrl UnsafeUrl">@T["Delete"]</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@model SummaryAdminUserViewModel

<h5>@Model.User.UserName</h5>

0 comments on commit 270d3e0

Please sign in to comment.