[PATCH 2 of 2] ui: Add support for extra 'quick' icons in repo browser

Ross Thomas ross at lns-nevasoft.com
Sat Feb 8 01:06:06 UTC 2020


# HG changeset patch
# User Ross Thomas <ross at lns-nevasoft.com>
# Date 1581113799 28800
#      Fri Feb 07 14:16:39 2020 -0800
# Branch stable
# Node ID 504adebdb50183678de362b52bc89a9c082f4ea7
# Parent  f273a7b53fe035c12a55b6a3e34f849af245d797
ui: Add support for extra 'quick' icons in repo browser
config: Add new value 'repo_list_extra' to enable/disable 'quick' icons

diff -r f273a7b53fe0 -r 504adebdb501 development.ini
--- a/development.ini	Fri Feb 07 13:55:27 2020 -0800
+++ b/development.ini	Fri Feb 07 14:16:39 2020 -0800
@@ -227,6 +227,9 @@
 #    INSTALL
 #    CHANGELOG
 
+## adds extra 'quick' action buttons to repos listed in the repository browsing pages.
+repo_list_extra = False
+
 ####################################
 ###           SSH CONFIG        ####
 ####################################
diff -r f273a7b53fe0 -r 504adebdb501 kallithea/controllers/home.py
--- a/kallithea/controllers/home.py	Fri Feb 07 13:55:27 2020 -0800
+++ b/kallithea/controllers/home.py	Fri Feb 07 14:16:39 2020 -0800
@@ -34,10 +34,12 @@
 from tg.i18n import ugettext as _
 from webob.exc import HTTPBadRequest
 
+from kallithea import CONFIG
 from kallithea.lib import helpers as h
 from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
 from kallithea.lib.base import BaseController, jsonify, render
 from kallithea.lib.utils import conditional_cache
+from kallithea.lib.utils2 import str2bool
 from kallithea.model.db import RepoGroup, Repository, User, UserGroup
 from kallithea.model.repo import RepoModel
 from kallithea.model.scm import UserGroupList
@@ -58,9 +60,11 @@
         repo_groups_list = self.scm_model.get_repo_groups()
         repos_list = Repository.query(sorted=True).filter_by(group=None).all()
 
+        with_extra = str2bool(CONFIG.get('repo_list_extra', False))
         c.data = RepoModel().get_repos_as_dict(repos_list,
                                                repo_groups_list=repo_groups_list,
-                                               short_name=True)
+                                               short_name=True,
+                                               with_extra = with_extra)
 
         return render('/index.html')
 
diff -r f273a7b53fe0 -r 504adebdb501 kallithea/front-end/style.less
--- a/kallithea/front-end/style.less	Fri Feb 07 13:55:27 2020 -0800
+++ b/kallithea/front-end/style.less	Fri Feb 07 14:16:39 2020 -0800
@@ -957,3 +957,9 @@
   /* the blue color doesn't look good, use normal color */
   color: inherit;
 }
+
+/* Repo list extras (could be combined with 'following' styles above */
+#content .follow .list-extra.show-following,
+#content .following .list-extra.show-follow {
+  display: none;
+}
diff -r f273a7b53fe0 -r 504adebdb501 kallithea/lib/paster_commands/template.ini.mako
--- a/kallithea/lib/paster_commands/template.ini.mako	Fri Feb 07 13:55:27 2020 -0800
+++ b/kallithea/lib/paster_commands/template.ini.mako	Fri Feb 07 14:16:39 2020 -0800
@@ -324,6 +324,9 @@
 #    INSTALL
 #    CHANGELOG
 
+<%text>## adds extra 'quick' action buttons to repos listed in the repository browsing pages.</%text>
+repo_list_extra = False
+
 <%text>####################################</%text>
 <%text>###           SSH CONFIG        ####</%text>
 <%text>####################################</%text>
