Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

DataShareBusiness.js 3.6KB

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