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