home » zplus/clif.git
Author zPlus <zplus@peers.community> 2022-08-03 18:38:24
Committer zPlus <zplus@peers.community> 2022-08-03 18:38:24
Commit 58e8483 (patch)
Tree b730647
Parent(s)

Add pagination to Log page.


commits diff: 6b84231..58e8483
2 files changed, 29 insertions, 3 deletionsdownload


Diffstat
-rw-r--r-- templates/repository/log.html 11
-rw-r--r-- web.py 21

Diff options
View
Side
Whitespace
Context lines
Inter-hunk lines
+11/-0 M   templates/repository/log.html
index d65c579..c0372e1
old size: 3K - new size: 3K
@@ -74,6 +74,17 @@
74 74 </tbody>
75 75 </table>
76 76
77 + <br />
78 +
79 + {% if offset > 0 %}
80 + {% set prev_offset = offset - log_pagination %}
81 + <a href="{{ url('log', repository=repository[:-4], revision=revision, offset=prev_offset) }}">« Prev</a>
82 + {% endif %}
83 +
84 + {% if commits|length == log_pagination %}
85 + {% set next_offset = offset + log_pagination %}
86 + <a href="{{ url('log', repository=repository[:-4], revision=revision, offset=next_offset) }}">Next »</a>
87 + {% endif %}
77 88 </div>
78 89
79 90 {% endblock %}

+18/-3 M   web.py
index de85fc3..e36d895
old size: 23K - new size: 24K
@@ -40,6 +40,9 @@ GITOLITE_HTTP_HOME = '/home/git'
40 40 # or when the domain needs to be displayed on some pages.
41 41 INSTANCE_DOMAIN = 'domain.local'
42 42
43 + # How many commits to show in the log page
44 + LOG_PAGINATION = 100
45 +
43 46
44 47
45 48
@@ -461,17 +464,29 @@ def log(repository, revision):
461 464
462 465 # At this point git_object should be a valid pygit2.GIT_OBJ_COMMIT
463 466
464 - # Read 50 commits
467 + # Read commits
468 + try: commits_offset = int(request.query.get('offset', 0))
469 + except: commits_offset = 0
470 +
465 471 commits = []
472 + commit_ith = 0
466 473 for commit in repo.walk(git_object.id):
467 - commits.append(commit)
468 - if len(commits) >= 50:
474 + # Skip the first one (offset)
475 + if commit_ith < commits_offset:
476 + commit_ith += 1
477 + continue
478 +
479 + # Stop if we have reached pagination size
480 + if len(commits) >= LOG_PAGINATION:
469 481 break
482 +
483 + commits.append(commit)
470 484
471 485 return template(
472 486 'repository/log.html',
473 487 heads=heads, head_ref=HEAD, tags=tags,
474 488 commits=commits,
489 + log_pagination=LOG_PAGINATION, offset=commits_offset,
475 490 repository=repository, revision=revision)
476 491
477 492 @bottle.post('/<repository:path>.git/log', name='log_change')