##// END OF EJS Templates
pull-requests: added quick filter to grid view.
marcink -
r4055:8b8d49d6 default
parent child Browse files
Show More
@@ -76,28 +76,28 b' class RepoPullRequestsView(RepoAppView, '
76
76
77 if filter_type == 'awaiting_review':
77 if filter_type == 'awaiting_review':
78 pull_requests = PullRequestModel().get_awaiting_review(
78 pull_requests = PullRequestModel().get_awaiting_review(
79 repo_name, source=source, opened_by=opened_by,
79 repo_name, search_q=search_q, source=source, opened_by=opened_by,
80 statuses=statuses, offset=start, length=limit,
80 statuses=statuses, offset=start, length=limit,
81 order_by=order_by, order_dir=order_dir)
81 order_by=order_by, order_dir=order_dir)
82 pull_requests_total_count = PullRequestModel().count_awaiting_review(
82 pull_requests_total_count = PullRequestModel().count_awaiting_review(
83 repo_name, source=source, statuses=statuses,
83 repo_name, search_q=search_q, source=source, statuses=statuses,
84 opened_by=opened_by)
84 opened_by=opened_by)
85 elif filter_type == 'awaiting_my_review':
85 elif filter_type == 'awaiting_my_review':
86 pull_requests = PullRequestModel().get_awaiting_my_review(
86 pull_requests = PullRequestModel().get_awaiting_my_review(
87 repo_name, source=source, opened_by=opened_by,
87 repo_name, search_q=search_q, source=source, opened_by=opened_by,
88 user_id=self._rhodecode_user.user_id, statuses=statuses,
88 user_id=self._rhodecode_user.user_id, statuses=statuses,
89 offset=start, length=limit, order_by=order_by,
89 offset=start, length=limit, order_by=order_by,
90 order_dir=order_dir)
90 order_dir=order_dir)
91 pull_requests_total_count = PullRequestModel().count_awaiting_my_review(
91 pull_requests_total_count = PullRequestModel().count_awaiting_my_review(
92 repo_name, source=source, user_id=self._rhodecode_user.user_id,
92 repo_name, search_q=search_q, source=source, user_id=self._rhodecode_user.user_id,
93 statuses=statuses, opened_by=opened_by)
93 statuses=statuses, opened_by=opened_by)
94 else:
94 else:
95 pull_requests = PullRequestModel().get_all(
95 pull_requests = PullRequestModel().get_all(
96 repo_name, source=source, opened_by=opened_by,
96 repo_name, search_q=search_q, source=source, opened_by=opened_by,
97 statuses=statuses, offset=start, length=limit,
97 statuses=statuses, offset=start, length=limit,
98 order_by=order_by, order_dir=order_dir)
98 order_by=order_by, order_dir=order_dir)
99 pull_requests_total_count = PullRequestModel().count_all(
99 pull_requests_total_count = PullRequestModel().count_all(
100 repo_name, source=source, statuses=statuses,
100 repo_name, search_q=search_q, source=source, statuses=statuses,
101 opened_by=opened_by)
101 opened_by=opened_by)
102
102
103 data = []
103 data = []
@@ -37,7 +37,7 b' import traceback'
37 import collections
37 import collections
38
38
39 from sqlalchemy import (
39 from sqlalchemy import (
40 or_, and_, not_, func, TypeDecorator, event,
40 or_, and_, not_, func, cast, TypeDecorator, event,
41 Index, Sequence, UniqueConstraint, ForeignKey, CheckConstraint, Column,
41 Index, Sequence, UniqueConstraint, ForeignKey, CheckConstraint, Column,
42 Boolean, String, Unicode, UnicodeText, DateTime, Integer, LargeBinary,
42 Boolean, String, Unicode, UnicodeText, DateTime, Integer, LargeBinary,
43 Text, Float, PickleType, BigInteger)
43 Text, Float, PickleType, BigInteger)
@@ -51,7 +51,7 b' from rhodecode.model import BaseModel'
51 from rhodecode.model.changeset_status import ChangesetStatusModel
51 from rhodecode.model.changeset_status import ChangesetStatusModel
52 from rhodecode.model.comment import CommentsModel
52 from rhodecode.model.comment import CommentsModel
53 from rhodecode.model.db import (
53 from rhodecode.model.db import (
54 or_, PullRequest, PullRequestReviewers, ChangesetStatus,
54 or_, String, cast, PullRequest, PullRequestReviewers, ChangesetStatus,
55 PullRequestVersion, ChangesetComment, Repository, RepoReviewRule)
55 PullRequestVersion, ChangesetComment, Repository, RepoReviewRule)
56 from rhodecode.model.meta import Session
56 from rhodecode.model.meta import Session
57 from rhodecode.model.notification import NotificationModel, \
57 from rhodecode.model.notification import NotificationModel, \
@@ -137,8 +137,8 b' class PullRequestModel(BaseModel):'
137 def get(self, pull_request):
137 def get(self, pull_request):
138 return self.__get_pull_request(pull_request)
138 return self.__get_pull_request(pull_request)
139
139
140 def _prepare_get_all_query(self, repo_name, source=False, statuses=None,
140 def _prepare_get_all_query(self, repo_name, search_q=None, source=False,
141 opened_by=None, order_by=None,
141 statuses=None, opened_by=None, order_by=None,
142 order_dir='desc', only_created=False):
142 order_dir='desc', only_created=False):
143 repo = None
143 repo = None
144 if repo_name:
144 if repo_name:
@@ -146,6 +146,14 b' class PullRequestModel(BaseModel):'
146
146
147 q = PullRequest.query()
147 q = PullRequest.query()
148
148
149 if search_q:
150 like_expression = u'%{}%'.format(safe_unicode(search_q))
151 q = q.filter(or_(
152 cast(PullRequest.pull_request_id, String).ilike(like_expression),
153 PullRequest.title.ilike(like_expression),
154 PullRequest.description.ilike(like_expression),
155 ))
156
149 # source or target
157 # source or target
150 if repo and source:
158 if repo and source:
151 q = q.filter(PullRequest.source_repo == repo)
159 q = q.filter(PullRequest.source_repo == repo)
@@ -179,28 +187,31 b' class PullRequestModel(BaseModel):'
179
187
180 return q
188 return q
181
189
182 def count_all(self, repo_name, source=False, statuses=None,
190 def count_all(self, repo_name, search_q=None, source=False, statuses=None,
183 opened_by=None):
191 opened_by=None):
184 """
192 """
185 Count the number of pull requests for a specific repository.
193 Count the number of pull requests for a specific repository.
186
194
187 :param repo_name: target or source repo
195 :param repo_name: target or source repo
196 :param search_q: filter by text
188 :param source: boolean flag to specify if repo_name refers to source
197 :param source: boolean flag to specify if repo_name refers to source
189 :param statuses: list of pull request statuses
198 :param statuses: list of pull request statuses
190 :param opened_by: author user of the pull request
199 :param opened_by: author user of the pull request
191 :returns: int number of pull requests
200 :returns: int number of pull requests
192 """
201 """
193 q = self._prepare_get_all_query(
202 q = self._prepare_get_all_query(
194 repo_name, source=source, statuses=statuses, opened_by=opened_by)
203 repo_name, search_q=search_q, source=source, statuses=statuses,
204 opened_by=opened_by)
195
205
196 return q.count()
206 return q.count()
197
207
198 def get_all(self, repo_name, source=False, statuses=None, opened_by=None,
208 def get_all(self, repo_name, search_q=None, source=False, statuses=None,
199 offset=0, length=None, order_by=None, order_dir='desc'):
209 opened_by=None, offset=0, length=None, order_by=None, order_dir='desc'):
200 """
210 """
201 Get all pull requests for a specific repository.
211 Get all pull requests for a specific repository.
202
212
203 :param repo_name: target or source repo
213 :param repo_name: target or source repo
214 :param search_q: filter by text
204 :param source: boolean flag to specify if repo_name refers to source
215 :param source: boolean flag to specify if repo_name refers to source
205 :param statuses: list of pull request statuses
216 :param statuses: list of pull request statuses
206 :param opened_by: author user of the pull request
217 :param opened_by: author user of the pull request
@@ -211,8 +222,8 b' class PullRequestModel(BaseModel):'
211 :returns: list of pull requests
222 :returns: list of pull requests
212 """
223 """
213 q = self._prepare_get_all_query(
224 q = self._prepare_get_all_query(
214 repo_name, source=source, statuses=statuses, opened_by=opened_by,
225 repo_name, search_q=search_q, source=source, statuses=statuses,
215 order_by=order_by, order_dir=order_dir)
226 opened_by=opened_by, order_by=order_by, order_dir=order_dir)
216
227
217 if length:
228 if length:
218 pull_requests = q.limit(length).offset(offset).all()
229 pull_requests = q.limit(length).offset(offset).all()
@@ -221,24 +232,25 b' class PullRequestModel(BaseModel):'
221
232
222 return pull_requests
233 return pull_requests
223
234
224 def count_awaiting_review(self, repo_name, source=False, statuses=None,
235 def count_awaiting_review(self, repo_name, search_q=None, source=False, statuses=None,
225 opened_by=None):
236 opened_by=None):
226 """
237 """
227 Count the number of pull requests for a specific repository that are
238 Count the number of pull requests for a specific repository that are
228 awaiting review.
239 awaiting review.
229
240
230 :param repo_name: target or source repo
241 :param repo_name: target or source repo
242 :param search_q: filter by text
231 :param source: boolean flag to specify if repo_name refers to source
243 :param source: boolean flag to specify if repo_name refers to source
232 :param statuses: list of pull request statuses
244 :param statuses: list of pull request statuses
233 :param opened_by: author user of the pull request
245 :param opened_by: author user of the pull request
234 :returns: int number of pull requests
246 :returns: int number of pull requests
235 """
247 """
236 pull_requests = self.get_awaiting_review(
248 pull_requests = self.get_awaiting_review(
237 repo_name, source=source, statuses=statuses, opened_by=opened_by)
249 repo_name, search_q=search_q, source=source, statuses=statuses, opened_by=opened_by)
238
250
239 return len(pull_requests)
251 return len(pull_requests)
240
252
241 def get_awaiting_review(self, repo_name, source=False, statuses=None,
253 def get_awaiting_review(self, repo_name, search_q=None, source=False, statuses=None,
242 opened_by=None, offset=0, length=None,
254 opened_by=None, offset=0, length=None,
243 order_by=None, order_dir='desc'):
255 order_by=None, order_dir='desc'):
244 """
256 """
@@ -246,6 +258,7 b' class PullRequestModel(BaseModel):'
246 review.
258 review.
247
259
248 :param repo_name: target or source repo
260 :param repo_name: target or source repo
261 :param search_q: filter by text
249 :param source: boolean flag to specify if repo_name refers to source
262 :param source: boolean flag to specify if repo_name refers to source
250 :param statuses: list of pull request statuses
263 :param statuses: list of pull request statuses
251 :param opened_by: author user of the pull request
264 :param opened_by: author user of the pull request
@@ -256,8 +269,8 b' class PullRequestModel(BaseModel):'
256 :returns: list of pull requests
269 :returns: list of pull requests
257 """
270 """
258 pull_requests = self.get_all(
271 pull_requests = self.get_all(
259 repo_name, source=source, statuses=statuses, opened_by=opened_by,
272 repo_name, search_q=search_q, source=source, statuses=statuses,
260 order_by=order_by, order_dir=order_dir)
273 opened_by=opened_by, order_by=order_by, order_dir=order_dir)
261
274
262 _filtered_pull_requests = []
275 _filtered_pull_requests = []
263 for pr in pull_requests:
276 for pr in pull_requests:
@@ -270,13 +283,14 b' class PullRequestModel(BaseModel):'
270 else:
283 else:
271 return _filtered_pull_requests
284 return _filtered_pull_requests
272
285
273 def count_awaiting_my_review(self, repo_name, source=False, statuses=None,
286 def count_awaiting_my_review(self, repo_name, search_q=None, source=False, statuses=None,
274 opened_by=None, user_id=None):
287 opened_by=None, user_id=None):
275 """
288 """
276 Count the number of pull requests for a specific repository that are
289 Count the number of pull requests for a specific repository that are
277 awaiting review from a specific user.
290 awaiting review from a specific user.
278
291
279 :param repo_name: target or source repo
292 :param repo_name: target or source repo
293 :param search_q: filter by text
280 :param source: boolean flag to specify if repo_name refers to source
294 :param source: boolean flag to specify if repo_name refers to source
281 :param statuses: list of pull request statuses
295 :param statuses: list of pull request statuses
282 :param opened_by: author user of the pull request
296 :param opened_by: author user of the pull request
@@ -284,12 +298,12 b' class PullRequestModel(BaseModel):'
284 :returns: int number of pull requests
298 :returns: int number of pull requests
285 """
299 """
286 pull_requests = self.get_awaiting_my_review(
300 pull_requests = self.get_awaiting_my_review(
287 repo_name, source=source, statuses=statuses, opened_by=opened_by,
301 repo_name, search_q=search_q, source=source, statuses=statuses,
288 user_id=user_id)
302 opened_by=opened_by, user_id=user_id)
289
303
290 return len(pull_requests)
304 return len(pull_requests)
291
305
292 def get_awaiting_my_review(self, repo_name, source=False, statuses=None,
306 def get_awaiting_my_review(self, repo_name, search_q=None, source=False, statuses=None,
293 opened_by=None, user_id=None, offset=0,
307 opened_by=None, user_id=None, offset=0,
294 length=None, order_by=None, order_dir='desc'):
308 length=None, order_by=None, order_dir='desc'):
295 """
309 """
@@ -297,6 +311,7 b' class PullRequestModel(BaseModel):'
297 review from a specific user.
311 review from a specific user.
298
312
299 :param repo_name: target or source repo
313 :param repo_name: target or source repo
314 :param search_q: filter by text
300 :param source: boolean flag to specify if repo_name refers to source
315 :param source: boolean flag to specify if repo_name refers to source
301 :param statuses: list of pull request statuses
316 :param statuses: list of pull request statuses
302 :param opened_by: author user of the pull request
317 :param opened_by: author user of the pull request
@@ -308,8 +323,8 b' class PullRequestModel(BaseModel):'
308 :returns: list of pull requests
323 :returns: list of pull requests
309 """
324 """
310 pull_requests = self.get_all(
325 pull_requests = self.get_all(
311 repo_name, source=source, statuses=statuses, opened_by=opened_by,
326 repo_name, search_q=search_q, source=source, statuses=statuses,
312 order_by=order_by, order_dir=order_dir)
327 opened_by=opened_by, order_by=order_by, order_dir=order_dir)
313
328
314 _my = PullRequestModel().get_not_reviewed(user_id)
329 _my = PullRequestModel().get_not_reviewed(user_id)
315 my_participation = []
330 my_participation = []
@@ -42,6 +42,20 b''
42 </span>
42 </span>
43 </li>
43 </li>
44 % endif
44 % endif
45
46 <li>
47 <div class="grid-quick-filter">
48 <ul class="grid-filter-box">
49 <li class="grid-filter-box-icon">
50 <i class="icon-search"></i>
51 </li>
52 <li class="grid-filter-box-input">
53 <input class="q_filter_box" id="q_filter" size="15" type="text" name="filter" placeholder="${_('quick filter...')}" value=""/>
54 </li>
55 </ul>
56 </div>
57 </li>
58
45 </ul>
59 </ul>
46
60
47 </div>
61 </div>
@@ -54,7 +68,6 b''
54
68
55 <script type="text/javascript">
69 <script type="text/javascript">
56 $(document).ready(function() {
70 $(document).ready(function() {
57
58 var $pullRequestListTable = $('#pull_request_list_table');
71 var $pullRequestListTable = $('#pull_request_list_table');
59
72
60 // object list
73 // object list
@@ -115,6 +128,15 b''
115 $pullRequestListTable.css('opacity', 0.3);
128 $pullRequestListTable.css('opacity', 0.3);
116 });
129 });
117
130
131 // filter
132 $('#q_filter').on('keyup',
133 $.debounce(250, function() {
134 $pullRequestListTable.DataTable().search(
135 $('#q_filter').val()
136 ).draw();
137 })
138 );
139
118 });
140 });
119
141
120 </script>
142 </script>
General Comments 0
You need to be logged in to leave comments. Login now