diff options
author | John Olheiser <42128690+jolheiser@users.noreply.github.com> | 2020-01-19 22:39:21 -0600 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2020-01-19 23:39:21 -0500 |
commit | 7d7ab1eeae43d99fe329878ac9c8db5e45e2dee5 (patch) | |
tree | af20001905b81ab8313fbd8a50114ca71764f7da /web_src | |
parent | c5014a7f2c4a263818269216d16d6f21b008cd17 (diff) | |
download | gitea-7d7ab1eeae43d99fe329878ac9c8db5e45e2dee5.tar.gz gitea-7d7ab1eeae43d99fe329878ac9c8db5e45e2dee5.zip |
Issue/PR Context Popups (#9822)
* Add data-index attribute to issue anchors
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Init JS
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Add required data to anchor
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Finish popup
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Revert changes to html.go
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Better octicon contexts
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Split out popup function for re-use
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Style changes, test fixes, and cross-reference support
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Prefer em to px
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Move label margin to base CSS
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Move JS to separate file.
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Move JS to features and fix module
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Remove query-string and hash
Co-Authored-By: silverwind <me@silverwind.io>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'web_src')
-rw-r--r-- | web_src/js/features/contextPopup.js | 66 | ||||
-rw-r--r-- | web_src/js/index.js | 2 | ||||
-rw-r--r-- | web_src/less/_base.less | 16 | ||||
-rw-r--r-- | web_src/less/themes/arc-green.less | 10 |
4 files changed, 94 insertions, 0 deletions
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 += `<div class="ui label" style="color: ${color}; background-color:#${label.color};">${label.name}</div>`; + } + if (labels.length > 0) { + labels = `<p>${labels}</p>`; + } + + 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: ` +<div> + <p><small>${issue.repository.full_name} on ${createdAt}</small></p> + <p><i class="octicon ${octicon}"></i> <strong>${issue.title}</strong> #${index}</p> + <p>${body}</p> + ${labels} +</div> +` + }); + }); +} 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('<div />').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; + } +} |