Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate ListPart search into own shape #16749

Merged
merged 16 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public override IDisplayResult Display(ListPart listPart, BuildPartDisplayContex
InitializeDisplayListPartDisplayShape(listPart, context),
InitializeDisplayListPartDetailAdminShape(listPart, context),
InitializeDisplayListPartNavigationAdminShape(listPart, context, settings),
InitializeDisplayListPartDetailAdminSearchPanelShape(),
InitializeDisplayListPartHeaderAdminShape(listPart, settings),
InitializeDisplayListPartSummaryAdmin(listPart)
);
Expand Down Expand Up @@ -134,6 +135,17 @@ private ShapeResult InitializeDisplayListPartDetailAdminShape(ListPart listPart,
}))
.Location("DetailAdmin", "Content:10");
}
private ShapeResult InitializeDisplayListPartDetailAdminSearchPanelShape()
{
return Initialize<ListPartViewModel>("ListPartDetailAdminSearchPanel", async model =>
{
var listPartFilterViewModel = new ListPartFilterViewModel();
await _updateModelAccessor.ModelUpdater.TryUpdateModelAsync(listPartFilterViewModel, Prefix);

model.ListPartFilterViewModel = listPartFilterViewModel;

}).Location("DetailAdmin", "Content:5");
}

private ShapeResult InitializeDisplayListPartDisplayShape(ListPart listPart, BuildPartDisplayContext context)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
@using OrchardCore.Contents
@using OrchardCore.Lists.ViewModels
@using System.Globalization
@using OrchardCore.Localization
@using Microsoft.AspNetCore.Authorization
@model OrchardCore.Lists.ViewModels.ListPartViewModel

