Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make dashboards support deep linking #10283

Merged
merged 5 commits into from Jun 17, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/Umbraco.Web.UI.Client/src/views/common/dashboard.controller.js
Expand Up @@ -8,7 +8,9 @@
*
*/

function DashboardController($scope, $routeParams, dashboardResource, localizationService) {
function DashboardController($scope, $routeParams, $location, dashboardResource, localizationService) {

const DASHBOARD_QUERY_PARAM = 'dashboard';

$scope.page = {};
$scope.page.nameLocked = true;
Expand All @@ -21,10 +23,9 @@ function DashboardController($scope, $routeParams, dashboardResource, localizati

dashboardResource.getDashboard($routeParams.section).then(function(tabs){
$scope.dashboard.tabs = tabs;

// set first tab to active
if($scope.dashboard.tabs && $scope.dashboard.tabs.length > 0) {
$scope.dashboard.tabs[0].active = true;

if ($scope.dashboard.tabs && $scope.dashboard.tabs.length > 0) {
initActiveTab();
}

$scope.page.loading = false;
ronaldbarendse marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -34,9 +35,25 @@ function DashboardController($scope, $routeParams, dashboardResource, localizati
$scope.dashboard.tabs.forEach(function(tab) {
tab.active = false;
});
ronaldbarendse marked this conversation as resolved.
Show resolved Hide resolved

tab.active = true;

$location.search(DASHBOARD_QUERY_PARAM, tab.alias);
};

function initActiveTab () {
// check the query param for a dashboard alias
const dashboardAlias = $location.search()[DASHBOARD_QUERY_PARAM];
const dashboardIndex = $scope.dashboard.tabs.findIndex(tab => tab.alias === dashboardAlias);
// set the first dashboard to active if there is no query param of we can't find a matching dashboard for the alias
ronaldbarendse marked this conversation as resolved.
Show resolved Hide resolved
const activeIndex = dashboardIndex !== -1 ? dashboardIndex : 0;

const tab = $scope.dashboard.tabs[activeIndex];

tab.active = true;
$location.search(DASHBOARD_QUERY_PARAM, tab.alias);
}

}


Expand Down