Upgraded dependencies, bumped to Node 24.
This commit is contained in:
@@ -1,3 +1,158 @@
|
||||
<script setup>
|
||||
import Cookies from 'js-cookie';
|
||||
import { inject, onMounted, ref } from 'vue';
|
||||
import { parse } from 'yaml';
|
||||
|
||||
import defaultTemplate from '#/assets/summary.yaml?raw';
|
||||
import { del, get, post } from '#/src/api.js';
|
||||
// import slugify from '#/utils/slugify.js';
|
||||
import events from '#/src/events.js';
|
||||
|
||||
import processSummaryTemplate from '#/utils/process-summary-template.js';
|
||||
|
||||
const props = defineProps({
|
||||
release: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
});
|
||||
|
||||
const pageContext = inject('pageContext');
|
||||
|
||||
const cookies = Cookies.withConverter({
|
||||
write: (value) => value,
|
||||
});
|
||||
|
||||
const templates = ref(pageContext.assets.templates);
|
||||
const selectedTemplate = ref(Number(pageContext.urlParsed.search.t) || templates.value.at(0)?.id || null);
|
||||
|
||||
const initialTemplate = templates.value.find((storedTemplate) => storedTemplate.id === selectedTemplate.value) || null;
|
||||
|
||||
const template = ref(initialTemplate?.template || defaultTemplate);
|
||||
const hasError = ref(false);
|
||||
const input = ref(null);
|
||||
const changed = ref(false);
|
||||
|
||||
const templateName = ref(initialTemplate?.name || `custom_${Date.now()}`);
|
||||
|
||||
function getSummary() {
|
||||
return processSummaryTemplate(template.value, props.release, pageContext.env);
|
||||
}
|
||||
|
||||
const summary = ref(getSummary());
|
||||
|
||||
function selectTemplate(templateId) {
|
||||
selectedTemplate.value = templateId;
|
||||
|
||||
const nextTemplate = templates.value.find((storedTemplate) => storedTemplate.id === templateId);
|
||||
|
||||
template.value = nextTemplate.template;
|
||||
templateName.value = nextTemplate.name;
|
||||
summary.value = getSummary();
|
||||
|
||||
cookies.set('selectedTemplate', String(templateId));
|
||||
window.location.href = `${window.location.origin}${window.location.pathname}?t=${nextTemplate.id}`;
|
||||
}
|
||||
|
||||
function update() {
|
||||
hasError.value = false;
|
||||
changed.value = true;
|
||||
|
||||
try {
|
||||
summary.value = getSummary();
|
||||
}
|
||||
catch (error) {
|
||||
hasError.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
async function save(explicit) {
|
||||
if (!explicit && !changed.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
parse(template.value);
|
||||
|
||||
const createdTemplate = await post('/templates', {
|
||||
name: templateName.value,
|
||||
template: template.value,
|
||||
}, {
|
||||
successFeedback: `Saved summary template '${templateName.value}'`,
|
||||
errorFeedback: `Failed to save summary template '${templateName.value}'`,
|
||||
});
|
||||
|
||||
changed.value = false;
|
||||
templates.value = await get(`/users/${pageContext.user.id}/templates`);
|
||||
|
||||
selectTemplate(createdTemplate.id);
|
||||
}
|
||||
catch (error) {
|
||||
events.emit('feedback', {
|
||||
type: 'error',
|
||||
message: `Failed to save summary template '${templateName.value}': ${error.message}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function add() {
|
||||
selectedTemplate.value = null;
|
||||
template.value = '';
|
||||
templateName.value = `custom_${Date.now()}`;
|
||||
summary.value = '';
|
||||
|
||||
input.value.focus();
|
||||
}
|
||||
|
||||
async function remove() {
|
||||
if (confirm(`Are you sure you want to delete summary template ${templateName.value}?`)) { // eslint-disable-line no-alert
|
||||
await del(`/templates/${selectedTemplate.value}`, {
|
||||
undoFeedback: `Deleted summary template '${templateName.value}'`,
|
||||
errorFeedback: `Failed to remove summary template '${templateName.value}'`,
|
||||
});
|
||||
|
||||
templates.value = await get(`/users/${pageContext.user.id}/templates`);
|
||||
|
||||
selectTemplate(templates.value.at(-1)?.id);
|
||||
}
|
||||
}
|
||||
|
||||
function copy() {
|
||||
navigator.clipboard.writeText(summary.value);
|
||||
|
||||
events.emit('feedback', {
|
||||
type: 'success',
|
||||
message: 'Summary copied to clipboard',
|
||||
});
|
||||
}
|
||||
|
||||
function reset() {
|
||||
if (confirm('Are you sure you want to reset the summary template to the default? Your custom template will be discarded.')) { // eslint-disable-line no-alert
|
||||
template.value = defaultTemplate;
|
||||
|
||||
update();
|
||||
|
||||
events.emit('feedback', {
|
||||
type: 'undo',
|
||||
message: 'Reset summary template',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function indent() {
|
||||
// YAML does not support tabs
|
||||
input.value.setRangeText(' ', input.value.selectionStart, input.value.selectionEnd, 'end');
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('beforeunload', (event) => {
|
||||
if (changed.value) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="editor">
|
||||
<div class="editor-header">
|
||||
@@ -89,159 +244,6 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, inject, onMounted } from 'vue';
|
||||
import { parse } from 'yaml';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
// import slugify from '#/utils/slugify.js';
|
||||
import events from '#/src/events.js';
|
||||
import { get, post, del } from '#/src/api.js';
|
||||
import processSummaryTemplate from '#/utils/process-summary-template.js';
|
||||
|
||||
import defaultTemplate from '#/assets/summary.yaml?raw'; // eslint-disable-line import/no-unresolved
|
||||
|
||||
const pageContext = inject('pageContext');
|
||||
|
||||
const cookies = Cookies.withConverter({
|
||||
write: (value) => value,
|
||||
});
|
||||
|
||||
const props = defineProps({
|
||||
release: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
});
|
||||
|
||||
const templates = ref(pageContext.assets.templates);
|
||||
const selectedTemplate = ref(Number(pageContext.urlParsed.search.t) || templates.value.at(0)?.id || null);
|
||||
|
||||
const initialTemplate = templates.value.find((storedTemplate) => storedTemplate.id === selectedTemplate.value) || null;
|
||||
|
||||
const template = ref(initialTemplate?.template || defaultTemplate);
|
||||
const hasError = ref(false);
|
||||
const input = ref(null);
|
||||
const changed = ref(false);
|
||||
|
||||
const templateName = ref(initialTemplate?.name || `custom_${Date.now()}`);
|
||||
|
||||
function getSummary() {
|
||||
return processSummaryTemplate(template.value, props.release, pageContext.env);
|
||||
}
|
||||
|
||||
const summary = ref(getSummary());
|
||||
|
||||
function selectTemplate(templateId) {
|
||||
selectedTemplate.value = templateId;
|
||||
|
||||
const nextTemplate = templates.value.find((storedTemplate) => storedTemplate.id === templateId);
|
||||
|
||||
template.value = nextTemplate.template;
|
||||
templateName.value = nextTemplate.name;
|
||||
summary.value = getSummary();
|
||||
|
||||
cookies.set('selectedTemplate', String(templateId));
|
||||
window.location.href = `${window.location.origin}${window.location.pathname}?t=${nextTemplate.id}`;
|
||||
}
|
||||
|
||||
function update() {
|
||||
hasError.value = false;
|
||||
changed.value = true;
|
||||
|
||||
try {
|
||||
summary.value = getSummary();
|
||||
} catch (error) {
|
||||
hasError.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
async function save(explicit) {
|
||||
if (!explicit && !changed.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
parse(template.value);
|
||||
|
||||
const createdTemplate = await post('/templates', {
|
||||
name: templateName.value,
|
||||
template: template.value,
|
||||
}, {
|
||||
successFeedback: `Saved summary template '${templateName.value}'`,
|
||||
errorFeedback: `Failed to save summary template '${templateName.value}'`,
|
||||
});
|
||||
|
||||
changed.value = false;
|
||||
templates.value = await get(`/users/${pageContext.user.id}/templates`);
|
||||
|
||||
selectTemplate(createdTemplate.id);
|
||||
} catch (error) {
|
||||
events.emit('feedback', {
|
||||
type: 'error',
|
||||
message: `Failed to save summary template '${templateName.value}': ${error.message}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function add() {
|
||||
selectedTemplate.value = null;
|
||||
template.value = '';
|
||||
templateName.value = `custom_${Date.now()}`;
|
||||
summary.value = '';
|
||||
|
||||
input.value.focus();
|
||||
}
|
||||
|
||||
async function remove() {
|
||||
if (confirm(`Are you sure you want to delete summary template ${templateName.value}?`)) { // eslint-disable-line no-restricted-globals, no-alert
|
||||
await del(`/templates/${selectedTemplate.value}`, {
|
||||
undoFeedback: `Deleted summary template '${templateName.value}'`,
|
||||
errorFeedback: `Failed to remove summary template '${templateName.value}'`,
|
||||
});
|
||||
|
||||
templates.value = await get(`/users/${pageContext.user.id}/templates`);
|
||||
|
||||
selectTemplate(templates.value.at(-1)?.id);
|
||||
}
|
||||
}
|
||||
|
||||
function copy() {
|
||||
navigator.clipboard.writeText(summary.value);
|
||||
|
||||
events.emit('feedback', {
|
||||
type: 'success',
|
||||
message: 'Summary copied to clipboard',
|
||||
});
|
||||
}
|
||||
|
||||
function reset() {
|
||||
if (confirm('Are you sure you want to reset the summary template to the default? Your custom template will be discarded.')) { // eslint-disable-line no-restricted-globals, no-alert
|
||||
template.value = defaultTemplate;
|
||||
|
||||
update();
|
||||
|
||||
events.emit('feedback', {
|
||||
type: 'undo',
|
||||
message: 'Reset summary template',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function indent() {
|
||||
// YAML does not support tabs
|
||||
input.value.setRangeText(' ', input.value.selectionStart, input.value.selectionEnd, 'end');
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('beforeunload', (event) => {
|
||||
if (changed.value) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.editor {
|
||||
display: flex;
|
||||
|
||||
Reference in New Issue
Block a user