connections.client.js
1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(function (angular) {
const SECTION_NAME = "connections";
angular
.module("BrowserSync")
.controller("ConnectionsController", [
"pagesConfig",
ConnectionsControllers
]);
/**
* @param pagesConfig
* @constructor
*/
function ConnectionsControllers(pagesConfig) {
var ctrl = this;
ctrl.section = pagesConfig[SECTION_NAME];
}
angular
.module("BrowserSync")
.directive("connectionList", function () {
return {
restrict: "E",
scope: {
options: "="
},
templateUrl: "connections.directive.html",
controller: ["$scope", "Clients", "Socket", connectionListDirective],
controllerAs: "ctrl"
};
});
/**
* Controller for the URL sync
* @param $scope - directive scope
* @param Clients
* @param Socket
*/
function connectionListDirective($scope, Clients, Socket) {
var ctrl = this;
ctrl.connections = [];
ctrl.update = function (data) {
ctrl.connections = data;
$scope.$digest();
};
// Always try to retreive the sockets first time.
Socket.getData("clients").then(function (data) {
ctrl.connections = data;
});
// Listen to events to update the list on the fly
Socket.on("ui:connections:update", ctrl.update);
$scope.$on("$destroy", function () {
Socket.off("ui:connections:update", ctrl.update);
});
ctrl.highlight = function (connection) {
Clients.highlight(connection);
};
}
})(angular);