mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-24 01:22:21 +00:00
8e56f61d0f
Added a new icon for closed PRs (similar to GitHub, GitLab, etc), Fixes https://codeberg.org/forgejo/forgejo/issues/4454. Before: - https://codeberg.org/attachments/b17c5846-506f-4b32-97c9-03f31c5ff758 - https://codeberg.org/attachments/babcd011-d340-4a9e-94db-ea17ef6d3c2b - https://codeberg.org/attachments/dbca009a-413e-48ab-84b1-55ad7f4fcd3d After: - https://codeberg.org/attachments/3e161f7b-4172-4a8c-a8eb-54bcf81c0cae - https://codeberg.org/attachments/0c308f7e-25a0-49a3-9c86-1b1f9ab39467 - https://codeberg.org/attachments/b982b6b8-c78a-4332-8269-50d01de834e0 Co-authored-by: 0ko <0ko@noreply.codeberg.org> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4455 Reviewed-by: Caesar Schinas <caesar@caesarschinas.com> Reviewed-by: 0ko <0ko@noreply.codeberg.org> Co-authored-by: Bram Hagens <bram@bramh.me> Co-committed-by: Bram Hagens <bram@bramh.me>
131 lines
3.7 KiB
Vue
131 lines
3.7 KiB
Vue
<script>
|
|
import {SvgIcon} from '../svg.js';
|
|
import {contrastColor} from '../utils/color.js';
|
|
import {GET} from '../modules/fetch.js';
|
|
import {emojiHTML} from '../features/emoji.js';
|
|
import {htmlEscape} from 'escape-goat';
|
|
|
|
const {appSubUrl, i18n} = window.config;
|
|
|
|
export default {
|
|
components: {SvgIcon},
|
|
data: () => ({
|
|
loading: false,
|
|
issue: null,
|
|
i18nErrorOccurred: i18n.error_occurred,
|
|
i18nErrorMessage: null,
|
|
}),
|
|
computed: {
|
|
createdAt() {
|
|
return new Date(this.issue.created_at).toLocaleDateString(undefined, {year: 'numeric', month: 'short', day: 'numeric'});
|
|
},
|
|
|
|
body() {
|
|
const body = this.issue.body.replace(/\n+/g, ' ');
|
|
if (body.length > 85) {
|
|
return `${body.substring(0, 85)}…`;
|
|
}
|
|
return body;
|
|
},
|
|
|
|
icon() {
|
|
if (this.issue.pull_request !== null) {
|
|
if (this.issue.pull_request.merged === true) {
|
|
return 'octicon-git-merge'; // Merged PR
|
|
}
|
|
|
|
if (this.issue.state === 'closed') {
|
|
return 'octicon-git-pull-request-closed'; // Closed PR
|
|
}
|
|
|
|
if (this.issue.pull_request.draft === true) {
|
|
return 'octicon-git-pull-request-draft'; // WIP PR
|
|
}
|
|
|
|
return 'octicon-git-pull-request'; // Open PR
|
|
}
|
|
|
|
if (this.issue.state === 'closed') {
|
|
return 'octicon-issue-closed'; // Closed issue
|
|
}
|
|
|
|
return 'octicon-issue-opened'; // Open issue
|
|
},
|
|
|
|
color() {
|
|
if (this.issue.pull_request !== null) {
|
|
if (this.issue.pull_request.merged === true) {
|
|
return 'purple'; // Merged PR
|
|
}
|
|
|
|
if (this.issue.pull_request.draft === true && this.issue.state === 'open') {
|
|
return 'grey'; // WIP PR
|
|
}
|
|
}
|
|
|
|
if (this.issue.state === 'closed') {
|
|
return 'red'; // Closed issue
|
|
}
|
|
|
|
return 'green'; // Open issue
|
|
},
|
|
|
|
labels() {
|
|
return this.issue.labels.map((label) => ({
|
|
name: htmlEscape(label.name).replaceAll(/:[-+\w]+:/g, (emoji) => {
|
|
return emojiHTML(emoji.substring(1, emoji.length - 1));
|
|
}),
|
|
color: `#${label.color}`,
|
|
textColor: contrastColor(`#${label.color}`),
|
|
}));
|
|
},
|
|
},
|
|
mounted() {
|
|
this.$refs.root.addEventListener('ce-load-context-popup', (e) => {
|
|
const data = e.detail;
|
|
if (!this.loading && this.issue === null) {
|
|
this.load(data);
|
|
}
|
|
});
|
|
},
|
|
methods: {
|
|
async load(data) {
|
|
this.loading = true;
|
|
this.i18nErrorMessage = null;
|
|
|
|
try {
|
|
const response = await GET(`${appSubUrl}/${data.owner}/${data.repo}/issues/${data.index}/info`);
|
|
const respJson = await response.json();
|
|
if (!response.ok) {
|
|
this.i18nErrorMessage = respJson.message ?? i18n.network_error;
|
|
return;
|
|
}
|
|
this.issue = respJson;
|
|
} catch {
|
|
this.i18nErrorMessage = i18n.network_error;
|
|
} finally {
|
|
this.loading = false;
|
|
}
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
<template>
|
|
<div ref="root">
|
|
<div v-if="loading" class="tw-h-12 tw-w-12 is-loading"/>
|
|
<div v-if="!loading && issue !== null" id="issue-info-popup">
|
|
<p><small>{{ issue.repository.full_name }} on {{ createdAt }}</small></p>
|
|
<p><svg-icon :name="icon" :class="['text', color]"/> <strong>{{ issue.title }}</strong> #{{ issue.number }}</p>
|
|
<p>{{ body }}</p>
|
|
<div class="labels-list">
|
|
<!-- eslint-disable-next-line vue/no-v-html -->
|
|
<div v-for="label in labels" :key="label.name" class="ui label" :style="{ color: label.textColor, backgroundColor: label.color }" v-html="label.name"/>
|
|
</div>
|
|
</div>
|
|
<div v-if="!loading && issue === null">
|
|
<p><small>{{ i18nErrorOccurred }}</small></p>
|
|
<p>{{ i18nErrorMessage }}</p>
|
|
</div>
|
|
</div>
|
|
</template>
|