1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- /**
- * Created by robin on 11/1/15.
- */
-
- angular.module('app')
- .controller('SideBarController', ['$scope', '$state', 'DataShareBusiness', '$mdDialog',
- function($scope, $state, DataShareBusiness, $mdDialog) {
-
- $scope.DataShareBusiness = DataShareBusiness;
-
- $scope.Search = {
- value: "",
- selected: null
- };
-
- $scope.getStateName = function()
- {
- if ($state.current.name.length == 0) {
- return "home";
- }
- return $state.current.name;
- };
-
- $scope.getCurrentGroups = function()
- {
- if (DataShareBusiness.CurrentGroups.length != 0) {
- var e = DataShareBusiness.CurrentGroups[DataShareBusiness.CurrentGroups.length - 1];
- if (e[DataShareBusiness.EntitiesType] == null || e[DataShareBusiness.EntitiesType].length == 0) {
- return e.Parent[DataShareBusiness.EntitiesType];
- }
- return e[DataShareBusiness.EntitiesType];
- }
- return DataShareBusiness[DataShareBusiness.EntitiesType];
- };
-
- $scope.search = function()
- {
- var groups = [];
- function searchRec(group)
- {
- if (group.Name.toLowerCase().indexOf($scope.Search.value.toLowerCase()) > -1) {
- groups.push(group);
- }
- if (group[DataShareBusiness.EntitiesType] != null) {
- group[DataShareBusiness.EntitiesType].forEach(searchRec);
- }
- }
- DataShareBusiness[DataShareBusiness.EntitiesType].forEach(searchRec);
- return groups;
- };
-
- $scope.goTo = function(group)
- {
- if (group != null) {
- $scope.Search.value = "";
- DataShareBusiness.goToGroup(group);
- }
- };
-
- $scope.goToFirstMatch = function()
- {
- if ($scope.Search.value.length != 0) {
- var groups = $scope.search();
- if (groups.length > 0) {
- $scope.goTo(groups[0]);
- }
- }
- };
-
- $scope.isInState = function(state)
- {
- return $state.current.name == state;
- };
- }]);
|