diff -r f273a7b53fe0 -r 504adebdb501 kallithea/model/repo.py
--- a/kallithea/model/repo.py	Fri Feb 07 13:55:27 2020 -0800
+++ b/kallithea/model/repo.py	Fri Feb 07 14:16:39 2020 -0800
@@ -132,7 +132,8 @@
 
     def get_repos_as_dict(self, repos_list, repo_groups_list=None,
                           admin=False,
-                          short_name=False):
+                          short_name=False,
+                          with_extra=False):
         """Return repository list for use by DataTable.
         repos_list: list of repositories - but will be filtered for read permission.
         repo_groups_list: added at top of list without permission check.
@@ -171,6 +172,9 @@
         def owner_actions(owner_id, username):
             return _render('user_name', owner_id, username)
 
+        def list_extra(repo_id, repo_name, is_following):
+            return _render('list_extra', repo_id, repo_name, is_following)
+
         repos_data = []
 
         for gr in repo_groups_list or []:
@@ -199,6 +203,19 @@
                 "rss": rss_lnk(repo.repo_name),
                 "atom": atom_lnk(repo.repo_name),
             }
+
+            # Add the 'extra' action items if requested
+            if with_extra:
+                from tg import request
+                from kallithea.model.scm import ScmModel
+
+                is_following = ScmModel().is_following_repo(
+                    repo.repo_name, request.authuser.user_id)
+
+                row.update({
+                    "extra": list_extra(repo.repo_id, repo.repo_name, is_following)
+                })
+
             if admin:
                 row.update({
                     "action": repo_actions(repo.repo_name),
diff -r f273a7b53fe0 -r 504adebdb501 kallithea/templates/data_table/_dt_elements.html
--- a/kallithea/templates/data_table/_dt_elements.html	Fri Feb 07 13:55:27 2020 -0800
+++ b/kallithea/templates/data_table/_dt_elements.html	Fri Feb 07 14:16:39 2020 -0800
@@ -59,6 +59,20 @@
   %endif
 </%def>
 
+<%def name="list_extra(repo_id, repo_name, repo_following)">
+  ## N.B. Same reservations as expressed in base.html (from whence this came)
+  %if request.authuser.username != 'default':
+    ## NOTE:  Needs to be one line or 'space' link rendered after icon
+    <a href="#" class="${'following' if repo_following else 'follow'}" onclick="toggleFollowingRepo(this, ${repo_id});"><i class="list-extra icon-heart-empty show-follow" title="${_('Follow')}"></i><i class="list-extra icon-heart show-following" title="${_('Unfollow')}"></i></a>
+
+    <a href="${h.url('repo_fork_home',repo_name=repo_name)}" title="${_('Fork')}"><i class="icon-fork"></i></a>
+  %endif
+
+  %if h.HasRepoPermissionLevel('admin')(repo_name):
+    <a href="${h.url('edit_repo',repo_name=repo_name)}" title="${_('Settings')}"><i class="icon-gear"></i></a>
+  %endif
+</%def>
+
 <%def name="repo_actions(repo_name)">
       <a href="${h.url('edit_repo',repo_name=repo_name)}" title="${_('Edit')}" class="btn btn-default btn-xs">
         <i class="icon-pencil"></i>${_('Edit')}
diff -r f273a7b53fe0 -r 504adebdb501 kallithea/templates/index_base.html
--- a/kallithea/templates/index_base.html	Fri Feb 07 13:55:27 2020 -0800
+++ b/kallithea/templates/index_base.html	Fri Feb 07 14:16:39 2020 -0800
@@ -61,6 +61,7 @@
                     {data: "last_rev_raw", defaultContent: '', visible: false, searchable: false},
                     {data: "last_changeset", defaultContent: '', title: ${h.jshtml(_('Tip'))}, orderData: [5,], searchable: false},
                     {data: "owner", defaultContent: '', title: ${h.jshtml(_('Owner'))}, searchable: false},
+                    {data: "extra", defaultContent: '', sortable: false},
                     {data: "atom", defaultContent: '', sortable: false}
                 ],
                 order: [[1, "asc"]],


More information about the kallithea-general mailing list