Skip to content

Commit

Permalink
Created some simple logic for searching within redirects (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdemooij9 authored Apr 17, 2022
1 parent d7de186 commit 86f769b
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public IActionResult Save(SaveRedirectPostModel postModel)
return Ok();
}

public IActionResult GetAll(int pageNumber, int pageSize)
public IActionResult GetAll(int pageNumber, int pageSize, string search = "")
{
var redirectsPaged = _redirectsService.GetAll(pageNumber, pageSize);
var redirectsPaged = _redirectsService.GetAll(pageNumber, pageSize, search);
var viewModels = redirectsPaged.Items.Select(it =>
{
var domain = it.Domain?.Name ?? it.CustomDomain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IRedirectsRepository
void Delete(Redirect redirect);

Redirect Get(int id);
IEnumerable<Redirect> GetAll(int pageNumber, int pageSize, out long totalRecords);
IEnumerable<Redirect> GetAll(int pageNumber, int pageSize, out long totalRecords, string search = "");
IEnumerable<Redirect> GetAllRegexRedirects();
IEnumerable<Redirect> GetByUrls(params string[] paths);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace SeoToolkit.Umbraco.Redirects.Core.Interfaces
{
public interface IRedirectsService
{
PagedResult<Redirect> GetAll(int pageNumber, int pageSize);
PagedResult<Redirect> GetAll(int pageNumber, int pageSize, string search = "");
Redirect Get(int id);
void Save(Redirect redirect);
void Delete(int[] ids);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,22 @@ public Redirect Get(int id)
}
}

public IEnumerable<Redirect> GetAll(int pageNumber, int pageSize, out long totalRecords)
public IEnumerable<Redirect> GetAll(int pageNumber, int pageSize, out long totalRecords, string search = "")
{
using (var scope = _scopeProvider.CreateScope(autoComplete: true))
{
var sql = scope.SqlContext.Sql()
.SelectAll()
.From<RedirectEntity>()
.OrderBy<RedirectEntity>(it => it.Id);
.From<RedirectEntity>();

if (!string.IsNullOrWhiteSpace(search))
{
sql = sql.Where<RedirectEntity>(it => it.OldUrl.Contains(search) ||
it.NewUrl.Contains(search) ||
it.CustomDomain.Contains(search));
}

sql = sql.OrderBy<RedirectEntity>(it => it.Id);

var result = scope.Database.Page<RedirectEntity>(pageNumber, pageSize, sql);
totalRecords = result.TotalItems;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public RedirectsService(IRedirectsRepository redirectsRepository,
_umbracoContextFactory = umbracoContextFactory;
}

public PagedResult<Redirect> GetAll(int pageNumber, int pageSize)
public PagedResult<Redirect> GetAll(int pageNumber, int pageSize, string search = "")
{
var result = _redirectsRepository.GetAll(pageNumber, pageSize, out var totalRecords);
var result = _redirectsRepository.GetAll(pageNumber, pageSize, out var totalRecords, search);
return new PagedResult<Redirect>(totalRecords, pageNumber, pageSize) { Items = result };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

vm.items = [];
vm.selection = [];
vm.searchFilter = "";

vm.options = {
filter: '',
Expand All @@ -32,6 +33,8 @@
vm.changePage = changePage;
vm.goToPage = goToPage;

vm.search = search;

vm.create = openRedirectDialog;
vm.deleteSelection = deleteSelection;

Expand Down Expand Up @@ -88,6 +91,10 @@
loadItems();
}

function search() {
loadItems();
}

function openRedirectDialog(model) {
var redirectDialogOptions = {
title: "Create redirect",
Expand Down Expand Up @@ -190,7 +197,7 @@

function loadItems() {
vm.loading = true;
$http.get("backoffice/SeoToolkit/Redirects/GetAll?pageNumber=" + vm.pageNumber + "&pageSize=" + vm.pageSize).then(function (response) {
$http.get("backoffice/SeoToolkit/Redirects/GetAll?pageNumber=" + vm.pageNumber + "&pageSize=" + vm.pageSize + "&search=" + vm.searchFilter).then(function (response) {

vm.totalPages = response.data.totalPages;
setItems(response.data.items);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<div ng-controller="SeoToolkit.Redirects.ListController as vm">

<umb-load-indicator ng-if="vm.loading"></umb-load-indicator>

<div class="umb-dashboard umb-scrollable row-fluid" ng-if="!vm.loading">
<div class="umb-dashboard umb-scrollable row-fluid">
<div class="umb-dashboard__content">

<umb-editor-sub-header ng-class="{'--state-selection':(vm.selection.length > 0)}">
Expand All @@ -21,7 +19,12 @@
label-key="buttons_clearSelection"
action="vm.clearSelection()">Clear Selection</umb-button>
</umb-editor-sub-header-content-left>

<umb-editor-sub-header-content-right ng-if="vm.selection.length == 0">
<umb-mini-search model="vm.searchFilter" on-search="vm.search()">

</umb-mini-search>
</umb-editor-sub-header-content-right>
<umb-editor-sub-header-content-right ng-if="vm.selection.length > 0">
<umb-button type="button"
button-style="white"
Expand All @@ -31,28 +34,33 @@
action="vm.deleteSelection()">Delete</umb-button>
</umb-editor-sub-header-content-right>
</umb-editor-sub-header>

<umb-table class="redirects-table"
items="vm.items"
item-properties="vm.options.includeProperties"
allow-select-all="vm.options.bulkActionsAllowed"
on-select="vm.selectItem(item, $index, $event)"
on-click="vm.clickItem(item)"
on-select-all="vm.selectAll($event)"
on-selected-all="vm.isSelectedAll()"
on-sorting-direction="vm.isSortDirection(col, direction)"
on-sort="vm.sort(field, allow, isSystem)">
</umb-table>

<div class="flex justify-center">
<umb-pagination page-number="vm.pageNumber"
total-pages="vm.totalPages"
on-next="vm.nextPage"
on-prev="vm.prevPage"
on-change="vm.changePage"
on-go-to-page="vm.goToPage">
</umb-pagination>
<umb-load-indicator ng-if="vm.loading"></umb-load-indicator>

<div ng-if="!vm.loading">
<umb-table class="redirects-table"
items="vm.items"
item-properties="vm.options.includeProperties"
allow-select-all="vm.options.bulkActionsAllowed"
on-select="vm.selectItem(item, $index, $event)"
on-click="vm.clickItem(item)"
on-select-all="vm.selectAll($event)"
on-selected-all="vm.isSelectedAll()"
on-sorting-direction="vm.isSortDirection(col, direction)"
on-sort="vm.sort(field, allow, isSystem)">
</umb-table>

<div class="flex justify-center">
<umb-pagination page-number="vm.pageNumber"
total-pages="vm.totalPages"
on-next="vm.nextPage"
on-prev="vm.prevPage"
on-change="vm.changePage"
on-go-to-page="vm.goToPage">
</umb-pagination>
</div>
</div>

</div>
</div>
</div>

0 comments on commit 86f769b

Please sign in to comment.