github.com/manicqin/nomad@v0.9.5/ui/app/components/job-version.js (about) 1 import Component from '@ember/component'; 2 import { computed } from '@ember/object'; 3 4 const changeTypes = ['Added', 'Deleted', 'Edited']; 5 6 export default Component.extend({ 7 classNames: ['job-version', 'boxed-section'], 8 9 version: null, 10 isOpen: false, 11 12 // Passes through to the job-diff component 13 verbose: true, 14 15 changeCount: computed('version.diff', function() { 16 const diff = this.get('version.diff'); 17 const taskGroups = diff.TaskGroups || []; 18 19 if (!diff) { 20 return 0; 21 } 22 23 return ( 24 fieldChanges(diff) + 25 taskGroups.reduce(arrayOfFieldChanges, 0) + 26 (taskGroups.mapBy('Tasks') || []).reduce(flatten, []).reduce(arrayOfFieldChanges, 0) 27 ); 28 }), 29 30 actions: { 31 toggleDiff() { 32 this.toggleProperty('isOpen'); 33 }, 34 }, 35 }); 36 37 const flatten = (accumulator, array) => accumulator.concat(array); 38 const countChanges = (total, field) => (changeTypes.includes(field.Type) ? total + 1 : total); 39 40 function fieldChanges(diff) { 41 return ( 42 (diff.Fields || []).reduce(countChanges, 0) + 43 (diff.Objects || []).reduce(arrayOfFieldChanges, 0) 44 ); 45 } 46 47 function arrayOfFieldChanges(count, diff) { 48 if (!diff) { 49 return count; 50 } 51 52 return count + fieldChanges(diff); 53 }