123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- (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];
- },
-
- getCurrentGroupOrRoot: function()
- {
- var group = data.getCurrentGroup();
- if (group == null) {
- return {
- Id: null,
- Groups: data.Groups,
- Name: "Root",
- Type: 1,
- ParentId: -1
- }
- }
- return group;
- },
-
- 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;
- }]);
- })();
|