Merge pull request #2287 from PerplexDaniel/U4-6985

Switching between sections - select last node
This commit is contained in:
Sebastiaan Janssen
2017-11-07 20:26:25 +01:00
committed by GitHub
2 changed files with 26 additions and 3 deletions

View File

@@ -3,7 +3,7 @@
* @name umbraco.directives.directive:umbSections
* @restrict E
**/
function sectionsDirective($timeout, $window, navigationService, treeService, sectionService, appState, eventsService, $location) {
function sectionsDirective($timeout, $window, navigationService, treeService, sectionService, appState, eventsService, $location, historyService) {
return {
restrict: "E", // restrict to an element
replace: true, // replace the html element with the template
@@ -161,7 +161,9 @@ function sectionsDirective($timeout, $window, navigationService, treeService, se
$location.path(section.routePath);
}
else {
$location.path(section.alias).search('');
var lastAccessed = historyService.getLastAccessedItemForSection(section.alias);
var path = lastAccessed != null ? lastAccessed.link : section.alias;
$location.path(path).search('');
}
};

View File

@@ -115,6 +115,27 @@ angular.module('umbraco.services')
*/
getCurrent: function(){
return nArray;
}
},
/**
* @ngdoc method
* @name umbraco.services.historyService#getLastAccessedItemForSection
* @methodOf umbraco.services.historyService
*
* @description
* Method to return the item that was last accessed in the given section
*
* @param {string} sectionAlias Alias of the section to return the last accessed item for.
*/
getLastAccessedItemForSection: function (sectionAlias) {
for (var i = 0, len = nArray.length; i < len; i++) {
var item = nArray[i];
if (item.link.indexOf(sectionAlias + "/") === 0) {
return item;
}
}
return null;
}
};
});