Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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"
- }
- }
- ];
- }),
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement