connections.client.js 1.7 KB

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