Show More
@@ -1,569 +1,593 b'' | |||
|
1 | 1 | <%inherit file="/base/base.html"/> |
|
2 | 2 | |
|
3 | 3 | <%def name="title()"> |
|
4 | 4 | ${c.repo_name} ${_('New pull request')} |
|
5 | 5 | </%def> |
|
6 | 6 | |
|
7 | 7 | <%def name="breadcrumbs_links()"> |
|
8 | 8 | ${_('New pull request')} |
|
9 | 9 | </%def> |
|
10 | 10 | |
|
11 | 11 | <%def name="menu_bar_nav()"> |
|
12 | 12 | ${self.menu_items(active='repositories')} |
|
13 | 13 | </%def> |
|
14 | 14 | |
|
15 | 15 | <%def name="menu_bar_subnav()"> |
|
16 | 16 | ${self.repo_menu(active='showpullrequest')} |
|
17 | 17 | </%def> |
|
18 | 18 | |
|
19 | 19 | <%def name="main()"> |
|
20 | 20 | <div class="box"> |
|
21 | 21 | <div class="title"> |
|
22 | 22 | ${self.repo_page_title(c.rhodecode_db_repo)} |
|
23 | 23 | ${self.breadcrumbs()} |
|
24 | 24 | </div> |
|
25 | 25 | |
|
26 | 26 | ${h.secure_form(url('pullrequest', repo_name=c.repo_name), method='post', id='pull_request_form')} |
|
27 | 27 | <div class="box pr-summary"> |
|
28 | 28 | |
|
29 | 29 | <div class="summary-details block-left"> |
|
30 | 30 | |
|
31 | 31 | <div class="form"> |
|
32 | 32 | <!-- fields --> |
|
33 | 33 | |
|
34 | 34 | <div class="fields" > |
|
35 | 35 | |
|
36 | 36 | <div class="field"> |
|
37 | 37 | <div class="label"> |
|
38 | 38 | <label for="pullrequest_title">${_('Title')}:</label> |
|
39 | 39 | </div> |
|
40 | 40 | <div class="input"> |
|
41 | 41 | ${h.text('pullrequest_title', c.default_title, class_="medium autogenerated-title")} |
|
42 | 42 | </div> |
|
43 | 43 | </div> |
|
44 | 44 | |
|
45 | 45 | <div class="field"> |
|
46 | 46 | <div class="label label-textarea"> |
|
47 | 47 | <label for="pullrequest_desc">${_('Description')}:</label> |
|
48 | 48 | </div> |
|
49 | 49 | <div class="textarea text-area editor"> |
|
50 | 50 | ${h.textarea('pullrequest_desc',size=30, )} |
|
51 | 51 | <span class="help-block"> |
|
52 | 52 | ${_('Write a short description on this pull request')} |
|
53 | 53 | </span> |
|
54 | 54 | </div> |
|
55 | 55 | </div> |
|
56 | 56 | |
|
57 | 57 | <div class="field"> |
|
58 | 58 | <div class="label label-textarea"> |
|
59 | 59 | <label for="pullrequest_desc">${_('Commit flow')}:</label> |
|
60 | 60 | </div> |
|
61 | 61 | |
|
62 | 62 | ## TODO: johbo: Abusing the "content" class here to get the |
|
63 | 63 | ## desired effect. Should be replaced by a proper solution. |
|
64 | 64 | |
|
65 | 65 | ##ORG |
|
66 | 66 | <div class="content"> |
|
67 | 67 | <strong>${_('Origin repository')}:</strong> |
|
68 | 68 | ${c.rhodecode_db_repo.description} |
|
69 | 69 | </div> |
|
70 | 70 | <div class="content"> |
|
71 | 71 | ${h.hidden('source_repo')} |
|
72 | 72 | ${h.hidden('source_ref')} |
|
73 | 73 | </div> |
|
74 | 74 | |
|
75 | 75 | ##OTHER, most Probably the PARENT OF THIS FORK |
|
76 | 76 | <div class="content"> |
|
77 | 77 | ## filled with JS |
|
78 | 78 | <div id="target_repo_desc"></div> |
|
79 | 79 | </div> |
|
80 | 80 | |
|
81 | 81 | <div class="content"> |
|
82 | 82 | ${h.hidden('target_repo')} |
|
83 | 83 | ${h.hidden('target_ref')} |
|
84 | 84 | <span id="target_ref_loading" style="display: none"> |
|
85 | 85 | ${_('Loading refs...')} |
|
86 | 86 | </span> |
|
87 | 87 | </div> |
|
88 | 88 | </div> |
|
89 | 89 | |
|
90 | 90 | <div class="field"> |
|
91 | 91 | <div class="label label-textarea"> |
|
92 | 92 | <label for="pullrequest_submit"></label> |
|
93 | 93 | </div> |
|
94 | 94 | <div class="input"> |
|
95 | 95 | <div class="pr-submit-button"> |
|
96 | 96 | ${h.submit('save',_('Submit Pull Request'),class_="btn")} |
|
97 | 97 | </div> |
|
98 | 98 | <div id="pr_open_message"></div> |
|
99 | 99 | </div> |
|
100 | 100 | </div> |
|
101 | 101 | |
|
102 | 102 | <div class="pr-spacing-container"></div> |
|
103 | 103 | </div> |
|
104 | 104 | </div> |
|
105 | 105 | </div> |
|
106 | 106 | <div> |
|
107 | 107 | <div class="reviewers-title block-right"> |
|
108 | 108 | <div class="pr-details-title"> |
|
109 | 109 | ${_('Pull request reviewers')} |
|
110 | <span class="calculate-reviewers"> - ${_('loading...')}</span> | |
|
110 | 111 | </div> |
|
111 | 112 | </div> |
|
112 | 113 | <div id="reviewers" class="block-right pr-details-content reviewers"> |
|
113 | 114 | ## members goes here, filled via JS based on initial selection ! |
|
114 | 115 | <input type="hidden" name="__start__" value="review_members:sequence"> |
|
115 | 116 | <ul id="review_members" class="group_members"></ul> |
|
116 | 117 | <input type="hidden" name="__end__" value="review_members:sequence"> |
|
117 | 118 | <div id="add_reviewer_input" class='ac'> |
|
118 | 119 | <div class="reviewer_ac"> |
|
119 | 120 | ${h.text('user', class_='ac-input', placeholder=_('Add reviewer'))} |
|
120 | 121 | <div id="reviewers_container"></div> |
|
121 | 122 | </div> |
|
122 | 123 | </div> |
|
123 | 124 | </div> |
|
124 | 125 | </div> |
|
125 | 126 | </div> |
|
126 | 127 | <div class="box"> |
|
127 | 128 | <div> |
|
128 | 129 | ## overview pulled by ajax |
|
129 | 130 | <div id="pull_request_overview"></div> |
|
130 | 131 | </div> |
|
131 | 132 | </div> |
|
132 | 133 | ${h.end_form()} |
|
133 | 134 | </div> |
|
134 | 135 | |
|
135 | 136 | <script type="text/javascript"> |
|
136 | 137 | $(function(){ |
|
137 | 138 | var defaultSourceRepo = '${c.default_repo_data['source_repo_name']}'; |
|
138 | 139 | var defaultSourceRepoData = ${c.default_repo_data['source_refs_json']|n}; |
|
139 | 140 | var defaultTargetRepo = '${c.default_repo_data['target_repo_name']}'; |
|
140 | 141 | var defaultTargetRepoData = ${c.default_repo_data['target_refs_json']|n}; |
|
141 | 142 | var targetRepoName = '${c.repo_name}'; |
|
142 | 143 | |
|
143 | 144 | var $pullRequestForm = $('#pull_request_form'); |
|
144 | 145 | var $sourceRepo = $('#source_repo', $pullRequestForm); |
|
145 | 146 | var $targetRepo = $('#target_repo', $pullRequestForm); |
|
146 | 147 | var $sourceRef = $('#source_ref', $pullRequestForm); |
|
147 | 148 | var $targetRef = $('#target_ref', $pullRequestForm); |
|
148 | 149 | |
|
149 | 150 | var calculateContainerWidth = function() { |
|
150 | 151 | var maxWidth = 0; |
|
151 | 152 | var repoSelect2Containers = ['#source_repo', '#target_repo']; |
|
152 | 153 | $.each(repoSelect2Containers, function(idx, value) { |
|
153 | 154 | $(value).select2('container').width('auto'); |
|
154 | 155 | var curWidth = $(value).select2('container').width(); |
|
155 | 156 | if (maxWidth <= curWidth) { |
|
156 | 157 | maxWidth = curWidth; |
|
157 | 158 | } |
|
158 | 159 | $.each(repoSelect2Containers, function(idx, value) { |
|
159 | 160 | $(value).select2('container').width(maxWidth + 10); |
|
160 | 161 | }); |
|
161 | 162 | }); |
|
162 | 163 | }; |
|
163 | 164 | |
|
164 | 165 | var initRefSelection = function(selectedRef) { |
|
165 | 166 | return function(element, callback) { |
|
166 | 167 | // translate our select2 id into a text, it's a mapping to show |
|
167 | 168 | // simple label when selecting by internal ID. |
|
168 | 169 | var id, refData; |
|
169 | 170 | if (selectedRef === undefined) { |
|
170 | 171 | id = element.val(); |
|
171 | 172 | refData = element.val().split(':'); |
|
172 | 173 | } else { |
|
173 | 174 | id = selectedRef; |
|
174 | 175 | refData = selectedRef.split(':'); |
|
175 | 176 | } |
|
176 | 177 | |
|
177 | 178 | var text = refData[1]; |
|
178 | 179 | if (refData[0] === 'rev') { |
|
179 | 180 | text = text.substring(0, 12); |
|
180 | 181 | } |
|
181 | 182 | |
|
182 | 183 | var data = {id: id, text: text}; |
|
183 | 184 | |
|
184 | 185 | callback(data); |
|
185 | 186 | }; |
|
186 | 187 | }; |
|
187 | 188 | |
|
188 | 189 | var formatRefSelection = function(item) { |
|
189 | 190 | var prefix = ''; |
|
190 | 191 | var refData = item.id.split(':'); |
|
191 | 192 | if (refData[0] === 'branch') { |
|
192 | 193 | prefix = '<i class="icon-branch"></i>'; |
|
193 | 194 | } |
|
194 | 195 | else if (refData[0] === 'book') { |
|
195 | 196 | prefix = '<i class="icon-bookmark"></i>'; |
|
196 | 197 | } |
|
197 | 198 | else if (refData[0] === 'tag') { |
|
198 | 199 | prefix = '<i class="icon-tag"></i>'; |
|
199 | 200 | } |
|
200 | 201 | |
|
201 | 202 | var originalOption = item.element; |
|
202 | 203 | return prefix + item.text; |
|
203 | 204 | }; |
|
204 | 205 | |
|
205 | 206 | // custom code mirror |
|
206 | 207 | var codeMirrorInstance = initPullRequestsCodeMirror('#pullrequest_desc'); |
|
207 | 208 | |
|
208 | 209 | var queryTargetRepo = function(self, query) { |
|
209 | 210 | // cache ALL results if query is empty |
|
210 | 211 | var cacheKey = query.term || '__'; |
|
211 | 212 | var cachedData = self.cachedDataSource[cacheKey]; |
|
212 | 213 | |
|
213 | 214 | if (cachedData) { |
|
214 | 215 | query.callback({results: cachedData.results}); |
|
215 | 216 | } else { |
|
216 | 217 | $.ajax({ |
|
217 | 218 | url: pyroutes.url('pullrequest_repo_destinations', {'repo_name': targetRepoName}), |
|
218 | 219 | data: {query: query.term}, |
|
219 | 220 | dataType: 'json', |
|
220 | 221 | type: 'GET', |
|
221 | 222 | success: function(data) { |
|
222 | 223 | self.cachedDataSource[cacheKey] = data; |
|
223 | 224 | query.callback({results: data.results}); |
|
224 | 225 | }, |
|
225 | 226 | error: function(data, textStatus, errorThrown) { |
|
226 | 227 | alert( |
|
227 | 228 | "Error while fetching entries.\nError code {0} ({1}).".format(data.status, data.statusText)); |
|
228 | 229 | } |
|
229 | 230 | }); |
|
230 | 231 | } |
|
231 | 232 | }; |
|
232 | 233 | |
|
233 | 234 | var queryTargetRefs = function(initialData, query) { |
|
234 | 235 | var data = {results: []}; |
|
235 | 236 | // filter initialData |
|
236 | 237 | $.each(initialData, function() { |
|
237 | 238 | var section = this.text; |
|
238 | 239 | var children = []; |
|
239 | 240 | $.each(this.children, function() { |
|
240 | 241 | if (query.term.length === 0 || |
|
241 | 242 | this.text.toUpperCase().indexOf(query.term.toUpperCase()) >= 0 ) { |
|
242 | 243 | children.push({'id': this.id, 'text': this.text}) |
|
243 | 244 | } |
|
244 | 245 | }); |
|
245 | 246 | data.results.push({'text': section, 'children': children}) |
|
246 | 247 | }); |
|
247 | 248 | query.callback({results: data.results}); |
|
248 | 249 | }; |
|
249 | 250 | |
|
250 | var prButtonLock = function(lockEnabled, msg) { | |
|
251 | ||
|
252 | var prButtonLockChecks = { | |
|
253 | 'compare': false, | |
|
254 | 'reviewers': false | |
|
255 | }; | |
|
256 | ||
|
257 | var prButtonLock = function(lockEnabled, msg, scope) { | |
|
258 | scope = scope || 'all'; | |
|
259 | if (scope == 'all'){ | |
|
260 | prButtonLockChecks['compare'] = !lockEnabled; | |
|
261 | prButtonLockChecks['reviewers'] = !lockEnabled; | |
|
262 | } else if (scope == 'compare') { | |
|
263 | prButtonLockChecks['compare'] = !lockEnabled; | |
|
264 | } else if (scope == 'reviewers'){ | |
|
265 | prButtonLockChecks['reviewers'] = !lockEnabled; | |
|
266 | } | |
|
267 | var checksMeet = prButtonLockChecks.compare && prButtonLockChecks.reviewers; | |
|
251 | 268 | if (lockEnabled) { |
|
252 | 269 | $('#save').attr('disabled', 'disabled'); |
|
253 | 270 | } |
|
254 | else { | |
|
271 | else if (checksMeet) { | |
|
255 | 272 | $('#save').removeAttr('disabled'); |
|
256 | 273 | } |
|
257 | 274 | |
|
258 | $('#pr_open_message').html(msg); | |
|
259 | ||
|
275 | if (msg) { | |
|
276 | $('#pr_open_message').html(msg); | |
|
277 | } | |
|
260 | 278 | }; |
|
261 | 279 | |
|
262 | 280 | var loadRepoRefDiffPreview = function() { |
|
263 | 281 | var sourceRepo = $sourceRepo.eq(0).val(); |
|
264 | 282 | var sourceRef = $sourceRef.eq(0).val().split(':'); |
|
265 | 283 | |
|
266 | 284 | var targetRepo = $targetRepo.eq(0).val(); |
|
267 | 285 | var targetRef = $targetRef.eq(0).val().split(':'); |
|
268 | 286 | |
|
269 | 287 | var url_data = { |
|
270 | 288 | 'repo_name': targetRepo, |
|
271 | 289 | 'target_repo': sourceRepo, |
|
272 | 290 | 'source_ref': targetRef[2], |
|
273 | 291 | 'source_ref_type': 'rev', |
|
274 | 292 | 'target_ref': sourceRef[2], |
|
275 | 293 | 'target_ref_type': 'rev', |
|
276 | 294 | 'merge': true, |
|
277 | 295 | '_': Date.now() // bypass browser caching |
|
278 | 296 | }; // gather the source/target ref and repo here |
|
279 | 297 | |
|
280 | 298 | if (sourceRef.length !== 3 || targetRef.length !== 3) { |
|
281 | 299 | prButtonLock(true, "${_('Please select origin and destination')}"); |
|
282 | 300 | return; |
|
283 | 301 | } |
|
284 | 302 | var url = pyroutes.url('compare_url', url_data); |
|
285 | 303 | |
|
286 | 304 | // lock PR button, so we cannot send PR before it's calculated |
|
287 | prButtonLock(true, "${_('Loading compare ...')}"); | |
|
305 | prButtonLock(true, "${_('Loading compare ...')}", 'compare'); | |
|
288 | 306 | |
|
289 | 307 | if (loadRepoRefDiffPreview._currentRequest) { |
|
290 | 308 | loadRepoRefDiffPreview._currentRequest.abort(); |
|
291 | 309 | } |
|
292 | 310 | |
|
293 | 311 | loadRepoRefDiffPreview._currentRequest = $.get(url) |
|
294 | 312 | .error(function(data, textStatus, errorThrown) { |
|
295 | 313 | alert( |
|
296 | 314 | "Error while processing request.\nError code {0} ({1}).".format( |
|
297 | 315 | data.status, data.statusText)); |
|
298 | 316 | }) |
|
299 | 317 | .done(function(data) { |
|
300 | 318 | loadRepoRefDiffPreview._currentRequest = null; |
|
301 | 319 | $('#pull_request_overview').html(data); |
|
302 | 320 | var commitElements = $(data).find('tr[commit_id]'); |
|
303 | 321 | |
|
304 | 322 | var prTitleAndDesc = getTitleAndDescription(sourceRef[1], |
|
305 | 323 | commitElements, 5); |
|
306 | 324 | |
|
307 | 325 | var title = prTitleAndDesc[0]; |
|
308 | 326 | var proposedDescription = prTitleAndDesc[1]; |
|
309 | 327 | |
|
310 | 328 | var useGeneratedTitle = ( |
|
311 | 329 | $('#pullrequest_title').hasClass('autogenerated-title') || |
|
312 | 330 | $('#pullrequest_title').val() === ""); |
|
313 | 331 | |
|
314 | 332 | if (title && useGeneratedTitle) { |
|
315 | 333 | // use generated title if we haven't specified our own |
|
316 | 334 | $('#pullrequest_title').val(title); |
|
317 | 335 | $('#pullrequest_title').addClass('autogenerated-title'); |
|
318 | 336 | |
|
319 | 337 | } |
|
320 | 338 | |
|
321 | 339 | var useGeneratedDescription = ( |
|
322 | 340 | !codeMirrorInstance._userDefinedDesc || |
|
323 | 341 | codeMirrorInstance.getValue() === ""); |
|
324 | 342 | |
|
325 | 343 | if (proposedDescription && useGeneratedDescription) { |
|
326 | 344 | // set proposed content, if we haven't defined our own, |
|
327 | 345 | // or we don't have description written |
|
328 | 346 | codeMirrorInstance._userDefinedDesc = false; // reset state |
|
329 | 347 | codeMirrorInstance.setValue(proposedDescription); |
|
330 | 348 | } |
|
331 | 349 | |
|
332 | 350 | var msg = ''; |
|
333 | 351 | if (commitElements.length === 1) { |
|
334 | 352 | msg = "${ungettext('This pull request will consist of __COMMITS__ commit.', 'This pull request will consist of __COMMITS__ commits.', 1)}"; |
|
335 | 353 | } else { |
|
336 | 354 | msg = "${ungettext('This pull request will consist of __COMMITS__ commit.', 'This pull request will consist of __COMMITS__ commits.', 2)}"; |
|
337 | 355 | } |
|
338 | 356 | |
|
339 | 357 | msg += ' <a id="pull_request_overview_url" href="{0}" target="_blank">${_('Show detailed compare.')}</a>'.format(url); |
|
340 | 358 | |
|
341 | 359 | if (commitElements.length) { |
|
342 | 360 | var commitsLink = '<a href="#pull_request_overview"><strong>{0}</strong></a>'.format(commitElements.length); |
|
343 | prButtonLock(false, msg.replace('__COMMITS__', commitsLink)); | |
|
361 | prButtonLock(false, msg.replace('__COMMITS__', commitsLink), 'compare'); | |
|
344 | 362 | } |
|
345 | 363 | else { |
|
346 | prButtonLock(true, "${_('There are no commits to merge.')}"); | |
|
364 | prButtonLock(true, "${_('There are no commits to merge.')}", 'compare'); | |
|
347 | 365 | } |
|
348 | 366 | |
|
349 | 367 | |
|
350 | 368 | }); |
|
351 | 369 | }; |
|
352 | 370 | |
|
353 | 371 | /** |
|
354 | 372 | Generate Title and Description for a PullRequest. |
|
355 | 373 | In case of 1 commits, the title and description is that one commit |
|
356 | 374 | in case of multiple commits, we iterate on them with max N number of commits, |
|
357 | 375 | and build description in a form |
|
358 | 376 | - commitN |
|
359 | 377 | - commitN+1 |
|
360 | 378 | ... |
|
361 | 379 | |
|
362 | 380 | Title is then constructed from branch names, or other references, |
|
363 | 381 | replacing '-' and '_' into spaces |
|
364 | 382 | |
|
365 | 383 | * @param sourceRef |
|
366 | 384 | * @param elements |
|
367 | 385 | * @param limit |
|
368 | 386 | * @returns {*[]} |
|
369 | 387 | */ |
|
370 | 388 | var getTitleAndDescription = function(sourceRef, elements, limit) { |
|
371 | 389 | var title = ''; |
|
372 | 390 | var desc = ''; |
|
373 | 391 | |
|
374 | 392 | $.each($(elements).get().reverse().slice(0, limit), function(idx, value) { |
|
375 | 393 | var rawMessage = $(value).find('td.td-description .message').data('messageRaw'); |
|
376 | 394 | desc += '- ' + rawMessage.split('\n')[0].replace(/\n+$/, "") + '\n'; |
|
377 | 395 | }); |
|
378 | 396 | // only 1 commit, use commit message as title |
|
379 | 397 | if (elements.length == 1) { |
|
380 | 398 | title = $(elements[0]).find('td.td-description .message').data('messageRaw').split('\n')[0]; |
|
381 | 399 | } |
|
382 | 400 | else { |
|
383 | 401 | // use reference name |
|
384 | 402 | title = sourceRef.replace(/-/g, ' ').replace(/_/g, ' ').capitalizeFirstLetter(); |
|
385 | 403 | } |
|
386 | 404 | |
|
387 | 405 | return [title, desc] |
|
388 | 406 | }; |
|
389 | 407 | |
|
390 | 408 | var Select2Box = function(element, overrides) { |
|
391 | 409 | var globalDefaults = { |
|
392 | 410 | dropdownAutoWidth: true, |
|
393 | 411 | containerCssClass: "drop-menu", |
|
394 |
dropdownCssClass: "drop-menu-dropdown" |
|
|
412 | dropdownCssClass: "drop-menu-dropdown" | |
|
395 | 413 | }; |
|
396 | 414 | |
|
397 | 415 | var initSelect2 = function(defaultOptions) { |
|
398 | 416 | var options = jQuery.extend(globalDefaults, defaultOptions, overrides); |
|
399 | 417 | element.select2(options); |
|
400 | 418 | }; |
|
401 | 419 | |
|
402 | 420 | return { |
|
403 | 421 | initRef: function() { |
|
404 | 422 | var defaultOptions = { |
|
405 | 423 | minimumResultsForSearch: 5, |
|
406 | 424 | formatSelection: formatRefSelection |
|
407 | 425 | }; |
|
408 | 426 | |
|
409 | 427 | initSelect2(defaultOptions); |
|
410 | 428 | }, |
|
411 | 429 | |
|
412 | 430 | initRepo: function(defaultValue, readOnly) { |
|
413 | 431 | var defaultOptions = { |
|
414 | 432 | initSelection : function (element, callback) { |
|
415 | 433 | var data = {id: defaultValue, text: defaultValue}; |
|
416 | 434 | callback(data); |
|
417 | 435 | } |
|
418 | 436 | }; |
|
419 | 437 | |
|
420 | 438 | initSelect2(defaultOptions); |
|
421 | 439 | |
|
422 | 440 | element.select2('val', defaultSourceRepo); |
|
423 | 441 | if (readOnly === true) { |
|
424 | 442 | element.select2('readonly', true); |
|
425 |
} |
|
|
443 | } | |
|
426 | 444 | } |
|
427 | 445 | }; |
|
428 | 446 | }; |
|
429 | 447 | |
|
430 | 448 | var initTargetRefs = function(refsData, selectedRef){ |
|
431 | 449 | Select2Box($targetRef, { |
|
432 | 450 | query: function(query) { |
|
433 | 451 | queryTargetRefs(refsData, query); |
|
434 | 452 | }, |
|
435 | 453 | initSelection : initRefSelection(selectedRef) |
|
436 | 454 | }).initRef(); |
|
437 | 455 | |
|
438 | 456 | if (!(selectedRef === undefined)) { |
|
439 | 457 | $targetRef.select2('val', selectedRef); |
|
440 | 458 | } |
|
441 | 459 | }; |
|
442 | 460 | |
|
443 | 461 | var targetRepoChanged = function(repoData) { |
|
444 | 462 | // generate new DESC of target repo displayed next to select |
|
445 | 463 | $('#target_repo_desc').html( |
|
446 | 464 | "<strong>${_('Destination repository')}</strong>: {0}".format(repoData['description']) |
|
447 | 465 | ); |
|
448 | 466 | |
|
449 | 467 | // generate dynamic select2 for refs. |
|
450 | 468 | initTargetRefs(repoData['refs']['select2_refs'], |
|
451 | 469 | repoData['refs']['selected_ref']); |
|
452 | 470 | |
|
453 | 471 | }; |
|
454 | 472 | |
|
455 | 473 | var sourceRefSelect2 = Select2Box( |
|
456 | 474 | $sourceRef, { |
|
457 | 475 | placeholder: "${_('Select commit reference')}", |
|
458 | 476 | query: function(query) { |
|
459 | 477 | var initialData = defaultSourceRepoData['refs']['select2_refs']; |
|
460 | 478 | queryTargetRefs(initialData, query) |
|
461 | 479 | }, |
|
462 | 480 | initSelection: initRefSelection() |
|
463 | 481 | } |
|
464 | 482 | ); |
|
465 | 483 | |
|
466 | 484 | var sourceRepoSelect2 = Select2Box($sourceRepo, { |
|
467 | 485 | query: function(query) {} |
|
468 | 486 | }); |
|
469 | 487 | |
|
470 | 488 | var targetRepoSelect2 = Select2Box($targetRepo, { |
|
471 | 489 | cachedDataSource: {}, |
|
472 | 490 | query: $.debounce(250, function(query) { |
|
473 | 491 | queryTargetRepo(this, query); |
|
474 | 492 | }), |
|
475 | 493 | formatResult: formatResult |
|
476 | 494 | }); |
|
477 | 495 | |
|
478 | 496 | sourceRefSelect2.initRef(); |
|
479 | 497 | |
|
480 | 498 | sourceRepoSelect2.initRepo(defaultSourceRepo, true); |
|
481 | 499 | |
|
482 | 500 | targetRepoSelect2.initRepo(defaultTargetRepo, false); |
|
483 | 501 | |
|
484 | 502 | $sourceRef.on('change', function(e){ |
|
485 | 503 | loadRepoRefDiffPreview(); |
|
486 | 504 | loadDefaultReviewers(); |
|
487 | 505 | }); |
|
488 | 506 | |
|
489 | 507 | $targetRef.on('change', function(e){ |
|
490 | 508 | loadRepoRefDiffPreview(); |
|
491 | 509 | loadDefaultReviewers(); |
|
492 | 510 | }); |
|
493 | 511 | |
|
494 | 512 | $targetRepo.on('change', function(e){ |
|
495 | 513 | var repoName = $(this).val(); |
|
496 | 514 | calculateContainerWidth(); |
|
497 | 515 | $targetRef.select2('destroy'); |
|
498 | 516 | $('#target_ref_loading').show(); |
|
499 | 517 | |
|
500 | 518 | $.ajax({ |
|
501 | 519 | url: pyroutes.url('pullrequest_repo_refs', |
|
502 | 520 | {'repo_name': targetRepoName, 'target_repo_name':repoName}), |
|
503 | 521 | data: {}, |
|
504 | 522 | dataType: 'json', |
|
505 | 523 | type: 'GET', |
|
506 | 524 | success: function(data) { |
|
507 | 525 | $('#target_ref_loading').hide(); |
|
508 | 526 | targetRepoChanged(data); |
|
509 | 527 | loadRepoRefDiffPreview(); |
|
510 | 528 | }, |
|
511 | 529 | error: function(data, textStatus, errorThrown) { |
|
512 | 530 | alert("Error while fetching entries.\nError code {0} ({1}).".format(data.status, data.statusText)); |
|
513 | 531 | } |
|
514 | 532 | }) |
|
515 | 533 | |
|
516 | 534 | }); |
|
517 | 535 | |
|
518 | 536 | var loadDefaultReviewers = function() { |
|
519 | 537 | if (loadDefaultReviewers._currentRequest) { |
|
520 | 538 | loadDefaultReviewers._currentRequest.abort(); |
|
521 | 539 | } |
|
540 | $('.calculate-reviewers').show(); | |
|
541 | prButtonLock(true, null, 'reviewers'); | |
|
542 | ||
|
522 | 543 | var url = pyroutes.url('repo_default_reviewers_data', {'repo_name': targetRepoName}); |
|
523 | 544 | |
|
524 | 545 | var sourceRepo = $sourceRepo.eq(0).val(); |
|
525 | 546 | var sourceRef = $sourceRef.eq(0).val().split(':'); |
|
526 | 547 | var targetRepo = $targetRepo.eq(0).val(); |
|
527 | 548 | var targetRef = $targetRef.eq(0).val().split(':'); |
|
528 | 549 | url += '?source_repo=' + sourceRepo; |
|
529 | 550 | url += '&source_ref=' + sourceRef[2]; |
|
530 | 551 | url += '&target_repo=' + targetRepo; |
|
531 | 552 | url += '&target_ref=' + targetRef[2]; |
|
532 | 553 | |
|
533 | 554 | loadDefaultReviewers._currentRequest = $.get(url) |
|
534 |
|
|
|
555 | .done(function(data) { | |
|
535 | 556 | loadDefaultReviewers._currentRequest = null; |
|
536 | 557 | |
|
537 | 558 | // reset && add the reviewer based on selected repo |
|
538 | 559 | $('#review_members').html(''); |
|
539 | 560 | for (var i = 0; i < data.reviewers.length; i++) { |
|
540 | 561 | var reviewer = data.reviewers[i]; |
|
541 | 562 | addReviewMember( |
|
542 | 563 | reviewer.user_id, reviewer.firstname, |
|
543 | 564 | reviewer.lastname, reviewer.username, |
|
544 | 565 | reviewer.gravatar_link, reviewer.reasons); |
|
545 | 566 | } |
|
546 | }); | |
|
567 | $('.calculate-reviewers').hide(); | |
|
568 | prButtonLock(false, null, 'reviewers'); | |
|
569 | }); | |
|
547 | 570 | }; |
|
548 | prButtonLock(true, "${_('Please select origin and destination')}"); | |
|
571 | ||
|
572 | prButtonLock(true, "${_('Please select origin and destination')}", 'all'); | |
|
549 | 573 | |
|
550 | 574 | // auto-load on init, the target refs select2 |
|
551 | 575 | calculateContainerWidth(); |
|
552 | 576 | targetRepoChanged(defaultTargetRepoData); |
|
553 | 577 | |
|
554 | 578 | $('#pullrequest_title').on('keyup', function(e){ |
|
555 | 579 | $(this).removeClass('autogenerated-title'); |
|
556 | 580 | }); |
|
557 | 581 | |
|
558 | %if c.default_source_ref: | |
|
582 | % if c.default_source_ref: | |
|
559 | 583 | // in case we have a pre-selected value, use it now |
|
560 | 584 | $sourceRef.select2('val', '${c.default_source_ref}'); |
|
561 | 585 | loadRepoRefDiffPreview(); |
|
562 | 586 | loadDefaultReviewers(); |
|
563 | %endif | |
|
587 | % endif | |
|
564 | 588 | |
|
565 | 589 | ReviewerAutoComplete('user'); |
|
566 | 590 | }); |
|
567 | 591 | </script> |
|
568 | 592 | |
|
569 | 593 | </%def> |
General Comments 0
You need to be logged in to leave comments.
Login now