59 | | loadDiffs: function( models ) { |
| 61 | /* |
| 62 | * Time to load all the models, each model represents a comparison |
| 63 | */ |
| 64 | loadDiffs: function( models, otherModels ) { |
| 65 | // in two handle mode, pass the other handle's models and copy over scopeOfChanges (tick width) |
| 66 | // from that model for positions this handle can't reach (but the other handle can reach) |
| 67 | // (only do this once) |
| 68 | if ( 'undefined' !== typeof otherModels ) { // otherModels only passed in two handle mode |
| 69 | _.each( models.where( { loadedStatus: 'true' } ), // select just the models that are marked as not needing loading, eg. positions this handle can't reach |
| 70 | function( theModel ) { |
| 71 | foundModel = otherModels.findWhere( { ID: theModel.id } ); //find the matching position from the other handle's models |
| 72 | if ( 'undefined' !== typeof foundModel ) { |
| 73 | theModel.set( 'scopeOfChanges', // set the displayed scope of changes for ticks this handle can't get to |
| 74 | foundModel |
| 75 | .get( 'scopeOfChanges' ) ); // copy the scope of changes from the other handle which can reach this spot |
| 76 | } |
| 77 | } |
| 78 | ); |
| 79 | } |
| 80 | this.loadDiffsRecursive( models, otherModels ); // recursively load models that need loading |
| 81 | }, |
| 82 | |
| 83 | /* |
| 84 | * load models that aren't loaded yet |
| 85 | */ |
| 86 | loadDiffsRecursive: function( models, otherModels ) { |
61 | | revisionsToLoad = models.where( { completed: false } ), |
62 | | delay = 0, |
63 | | totalChanges; |
64 | | |
65 | | // match slider to passed revision_id |
66 | | _.each( revisionsToLoad, function( revision ) { |
67 | | if ( revision.get( 'ID' ) == revisions.model.settings.revision_id ) |
| 88 | revision = models.findWhere( { loadedStatus: 'false' } ), // find the first model needing loadingh |
| 89 | totalChanges, |
| 90 | foundModel; |
| 91 | if ( 'undefined' === typeof revision ) { // nothing to load this time |
| 92 | self.tickmarkView.render(); |
| 93 | } else { |
| 94 | if ( revision.get( 'ID' ) == revisions.model.settings.revision_id ) { // match slider to passed revision_id |
84 | | totalChanges = model.get( 'linesAdded' ) + model.get( 'linesDeleted' ), |
85 | | scopeOfChanges = 'vsmall'; |
| 113 | // Note: hard coded scope of changes |
| 114 | // TODO change to dynamic based on range of values |
| 115 | if ( totalChanges > 1 && totalChanges <= 3 ) { |
| 116 | scopeOfChanges = 'small'; |
| 117 | } else if ( totalChanges > 3 && totalChanges <= 5 ) { |
| 118 | scopeOfChanges = 'med'; |
| 119 | } else if ( totalChanges > 5 && totalChanges <= 10 ) { |
| 120 | scopeOfChanges = 'large'; |
| 121 | } else if ( totalChanges > 10 ) { |
| 122 | scopeOfChanges = 'vlarge'; |
| 123 | } |
| 124 | model.set( 'scopeOfChanges', scopeOfChanges ); |
| 125 | if ( 0 !== self.rightDiff && |
| 126 | model.get( 'ID' ) === self.revisions.at( self.rightDiff - 1 ).get( 'ID' ) ) { |
87 | | // Note: hard coded scope of changes |
88 | | // TODO change to dynamic based on range of values |
89 | | if ( totalChanges > 1 && totalChanges <= 3 ) { |
90 | | scopeOfChanges = 'small'; |
91 | | } else if ( totalChanges > 3 && totalChanges <= 5 ) { |
92 | | scopeOfChanges = 'med'; |
93 | | } else if ( totalChanges > 5 && totalChanges <= 10 ) { |
94 | | scopeOfChanges = 'large'; |
95 | | } else if ( totalChanges > 10 ) { |
96 | | scopeOfChanges = 'vlarge'; |
97 | | } |
98 | | model.set( 'scopeOfChanges', scopeOfChanges ); |
99 | | if ( 0 !== self.rightDiff && |
100 | | model.get( 'ID' ) === self.revisions.at( self.rightDiff - 1 ).get( 'ID' ) ) { |
101 | | // reload if current model refreshed |
102 | | self.revisionView.render(); |
103 | | } |
104 | | self.tickmarkView.render(); |
105 | | } |
106 | | } ); |
107 | | }, delay ) ; |
108 | | delay = delay + 150; // stagger model loads to avoid hammering server with requests |
| 128 | // reload if current model refreshed |
| 129 | self.revisionView.render(); |
| 130 | } |
| 131 | model.set( 'loadedStatus', 'true' ); |
| 132 | self.loadDiffsRecursive( models, otherModels ); |
| 133 | } |