您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DataShareBusiness.js 3.7KB

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