Show More
@@ -1,657 +1,659 b'' | |||
|
1 | 1 | // # Copyright (C) 2010-2020 RhodeCode GmbH |
|
2 | 2 | // # |
|
3 | 3 | // # This program is free software: you can redistribute it and/or modify |
|
4 | 4 | // # it under the terms of the GNU Affero General Public License, version 3 |
|
5 | 5 | // # (only), as published by the Free Software Foundation. |
|
6 | 6 | // # |
|
7 | 7 | // # This program is distributed in the hope that it will be useful, |
|
8 | 8 | // # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 | 9 | // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 | 10 | // # GNU General Public License for more details. |
|
11 | 11 | // # |
|
12 | 12 | // # You should have received a copy of the GNU Affero General Public License |
|
13 | 13 | // # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
14 | 14 | // # |
|
15 | 15 | // # This program is dual-licensed. If you wish to learn more about the |
|
16 | 16 | // # RhodeCode Enterprise Edition, including its added features, Support services, |
|
17 | 17 | // # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
18 | 18 | |
|
19 | 19 | |
|
20 | 20 | var prButtonLockChecks = { |
|
21 | 21 | 'compare': false, |
|
22 | 22 | 'reviewers': false |
|
23 | 23 | }; |
|
24 | 24 | |
|
25 | 25 | /** |
|
26 | 26 | * lock button until all checks and loads are made. E.g reviewer calculation |
|
27 | 27 | * should prevent from submitting a PR |
|
28 | 28 | * @param lockEnabled |
|
29 | 29 | * @param msg |
|
30 | 30 | * @param scope |
|
31 | 31 | */ |
|
32 | 32 | var prButtonLock = function(lockEnabled, msg, scope) { |
|
33 | 33 | scope = scope || 'all'; |
|
34 | 34 | if (scope == 'all'){ |
|
35 | 35 | prButtonLockChecks['compare'] = !lockEnabled; |
|
36 | 36 | prButtonLockChecks['reviewers'] = !lockEnabled; |
|
37 | 37 | } else if (scope == 'compare') { |
|
38 | 38 | prButtonLockChecks['compare'] = !lockEnabled; |
|
39 | 39 | } else if (scope == 'reviewers'){ |
|
40 | 40 | prButtonLockChecks['reviewers'] = !lockEnabled; |
|
41 | 41 | } |
|
42 | 42 | var checksMeet = prButtonLockChecks.compare && prButtonLockChecks.reviewers; |
|
43 | 43 | if (lockEnabled) { |
|
44 | 44 | $('#pr_submit').attr('disabled', 'disabled'); |
|
45 | 45 | } |
|
46 | 46 | else if (checksMeet) { |
|
47 | 47 | $('#pr_submit').removeAttr('disabled'); |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | if (msg) { |
|
51 | 51 | $('#pr_open_message').html(msg); |
|
52 | 52 | } |
|
53 | 53 | }; |
|
54 | 54 | |
|
55 | 55 | |
|
56 | 56 | /** |
|
57 | 57 | Generate Title and Description for a PullRequest. |
|
58 | 58 | In case of 1 commits, the title and description is that one commit |
|
59 | 59 | in case of multiple commits, we iterate on them with max N number of commits, |
|
60 | 60 | and build description in a form |
|
61 | 61 | - commitN |
|
62 | 62 | - commitN+1 |
|
63 | 63 | ... |
|
64 | 64 | |
|
65 | 65 | Title is then constructed from branch names, or other references, |
|
66 | 66 | replacing '-' and '_' into spaces |
|
67 | 67 | |
|
68 | 68 | * @param sourceRef |
|
69 | 69 | * @param elements |
|
70 | 70 | * @param limit |
|
71 | 71 | * @returns {*[]} |
|
72 | 72 | */ |
|
73 | var getTitleAndDescription = function(sourceRef, elements, limit) { | |
|
73 | var getTitleAndDescription = function(sourceRefType, sourceRef, elements, limit) { | |
|
74 | 74 | var title = ''; |
|
75 | 75 | var desc = ''; |
|
76 | 76 | |
|
77 | 77 | $.each($(elements).get().reverse().slice(0, limit), function(idx, value) { |
|
78 | 78 | var rawMessage = value['message']; |
|
79 | 79 | desc += '- ' + rawMessage.split('\n')[0].replace(/\n+$/, "") + '\n'; |
|
80 | 80 | }); |
|
81 | 81 | // only 1 commit, use commit message as title |
|
82 | 82 | if (elements.length === 1) { |
|
83 | 83 | var rawMessage = elements[0]['message']; |
|
84 | 84 | title = rawMessage.split('\n')[0]; |
|
85 | 85 | } |
|
86 | 86 | else { |
|
87 | 87 | // use reference name |
|
88 |
|
|
|
88 | var normalizedRef = sourceRef.replace(/-/g, ' ').replace(/_/g, ' ').capitalizeFirstLetter() | |
|
89 | var refType = sourceRefType; | |
|
90 | title = 'Changes from {0}: {1}'.format(refType, normalizedRef); | |
|
89 | 91 | } |
|
90 | 92 | |
|
91 | 93 | return [title, desc] |
|
92 | 94 | }; |
|
93 | 95 | |
|
94 | 96 | |
|
95 | 97 | ReviewersController = function () { |
|
96 | 98 | var self = this; |
|
97 | 99 | this.$reviewRulesContainer = $('#review_rules'); |
|
98 | 100 | this.$rulesList = this.$reviewRulesContainer.find('.pr-reviewer-rules'); |
|
99 | 101 | this.forbidReviewUsers = undefined; |
|
100 | 102 | this.$reviewMembers = $('#review_members'); |
|
101 | 103 | this.currentRequest = null; |
|
102 | 104 | this.diffData = null; |
|
103 | 105 | //dummy handler, we might register our own later |
|
104 | 106 | this.diffDataHandler = function(data){}; |
|
105 | 107 | |
|
106 | 108 | this.defaultForbidReviewUsers = function () { |
|
107 | 109 | return [ |
|
108 | 110 | { |
|
109 | 111 | 'username': 'default', |
|
110 | 112 | 'user_id': templateContext.default_user.user_id |
|
111 | 113 | } |
|
112 | 114 | ]; |
|
113 | 115 | }; |
|
114 | 116 | |
|
115 | 117 | this.hideReviewRules = function () { |
|
116 | 118 | self.$reviewRulesContainer.hide(); |
|
117 | 119 | }; |
|
118 | 120 | |
|
119 | 121 | this.showReviewRules = function () { |
|
120 | 122 | self.$reviewRulesContainer.show(); |
|
121 | 123 | }; |
|
122 | 124 | |
|
123 | 125 | this.addRule = function (ruleText) { |
|
124 | 126 | self.showReviewRules(); |
|
125 | 127 | return '<div>- {0}</div>'.format(ruleText) |
|
126 | 128 | }; |
|
127 | 129 | |
|
128 | 130 | this.loadReviewRules = function (data) { |
|
129 | 131 | self.diffData = data; |
|
130 | 132 | |
|
131 | 133 | // reset forbidden Users |
|
132 | 134 | this.forbidReviewUsers = self.defaultForbidReviewUsers(); |
|
133 | 135 | |
|
134 | 136 | // reset state of review rules |
|
135 | 137 | self.$rulesList.html(''); |
|
136 | 138 | |
|
137 | 139 | if (!data || data.rules === undefined || $.isEmptyObject(data.rules)) { |
|
138 | 140 | // default rule, case for older repo that don't have any rules stored |
|
139 | 141 | self.$rulesList.append( |
|
140 | 142 | self.addRule( |
|
141 | 143 | _gettext('All reviewers must vote.')) |
|
142 | 144 | ); |
|
143 | 145 | return self.forbidReviewUsers |
|
144 | 146 | } |
|
145 | 147 | |
|
146 | 148 | if (data.rules.voting !== undefined) { |
|
147 | 149 | if (data.rules.voting < 0) { |
|
148 | 150 | self.$rulesList.append( |
|
149 | 151 | self.addRule( |
|
150 | 152 | _gettext('All individual reviewers must vote.')) |
|
151 | 153 | ) |
|
152 | 154 | } else if (data.rules.voting === 1) { |
|
153 | 155 | self.$rulesList.append( |
|
154 | 156 | self.addRule( |
|
155 | 157 | _gettext('At least {0} reviewer must vote.').format(data.rules.voting)) |
|
156 | 158 | ) |
|
157 | 159 | |
|
158 | 160 | } else { |
|
159 | 161 | self.$rulesList.append( |
|
160 | 162 | self.addRule( |
|
161 | 163 | _gettext('At least {0} reviewers must vote.').format(data.rules.voting)) |
|
162 | 164 | ) |
|
163 | 165 | } |
|
164 | 166 | } |
|
165 | 167 | |
|
166 | 168 | if (data.rules.voting_groups !== undefined) { |
|
167 | 169 | $.each(data.rules.voting_groups, function (index, rule_data) { |
|
168 | 170 | self.$rulesList.append( |
|
169 | 171 | self.addRule(rule_data.text) |
|
170 | 172 | ) |
|
171 | 173 | }); |
|
172 | 174 | } |
|
173 | 175 | |
|
174 | 176 | if (data.rules.use_code_authors_for_review) { |
|
175 | 177 | self.$rulesList.append( |
|
176 | 178 | self.addRule( |
|
177 | 179 | _gettext('Reviewers picked from source code changes.')) |
|
178 | 180 | ) |
|
179 | 181 | } |
|
180 | 182 | if (data.rules.forbid_adding_reviewers) { |
|
181 | 183 | $('#add_reviewer_input').remove(); |
|
182 | 184 | self.$rulesList.append( |
|
183 | 185 | self.addRule( |
|
184 | 186 | _gettext('Adding new reviewers is forbidden.')) |
|
185 | 187 | ) |
|
186 | 188 | } |
|
187 | 189 | if (data.rules.forbid_author_to_review) { |
|
188 | 190 | self.forbidReviewUsers.push(data.rules_data.pr_author); |
|
189 | 191 | self.$rulesList.append( |
|
190 | 192 | self.addRule( |
|
191 | 193 | _gettext('Author is not allowed to be a reviewer.')) |
|
192 | 194 | ) |
|
193 | 195 | } |
|
194 | 196 | if (data.rules.forbid_commit_author_to_review) { |
|
195 | 197 | |
|
196 | 198 | if (data.rules_data.forbidden_users) { |
|
197 | 199 | $.each(data.rules_data.forbidden_users, function (index, member_data) { |
|
198 | 200 | self.forbidReviewUsers.push(member_data) |
|
199 | 201 | }); |
|
200 | 202 | |
|
201 | 203 | } |
|
202 | 204 | |
|
203 | 205 | self.$rulesList.append( |
|
204 | 206 | self.addRule( |
|
205 | 207 | _gettext('Commit Authors are not allowed to be a reviewer.')) |
|
206 | 208 | ) |
|
207 | 209 | } |
|
208 | 210 | |
|
209 | 211 | return self.forbidReviewUsers |
|
210 | 212 | }; |
|
211 | 213 | |
|
212 | 214 | this.loadDefaultReviewers = function (sourceRepo, sourceRef, targetRepo, targetRef) { |
|
213 | 215 | |
|
214 | 216 | if (self.currentRequest) { |
|
215 | 217 | // make sure we cleanup old running requests before triggering this again |
|
216 | 218 | self.currentRequest.abort(); |
|
217 | 219 | } |
|
218 | 220 | |
|
219 | 221 | $('.calculate-reviewers').show(); |
|
220 | 222 | // reset reviewer members |
|
221 | 223 | self.$reviewMembers.empty(); |
|
222 | 224 | |
|
223 | 225 | prButtonLock(true, null, 'reviewers'); |
|
224 | 226 | $('#user').hide(); // hide user autocomplete before load |
|
225 | 227 | |
|
226 | 228 | // lock PR button, so we cannot send PR before it's calculated |
|
227 | 229 | prButtonLock(true, _gettext('Loading diff ...'), 'compare'); |
|
228 | 230 | |
|
229 | 231 | if (sourceRef.length !== 3 || targetRef.length !== 3) { |
|
230 | 232 | // don't load defaults in case we're missing some refs... |
|
231 | 233 | $('.calculate-reviewers').hide(); |
|
232 | 234 | return |
|
233 | 235 | } |
|
234 | 236 | |
|
235 | 237 | var url = pyroutes.url('repo_default_reviewers_data', |
|
236 | 238 | { |
|
237 | 239 | 'repo_name': templateContext.repo_name, |
|
238 | 240 | 'source_repo': sourceRepo, |
|
239 | 241 | 'source_ref': sourceRef[2], |
|
240 | 242 | 'target_repo': targetRepo, |
|
241 | 243 | 'target_ref': targetRef[2] |
|
242 | 244 | }); |
|
243 | 245 | |
|
244 | 246 | self.currentRequest = $.ajax({ |
|
245 | 247 | url: url, |
|
246 | 248 | headers: {'X-PARTIAL-XHR': true}, |
|
247 | 249 | type: 'GET', |
|
248 | 250 | success: function (data) { |
|
249 | 251 | |
|
250 | 252 | self.currentRequest = null; |
|
251 | 253 | |
|
252 | 254 | // review rules |
|
253 | 255 | self.loadReviewRules(data); |
|
254 | 256 | self.handleDiffData(data["diff_info"]); |
|
255 | 257 | |
|
256 | 258 | for (var i = 0; i < data.reviewers.length; i++) { |
|
257 | 259 | var reviewer = data.reviewers[i]; |
|
258 | 260 | self.addReviewMember(reviewer, reviewer.reasons, reviewer.mandatory); |
|
259 | 261 | } |
|
260 | 262 | $('.calculate-reviewers').hide(); |
|
261 | 263 | prButtonLock(false, null, 'reviewers'); |
|
262 | 264 | $('#user').show(); // show user autocomplete after load |
|
263 | 265 | |
|
264 | 266 | var commitElements = data["diff_info"]['commits']; |
|
265 | 267 | if (commitElements.length === 0) { |
|
266 | 268 | prButtonLock(true, _gettext('no commits'), 'all'); |
|
267 | 269 | |
|
268 | 270 | } else { |
|
269 | 271 | // un-lock PR button, so we cannot send PR before it's calculated |
|
270 | 272 | prButtonLock(false, null, 'compare'); |
|
271 | 273 | } |
|
272 | 274 | |
|
273 | 275 | }, |
|
274 | 276 | error: function (jqXHR, textStatus, errorThrown) { |
|
275 | 277 | var prefix = "Loading diff and reviewers failed\n" |
|
276 | 278 | var message = formatErrorMessage(jqXHR, textStatus, errorThrown, prefix); |
|
277 | 279 | ajaxErrorSwal(message); |
|
278 | 280 | } |
|
279 | 281 | }); |
|
280 | 282 | |
|
281 | 283 | }; |
|
282 | 284 | |
|
283 | 285 | // check those, refactor |
|
284 | 286 | this.removeReviewMember = function (reviewer_id, mark_delete) { |
|
285 | 287 | var reviewer = $('#reviewer_{0}'.format(reviewer_id)); |
|
286 | 288 | |
|
287 | 289 | if (typeof (mark_delete) === undefined) { |
|
288 | 290 | mark_delete = false; |
|
289 | 291 | } |
|
290 | 292 | |
|
291 | 293 | if (mark_delete === true) { |
|
292 | 294 | if (reviewer) { |
|
293 | 295 | // now delete the input |
|
294 | 296 | $('#reviewer_{0} input'.format(reviewer_id)).remove(); |
|
295 | 297 | // mark as to-delete |
|
296 | 298 | var obj = $('#reviewer_{0}_name'.format(reviewer_id)); |
|
297 | 299 | obj.addClass('to-delete'); |
|
298 | 300 | obj.css({"text-decoration": "line-through", "opacity": 0.5}); |
|
299 | 301 | } |
|
300 | 302 | } else { |
|
301 | 303 | $('#reviewer_{0}'.format(reviewer_id)).remove(); |
|
302 | 304 | } |
|
303 | 305 | }; |
|
304 | 306 | |
|
305 | 307 | this.reviewMemberEntry = function () { |
|
306 | 308 | |
|
307 | 309 | }; |
|
308 | 310 | |
|
309 | 311 | this.addReviewMember = function (reviewer_obj, reasons, mandatory) { |
|
310 | 312 | var members = self.$reviewMembers.get(0); |
|
311 | 313 | var id = reviewer_obj.user_id; |
|
312 | 314 | var username = reviewer_obj.username; |
|
313 | 315 | |
|
314 | 316 | var reasons = reasons || []; |
|
315 | 317 | var mandatory = mandatory || false; |
|
316 | 318 | |
|
317 | 319 | // register IDS to check if we don't have this ID already in |
|
318 | 320 | var currentIds = []; |
|
319 | 321 | var _els = self.$reviewMembers.find('li').toArray(); |
|
320 | 322 | for (el in _els) { |
|
321 | 323 | currentIds.push(_els[el].id) |
|
322 | 324 | } |
|
323 | 325 | |
|
324 | 326 | var userAllowedReview = function (userId) { |
|
325 | 327 | var allowed = true; |
|
326 | 328 | $.each(self.forbidReviewUsers, function (index, member_data) { |
|
327 | 329 | if (parseInt(userId) === member_data['user_id']) { |
|
328 | 330 | allowed = false; |
|
329 | 331 | return false // breaks the loop |
|
330 | 332 | } |
|
331 | 333 | }); |
|
332 | 334 | return allowed |
|
333 | 335 | }; |
|
334 | 336 | |
|
335 | 337 | var userAllowed = userAllowedReview(id); |
|
336 | 338 | if (!userAllowed) { |
|
337 | 339 | alert(_gettext('User `{0}` not allowed to be a reviewer').format(username)); |
|
338 | 340 | } else { |
|
339 | 341 | // only add if it's not there |
|
340 | 342 | var alreadyReviewer = currentIds.indexOf('reviewer_' + id) != -1; |
|
341 | 343 | |
|
342 | 344 | if (alreadyReviewer) { |
|
343 | 345 | alert(_gettext('User `{0}` already in reviewers').format(username)); |
|
344 | 346 | } else { |
|
345 | 347 | members.innerHTML += renderTemplate('reviewMemberEntry', { |
|
346 | 348 | 'member': reviewer_obj, |
|
347 | 349 | 'mandatory': mandatory, |
|
348 | 350 | 'allowed_to_update': true, |
|
349 | 351 | 'review_status': 'not_reviewed', |
|
350 | 352 | 'review_status_label': _gettext('Not Reviewed'), |
|
351 | 353 | 'reasons': reasons, |
|
352 | 354 | 'create': true |
|
353 | 355 | }); |
|
354 | 356 | tooltipActivate(); |
|
355 | 357 | } |
|
356 | 358 | } |
|
357 | 359 | |
|
358 | 360 | }; |
|
359 | 361 | |
|
360 | 362 | this.updateReviewers = function (repo_name, pull_request_id) { |
|
361 | 363 | var postData = $('#reviewers input').serialize(); |
|
362 | 364 | _updatePullRequest(repo_name, pull_request_id, postData); |
|
363 | 365 | }; |
|
364 | 366 | |
|
365 | 367 | this.handleDiffData = function (data) { |
|
366 | 368 | self.diffDataHandler(data) |
|
367 | 369 | } |
|
368 | 370 | }; |
|
369 | 371 | |
|
370 | 372 | |
|
371 | 373 | var _updatePullRequest = function(repo_name, pull_request_id, postData) { |
|
372 | 374 | var url = pyroutes.url( |
|
373 | 375 | 'pullrequest_update', |
|
374 | 376 | {"repo_name": repo_name, "pull_request_id": pull_request_id}); |
|
375 | 377 | if (typeof postData === 'string' ) { |
|
376 | 378 | postData += '&csrf_token=' + CSRF_TOKEN; |
|
377 | 379 | } else { |
|
378 | 380 | postData.csrf_token = CSRF_TOKEN; |
|
379 | 381 | } |
|
380 | 382 | |
|
381 | 383 | var success = function(o) { |
|
382 | 384 | var redirectUrl = o['redirect_url']; |
|
383 | 385 | if (redirectUrl !== undefined && redirectUrl !== null && redirectUrl !== '') { |
|
384 | 386 | window.location = redirectUrl; |
|
385 | 387 | } else { |
|
386 | 388 | window.location.reload(); |
|
387 | 389 | } |
|
388 | 390 | }; |
|
389 | 391 | |
|
390 | 392 | ajaxPOST(url, postData, success); |
|
391 | 393 | }; |
|
392 | 394 | |
|
393 | 395 | /** |
|
394 | 396 | * PULL REQUEST update commits |
|
395 | 397 | */ |
|
396 | 398 | var updateCommits = function(repo_name, pull_request_id, force) { |
|
397 | 399 | var postData = { |
|
398 | 400 | 'update_commits': true |
|
399 | 401 | }; |
|
400 | 402 | if (force !== undefined && force === true) { |
|
401 | 403 | postData['force_refresh'] = true |
|
402 | 404 | } |
|
403 | 405 | _updatePullRequest(repo_name, pull_request_id, postData); |
|
404 | 406 | }; |
|
405 | 407 | |
|
406 | 408 | |
|
407 | 409 | /** |
|
408 | 410 | * PULL REQUEST edit info |
|
409 | 411 | */ |
|
410 | 412 | var editPullRequest = function(repo_name, pull_request_id, title, description, renderer) { |
|
411 | 413 | var url = pyroutes.url( |
|
412 | 414 | 'pullrequest_update', |
|
413 | 415 | {"repo_name": repo_name, "pull_request_id": pull_request_id}); |
|
414 | 416 | |
|
415 | 417 | var postData = { |
|
416 | 418 | 'title': title, |
|
417 | 419 | 'description': description, |
|
418 | 420 | 'description_renderer': renderer, |
|
419 | 421 | 'edit_pull_request': true, |
|
420 | 422 | 'csrf_token': CSRF_TOKEN |
|
421 | 423 | }; |
|
422 | 424 | var success = function(o) { |
|
423 | 425 | window.location.reload(); |
|
424 | 426 | }; |
|
425 | 427 | ajaxPOST(url, postData, success); |
|
426 | 428 | }; |
|
427 | 429 | |
|
428 | 430 | |
|
429 | 431 | /** |
|
430 | 432 | * Reviewer autocomplete |
|
431 | 433 | */ |
|
432 | 434 | var ReviewerAutoComplete = function(inputId) { |
|
433 | 435 | $(inputId).autocomplete({ |
|
434 | 436 | serviceUrl: pyroutes.url('user_autocomplete_data'), |
|
435 | 437 | minChars:2, |
|
436 | 438 | maxHeight:400, |
|
437 | 439 | deferRequestBy: 300, //miliseconds |
|
438 | 440 | showNoSuggestionNotice: true, |
|
439 | 441 | tabDisabled: true, |
|
440 | 442 | autoSelectFirst: true, |
|
441 | 443 | params: { user_id: templateContext.rhodecode_user.user_id, user_groups:true, user_groups_expand:true, skip_default_user:true }, |
|
442 | 444 | formatResult: autocompleteFormatResult, |
|
443 | 445 | lookupFilter: autocompleteFilterResult, |
|
444 | 446 | onSelect: function(element, data) { |
|
445 | 447 | var mandatory = false; |
|
446 | 448 | var reasons = [_gettext('added manually by "{0}"').format(templateContext.rhodecode_user.username)]; |
|
447 | 449 | |
|
448 | 450 | // add whole user groups |
|
449 | 451 | if (data.value_type == 'user_group') { |
|
450 | 452 | reasons.push(_gettext('member of "{0}"').format(data.value_display)); |
|
451 | 453 | |
|
452 | 454 | $.each(data.members, function(index, member_data) { |
|
453 | 455 | var reviewer = member_data; |
|
454 | 456 | reviewer['user_id'] = member_data['id']; |
|
455 | 457 | reviewer['gravatar_link'] = member_data['icon_link']; |
|
456 | 458 | reviewer['user_link'] = member_data['profile_link']; |
|
457 | 459 | reviewer['rules'] = []; |
|
458 | 460 | reviewersController.addReviewMember(reviewer, reasons, mandatory); |
|
459 | 461 | }) |
|
460 | 462 | } |
|
461 | 463 | // add single user |
|
462 | 464 | else { |
|
463 | 465 | var reviewer = data; |
|
464 | 466 | reviewer['user_id'] = data['id']; |
|
465 | 467 | reviewer['gravatar_link'] = data['icon_link']; |
|
466 | 468 | reviewer['user_link'] = data['profile_link']; |
|
467 | 469 | reviewer['rules'] = []; |
|
468 | 470 | reviewersController.addReviewMember(reviewer, reasons, mandatory); |
|
469 | 471 | } |
|
470 | 472 | |
|
471 | 473 | $(inputId).val(''); |
|
472 | 474 | } |
|
473 | 475 | }); |
|
474 | 476 | }; |
|
475 | 477 | |
|
476 | 478 | |
|
477 | 479 | VersionController = function () { |
|
478 | 480 | var self = this; |
|
479 | 481 | this.$verSource = $('input[name=ver_source]'); |
|
480 | 482 | this.$verTarget = $('input[name=ver_target]'); |
|
481 | 483 | this.$showVersionDiff = $('#show-version-diff'); |
|
482 | 484 | |
|
483 | 485 | this.adjustRadioSelectors = function (curNode) { |
|
484 | 486 | var getVal = function (item) { |
|
485 | 487 | if (item == 'latest') { |
|
486 | 488 | return Number.MAX_SAFE_INTEGER |
|
487 | 489 | } |
|
488 | 490 | else { |
|
489 | 491 | return parseInt(item) |
|
490 | 492 | } |
|
491 | 493 | }; |
|
492 | 494 | |
|
493 | 495 | var curVal = getVal($(curNode).val()); |
|
494 | 496 | var cleared = false; |
|
495 | 497 | |
|
496 | 498 | $.each(self.$verSource, function (index, value) { |
|
497 | 499 | var elVal = getVal($(value).val()); |
|
498 | 500 | |
|
499 | 501 | if (elVal > curVal) { |
|
500 | 502 | if ($(value).is(':checked')) { |
|
501 | 503 | cleared = true; |
|
502 | 504 | } |
|
503 | 505 | $(value).attr('disabled', 'disabled'); |
|
504 | 506 | $(value).removeAttr('checked'); |
|
505 | 507 | $(value).css({'opacity': 0.1}); |
|
506 | 508 | } |
|
507 | 509 | else { |
|
508 | 510 | $(value).css({'opacity': 1}); |
|
509 | 511 | $(value).removeAttr('disabled'); |
|
510 | 512 | } |
|
511 | 513 | }); |
|
512 | 514 | |
|
513 | 515 | if (cleared) { |
|
514 | 516 | // if we unchecked an active, set the next one to same loc. |
|
515 | 517 | $(this.$verSource).filter('[value={0}]'.format( |
|
516 | 518 | curVal)).attr('checked', 'checked'); |
|
517 | 519 | } |
|
518 | 520 | |
|
519 | 521 | self.setLockAction(false, |
|
520 | 522 | $(curNode).data('verPos'), |
|
521 | 523 | $(this.$verSource).filter(':checked').data('verPos') |
|
522 | 524 | ); |
|
523 | 525 | }; |
|
524 | 526 | |
|
525 | 527 | |
|
526 | 528 | this.attachVersionListener = function () { |
|
527 | 529 | self.$verTarget.change(function (e) { |
|
528 | 530 | self.adjustRadioSelectors(this) |
|
529 | 531 | }); |
|
530 | 532 | self.$verSource.change(function (e) { |
|
531 | 533 | self.adjustRadioSelectors(self.$verTarget.filter(':checked')) |
|
532 | 534 | }); |
|
533 | 535 | }; |
|
534 | 536 | |
|
535 | 537 | this.init = function () { |
|
536 | 538 | |
|
537 | 539 | var curNode = self.$verTarget.filter(':checked'); |
|
538 | 540 | self.adjustRadioSelectors(curNode); |
|
539 | 541 | self.setLockAction(true); |
|
540 | 542 | self.attachVersionListener(); |
|
541 | 543 | |
|
542 | 544 | }; |
|
543 | 545 | |
|
544 | 546 | this.setLockAction = function (state, selectedVersion, otherVersion) { |
|
545 | 547 | var $showVersionDiff = this.$showVersionDiff; |
|
546 | 548 | |
|
547 | 549 | if (state) { |
|
548 | 550 | $showVersionDiff.attr('disabled', 'disabled'); |
|
549 | 551 | $showVersionDiff.addClass('disabled'); |
|
550 | 552 | $showVersionDiff.html($showVersionDiff.data('labelTextLocked')); |
|
551 | 553 | } |
|
552 | 554 | else { |
|
553 | 555 | $showVersionDiff.removeAttr('disabled'); |
|
554 | 556 | $showVersionDiff.removeClass('disabled'); |
|
555 | 557 | |
|
556 | 558 | if (selectedVersion == otherVersion) { |
|
557 | 559 | $showVersionDiff.html($showVersionDiff.data('labelTextShow')); |
|
558 | 560 | } else { |
|
559 | 561 | $showVersionDiff.html($showVersionDiff.data('labelTextDiff')); |
|
560 | 562 | } |
|
561 | 563 | } |
|
562 | 564 | |
|
563 | 565 | }; |
|
564 | 566 | |
|
565 | 567 | this.showVersionDiff = function () { |
|
566 | 568 | var target = self.$verTarget.filter(':checked'); |
|
567 | 569 | var source = self.$verSource.filter(':checked'); |
|
568 | 570 | |
|
569 | 571 | if (target.val() && source.val()) { |
|
570 | 572 | var params = { |
|
571 | 573 | 'pull_request_id': templateContext.pull_request_data.pull_request_id, |
|
572 | 574 | 'repo_name': templateContext.repo_name, |
|
573 | 575 | 'version': target.val(), |
|
574 | 576 | 'from_version': source.val() |
|
575 | 577 | }; |
|
576 | 578 | window.location = pyroutes.url('pullrequest_show', params) |
|
577 | 579 | } |
|
578 | 580 | |
|
579 | 581 | return false; |
|
580 | 582 | }; |
|
581 | 583 | |
|
582 | 584 | this.toggleVersionView = function (elem) { |
|
583 | 585 | |
|
584 | 586 | if (this.$showVersionDiff.is(':visible')) { |
|
585 | 587 | $('.version-pr').hide(); |
|
586 | 588 | this.$showVersionDiff.hide(); |
|
587 | 589 | $(elem).html($(elem).data('toggleOn')) |
|
588 | 590 | } else { |
|
589 | 591 | $('.version-pr').show(); |
|
590 | 592 | this.$showVersionDiff.show(); |
|
591 | 593 | $(elem).html($(elem).data('toggleOff')) |
|
592 | 594 | } |
|
593 | 595 | |
|
594 | 596 | return false |
|
595 | 597 | }; |
|
596 | 598 | |
|
597 | 599 | this.toggleElement = function (elem, target) { |
|
598 | 600 | var $elem = $(elem); |
|
599 | 601 | var $target = $(target); |
|
600 | 602 | |
|
601 | 603 | if ($target.is(':visible')) { |
|
602 | 604 | $target.hide(); |
|
603 | 605 | $elem.html($elem.data('toggleOn')) |
|
604 | 606 | } else { |
|
605 | 607 | $target.show(); |
|
606 | 608 | $elem.html($elem.data('toggleOff')) |
|
607 | 609 | } |
|
608 | 610 | |
|
609 | 611 | return false |
|
610 | 612 | } |
|
611 | 613 | |
|
612 | 614 | }; |
|
613 | 615 | |
|
614 | 616 | |
|
615 | 617 | UpdatePrController = function () { |
|
616 | 618 | var self = this; |
|
617 | 619 | this.$updateCommits = $('#update_commits'); |
|
618 | 620 | this.$updateCommitsSwitcher = $('#update_commits_switcher'); |
|
619 | 621 | |
|
620 | 622 | this.lockUpdateButton = function (label) { |
|
621 | 623 | self.$updateCommits.attr('disabled', 'disabled'); |
|
622 | 624 | self.$updateCommitsSwitcher.attr('disabled', 'disabled'); |
|
623 | 625 | |
|
624 | 626 | self.$updateCommits.addClass('disabled'); |
|
625 | 627 | self.$updateCommitsSwitcher.addClass('disabled'); |
|
626 | 628 | |
|
627 | 629 | self.$updateCommits.removeClass('btn-primary'); |
|
628 | 630 | self.$updateCommitsSwitcher.removeClass('btn-primary'); |
|
629 | 631 | |
|
630 | 632 | self.$updateCommits.text(_gettext(label)); |
|
631 | 633 | }; |
|
632 | 634 | |
|
633 | 635 | this.isUpdateLocked = function () { |
|
634 | 636 | return self.$updateCommits.attr('disabled') !== undefined; |
|
635 | 637 | }; |
|
636 | 638 | |
|
637 | 639 | this.updateCommits = function (curNode) { |
|
638 | 640 | if (self.isUpdateLocked()) { |
|
639 | 641 | return |
|
640 | 642 | } |
|
641 | 643 | self.lockUpdateButton(_gettext('Updating...')); |
|
642 | 644 | updateCommits( |
|
643 | 645 | templateContext.repo_name, |
|
644 | 646 | templateContext.pull_request_data.pull_request_id); |
|
645 | 647 | }; |
|
646 | 648 | |
|
647 | 649 | this.forceUpdateCommits = function () { |
|
648 | 650 | if (self.isUpdateLocked()) { |
|
649 | 651 | return |
|
650 | 652 | } |
|
651 | 653 | self.lockUpdateButton(_gettext('Force updating...')); |
|
652 | 654 | var force = true; |
|
653 | 655 | updateCommits( |
|
654 | 656 | templateContext.repo_name, |
|
655 | 657 | templateContext.pull_request_data.pull_request_id, force); |
|
656 | 658 | }; |
|
657 | 659 | }; No newline at end of file |
@@ -1,1208 +1,1208 b'' | |||
|
1 | 1 | ## -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | <%! |
|
4 | 4 | from rhodecode.lib import html_filters |
|
5 | 5 | %> |
|
6 | 6 | |
|
7 | 7 | <%inherit file="root.mako"/> |
|
8 | 8 | |
|
9 | 9 | <%include file="/ejs_templates/templates.html"/> |
|
10 | 10 | |
|
11 | 11 | <div class="outerwrapper"> |
|
12 | 12 | <!-- HEADER --> |
|
13 | 13 | <div class="header"> |
|
14 | 14 | <div id="header-inner" class="wrapper"> |
|
15 | 15 | <div id="logo"> |
|
16 | 16 | <div class="logo-wrapper"> |
|
17 | 17 | <a href="${h.route_path('home')}"><img src="${h.asset('images/rhodecode-logo-white-60x60.png')}" alt="RhodeCode"/></a> |
|
18 | 18 | </div> |
|
19 | 19 | % if c.rhodecode_name: |
|
20 | 20 | <div class="branding"> |
|
21 | 21 | <a href="${h.route_path('home')}">${h.branding(c.rhodecode_name)}</a> |
|
22 | 22 | </div> |
|
23 | 23 | % endif |
|
24 | 24 | </div> |
|
25 | 25 | <!-- MENU BAR NAV --> |
|
26 | 26 | ${self.menu_bar_nav()} |
|
27 | 27 | <!-- END MENU BAR NAV --> |
|
28 | 28 | </div> |
|
29 | 29 | </div> |
|
30 | 30 | ${self.menu_bar_subnav()} |
|
31 | 31 | <!-- END HEADER --> |
|
32 | 32 | |
|
33 | 33 | <!-- CONTENT --> |
|
34 | 34 | <div id="content" class="wrapper"> |
|
35 | 35 | |
|
36 | 36 | <rhodecode-toast id="notifications"></rhodecode-toast> |
|
37 | 37 | |
|
38 | 38 | <div class="main"> |
|
39 | 39 | ${next.main()} |
|
40 | 40 | </div> |
|
41 | 41 | </div> |
|
42 | 42 | <!-- END CONTENT --> |
|
43 | 43 | |
|
44 | 44 | </div> |
|
45 | 45 | <!-- FOOTER --> |
|
46 | 46 | <div id="footer"> |
|
47 | 47 | <div id="footer-inner" class="title wrapper"> |
|
48 | 48 | <div> |
|
49 | 49 | <% sid = 'block' if request.GET.get('showrcid') else 'none' %> |
|
50 | 50 | |
|
51 | 51 | <p class="footer-link-right"> |
|
52 | 52 | <a class="grey-link-action" href="${h.route_path('home', _query={'showrcid': 1})}"> |
|
53 | 53 | RhodeCode |
|
54 | 54 | % if c.visual.show_version: |
|
55 | 55 | ${c.rhodecode_version} |
|
56 | 56 | % endif |
|
57 | 57 | ${c.rhodecode_edition} |
|
58 | 58 | </a> | |
|
59 | 59 | |
|
60 | 60 | % if c.visual.rhodecode_support_url: |
|
61 | 61 | <a class="grey-link-action" href="${c.visual.rhodecode_support_url}" target="_blank">${_('Support')}</a> | |
|
62 | 62 | <a class="grey-link-action" href="https://docs.rhodecode.com" target="_blank">${_('Documentation')}</a> |
|
63 | 63 | % endif |
|
64 | 64 | |
|
65 | 65 | </p> |
|
66 | 66 | |
|
67 | 67 | <p class="server-instance" style="display:${sid}"> |
|
68 | 68 | ## display hidden instance ID if specially defined |
|
69 | 69 | © 2010-${h.datetime.today().year}, <a href="${h.route_url('rhodecode_official')}" target="_blank">RhodeCode GmbH</a>. All rights reserved. |
|
70 | 70 | % if c.rhodecode_instanceid: |
|
71 | 71 | ${_('RhodeCode instance id: {}').format(c.rhodecode_instanceid)} |
|
72 | 72 | % endif |
|
73 | 73 | </p> |
|
74 | 74 | </div> |
|
75 | 75 | </div> |
|
76 | 76 | </div> |
|
77 | 77 | |
|
78 | 78 | <!-- END FOOTER --> |
|
79 | 79 | |
|
80 | 80 | ### MAKO DEFS ### |
|
81 | 81 | |
|
82 | 82 | <%def name="menu_bar_subnav()"> |
|
83 | 83 | </%def> |
|
84 | 84 | |
|
85 | 85 | <%def name="breadcrumbs(class_='breadcrumbs')"> |
|
86 | 86 | <div class="${class_}"> |
|
87 | 87 | ${self.breadcrumbs_links()} |
|
88 | 88 | </div> |
|
89 | 89 | </%def> |
|
90 | 90 | |
|
91 | 91 | <%def name="admin_menu(active=None)"> |
|
92 | 92 | |
|
93 | 93 | <div id="context-bar"> |
|
94 | 94 | <div class="wrapper"> |
|
95 | 95 | <div class="title"> |
|
96 | 96 | <div class="title-content"> |
|
97 | 97 | <div class="title-main"> |
|
98 | 98 | % if c.is_super_admin: |
|
99 | 99 | ${_('Super-admin Panel')} |
|
100 | 100 | % else: |
|
101 | 101 | ${_('Delegated Admin Panel')} |
|
102 | 102 | % endif |
|
103 | 103 | </div> |
|
104 | 104 | </div> |
|
105 | 105 | </div> |
|
106 | 106 | |
|
107 | 107 | <ul id="context-pages" class="navigation horizontal-list"> |
|
108 | 108 | |
|
109 | 109 | ## super-admin case |
|
110 | 110 | % if c.is_super_admin: |
|
111 | 111 | <li class="${h.is_active('audit_logs', active)}"><a href="${h.route_path('admin_audit_logs')}">${_('Admin audit logs')}</a></li> |
|
112 | 112 | <li class="${h.is_active('repositories', active)}"><a href="${h.route_path('repos')}">${_('Repositories')}</a></li> |
|
113 | 113 | <li class="${h.is_active('repository_groups', active)}"><a href="${h.route_path('repo_groups')}">${_('Repository groups')}</a></li> |
|
114 | 114 | <li class="${h.is_active('users', active)}"><a href="${h.route_path('users')}">${_('Users')}</a></li> |
|
115 | 115 | <li class="${h.is_active('user_groups', active)}"><a href="${h.route_path('user_groups')}">${_('User groups')}</a></li> |
|
116 | 116 | <li class="${h.is_active('permissions', active)}"><a href="${h.route_path('admin_permissions_application')}">${_('Permissions')}</a></li> |
|
117 | 117 | <li class="${h.is_active('authentication', active)}"><a href="${h.route_path('auth_home', traverse='')}">${_('Authentication')}</a></li> |
|
118 | 118 | <li class="${h.is_active('integrations', active)}"><a href="${h.route_path('global_integrations_home')}">${_('Integrations')}</a></li> |
|
119 | 119 | <li class="${h.is_active('defaults', active)}"><a href="${h.route_path('admin_defaults_repositories')}">${_('Defaults')}</a></li> |
|
120 | 120 | <li class="${h.is_active('settings', active)}"><a href="${h.route_path('admin_settings')}">${_('Settings')}</a></li> |
|
121 | 121 | |
|
122 | 122 | ## delegated admin |
|
123 | 123 | % elif c.is_delegated_admin: |
|
124 | 124 | <% |
|
125 | 125 | repositories=c.auth_user.repositories_admin or c.can_create_repo |
|
126 | 126 | repository_groups=c.auth_user.repository_groups_admin or c.can_create_repo_group |
|
127 | 127 | user_groups=c.auth_user.user_groups_admin or c.can_create_user_group |
|
128 | 128 | %> |
|
129 | 129 | |
|
130 | 130 | %if repositories: |
|
131 | 131 | <li class="${h.is_active('repositories', active)} local-admin-repos"><a href="${h.route_path('repos')}">${_('Repositories')}</a></li> |
|
132 | 132 | %endif |
|
133 | 133 | %if repository_groups: |
|
134 | 134 | <li class="${h.is_active('repository_groups', active)} local-admin-repo-groups"><a href="${h.route_path('repo_groups')}">${_('Repository groups')}</a></li> |
|
135 | 135 | %endif |
|
136 | 136 | %if user_groups: |
|
137 | 137 | <li class="${h.is_active('user_groups', active)} local-admin-user-groups"><a href="${h.route_path('user_groups')}">${_('User groups')}</a></li> |
|
138 | 138 | %endif |
|
139 | 139 | % endif |
|
140 | 140 | </ul> |
|
141 | 141 | |
|
142 | 142 | </div> |
|
143 | 143 | <div class="clear"></div> |
|
144 | 144 | </div> |
|
145 | 145 | </%def> |
|
146 | 146 | |
|
147 | 147 | <%def name="dt_info_panel(elements)"> |
|
148 | 148 | <dl class="dl-horizontal"> |
|
149 | 149 | %for dt, dd, title, show_items in elements: |
|
150 | 150 | <dt>${dt}:</dt> |
|
151 | 151 | <dd title="${h.tooltip(title)}"> |
|
152 | 152 | %if callable(dd): |
|
153 | 153 | ## allow lazy evaluation of elements |
|
154 | 154 | ${dd()} |
|
155 | 155 | %else: |
|
156 | 156 | ${dd} |
|
157 | 157 | %endif |
|
158 | 158 | %if show_items: |
|
159 | 159 | <span class="btn-collapse" data-toggle="item-${h.md5_safe(dt)[:6]}-details">${_('Show More')} </span> |
|
160 | 160 | %endif |
|
161 | 161 | </dd> |
|
162 | 162 | |
|
163 | 163 | %if show_items: |
|
164 | 164 | <div class="collapsable-content" data-toggle="item-${h.md5_safe(dt)[:6]}-details" style="display: none"> |
|
165 | 165 | %for item in show_items: |
|
166 | 166 | <dt></dt> |
|
167 | 167 | <dd>${item}</dd> |
|
168 | 168 | %endfor |
|
169 | 169 | </div> |
|
170 | 170 | %endif |
|
171 | 171 | |
|
172 | 172 | %endfor |
|
173 | 173 | </dl> |
|
174 | 174 | </%def> |
|
175 | 175 | |
|
176 | 176 | <%def name="tr_info_entry(element)"> |
|
177 | 177 | <% key, val, title, show_items = element %> |
|
178 | 178 | |
|
179 | 179 | <tr> |
|
180 | 180 | <td style="vertical-align: top">${key}</td> |
|
181 | 181 | <td title="${h.tooltip(title)}"> |
|
182 | 182 | %if callable(val): |
|
183 | 183 | ## allow lazy evaluation of elements |
|
184 | 184 | ${val()} |
|
185 | 185 | %else: |
|
186 | 186 | ${val} |
|
187 | 187 | %endif |
|
188 | 188 | %if show_items: |
|
189 | 189 | <div class="collapsable-content" data-toggle="item-${h.md5_safe(val)[:6]}-details" style="display: none"> |
|
190 | 190 | % for item in show_items: |
|
191 | 191 | <dt></dt> |
|
192 | 192 | <dd>${item}</dd> |
|
193 | 193 | % endfor |
|
194 | 194 | </div> |
|
195 | 195 | %endif |
|
196 | 196 | </td> |
|
197 | 197 | <td style="vertical-align: top"> |
|
198 | 198 | %if show_items: |
|
199 | 199 | <span class="btn-collapse" data-toggle="item-${h.md5_safe(val)[:6]}-details">${_('Show More')} </span> |
|
200 | 200 | %endif |
|
201 | 201 | </td> |
|
202 | 202 | </tr> |
|
203 | 203 | |
|
204 | 204 | </%def> |
|
205 | 205 | |
|
206 | 206 | <%def name="gravatar(email, size=16, tooltip=False, tooltip_alt=None, user=None, extra_class=None)"> |
|
207 | 207 | <% |
|
208 | 208 | if size > 16: |
|
209 | 209 | gravatar_class = ['gravatar','gravatar-large'] |
|
210 | 210 | else: |
|
211 | 211 | gravatar_class = ['gravatar'] |
|
212 | 212 | |
|
213 | 213 | data_hovercard_url = '' |
|
214 | 214 | data_hovercard_alt = tooltip_alt.replace('<', '<').replace('>', '>') if tooltip_alt else '' |
|
215 | 215 | |
|
216 | 216 | if tooltip: |
|
217 | 217 | gravatar_class += ['tooltip-hovercard'] |
|
218 | 218 | if extra_class: |
|
219 | 219 | gravatar_class += extra_class |
|
220 | 220 | if tooltip and user: |
|
221 | 221 | if user.username == h.DEFAULT_USER: |
|
222 | 222 | gravatar_class.pop(-1) |
|
223 | 223 | else: |
|
224 | 224 | data_hovercard_url = request.route_path('hovercard_user', user_id=getattr(user, 'user_id', '')) |
|
225 | 225 | gravatar_class = ' '.join(gravatar_class) |
|
226 | 226 | |
|
227 | 227 | %> |
|
228 | 228 | <%doc> |
|
229 | 229 | TODO: johbo: For now we serve double size images to make it smooth |
|
230 | 230 | for retina. This is how it worked until now. Should be replaced |
|
231 | 231 | with a better solution at some point. |
|
232 | 232 | </%doc> |
|
233 | 233 | |
|
234 | 234 | <img class="${gravatar_class}" height="${size}" width="${size}" data-hovercard-url="${data_hovercard_url}" data-hovercard-alt="${data_hovercard_alt}" src="${h.gravatar_url(email, size * 2)}" /> |
|
235 | 235 | </%def> |
|
236 | 236 | |
|
237 | 237 | |
|
238 | 238 | <%def name="gravatar_with_user(contact, size=16, show_disabled=False, tooltip=False, _class='rc-user')"> |
|
239 | 239 | <% |
|
240 | 240 | email = h.email_or_none(contact) |
|
241 | 241 | rc_user = h.discover_user(contact) |
|
242 | 242 | %> |
|
243 | 243 | |
|
244 | 244 | <div class="${_class}"> |
|
245 | 245 | ${self.gravatar(email, size, tooltip=tooltip, tooltip_alt=contact, user=rc_user)} |
|
246 | 246 | <span class="${('user user-disabled' if show_disabled else 'user')}"> |
|
247 | 247 | ${h.link_to_user(rc_user or contact)} |
|
248 | 248 | </span> |
|
249 | 249 | </div> |
|
250 | 250 | </%def> |
|
251 | 251 | |
|
252 | 252 | |
|
253 | 253 | <%def name="user_group_icon(user_group=None, size=16, tooltip=False)"> |
|
254 | 254 | <% |
|
255 | 255 | if (size > 16): |
|
256 | 256 | gravatar_class = 'icon-user-group-alt' |
|
257 | 257 | else: |
|
258 | 258 | gravatar_class = 'icon-user-group-alt' |
|
259 | 259 | |
|
260 | 260 | if tooltip: |
|
261 | 261 | gravatar_class += ' tooltip-hovercard' |
|
262 | 262 | |
|
263 | 263 | data_hovercard_url = request.route_path('hovercard_user_group', user_group_id=user_group.users_group_id) |
|
264 | 264 | %> |
|
265 | 265 | <%doc> |
|
266 | 266 | TODO: johbo: For now we serve double size images to make it smooth |
|
267 | 267 | for retina. This is how it worked until now. Should be replaced |
|
268 | 268 | with a better solution at some point. |
|
269 | 269 | </%doc> |
|
270 | 270 | |
|
271 | 271 | <i style="font-size: ${size}px" class="${gravatar_class} x-icon-size-${size}" data-hovercard-url="${data_hovercard_url}"></i> |
|
272 | 272 | </%def> |
|
273 | 273 | |
|
274 | 274 | <%def name="repo_page_title(repo_instance)"> |
|
275 | 275 | <div class="title-content repo-title"> |
|
276 | 276 | |
|
277 | 277 | <div class="title-main"> |
|
278 | 278 | ## SVN/HG/GIT icons |
|
279 | 279 | %if h.is_hg(repo_instance): |
|
280 | 280 | <i class="icon-hg"></i> |
|
281 | 281 | %endif |
|
282 | 282 | %if h.is_git(repo_instance): |
|
283 | 283 | <i class="icon-git"></i> |
|
284 | 284 | %endif |
|
285 | 285 | %if h.is_svn(repo_instance): |
|
286 | 286 | <i class="icon-svn"></i> |
|
287 | 287 | %endif |
|
288 | 288 | |
|
289 | 289 | ## public/private |
|
290 | 290 | %if repo_instance.private: |
|
291 | 291 | <i class="icon-repo-private"></i> |
|
292 | 292 | %else: |
|
293 | 293 | <i class="icon-repo-public"></i> |
|
294 | 294 | %endif |
|
295 | 295 | |
|
296 | 296 | ## repo name with group name |
|
297 | 297 | ${h.breadcrumb_repo_link(repo_instance)} |
|
298 | 298 | |
|
299 | 299 | ## Context Actions |
|
300 | 300 | <div class="pull-right"> |
|
301 | 301 | %if c.rhodecode_user.username != h.DEFAULT_USER: |
|
302 | 302 | <a href="${h.route_path('atom_feed_home', repo_name=c.rhodecode_db_repo.repo_uid, _query=dict(auth_token=c.rhodecode_user.feed_token))}" title="${_('RSS Feed')}" class="btn btn-sm"><i class="icon-rss-sign"></i>RSS</a> |
|
303 | 303 | |
|
304 | 304 | <a href="#WatchRepo" onclick="toggleFollowingRepo(this, templateContext.repo_id); return false" title="${_('Watch this Repository and actions on it in your personalized journal')}" class="btn btn-sm ${('watching' if c.repository_is_user_following else '')}"> |
|
305 | 305 | % if c.repository_is_user_following: |
|
306 | 306 | <i class="icon-eye-off"></i>${_('Unwatch')} |
|
307 | 307 | % else: |
|
308 | 308 | <i class="icon-eye"></i>${_('Watch')} |
|
309 | 309 | % endif |
|
310 | 310 | |
|
311 | 311 | </a> |
|
312 | 312 | %else: |
|
313 | 313 | <a href="${h.route_path('atom_feed_home', repo_name=c.rhodecode_db_repo.repo_uid)}" title="${_('RSS Feed')}" class="btn btn-sm"><i class="icon-rss-sign"></i>RSS</a> |
|
314 | 314 | %endif |
|
315 | 315 | </div> |
|
316 | 316 | |
|
317 | 317 | </div> |
|
318 | 318 | |
|
319 | 319 | ## FORKED |
|
320 | 320 | %if repo_instance.fork: |
|
321 | 321 | <p class="discreet"> |
|
322 | 322 | <i class="icon-code-fork"></i> ${_('Fork of')} |
|
323 | 323 | ${h.link_to_if(c.has_origin_repo_read_perm,repo_instance.fork.repo_name, h.route_path('repo_summary', repo_name=repo_instance.fork.repo_name))} |
|
324 | 324 | </p> |
|
325 | 325 | %endif |
|
326 | 326 | |
|
327 | 327 | ## IMPORTED FROM REMOTE |
|
328 | 328 | %if repo_instance.clone_uri: |
|
329 | 329 | <p class="discreet"> |
|
330 | 330 | <i class="icon-code-fork"></i> ${_('Clone from')} |
|
331 | 331 | <a href="${h.safe_str(h.hide_credentials(repo_instance.clone_uri))}">${h.hide_credentials(repo_instance.clone_uri)}</a> |
|
332 | 332 | </p> |
|
333 | 333 | %endif |
|
334 | 334 | |
|
335 | 335 | ## LOCKING STATUS |
|
336 | 336 | %if repo_instance.locked[0]: |
|
337 | 337 | <p class="locking_locked discreet"> |
|
338 | 338 | <i class="icon-repo-lock"></i> |
|
339 | 339 | ${_('Repository locked by %(user)s') % {'user': h.person_by_id(repo_instance.locked[0])}} |
|
340 | 340 | </p> |
|
341 | 341 | %elif repo_instance.enable_locking: |
|
342 | 342 | <p class="locking_unlocked discreet"> |
|
343 | 343 | <i class="icon-repo-unlock"></i> |
|
344 | 344 | ${_('Repository not locked. Pull repository to lock it.')} |
|
345 | 345 | </p> |
|
346 | 346 | %endif |
|
347 | 347 | |
|
348 | 348 | </div> |
|
349 | 349 | </%def> |
|
350 | 350 | |
|
351 | 351 | <%def name="repo_menu(active=None)"> |
|
352 | 352 | <% |
|
353 | 353 | ## determine if we have "any" option available |
|
354 | 354 | can_lock = h.HasRepoPermissionAny('repository.write','repository.admin')(c.repo_name) and c.rhodecode_db_repo.enable_locking |
|
355 | 355 | has_actions = can_lock |
|
356 | 356 | |
|
357 | 357 | %> |
|
358 | 358 | % if c.rhodecode_db_repo.archived: |
|
359 | 359 | <div class="alert alert-warning text-center"> |
|
360 | 360 | <strong>${_('This repository has been archived. It is now read-only.')}</strong> |
|
361 | 361 | </div> |
|
362 | 362 | % endif |
|
363 | 363 | |
|
364 | 364 | <!--- REPO CONTEXT BAR --> |
|
365 | 365 | <div id="context-bar"> |
|
366 | 366 | <div class="wrapper"> |
|
367 | 367 | |
|
368 | 368 | <div class="title"> |
|
369 | 369 | ${self.repo_page_title(c.rhodecode_db_repo)} |
|
370 | 370 | </div> |
|
371 | 371 | |
|
372 | 372 | <ul id="context-pages" class="navigation horizontal-list"> |
|
373 | 373 | <li class="${h.is_active('summary', active)}"><a class="menulink" href="${h.route_path('repo_summary_explicit', repo_name=c.repo_name)}"><div class="menulabel">${_('Summary')}</div></a></li> |
|
374 | 374 | <li class="${h.is_active('commits', active)}"><a class="menulink" href="${h.route_path('repo_commits', repo_name=c.repo_name)}"><div class="menulabel">${_('Commits')}</div></a></li> |
|
375 | 375 | <li class="${h.is_active('files', active)}"><a class="menulink" href="${h.repo_files_by_ref_url(c.repo_name, c.rhodecode_db_repo.repo_type, f_path='', ref_name=c.rhodecode_db_repo.landing_ref_name, commit_id='tip', query={'at':c.rhodecode_db_repo.landing_ref_name})}"><div class="menulabel">${_('Files')}</div></a></li> |
|
376 | 376 | <li class="${h.is_active('compare', active)}"><a class="menulink" href="${h.route_path('repo_compare_select',repo_name=c.repo_name)}"><div class="menulabel">${_('Compare')}</div></a></li> |
|
377 | 377 | |
|
378 | 378 | ## TODO: anderson: ideally it would have a function on the scm_instance "enable_pullrequest() and enable_fork()" |
|
379 | 379 | %if c.rhodecode_db_repo.repo_type in ['git','hg']: |
|
380 | 380 | <li class="${h.is_active('showpullrequest', active)}"> |
|
381 | 381 | <a class="menulink" href="${h.route_path('pullrequest_show_all', repo_name=c.repo_name)}" title="${h.tooltip(_('Show Pull Requests for %s') % c.repo_name)}"> |
|
382 | 382 | <div class="menulabel"> |
|
383 | 383 | ${_('Pull Requests')} <span class="menulink-counter">${c.repository_pull_requests}</span> |
|
384 | 384 | </div> |
|
385 | 385 | </a> |
|
386 | 386 | </li> |
|
387 | 387 | %endif |
|
388 | 388 | |
|
389 | 389 | <li class="${h.is_active('artifacts', active)}"> |
|
390 | 390 | <a class="menulink" href="${h.route_path('repo_artifacts_list',repo_name=c.repo_name)}"> |
|
391 | 391 | <div class="menulabel"> |
|
392 | 392 | ${_('Artifacts')} <span class="menulink-counter">${c.repository_artifacts}</span> |
|
393 | 393 | </div> |
|
394 | 394 | </a> |
|
395 | 395 | </li> |
|
396 | 396 | |
|
397 | 397 | %if not c.rhodecode_db_repo.archived and h.HasRepoPermissionAll('repository.admin')(c.repo_name): |
|
398 | 398 | <li class="${h.is_active('settings', active)}"><a class="menulink" href="${h.route_path('edit_repo',repo_name=c.repo_name)}"><div class="menulabel">${_('Repository Settings')}</div></a></li> |
|
399 | 399 | %endif |
|
400 | 400 | |
|
401 | 401 | <li class="${h.is_active('options', active)}"> |
|
402 | 402 | % if has_actions: |
|
403 | 403 | <a class="menulink dropdown"> |
|
404 | 404 | <div class="menulabel">${_('Options')}<div class="show_more"></div></div> |
|
405 | 405 | </a> |
|
406 | 406 | <ul class="submenu"> |
|
407 | 407 | %if can_lock: |
|
408 | 408 | %if c.rhodecode_db_repo.locked[0]: |
|
409 | 409 | <li><a class="locking_del" href="${h.route_path('repo_edit_toggle_locking',repo_name=c.repo_name)}">${_('Unlock Repository')}</a></li> |
|
410 | 410 | %else: |
|
411 | 411 | <li><a class="locking_add" href="${h.route_path('repo_edit_toggle_locking',repo_name=c.repo_name)}">${_('Lock Repository')}</a></li> |
|
412 | 412 | %endif |
|
413 | 413 | %endif |
|
414 | 414 | </ul> |
|
415 | 415 | % endif |
|
416 | 416 | </li> |
|
417 | 417 | |
|
418 | 418 | </ul> |
|
419 | 419 | </div> |
|
420 | 420 | <div class="clear"></div> |
|
421 | 421 | </div> |
|
422 | 422 | |
|
423 | 423 | <!--- REPO END CONTEXT BAR --> |
|
424 | 424 | |
|
425 | 425 | </%def> |
|
426 | 426 | |
|
427 | 427 | <%def name="repo_group_page_title(repo_group_instance)"> |
|
428 | 428 | <div class="title-content"> |
|
429 | 429 | <div class="title-main"> |
|
430 | 430 | ## Repository Group icon |
|
431 | 431 | <i class="icon-repo-group"></i> |
|
432 | 432 | |
|
433 | 433 | ## repo name with group name |
|
434 | 434 | ${h.breadcrumb_repo_group_link(repo_group_instance)} |
|
435 | 435 | </div> |
|
436 | 436 | |
|
437 | 437 | <%namespace name="dt" file="/data_table/_dt_elements.mako"/> |
|
438 | 438 | <div class="repo-group-desc discreet"> |
|
439 | 439 | ${dt.repo_group_desc(repo_group_instance.description_safe, repo_group_instance.personal, c.visual.stylify_metatags)} |
|
440 | 440 | </div> |
|
441 | 441 | |
|
442 | 442 | </div> |
|
443 | 443 | </%def> |
|
444 | 444 | |
|
445 | 445 | |
|
446 | 446 | <%def name="repo_group_menu(active=None)"> |
|
447 | 447 | <% |
|
448 | 448 | gr_name = c.repo_group.group_name if c.repo_group else None |
|
449 | 449 | # create repositories with write permission on group is set to true |
|
450 | 450 | group_admin = h.HasRepoGroupPermissionAny('group.admin')(gr_name, 'group admin index page') |
|
451 | 451 | |
|
452 | 452 | %> |
|
453 | 453 | |
|
454 | 454 | |
|
455 | 455 | <!--- REPO GROUP CONTEXT BAR --> |
|
456 | 456 | <div id="context-bar"> |
|
457 | 457 | <div class="wrapper"> |
|
458 | 458 | <div class="title"> |
|
459 | 459 | ${self.repo_group_page_title(c.repo_group)} |
|
460 | 460 | </div> |
|
461 | 461 | |
|
462 | 462 | <ul id="context-pages" class="navigation horizontal-list"> |
|
463 | 463 | <li class="${h.is_active('home', active)}"> |
|
464 | 464 | <a class="menulink" href="${h.route_path('repo_group_home', repo_group_name=c.repo_group.group_name)}"><div class="menulabel">${_('Group Home')}</div></a> |
|
465 | 465 | </li> |
|
466 | 466 | % if c.is_super_admin or group_admin: |
|
467 | 467 | <li class="${h.is_active('settings', active)}"> |
|
468 | 468 | <a class="menulink" href="${h.route_path('edit_repo_group',repo_group_name=c.repo_group.group_name)}" title="${_('You have admin right to this group, and can edit it')}"><div class="menulabel">${_('Group Settings')}</div></a> |
|
469 | 469 | </li> |
|
470 | 470 | % endif |
|
471 | 471 | |
|
472 | 472 | </ul> |
|
473 | 473 | </div> |
|
474 | 474 | <div class="clear"></div> |
|
475 | 475 | </div> |
|
476 | 476 | |
|
477 | 477 | <!--- REPO GROUP CONTEXT BAR --> |
|
478 | 478 | |
|
479 | 479 | </%def> |
|
480 | 480 | |
|
481 | 481 | |
|
482 | 482 | <%def name="usermenu(active=False)"> |
|
483 | 483 | <% |
|
484 | 484 | not_anonymous = c.rhodecode_user.username != h.DEFAULT_USER |
|
485 | 485 | |
|
486 | 486 | gr_name = c.repo_group.group_name if (hasattr(c, 'repo_group') and c.repo_group) else None |
|
487 | 487 | # create repositories with write permission on group is set to true |
|
488 | 488 | |
|
489 | 489 | can_fork = c.is_super_admin or h.HasPermissionAny('hg.fork.repository')() |
|
490 | 490 | create_on_write = h.HasPermissionAny('hg.create.write_on_repogroup.true')() |
|
491 | 491 | group_write = h.HasRepoGroupPermissionAny('group.write')(gr_name, 'can write into group index page') |
|
492 | 492 | group_admin = h.HasRepoGroupPermissionAny('group.admin')(gr_name, 'group admin index page') |
|
493 | 493 | |
|
494 | 494 | can_create_repos = c.is_super_admin or c.can_create_repo |
|
495 | 495 | can_create_repo_groups = c.is_super_admin or c.can_create_repo_group |
|
496 | 496 | |
|
497 | 497 | can_create_repos_in_group = c.is_super_admin or group_admin or (group_write and create_on_write) |
|
498 | 498 | can_create_repo_groups_in_group = c.is_super_admin or group_admin |
|
499 | 499 | %> |
|
500 | 500 | |
|
501 | 501 | % if not_anonymous: |
|
502 | 502 | <% |
|
503 | 503 | default_target_group = dict() |
|
504 | 504 | if c.rhodecode_user.personal_repo_group: |
|
505 | 505 | default_target_group = dict(parent_group=c.rhodecode_user.personal_repo_group.group_id) |
|
506 | 506 | %> |
|
507 | 507 | |
|
508 | 508 | ## create action |
|
509 | 509 | <li> |
|
510 | 510 | <a href="#create-actions" onclick="return false;" class="menulink childs"> |
|
511 |
<i class=" |
|
|
511 | <i class="icon-plus-circled"></i> | |
|
512 | 512 | </a> |
|
513 | 513 | |
|
514 | 514 | <div class="action-menu submenu"> |
|
515 | 515 | |
|
516 | 516 | <ol> |
|
517 | 517 | ## scope of within a repository |
|
518 | 518 | % if hasattr(c, 'rhodecode_db_repo') and c.rhodecode_db_repo: |
|
519 | 519 | <li class="submenu-title">${_('This Repository')}</li> |
|
520 | 520 | <li> |
|
521 | 521 | <a href="${h.route_path('pullrequest_new',repo_name=c.repo_name)}">${_('Create Pull Request')}</a> |
|
522 | 522 | </li> |
|
523 | 523 | % if can_fork: |
|
524 | 524 | <li> |
|
525 | 525 | <a href="${h.route_path('repo_fork_new',repo_name=c.repo_name,_query=default_target_group)}">${_('Fork this repository')}</a> |
|
526 | 526 | </li> |
|
527 | 527 | % endif |
|
528 | 528 | % endif |
|
529 | 529 | |
|
530 | 530 | ## scope of within repository groups |
|
531 | 531 | % if hasattr(c, 'repo_group') and c.repo_group and (can_create_repos_in_group or can_create_repo_groups_in_group): |
|
532 | 532 | <li class="submenu-title">${_('This Repository Group')}</li> |
|
533 | 533 | |
|
534 | 534 | % if can_create_repos_in_group: |
|
535 | 535 | <li> |
|
536 | 536 | <a href="${h.route_path('repo_new',_query=dict(parent_group=c.repo_group.group_id))}">${_('New Repository')}</a> |
|
537 | 537 | </li> |
|
538 | 538 | % endif |
|
539 | 539 | |
|
540 | 540 | % if can_create_repo_groups_in_group: |
|
541 | 541 | <li> |
|
542 | 542 | <a href="${h.route_path('repo_group_new',_query=dict(parent_group=c.repo_group.group_id))}">${_(u'New Repository Group')}</a> |
|
543 | 543 | </li> |
|
544 | 544 | % endif |
|
545 | 545 | % endif |
|
546 | 546 | |
|
547 | 547 | ## personal group |
|
548 | 548 | % if c.rhodecode_user.personal_repo_group: |
|
549 | 549 | <li class="submenu-title">Personal Group</li> |
|
550 | 550 | |
|
551 | 551 | <li> |
|
552 | 552 | <a href="${h.route_path('repo_new',_query=dict(parent_group=c.rhodecode_user.personal_repo_group.group_id))}" >${_('New Repository')} </a> |
|
553 | 553 | </li> |
|
554 | 554 | |
|
555 | 555 | <li> |
|
556 | 556 | <a href="${h.route_path('repo_group_new',_query=dict(parent_group=c.rhodecode_user.personal_repo_group.group_id))}">${_('New Repository Group')} </a> |
|
557 | 557 | </li> |
|
558 | 558 | % endif |
|
559 | 559 | |
|
560 | 560 | ## Global actions |
|
561 | 561 | <li class="submenu-title">RhodeCode</li> |
|
562 | 562 | % if can_create_repos: |
|
563 | 563 | <li> |
|
564 | 564 | <a href="${h.route_path('repo_new')}" >${_('New Repository')}</a> |
|
565 | 565 | </li> |
|
566 | 566 | % endif |
|
567 | 567 | |
|
568 | 568 | % if can_create_repo_groups: |
|
569 | 569 | <li> |
|
570 | 570 | <a href="${h.route_path('repo_group_new')}" >${_(u'New Repository Group')}</a> |
|
571 | 571 | </li> |
|
572 | 572 | % endif |
|
573 | 573 | |
|
574 | 574 | <li> |
|
575 | 575 | <a href="${h.route_path('gists_new')}">${_(u'New Gist')}</a> |
|
576 | 576 | </li> |
|
577 | 577 | |
|
578 | 578 | </ol> |
|
579 | 579 | |
|
580 | 580 | </div> |
|
581 | 581 | </li> |
|
582 | 582 | |
|
583 | 583 | ## notifications |
|
584 | 584 | <li> |
|
585 | 585 | <a class="${('empty' if c.unread_notifications == 0 else '')}" href="${h.route_path('notifications_show_all')}"> |
|
586 | 586 | ${c.unread_notifications} |
|
587 | 587 | </a> |
|
588 | 588 | </li> |
|
589 | 589 | % endif |
|
590 | 590 | |
|
591 | 591 | ## USER MENU |
|
592 | 592 | <li id="quick_login_li" class="${'active' if active else ''}"> |
|
593 | 593 | % if c.rhodecode_user.username == h.DEFAULT_USER: |
|
594 | 594 | <a id="quick_login_link" class="menulink childs" href="${h.route_path('login', _query={'came_from': h.current_route_path(request)})}"> |
|
595 | 595 | ${gravatar(c.rhodecode_user.email, 20)} |
|
596 | 596 | <span class="user"> |
|
597 | 597 | <span>${_('Sign in')}</span> |
|
598 | 598 | </span> |
|
599 | 599 | </a> |
|
600 | 600 | % else: |
|
601 | 601 | ## logged in user |
|
602 | 602 | <a id="quick_login_link" class="menulink childs"> |
|
603 | 603 | ${gravatar(c.rhodecode_user.email, 20)} |
|
604 | 604 | <span class="user"> |
|
605 | 605 | <span class="menu_link_user">${c.rhodecode_user.username}</span> |
|
606 | 606 | <div class="show_more"></div> |
|
607 | 607 | </span> |
|
608 | 608 | </a> |
|
609 | 609 | ## subnav with menu for logged in user |
|
610 | 610 | <div class="user-menu submenu"> |
|
611 | 611 | <div id="quick_login"> |
|
612 | 612 | %if c.rhodecode_user.username != h.DEFAULT_USER: |
|
613 | 613 | <div class=""> |
|
614 | 614 | <div class="big_gravatar">${gravatar(c.rhodecode_user.email, 48)}</div> |
|
615 | 615 | <div class="full_name">${c.rhodecode_user.full_name_or_username}</div> |
|
616 | 616 | <div class="email">${c.rhodecode_user.email}</div> |
|
617 | 617 | </div> |
|
618 | 618 | <div class=""> |
|
619 | 619 | <ol class="links"> |
|
620 | 620 | <li>${h.link_to(_(u'My account'),h.route_path('my_account_profile'))}</li> |
|
621 | 621 | % if c.rhodecode_user.personal_repo_group: |
|
622 | 622 | <li>${h.link_to(_(u'My personal group'), h.route_path('repo_group_home', repo_group_name=c.rhodecode_user.personal_repo_group.group_name))}</li> |
|
623 | 623 | % endif |
|
624 | 624 | <li>${h.link_to(_(u'Pull Requests'), h.route_path('my_account_pullrequests'))}</li> |
|
625 | 625 | |
|
626 | 626 | % if c.debug_style: |
|
627 | 627 | <li> |
|
628 | 628 | <a class="menulink" title="${_('Style')}" href="${h.route_path('debug_style_home')}"> |
|
629 | 629 | <div class="menulabel">${_('[Style]')}</div> |
|
630 | 630 | </a> |
|
631 | 631 | </li> |
|
632 | 632 | % endif |
|
633 | 633 | |
|
634 | 634 | ## bookmark-items |
|
635 | 635 | <li class="bookmark-items"> |
|
636 | 636 | ${_('Bookmarks')} |
|
637 | 637 | <div class="pull-right"> |
|
638 | 638 | <a href="${h.route_path('my_account_bookmarks')}"> |
|
639 | 639 | |
|
640 | 640 | <i class="icon-cog"></i> |
|
641 | 641 | </a> |
|
642 | 642 | </div> |
|
643 | 643 | </li> |
|
644 | 644 | % if not c.bookmark_items: |
|
645 | 645 | <li> |
|
646 | 646 | <a href="${h.route_path('my_account_bookmarks')}">${_('No Bookmarks yet.')}</a> |
|
647 | 647 | </li> |
|
648 | 648 | % endif |
|
649 | 649 | % for item in c.bookmark_items: |
|
650 | 650 | <li> |
|
651 | 651 | % if item.repository: |
|
652 | 652 | <div> |
|
653 | 653 | <a class="bookmark-item" href="${h.route_path('my_account_goto_bookmark', bookmark_id=item.position)}"> |
|
654 | 654 | <code>${item.position}</code> |
|
655 | 655 | % if item.repository.repo_type == 'hg': |
|
656 | 656 | <i class="icon-hg" title="${_('Repository')}" style="font-size: 16px"></i> |
|
657 | 657 | % elif item.repository.repo_type == 'git': |
|
658 | 658 | <i class="icon-git" title="${_('Repository')}" style="font-size: 16px"></i> |
|
659 | 659 | % elif item.repository.repo_type == 'svn': |
|
660 | 660 | <i class="icon-svn" title="${_('Repository')}" style="font-size: 16px"></i> |
|
661 | 661 | % endif |
|
662 | 662 | ${(item.title or h.shorter(item.repository.repo_name, 30))} |
|
663 | 663 | </a> |
|
664 | 664 | </div> |
|
665 | 665 | % elif item.repository_group: |
|
666 | 666 | <div> |
|
667 | 667 | <a class="bookmark-item" href="${h.route_path('my_account_goto_bookmark', bookmark_id=item.position)}"> |
|
668 | 668 | <code>${item.position}</code> |
|
669 | 669 | <i class="icon-repo-group" title="${_('Repository group')}" style="font-size: 14px"></i> |
|
670 | 670 | ${(item.title or h.shorter(item.repository_group.group_name, 30))} |
|
671 | 671 | </a> |
|
672 | 672 | </div> |
|
673 | 673 | % else: |
|
674 | 674 | <a class="bookmark-item" href="${h.route_path('my_account_goto_bookmark', bookmark_id=item.position)}"> |
|
675 | 675 | <code>${item.position}</code> |
|
676 | 676 | ${item.title} |
|
677 | 677 | </a> |
|
678 | 678 | % endif |
|
679 | 679 | </li> |
|
680 | 680 | % endfor |
|
681 | 681 | |
|
682 | 682 | <li class="logout"> |
|
683 | 683 | ${h.secure_form(h.route_path('logout'), request=request)} |
|
684 | 684 | ${h.submit('log_out', _(u'Sign Out'),class_="btn btn-primary")} |
|
685 | 685 | ${h.end_form()} |
|
686 | 686 | </li> |
|
687 | 687 | </ol> |
|
688 | 688 | </div> |
|
689 | 689 | %endif |
|
690 | 690 | </div> |
|
691 | 691 | </div> |
|
692 | 692 | |
|
693 | 693 | % endif |
|
694 | 694 | </li> |
|
695 | 695 | </%def> |
|
696 | 696 | |
|
697 | 697 | <%def name="menu_items(active=None)"> |
|
698 | 698 | <% |
|
699 | 699 | notice_messages, notice_level = c.rhodecode_user.get_notice_messages() |
|
700 | 700 | notice_display = 'none' if len(notice_messages) == 0 else '' |
|
701 | 701 | %> |
|
702 | 702 | <style> |
|
703 | 703 | |
|
704 | 704 | </style> |
|
705 | 705 | |
|
706 | 706 | <ul id="quick" class="main_nav navigation horizontal-list"> |
|
707 | 707 | ## notice box for important system messages |
|
708 | 708 | <li style="display: ${notice_display}"> |
|
709 | 709 | <a class="notice-box" href="#openNotice" onclick="$('.notice-messages-container').toggle(); return false"> |
|
710 | 710 | <div class="menulabel-notice ${notice_level}" > |
|
711 | 711 | ${len(notice_messages)} |
|
712 | 712 | </div> |
|
713 | 713 | </a> |
|
714 | 714 | </li> |
|
715 | 715 | <div class="notice-messages-container" style="display: none"> |
|
716 | 716 | <div class="notice-messages"> |
|
717 | 717 | <table class="rctable"> |
|
718 | 718 | % for notice in notice_messages: |
|
719 | 719 | <tr id="notice-message-${notice['msg_id']}" class="notice-message-${notice['level']}"> |
|
720 | 720 | <td style="vertical-align: text-top; width: 20px"> |
|
721 | 721 | <i class="tooltip icon-info notice-color-${notice['level']}" title="${notice['level']}"></i> |
|
722 | 722 | </td> |
|
723 | 723 | <td> |
|
724 | 724 | <span><i class="icon-plus-squared cursor-pointer" onclick="$('#notice-${notice['msg_id']}').toggle()"></i> </span> |
|
725 | 725 | ${notice['subject']} |
|
726 | 726 | |
|
727 | 727 | <div id="notice-${notice['msg_id']}" style="display: none"> |
|
728 | 728 | ${h.render(notice['body'], renderer='markdown')} |
|
729 | 729 | </div> |
|
730 | 730 | </td> |
|
731 | 731 | <td style="vertical-align: text-top; width: 35px;"> |
|
732 | 732 | <a class="tooltip" title="${_('dismiss')}" href="#dismiss" onclick="dismissNotice(${notice['msg_id']});return false"> |
|
733 | 733 | <i class="icon-remove icon-filled-red"></i> |
|
734 | 734 | </a> |
|
735 | 735 | </td> |
|
736 | 736 | </tr> |
|
737 | 737 | |
|
738 | 738 | % endfor |
|
739 | 739 | </table> |
|
740 | 740 | </div> |
|
741 | 741 | </div> |
|
742 | 742 | ## Main filter |
|
743 | 743 | <li> |
|
744 | 744 | <div class="menulabel main_filter_box"> |
|
745 | 745 | <div class="main_filter_input_box"> |
|
746 | 746 | <ul class="searchItems"> |
|
747 | 747 | |
|
748 | 748 | <li class="searchTag searchTagIcon"> |
|
749 | 749 | <i class="icon-search"></i> |
|
750 | 750 | </li> |
|
751 | 751 | |
|
752 | 752 | % if c.template_context['search_context']['repo_id']: |
|
753 | 753 | <li class="searchTag searchTagFilter searchTagHidable" > |
|
754 | 754 | ##<a href="${h.route_path('search_repo',repo_name=c.template_context['search_context']['repo_name'])}"> |
|
755 | 755 | <span class="tag"> |
|
756 | 756 | This repo |
|
757 | 757 | <a href="#removeGoToFilter" onclick="removeGoToFilter(); return false"><i class="icon-cancel-circled"></i></a> |
|
758 | 758 | </span> |
|
759 | 759 | ##</a> |
|
760 | 760 | </li> |
|
761 | 761 | % elif c.template_context['search_context']['repo_group_id']: |
|
762 | 762 | <li class="searchTag searchTagFilter searchTagHidable"> |
|
763 | 763 | ##<a href="${h.route_path('search_repo_group',repo_group_name=c.template_context['search_context']['repo_group_name'])}"> |
|
764 | 764 | <span class="tag"> |
|
765 | 765 | This group |
|
766 | 766 | <a href="#removeGoToFilter" onclick="removeGoToFilter(); return false"><i class="icon-cancel-circled"></i></a> |
|
767 | 767 | </span> |
|
768 | 768 | ##</a> |
|
769 | 769 | </li> |
|
770 | 770 | % endif |
|
771 | 771 | |
|
772 | 772 | <li class="searchTagInput"> |
|
773 | 773 | <input class="main_filter_input" id="main_filter" size="25" type="text" name="main_filter" placeholder="${_('search / go to...')}" value="" /> |
|
774 | 774 | </li> |
|
775 | 775 | <li class="searchTag searchTagHelp"> |
|
776 | 776 | <a href="#showFilterHelp" onclick="showMainFilterBox(); return false">?</a> |
|
777 | 777 | </li> |
|
778 | 778 | </ul> |
|
779 | 779 | </div> |
|
780 | 780 | </div> |
|
781 | 781 | |
|
782 | 782 | <div id="main_filter_help" style="display: none"> |
|
783 | 783 | - Use '/' key to quickly access this field. |
|
784 | 784 | |
|
785 | 785 | - Enter a name of repository, or repository group for quick search. |
|
786 | 786 | |
|
787 | 787 | - Prefix query to allow special search: |
|
788 | 788 | |
|
789 | 789 | user:admin, to search for usernames, always global |
|
790 | 790 | |
|
791 | 791 | user_group:devops, to search for user groups, always global |
|
792 | 792 | |
|
793 | 793 | pr:303, to search for pull request number, title, or description, always global |
|
794 | 794 | |
|
795 | 795 | commit:efced4, to search for commits, scoped to repositories or groups |
|
796 | 796 | |
|
797 | 797 | file:models.py, to search for file paths, scoped to repositories or groups |
|
798 | 798 | |
|
799 | 799 | % if c.template_context['search_context']['repo_id']: |
|
800 | 800 | For advanced full text search visit: <a href="${h.route_path('search_repo',repo_name=c.template_context['search_context']['repo_name'])}">repository search</a> |
|
801 | 801 | % elif c.template_context['search_context']['repo_group_id']: |
|
802 | 802 | For advanced full text search visit: <a href="${h.route_path('search_repo_group',repo_group_name=c.template_context['search_context']['repo_group_name'])}">repository group search</a> |
|
803 | 803 | % else: |
|
804 | 804 | For advanced full text search visit: <a href="${h.route_path('search')}">global search</a> |
|
805 | 805 | % endif |
|
806 | 806 | </div> |
|
807 | 807 | </li> |
|
808 | 808 | |
|
809 | 809 | ## ROOT MENU |
|
810 | 810 | <li class="${h.is_active('home', active)}"> |
|
811 | 811 | <a class="menulink" title="${_('Home')}" href="${h.route_path('home')}"> |
|
812 | 812 | <div class="menulabel">${_('Home')}</div> |
|
813 | 813 | </a> |
|
814 | 814 | </li> |
|
815 | 815 | |
|
816 | 816 | %if c.rhodecode_user.username != h.DEFAULT_USER: |
|
817 | 817 | <li class="${h.is_active('journal', active)}"> |
|
818 | 818 | <a class="menulink" title="${_('Show activity journal')}" href="${h.route_path('journal')}"> |
|
819 | 819 | <div class="menulabel">${_('Journal')}</div> |
|
820 | 820 | </a> |
|
821 | 821 | </li> |
|
822 | 822 | %else: |
|
823 | 823 | <li class="${h.is_active('journal', active)}"> |
|
824 | 824 | <a class="menulink" title="${_('Show Public activity journal')}" href="${h.route_path('journal_public')}"> |
|
825 | 825 | <div class="menulabel">${_('Public journal')}</div> |
|
826 | 826 | </a> |
|
827 | 827 | </li> |
|
828 | 828 | %endif |
|
829 | 829 | |
|
830 | 830 | <li class="${h.is_active('gists', active)}"> |
|
831 | 831 | <a class="menulink childs" title="${_('Show Gists')}" href="${h.route_path('gists_show')}"> |
|
832 | 832 | <div class="menulabel">${_('Gists')}</div> |
|
833 | 833 | </a> |
|
834 | 834 | </li> |
|
835 | 835 | |
|
836 | 836 | % if c.is_super_admin or c.is_delegated_admin: |
|
837 | 837 | <li class="${h.is_active('admin', active)}"> |
|
838 | 838 | <a class="menulink childs" title="${_('Admin settings')}" href="${h.route_path('admin_home')}"> |
|
839 | 839 | <div class="menulabel">${_('Admin')} </div> |
|
840 | 840 | </a> |
|
841 | 841 | </li> |
|
842 | 842 | % endif |
|
843 | 843 | |
|
844 | 844 | ## render extra user menu |
|
845 | 845 | ${usermenu(active=(active=='my_account'))} |
|
846 | 846 | |
|
847 | 847 | </ul> |
|
848 | 848 | |
|
849 | 849 | <script type="text/javascript"> |
|
850 | 850 | var visualShowPublicIcon = "${c.visual.show_public_icon}" == "True"; |
|
851 | 851 | |
|
852 | 852 | var formatRepoResult = function(result, container, query, escapeMarkup) { |
|
853 | 853 | return function(data, escapeMarkup) { |
|
854 | 854 | if (!data.repo_id){ |
|
855 | 855 | return data.text; // optgroup text Repositories |
|
856 | 856 | } |
|
857 | 857 | |
|
858 | 858 | var tmpl = ''; |
|
859 | 859 | var repoType = data['repo_type']; |
|
860 | 860 | var repoName = data['text']; |
|
861 | 861 | |
|
862 | 862 | if(data && data.type == 'repo'){ |
|
863 | 863 | if(repoType === 'hg'){ |
|
864 | 864 | tmpl += '<i class="icon-hg"></i> '; |
|
865 | 865 | } |
|
866 | 866 | else if(repoType === 'git'){ |
|
867 | 867 | tmpl += '<i class="icon-git"></i> '; |
|
868 | 868 | } |
|
869 | 869 | else if(repoType === 'svn'){ |
|
870 | 870 | tmpl += '<i class="icon-svn"></i> '; |
|
871 | 871 | } |
|
872 | 872 | if(data['private']){ |
|
873 | 873 | tmpl += '<i class="icon-lock" ></i> '; |
|
874 | 874 | } |
|
875 | 875 | else if(visualShowPublicIcon){ |
|
876 | 876 | tmpl += '<i class="icon-unlock-alt"></i> '; |
|
877 | 877 | } |
|
878 | 878 | } |
|
879 | 879 | tmpl += escapeMarkup(repoName); |
|
880 | 880 | return tmpl; |
|
881 | 881 | |
|
882 | 882 | }(result, escapeMarkup); |
|
883 | 883 | }; |
|
884 | 884 | |
|
885 | 885 | var formatRepoGroupResult = function(result, container, query, escapeMarkup) { |
|
886 | 886 | return function(data, escapeMarkup) { |
|
887 | 887 | if (!data.repo_group_id){ |
|
888 | 888 | return data.text; // optgroup text Repositories |
|
889 | 889 | } |
|
890 | 890 | |
|
891 | 891 | var tmpl = ''; |
|
892 | 892 | var repoGroupName = data['text']; |
|
893 | 893 | |
|
894 | 894 | if(data){ |
|
895 | 895 | |
|
896 | 896 | tmpl += '<i class="icon-repo-group"></i> '; |
|
897 | 897 | |
|
898 | 898 | } |
|
899 | 899 | tmpl += escapeMarkup(repoGroupName); |
|
900 | 900 | return tmpl; |
|
901 | 901 | |
|
902 | 902 | }(result, escapeMarkup); |
|
903 | 903 | }; |
|
904 | 904 | |
|
905 | 905 | var escapeRegExChars = function (value) { |
|
906 | 906 | return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); |
|
907 | 907 | }; |
|
908 | 908 | |
|
909 | 909 | var getRepoIcon = function(repo_type) { |
|
910 | 910 | if (repo_type === 'hg') { |
|
911 | 911 | return '<i class="icon-hg"></i> '; |
|
912 | 912 | } |
|
913 | 913 | else if (repo_type === 'git') { |
|
914 | 914 | return '<i class="icon-git"></i> '; |
|
915 | 915 | } |
|
916 | 916 | else if (repo_type === 'svn') { |
|
917 | 917 | return '<i class="icon-svn"></i> '; |
|
918 | 918 | } |
|
919 | 919 | return '' |
|
920 | 920 | }; |
|
921 | 921 | |
|
922 | 922 | var autocompleteMainFilterFormatResult = function (data, value, org_formatter) { |
|
923 | 923 | |
|
924 | 924 | if (value.split(':').length === 2) { |
|
925 | 925 | value = value.split(':')[1] |
|
926 | 926 | } |
|
927 | 927 | |
|
928 | 928 | var searchType = data['type']; |
|
929 | 929 | var searchSubType = data['subtype']; |
|
930 | 930 | var valueDisplay = data['value_display']; |
|
931 | 931 | var valueIcon = data['value_icon']; |
|
932 | 932 | |
|
933 | 933 | var pattern = '(' + escapeRegExChars(value) + ')'; |
|
934 | 934 | |
|
935 | 935 | valueDisplay = Select2.util.escapeMarkup(valueDisplay); |
|
936 | 936 | |
|
937 | 937 | // highlight match |
|
938 | 938 | if (searchType != 'text') { |
|
939 | 939 | valueDisplay = valueDisplay.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>'); |
|
940 | 940 | } |
|
941 | 941 | |
|
942 | 942 | var icon = ''; |
|
943 | 943 | |
|
944 | 944 | if (searchType === 'hint') { |
|
945 | 945 | icon += '<i class="icon-repo-group"></i> '; |
|
946 | 946 | } |
|
947 | 947 | // full text search/hints |
|
948 | 948 | else if (searchType === 'search') { |
|
949 | 949 | if (valueIcon === undefined) { |
|
950 | 950 | icon += '<i class="icon-more"></i> '; |
|
951 | 951 | } else { |
|
952 | 952 | icon += valueIcon + ' '; |
|
953 | 953 | } |
|
954 | 954 | |
|
955 | 955 | if (searchSubType !== undefined && searchSubType == 'repo') { |
|
956 | 956 | valueDisplay += '<div class="pull-right tag">repository</div>'; |
|
957 | 957 | } |
|
958 | 958 | else if (searchSubType !== undefined && searchSubType == 'repo_group') { |
|
959 | 959 | valueDisplay += '<div class="pull-right tag">repo group</div>'; |
|
960 | 960 | } |
|
961 | 961 | } |
|
962 | 962 | // repository |
|
963 | 963 | else if (searchType === 'repo') { |
|
964 | 964 | |
|
965 | 965 | var repoIcon = getRepoIcon(data['repo_type']); |
|
966 | 966 | icon += repoIcon; |
|
967 | 967 | |
|
968 | 968 | if (data['private']) { |
|
969 | 969 | icon += '<i class="icon-lock" ></i> '; |
|
970 | 970 | } |
|
971 | 971 | else if (visualShowPublicIcon) { |
|
972 | 972 | icon += '<i class="icon-unlock-alt"></i> '; |
|
973 | 973 | } |
|
974 | 974 | } |
|
975 | 975 | // repository groups |
|
976 | 976 | else if (searchType === 'repo_group') { |
|
977 | 977 | icon += '<i class="icon-repo-group"></i> '; |
|
978 | 978 | } |
|
979 | 979 | // user group |
|
980 | 980 | else if (searchType === 'user_group') { |
|
981 | 981 | icon += '<i class="icon-group"></i> '; |
|
982 | 982 | } |
|
983 | 983 | // user |
|
984 | 984 | else if (searchType === 'user') { |
|
985 | 985 | icon += '<img class="gravatar" src="{0}"/>'.format(data['icon_link']); |
|
986 | 986 | } |
|
987 | 987 | // pull request |
|
988 | 988 | else if (searchType === 'pull_request') { |
|
989 | 989 | icon += '<i class="icon-merge"></i> '; |
|
990 | 990 | } |
|
991 | 991 | // commit |
|
992 | 992 | else if (searchType === 'commit') { |
|
993 | 993 | var repo_data = data['repo_data']; |
|
994 | 994 | var repoIcon = getRepoIcon(repo_data['repository_type']); |
|
995 | 995 | if (repoIcon) { |
|
996 | 996 | icon += repoIcon; |
|
997 | 997 | } else { |
|
998 | 998 | icon += '<i class="icon-tag"></i>'; |
|
999 | 999 | } |
|
1000 | 1000 | } |
|
1001 | 1001 | // file |
|
1002 | 1002 | else if (searchType === 'file') { |
|
1003 | 1003 | var repo_data = data['repo_data']; |
|
1004 | 1004 | var repoIcon = getRepoIcon(repo_data['repository_type']); |
|
1005 | 1005 | if (repoIcon) { |
|
1006 | 1006 | icon += repoIcon; |
|
1007 | 1007 | } else { |
|
1008 | 1008 | icon += '<i class="icon-tag"></i>'; |
|
1009 | 1009 | } |
|
1010 | 1010 | } |
|
1011 | 1011 | // generic text |
|
1012 | 1012 | else if (searchType === 'text') { |
|
1013 | 1013 | icon = ''; |
|
1014 | 1014 | } |
|
1015 | 1015 | |
|
1016 | 1016 | var tmpl = '<div class="ac-container-wrap">{0}{1}</div>'; |
|
1017 | 1017 | return tmpl.format(icon, valueDisplay); |
|
1018 | 1018 | }; |
|
1019 | 1019 | |
|
1020 | 1020 | var handleSelect = function(element, suggestion) { |
|
1021 | 1021 | if (suggestion.type === "hint") { |
|
1022 | 1022 | // we skip action |
|
1023 | 1023 | $('#main_filter').focus(); |
|
1024 | 1024 | } |
|
1025 | 1025 | else if (suggestion.type === "text") { |
|
1026 | 1026 | // we skip action |
|
1027 | 1027 | $('#main_filter').focus(); |
|
1028 | 1028 | |
|
1029 | 1029 | } else { |
|
1030 | 1030 | window.location = suggestion['url']; |
|
1031 | 1031 | } |
|
1032 | 1032 | }; |
|
1033 | 1033 | |
|
1034 | 1034 | var autocompleteMainFilterResult = function (suggestion, originalQuery, queryLowerCase) { |
|
1035 | 1035 | if (queryLowerCase.split(':').length === 2) { |
|
1036 | 1036 | queryLowerCase = queryLowerCase.split(':')[1] |
|
1037 | 1037 | } |
|
1038 | 1038 | if (suggestion.type === "text") { |
|
1039 | 1039 | // special case we don't want to "skip" display for |
|
1040 | 1040 | return true |
|
1041 | 1041 | } |
|
1042 | 1042 | return suggestion.value_display.toLowerCase().indexOf(queryLowerCase) !== -1; |
|
1043 | 1043 | }; |
|
1044 | 1044 | |
|
1045 | 1045 | var cleanContext = { |
|
1046 | 1046 | repo_view_type: null, |
|
1047 | 1047 | |
|
1048 | 1048 | repo_id: null, |
|
1049 | 1049 | repo_name: "", |
|
1050 | 1050 | |
|
1051 | 1051 | repo_group_id: null, |
|
1052 | 1052 | repo_group_name: null |
|
1053 | 1053 | }; |
|
1054 | 1054 | var removeGoToFilter = function () { |
|
1055 | 1055 | $('.searchTagHidable').hide(); |
|
1056 | 1056 | $('#main_filter').autocomplete( |
|
1057 | 1057 | 'setOptions', {params:{search_context: cleanContext}}); |
|
1058 | 1058 | }; |
|
1059 | 1059 | |
|
1060 | 1060 | $('#main_filter').autocomplete({ |
|
1061 | 1061 | serviceUrl: pyroutes.url('goto_switcher_data'), |
|
1062 | 1062 | params: { |
|
1063 | 1063 | "search_context": templateContext.search_context |
|
1064 | 1064 | }, |
|
1065 | 1065 | minChars:2, |
|
1066 | 1066 | maxHeight:400, |
|
1067 | 1067 | deferRequestBy: 300, //miliseconds |
|
1068 | 1068 | tabDisabled: true, |
|
1069 | 1069 | autoSelectFirst: false, |
|
1070 | 1070 | containerClass: 'autocomplete-qfilter-suggestions', |
|
1071 | 1071 | formatResult: autocompleteMainFilterFormatResult, |
|
1072 | 1072 | lookupFilter: autocompleteMainFilterResult, |
|
1073 | 1073 | onSelect: function (element, suggestion) { |
|
1074 | 1074 | handleSelect(element, suggestion); |
|
1075 | 1075 | return false; |
|
1076 | 1076 | }, |
|
1077 | 1077 | onSearchError: function (element, query, jqXHR, textStatus, errorThrown) { |
|
1078 | 1078 | if (jqXHR !== 'abort') { |
|
1079 | 1079 | var message = formatErrorMessage(jqXHR, textStatus, errorThrown); |
|
1080 | 1080 | SwalNoAnimation.fire({ |
|
1081 | 1081 | icon: 'error', |
|
1082 | 1082 | title: _gettext('Error during search operation'), |
|
1083 | 1083 | html: '<span style="white-space: pre-line">{0}</span>'.format(message), |
|
1084 | 1084 | }).then(function(result) { |
|
1085 | 1085 | window.location.reload(); |
|
1086 | 1086 | }) |
|
1087 | 1087 | } |
|
1088 | 1088 | }, |
|
1089 | 1089 | onSearchStart: function (params) { |
|
1090 | 1090 | $('.searchTag.searchTagIcon').html('<i class="icon-spin animate-spin"></i>') |
|
1091 | 1091 | }, |
|
1092 | 1092 | onSearchComplete: function (query, suggestions) { |
|
1093 | 1093 | $('.searchTag.searchTagIcon').html('<i class="icon-search"></i>') |
|
1094 | 1094 | }, |
|
1095 | 1095 | }); |
|
1096 | 1096 | |
|
1097 | 1097 | showMainFilterBox = function () { |
|
1098 | 1098 | $('#main_filter_help').toggle(); |
|
1099 | 1099 | }; |
|
1100 | 1100 | |
|
1101 | 1101 | $('#main_filter').on('keydown.autocomplete', function (e) { |
|
1102 | 1102 | |
|
1103 | 1103 | var BACKSPACE = 8; |
|
1104 | 1104 | var el = $(e.currentTarget); |
|
1105 | 1105 | if(e.which === BACKSPACE){ |
|
1106 | 1106 | var inputVal = el.val(); |
|
1107 | 1107 | if (inputVal === ""){ |
|
1108 | 1108 | removeGoToFilter() |
|
1109 | 1109 | } |
|
1110 | 1110 | } |
|
1111 | 1111 | }); |
|
1112 | 1112 | |
|
1113 | 1113 | var dismissNotice = function(noticeId) { |
|
1114 | 1114 | |
|
1115 | 1115 | var url = pyroutes.url('user_notice_dismiss', |
|
1116 | 1116 | {"user_id": templateContext.rhodecode_user.user_id}); |
|
1117 | 1117 | |
|
1118 | 1118 | var postData = { |
|
1119 | 1119 | 'csrf_token': CSRF_TOKEN, |
|
1120 | 1120 | 'notice_id': noticeId, |
|
1121 | 1121 | }; |
|
1122 | 1122 | |
|
1123 | 1123 | var success = function(response) { |
|
1124 | 1124 | $('#notice-message-' + noticeId).remove(); |
|
1125 | 1125 | return false; |
|
1126 | 1126 | }; |
|
1127 | 1127 | var failure = function(data, textStatus, xhr) { |
|
1128 | 1128 | alert("error processing request: " + textStatus); |
|
1129 | 1129 | return false; |
|
1130 | 1130 | }; |
|
1131 | 1131 | ajaxPOST(url, postData, success, failure); |
|
1132 | 1132 | } |
|
1133 | 1133 | </script> |
|
1134 | 1134 | <script src="${h.asset('js/rhodecode/base/keyboard-bindings.js', ver=c.rhodecode_version_hash)}"></script> |
|
1135 | 1135 | </%def> |
|
1136 | 1136 | |
|
1137 | 1137 | <div class="modal" id="help_kb" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> |
|
1138 | 1138 | <div class="modal-dialog"> |
|
1139 | 1139 | <div class="modal-content"> |
|
1140 | 1140 | <div class="modal-header"> |
|
1141 | 1141 | <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> |
|
1142 | 1142 | <h4 class="modal-title" id="myModalLabel">${_('Keyboard shortcuts')}</h4> |
|
1143 | 1143 | </div> |
|
1144 | 1144 | <div class="modal-body"> |
|
1145 | 1145 | <div class="block-left"> |
|
1146 | 1146 | <table class="keyboard-mappings"> |
|
1147 | 1147 | <tbody> |
|
1148 | 1148 | <tr> |
|
1149 | 1149 | <th></th> |
|
1150 | 1150 | <th>${_('Site-wide shortcuts')}</th> |
|
1151 | 1151 | </tr> |
|
1152 | 1152 | <% |
|
1153 | 1153 | elems = [ |
|
1154 | 1154 | ('/', 'Use quick search box'), |
|
1155 | 1155 | ('g h', 'Goto home page'), |
|
1156 | 1156 | ('g g', 'Goto my private gists page'), |
|
1157 | 1157 | ('g G', 'Goto my public gists page'), |
|
1158 | 1158 | ('g 0-9', 'Goto bookmarked items from 0-9'), |
|
1159 | 1159 | ('n r', 'New repository page'), |
|
1160 | 1160 | ('n g', 'New gist page'), |
|
1161 | 1161 | ] |
|
1162 | 1162 | %> |
|
1163 | 1163 | %for key, desc in elems: |
|
1164 | 1164 | <tr> |
|
1165 | 1165 | <td class="keys"> |
|
1166 | 1166 | <span class="key tag">${key}</span> |
|
1167 | 1167 | </td> |
|
1168 | 1168 | <td>${desc}</td> |
|
1169 | 1169 | </tr> |
|
1170 | 1170 | %endfor |
|
1171 | 1171 | </tbody> |
|
1172 | 1172 | </table> |
|
1173 | 1173 | </div> |
|
1174 | 1174 | <div class="block-left"> |
|
1175 | 1175 | <table class="keyboard-mappings"> |
|
1176 | 1176 | <tbody> |
|
1177 | 1177 | <tr> |
|
1178 | 1178 | <th></th> |
|
1179 | 1179 | <th>${_('Repositories')}</th> |
|
1180 | 1180 | </tr> |
|
1181 | 1181 | <% |
|
1182 | 1182 | elems = [ |
|
1183 | 1183 | ('g s', 'Goto summary page'), |
|
1184 | 1184 | ('g c', 'Goto changelog page'), |
|
1185 | 1185 | ('g f', 'Goto files page'), |
|
1186 | 1186 | ('g F', 'Goto files page with file search activated'), |
|
1187 | 1187 | ('g p', 'Goto pull requests page'), |
|
1188 | 1188 | ('g o', 'Goto repository settings'), |
|
1189 | 1189 | ('g O', 'Goto repository access permissions settings'), |
|
1190 | 1190 | ] |
|
1191 | 1191 | %> |
|
1192 | 1192 | %for key, desc in elems: |
|
1193 | 1193 | <tr> |
|
1194 | 1194 | <td class="keys"> |
|
1195 | 1195 | <span class="key tag">${key}</span> |
|
1196 | 1196 | </td> |
|
1197 | 1197 | <td>${desc}</td> |
|
1198 | 1198 | </tr> |
|
1199 | 1199 | %endfor |
|
1200 | 1200 | </tbody> |
|
1201 | 1201 | </table> |
|
1202 | 1202 | </div> |
|
1203 | 1203 | </div> |
|
1204 | 1204 | <div class="modal-footer"> |
|
1205 | 1205 | </div> |
|
1206 | 1206 | </div><!-- /.modal-content --> |
|
1207 | 1207 | </div><!-- /.modal-dialog --> |
|
1208 | 1208 | </div><!-- /.modal --> |
@@ -1,537 +1,537 b'' | |||
|
1 | 1 | <%inherit file="/base/base.mako"/> |
|
2 | 2 | <%namespace name="dt" file="/data_table/_dt_elements.mako"/> |
|
3 | 3 | |
|
4 | 4 | <%def name="title()"> |
|
5 | 5 | ${c.repo_name} ${_('New pull request')} |
|
6 | 6 | </%def> |
|
7 | 7 | |
|
8 | 8 | <%def name="breadcrumbs_links()"></%def> |
|
9 | 9 | |
|
10 | 10 | <%def name="menu_bar_nav()"> |
|
11 | 11 | ${self.menu_items(active='repositories')} |
|
12 | 12 | </%def> |
|
13 | 13 | |
|
14 | 14 | <%def name="menu_bar_subnav()"> |
|
15 | 15 | ${self.repo_menu(active='showpullrequest')} |
|
16 | 16 | </%def> |
|
17 | 17 | |
|
18 | 18 | <%def name="main()"> |
|
19 | 19 | <div class="box"> |
|
20 | 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 | 22 | <div class="box pr-summary"> |
|
23 | 23 | |
|
24 | 24 | <div class="summary-details block-left"> |
|
25 | 25 | |
|
26 | 26 | |
|
27 | 27 | <div class="pr-details-title"> |
|
28 | 28 | ${_('New pull request')} |
|
29 | 29 | </div> |
|
30 | 30 | |
|
31 | 31 | <div class="form" style="padding-top: 10px"> |
|
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 | <p class="help-block"> |
|
44 | 44 | Start the title with WIP: to prevent accidental merge of Work In Progress pull request before it's ready. |
|
45 | 45 | </p> |
|
46 | 46 | </div> |
|
47 | 47 | |
|
48 | 48 | <div class="field"> |
|
49 | 49 | <div class="label label-textarea"> |
|
50 | 50 | <label for="pullrequest_desc">${_('Description')}:</label> |
|
51 | 51 | </div> |
|
52 | 52 | <div class="textarea text-area"> |
|
53 | 53 | <input id="pr-renderer-input" type="hidden" name="description_renderer" value="${c.visual.default_renderer}"> |
|
54 | 54 | ${dt.markup_form('pullrequest_desc')} |
|
55 | 55 | </div> |
|
56 | 56 | </div> |
|
57 | 57 | |
|
58 | 58 | <div class="field"> |
|
59 | 59 | <div class="label label-textarea"> |
|
60 | 60 | <label for="commit_flow">${_('Commit flow')}:</label> |
|
61 | 61 | </div> |
|
62 | 62 | |
|
63 | 63 | ## TODO: johbo: Abusing the "content" class here to get the |
|
64 | 64 | ## desired effect. Should be replaced by a proper solution. |
|
65 | 65 | |
|
66 | 66 | ##ORG |
|
67 | 67 | <div class="content"> |
|
68 | 68 | <strong>${_('Source repository')}:</strong> |
|
69 | 69 | ${c.rhodecode_db_repo.description} |
|
70 | 70 | </div> |
|
71 | 71 | <div class="content"> |
|
72 | 72 | ${h.hidden('source_repo')} |
|
73 | 73 | ${h.hidden('source_ref')} |
|
74 | 74 | </div> |
|
75 | 75 | |
|
76 | 76 | ##OTHER, most Probably the PARENT OF THIS FORK |
|
77 | 77 | <div class="content"> |
|
78 | 78 | ## filled with JS |
|
79 | 79 | <div id="target_repo_desc"></div> |
|
80 | 80 | </div> |
|
81 | 81 | |
|
82 | 82 | <div class="content"> |
|
83 | 83 | ${h.hidden('target_repo')} |
|
84 | 84 | ${h.hidden('target_ref')} |
|
85 | 85 | <span id="target_ref_loading" style="display: none"> |
|
86 | 86 | ${_('Loading refs...')} |
|
87 | 87 | </span> |
|
88 | 88 | </div> |
|
89 | 89 | </div> |
|
90 | 90 | |
|
91 | 91 | <div class="field"> |
|
92 | 92 | <div class="label label-textarea"> |
|
93 | 93 | <label for="pullrequest_submit"></label> |
|
94 | 94 | </div> |
|
95 | 95 | <div class="input"> |
|
96 | 96 | <div class="pr-submit-button"> |
|
97 | 97 | <input id="pr_submit" class="btn" name="save" type="submit" value="${_('Submit Pull Request')}"> |
|
98 | 98 | </div> |
|
99 | 99 | <div id="pr_open_message"></div> |
|
100 | 100 | </div> |
|
101 | 101 | </div> |
|
102 | 102 | |
|
103 | 103 | <div class="pr-spacing-container"></div> |
|
104 | 104 | </div> |
|
105 | 105 | </div> |
|
106 | 106 | </div> |
|
107 | 107 | <div> |
|
108 | 108 | ## AUTHOR |
|
109 | 109 | <div class="reviewers-title block-right"> |
|
110 | 110 | <div class="pr-details-title"> |
|
111 | 111 | ${_('Author of this pull request')} |
|
112 | 112 | </div> |
|
113 | 113 | </div> |
|
114 | 114 | <div class="block-right pr-details-content reviewers"> |
|
115 | 115 | <ul class="group_members"> |
|
116 | 116 | <li> |
|
117 | 117 | ${self.gravatar_with_user(c.rhodecode_user.email, 16, tooltip=True)} |
|
118 | 118 | </li> |
|
119 | 119 | </ul> |
|
120 | 120 | </div> |
|
121 | 121 | |
|
122 | 122 | ## REVIEW RULES |
|
123 | 123 | <div id="review_rules" style="display: none" class="reviewers-title block-right"> |
|
124 | 124 | <div class="pr-details-title"> |
|
125 | 125 | ${_('Reviewer rules')} |
|
126 | 126 | </div> |
|
127 | 127 | <div class="pr-reviewer-rules"> |
|
128 | 128 | ## review rules will be appended here, by default reviewers logic |
|
129 | 129 | </div> |
|
130 | 130 | </div> |
|
131 | 131 | |
|
132 | 132 | ## REVIEWERS |
|
133 | 133 | <div class="reviewers-title block-right"> |
|
134 | 134 | <div class="pr-details-title"> |
|
135 | 135 | ${_('Pull request reviewers')} |
|
136 | 136 | <span class="calculate-reviewers"> - ${_('loading...')}</span> |
|
137 | 137 | </div> |
|
138 | 138 | </div> |
|
139 | 139 | <div id="reviewers" class="block-right pr-details-content reviewers"> |
|
140 | 140 | ## members goes here, filled via JS based on initial selection ! |
|
141 | 141 | <input type="hidden" name="__start__" value="review_members:sequence"> |
|
142 | 142 | <ul id="review_members" class="group_members"></ul> |
|
143 | 143 | <input type="hidden" name="__end__" value="review_members:sequence"> |
|
144 | 144 | <div id="add_reviewer_input" class='ac'> |
|
145 | 145 | <div class="reviewer_ac"> |
|
146 | 146 | ${h.text('user', class_='ac-input', placeholder=_('Add reviewer or reviewer group'))} |
|
147 | 147 | <div id="reviewers_container"></div> |
|
148 | 148 | </div> |
|
149 | 149 | </div> |
|
150 | 150 | </div> |
|
151 | 151 | </div> |
|
152 | 152 | </div> |
|
153 | 153 | <div class="box"> |
|
154 | 154 | <div> |
|
155 | 155 | ## overview pulled by ajax |
|
156 | 156 | <div id="pull_request_overview"></div> |
|
157 | 157 | </div> |
|
158 | 158 | </div> |
|
159 | 159 | ${h.end_form()} |
|
160 | 160 | </div> |
|
161 | 161 | |
|
162 | 162 | <script type="text/javascript"> |
|
163 | 163 | $(function(){ |
|
164 | 164 | var defaultSourceRepo = '${c.default_repo_data['source_repo_name']}'; |
|
165 | 165 | var defaultSourceRepoData = ${c.default_repo_data['source_refs_json']|n}; |
|
166 | 166 | var defaultTargetRepo = '${c.default_repo_data['target_repo_name']}'; |
|
167 | 167 | var defaultTargetRepoData = ${c.default_repo_data['target_refs_json']|n}; |
|
168 | 168 | |
|
169 | 169 | var $pullRequestForm = $('#pull_request_form'); |
|
170 | 170 | var $pullRequestSubmit = $('#pr_submit', $pullRequestForm); |
|
171 | 171 | var $sourceRepo = $('#source_repo', $pullRequestForm); |
|
172 | 172 | var $targetRepo = $('#target_repo', $pullRequestForm); |
|
173 | 173 | var $sourceRef = $('#source_ref', $pullRequestForm); |
|
174 | 174 | var $targetRef = $('#target_ref', $pullRequestForm); |
|
175 | 175 | |
|
176 | 176 | var sourceRepo = function() { return $sourceRepo.eq(0).val() }; |
|
177 | 177 | var sourceRef = function() { return $sourceRef.eq(0).val().split(':') }; |
|
178 | 178 | |
|
179 | 179 | var targetRepo = function() { return $targetRepo.eq(0).val() }; |
|
180 | 180 | var targetRef = function() { return $targetRef.eq(0).val().split(':') }; |
|
181 | 181 | |
|
182 | 182 | var calculateContainerWidth = function() { |
|
183 | 183 | var maxWidth = 0; |
|
184 | 184 | var repoSelect2Containers = ['#source_repo', '#target_repo']; |
|
185 | 185 | $.each(repoSelect2Containers, function(idx, value) { |
|
186 | 186 | $(value).select2('container').width('auto'); |
|
187 | 187 | var curWidth = $(value).select2('container').width(); |
|
188 | 188 | if (maxWidth <= curWidth) { |
|
189 | 189 | maxWidth = curWidth; |
|
190 | 190 | } |
|
191 | 191 | $.each(repoSelect2Containers, function(idx, value) { |
|
192 | 192 | $(value).select2('container').width(maxWidth + 10); |
|
193 | 193 | }); |
|
194 | 194 | }); |
|
195 | 195 | }; |
|
196 | 196 | |
|
197 | 197 | var initRefSelection = function(selectedRef) { |
|
198 | 198 | return function(element, callback) { |
|
199 | 199 | // translate our select2 id into a text, it's a mapping to show |
|
200 | 200 | // simple label when selecting by internal ID. |
|
201 | 201 | var id, refData; |
|
202 | 202 | if (selectedRef === undefined || selectedRef === null) { |
|
203 | 203 | id = element.val(); |
|
204 | 204 | refData = element.val().split(':'); |
|
205 | 205 | |
|
206 | 206 | if (refData.length !== 3){ |
|
207 | 207 | refData = ["", "", ""] |
|
208 | 208 | } |
|
209 | 209 | } else { |
|
210 | 210 | id = selectedRef; |
|
211 | 211 | refData = selectedRef.split(':'); |
|
212 | 212 | } |
|
213 | 213 | |
|
214 | 214 | var text = refData[1]; |
|
215 | 215 | if (refData[0] === 'rev') { |
|
216 | 216 | text = text.substring(0, 12); |
|
217 | 217 | } |
|
218 | 218 | |
|
219 | 219 | var data = {id: id, text: text}; |
|
220 | 220 | callback(data); |
|
221 | 221 | }; |
|
222 | 222 | }; |
|
223 | 223 | |
|
224 | 224 | var formatRefSelection = function(data, container, escapeMarkup) { |
|
225 | 225 | var prefix = ''; |
|
226 | 226 | var refData = data.id.split(':'); |
|
227 | 227 | if (refData[0] === 'branch') { |
|
228 | 228 | prefix = '<i class="icon-branch"></i>'; |
|
229 | 229 | } |
|
230 | 230 | else if (refData[0] === 'book') { |
|
231 | 231 | prefix = '<i class="icon-bookmark"></i>'; |
|
232 | 232 | } |
|
233 | 233 | else if (refData[0] === 'tag') { |
|
234 | 234 | prefix = '<i class="icon-tag"></i>'; |
|
235 | 235 | } |
|
236 | 236 | |
|
237 | 237 | var originalOption = data.element; |
|
238 | 238 | return prefix + escapeMarkup(data.text); |
|
239 | 239 | };formatSelection: |
|
240 | 240 | |
|
241 | 241 | // custom code mirror |
|
242 | 242 | var codeMirrorInstance = $('#pullrequest_desc').get(0).MarkupForm.cm; |
|
243 | 243 | |
|
244 | 244 | var diffDataHandler = function(data) { |
|
245 | 245 | |
|
246 | 246 | $('#pull_request_overview').html(data); |
|
247 | 247 | |
|
248 | 248 | var commitElements = data['commits']; |
|
249 | 249 | var files = data['files']; |
|
250 | 250 | var added = data['stats'][0] |
|
251 | 251 | var deleted = data['stats'][1] |
|
252 | 252 | var commonAncestorId = data['ancestor']; |
|
253 | ||
|
254 | var prTitleAndDesc = getTitleAndDescription( | |
|
255 | sourceRef()[1], commitElements, 5); | |
|
253 | var _sourceRefType = sourceRef()[0]; | |
|
254 | var _sourceRefName = sourceRef()[1]; | |
|
255 | var prTitleAndDesc = getTitleAndDescription(_sourceRefType, _sourceRefName, commitElements, 5); | |
|
256 | 256 | |
|
257 | 257 | var title = prTitleAndDesc[0]; |
|
258 | 258 | var proposedDescription = prTitleAndDesc[1]; |
|
259 | 259 | |
|
260 | 260 | var useGeneratedTitle = ( |
|
261 | 261 | $('#pullrequest_title').hasClass('autogenerated-title') || |
|
262 | 262 | $('#pullrequest_title').val() === ""); |
|
263 | 263 | |
|
264 | 264 | if (title && useGeneratedTitle) { |
|
265 | 265 | // use generated title if we haven't specified our own |
|
266 | 266 | $('#pullrequest_title').val(title); |
|
267 | 267 | $('#pullrequest_title').addClass('autogenerated-title'); |
|
268 | 268 | |
|
269 | 269 | } |
|
270 | 270 | |
|
271 | 271 | var useGeneratedDescription = ( |
|
272 | 272 | !codeMirrorInstance._userDefinedValue || |
|
273 | 273 | codeMirrorInstance.getValue() === ""); |
|
274 | 274 | |
|
275 | 275 | if (proposedDescription && useGeneratedDescription) { |
|
276 | 276 | // set proposed content, if we haven't defined our own, |
|
277 | 277 | // or we don't have description written |
|
278 | 278 | codeMirrorInstance._userDefinedValue = false; // reset state |
|
279 | 279 | codeMirrorInstance.setValue(proposedDescription); |
|
280 | 280 | } |
|
281 | 281 | |
|
282 | 282 | // refresh our codeMirror so events kicks in and it's change aware |
|
283 | 283 | codeMirrorInstance.refresh(); |
|
284 | 284 | |
|
285 | 285 | var url_data = { |
|
286 | 286 | 'repo_name': targetRepo(), |
|
287 | 287 | 'target_repo': sourceRepo(), |
|
288 | 288 | 'source_ref': targetRef()[2], |
|
289 | 289 | 'source_ref_type': 'rev', |
|
290 | 290 | 'target_ref': sourceRef()[2], |
|
291 | 291 | 'target_ref_type': 'rev', |
|
292 | 292 | 'merge': true, |
|
293 | 293 | '_': Date.now() // bypass browser caching |
|
294 | 294 | }; // gather the source/target ref and repo here |
|
295 | 295 | var url = pyroutes.url('repo_compare', url_data); |
|
296 | 296 | |
|
297 | 297 | var msg = '<input id="common_ancestor" type="hidden" name="common_ancestor" value="{0}">'.format(commonAncestorId); |
|
298 | 298 | msg += '<input type="hidden" name="__start__" value="revisions:sequence">' |
|
299 | 299 | |
|
300 | 300 | $.each(commitElements, function(idx, value) { |
|
301 | 301 | msg += '<input type="hidden" name="revisions" value="{0}">'.format(value["raw_id"]); |
|
302 | 302 | }); |
|
303 | 303 | |
|
304 | 304 | msg += '<input type="hidden" name="__end__" value="revisions:sequence">' |
|
305 | 305 | msg += _ngettext( |
|
306 | 306 | 'This pull requests will consist of <strong>{0} commit</strong>.', |
|
307 | 307 | 'This pull requests will consist of <strong>{0} commits</strong>.', |
|
308 | 308 | commitElements.length).format(commitElements.length) |
|
309 | 309 | |
|
310 | 310 | msg += '\n'; |
|
311 | 311 | msg += _ngettext( |
|
312 | 312 | '<strong>{0} file</strong> changed, ', |
|
313 | 313 | '<strong>{0} files</strong> changed, ', |
|
314 | 314 | files.length).format(files.length) |
|
315 | 315 | msg += '<span class="op-added">{0} lines inserted</span>, <span class="op-deleted">{1} lines deleted</span>.'.format(added, deleted) |
|
316 | 316 | |
|
317 | 317 | msg += '\n\n <a class="" id="pull_request_overview_url" href="{0}" target="_blank">${_('Show detailed compare.')}</a>'.format(url); |
|
318 | 318 | |
|
319 | 319 | if (commitElements.length) { |
|
320 | 320 | var commitsLink = '<a href="#pull_request_overview"><strong>{0}</strong></a>'.format(commitElements.length); |
|
321 | 321 | prButtonLock(false, msg.replace('__COMMITS__', commitsLink), 'compare'); |
|
322 | 322 | } |
|
323 | 323 | else { |
|
324 | 324 | prButtonLock(true, "${_('There are no commits to merge.')}", 'compare'); |
|
325 | 325 | } |
|
326 | 326 | |
|
327 | 327 | }; |
|
328 | 328 | |
|
329 | 329 | reviewersController = new ReviewersController(); |
|
330 | 330 | reviewersController.diffDataHandler = diffDataHandler; |
|
331 | 331 | |
|
332 | 332 | var queryTargetRepo = function(self, query) { |
|
333 | 333 | // cache ALL results if query is empty |
|
334 | 334 | var cacheKey = query.term || '__'; |
|
335 | 335 | var cachedData = self.cachedDataSource[cacheKey]; |
|
336 | 336 | |
|
337 | 337 | if (cachedData) { |
|
338 | 338 | query.callback({results: cachedData.results}); |
|
339 | 339 | } else { |
|
340 | 340 | $.ajax({ |
|
341 | 341 | url: pyroutes.url('pullrequest_repo_targets', {'repo_name': templateContext.repo_name}), |
|
342 | 342 | data: {query: query.term}, |
|
343 | 343 | dataType: 'json', |
|
344 | 344 | type: 'GET', |
|
345 | 345 | success: function(data) { |
|
346 | 346 | self.cachedDataSource[cacheKey] = data; |
|
347 | 347 | query.callback({results: data.results}); |
|
348 | 348 | }, |
|
349 | 349 | error: function(jqXHR, textStatus, errorThrown) { |
|
350 | 350 | var prefix = "Error while fetching entries.\n" |
|
351 | 351 | var message = formatErrorMessage(jqXHR, textStatus, errorThrown, prefix); |
|
352 | 352 | ajaxErrorSwal(message); |
|
353 | 353 | } |
|
354 | 354 | }); |
|
355 | 355 | } |
|
356 | 356 | }; |
|
357 | 357 | |
|
358 | 358 | var queryTargetRefs = function(initialData, query) { |
|
359 | 359 | var data = {results: []}; |
|
360 | 360 | // filter initialData |
|
361 | 361 | $.each(initialData, function() { |
|
362 | 362 | var section = this.text; |
|
363 | 363 | var children = []; |
|
364 | 364 | $.each(this.children, function() { |
|
365 | 365 | if (query.term.length === 0 || |
|
366 | 366 | this.text.toUpperCase().indexOf(query.term.toUpperCase()) >= 0 ) { |
|
367 | 367 | children.push({'id': this.id, 'text': this.text}) |
|
368 | 368 | } |
|
369 | 369 | }); |
|
370 | 370 | data.results.push({'text': section, 'children': children}) |
|
371 | 371 | }); |
|
372 | 372 | query.callback({results: data.results}); |
|
373 | 373 | }; |
|
374 | 374 | |
|
375 | 375 | var Select2Box = function(element, overrides) { |
|
376 | 376 | var globalDefaults = { |
|
377 | 377 | dropdownAutoWidth: true, |
|
378 | 378 | containerCssClass: "drop-menu", |
|
379 | 379 | dropdownCssClass: "drop-menu-dropdown" |
|
380 | 380 | }; |
|
381 | 381 | |
|
382 | 382 | var initSelect2 = function(defaultOptions) { |
|
383 | 383 | var options = jQuery.extend(globalDefaults, defaultOptions, overrides); |
|
384 | 384 | element.select2(options); |
|
385 | 385 | }; |
|
386 | 386 | |
|
387 | 387 | return { |
|
388 | 388 | initRef: function() { |
|
389 | 389 | var defaultOptions = { |
|
390 | 390 | minimumResultsForSearch: 5, |
|
391 | 391 | formatSelection: formatRefSelection |
|
392 | 392 | }; |
|
393 | 393 | |
|
394 | 394 | initSelect2(defaultOptions); |
|
395 | 395 | }, |
|
396 | 396 | |
|
397 | 397 | initRepo: function(defaultValue, readOnly) { |
|
398 | 398 | var defaultOptions = { |
|
399 | 399 | initSelection : function (element, callback) { |
|
400 | 400 | var data = {id: defaultValue, text: defaultValue}; |
|
401 | 401 | callback(data); |
|
402 | 402 | } |
|
403 | 403 | }; |
|
404 | 404 | |
|
405 | 405 | initSelect2(defaultOptions); |
|
406 | 406 | |
|
407 | 407 | element.select2('val', defaultSourceRepo); |
|
408 | 408 | if (readOnly === true) { |
|
409 | 409 | element.select2('readonly', true); |
|
410 | 410 | } |
|
411 | 411 | } |
|
412 | 412 | }; |
|
413 | 413 | }; |
|
414 | 414 | |
|
415 | 415 | var initTargetRefs = function(refsData, selectedRef) { |
|
416 | 416 | |
|
417 | 417 | Select2Box($targetRef, { |
|
418 | 418 | placeholder: "${_('Select commit reference')}", |
|
419 | 419 | query: function(query) { |
|
420 | 420 | queryTargetRefs(refsData, query); |
|
421 | 421 | }, |
|
422 | 422 | initSelection : initRefSelection(selectedRef) |
|
423 | 423 | }).initRef(); |
|
424 | 424 | |
|
425 | 425 | if (!(selectedRef === undefined)) { |
|
426 | 426 | $targetRef.select2('val', selectedRef); |
|
427 | 427 | } |
|
428 | 428 | }; |
|
429 | 429 | |
|
430 | 430 | var targetRepoChanged = function(repoData) { |
|
431 | 431 | // generate new DESC of target repo displayed next to select |
|
432 | 432 | var prLink = pyroutes.url('pullrequest_new', {'repo_name': repoData['name']}); |
|
433 | 433 | $('#target_repo_desc').html( |
|
434 | 434 | "<strong>${_('Target repository')}</strong>: {0}. <a href=\"{1}\">Switch base, and use as source.</a>".format(repoData['description'], prLink) |
|
435 | 435 | ); |
|
436 | 436 | |
|
437 | 437 | // generate dynamic select2 for refs. |
|
438 | 438 | initTargetRefs(repoData['refs']['select2_refs'], |
|
439 | 439 | repoData['refs']['selected_ref']); |
|
440 | 440 | |
|
441 | 441 | }; |
|
442 | 442 | |
|
443 | 443 | var sourceRefSelect2 = Select2Box($sourceRef, { |
|
444 | 444 | placeholder: "${_('Select commit reference')}", |
|
445 | 445 | query: function(query) { |
|
446 | 446 | var initialData = defaultSourceRepoData['refs']['select2_refs']; |
|
447 | 447 | queryTargetRefs(initialData, query) |
|
448 | 448 | }, |
|
449 | 449 | initSelection: initRefSelection() |
|
450 | 450 | } |
|
451 | 451 | ); |
|
452 | 452 | |
|
453 | 453 | var sourceRepoSelect2 = Select2Box($sourceRepo, { |
|
454 | 454 | query: function(query) {} |
|
455 | 455 | }); |
|
456 | 456 | |
|
457 | 457 | var targetRepoSelect2 = Select2Box($targetRepo, { |
|
458 | 458 | cachedDataSource: {}, |
|
459 | 459 | query: $.debounce(250, function(query) { |
|
460 | 460 | queryTargetRepo(this, query); |
|
461 | 461 | }), |
|
462 | 462 | formatResult: formatRepoResult |
|
463 | 463 | }); |
|
464 | 464 | |
|
465 | 465 | sourceRefSelect2.initRef(); |
|
466 | 466 | |
|
467 | 467 | sourceRepoSelect2.initRepo(defaultSourceRepo, true); |
|
468 | 468 | |
|
469 | 469 | targetRepoSelect2.initRepo(defaultTargetRepo, false); |
|
470 | 470 | |
|
471 | 471 | $sourceRef.on('change', function(e){ |
|
472 | 472 | reviewersController.loadDefaultReviewers( |
|
473 | 473 | sourceRepo(), sourceRef(), targetRepo(), targetRef()); |
|
474 | 474 | }); |
|
475 | 475 | |
|
476 | 476 | $targetRef.on('change', function(e){ |
|
477 | 477 | reviewersController.loadDefaultReviewers( |
|
478 | 478 | sourceRepo(), sourceRef(), targetRepo(), targetRef()); |
|
479 | 479 | }); |
|
480 | 480 | |
|
481 | 481 | $targetRepo.on('change', function(e){ |
|
482 | 482 | var repoName = $(this).val(); |
|
483 | 483 | calculateContainerWidth(); |
|
484 | 484 | $targetRef.select2('destroy'); |
|
485 | 485 | $('#target_ref_loading').show(); |
|
486 | 486 | |
|
487 | 487 | $.ajax({ |
|
488 | 488 | url: pyroutes.url('pullrequest_repo_refs', |
|
489 | 489 | {'repo_name': templateContext.repo_name, 'target_repo_name':repoName}), |
|
490 | 490 | data: {}, |
|
491 | 491 | dataType: 'json', |
|
492 | 492 | type: 'GET', |
|
493 | 493 | success: function(data) { |
|
494 | 494 | $('#target_ref_loading').hide(); |
|
495 | 495 | targetRepoChanged(data); |
|
496 | 496 | }, |
|
497 | 497 | error: function(jqXHR, textStatus, errorThrown) { |
|
498 | 498 | var prefix = "Error while fetching entries.\n" |
|
499 | 499 | var message = formatErrorMessage(jqXHR, textStatus, errorThrown, prefix); |
|
500 | 500 | ajaxErrorSwal(message); |
|
501 | 501 | } |
|
502 | 502 | }) |
|
503 | 503 | |
|
504 | 504 | }); |
|
505 | 505 | |
|
506 | 506 | $pullRequestForm.on('submit', function(e){ |
|
507 | 507 | // Flush changes into textarea |
|
508 | 508 | codeMirrorInstance.save(); |
|
509 | 509 | prButtonLock(true, null, 'all'); |
|
510 | 510 | $pullRequestSubmit.val(_gettext('Please wait creating pull request...')); |
|
511 | 511 | }); |
|
512 | 512 | |
|
513 | 513 | prButtonLock(true, "${_('Please select source and target')}", 'all'); |
|
514 | 514 | |
|
515 | 515 | // auto-load on init, the target refs select2 |
|
516 | 516 | calculateContainerWidth(); |
|
517 | 517 | targetRepoChanged(defaultTargetRepoData); |
|
518 | 518 | |
|
519 | 519 | $('#pullrequest_title').on('keyup', function(e){ |
|
520 | 520 | $(this).removeClass('autogenerated-title'); |
|
521 | 521 | }); |
|
522 | 522 | |
|
523 | 523 | % if c.default_source_ref: |
|
524 | 524 | // in case we have a pre-selected value, use it now |
|
525 | 525 | $sourceRef.select2('val', '${c.default_source_ref}'); |
|
526 | 526 | |
|
527 | 527 | |
|
528 | 528 | // default reviewers |
|
529 | 529 | reviewersController.loadDefaultReviewers( |
|
530 | 530 | sourceRepo(), sourceRef(), targetRepo(), targetRef()); |
|
531 | 531 | % endif |
|
532 | 532 | |
|
533 | 533 | ReviewerAutoComplete('#user'); |
|
534 | 534 | }); |
|
535 | 535 | </script> |
|
536 | 536 | |
|
537 | 537 | </%def> |
General Comments 0
You need to be logged in to leave comments.
Login now