Skip to content

Commit

Permalink
Added support for selecting root node for each redirect
Browse files Browse the repository at this point in the history
+ Updated Angular service
+ Updated dashboard and property editor
+ Migration for adding new column to the database table
+ etc.
  • Loading branch information
abjerner committed Mar 23, 2017
1 parent fd8427c commit 0e14523
Show file tree
Hide file tree
Showing 24 changed files with 503 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<key alias="content">Indhold</key>
<key alias="media">Medie</key>
<key alias="url">URL</key>
<key alias="site">Site</key>
<key alias="siteDescription">Vælg det site (eller rodnode) som redirectet skal gælde for. Vælges det ikke noget site, vil redirectet virke for alle domæner/sites i Umbraco-løsningen.</key>
<key alias="allSites">Alle sites</key>
<key alias="originalUrl">Oprindelig URL</key>
<key alias="destination">Destination</key>
<key alias="selectDestination">Vælg destination</key>
Expand All @@ -29,5 +32,9 @@
<key alias="pagination">Viser %0%-%1% af %2% – Side %3% af %4%</key>
<key alias="urlNotValid"><![CDATA[Den angivne URL er ikke gyldig. En gyldig URL bør fx se ud som <code>/side</code> eller <code>/underside</code>.]]></key>
<key alias="addNewRedirectSubTitle">Udfyld nedenstående felter for at tilføje et nyt redirect.</key>
<key alias="media_all">Alle typer</key>
<key alias="media_content">Indhold</key>
<key alias="media_media">Medier</key>
<key alias="media_url">URLs</key>
</area>
</language>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<key alias="content">Content</key>
<key alias="media">Media</key>
<key alias="url">URL</key>
<key alias="site">Site</key>
<key alias="siteDescription">Select the site (or root node) the redirect should apply to. If a site is not selected, the redirect will apply to all domains/sites in the Umbraco solution.</key>
<key alias="allSites">All sites</key>
<key alias="originalUrl">Original URL</key>
<key alias="destination">Destination</key>
<key alias="selectDestination">Select destination</key>
Expand All @@ -29,5 +32,9 @@
<key alias="pagination">Showing %0%-%1% of %2% - Page %3% of %4%</key>
<key alias="urlNotValid"><![CDATA[The specified URL is not valid. A valid URL should look like <code>/page</code> or <code>/page/subpage</code>.]]></key>
<key alias="addNewRedirectSubTitle">Fill out the fields below to add a new redirect.</key>
<key alias="media_all">All types</key>
<key alias="media_content">Content</key>
<key alias="media_media">Media</key>
<key alias="media_url">URLs</key>
</area>
</language>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<key alias="content">Content</key>
<key alias="media">Media</key>
<key alias="url">URL</key>
<key alias="site">Site</key>
<key alias="allSites">All sites</key>
<key alias="originalUrl">Original URL</key>
<key alias="destination">Destination</key>
<key alias="selectDestination">Select destination</key>
Expand All @@ -29,5 +31,9 @@
<key alias="pagination">Showing %0%-%1% of %2% - Page %3% of %4%</key>
<key alias="urlNotValid"><![CDATA[The specified URL is not valid. A valid URL should look like <code>/page</code> or <code>/page/subpage</code>.]]></key>
<key alias="addNewRedirectSubTitle">Fill out the fields below to add a new redirect.</key>
<key alias="media_all">All types</key>
<key alias="media_content">Content</key>
<key alias="media_media">Media</key>
<key alias="media_url">URLs</key>
</area>
</language>
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
angular.module('umbraco').controller('SkybrudUmbracoRedirects.AddRedirectDialog.Controller', function ($scope, $http, notificationsService, skybrudRedirectsService) {

$scope.options = $scope.dialogOptions.options;
$scope.options = $scope.dialogOptions.options || {};

$scope.type = $scope.options && $scope.options.media ? 'media' : 'content';
$scope.content = $scope.options && $scope.options.content;
$scope.media = $scope.options && $scope.options.media;
$scope.type = $scope.options.media ? 'media' : 'content';
$scope.content = $scope.options.content;
$scope.media = $scope.options.media;

$scope.hideRootNodeOption = $scope.options.hideRootNodeOption === '1' || $scope.options.hideRootNodeOption === true;

$scope.redirect = {
rootNodeId: 0,
url: '',
link: null
};

$scope.rootNodes = [
{ id: 0, name: 'All sites' }
];

$scope.rootNode = $scope.rootNodes[0];

if ($scope.content) {
$scope.redirect.link = {
Expand All @@ -21,7 +29,7 @@
}
} else if ($scope.media) {

// $scope.media doesn't expode the URL directly, so we need to read it from the "_umb_urls" property
// $scope.media doesn't expose the URL directly, so we need to read it from the "_umb_urls" property
var mediaUrl = null;
angular.forEach($scope.media.tabs, function (tab) {
angular.forEach(tab.properties, function (property) {
Expand All @@ -40,6 +48,10 @@

}

$scope.rootNodeChanged = function() {
$scope.redirect.rootNodeId = $scope.rootNode.id;
};

$scope.addLink = function () {
skybrudRedirectsService.addLink(function (link) {
$scope.redirect.link = link;
Expand Down Expand Up @@ -76,6 +88,7 @@
}

var params = {
rootNodeId: $scope.redirect.rootNodeId,
url: $scope.redirect.url,
linkMode: $scope.type,
linkId: $scope.redirect.link.id,
Expand All @@ -100,4 +113,17 @@

};

skybrudRedirectsService.getRootNodes().success(function (r) {
angular.forEach(r.data, function (rootNode) {
$scope.rootNodes.push(rootNode);

// If a property editor for content, the current root node (if present) should be pre-selected
if ($scope.content && (',' + $scope.content.path + ',').indexOf(',' + rootNode.id + ',') > 0) {
$scope.rootNode = rootNode;
$scope.rootNodeChanged();
}

});
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
$scope.redirects = [];
$scope.mode = 'list';

$scope.rootNodes = [
{ name: 'All sites', value: '' }
];

localizationService.localize('redirects_allSites').then(function (value) {
$scope.rootNodes[0].name = value;
});

$scope.types = [
{ name: 'All types', value: 'all' },
Expand All @@ -11,7 +18,14 @@
{ name: 'URL', value: 'url' }
];

angular.forEach($scope.types, function (type) {
localizationService.localize('redirects_media_' + type.value).then(function (value) {
type.name = value;
});
});

$scope.filters = {
rootNode: $scope.rootNodes[0],
type: $scope.types[0],
text: ''
};
Expand Down Expand Up @@ -50,7 +64,7 @@
text: '',
page: 1,
pages: 0,
limit: 10,
limit: 11,
offset: 0,
pagination: []
};
Expand Down Expand Up @@ -81,6 +95,12 @@

$scope.activeFilters = 0;

// Any filters?
if ($scope.filters.rootNode && $scope.filters.rootNode.id > 0) {
args.rootNodeId = $scope.filters.rootNode.id;
$scope.activeFilters++;
}

// Any filters?
if ($scope.filters.type.value != 'all') {
args.type = $scope.filters.type.value;
Expand Down Expand Up @@ -141,6 +161,12 @@

};

skybrudRedirectsService.getRootNodes().success(function (r) {
angular.forEach(r.data, function (rootNode) {
$scope.rootNodes.push(rootNode);
});
});

$scope.updateList();

$scope.$watch('filters', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,27 @@

$scope.loading = false;

$scope.options = $scope.dialogOptions.options || {};

// Make a copy of the redirect so we don't modify the object used in the list
$scope.redirect = angular.copy($scope.dialogOptions.redirect);





$scope.hideRootNodeOption = $scope.options.hideRootNodeOption === '1' || $scope.options.hideRootNodeOption === true;

$scope.rootNodes = [
{ id: 0, name: 'All sites' }
];

$scope.rootNode = $scope.rootNodes[0];

$scope.rootNodeChanged = function () {
$scope.redirect.rootNodeId = $scope.rootNode.id;
};

$scope.addLink = function () {
skybrudRedirectsService.addLink(function (link) {
$scope.redirect.link = link;
Expand Down Expand Up @@ -66,4 +84,17 @@

};

skybrudRedirectsService.getRootNodes().success(function (r) {
angular.forEach(r.data, function (rootNode) {
$scope.rootNodes.push(rootNode);

// If a property editor for content, the current root node (if present) should be pre-selected
if ($scope.redirect.rootNodeId == rootNode.id) {
$scope.rootNode = rootNode;
$scope.rootNodeChanged();
}

});
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@
// If we're neither in the content or media section, we stop further execution (eg. property editor preview)
if ($scope.type != 'content' && $scope.type != 'media') return;

console.log($scope.model.config);

$scope.addRedirect = function () {
if ($scope.type == 'content') {
skybrudRedirectsService.addRedirect({
content: $scope.$parent.$parent.$parent.content,
hideRootNodeOption: $scope.model.config.hideRootNodeOption,
callback: function () {
$scope.updateList();
}
});
} else if ($scope.type == 'media') {
skybrudRedirectsService.addRedirect({
hideRootNodeOption: $scope.model.config.hideRootNodeOption,
media: $scope.$parent.$parent.$parent.content,
callback: function () {
$scope.updateList();
Expand All @@ -30,8 +34,11 @@
};

$scope.editRedirect = function (redirect) {
skybrudRedirectsService.editRedirect(redirect, function () {
$scope.updateList();
skybrudRedirectsService.editRedirect(redirect, {
hideRootNodeOption: $scope.model.config.hideRootNodeOption,
callback: function () {
$scope.updateList();
}
});
};

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

};

service.getRootNodes = function() {
return $http.get('/umbraco/backoffice/api/Redirects/GetRootNodes');
};

return service;

});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ <h3><localize key="redirects_redirects">Redirects</localize></h3>


<div style="margin-bottom: 20px; display: flex;">
<select style="margin-right: 10px;" ng-options="item as item.name for item in rootNodes" ng-model="filters.rootNode"></select>
<select style="margin-right: 10px;" ng-options="item as item.name for item in types track by item.value" ng-model="filters.type"></select>
<input type="text" ng-model="filters.text" placeholder="Type to search..." style="max-width: initial; flex: 1; margin-right: 100px;" />
<a href="#" prevent-default ng-click="addRedirect()" class="umb-era-button umb-button--s">
Expand All @@ -23,6 +24,7 @@ <h3><localize key="redirects_redirects">Redirects</localize></h3>
<div class="umb-table-row">
<div class="umb-table-cell"></div>
<div class="umb-table-cell col-id"><localize key="redirects_id">ID</localize></div>
<div class="umb-table-cell"><localize key="redirects_site">Site</localize></div>
<div class="umb-table-cell"><localize key="redirects_originalUrl">Original URL</localize></div>
<div class="umb-table-cell col-destination"><localize key="redirects_destination">Destination</localize></div>
<div class="umb-table-cell col-date"><localize key="redirects_created">Created</localize></div>
Expand All @@ -42,7 +44,17 @@ <h3><localize key="redirects_redirects">Redirects</localize></h3>
<i class="umb-table-body__icon umb-table-body__fileicon icon-shuffle"></i>
</div>
<div class="umb-table-cell col-id">{{redirect.id}}</div>
<div class="umb-table-cell"><a href="{{redirect.url}}{{redirect.queryString ? '?' + redirect.queryString : ''}}" rel="noopener noreferrer" target="_blank" target="_blank">{{redirect.url}}{{redirect.queryString ? '?' + redirect.queryString : ''}}</a></div>

<div class="umb-table-cell">
<span ng-show="redirect.rootNodeId">
<a href="http://umbraco75.omgbacon.dk/umbraco/#/content/content/edit/{{redirect.rootNodeId}}">{{redirect.rootNodeName}}</a>
</span>
<span ng-hide="redirect.rootNodeId">All sites</span>
</div>

<div class="umb-table-cell">
<a href="{{redirect.urls[0]}}" rel="noopener noreferrer" target="_blank" target="_blank">{{redirect.url}}{{redirect.queryString ? '?' + redirect.queryString : ''}}</a>
</div>
<div class="umb-table-cell col-destination">
<span ng-if="redirect.link.mode == 'content'">
<localize key="redirects_content">Content</localize>: <a href="{{redirect.link.url}}" rel="noopener noreferrer" target="_blank">{{redirect.link.name ? redirect.link.name : redirect.link.url}}</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ <h4 class="umb-overlay__title">
</div>

<div class="umb-overlay-container">
<label ng-hide="hideRootNodeOption">
<strong><localize key="redirects_site">Site</localize></strong>
<small><localize key="redirects_siteDescription"></localize></small>
<select ng-options="item as item.name for item in rootNodes track by item.id" ng-model="rootNode" ng-change="rootNodeChanged()"></select>
</label>
<label>
<strong><localize key="redirects_originalUrl">Original URL</localize></strong>
<small>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ <h4 class="umb-overlay__title">
</div>

<div class="umb-overlay-container">
<label ng-hide="hideRootNodeOption">
<strong>Site</strong>
<small>Vælg det site (eller rodnode) som redirectet skal gælde for. Vælges det ikke noget site, vil redirectet virke for alle domæner/sites i Umbraco-løsningen.</small>
<select ng-options="item as item.name for item in rootNodes track by item.id" ng-model="rootNode" ng-change="rootNodeChanged()"></select>
</label>
<label>
<strong><localize key="redirects_originalUrl">Original URL</localize></strong>
<small>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ <h3><localize key="redirects_redirects">Redirects</localize></h3>
<i class="umb-table-body__icon umb-table-body__fileicon icon-shuffle"></i>
</div>
<div class="umb-table-cell col-id">{{redirect.id}}</div>
<div class="umb-table-cell"><a href="{{redirect.url}}{{redirect.queryString ? '?' + redirect.queryString : ''}}" rel="noopener noreferrer" target="_blank" target="_blank">{{redirect.url}}{{redirect.queryString ? '?' + redirect.queryString : ''}}</a></div>
<div class="umb-table-cell">
<a href="{{redirect.urls[0]}}" rel="noopener noreferrer" target="_blank" target="_blank">{{redirect.url}}{{redirect.queryString ? '?' + redirect.queryString : ''}}</a>
</div>
<div class="umb-table-cell col-destination">
<span ng-if="redirect.link.mode == 'content'">
<localize key="redirects_content">Content</localize>: <a href="{{redirect.link.url}}" rel="noopener noreferrer" target="_blank">{{redirect.link.name ? redirect.link.name : redirect.link.url}}</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@
"name": "Skybrud Redirects",
"editor": {
"view": "~/App_Plugins/Skybrud.Umbraco.Redirects/Views/PropertyEditor.html?v=0.2.4",
"hideLabel": true
"hideLabel": true
},
"prevalues": {
"fields": [
{
"label": "Hide site option",
"description": "Specify the option to select a site should be hidden when creating or editing a redirect from the property editor.",
"key": "hideRootNodeOption",
"view": "boolean"
}
]
}
}
],
Expand Down
Loading

0 comments on commit 0e14523

Please sign in to comment.