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