|
143 | 143 | return; |
144 | 144 |
|
145 | 145 | function mainSearch() { |
146 | | - console.log(vm.mainSearchInp); |
147 | | - |
148 | 146 | var searchText = vm.mainSearchInp; |
149 | 147 |
|
150 | 148 | if(typeof searchText == 'undefined' || searchText.length == 0 || (searchText = searchText.trim()).length == 0) { |
151 | 149 | restoreCommits(); |
152 | 150 | return; |
153 | 151 | } |
154 | 152 |
|
155 | | - var shaRegex = /\b[0-9a-f]{5,40}\b/; |
| 153 | + clearGraph(); |
| 154 | + var promise = null; |
156 | 155 |
|
| 156 | + var shaRegex = /\b[0-9a-f]{5,40}\b/; |
157 | 157 | if(shaRegex.test(searchText)) { |
158 | 158 | // it is probably an SHA. |
159 | | - repoDetailService.searchForHash(searchText).then(function(commits) { |
| 159 | + promise = repoDetailService.searchForHash(searchText).then(function(commits) { |
160 | 160 | vm.commitDetails = null; |
161 | 161 | parseCommits(commits); |
162 | 162 | vm.commits = commits; |
163 | 163 | resetCommitMap(); |
164 | | - if(commits.length > 0) { |
165 | | - $timeout(loadGraph); |
| 164 | + return vm.commits; |
| 165 | + }); |
| 166 | + } |
| 167 | + |
| 168 | + // search in commit messages. |
| 169 | + |
| 170 | + if(promise) { |
| 171 | + promise.then(searchByCommitMessage); |
| 172 | + } |
| 173 | + else { |
| 174 | + searchByCommitMessage(); |
| 175 | + } |
| 176 | + |
| 177 | + function searchByCommitMessage() { |
| 178 | + return repoDetailService.searchForCommitMessage(searchText).then(function(commits) { |
| 179 | + parseCommits(commits); |
| 180 | + if(promise) { |
| 181 | + vm.commits = vm.commits || []; |
| 182 | + } |
| 183 | + else { |
| 184 | + vm.commits = []; |
166 | 185 | } |
| 186 | + |
| 187 | + resetTempCommits(); |
| 188 | + |
| 189 | + // Array.prototype.push.apply(vm.commits, commits); |
| 190 | + vm.commits = addUniqueCommits(vm.commits, commits); |
| 191 | + |
| 192 | + resetCommitMap(); |
167 | 193 | return vm.commits; |
168 | 194 | }); |
169 | 195 | } |
170 | 196 | } |
171 | 197 |
|
| 198 | + |
| 199 | + /** |
| 200 | + * Adds commits2 to commits1. Skips duplicates. Does not modify, returns new array. |
| 201 | + */ |
| 202 | + function addUniqueCommits(commits1, commits2) { |
| 203 | + var commits1Copy = commits1.slice(0); |
| 204 | + |
| 205 | + var hashes = commits1.map(function(c) { |
| 206 | + return c.hash; |
| 207 | + }); |
| 208 | + |
| 209 | + var uniqueCommits = commits2.filter(function(c) { |
| 210 | + return hashes.indexOf(c.hash) == -1; |
| 211 | + }); |
| 212 | + |
| 213 | + Array.prototype.push.apply(commits1Copy, uniqueCommits); |
| 214 | + |
| 215 | + return commits1Copy; |
| 216 | + } |
| 217 | + |
172 | 218 | /** |
173 | 219 | * Stores commits in `commitsBackup` and `commitMapBackup`. Restore using `restoreCommits` |
174 | 220 | */ |
|
192 | 238 | graphBackup = null; |
193 | 239 | graphBackup = new Image(); |
194 | 240 | graphBackup.src = canvas.toDataURL("image/png"); |
195 | | - // graphBackup = document.createElement('canvas'); |
196 | | - // graphBackup.width = canvas.width; |
197 | | - // graphBackup.height = canvas.height; |
198 | | - |
199 | | - //var graphBackupCtx = graphBackup.getContext('2D'); |
200 | | - //graphBackupCtx.drawImage(canvas, 0, 0); |
201 | 241 | } |
202 | 242 |
|
203 | 243 | function restoreGraph() { |
204 | | - // $('#graph-container').append('<canvas id="log-graph"></canvas>'); |
205 | 244 | var canvas = document.getElementById('log-graph'); |
206 | 245 | canvas.width = graphBackup.width; |
207 | 246 | canvas.height = graphBackup.height; |
|
215 | 254 | ctx.drawImage(graphBackup, 0, 0); |
216 | 255 | } |
217 | 256 |
|
| 257 | + function clearGraph() { |
| 258 | + var canvas = document.getElementById('log-graph'); |
| 259 | + if(!canvas) { |
| 260 | + return; |
| 261 | + } |
| 262 | + var ctx = canvas.getContext('2d'); |
| 263 | + |
| 264 | + ctx.clearRect(0, 0, canvas.width, canvas.height); |
| 265 | + canvas.width = 0; |
| 266 | + canvas.height = 0; |
| 267 | + } |
| 268 | + |
218 | 269 | function abortMerge() { |
219 | 270 | return repoDetailService.abortMerge().then(function(d) { |
220 | 271 | if(!d.errorCode) { |
|
1307 | 1358 | this.mergeIntoCurrent = mergeIntoCurrent; |
1308 | 1359 | this.abortMerge = abortMerge; |
1309 | 1360 | this.searchForHash = searchForHash; |
| 1361 | + this.searchForCommitMessage = searchForCommitMessage; |
1310 | 1362 |
|
1311 | 1363 | return; |
1312 | 1364 |
|
| 1365 | + function searchForCommitMessage(searchText) { |
| 1366 | + return $http.post('/repo/' + repoName + '/searchforcommitmessage', {text: window.encodeURIComponent(searchText)}).then(function(res) { |
| 1367 | + return res.data; |
| 1368 | + }); |
| 1369 | + } |
| 1370 | + |
1313 | 1371 | function searchForHash(hash) { |
1314 | 1372 | return $http.post('/repo/' + repoName + '/searchforhash', {hash: hash}).then(function(res) { |
1315 | 1373 | return res.data; |
|
0 commit comments