|
17 | 17 | # |
18 | 18 | # Home controller. |
19 | 19 | # |
20 | | -cyclotronApp.controller 'DashboardController', ($scope, $stateParams, $location, $timeout, $window, $q, $uibModal, analyticsService, configService, cyclotronDataService, dashboardService, dataService, loadService, logService, parameterService, userService) -> |
| 20 | +cyclotronApp.controller 'DashboardController', ($scope, $stateParams, $localForage, $location, $timeout, $window, $q, $uibModal, analyticsService, configService, cyclotronDataService, dashboardService, dataService, loadService, logService, parameterService, userService) -> |
21 | 21 |
|
22 | 22 | preloadTimer = null |
23 | 23 | rotateTimer = null |
@@ -101,6 +101,9 @@ cyclotronApp.controller 'DashboardController', ($scope, $stateParams, $location, |
101 | 101 |
|
102 | 102 | $scope.updateUrl() |
103 | 103 |
|
| 104 | + $window.Cyclotron.currentPage = |
| 105 | + widgets: {} |
| 106 | + |
104 | 107 | # Track analytics |
105 | 108 | analyticsService.recordPageView $scope.dashboardWrapper, $scope.currentPageIndex, $scope.firstLoad |
106 | 109 |
|
@@ -285,18 +288,32 @@ cyclotronApp.controller 'DashboardController', ($scope, $stateParams, $location, |
285 | 288 | dashboardService.setDashboardDefaults(dashboard) |
286 | 289 | $scope.dashboard = dashboard |
287 | 290 |
|
| 291 | + # Initialize dashboard overrides |
| 292 | + $scope.dashboardOverrides.pages ?= [] |
| 293 | + _.each dashboard.pages, (page, index) -> |
| 294 | + if !$scope.dashboardOverrides.pages[index]? |
| 295 | + $scope.dashboardOverrides.pages.push { widgets: [] } |
| 296 | + $scope.dashboardOverrides.pages[index].widgets ?= [] |
| 297 | + _.each page.widgets, (widget, widgetIndex) -> |
| 298 | + if !$scope.dashboardOverrides.pages[index].widgets[widgetIndex]? |
| 299 | + $scope.dashboardOverrides.pages[index].widgets.push {} |
| 300 | + |
288 | 301 | # Optionally disable analytics |
289 | 302 | if dashboard.disableAnalytics == true |
290 | 303 | configService.enableAnalytics = false |
291 | 304 |
|
292 | 305 | dependenciesLoaded = -> |
293 | | - # Update current page if needed |
294 | | - if $scope.currentPage? |
| 306 | + # Check if a new revision of the Dashboard has been loaded |
| 307 | + if $scope.latestRevision and $scope.latestRevision < $scope.dashboardWrapper.rev |
| 308 | + # Update current page if needed |
295 | 309 | originalPage = $scope.currentPage[$scope.currentPage.length-1] |
296 | 310 | newPage = $scope.dashboard.pages[$scope.currentPageIndex] |
297 | 311 | if !angular.equals(originalPage, newPage) |
| 312 | + logService.debug 'Replacing the current page with a new revision' |
298 | 313 | $scope.currentPage[$scope.currentPage.length-1] = newPage |
299 | 314 |
|
| 315 | + $scope.latestRevision = $scope.dashboardWrapper.rev |
| 316 | + |
300 | 317 | # Resolve promise |
301 | 318 | deferred.resolve() |
302 | 319 |
|
@@ -389,7 +406,7 @@ cyclotronApp.controller 'DashboardController', ($scope, $stateParams, $location, |
389 | 406 | _.each themes, (theme) -> |
390 | 407 | loadService.loadCssUrl('/css/app.themes.' + theme + '.css', true) |
391 | 408 |
|
392 | | - # Intialize parameters |
| 409 | + # Initialize parameters |
393 | 410 | parameterService.initializeParameters($scope.dashboard).then -> |
394 | 411 |
|
395 | 412 | # Watch querystring for changes |
@@ -449,7 +466,14 @@ cyclotronApp.controller 'DashboardController', ($scope, $stateParams, $location, |
449 | 466 | .search $scope.deeplinkOptions |
450 | 467 | .toString() |
451 | 468 |
|
452 | | - $scope.loadDashboard().then $scope.initialLoad |
| 469 | + # Load Overrides, then the dashboard |
| 470 | + $localForage.bind($scope, { |
| 471 | + key: 'dashboardOverrides' |
| 472 | + defaultValue: { pages: [] } |
| 473 | + }).then -> |
| 474 | + $window.Cyclotron.dashboardOverrides = $scope.dashboardOverrides |
| 475 | + logService.debug 'Dashboard Overrides: ' + JSON.stringify($scope.dashboardOverrides) |
| 476 | + $scope.loadDashboard().then $scope.initialLoad |
453 | 477 |
|
454 | 478 | # |
455 | 479 | # Hot Key Bindings |
|
0 commit comments