Fix activity comment file attach text and download.
Link uploaded attachment ids to the comment entry, label photo-only notes as file attached, and expose view/download actions for non-image files. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -16,7 +16,11 @@ import type { ActivityDto, ActivityType, OrganizationDto, OrgUserDto } from '@me
|
|||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
activity: ActivityDto;
|
activity: ActivityDto;
|
||||||
saving?: boolean;
|
saving?: boolean;
|
||||||
save: (payload: { text: string; photoOnly: boolean }) => Promise<void>;
|
save: (payload: {
|
||||||
|
text: string;
|
||||||
|
photoOnly: boolean;
|
||||||
|
attachmentIds?: string[];
|
||||||
|
}) => Promise<void>;
|
||||||
/** بالاتر از مودال خلاصهٔ فعالیت */
|
/** بالاتر از مودال خلاصهٔ فعالیت */
|
||||||
overlayZIndex?: number;
|
overlayZIndex?: number;
|
||||||
}>();
|
}>();
|
||||||
@@ -233,28 +237,35 @@ async function toggleVoiceNote() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadQueue(items: Array<{ localId: string; name: string; file: File }>, drop: (localId: string) => void) {
|
async function uploadQueue(
|
||||||
|
items: Array<{ localId: string; name: string; file: File }>,
|
||||||
|
drop: (localId: string) => void,
|
||||||
|
): Promise<string[]> {
|
||||||
|
const ids: string[] = [];
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const form = new FormData();
|
const form = new FormData();
|
||||||
form.append('file', item.file, item.name);
|
form.append('file', item.file, item.name);
|
||||||
await api.post(`/activities/${props.activity.id}/images`, form);
|
const { data } = await api.post<{ id: string }>(`/activities/${props.activity.id}/images`, form);
|
||||||
|
ids.push(data.id);
|
||||||
drop(item.localId);
|
drop(item.localId);
|
||||||
uploadedCount.value += 1;
|
uploadedCount.value += 1;
|
||||||
}
|
}
|
||||||
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadPendingPhotos() {
|
async function uploadPendingPhotos(): Promise<string[]> {
|
||||||
await uploadQueue([...pendingPhotos.value], (localId) => {
|
const photoIds = await uploadQueue([...pendingPhotos.value], (localId) => {
|
||||||
pendingPhotos.value = pendingPhotos.value.filter((item) => item.localId !== localId);
|
pendingPhotos.value = pendingPhotos.value.filter((item) => item.localId !== localId);
|
||||||
});
|
});
|
||||||
await uploadQueue([...pendingVoices.value], (localId) => {
|
const voiceIds = await uploadQueue([...pendingVoices.value], (localId) => {
|
||||||
const voice = pendingVoices.value.find((item) => item.localId === localId);
|
const voice = pendingVoices.value.find((item) => item.localId === localId);
|
||||||
if (voice) URL.revokeObjectURL(voice.url);
|
if (voice) URL.revokeObjectURL(voice.url);
|
||||||
pendingVoices.value = pendingVoices.value.filter((item) => item.localId !== localId);
|
pendingVoices.value = pendingVoices.value.filter((item) => item.localId !== localId);
|
||||||
});
|
});
|
||||||
await uploadQueue([...pendingFiles.value], (localId) => {
|
const fileIds = await uploadQueue([...pendingFiles.value], (localId) => {
|
||||||
pendingFiles.value = pendingFiles.value.filter((item) => item.localId !== localId);
|
pendingFiles.value = pendingFiles.value.filter((item) => item.localId !== localId);
|
||||||
});
|
});
|
||||||
|
return [...photoIds, ...voiceIds, ...fileIds];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submit() {
|
async function submit() {
|
||||||
@@ -268,11 +279,15 @@ async function submit() {
|
|||||||
pendingFiles.value.length > 0 ||
|
pendingFiles.value.length > 0 ||
|
||||||
uploadedCount.value > 0;
|
uploadedCount.value > 0;
|
||||||
try {
|
try {
|
||||||
await uploadPendingPhotos();
|
const attachmentIds = await uploadPendingPhotos();
|
||||||
await props.save({ text, photoOnly: hadPhoto && !text });
|
await props.save({
|
||||||
|
text,
|
||||||
|
photoOnly: hadPhoto && !text,
|
||||||
|
attachmentIds,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
photoError.value =
|
photoError.value =
|
||||||
pendingPhotos.value.length > 0
|
pendingPhotos.value.length > 0 || pendingFiles.value.length > 0 || pendingVoices.value.length > 0
|
||||||
? apiMessage(error, 'افزودن فایل ناموفق بود.')
|
? apiMessage(error, 'افزودن فایل ناموفق بود.')
|
||||||
: apiMessage(error, 'ثبت نظر ناموفق بود.');
|
: apiMessage(error, 'ثبت نظر ناموفق بود.');
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -309,17 +309,35 @@ function apiMessage(e: unknown, fallback: string) {
|
|||||||
return fallback;
|
return fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function viewMedia(item: NoteMedia) {
|
||||||
|
window.open(item.url, '_blank', 'noopener,noreferrer');
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadMedia(item: NoteMedia) {
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = item.url;
|
||||||
|
link.download = item.name || 'file';
|
||||||
|
link.rel = 'noopener';
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
link.remove();
|
||||||
|
}
|
||||||
|
|
||||||
async function loadNoteMedia(row: ActivityDto) {
|
async function loadNoteMedia(row: ActivityDto) {
|
||||||
clearNoteMedia();
|
clearNoteMedia();
|
||||||
const next: NoteMedia[] = [];
|
const next: NoteMedia[] = [];
|
||||||
for (const image of row.images ?? []) {
|
for (const image of row.images ?? []) {
|
||||||
const mime = image.mimeType.toLowerCase();
|
const mime = (image.mimeType || 'application/octet-stream').toLowerCase();
|
||||||
const kind = mime.startsWith('audio/') ? 'audio' : mime.startsWith('image/') ? 'image' : 'file';
|
const kind = mime.startsWith('audio/') ? 'audio' : mime.startsWith('image/') ? 'image' : 'file';
|
||||||
try {
|
try {
|
||||||
const { data } = await api.get<Blob>(`/activities/${row.id}/images/${image.id}`, {
|
const { data } = await api.get<Blob>(`/activities/${row.id}/images/${image.id}`, {
|
||||||
responseType: 'blob',
|
responseType: 'blob',
|
||||||
});
|
});
|
||||||
const url = URL.createObjectURL(data);
|
const blob =
|
||||||
|
data.type && data.type !== 'application/octet-stream' && !data.type.includes('json')
|
||||||
|
? data
|
||||||
|
: new Blob([data], { type: mime });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
if (props.activityId !== row.id) {
|
if (props.activityId !== row.id) {
|
||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
continue;
|
continue;
|
||||||
@@ -455,10 +473,14 @@ async function postponeTo(iso: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submitComment(payload: { text: string; photoOnly: boolean }) {
|
async function submitComment(payload: {
|
||||||
|
text: string;
|
||||||
|
photoOnly: boolean;
|
||||||
|
attachmentIds?: string[];
|
||||||
|
}) {
|
||||||
const id = props.activityId;
|
const id = props.activityId;
|
||||||
const row = activity.value;
|
const row = activity.value;
|
||||||
const body = payload.text.trim() || (payload.photoOnly ? 'عکس پیوست شد.' : '');
|
const body = payload.text.trim() || (payload.photoOnly ? 'فایل پیوست شد.' : '');
|
||||||
if (!id || !row || !body) return;
|
if (!id || !row || !body) return;
|
||||||
saving.value = true;
|
saving.value = true;
|
||||||
error.value = '';
|
error.value = '';
|
||||||
@@ -467,7 +489,9 @@ async function submitComment(payload: { text: string; photoOnly: boolean }) {
|
|||||||
const now = new Date();
|
const now = new Date();
|
||||||
const author = auth.user?.fullName?.trim();
|
const author = auth.user?.fullName?.trim();
|
||||||
const stamp = `[${formatJalaliNumeric(now)} ساعت ${formatClockFa(now)}${author ? ` — ${author}` : ''}]`;
|
const stamp = `[${formatJalaliNumeric(now)} ساعت ${formatClockFa(now)}${author ? ` — ${author}` : ''}]`;
|
||||||
const entry = `${stamp}\n${body}`;
|
const ids = [...new Set((payload.attachmentIds ?? []).filter(Boolean))];
|
||||||
|
const attachLine = ids.length ? `\n[[attachments:${ids.join(',')}]]` : '';
|
||||||
|
const entry = `${stamp}\n${body}${attachLine}`;
|
||||||
await api.patch(`/activities/${id}`, { description: prev ? `${prev}\n\n${entry}` : entry });
|
await api.patch(`/activities/${id}`, { description: prev ? `${prev}\n\n${entry}` : entry });
|
||||||
commentOpen.value = false;
|
commentOpen.value = false;
|
||||||
await load(id);
|
await load(id);
|
||||||
@@ -597,11 +621,60 @@ function openFull() {
|
|||||||
:preview="{ zIndex: 1300 }"
|
:preview="{ zIndex: 1300 }"
|
||||||
/>
|
/>
|
||||||
</a-flex>
|
</a-flex>
|
||||||
|
<a-flex
|
||||||
|
v-if="entry.media.some((item) => item.kind === 'audio')"
|
||||||
|
vertical
|
||||||
|
:gap="8"
|
||||||
|
:style="{ marginTop: '8px' }"
|
||||||
|
>
|
||||||
|
<audio
|
||||||
|
v-for="voice in entry.media.filter((item) => item.kind === 'audio')"
|
||||||
|
:key="voice.id"
|
||||||
|
:src="voice.url"
|
||||||
|
controls
|
||||||
|
preload="metadata"
|
||||||
|
style="width: 100%"
|
||||||
|
/>
|
||||||
|
</a-flex>
|
||||||
|
<a-flex
|
||||||
|
v-if="entry.media.some((item) => item.kind === 'file')"
|
||||||
|
vertical
|
||||||
|
:gap="4"
|
||||||
|
:style="{ marginTop: '8px' }"
|
||||||
|
>
|
||||||
|
<a-flex
|
||||||
|
v-for="file in entry.media.filter((item) => item.kind === 'file')"
|
||||||
|
:key="file.id"
|
||||||
|
align="center"
|
||||||
|
justify="space-between"
|
||||||
|
:gap="8"
|
||||||
|
wrap="wrap"
|
||||||
|
>
|
||||||
|
<a-typography-text>{{ file.name }}</a-typography-text>
|
||||||
|
<a-space :size="4">
|
||||||
|
<a-button type="link" @click="viewMedia(file)">مشاهده</a-button>
|
||||||
|
<a-button type="link" @click="downloadMedia(file)">دانلود</a-button>
|
||||||
|
</a-space>
|
||||||
|
</a-flex>
|
||||||
|
</a-flex>
|
||||||
</div>
|
</div>
|
||||||
<div v-for="image in threadBlocks.loose.filter((item) => item.kind === 'image')" :key="image.id" :style="noteBubbleStyle">
|
<div v-for="image in threadBlocks.loose.filter((item) => item.kind === 'image')" :key="image.id" :style="noteBubbleStyle">
|
||||||
<a-image :src="image.url" :alt="image.name" :width="72"
|
<a-image :src="image.url" :alt="image.name" :width="72"
|
||||||
:height="72" :preview="{ zIndex: 1300 }" />
|
:height="72" :preview="{ zIndex: 1300 }" />
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
v-for="file in threadBlocks.loose.filter((item) => item.kind === 'file')"
|
||||||
|
:key="file.id"
|
||||||
|
:style="noteBubbleStyle"
|
||||||
|
>
|
||||||
|
<a-flex align="center" justify="space-between" :gap="8" wrap="wrap">
|
||||||
|
<a-typography-text>{{ file.name }}</a-typography-text>
|
||||||
|
<a-space :size="4">
|
||||||
|
<a-button type="link" @click="viewMedia(file)">مشاهده</a-button>
|
||||||
|
<a-button type="link" @click="downloadMedia(file)">دانلود</a-button>
|
||||||
|
</a-space>
|
||||||
|
</a-flex>
|
||||||
|
</div>
|
||||||
</a-flex>
|
</a-flex>
|
||||||
<div v-else-if="plainNote || looseImages.length" :style="noteBubbleStyle">
|
<div v-else-if="plainNote || looseImages.length" :style="noteBubbleStyle">
|
||||||
<a-typography-paragraph v-if="plainNote" :style="{ margin: 0, whiteSpace: 'pre-wrap' }">
|
<a-typography-paragraph v-if="plainNote" :style="{ margin: 0, whiteSpace: 'pre-wrap' }">
|
||||||
|
|||||||
@@ -865,16 +865,20 @@ async function loadActivityImages(row: ActivityDto) {
|
|||||||
clearImageUrls();
|
clearImageUrls();
|
||||||
const next: NoteMedia[] = [];
|
const next: NoteMedia[] = [];
|
||||||
for (const image of row.images ?? []) {
|
for (const image of row.images ?? []) {
|
||||||
const mime = image.mimeType.toLowerCase();
|
const mime = (image.mimeType || 'application/octet-stream').toLowerCase();
|
||||||
const kind = mime.startsWith('audio/') ? 'audio' : mime.startsWith('image/') ? 'image' : 'file';
|
const kind = mime.startsWith('audio/') ? 'audio' : mime.startsWith('image/') ? 'image' : 'file';
|
||||||
try {
|
try {
|
||||||
const { data } = await api.get<Blob>(`/activities/${row.id}/images/${image.id}`, {
|
const { data } = await api.get<Blob>(`/activities/${row.id}/images/${image.id}`, {
|
||||||
responseType: 'blob',
|
responseType: 'blob',
|
||||||
});
|
});
|
||||||
|
const blob =
|
||||||
|
data.type && data.type !== 'application/octet-stream' && !data.type.includes('json')
|
||||||
|
? data
|
||||||
|
: new Blob([data], { type: mime });
|
||||||
next.push({
|
next.push({
|
||||||
id: image.id,
|
id: image.id,
|
||||||
name: image.fileName,
|
name: image.fileName,
|
||||||
url: URL.createObjectURL(data),
|
url: URL.createObjectURL(blob),
|
||||||
kind,
|
kind,
|
||||||
createdAt: image.createdAt,
|
createdAt: image.createdAt,
|
||||||
});
|
});
|
||||||
@@ -885,6 +889,20 @@ async function loadActivityImages(row: ActivityDto) {
|
|||||||
imageUrls.value = next;
|
imageUrls.value = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function viewMedia(item: NoteMedia) {
|
||||||
|
window.open(item.url, '_blank', 'noopener,noreferrer');
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadMedia(item: NoteMedia) {
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = item.url;
|
||||||
|
link.download = item.name || 'file';
|
||||||
|
link.rel = 'noopener';
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
link.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async function loadUsers() {
|
async function loadUsers() {
|
||||||
try {
|
try {
|
||||||
@@ -1004,8 +1022,12 @@ async function postponeTo(iso: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function submitComment(payload: { text: string; photoOnly: boolean }) {
|
async function submitComment(payload: {
|
||||||
const body = payload.text.trim() || (payload.photoOnly ? 'عکس پیوست شد.' : '');
|
text: string;
|
||||||
|
photoOnly: boolean;
|
||||||
|
attachmentIds?: string[];
|
||||||
|
}) {
|
||||||
|
const body = payload.text.trim() || (payload.photoOnly ? 'فایل پیوست شد.' : '');
|
||||||
if (!id.value || !activity.value || !body) return;
|
if (!id.value || !activity.value || !body) return;
|
||||||
saving.value = true;
|
saving.value = true;
|
||||||
error.value = '';
|
error.value = '';
|
||||||
@@ -1014,7 +1036,9 @@ async function submitComment(payload: { text: string; photoOnly: boolean }) {
|
|||||||
const now = new Date();
|
const now = new Date();
|
||||||
const author = auth.user?.fullName?.trim();
|
const author = auth.user?.fullName?.trim();
|
||||||
const stamp = `[${formatJalaliNumeric(now)} ساعت ${formatClockFa(now)}${author ? ` — ${author}` : ''}]`;
|
const stamp = `[${formatJalaliNumeric(now)} ساعت ${formatClockFa(now)}${author ? ` — ${author}` : ''}]`;
|
||||||
const entry = `${stamp}\n${body}`;
|
const ids = [...new Set((payload.attachmentIds ?? []).filter(Boolean))];
|
||||||
|
const attachLine = ids.length ? `\n[[attachments:${ids.join(',')}]]` : '';
|
||||||
|
const entry = `${stamp}\n${body}${attachLine}`;
|
||||||
const next = prev ? `${prev}\n\n${entry}` : entry;
|
const next = prev ? `${prev}\n\n${entry}` : entry;
|
||||||
await api.patch(`/activities/${id.value}`, { description: next });
|
await api.patch(`/activities/${id.value}`, { description: next });
|
||||||
commentOpen.value = false;
|
commentOpen.value = false;
|
||||||
@@ -1663,7 +1687,11 @@ onUnmounted(() => {
|
|||||||
</div>
|
</div>
|
||||||
<ul v-if="entry.media.some((image) => image.kind === 'file')" class="note-files">
|
<ul v-if="entry.media.some((image) => image.kind === 'file')" class="note-files">
|
||||||
<li v-for="image in entry.media.filter((item) => item.kind === 'file')" :key="image.id">
|
<li v-for="image in entry.media.filter((item) => item.kind === 'file')" :key="image.id">
|
||||||
<a :href="image.url" :download="image.name">{{ image.name }}</a>
|
<span class="note-file-name">{{ image.name }}</span>
|
||||||
|
<span class="note-file-actions">
|
||||||
|
<button type="button" class="note-file-btn" @click="viewMedia(image)">مشاهده</button>
|
||||||
|
<button type="button" class="note-file-btn" @click="downloadMedia(image)">دانلود</button>
|
||||||
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</template>
|
</template>
|
||||||
@@ -1746,7 +1774,11 @@ onUnmounted(() => {
|
|||||||
</div>
|
</div>
|
||||||
<ul v-if="looseMedia.some((image) => image.kind === 'file')" class="note-files">
|
<ul v-if="looseMedia.some((image) => image.kind === 'file')" class="note-files">
|
||||||
<li v-for="image in looseMedia.filter((item) => item.kind === 'file')" :key="image.id">
|
<li v-for="image in looseMedia.filter((item) => item.kind === 'file')" :key="image.id">
|
||||||
<a :href="image.url" :download="image.name">{{ image.name }}</a>
|
<span class="note-file-name">{{ image.name }}</span>
|
||||||
|
<span class="note-file-actions">
|
||||||
|
<button type="button" class="note-file-btn" @click="viewMedia(image)">مشاهده</button>
|
||||||
|
<button type="button" class="note-file-btn" @click="downloadMedia(image)">دانلود</button>
|
||||||
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@@ -2677,8 +2709,35 @@ dd {
|
|||||||
gap: 0.35rem;
|
gap: 0.35rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.note-files a {
|
.note-files li {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.note-file-name {
|
||||||
color: #0f766e;
|
color: #0f766e;
|
||||||
|
font-weight: 600;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.note-file-actions {
|
||||||
|
display: inline-flex;
|
||||||
|
gap: 0.35rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.note-file-btn {
|
||||||
|
border: 1px solid #99f6e4;
|
||||||
|
background: #fff;
|
||||||
|
color: #0f766e;
|
||||||
|
border-radius: 0.45rem;
|
||||||
|
font: inherit;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
font-weight: 700;
|
||||||
|
padding: 0.2rem 0.55rem;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dock {
|
.dock {
|
||||||
|
|||||||
Reference in New Issue
Block a user