You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DataShareBusiness.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. var search = data.getSearchString(-1);
  22. $location.search({group: search.length == 0 ? undefined : search});
  23. });
  24. },
  25. getCurrentGroup: function()
  26. {
  27. if (data.CurrentGroups.length == 0) {
  28. return null;
  29. }
  30. return data.CurrentGroups[data.CurrentGroups.length - 1];
  31. },
  32. getCurrentGroupOrRoot: function()
  33. {
  34. var group = data.getCurrentGroup();
  35. if (group == null) {
  36. return {
  37. Id: null,
  38. Groups: data.Groups,
  39. Name: "Root",
  40. Type: 1,
  41. ParentId: -1
  42. }
  43. }
  44. return group;
  45. },
  46. getSearchString: function(group)
  47. {
  48. if (group == -1 && data.CurrentGroups.length != 0) {
  49. group = data.CurrentGroups[data.CurrentGroups.length - 1];
  50. }
  51. if (group == null) {
  52. return "";
  53. }
  54. var search = [];
  55. while (group != null){
  56. search.push(group.Name);
  57. group = group.Parent;
  58. }
  59. return search.reverse().join(data.SearchSeparator);
  60. },
  61. getGroupUrl: function(group)
  62. {
  63. var search = data.getSearchString(group);
  64. return $state.href('home') + $location.hash() + (search.length != 0 ? "?group=" + search : "");
  65. },
  66. setFromSearchString: function(string)
  67. {
  68. if (data.Groups == null) {
  69. return;
  70. }
  71. if (string == null) {
  72. data.setCurrentGroup(null);
  73. return;
  74. }
  75. var group = {Groups: data.Groups};
  76. var names = string.split(data.SearchSeparator);
  77. names.forEach(function(name)
  78. {
  79. var g = group.Groups.find(function(g)
  80. {
  81. return g.Name == name;
  82. });
  83. if (g != null) {
  84. group = g;
  85. }
  86. });
  87. data.setCurrentGroup(group);
  88. },
  89. upCurrentGroup: function()
  90. {
  91. if (data.CurrentGroups.length > 1) {
  92. data.setCurrentGroup(data.CurrentGroups[data.CurrentGroups.length - 2]);
  93. }
  94. else if (data.CurrentGroups.length == 1) {
  95. data.setCurrentGroup(null);
  96. }
  97. }
  98. };
  99. return data;
  100. }]);
  101. })();