You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sidebar.controller.js 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Created by robin on 11/1/15.
  3. */
  4. angular.module('app')
  5. .controller('SideBarController', ['$scope', '$state', 'DataShareBusiness', '$mdDialog',
  6. function($scope, $state, DataShareBusiness, $mdDialog) {
  7. $scope.DataShareBusiness = DataShareBusiness;
  8. $scope.Search = {
  9. value: "",
  10. selected: null
  11. };
  12. $scope.getStateName = function()
  13. {
  14. if ($state.current.name.length == 0) {
  15. return "home";
  16. }
  17. return $state.current.name;
  18. };
  19. $scope.getCurrentGroups = function()
  20. {
  21. if (DataShareBusiness.CurrentGroups.length != 0) {
  22. var e = DataShareBusiness.CurrentGroups[DataShareBusiness.CurrentGroups.length - 1];
  23. if (e[DataShareBusiness.EntitiesType] == null || e[DataShareBusiness.EntitiesType].length == 0) {
  24. return e.Parent[DataShareBusiness.EntitiesType];
  25. }
  26. return e[DataShareBusiness.EntitiesType];
  27. }
  28. return DataShareBusiness[DataShareBusiness.EntitiesType];
  29. };
  30. $scope.search = function()
  31. {
  32. var groups = [];
  33. function searchRec(group)
  34. {
  35. if (group.Name.toLowerCase().indexOf($scope.Search.value.toLowerCase()) > -1) {
  36. groups.push(group);
  37. }
  38. if (group[DataShareBusiness.EntitiesType] != null) {
  39. group[DataShareBusiness.EntitiesType].forEach(searchRec);
  40. }
  41. }
  42. DataShareBusiness[DataShareBusiness.EntitiesType].forEach(searchRec);
  43. return groups;
  44. };
  45. $scope.goTo = function(group)
  46. {
  47. if (group != null) {
  48. $scope.Search.value = "";
  49. DataShareBusiness.goToGroup(group);
  50. }
  51. };
  52. $scope.goToFirstMatch = function()
  53. {
  54. if ($scope.Search.value.length != 0) {
  55. var groups = $scope.search();
  56. if (groups.length > 0) {
  57. $scope.goTo(groups[0]);
  58. }
  59. }
  60. };
  61. $scope.isInState = function(state)
  62. {
  63. return $state.current.name == state;
  64. };
  65. }]);