2021-07-13 23:39:19 +05:30
|
|
|
<script>
|
|
|
|
import {SvgIcon} from '../svg.js';
|
2024-04-07 21:49:25 +05:30
|
|
|
import {contrastColor} from '../utils/color.js';
|
2024-02-24 17:33:53 +05:30
|
|
|
import {GET} from '../modules/fetch.js';
|
2024-03-30 01:11:13 +05:30
|
|
|
import {emojiHTML} from '../features/emoji.js';
|
|
|
|
import {htmlEscape} from 'escape-goat';
|
2021-07-13 23:39:19 +05:30
|
|
|
|
2021-12-28 18:58:27 +05:30
|
|
|
const {appSubUrl, i18n} = window.config;
|
2021-07-13 23:39:19 +05:30
|
|
|
|
|
|
|
export default {
|
2022-12-23 21:33:11 +05:30
|
|
|
components: {SvgIcon},
|
2021-07-13 23:39:19 +05:30
|
|
|
data: () => ({
|
|
|
|
loading: false,
|
2021-12-28 18:58:27 +05:30
|
|
|
issue: null,
|
|
|
|
i18nErrorOccurred: i18n.error_occurred,
|
|
|
|
i18nErrorMessage: null,
|
2021-07-13 23:39:19 +05:30
|
|
|
}),
|
|
|
|
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.state === 'open') {
|
2024-02-05 04:07:45 +05:30
|
|
|
if (this.issue.pull_request.draft === true) {
|
|
|
|
return 'octicon-git-pull-request-draft'; // WIP PR
|
|
|
|
}
|
2021-07-13 23:39:19 +05:30
|
|
|
return 'octicon-git-pull-request'; // Open PR
|
|
|
|
} else if (this.issue.pull_request.merged === true) {
|
|
|
|
return 'octicon-git-merge'; // Merged PR
|
|
|
|
}
|
|
|
|
return 'octicon-git-pull-request'; // Closed PR
|
|
|
|
} else if (this.issue.state === 'open') {
|
|
|
|
return 'octicon-issue-opened'; // Open Issue
|
|
|
|
}
|
|
|
|
return 'octicon-issue-closed'; // Closed Issue
|
|
|
|
},
|
|
|
|
|
|
|
|
color() {
|
2024-02-05 04:07:45 +05:30
|
|
|
if (this.issue.pull_request !== null) {
|
|
|
|
if (this.issue.pull_request.draft === true) {
|
|
|
|
return 'grey'; // WIP PR
|
|
|
|
} else if (this.issue.pull_request.merged === true) {
|
|
|
|
return 'purple'; // Merged PR
|
|
|
|
}
|
|
|
|
}
|
2021-07-13 23:39:19 +05:30
|
|
|
if (this.issue.state === 'open') {
|
2024-02-05 04:07:45 +05:30
|
|
|
return 'green'; // Open Issue
|
2021-07-13 23:39:19 +05:30
|
|
|
}
|
2024-02-05 04:07:45 +05:30
|
|
|
return 'red'; // Closed Issue
|
2021-07-13 23:39:19 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
labels() {
|
2024-04-07 21:49:25 +05:30
|
|
|
return this.issue.labels.map((label) => ({
|
|
|
|
name: htmlEscape(label.name).replaceAll(/:[-+\w]+:/g, (emoji) => {
|
2024-03-30 01:11:13 +05:30
|
|
|
return emojiHTML(emoji.substring(1, emoji.length - 1));
|
2024-04-07 21:49:25 +05:30
|
|
|
}),
|
|
|
|
color: `#${label.color}`,
|
|
|
|
textColor: contrastColor(`#${label.color}`),
|
|
|
|
}));
|
2024-03-22 19:36:53 +05:30
|
|
|
},
|
2021-07-13 23:39:19 +05:30
|
|
|
},
|
|
|
|
mounted() {
|
2023-03-05 19:53:42 +05:30
|
|
|
this.$refs.root.addEventListener('ce-load-context-popup', (e) => {
|
2022-10-01 19:56:38 +05:30
|
|
|
const data = e.detail;
|
2021-07-13 23:39:19 +05:30
|
|
|
if (!this.loading && this.issue === null) {
|
2022-10-01 19:56:38 +05:30
|
|
|
this.load(data);
|
2021-07-13 23:39:19 +05:30
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
2024-02-24 17:33:53 +05:30
|
|
|
async load(data) {
|
2021-07-13 23:39:19 +05:30
|
|
|
this.loading = true;
|
2021-12-28 18:58:27 +05:30
|
|
|
this.i18nErrorMessage = null;
|
2024-02-24 17:33:53 +05:30
|
|
|
|
|
|
|
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;
|
2021-12-28 18:58:27 +05:30
|
|
|
}
|
2024-02-24 17:33:53 +05:30
|
|
|
this.issue = respJson;
|
|
|
|
} catch {
|
|
|
|
this.i18nErrorMessage = i18n.network_error;
|
|
|
|
} finally {
|
2021-07-13 23:39:19 +05:30
|
|
|
this.loading = false;
|
2024-02-24 17:33:53 +05:30
|
|
|
}
|
2024-03-22 19:36:53 +05:30
|
|
|
},
|
|
|
|
},
|
2021-07-13 23:39:19 +05:30
|
|
|
};
|
|
|
|
</script>
|
2023-09-02 20:29:07 +05:30
|
|
|
<template>
|
|
|
|
<div ref="root">
|
2024-03-28 01:48:04 +05:30
|
|
|
<div v-if="loading" class="tw-h-12 tw-w-12 is-loading"/>
|
2024-03-30 01:11:13 +05:30
|
|
|
<div v-if="!loading && issue !== null" id="issue-info-popup">
|
2023-09-02 20:29:07 +05:30
|
|
|
<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>
|
2024-04-07 21:49:25 +05:30
|
|
|
<div class="labels-list">
|
2024-03-30 01:11:13 +05:30
|
|
|
<!-- 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"/>
|
2023-09-02 20:29:07 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-if="!loading && issue === null">
|
|
|
|
<p><small>{{ i18nErrorOccurred }}</small></p>
|
|
|
|
<p>{{ i18nErrorMessage }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|