Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

DataShareBusiness.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. (function()
  2. {
  3. angular.module('appSdk')
  4. .factory('DataShareBusiness', ['$location', function ($location) {
  5. var data = {
  6. Groups: null,
  7. SearchSeparator: "~",
  8. CurrentGroups: [],
  9. setCurrentGroup: function(group)
  10. {
  11. data.CurrentGroups = [];
  12. while (group != null) {
  13. data.CurrentGroups.push(group);
  14. group = group.Parent;
  15. }
  16. data.CurrentGroups.reverse();
  17. $location.search(data.getSearchString(-1));
  18. },
  19. getCurrentGroup: function()
  20. {
  21. if (data.CurrentGroups.length == 0) {
  22. return null;
  23. }
  24. return data.CurrentGroups[data.CurrentGroups.length - 1];
  25. },
  26. getCurrentGroupOrRoot: function()
  27. {
  28. var group = data.getCurrentGroup();
  29. if (group == null) {
  30. return {
  31. Id: null,
  32. Groups: data.Groups,
  33. Name: "Root",
  34. Type: 1,
  35. ParentId: -1
  36. }
  37. }
  38. return group;
  39. },
  40. getSearchString: function(group)
  41. {
  42. if (group == -1 && data.CurrentGroups.length != 0) {
  43. group = data.CurrentGroups[data.CurrentGroups.length - 1];
  44. }
  45. if (group == null) {
  46. return "";
  47. }
  48. var search = [];
  49. while (group != null){
  50. search.push(group.Name);
  51. group = group.Parent;
  52. }
  53. return search.reverse().join(data.SearchSeparator);
  54. },
  55. getGroupUrl: function(group)
  56. {
  57. var search = data.getSearchString(group);
  58. return "#" + $location.path() + $location.hash() + "?" + search;
  59. },
  60. setFromSearchString: function(string)
  61. {
  62. if (string == null) {
  63. data.setCurrentGroup(null);
  64. return;
  65. }
  66. var group = {Groups: data.Groups};
  67. var names = string.split(data.SearchSeparator);
  68. names.forEach(function(name)
  69. {
  70. var g = group.Groups.find(function(g)
  71. {
  72. return g.Name == name;
  73. });
  74. if (g != null) {
  75. group = g;
  76. }
  77. });
  78. data.setCurrentGroup(group);
  79. },
  80. upCurrentGroup: function()
  81. {
  82. if (data.CurrentGroups.length > 1) {
  83. data.setCurrentGroup(data.CurrentGroups[data.CurrentGroups.length - 2]);
  84. }
  85. else if (data.CurrentGroups.length == 1) {
  86. data.setCurrentGroup(null);
  87. }
  88. }
  89. };
  90. return data;
  91. }]);
  92. })();