github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/public/static/js/directives/directives.patch.js (about) 1 var directives = directives || {}; 2 3 directives.patch = angular.module('directives.patch', ['filters.common', 'directives.github']); 4 5 directives.patch.directive('patchCommitPanel', function() { 6 return { 7 scope : true, 8 restrict : 'E', 9 templateUrl : '/static/partials/patch_commit_panel.html', 10 link : function(scope, element, attrs) { 11 scope.patchinfo = {}; 12 scope.basecommit = {}; 13 if(attrs.hideDescription){ 14 scope.hideDescription = true 15 } 16 scope.$parent.$watch(attrs.basecommit, function(v) { 17 scope.basecommit = v; 18 }); 19 scope.$parent.$watch(attrs.patchinfo, function(v) { 20 scope.patchinfo = v; 21 scope.patchinfo.shorthash = scope.patchinfo.Patch.Githash.substr(0, 10) 22 // get diff totals 23 totalAdd = 0; 24 totalDel = 0; 25 _.each(scope.patchinfo.Patch.Patches, function(patch) { 26 _.each(patch.PatchSet.Summary, function(diff) { 27 totalAdd += diff.Additions; 28 totalDel += diff.Deletions; 29 }) 30 }); 31 scope.totals = {additions: totalAdd, deletions: totalDel}; 32 }); 33 scope.timezone = attrs.timezone; 34 scope.base = attrs.base; 35 scope.baselink = attrs.baselink; 36 } 37 }; 38 }); 39 40 directives.patch.directive('patchDiffPanel', function() { 41 return { 42 scope : true, 43 restrict : 'E', 44 templateUrl : '/static/partials/patch_diff.html', 45 link : function(scope, element, attrs) { 46 47 scope.baselink = attrs.baselink; 48 scope.type = attrs.type; 49 50 // lookup table with constants for sorting / displaying diff results. 51 // there is redundancy here between "success/pass" and "failed/fail" 52 // to allow this to work generically with both test and task statuses 53 scope.diffTypes = { 54 successfailed: {icon:"fa-bug", type: 0}, 55 passfail: {icon:"fa-bug", type: 0}, 56 failedfailed: {icon:"fa-question", type: 1}, 57 failfail: {icon:"fa-question", type: 1}, 58 failed: {icon:"", type: 2}, 59 fail: {icon:"", type: 2}, 60 undefinedfailed: {icon:"", type: 2}, 61 undefinedfail: {icon:"", type: 2}, 62 failedsuccess: {icon:"fa-star", type: 3}, 63 failpass: {icon:"fa-star", type: 3}, 64 success: {icon:"", type: 4}, 65 pass: {icon:"", type: 4}, 66 undefinedsuccess: {icon:"", type: 4}, 67 undefinedpass: {icon:"", type: 4}, 68 successsuccess: {icon:"", type: 5}, 69 passpass: {icon:"", type: 5}, 70 }; 71 72 // helper for ranking status combinations 73 scope.getDisplayInfo = function(diff) { 74 // concat results for key lookup 75 if (typeof(diff.original) == "object") { 76 // task diffs have an extra layer we need to extract 77 key = diff.original.status + diff.patch.status; 78 } else { 79 // test diffs are simpler 80 key = diff.original + diff.patch; 81 } 82 if (key in scope.diffTypes) { 83 return scope.diffTypes[key]; 84 } 85 // else return a default 86 return {icon: "", type:1000}; 87 } 88 89 scope.diffs = []; 90 scope.$parent.$watch(attrs.diffs, function(d) { 91 // only iterate if valid diffs are given 92 if (!d || !d.length) { 93 return 94 } 95 scope.diffs = d; 96 _.each(scope.diffs, function(diff) { 97 diff.originalLink = scope.baselink + diff.original; 98 diff.patchLink = scope.baselink + diff.patch; 99 diff.displayInfo = scope.getDisplayInfo(diff.diff); 100 }); 101 }); 102 103 } 104 }; 105 });