Simplify logic in PageSelectionCtrl

This commit is contained in:
Maikel Linke
2020-03-18 09:31:28 +11:00
parent 1d42ce885b
commit 5a9b5660f1

View File

@@ -3,14 +3,14 @@ Darkswarm.controller "PageSelectionCtrl", ($scope, $location) ->
# The path looks like `/contact` for the URL `https://ofn.org/shop#/contact`.
# We remove the slash at the beginning.
page = $location.path()[1..]
if page in $scope.whitelist
$scope.lastPage = page
page
else if page
# The path points to an unrelated path like `/login`. Stay where we were.
$scope.lastPage
else
$scope.whitelist[0]
return $scope.whitelist[0] unless page
# If the path points to an unrelated path like `/login`, stay where we were.
return $scope.lastPage unless page in $scope.whitelist
$scope.lastPage = page
page
$scope.whitelistPages = (pages) ->
$scope.whitelist = pages