From 8565130166ef427b8e5dce565b4e8f9c8304a508 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Mon, 9 Apr 2018 18:00:08 +0200 Subject: [PATCH] Allow deeplinking of domains into email view --- dashboard/src/js/index.js | 3 +++ dashboard/src/views/email.html | 2 +- dashboard/src/views/email.js | 35 ++++++++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/dashboard/src/js/index.js b/dashboard/src/js/index.js index a84046838..b262fd0e9 100644 --- a/dashboard/src/js/index.js +++ b/dashboard/src/js/index.js @@ -74,6 +74,9 @@ app.config(['$routeProvider', function ($routeProvider) { }).when('/email', { controller: 'EmailController', templateUrl: 'views/email.html?<%= revision %>' + }).when('/email/:domain', { + controller: 'EmailController', + templateUrl: 'views/email.html?<%= revision %>' }).when('/settings', { controller: 'SettingsController', templateUrl: 'views/settings.html?<%= revision %>' diff --git a/dashboard/src/views/email.html b/dashboard/src/views/email.html index b09073913..e956cc25b 100644 --- a/dashboard/src/views/email.html +++ b/dashboard/src/views/email.html @@ -231,7 +231,7 @@

Email - +

diff --git a/dashboard/src/views/email.js b/dashboard/src/views/email.js index 5d01c4931..b7226e007 100644 --- a/dashboard/src/views/email.js +++ b/dashboard/src/views/email.js @@ -474,6 +474,10 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio } } + $scope.selectDomain = function () { + $location.path('/email/' + $scope.selectedDomain.domain, false); + }; + $scope.refreshDomain = function () { $scope.refreshBusy = true; @@ -556,6 +560,8 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio }; Client.onReady(function () { + var domain = $location.path().slice('/email/'.length); + Client.getUsers(function (error, users) { if (error) return console.error('Unable to get user listing.', error); @@ -569,14 +575,39 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio if (error) return console.error('Unable to get domain listing.', error); $scope.domains = domains; - $scope.selectedDomain = $scope.domains[0]; + $scope.selectedDomain = domains.find(function (d) { return d.domain === domain; }); - $scope.refreshDomain(); + if (!$scope.selectedDomain) { + $location.path('/email/' + domains[0].domain, false); + } else { + $scope.refreshDomain(); + } $scope.ready = true; }); }); + }); + function hashChangeListener() { + if (!$scope.ready) return; + + // event listener is called from DOM not angular, need to use $apply + $scope.$apply(function () { + var domain = $location.path().slice('/email/'.length); + $scope.selectedDomain = $scope.domains.find(function (d) { return d.domain === domain; }); + + if (!$scope.selectedDomain) { + $location.path('/email/' + $scope.domains[0].domain, false); + } else { + $scope.refreshDomain(); + } + }); + } + + window.addEventListener('hashchange', hashChangeListener); + + $scope.$on('$destroy', function handler() { + window.removeEventListener('hashchange', hashChangeListener); }); // setup all the dialog focus handling