diff --git a/src/js/index.js b/src/js/index.js index d4fdb19db..63b2dccf8 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -110,7 +110,7 @@ app.config(['$routeProvider', function ($routeProvider) { }).when('/users', { controller: 'UsersController', templateUrl: 'views/users.html?<%= revision %>' - }).when('/app/:appId', { + }).when('/app/:appId/:view?', { controller: 'AppController', templateUrl: 'views/app.html?<%= revision %>' }).when('/appstore', { diff --git a/src/views/app.js b/src/views/app.js index b675c9880..b65834d01 100644 --- a/src/views/app.js +++ b/src/views/app.js @@ -34,12 +34,23 @@ // }); // }; -angular.module('Application').controller('AppController', ['$scope', '$location', '$timeout', '$interval', 'Client', function ($scope, $location, $timeout, $interval, Client) { +angular.module('Application').controller('AppController', ['$scope', '$location', '$timeout', '$interval', '$route', '$routeParams', 'Client', function ($scope, $location, $timeout, $interval, $route, $routeParams, Client) { Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); }); - var appId = $location.path().slice('/app/'.length); + // Avoid full reload on path change + // https://stackoverflow.com/a/22614334 + // reloadOnUrl: false in $routeProvider did not work! + var lastRoute = $route.current; + $scope.$on('$locationChangeSuccess', function (/* event */) { + if (lastRoute.$$route.originalPath === $route.current.$$route.originalPath) { + $route.current = lastRoute; + } + }); - $scope.view = 'display'; + var appId = $routeParams.appId; + if (!appId) return $location.path('/apps'); + + $scope.view = ''; $scope.app = null; $scope.activeTask = null; $scope.appIsRestarting = false; @@ -57,6 +68,7 @@ angular.module('Application').controller('AppController', ['$scope', '$location' $scope.setView = function (view) { if ($scope.view === view) return; + $route.updateParams({ view: view }); $scope[view].show(); $scope.view = view; }; @@ -737,6 +749,8 @@ angular.module('Application').controller('AppController', ['$scope', '$location' $scope.app = app; + $scope.setView($routeParams.view || 'display'); + asyncSeries([ fetchUsers, fetchGroups,