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