# HG changeset patch # User Daniel Dourvaris # Date 2019-11-07 13:10:03 # Node ID 4a632ba4ac936148ac3d355c141457811479a234 # Parent a792f9c3f7d3e078c7d7823f57ec33c5d9a844f3 hovercards: enable hovercards on parsed commits references. diff --git a/rhodecode/lib/base.py b/rhodecode/lib/base.py --- a/rhodecode/lib/base.py +++ b/rhodecode/lib/base.py @@ -539,12 +539,24 @@ def add_events_routes(config): pattern='/{repo_name}/pull-request/{pull_request_id}') config.add_route(name='pull_requests_global', pattern='/pull-request/{pull_request_id}') + config.add_route(name='repo_commit', pattern='/{repo_name}/changeset/{commit_id}') - config.add_route(name='repo_files', pattern='/{repo_name}/files/{commit_id}/{f_path}') + config.add_route(name='hovercard_user', + pattern='/_hovercard/user/{user_id}') + + config.add_route(name='hovercard_user_group', + pattern='/_hovercard/user_group/{user_group_id}') + + config.add_route(name='hovercard_pull_request', + pattern='/_hovercard/pull_request/{pull_request_id}') + + config.add_route(name='hovercard_repo_commit', + pattern='/_hovercard/commit/{repo_name}/{commit_id}') + def bootstrap_config(request): import pyramid.testing diff --git a/rhodecode/lib/helpers.py b/rhodecode/lib/helpers.py --- a/rhodecode/lib/helpers.py +++ b/rhodecode/lib/helpers.py @@ -1577,21 +1577,21 @@ def urlify_text(text_, safe=True): def url_func(match_obj): url_full = match_obj.groups()[0] return '%(url)s' % ({'url': url_full}) - _newtext = url_pat.sub(url_func, text_) + _new_text = url_pat.sub(url_func, text_) if safe: - return literal(_newtext) - return _newtext + return literal(_new_text) + return _new_text -def urlify_commits(text_, repository): +def urlify_commits(text_, repo_name): """ Extract commit ids from text and make link from them :param text_: - :param repository: repo name to build the URL with + :param repo_name: repo name to build the URL with """ - URL_PAT = re.compile(r'(^|\s)([0-9a-fA-F]{12,40})($|\s)') + url_pat = re.compile(r'(^|\s)([0-9a-fA-F]{12,40})($|\s)') def url_func(match_obj): commit_id = match_obj.groups()[1] @@ -1599,20 +1599,24 @@ def urlify_commits(text_, repository): suf = match_obj.groups()[2] tmpl = ( - '%(pref)s' + '%(pref)s' '%(commit_id)s%(suf)s' ) return tmpl % { 'pref': pref, 'cls': 'revision-link', - 'url': route_url('repo_commit', repo_name=repository, commit_id=commit_id), + 'url': route_url( + 'repo_commit', repo_name=repo_name, commit_id=commit_id), 'commit_id': commit_id, - 'suf': suf + 'suf': suf, + 'hovercard_alt': 'Commit: {}'.format(commit_id), + 'hovercard_url': route_url( + 'hovercard_repo_commit', repo_name=repo_name, commit_id=commit_id) } - newtext = URL_PAT.sub(url_func, text_) + new_text = url_pat.sub(url_func, text_) - return newtext + return new_text def _process_url_func(match_obj, repo_name, uid, entry, @@ -1767,9 +1771,6 @@ def urlify_commit_message(commit_text, r """ Parses given text message and makes proper links. issues are linked to given issue-server, and rest is a commit link - - :param commit_text: - :param repository: """ def escaper(_text): return _text.replace('<', '<').replace('>', '>') diff --git a/rhodecode/public/js/src/rhodecode.js b/rhodecode/public/js/src/rhodecode.js --- a/rhodecode/public/js/src/rhodecode.js +++ b/rhodecode/public/js/src/rhodecode.js @@ -243,7 +243,7 @@ var tooltipActivate = function () { }); var hovercardCache = {}; - var loadHoverCard = function (url, callback) { + var loadHoverCard = function (url, altHovercard, callback) { var id = url; if (hovercardCache[id] !== undefined) { @@ -257,7 +257,12 @@ var tooltipActivate = function () { callback(hovercardCache[id]); return true; }).fail(function (data, textStatus, errorThrown) { - var msg = "

Error while fetching hovercard.\nError code {0} ({1}).

".format(data.status,data.statusText); + + if (parseInt(data.status) === 404) { + var msg = "

{0}

".format(altHovercard || "No Data exists for this hovercard"); + } else { + var msg = "

Error while fetching hovercard.\nError code {0} ({1}).

".format(data.status,data.statusText); + } callback(msg); return false }); @@ -291,16 +296,17 @@ var tooltipActivate = function () { // we set a variable so the data is only loaded once via Ajax, not every time the tooltip opens if ($origin.data('loaded') !== true) { var hovercardUrl = $origin.data('hovercardUrl'); + var altHovercard =$origin.data('hovercardAlt'); if (hovercardUrl !== undefined && hovercardUrl !== "") { - var loaded = loadHoverCard(hovercardUrl, function (data) { + var loaded = loadHoverCard(hovercardUrl, altHovercard, function (data) { instance.content(data); }) } else { if ($origin.data('hovercardAltHtml')) { var data = atob($origin.data('hovercardAltHtml')); } else { - var data = '
{0}
'.format($origin.data('hovercardAlt')) + var data = '
{0}
'.format(altHovercard) } var loaded = true; instance.content(data); diff --git a/rhodecode/templates/base/issue_tracker_settings.mako b/rhodecode/templates/base/issue_tracker_settings.mako --- a/rhodecode/templates/base/issue_tracker_settings.mako +++ b/rhodecode/templates/base/issue_tracker_settings.mako @@ -178,11 +178,13 @@
-
diff --git a/rhodecode/tests/lib/test_libs.py b/rhodecode/tests/lib/test_libs.py --- a/rhodecode/tests/lib/test_libs.py +++ b/rhodecode/tests/lib/test_libs.py @@ -454,7 +454,10 @@ def test_clone_url_generator(tmpl, repo_ assert clone_url == expected -def _quick_url(text, tmpl="""%s""", url_=None): +idx = 0 + + +def _quick_url(text, tmpl="""%s""", url_=None, commits=''): """ Changes `some text url[foo]` => `some text foo @@ -462,47 +465,86 @@ def _quick_url(text, tmpl="""