Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. import Ember from 'ember';
  2. const { A, get, String: { pluralize } } = Ember;
  3.  
  4. export default Ember.Controller.extend({
  5. facetsForChecklist: Ember.computed('taskFacets', 'selectedFacets', function() {
  6. // Merged facets is an array of objects of the form { facetAttribute: {}, taskFacets: [] }
  7. const mergedFacets = this.get('taskFacets').reduce(function(mergedFacets, taskFacet) {
  8. const facetAttribute = get(taskFacet, 'facetAttribute');
  9. const facetAttributeId = get(taskFacet, 'facetAttributeId');
  10. const mergedFacet = mergedFacets.findBy('facetAttribute.id', facetAttributeId)
  11. || mergedFacets.pushObject({ facetAttribute, taskFacets: [] });
  12. mergedFacet.taskFacets.push(taskFacet);
  13. return mergedFacets;
  14. }, A());
  15.  
  16. return mergedFacets.map(({facetAttribute, taskFacets}) => {
  17. const facetAttributeId = get(facetAttribute, 'id')
  18. const facetAttributeName = get(facetAttribute, 'name');
  19. const options = taskFacets.map((taskFacet) => {
  20. return { id: get(taskFacet, 'id'), value: get(taskFacet, 'name') };
  21. });
  22. const selectedOptionIds = this.get('selectedFacets')[facetAttributeId] || [];
  23. const title = `Viewing ${selectedOptionIds.length ? 'Filtered' : 'All'} ${pluralize(facetAttributeName)}`;
  24. return { title, facetAttribute, options, selectedOptionIds };
  25. });
  26. }),
  27.  
  28.  
  29.  
  30.  
  31.  
  32. selectedFacets: Ember.computed(() => ({})),
  33.  
  34. stringifiedFacetsForChecklist: Ember.computed('facetsForChecklist', function() {
  35. return JSON.stringify(this.get('facetsForChecklist'), null, ' ');
  36. }),
  37.  
  38. stringifiedTaskFacets: Ember.computed('taskFacets', function() {
  39. return JSON.stringify(this.get('taskFacets'), null, ' ');
  40. }),
  41.  
  42. stringifiedMergedFacets: Ember.computed('taskFacets', function() {
  43. // Repeated here so we can visualize the interim step
  44. const mergedFacets = this.get('taskFacets').reduce(function(mergedFacets, taskFacet) {
  45. const facetAttribute = get(taskFacet, 'facetAttribute');
  46. const facetAttributeId = get(taskFacet, 'facetAttributeId');
  47. const mergedFacet = mergedFacets.findBy('facetAttribute.id', facetAttributeId)
  48. || mergedFacets.pushObject({ facetAttribute, taskFacets: [] });
  49. mergedFacet.taskFacets.push(taskFacet);
  50. return mergedFacets;
  51. }, A());
  52. return JSON.stringify(mergedFacets, null, ' ');
  53. }),
  54.  
  55. taskFacets: Ember.computed(function() {
  56. return [
  57. {
  58. "id": "s-00000000-0000-0000-0000-000000000001\/Security::User",
  59. "facetAttributeId": "assignee",
  60. "name": "A User",
  61. "taskCount": 2,
  62. "facetAttribute": {
  63. "id": "assignee",
  64. "name": "Assignee"
  65. },
  66. },
  67. {
  68. "id": "s-00000000-0000-0000-0000-000000000002\/Security::User",
  69. "facetAttributeId": "assignee",
  70. "name": "Another User",
  71. "taskCount": 1,
  72. "facetAttribute": {
  73. "id": "assignee",
  74. "name": "Assignee"
  75. },
  76. },
  77. {
  78. "id": "s-b5a41a6a-40e6-4ae7-b8c1-e90b617fd5f9",
  79. "facetAttributeId": "flow_template_id",
  80. "name": "Flow Template 1",
  81. "taskCount": 2,
  82. "facetAttribute": {
  83. "id": "flow_template_id",
  84. "name": "Flow"
  85. },
  86. },
  87. {
  88. "id": "s-bc6d73a5-0c12-4f38-8a58-cbb63bd65b57",
  89. "facetAttributeId": "flow_template_id",
  90. "name": "Flow Template 2",
  91. "taskCount": 1,
  92. "facetAttribute": {
  93. "id": "flow_template_id",
  94. "name": "Flow"
  95. },
  96. },
  97. {
  98. "id": "Task Configuration 1",
  99. "facetAttributeId": "task_configuration_name",
  100. "name": "Task Configuration 1",
  101. "taskCount": 2,
  102. "facetAttribute": {
  103. "id": "task_configuration_name",
  104. "name": "Task Type"
  105. }
  106. },
  107. {
  108. "id": "Task Configuration 2",
  109. "facetAttributeId": "task_configuration_name",
  110. "name": "Task Configuration 2",
  111. "taskCount": 1,
  112. "facetAttribute": {
  113. "id": "task_configuration_name",
  114. "name": "Task Type"
  115. }
  116. }
  117. ];
  118. }),
  119. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement