sidebar.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. angular.module('sentinelDashboardApp')
  2. .directive('sidebar', ['$location', '$stateParams', 'AppService', function () {
  3. return {
  4. templateUrl: 'app/scripts/directives/sidebar/sidebar.html',
  5. restrict: 'E',
  6. replace: true,
  7. scope: {
  8. },
  9. controller: function ($scope, $stateParams, $location, AppService) {
  10. $scope.app = $stateParams.app;
  11. $scope.collapseVar = 0;
  12. // app
  13. AppService.getApps().success(
  14. function (data) {
  15. if (data.code === 0) {
  16. let path = $location.path().split('/');
  17. let initHashApp = path[path.length - 1];
  18. $scope.apps = data.data;
  19. $scope.apps = $scope.apps.map(function (item) {
  20. if (item.app === initHashApp) {
  21. item.active = true;
  22. }
  23. let healthyCount = 0;
  24. for (let i in item.machines) {
  25. if (item.machines[i].healthy) {
  26. healthyCount++;
  27. }
  28. }
  29. item.healthyCount = healthyCount;
  30. // Handle appType
  31. item.isGateway = item.appType === 1 || item.appType === 11 || item.appType === 12;
  32. if (item.shown) {
  33. return item;
  34. }
  35. });
  36. }
  37. }
  38. );
  39. // toggle side bar
  40. $scope.click = function ($event) {
  41. let entry = angular.element($event.target).scope().entry;
  42. entry.active = !entry.active;// toggle this clicked app bar
  43. $scope.apps.forEach(function (item) { // collapse other app bars
  44. if (item !== entry) {
  45. item.active = false;
  46. }
  47. });
  48. };
  49. /**
  50. * @deprecated
  51. */
  52. $scope.addSearchApp = function () {
  53. let findApp = false;
  54. for (let i = 0; i < $scope.apps.length; i++) {
  55. if ($scope.apps[i].app === $scope.searchApp) {
  56. findApp = true;
  57. break;
  58. }
  59. }
  60. if (!findApp) {
  61. $scope.apps.push({ app: $scope.searchApp });
  62. }
  63. };
  64. }
  65. };
  66. }]);