feat: refs #8440 add delete functionality to notes and update required attributes
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jose Antonio Tubau 2025-02-12 14:40:17 +01:00
parent b229fc0ff3
commit 62e8b5b307
2 changed files with 43 additions and 15 deletions

View File

@ -25,13 +25,16 @@ const $attrs = computed(() => {
return rest; return rest;
}); });
const isRequired = computed(() => { const isRequired = ref(() => {
return Object.keys($attrs).includes('required') return Object.keys($attrs).includes('required');
});
const isDeletable = ref(() => {
return Object.keys($attrs).includes('removable');
}); });
const $props = defineProps({ const $props = defineProps({
url: { type: String, default: null }, url: { type: String, default: null },
saveUrl: {type: String, default: null}, saveUrl: { type: String, default: null },
filter: { type: Object, default: () => {} }, filter: { type: Object, default: () => {} },
body: { type: Object, default: () => {} }, body: { type: Object, default: () => {} },
addNote: { type: Boolean, default: false }, addNote: { type: Boolean, default: false },
@ -52,6 +55,11 @@ function handleClick(e) {
else insert(); else insert();
} }
async function deleteNote(e) {
await axios.delete(`${$props.url}/${e.id}`);
await vnPaginateRef.value.fetch();
}
async function insert() { async function insert() {
if (!newNote.text || ($props.selectType && !newNote.observationTypeFk)) return; if (!newNote.text || ($props.selectType && !newNote.observationTypeFk)) return;
@ -65,7 +73,7 @@ async function insert() {
} }
function confirmAndUpdate() { function confirmAndUpdate() {
if(!newNote.text && originalText) if (!newNote.text && originalText)
quasar quasar
.dialog({ .dialog({
component: VnConfirm, component: VnConfirm,
@ -88,11 +96,17 @@ async function update() {
...body, ...body,
...{ notes: newNote.text }, ...{ notes: newNote.text },
}; };
await axios.patch(`${$props.saveUrl ?? `${$props.url}/${$props.body.workerFk}`}`, newBody); await axios.patch(
`${$props.saveUrl ?? `${$props.url}/${$props.body.workerFk}`}`,
newBody,
);
} }
onBeforeRouteLeave((to, from, next) => { onBeforeRouteLeave((to, from, next) => {
if ((newNote.text && !$props.justInput) || (newNote.text !== originalText) && $props.justInput) if (
(newNote.text && !$props.justInput) ||
(newNote.text !== originalText && $props.justInput)
)
quasar.dialog({ quasar.dialog({
component: VnConfirm, component: VnConfirm,
componentProps: { componentProps: {
@ -104,12 +118,11 @@ onBeforeRouteLeave((to, from, next) => {
else next(); else next();
}); });
function fetchData([ data ]) { function fetchData([data]) {
newNote.text = data?.notes; newNote.text = data?.notes;
originalText = data?.notes; originalText = data?.notes;
emit('onFetch', data); emit('onFetch', data);
} }
</script> </script>
<template> <template>
<FetchData <FetchData
@ -126,8 +139,8 @@ function fetchData([ data ]) {
@on-fetch="fetchData" @on-fetch="fetchData"
auto-load auto-load
/> />
<QCard <QCard
class="q-pa-xs q-mb-lg full-width" class="q-pa-xs q-mb-lg full-width"
:class="{ 'just-input': $props.justInput }" :class="{ 'just-input': $props.justInput }"
v-if="$props.addNote || $props.justInput" v-if="$props.addNote || $props.justInput"
> >
@ -143,7 +156,7 @@ function fetchData([ data ]) {
v-model="newNote.observationTypeFk" v-model="newNote.observationTypeFk"
option-label="description" option-label="description"
style="flex: 0.15" style="flex: 0.15"
:required="isRequired" :required="Object.keys($attrs).includes('required')"
@keyup.enter.stop="insert" @keyup.enter.stop="insert"
/> />
<VnInput <VnInput
@ -151,10 +164,9 @@ function fetchData([ data ]) {
type="textarea" type="textarea"
:label="$props.justInput && newNote.text ? '' : t('Add note here...')" :label="$props.justInput && newNote.text ? '' : t('Add note here...')"
filled filled
size="lg"
autogrow autogrow
@keyup.enter.stop="handleClick" @keyup.enter.stop="handleClick"
:required="isRequired" :required="Object.keys($attrs).includes('required')"
clearable clearable
> >
<template #append> <template #append>
@ -218,12 +230,27 @@ function fetchData([ data ]) {
> >
{{ {{
observationTypes.find( observationTypes.find(
(ot) => ot.id === note.observationTypeFk (ot) => ot.id === note.observationTypeFk,
)?.description )?.description
}} }}
</QBadge> </QBadge>
</div> </div>
<span v-text="toDateHourMin(note.created)" /> <span v-text="toDateHourMin(note.created)" />
<div>
<QIcon
v-if="Object.keys($attrs).includes('deletable')"
name="delete"
size="sm"
class="cursor-pointer"
color="primary"
@click="deleteNote(note)"
data-cy="ticketNotesRemoveNoteBtn"
>
<QTooltip>
{{ t('ticketNotes.removeNote') }}
</QTooltip>
</QIcon>
</div>
</div> </div>
</QCardSection> </QCardSection>
<QCardSection class="q-pa-xs q-my-none q-py-none"> <QCardSection class="q-pa-xs q-my-none q-py-none">

View File

@ -30,5 +30,6 @@ const body = {
:body="body" :body="body"
style="overflow-y: auto" style="overflow-y: auto"
required required
deletable
/> />
</template> </template>