Show More
@@ -1,400 +1,405 b'' | |||
|
1 | 1 | ## -*- coding: utf-8 -*- |
|
2 | 2 | ## usage: |
|
3 | 3 | ## <%namespace name="comment" file="/changeset/changeset_file_comment.mako"/> |
|
4 | 4 | ## ${comment.comment_block(comment)} |
|
5 | 5 | ## |
|
6 | 6 | <%namespace name="base" file="/base/base.mako"/> |
|
7 | 7 | |
|
8 | 8 | <%def name="comment_block(comment, inline=False)"> |
|
9 | 9 | <% pr_index_ver = comment.get_index_version(getattr(c, 'versions', [])) %> |
|
10 | 10 | % if inline: |
|
11 | 11 | <% outdated_at_ver = comment.outdated_at_version(getattr(c, 'at_version_num', None)) %> |
|
12 | 12 | % else: |
|
13 | 13 | <% outdated_at_ver = comment.older_than_version(getattr(c, 'at_version_num', None)) %> |
|
14 | 14 | % endif |
|
15 | 15 | |
|
16 | 16 | |
|
17 | 17 | <div class="comment |
|
18 | 18 | ${'comment-inline' if inline else 'comment-general'} |
|
19 | 19 | ${'comment-outdated' if outdated_at_ver else 'comment-current'}" |
|
20 | 20 | id="comment-${comment.comment_id}" |
|
21 | 21 | line="${comment.line_no}" |
|
22 | 22 | data-comment-id="${comment.comment_id}" |
|
23 | 23 | data-comment-type="${comment.comment_type}" |
|
24 | 24 | data-comment-inline=${h.json.dumps(inline)} |
|
25 | 25 | style="${'display: none;' if outdated_at_ver else ''}"> |
|
26 | 26 | |
|
27 | 27 | <div class="meta"> |
|
28 | 28 | <div class="comment-type-label"> |
|
29 | 29 | <div class="comment-label ${comment.comment_type or 'note'}" id="comment-label-${comment.comment_id}"> |
|
30 | 30 | % if comment.comment_type == 'todo': |
|
31 | 31 | % if comment.resolved: |
|
32 | 32 | <div class="resolved tooltip" title="${_('Resolved by comment #{}').format(comment.resolved.comment_id)}"> |
|
33 | 33 | <a href="#comment-${comment.resolved.comment_id}">${comment.comment_type}</a> |
|
34 | 34 | </div> |
|
35 | 35 | % else: |
|
36 | 36 | <div class="resolved tooltip" style="display: none"> |
|
37 | 37 | <span>${comment.comment_type}</span> |
|
38 | 38 | </div> |
|
39 | 39 | <div class="resolve tooltip" onclick="return Rhodecode.comments.createResolutionComment(${comment.comment_id});" title="${_('Click to resolve this comment')}"> |
|
40 | 40 | ${comment.comment_type} |
|
41 | 41 | </div> |
|
42 | 42 | % endif |
|
43 | 43 | % else: |
|
44 | 44 | % if comment.resolved_comment: |
|
45 | 45 | fix |
|
46 | 46 | % else: |
|
47 | 47 | ${comment.comment_type or 'note'} |
|
48 | 48 | % endif |
|
49 | 49 | % endif |
|
50 | 50 | </div> |
|
51 | 51 | </div> |
|
52 | 52 | |
|
53 | 53 | <div class="author ${'author-inline' if inline else 'author-general'}"> |
|
54 | 54 | ${base.gravatar_with_user(comment.author.email, 16)} |
|
55 | 55 | </div> |
|
56 | 56 | <div class="date"> |
|
57 | 57 | ${h.age_component(comment.modified_at, time_is_local=True)} |
|
58 | 58 | </div> |
|
59 | 59 | % if inline: |
|
60 | 60 | <span></span> |
|
61 | 61 | % else: |
|
62 | 62 | <div class="status-change"> |
|
63 | 63 | % if comment.pull_request: |
|
64 | 64 | <a href="${h.url('pullrequest_show',repo_name=comment.pull_request.target_repo.repo_name,pull_request_id=comment.pull_request.pull_request_id)}"> |
|
65 | 65 | % if comment.status_change: |
|
66 | 66 | ${_('pull request #%s') % comment.pull_request.pull_request_id}: |
|
67 | 67 | % else: |
|
68 | 68 | ${_('pull request #%s') % comment.pull_request.pull_request_id} |
|
69 | 69 | % endif |
|
70 | 70 | </a> |
|
71 | 71 | % else: |
|
72 | 72 | % if comment.status_change: |
|
73 | 73 | ${_('Status change on commit')}: |
|
74 | 74 | % endif |
|
75 | 75 | % endif |
|
76 | 76 | </div> |
|
77 | 77 | % endif |
|
78 | 78 | |
|
79 | 79 | % if comment.status_change: |
|
80 | 80 | <div class="${'flag_status %s' % comment.status_change[0].status}"></div> |
|
81 | 81 | <div title="${_('Commit status')}" class="changeset-status-lbl"> |
|
82 | 82 | ${comment.status_change[0].status_lbl} |
|
83 | 83 | </div> |
|
84 | 84 | % endif |
|
85 | 85 | |
|
86 | 86 | % if comment.resolved_comment: |
|
87 | 87 | <a class="has-spacer-before" href="#comment-${comment.resolved_comment.comment_id}" onclick="Rhodecode.comments.scrollToComment($('#comment-${comment.resolved_comment.comment_id}'), 0, ${h.json.dumps(comment.resolved_comment.outdated)})"> |
|
88 | 88 | ${_('resolves comment #{}').format(comment.resolved_comment.comment_id)} |
|
89 | 89 | </a> |
|
90 | 90 | % endif |
|
91 | 91 | |
|
92 | 92 | <a class="permalink" href="#comment-${comment.comment_id}"> ¶</a> |
|
93 | 93 | |
|
94 | 94 | <div class="comment-links-block"> |
|
95 | ||
|
95 | % if comment.pull_request and comment.pull_request.author.user_id == comment.author.user_id: | |
|
96 | <span class="tag authortag tooltip" title="${_('Pull request author')}"> | |
|
97 | ${_('author')} | |
|
98 | </span> | |
|
99 | | | |
|
100 | % endif | |
|
96 | 101 | % if inline: |
|
97 | 102 | <div class="pr-version-inline"> |
|
98 | 103 | <a href="${h.url.current(version=comment.pull_request_version_id, anchor='comment-{}'.format(comment.comment_id))}"> |
|
99 | 104 | % if outdated_at_ver: |
|
100 | 105 | <code class="pr-version-num" title="${_('Outdated comment from pull request version {0}').format(pr_index_ver)}"> |
|
101 | 106 | outdated ${'v{}'.format(pr_index_ver)} | |
|
102 | 107 | </code> |
|
103 | 108 | % elif pr_index_ver: |
|
104 | 109 | <code class="pr-version-num" title="${_('Comment from pull request version {0}').format(pr_index_ver)}"> |
|
105 | 110 | ${'v{}'.format(pr_index_ver)} | |
|
106 | 111 | </code> |
|
107 | 112 | % endif |
|
108 | 113 | </a> |
|
109 | 114 | </div> |
|
110 | 115 | % else: |
|
111 | 116 | % if comment.pull_request_version_id and pr_index_ver: |
|
112 | 117 | | |
|
113 | 118 | <div class="pr-version"> |
|
114 | 119 | % if comment.outdated: |
|
115 | 120 | <a href="?version=${comment.pull_request_version_id}#comment-${comment.comment_id}"> |
|
116 | 121 | ${_('Outdated comment from pull request version {}').format(pr_index_ver)} |
|
117 | 122 | </a> |
|
118 | 123 | % else: |
|
119 | 124 | <div title="${_('Comment from pull request version {0}').format(pr_index_ver)}"> |
|
120 | 125 | <a href="${h.url('pullrequest_show',repo_name=comment.pull_request.target_repo.repo_name,pull_request_id=comment.pull_request.pull_request_id, version=comment.pull_request_version_id)}"> |
|
121 | 126 | <code class="pr-version-num"> |
|
122 | 127 | ${'v{}'.format(pr_index_ver)} |
|
123 | 128 | </code> |
|
124 | 129 | </a> |
|
125 | 130 | </div> |
|
126 | 131 | % endif |
|
127 | 132 | </div> |
|
128 | 133 | % endif |
|
129 | 134 | % endif |
|
130 | 135 | |
|
131 | 136 | ## show delete comment if it's not a PR (regular comments) or it's PR that is not closed |
|
132 | 137 | ## only super-admin, repo admin OR comment owner can delete, also hide delete if currently viewed comment is outdated |
|
133 | 138 | %if not outdated_at_ver and (not comment.pull_request or (comment.pull_request and not comment.pull_request.is_closed())): |
|
134 | 139 | ## permissions to delete |
|
135 | 140 | %if h.HasPermissionAny('hg.admin')() or h.HasRepoPermissionAny('repository.admin')(c.repo_name) or comment.author.user_id == c.rhodecode_user.user_id: |
|
136 | 141 | ## TODO: dan: add edit comment here |
|
137 | 142 | <a onclick="return Rhodecode.comments.deleteComment(this);" class="delete-comment"> ${_('Delete')}</a> |
|
138 | 143 | %else: |
|
139 | 144 | <button class="btn-link" disabled="disabled"> ${_('Delete')}</button> |
|
140 | 145 | %endif |
|
141 | 146 | %else: |
|
142 | 147 | <button class="btn-link" disabled="disabled"> ${_('Delete')}</button> |
|
143 | 148 | %endif |
|
144 | 149 | |
|
145 | 150 | % if outdated_at_ver: |
|
146 | 151 | | <a onclick="return Rhodecode.comments.prevOutdatedComment(this);" class="prev-comment"> ${_('Prev')}</a> |
|
147 | 152 | | <a onclick="return Rhodecode.comments.nextOutdatedComment(this);" class="next-comment"> ${_('Next')}</a> |
|
148 | 153 | % else: |
|
149 | 154 | | <a onclick="return Rhodecode.comments.prevComment(this);" class="prev-comment"> ${_('Prev')}</a> |
|
150 | 155 | | <a onclick="return Rhodecode.comments.nextComment(this);" class="next-comment"> ${_('Next')}</a> |
|
151 | 156 | % endif |
|
152 | 157 | |
|
153 | 158 | </div> |
|
154 | 159 | </div> |
|
155 | 160 | <div class="text"> |
|
156 | 161 | ${comment.render(mentions=True)|n} |
|
157 | 162 | </div> |
|
158 | 163 | |
|
159 | 164 | </div> |
|
160 | 165 | </%def> |
|
161 | 166 | |
|
162 | 167 | ## generate main comments |
|
163 | 168 | <%def name="generate_comments(comments, include_pull_request=False, is_pull_request=False)"> |
|
164 | 169 | <div class="general-comments" id="comments"> |
|
165 | 170 | %for comment in comments: |
|
166 | 171 | <div id="comment-tr-${comment.comment_id}"> |
|
167 | 172 | ## only render comments that are not from pull request, or from |
|
168 | 173 | ## pull request and a status change |
|
169 | 174 | %if not comment.pull_request or (comment.pull_request and comment.status_change) or include_pull_request: |
|
170 | 175 | ${comment_block(comment)} |
|
171 | 176 | %endif |
|
172 | 177 | </div> |
|
173 | 178 | %endfor |
|
174 | 179 | ## to anchor ajax comments |
|
175 | 180 | <div id="injected_page_comments"></div> |
|
176 | 181 | </div> |
|
177 | 182 | </%def> |
|
178 | 183 | |
|
179 | 184 | |
|
180 | 185 | <%def name="comments(post_url, cur_status, is_pull_request=False, is_compare=False, change_status=True, form_extras=None)"> |
|
181 | 186 | |
|
182 | 187 | <div class="comments"> |
|
183 | 188 | <% |
|
184 | 189 | if is_pull_request: |
|
185 | 190 | placeholder = _('Leave a comment on this Pull Request.') |
|
186 | 191 | elif is_compare: |
|
187 | 192 | placeholder = _('Leave a comment on {} commits in this range.').format(len(form_extras)) |
|
188 | 193 | else: |
|
189 | 194 | placeholder = _('Leave a comment on this Commit.') |
|
190 | 195 | %> |
|
191 | 196 | |
|
192 | 197 | % if c.rhodecode_user.username != h.DEFAULT_USER: |
|
193 | 198 | <div class="js-template" id="cb-comment-general-form-template"> |
|
194 | 199 | ## template generated for injection |
|
195 | 200 | ${comment_form(form_type='general', review_statuses=c.commit_statuses, form_extras=form_extras)} |
|
196 | 201 | </div> |
|
197 | 202 | |
|
198 | 203 | <div id="cb-comment-general-form-placeholder" class="comment-form ac"> |
|
199 | 204 | ## inject form here |
|
200 | 205 | </div> |
|
201 | 206 | <script type="text/javascript"> |
|
202 | 207 | var lineNo = 'general'; |
|
203 | 208 | var resolvesCommentId = null; |
|
204 | 209 | var generalCommentForm = Rhodecode.comments.createGeneralComment( |
|
205 | 210 | lineNo, "${placeholder}", resolvesCommentId); |
|
206 | 211 | |
|
207 | 212 | // set custom success callback on rangeCommit |
|
208 | 213 | % if is_compare: |
|
209 | 214 | generalCommentForm.setHandleFormSubmit(function(o) { |
|
210 | 215 | var self = generalCommentForm; |
|
211 | 216 | |
|
212 | 217 | var text = self.cm.getValue(); |
|
213 | 218 | var status = self.getCommentStatus(); |
|
214 | 219 | var commentType = self.getCommentType(); |
|
215 | 220 | |
|
216 | 221 | if (text === "" && !status) { |
|
217 | 222 | return; |
|
218 | 223 | } |
|
219 | 224 | |
|
220 | 225 | // we can pick which commits we want to make the comment by |
|
221 | 226 | // selecting them via click on preview pane, this will alter the hidden inputs |
|
222 | 227 | var cherryPicked = $('#changeset_compare_view_content .compare_select.hl').length > 0; |
|
223 | 228 | |
|
224 | 229 | var commitIds = []; |
|
225 | 230 | $('#changeset_compare_view_content .compare_select').each(function(el) { |
|
226 | 231 | var commitId = this.id.replace('row-', ''); |
|
227 | 232 | if ($(this).hasClass('hl') || !cherryPicked) { |
|
228 | 233 | $("input[data-commit-id='{0}']".format(commitId)).val(commitId); |
|
229 | 234 | commitIds.push(commitId); |
|
230 | 235 | } else { |
|
231 | 236 | $("input[data-commit-id='{0}']".format(commitId)).val('') |
|
232 | 237 | } |
|
233 | 238 | }); |
|
234 | 239 | |
|
235 | 240 | self.setActionButtonsDisabled(true); |
|
236 | 241 | self.cm.setOption("readOnly", true); |
|
237 | 242 | var postData = { |
|
238 | 243 | 'text': text, |
|
239 | 244 | 'changeset_status': status, |
|
240 | 245 | 'comment_type': commentType, |
|
241 | 246 | 'commit_ids': commitIds, |
|
242 | 247 | 'csrf_token': CSRF_TOKEN |
|
243 | 248 | }; |
|
244 | 249 | |
|
245 | 250 | var submitSuccessCallback = function(o) { |
|
246 | 251 | location.reload(true); |
|
247 | 252 | }; |
|
248 | 253 | var submitFailCallback = function(){ |
|
249 | 254 | self.resetCommentFormState(text) |
|
250 | 255 | }; |
|
251 | 256 | self.submitAjaxPOST( |
|
252 | 257 | self.submitUrl, postData, submitSuccessCallback, submitFailCallback); |
|
253 | 258 | }); |
|
254 | 259 | % endif |
|
255 | 260 | |
|
256 | 261 | |
|
257 | 262 | </script> |
|
258 | 263 | % else: |
|
259 | 264 | ## form state when not logged in |
|
260 | 265 | <div class="comment-form ac"> |
|
261 | 266 | |
|
262 | 267 | <div class="comment-area"> |
|
263 | 268 | <div class="comment-area-header"> |
|
264 | 269 | <ul class="nav-links clearfix"> |
|
265 | 270 | <li class="active"> |
|
266 | 271 | <a class="disabled" href="#edit-btn" disabled="disabled" onclick="return false">${_('Write')}</a> |
|
267 | 272 | </li> |
|
268 | 273 | <li class=""> |
|
269 | 274 | <a class="disabled" href="#preview-btn" disabled="disabled" onclick="return false">${_('Preview')}</a> |
|
270 | 275 | </li> |
|
271 | 276 | </ul> |
|
272 | 277 | </div> |
|
273 | 278 | |
|
274 | 279 | <div class="comment-area-write" style="display: block;"> |
|
275 | 280 | <div id="edit-container"> |
|
276 | 281 | <div style="padding: 40px 0"> |
|
277 | 282 | ${_('You need to be logged in to leave comments.')} |
|
278 | 283 | <a href="${h.route_path('login', _query={'came_from': h.url.current()})}">${_('Login now')}</a> |
|
279 | 284 | </div> |
|
280 | 285 | </div> |
|
281 | 286 | <div id="preview-container" class="clearfix" style="display: none;"> |
|
282 | 287 | <div id="preview-box" class="preview-box"></div> |
|
283 | 288 | </div> |
|
284 | 289 | </div> |
|
285 | 290 | |
|
286 | 291 | <div class="comment-area-footer"> |
|
287 | 292 | <div class="toolbar"> |
|
288 | 293 | <div class="toolbar-text"> |
|
289 | 294 | </div> |
|
290 | 295 | </div> |
|
291 | 296 | </div> |
|
292 | 297 | </div> |
|
293 | 298 | |
|
294 | 299 | <div class="comment-footer"> |
|
295 | 300 | </div> |
|
296 | 301 | |
|
297 | 302 | </div> |
|
298 | 303 | % endif |
|
299 | 304 | |
|
300 | 305 | <script type="text/javascript"> |
|
301 | 306 | bindToggleButtons(); |
|
302 | 307 | </script> |
|
303 | 308 | </div> |
|
304 | 309 | </%def> |
|
305 | 310 | |
|
306 | 311 | |
|
307 | 312 | <%def name="comment_form(form_type, form_id='', lineno_id='{1}', review_statuses=None, form_extras=None)"> |
|
308 | 313 | ## comment injected based on assumption that user is logged in |
|
309 | 314 | |
|
310 | 315 | <form ${'id="{}"'.format(form_id) if form_id else '' |n} action="#" method="GET"> |
|
311 | 316 | |
|
312 | 317 | <div class="comment-area"> |
|
313 | 318 | <div class="comment-area-header"> |
|
314 | 319 | <ul class="nav-links clearfix"> |
|
315 | 320 | <li class="active"> |
|
316 | 321 | <a href="#edit-btn" tabindex="-1" id="edit-btn_${lineno_id}">${_('Write')}</a> |
|
317 | 322 | </li> |
|
318 | 323 | <li class=""> |
|
319 | 324 | <a href="#preview-btn" tabindex="-1" id="preview-btn_${lineno_id}">${_('Preview')}</a> |
|
320 | 325 | </li> |
|
321 | 326 | <li class="pull-right"> |
|
322 | 327 | <select class="comment-type" id="comment_type_${lineno_id}" name="comment_type"> |
|
323 | 328 | % for val in c.visual.comment_types: |
|
324 | 329 | <option value="${val}">${val.upper()}</option> |
|
325 | 330 | % endfor |
|
326 | 331 | </select> |
|
327 | 332 | </li> |
|
328 | 333 | </ul> |
|
329 | 334 | </div> |
|
330 | 335 | |
|
331 | 336 | <div class="comment-area-write" style="display: block;"> |
|
332 | 337 | <div id="edit-container_${lineno_id}"> |
|
333 | 338 | <textarea id="text_${lineno_id}" name="text" class="comment-block-ta ac-input"></textarea> |
|
334 | 339 | </div> |
|
335 | 340 | <div id="preview-container_${lineno_id}" class="clearfix" style="display: none;"> |
|
336 | 341 | <div id="preview-box_${lineno_id}" class="preview-box"></div> |
|
337 | 342 | </div> |
|
338 | 343 | </div> |
|
339 | 344 | |
|
340 | 345 | <div class="comment-area-footer"> |
|
341 | 346 | <div class="toolbar"> |
|
342 | 347 | <div class="toolbar-text"> |
|
343 | 348 | ${(_('Comments parsed using %s syntax with %s, and %s actions support.') % ( |
|
344 | 349 | ('<a href="%s">%s</a>' % (h.url('%s_help' % c.visual.default_renderer), c.visual.default_renderer.upper())), |
|
345 | 350 | ('<span class="tooltip" title="%s">@mention</span>' % _('Use @username inside this text to send notification to this RhodeCode user')), |
|
346 | 351 | ('<span class="tooltip" title="%s">`/`</span>' % _('Start typing with / for certain actions to be triggered via text box.')) |
|
347 | 352 | ) |
|
348 | 353 | )|n} |
|
349 | 354 | </div> |
|
350 | 355 | </div> |
|
351 | 356 | </div> |
|
352 | 357 | </div> |
|
353 | 358 | |
|
354 | 359 | <div class="comment-footer"> |
|
355 | 360 | |
|
356 | 361 | % if review_statuses: |
|
357 | 362 | <div class="status_box"> |
|
358 | 363 | <select id="change_status_${lineno_id}" name="changeset_status"> |
|
359 | 364 | <option></option> ## Placeholder |
|
360 | 365 | % for status, lbl in review_statuses: |
|
361 | 366 | <option value="${status}" data-status="${status}">${lbl}</option> |
|
362 | 367 | %if is_pull_request and change_status and status in ('approved', 'rejected'): |
|
363 | 368 | <option value="${status}_closed" data-status="${status}">${lbl} & ${_('Closed')}</option> |
|
364 | 369 | %endif |
|
365 | 370 | % endfor |
|
366 | 371 | </select> |
|
367 | 372 | </div> |
|
368 | 373 | % endif |
|
369 | 374 | |
|
370 | 375 | ## inject extra inputs into the form |
|
371 | 376 | % if form_extras and isinstance(form_extras, (list, tuple)): |
|
372 | 377 | <div id="comment_form_extras"> |
|
373 | 378 | % for form_ex_el in form_extras: |
|
374 | 379 | ${form_ex_el|n} |
|
375 | 380 | % endfor |
|
376 | 381 | </div> |
|
377 | 382 | % endif |
|
378 | 383 | |
|
379 | 384 | <div class="action-buttons"> |
|
380 | 385 | ## inline for has a file, and line-number together with cancel hide button. |
|
381 | 386 | % if form_type == 'inline': |
|
382 | 387 | <input type="hidden" name="f_path" value="{0}"> |
|
383 | 388 | <input type="hidden" name="line" value="${lineno_id}"> |
|
384 | 389 | <button type="button" class="cb-comment-cancel" onclick="return Rhodecode.comments.cancelComment(this);"> |
|
385 | 390 | ${_('Cancel')} |
|
386 | 391 | </button> |
|
387 | 392 | % endif |
|
388 | 393 | |
|
389 | 394 | % if form_type != 'inline': |
|
390 | 395 | <div class="action-buttons-extra"></div> |
|
391 | 396 | % endif |
|
392 | 397 | |
|
393 | 398 | ${h.submit('save', _('Comment'), class_='btn btn-success comment-button-input')} |
|
394 | 399 | |
|
395 | 400 | </div> |
|
396 | 401 | </div> |
|
397 | 402 | |
|
398 | 403 | </form> |
|
399 | 404 | |
|
400 | 405 | </%def> No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now