1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- (function()
- {
- angular.module('appSdk')
- .factory('DataShareBusiness', ['$location', function ($location) {
-
- var data = {
- Groups: null,
-
- SearchSeparator: "~",
-
- CurrentGroups: [],
-
- setCurrentGroup: function(group)
- {
- data.CurrentGroups = [];
- while (group != null) {
- data.CurrentGroups.push(group);
- group = group.Parent;
- }
- data.CurrentGroups.reverse();
-
- $location.search(data.getSearchString(-1));
- },
-
- getCurrentGroup: function()
- {
- if (data.CurrentGroups.length == 0) {
- return null;
- }
- return data.CurrentGroups[data.CurrentGroups.length - 1];
- },
-
- getSearchString: function(group)
- {
- if (group == -1 && data.CurrentGroups.length != 0) {
- group = data.CurrentGroups[data.CurrentGroups.length - 1];
- }
- if (group == null) {
- return "";
- }
- var search = [];
- while (group != null){
- search.push(group.Name);
- group = group.Parent;
- }
- return search.reverse().join(data.SearchSeparator);
- },
-
- getGroupUrl: function(group)
- {
- var search = data.getSearchString(group);
- return "#" + $location.path() + $location.hash() + "?" + search;
- },
-
- setFromSearchString: function(string)
- {
- if (string == null) {
- data.setCurrentGroup(null);
- return;
- }
- var group = {Groups: data.Groups};
- var names = string.split(data.SearchSeparator);
- names.forEach(function(name)
- {
- var g = group.Groups.find(function(g)
- {
- return g.Name == name;
- });
- if (g != null) {
- group = g;
- }
- });
- data.setCurrentGroup(group);
- },
-
- upCurrentGroup: function()
- {
- if (data.CurrentGroups.length > 1) {
- data.setCurrentGroup(data.CurrentGroups[data.CurrentGroups.length - 2]);
- }
- else if (data.CurrentGroups.length == 1) {
- data.setCurrentGroup(null);
- }
- }
- };
-
- return data;
- }]);
- })();
|