Last active
July 26, 2017 20:22
-
-
Save mnoble01/d7dda41cf9e3eb5131f1d67787f6c78f to your computer and use it in GitHub Desktop.
Task Facet data munging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const { A, get, String: { pluralize } } = Ember; | |
export default Ember.Controller.extend({ | |
facetsForChecklist: Ember.computed('taskFacets', 'selectedFacets', function() { | |
// Merged facets is an array of objects of the form { facetAttribute: {}, taskFacets: [] } | |
const mergedFacets = this.get('taskFacets').reduce(function(mergedFacets, taskFacet) { | |
const facetAttribute = get(taskFacet, 'facetAttribute'); | |
const facetAttributeId = get(taskFacet, 'facetAttributeId'); | |
const mergedFacet = mergedFacets.findBy('facetAttribute.id', facetAttributeId) | |
|| mergedFacets.pushObject({ facetAttribute, taskFacets: [] }); | |
mergedFacet.taskFacets.push(taskFacet); | |
return mergedFacets; | |
}, A()); | |
return mergedFacets.map(({facetAttribute, taskFacets}) => { | |
const facetAttributeId = get(facetAttribute, 'id') | |
const facetAttributeName = get(facetAttribute, 'name'); | |
const options = taskFacets.map((taskFacet) => { | |
return { id: get(taskFacet, 'id'), value: get(taskFacet, 'name') }; | |
}); | |
const selectedOptionIds = this.get('selectedFacets')[facetAttributeId] || []; | |
const title = `Viewing ${selectedOptionIds.length ? 'Filtered' : 'All'} ${pluralize(facetAttributeName)}`; | |
return { title, facetAttribute, options, selectedOptionIds }; | |
}); | |
}), | |
selectedFacets: Ember.computed(() => ({})), | |
stringifiedFacetsForChecklist: Ember.computed('facetsForChecklist', function() { | |
return JSON.stringify(this.get('facetsForChecklist'), null, ' '); | |
}), | |
stringifiedTaskFacets: Ember.computed('taskFacets', function() { | |
return JSON.stringify(this.get('taskFacets'), null, ' '); | |
}), | |
stringifiedMergedFacets: Ember.computed('taskFacets', function() { | |
// Repeated here so we can visualize the interim step | |
const mergedFacets = this.get('taskFacets').reduce(function(mergedFacets, taskFacet) { | |
const facetAttribute = get(taskFacet, 'facetAttribute'); | |
const facetAttributeId = get(taskFacet, 'facetAttributeId'); | |
const mergedFacet = mergedFacets.findBy('facetAttribute.id', facetAttributeId) | |
|| mergedFacets.pushObject({ facetAttribute, taskFacets: [] }); | |
mergedFacet.taskFacets.push(taskFacet); | |
return mergedFacets; | |
}, A()); | |
return JSON.stringify(mergedFacets, null, ' '); | |
}), | |
taskFacets: Ember.computed(function() { | |
return [ | |
{ | |
"id": "s-00000000-0000-0000-0000-000000000001\/Security::User", | |
"facetAttributeId": "assignee", | |
"name": "A User", | |
"taskCount": 2, | |
"facetAttribute": { | |
"id": "assignee", | |
"name": "Assignee" | |
}, | |
}, | |
{ | |
"id": "s-00000000-0000-0000-0000-000000000002\/Security::User", | |
"facetAttributeId": "assignee", | |
"name": "Another User", | |
"taskCount": 1, | |
"facetAttribute": { | |
"id": "assignee", | |
"name": "Assignee" | |
}, | |
}, | |
{ | |
"id": "s-b5a41a6a-40e6-4ae7-b8c1-e90b617fd5f9", | |
"facetAttributeId": "flow_template_id", | |
"name": "Flow Template 1", | |
"taskCount": 2, | |
"facetAttribute": { | |
"id": "flow_template_id", | |
"name": "Flow" | |
}, | |
}, | |
{ | |
"id": "s-bc6d73a5-0c12-4f38-8a58-cbb63bd65b57", | |
"facetAttributeId": "flow_template_id", | |
"name": "Flow Template 2", | |
"taskCount": 1, | |
"facetAttribute": { | |
"id": "flow_template_id", | |
"name": "Flow" | |
}, | |
}, | |
{ | |
"id": "Task Configuration 1", | |
"facetAttributeId": "task_configuration_name", | |
"name": "Task Configuration 1", | |
"taskCount": 2, | |
"facetAttribute": { | |
"id": "task_configuration_name", | |
"name": "Task Type" | |
} | |
}, | |
{ | |
"id": "Task Configuration 2", | |
"facetAttributeId": "task_configuration_name", | |
"name": "Task Configuration 2", | |
"taskCount": 1, | |
"facetAttribute": { | |
"id": "task_configuration_name", | |
"name": "Task Type" | |
} | |
} | |
]; | |
}), | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.12.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment