|
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | 4 | class ClosedWindowListCtrl { |
5 | | - constructor() { |
| 5 | + constructor($scope, $timeout) { |
| 6 | + this.$scope = $scope; |
| 7 | + this.$timeout = $timeout; |
6 | 8 | this.closedWindows = []; |
7 | 9 | this.closedTabsShow = false; |
| 10 | + this.overriddenIcon = ''; |
| 11 | + |
| 12 | + this._watch(); |
| 13 | + } |
| 14 | + |
| 15 | + override() { |
| 16 | + return this.overriddenIcon; |
8 | 17 | } |
9 | 18 |
|
10 | 19 | refreshClosedWindows() { |
11 | 20 | this.closedWindows = window.storeService.getPreviousClosedWindows(); |
| 21 | + this.updateSeen(); |
| 22 | + } |
| 23 | + |
| 24 | + updateSeen() { |
| 25 | + var seen = window.windowService.getClosedWindowSeen(); |
| 26 | + this.overriddenIcon = seen ? '' : (this.$scope.icon + '_active'); |
| 27 | + |
| 28 | + if (!seen && this.closedTabsShow && document.hasFocus()) { |
| 29 | + window.windowService.seenClosedWindows(); |
| 30 | + } |
12 | 31 | } |
13 | 32 |
|
14 | 33 | click() { |
| 34 | + this.overriddenIcon = ''; |
15 | 35 | this.refreshClosedWindows(); |
16 | 36 | this.closedTabsShow = this.closedWindows.length > 0; |
| 37 | + |
| 38 | + if (window.windowService) { |
| 39 | + window.windowService.seenClosedWindows(); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + _watch() { |
| 44 | + var listener = () => this.$timeout(() => this.refreshClosedWindows()); |
| 45 | + var addListener = () => { |
| 46 | + window.windowService.addClosedWindowListener(listener); |
| 47 | + this.refreshClosedWindows(); |
| 48 | + }; |
| 49 | + |
| 50 | + // Can't guarantee that windowService exists, so if it doesn't, watch. |
| 51 | + if (window.windowService) { |
| 52 | + addListener(); |
| 53 | + } else { |
| 54 | + this.$scope.$watch(() => window.windowService, () => { |
| 55 | + addListener(); |
| 56 | + }); |
| 57 | + } |
| 58 | + |
| 59 | + this.$scope.$on('$destroy', () => { |
| 60 | + window.windowService.removeClosedWindowListener(listener); |
| 61 | + }); |
17 | 62 | } |
18 | 63 | } |
19 | | - ClosedWindowListCtrl.$inject = []; |
| 64 | + ClosedWindowListCtrl.$inject = ['$scope', '$timeout']; |
20 | 65 |
|
21 | 66 | angular.module('stockflux.closedWindows') |
22 | 67 | .controller('ClosedWindowListCtrl', ClosedWindowListCtrl); |
|
0 commit comments