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/js/features | |
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/js/features')
-rw-r--r-- | web_src/js/features/contextPopup.js | 66 |
1 files changed, 66 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> +` + }); + }); +} |