remote-debug.client.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. (function (angular) {
  2. const SECTION_NAME = "remote-debug";
  3. angular
  4. .module("BrowserSync")
  5. .controller("RemoteDebugController", [
  6. "options",
  7. "Socket",
  8. "pagesConfig",
  9. RemoteDebugController
  10. ]);
  11. /**
  12. * @param options
  13. * @param Socket
  14. * @param pagesConfig
  15. */
  16. function RemoteDebugController(options, Socket, pagesConfig) {
  17. var ctrl = this;
  18. ctrl.options = options.bs;
  19. ctrl.uiOptions = options.ui;
  20. ctrl.clientFiles = options.ui.clientFiles || {};
  21. ctrl.section = pagesConfig[SECTION_NAME];
  22. ctrl.overlayGrid = options.ui[SECTION_NAME]["overlay-grid"];
  23. ctrl.items = [];
  24. if (Object.keys(ctrl.clientFiles).length) {
  25. Object.keys(ctrl.clientFiles).forEach(function (key) {
  26. if (ctrl.clientFiles[key].context === SECTION_NAME) {
  27. ctrl.items.push(ctrl.clientFiles[key]);
  28. }
  29. });
  30. }
  31. ctrl.toggleClientFile = function (item) {
  32. if (item.active) {
  33. return ctrl.enable(item);
  34. }
  35. return ctrl.disable(item);
  36. };
  37. ctrl.toggleOverlayGrid = function (item) {
  38. var ns = SECTION_NAME + ":overlay-grid";
  39. Socket.uiEvent({
  40. namespace: ns,
  41. event: "toggle",
  42. data: item.active
  43. });
  44. };
  45. ctrl.enable = function (item) {
  46. Socket.uiEvent({
  47. namespace: SECTION_NAME + ":files",
  48. event: "enableFile",
  49. data: item
  50. });
  51. };
  52. ctrl.disable = function (item) {
  53. Socket.uiEvent({
  54. namespace: SECTION_NAME + ":files",
  55. event: "disableFile",
  56. data: item
  57. });
  58. };
  59. }
  60. /**
  61. * Display the snippet when in snippet mode
  62. */
  63. angular
  64. .module("BrowserSync")
  65. .directive("noCache", function () {
  66. return {
  67. restrict: "E",
  68. replace: true,
  69. scope: {
  70. "options": "="
  71. },
  72. templateUrl: "no-cache.html",
  73. controller: ["$scope", "Socket", noCacheDirectiveControlller],
  74. controllerAs: "ctrl"
  75. };
  76. });
  77. /**
  78. * @param $scope
  79. * @param Socket
  80. */
  81. function noCacheDirectiveControlller ($scope, Socket) {
  82. var ctrl = this;
  83. ctrl.noCache = $scope.options[SECTION_NAME]["no-cache"];
  84. ctrl.toggleLatency = function (item) {
  85. Socket.emit("ui:no-cache", {
  86. event: "toggle",
  87. data: item.active
  88. });
  89. };
  90. }
  91. /**
  92. * Display the snippet when in snippet mode
  93. */
  94. angular
  95. .module("BrowserSync")
  96. .directive("compression", function () {
  97. return {
  98. restrict: "E",
  99. replace: true,
  100. scope: {
  101. "options": "="
  102. },
  103. templateUrl: "compression.html",
  104. controller: ["$scope", "Socket", compressionDirectiveControlller],
  105. controllerAs: "ctrl"
  106. };
  107. });
  108. /**
  109. * @param $scope
  110. * @param Socket
  111. */
  112. function compressionDirectiveControlller ($scope, Socket) {
  113. var ctrl = this;
  114. ctrl.compression = $scope.options[SECTION_NAME]["compression"];
  115. ctrl.toggleLatency = function (item) {
  116. Socket.emit("ui:compression", {
  117. event: "toggle",
  118. data: item.active
  119. });
  120. };
  121. }
  122. })(angular);