1
0
Fork 0
forked from forgejo/forgejo

SVG Octicon fixes (#10237)

* SVG fixes

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* Colorize span->svg only

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* @silverwind suggestions

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* Alphabetical

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* Convert suburl and staticPrefix to window.config

Signed-off-by: jolheiser <john.olheiser@gmail.com>

* De-structure

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com>
This commit is contained in:
John Olheiser 2020-02-11 19:53:18 -06:00 committed by GitHub
parent 2399bad1f1
commit d67e9b9629
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 72 additions and 60 deletions

View file

@ -1,15 +1,19 @@
export default function initContextPopups(suburl) {
import { svg } from '../utils.js';
const { AppSubUrl } = window.config;
export default function initContextPopups() {
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));
issuePopup(owner, repo, index, $(this));
});
}
function issuePopup(suburl, owner, repo, index, $element) {
$.get(`${suburl}/api/v1/repos/${owner}/${repo}/issues/${index}`, (issue) => {
function issuePopup(owner, repo, index, $element) {
$.get(`${AppSubUrl}/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, ' ');
@ -34,19 +38,24 @@ function issuePopup(suburl, owner, repo, index, $element) {
labels = `<p>${labels}</p>`;
}
let octicon;
let octicon, color;
if (issue.pull_request !== null) {
if (issue.state === 'open') {
octicon = 'green octicon-git-pull-request'; // Open PR
color = 'green';
octicon = 'octicon-git-pull-request'; // Open PR
} else if (issue.pull_request.merged === true) {
octicon = 'purple octicon-git-merge'; // Merged PR
color = 'purple';
octicon = 'octicon-git-merge'; // Merged PR
} else {
octicon = 'red octicon-git-pull-request'; // Closed PR
color = 'red';
octicon = 'octicon-git-pull-request'; // Closed PR
}
} else if (issue.state === 'open') {
octicon = 'green octicon-issue-opened'; // Open Issue
color = 'green';
octicon = 'octicon-issue-opened'; // Open Issue
} else {
octicon = 'red octicon-issue-closed'; // Closed Issue
color = 'red';
octicon = 'octicon-issue-closed'; // Closed Issue
}
$element.popup({
@ -57,7 +66,7 @@ function issuePopup(suburl, owner, repo, index, $element) {
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><span class="${color}">${svg(octicon, 16)}</span> <strong>${issue.title}</strong> #${index}</p>
<p>${body}</p>
${labels}
</div>