@inject OrchardCore.ContentManagement.Display.IContentItemDisplayManager ContentItemDisplayManager
@inject OrchardCore.ContentManagement.IContentManager ContentManager
@inject Microsoft.AspNetCore.Authorization.IAuthorizationService AuthorizationService
@{
var enableOrdering =
Model.EnableOrdering &&
Expand All @@ -19,28 +11,7 @@
{
<script asp-src="~/OrchardCore.Lists/Scripts/ci-list-ordering.min.js" debug-src="~/OrchardCore.Lists/Scripts/ci-list-ordering.js" asp-name="ci-list-ordering" at="Foot" depends-on="Sortable, jQuery"></script>
}

var authorizedContentTypeDefinitions = new List<ContentTypeDefinition>();

foreach (var contentTypeDefinition in Model.ContainedContentTypeDefinitions)
{
if (await AuthorizationService.AuthorizeAsync(
User,
CommonPermissions.EditContent,
await ContentManager.NewAsync(contentTypeDefinition.Name)))
{
authorizedContentTypeDefinitions.Add(contentTypeDefinition);
}
}
var dropdownClassList = new List<string>()
{
"dropdown-menu"
};

if (CultureInfo.CurrentUICulture.IsRightToLeft())
{
dropdownClassList.Add("dropdown-menu-start");
}

giannik marked this conversation as resolved.
Show resolved Hide resolved
}
@if (!Model.ContainedContentTypeDefinitions.Any())
{
Expand All @@ -50,30 +21,6 @@
}
else
{
<form>
<div class="card text-bg-theme mb-3 position-sticky action-bar">
<div class="card-body">
<div class="row gx-3">
<div class="col">
<div class="input-group has-filter">
<button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" id="filter-dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa-solid fa-filter" title="@T["Filters"]" aria-hidden="true"></i>
</button>
<div class="@string.Join(' ', dropdownClassList)" aria-labelledby="filter-dropdown">
@* Latest not surfaced here to be consistent with the main content items list filter. *@
<a class="dropdown-item" href="?Status=Draft">@T["Only draft items"]</a>
<a class="dropdown-item" href="?Status=Published">@T["Only published items"]</a>
<a class="dropdown-item" href="?Status=Owner">@T["Owned by me"]</a>
</div>
<i class="fa-solid fa-search form-control-feedback" aria-hidden="true"></i>
<input name="@nameof(ListPartFilterViewModel.Status)" value="@Model.ListPartFilterViewModel.Status" class="form-control" type="hidden" />
<input name="@nameof(ListPartFilterViewModel.DisplayText)" value="@Model.ListPartFilterViewModel.DisplayText" class="form-control" placeholder="@T["Search"]" type="search" autofocus />
</div>
</div>
</div>
</div>
</div>
</form>

@if (Model.ContentItems.Any())
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@using System.Globalization
@using Microsoft.AspNetCore.Mvc.TagHelpers
@using OrchardCore.Lists.ViewModels
@using OrchardCore.Localization

@model OrchardCore.Lists.ViewModels.ListPartViewModel

giannik marked this conversation as resolved.
Show resolved Hide resolved
@{
var dropdownClassList = CultureInfo.CurrentUICulture.IsRightToLeft()
? "dropdown-menu dropdown-menu-start"
: "dropdown-menu";
Comment on lines +9 to +11
Copy link
Member

@hishamco hishamco Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just have one question before you nominate me @MikeAlhayek, this time there are 4 spaces before it's by intention or VS formatting?!!

}

<form>
<div class="card text-bg-theme mb-3 position-sticky action-bar">
<div class="card-body">
<div class="row gx-3">
<div class="col">
<div class="input-group has-filter">
<button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" id="filter-dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa-solid fa-filter" title="@T["Filters"]" aria-hidden="true"></i>
</button>
<div class="@dropdownClassList" aria-labelledby="filter-dropdown">
@* Latest not surfaced here to be consistent with the main content items list filter. *@
<a class="dropdown-item" href="?Status=Draft">@T["Only draft items"]</a>
<a class="dropdown-item" href="?Status=Published">@T["Only published items"]</a>
<a class="dropdown-item" href="?Status=Owner">@T["Owned by me"]</a>
</div>
<i class="fa-solid fa-search form-control-feedback" aria-hidden="true"></i>
<input name="@nameof(ListPartFilterViewModel.Status)" value="@Model.ListPartFilterViewModel.Status" class="form-control" type="hidden" />
<input name="@nameof(ListPartFilterViewModel.DisplayText)" value="@Model.ListPartFilterViewModel.DisplayText" class="form-control" placeholder="@T["Search"]" type="search" autofocus />
</div>
</div>
</div>
</div>
</div>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@
@using OrchardCore.ContentManagement
@using OrchardCore.Contents
@model OrchardCore.Lists.ViewModels.ListPartNavigationAdminViewModel
@inject OrchardCore.ContentManagement.IContentManager ContentManager
@inject Microsoft.AspNetCore.Authorization.IAuthorizationService AuthorizationService

@inject IContentManager ContentManager
@inject IAuthorizationService AuthorizationService
@{
var authorizedContentTypeDefinitions = new List<ContentTypeDefinition>();
foreach (var contentTypeDefinition in Model.ContainedContentTypeDefinitions)
{
if (!await AuthorizationService.AuthorizeAsync(User, CommonPermissions.EditContent, await ContentManager.NewAsync(contentTypeDefinition.Name)))
{
continue;
}

authorizedContentTypeDefinitions.Add(contentTypeDefinition);
}
}
<div class="card text-bg-theme text-right mb-3 second-action-bar">
<div class="card-body">
<div class="d-flex justify-content-end">
Expand All @@ -21,9 +32,9 @@
</a>
}

@if (Model.ContainedContentTypeDefinitions.Length == 1)
@if (authorizedContentTypeDefinitions.Count == 1)
{
var contentTypeDefinition = Model.ContainedContentTypeDefinitions[0];
var contentTypeDefinition = authorizedContentTypeDefinitions.FirstOrDefault();

if (await AuthorizationService.AuthorizeContentTypeAsync(User, CommonPermissions.EditContent, contentTypeDefinition, User.Identity.Name))
{
Expand All @@ -32,13 +43,13 @@
</a>
}
}
else if (Model.ContainedContentTypeDefinitions.Length > 1)
else if (authorizedContentTypeDefinitions.Count > 1)
{
<a class="btn btn-secondary dropdown-toggle" id="dropdownMenuLink" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
@T["New"]
</a>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuLink">
@foreach (var containedContentTypeDefinition in Model.ContainedContentTypeDefinitions)
@foreach (var containedContentTypeDefinition in authorizedContentTypeDefinitions)
{
if (!await AuthorizationService.AuthorizeContentTypeAsync(User, CommonPermissions.EditContent, containedContentTypeDefinition, User.Identity.Name))
{
Expand Down