From 7d7ab1eeae43d99fe329878ac9c8db5e45e2dee5 Mon Sep 17 00:00:00 2001 From: John Olheiser <42128690+jolheiser@users.noreply.github.com> Date: Sun, 19 Jan 2020 22:39:21 -0600 Subject: Issue/PR Context Popups (#9822) * Add data-index attribute to issue anchors Signed-off-by: jolheiser * Init JS Signed-off-by: jolheiser * Add required data to anchor Signed-off-by: jolheiser * Finish popup Signed-off-by: jolheiser * Revert changes to html.go Signed-off-by: jolheiser * Better octicon contexts Signed-off-by: jolheiser * Split out popup function for re-use Signed-off-by: jolheiser * Style changes, test fixes, and cross-reference support Signed-off-by: jolheiser * Prefer em to px Signed-off-by: jolheiser * Move label margin to base CSS Signed-off-by: jolheiser * Move JS to separate file. Signed-off-by: jolheiser * Move JS to features and fix module Signed-off-by: jolheiser * Remove query-string and hash Co-Authored-By: silverwind Co-authored-by: Lauris BH Co-authored-by: Antoine GIRARD Co-authored-by: silverwind Co-authored-by: Lunny Xiao Co-authored-by: zeripath --- web_src/js/features/contextPopup.js | 66 +++++++++++++++++++++++++++++++++++++ web_src/js/index.js | 2 ++ web_src/less/_base.less | 16 +++++++++ web_src/less/themes/arc-green.less | 10 ++++++ 4 files changed, 94 insertions(+) create mode 100644 web_src/js/features/contextPopup.js (limited to 'web_src') diff --git a/web_src/js/features/contextPopup.js b/web_src/js/features/contextPopup.js new file mode 100644 index 0000000000..90b8493666 --- /dev/null +++ b/web_src/js/features/contextPopup.js @@ -0,0 +1,66 @@ +export default function initContextPopups(suburl) { + const refIssues = $('.ref-issue'); + if (!refIssues.length) return; + + refIssues.each(function () { + const [index, _issues, repo, owner] = $(this).attr('href').replace(/[#?].*$/, '').split('/').reverse(); + issuePopup(suburl, owner, repo, index, $(this)); + }); +} + +function issuePopup(suburl, owner, repo, index, $element) { + $.get(`${suburl}/api/v1/repos/${owner}/${repo}/issues/${index}`, (issue) => { + const createdAt = new Date(issue.created_at).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' }); + + let body = issue.body.replace(/\n+/g, ' '); + if (body.length > 85) { + body = `${body.substring(0, 85)}...`; + } + + let labels = ''; + for (let i = 0; i < issue.labels.length; i++) { + const label = issue.labels[i]; + const red = parseInt(label.color.substring(0, 2), 16); + const green = parseInt(label.color.substring(2, 4), 16); + const blue = parseInt(label.color.substring(4, 6), 16); + let color = '#ffffff'; + if ((red * 0.299 + green * 0.587 + blue * 0.114) > 125) { + color = '#000000'; + } + labels += `
${label.name}
`; + } + if (labels.length > 0) { + labels = `

${labels}

`; + } + + let octicon; + if (issue.pull_request !== null) { + if (issue.state === 'open') { + octicon = 'green octicon-git-pull-request'; // Open PR + } else if (issue.pull_request.merged === true) { + octicon = 'purple octicon-git-merge'; // Merged PR + } else { + octicon = 'red octicon-git-pull-request'; // Closed PR + } + } else if (issue.state === 'open') { + octicon = 'green octicon-issue-opened'; // Open Issue + } else { + octicon = 'red octicon-issue-closed'; // Closed Issue + } + + $element.popup({ + variation: 'wide', + delay: { + show: 250 + }, + html: ` +
+

${issue.repository.full_name} on ${createdAt}

+

${issue.title} #${index}

+

${body}

+ ${labels} +
+` + }); + }); +} diff --git a/web_src/js/index.js b/web_src/js/index.js index 619ca74e52..9168e7a943 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -5,6 +5,7 @@ import './publicPath.js'; import './gitGraphLoader.js'; import './semanticDropdown.js'; +import initContextPopups from './features/contextPopup'; function htmlEncode(text) { return jQuery('
').text(text).html(); @@ -2556,6 +2557,7 @@ $(document).ready(() => { initPullRequestReview(); initRepoStatusChecker(); initTemplateSearch(); + initContextPopups(suburl); // Repo clone url. if ($('#repo-clone-url').length > 0) { diff --git a/web_src/less/_base.less b/web_src/less/_base.less index 068b9e8144..f34cb71013 100644 --- a/web_src/less/_base.less +++ b/web_src/less/_base.less @@ -1185,3 +1185,19 @@ i.icon.centerlock { vertical-align: middle; height: 2.1666em !important; } + +.octicon { + &.green { + color: #21ba45; + } + &.red { + color: #db2828; + } + &.purple { + color: #a333c8; + } +} + +.ui.popup .ui.label { + margin-bottom: 0.4em; +} diff --git a/web_src/less/themes/arc-green.less b/web_src/less/themes/arc-green.less index 69e8963fbb..5aa7c8f2c5 100644 --- a/web_src/less/themes/arc-green.less +++ b/web_src/less/themes/arc-green.less @@ -1463,3 +1463,13 @@ a.ui.labels .label:hover { } } } + +.ui.popup { + background-color: #383c4a; + color: #9e9e9e; + border-color: #9e9e9e; + + &.top::before { + background-color: #383c4a; + } +} -- cgit v1.2.3