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