##// END OF EJS Templates
Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
marcink -
r2439:ad19dfcd codereview
parent child Browse files
Show More
@@ -220,10 +220,10 b' class ChangesetController(BaseRepoContro'
220 220
221 221 c.comments.extend(ChangesetCommentsModel()\
222 222 .get_comments(c.rhodecode_db_repo.repo_id,
223 changeset.raw_id))
223 revision=changeset.raw_id))
224 224 inlines = ChangesetCommentsModel()\
225 225 .get_inline_comments(c.rhodecode_db_repo.repo_id,
226 changeset.raw_id)
226 revision=changeset.raw_id)
227 227 c.inline_comments.extend(inlines)
228 228 c.changes[changeset.raw_id] = []
229 229 try:
@@ -295,7 +295,7 b' class ChangesetController(BaseRepoContro'
295 295 )
296 296
297 297 # count inline comments
298 for path, lines in c.inline_comments:
298 for _, lines in c.inline_comments:
299 299 for comments in lines.values():
300 300 c.inline_cnt += len(comments)
301 301
@@ -135,21 +135,44 b' class ChangesetCommentsModel(BaseModel):'
135 135
136 136 return comment
137 137
138 def get_comments(self, repo_id, revision):
139 return ChangesetComment.query()\
138 def get_comments(self, repo_id, revision=None, pull_request_id=None):
139 """
140 Get's main comments based on revision or pull_request_id
141
142 :param repo_id:
143 :type repo_id:
144 :param revision:
145 :type revision:
146 :param pull_request_id:
147 :type pull_request_id:
148 """
149 q = ChangesetComment.query()\
140 150 .filter(ChangesetComment.repo_id == repo_id)\
141 .filter(ChangesetComment.revision == revision)\
142 151 .filter(ChangesetComment.line_no == None)\
143 .filter(ChangesetComment.f_path == None).all()
152 .filter(ChangesetComment.f_path == None)
153 if revision:
154 q = q.filter(ChangesetComment.revision == revision)
155 elif pull_request_id:
156 q = q.filter(ChangesetComment.pull_request_id == pull_request_id)
157 else:
158 raise Exception('Please specify revision or pull_request_id')
159 return q.all()
144 160
145 def get_inline_comments(self, repo_id, revision):
146 comments = self.sa.query(ChangesetComment)\
161 def get_inline_comments(self, repo_id, revision=None, pull_request_id=None):
162 q = self.sa.query(ChangesetComment)\
147 163 .filter(ChangesetComment.repo_id == repo_id)\
148 .filter(ChangesetComment.revision == revision)\
149 164 .filter(ChangesetComment.line_no != None)\
150 165 .filter(ChangesetComment.f_path != None)\
151 166 .order_by(ChangesetComment.comment_id.asc())\
152 .all()
167
168 if revision:
169 q = q.filter(ChangesetComment.revision == revision)
170 elif pull_request_id:
171 q = q.filter(ChangesetComment.pull_request_id == pull_request_id)
172 else:
173 raise Exception('Please specify revision or pull_request_id')
174
175 comments = q.all()
153 176
154 177 paths = defaultdict(lambda: defaultdict(list))
155 178
@@ -134,8 +134,10 b''
134 134 <%namespace name="comment" file="/changeset/changeset_file_comment.html"/>
135 135 ${comment.comment_inline_form(c.changeset)}
136 136
137 ## render comments
138 ${comment.comments(c.changeset)}
137 ## render comments main comments form and it status
138 ${comment.comments(h.url('changeset_comment', repo_name=c.repo_name, revision=c.changeset.raw_id),
139 h.changeset_status(c.rhodecode_db_repo, c.changeset.raw_id))}
140
139 141 <script type="text/javascript">
140 142 YUE.onDOMReady(function(){
141 143 AJAX_COMMENT_URL = "${url('changeset_comment',repo_name=c.repo_name,revision=c.changeset.raw_id)}";
@@ -166,14 +168,6 b''
166 168 var file_comments = YUQ('.inline-comment-placeholder');
167 169 renderInlineComments(file_comments);
168 170
169 YUE.on(YUD.get('show_changeset_status_box'),'change',function(e){
170 if(e.currentTarget.checked){
171 YUD.setStyle('status_block_container','display','');
172 }
173 else{
174 YUD.setStyle('status_block_container','display','none');
175 }
176 })
177 171 })
178 172
179 173 </script>
@@ -77,7 +77,8 b''
77 77 </%def>
78 78
79 79
80 <%def name="inlines(changeset)">
80 ## generates inlines taken from c.comments var
81 <%def name="inlines()">
81 82 <div class="comments-number">${ungettext("%d comment", "%d comments", len(c.comments)) % len(c.comments)} ${ungettext("(%d inline)", "(%d inline)", c.inline_cnt) % c.inline_cnt}</div>
82 83 %for path, lines in c.inline_comments:
83 84 % for line,comments in lines.iteritems():
@@ -92,11 +93,12 b''
92 93 </%def>
93 94
94 95 ## MAIN COMMENT FORM
95 <%def name="comments(changeset)">
96 <%def name="comments(post_url, cur_status)">
96 97
97 98 <div class="comments">
98 99 <div id="inline-comments-container">
99 ${inlines(changeset)}
100 ## generate inlines for this changeset
101 ${inlines()}
100 102 </div>
101 103
102 104 %for co in c.comments:
@@ -106,7 +108,7 b''
106 108 %endfor
107 109 %if c.rhodecode_user.username != 'default':
108 110 <div class="comment-form ac">
109 ${h.form(h.url('changeset_comment', repo_name=c.repo_name, revision=changeset.raw_id))}
111 ${h.form(post_url)}
110 112 <strong>${_('Leave a comment')}</strong>
111 113 <div class="clearfix">
112 114 <div class="comment-help">
@@ -120,7 +122,7 b''
120 122 <div id="status_block_container" class="status-block" style="display:none">
121 123 %for status,lbl in c.changeset_statuses:
122 124 <div class="">
123 <img src="${h.url('/images/icons/flag_status_%s.png' % status)}" /> <input ${'checked="checked"' if status == h.changeset_status(c.rhodecode_db_repo, c.changeset.raw_id) else ''}" type="radio" name="changeset_status" value="${status}"> <label>${lbl}</label>
125 <img src="${h.url('/images/icons/flag_status_%s.png' % status)}" /> <input ${'checked="checked"' if status == cur_status else ''}" type="radio" name="changeset_status" value="${status}"> <label>${lbl}</label>
124 126 </div>
125 127 %endfor
126 128 </div>
@@ -137,6 +139,17 b''
137 139 <script>
138 140 YUE.onDOMReady(function () {
139 141 MentionsAutoComplete('text', 'mentions_container', _USERS_AC_DATA, _GROUPS_AC_DATA);
142
143 // changeset status box listener
144 YUE.on(YUD.get('show_changeset_status_box'),'change',function(e){
145 if(e.currentTarget.checked){
146 YUD.setStyle('status_block_container','display','');
147 }
148 else{
149 YUD.setStyle('status_block_container','display','none');
150 }
151 })
152
140 153 });
141 154 </script>
142 155 </%def>
General Comments 0
You need to be logged in to leave comments. Login now