Permalink
Browse files

Gist of the 301 redirects dashboard, in all the wrong places = needs …

…paging, but more importantly search by redirect url (that will need adding to the service)
  • Loading branch information...
marcemarc committed Jun 13, 2016
1 parent 795e694 commit d701639da98e67a71ba3ad4c15ffba8253cd803e
@@ -0,0 +1,9 @@
{
"$schema": "/App_Plugins/manifestSchema.json",
"javascript":[
"~/app_plugins/redirecturldashboard/redirecturlsearch.controller.js"
],
"css" : [
]
}
@@ -0,0 +1,64 @@
angular.module("umbraco").controller("Umbraco.RedirectUrlSearch", function ($scope, $http, angularHelper, notificationsService, entityResource) {
//...todo
//paging
//search by url or url part
//search by domain
//display domain in dashboard results?
$scope.isSearch = false;
$scope.hasResults = false;
$scope.search = function () {
//do we want to search by url and by domain...
var searchTerm = $scope.searchTerm;
$http.get("backoffice/api/RedirectUrlManagement/SearchRedirectUrls/?searchTerm=" + searchTerm).then(function (response) {
var matchingItems = response.data;
$scope.isSearch = true;
$scope.StatusMessage = matchingItems.StatusMessage;
$scope.hasResults = matchingItems.HasSearchResults;
$scope.redirectUrls = matchingItems.SearchResults;
angular.forEach($scope.redirectUrls, function (item) {
$http.get("backoffice/api/RedirectUrlManagement/GetPublishedUrl/?id=" + item.ContentId).then(function (response) {
item.ContentUrl = response.data;
});
});
});
};
$scope.load = function () {
// $scope.searchTerm = "";
$scope.search();
};
$scope.removeRedirect = function (redirectToDelete) {
$http.post("backoffice/api/RedirectUrlManagement/DeleteRedirectUrl/" + redirectToDelete.Id).then(function (response) {
if (response.status == 200) {
notificationsService.success('Redirect Url Removed!', 'Redirect Url ' + redirectToDelete.Url + ' has been deleted');
// now remove from table client sides
var index = -1;
var urlArr = eval($scope.redirectUrls);
for (var i = 0; i < urlArr.length; i++) {
if (urlArr[i].Id === redirectToDelete.Id) {
index = i;
break;
}
}
if (index === -1) {
notificationsService.warning('Redirect Url Removal Error!', 'Redirect Url ' + redirectToDelete.Url + ' may have already been removed');
}
$scope.redirectUrls.splice(index, 1);
}
else {
notificationsService.warning('Redirect Url Error!','Redirect Url ' + redirectToDelete.Url + ' was not deleted');
}
});
};
$scope.load();
});
@@ -0,0 +1,28 @@
<div class="redirecturlsearch" ng-controller="Umbraco.RedirectUrlSearch">
<h2>Redirect Url Search</h2>
<p>When you move and rename pages in Umbraco, 301 permanent redirects are automatically created</p>
<p>Here is a list of the redirects</p>
<!--<div class="control-group umb-control-group">
<div class="umb-el-wrap">
<label class="control-label" for="searchTerm">
Search Url:
</label>
<div class="controls controls-row">
<input name="searchTerm" type="text" ng-model="searchTerm" no-dirty-check class="col-md-12" /> <button class="btn btn-primary" ng-click="search()">Search</button>
</div>
</div>
</div>-->
<div ng-bind="StatusMessage"></div>
<table ng-show="hasResults" class="table table-hover">
<tr><th>Original Url</th><th>Redirected To</th><th>Date Created</th><th>Remove</th></tr>
<tbody>
<tr class="redirecturls-search-result" ng-repeat="redirectUrl in redirectUrls">
<td><a href="{{redirectUrl.Url}}">{{redirectUrl.Url}}</a></td><td><a href="{{redirectUrl.ContentUrl}}">{{redirectUrl.ContentUrl}}</a> <a title="edit item" href="/umbraco/#/content/content/edit/{{redirectUrl.ContentId}}"><i class="icon icon-edit"></i></a></td><td>{{redirectUrl.CreateDateUtc | date:'medium'}}</td><td><button class="btn btn-small btn-primary" ng-click="removeRedirect(redirectUrl)">Remove</button></td>
</tr>
</tbody>
</table>
@@ -579,6 +579,8 @@
<Content Include="App_Plugins\ModelsBuilder\modelsbuilder.controller.js" />
<Content Include="App_Plugins\ModelsBuilder\modelsbuilder.htm" />
<Content Include="App_Plugins\ModelsBuilder\modelsbuilder.resource.js" />
<Content Include="App_Plugins\RedirectUrlDashboard\redirecturlsearch.controller.js" />
<Content Include="App_Plugins\RedirectUrlDashboard\redirecturlsearch.html" />
<Content Include="Config\grid.editors.config.js" />
<Content Include="Config\Lang\cs-CZ.user.xml" />
<Content Include="Config\Lang\da-DK.user.xml" />
@@ -638,6 +640,7 @@
</Content>
<Content Include="Umbraco\Install\Views\Web.config" />
<Content Include="App_Plugins\ModelsBuilder\package.manifest" />
<Content Include="App_Plugins\RedirectUrlDashboard\package.manifest" />
<None Include="Config\404handlers.Release.config">
<DependentUpon>404handlers.config</DependentUpon>
</None>
@@ -34,6 +34,11 @@
views/dashboard/developer/examinemanagement.html
</control>
</tab>
<tab caption="Redirect Url Management">
<control>
/App_Plugins/RedirectUrlDashboard/redirecturlsearch.html
</control>
</tab>
<tab caption="Xml Data Integrity Report">
<control>
views/dashboard/developer/xmldataintegrityreport.html
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using Umbraco.Core.Models;
using Umbraco.Web.WebApi;
namespace Umbraco.Web.Redirects
{
public class RedirectUrlManagementController : UmbracoAuthorizedApiController
{
//add paging
[HttpGet]
public RedirectUrlSearchResult SearchRedirectUrls(string searchTerm, int page = 0)
{
int pageSize = 20;
var searchResult = new RedirectUrlSearchResult();
var redirectUrlService = Services.RedirectUrlService;
long resultCount = 0L;
// need endpoint for search functionality
// by url, by domain ? it's the url that you want to find them by, that's what you see..
var redirects = redirectUrlService.GetAllRedirectUrls(page, 20, out resultCount);
searchResult.SearchResults = redirects;
searchResult.TotalCount = resultCount;
searchResult.CurrentPage = page;
//hmm how many results 'could there be ?
searchResult.PageCount = ((int)resultCount + pageSize - 1) / pageSize;
searchResult.HasSearchResults = resultCount > 0;
searchResult.HasExactMatch = (resultCount == 1);
return searchResult;
}
[HttpGet]
public HttpResponseMessage GetPublishedUrl(int id)
{
var publishedUrl = "#";
if (id > 0)
{
publishedUrl = Umbraco.Url(id);
}
return new HttpResponseMessage()
{
Content = new StringContent(
publishedUrl,
Encoding.UTF8,
"text/html"
)
};
}
[HttpPost]
public HttpResponseMessage DeleteRedirectUrl(int id)
{
var redirectUrlService = Services.RedirectUrlService;
// has the redirect already been deleted ?
//var redirectUrl = redirectUrlService.GetById(redirectUrl.Id);
//if (redirectUrl== null)
//{
// return new HttpResponseMessage(System.Net.HttpStatusCode.NotFound);
//}
redirectUrlService.Delete(id);
return new HttpResponseMessage(System.Net.HttpStatusCode.OK);
}
}
}
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core.Models;
namespace Umbraco.Web.Redirects
{
public class RedirectUrlSearchResult
{
public string StatusMessage { get; set; }
public IEnumerable<IRedirectUrl> SearchResults { get; set; }
public bool HasSearchResults { get; set; }
public bool HasExactMatch { get; set; }
public long TotalCount { get; set; }
public int PageCount { get; set; }
public int CurrentPage { get; set; }
}
}
@@ -359,6 +359,8 @@
<Compile Include="PropertyEditors\ValueConverters\ImageCropDataSetConverter.cs" />
<Compile Include="PropertyEditors\ValueConverters\ImageCropperValueConverter.cs" />
<Compile Include="Redirects\RedirectTrackingEventHandler.cs" />
<Compile Include="Redirects\RedirectUrlManagementController.cs" />
<Compile Include="Redirects\RedirectUrlSearchResult.cs" />
<Compile Include="RequestLifespanMessagesFactory.cs" />
<Compile Include="RouteDataExtensions.cs" />
<Compile Include="Routing\ContentFinderByRedirectUrl.cs" />

0 comments on commit d701639

Please sign in to comment.