history.client.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. (function (angular) {
  2. const SECTION_NAME = "history";
  3. angular
  4. .module("BrowserSync")
  5. .controller("HistoryController", [
  6. "$scope",
  7. "options",
  8. "History",
  9. "pagesConfig",
  10. historyController
  11. ]);
  12. /**
  13. * @param $scope
  14. * @param options
  15. * @param History
  16. * @param pagesConfig
  17. */
  18. function historyController($scope, options, History, pagesConfig) {
  19. var ctrl = this;
  20. ctrl.options = options.bs;
  21. ctrl.section = pagesConfig[SECTION_NAME];
  22. ctrl.visited = [];
  23. ctrl.update = function (items) {
  24. ctrl.visited = items;
  25. $scope.$digest();
  26. };
  27. History.get().then(function (items) {
  28. ctrl.visited = items;
  29. });
  30. History.on("change", ctrl.update);
  31. $scope.$on("$destroy", function () {
  32. History.off(ctrl.update);
  33. });
  34. ctrl.clearVisited = function () {
  35. History.clear();
  36. };
  37. }
  38. angular
  39. .module("BrowserSync")
  40. .directive("historyList", function () {
  41. return {
  42. restrict: "E",
  43. scope: {
  44. options: "=",
  45. visited: "="
  46. },
  47. templateUrl: "history.directive.html",
  48. controller: ["$scope", "History", "Clients", historyDirective],
  49. controllerAs: "ctrl"
  50. };
  51. });
  52. /**
  53. * Controller for the URL sync
  54. * @param $scope - directive scope
  55. * @param History
  56. * @param Clients
  57. */
  58. function historyDirective($scope, History, Clients) {
  59. var ctrl = this;
  60. ctrl.visited = [];
  61. ctrl.utils = {};
  62. ctrl.utils.localUrl = function (path) {
  63. return [$scope.options.urls.local, path].join("");
  64. };
  65. ctrl.updateVisited = function (data) {
  66. ctrl.visited = data;
  67. $scope.$digest();
  68. };
  69. ctrl.sendAllTo = function (url) {
  70. url.success = true;
  71. Clients.sendAllTo(url.path);
  72. setTimeout(function () {
  73. url.success = false;
  74. $scope.$digest();
  75. }, 1000);
  76. };
  77. ctrl.removeVisited = function (item) {
  78. History.remove(item);
  79. };
  80. History.get().then(function (items) {
  81. ctrl.visited = items;
  82. });
  83. History.on("change", ctrl.updateVisited);
  84. $scope.$on("$destroy", function () {
  85. History.off(ctrl.updateVisited);
  86. });
  87. }
  88. })(angular);