67
67
<span class =" font-weight-bold" >Sent:</span >
68
68
{{ format.formatDate(item.sentDate) }}
69
69
</div >
70
- <div class =" pt-1" v-html =" item.message" />
70
+ <div class =" pt-1" @click.capture = " handlePdf " v-html =" item.message" />
71
71
</v-col >
72
72
</v-row >
73
73
</template >
@@ -209,6 +209,16 @@ export default {
209
209
deriveFromDisplay (item ) {
210
210
return item .ofmSourceSystem ? ` ${ this .userInfo ? .firstName ?? ' ' } ${this .userInfo ? .lastName }` : OFM_PROGRAM
211
211
},
212
+ handlePdf(event) {
213
+ if (event.target.classList.contains('conversation-pdf')) {
214
+ fetch(event.target.dataset.link)
215
+ .then((res) => res.blob())
216
+ .then((blob) => {
217
+ const blobUrl = URL.createObjectURL(blob)
218
+ window.open(blobUrl)
219
+ })
220
+ }
221
+ },
212
222
async formatConversation() {
213
223
const parser = new DOMParser()
214
224
for (const conversation of this.assistanceRequestConversation) {
@@ -218,15 +228,36 @@ export default {
218
228
const matches = ID_REGEX.exec(img.getAttribute('src'))
219
229
if (matches) {
220
230
const fileId = matches[1]
221
- const image = await FileService.getFile(fileId)
222
- const imageType = deriveImageType(image )
223
- img.setAttribute('src', ` data: image/ ${imageType};base64,${image }` )
231
+ const imageFile = await FileService.getFile(fileId, true )
232
+ const imageType = deriveImageType(imageFile.fileData )
233
+ img.setAttribute('src', ` data: image/ ${imageType};base64,${imageFile . fileData }` )
224
234
} else {
225
235
img.remove()
226
236
}
227
237
}
238
+
228
239
// Remove CRM links for now until we can support them
229
- document.querySelectorAll('a[href*="/api/data"]').forEach((link) => link.remove())
240
+ const fileLinks = document.querySelectorAll('a[href*="/api/data"]')
241
+
242
+ for (const fileLink of fileLinks) {
243
+ const matches = ID_REGEX.exec(fileLink.dataset.value)
244
+ if (matches) {
245
+ const fileId = matches[1]
246
+ const file = await FileService.getFile(fileId)
247
+ const dataLink = ` data: ${file .mimetype };base64,${file .fileData }`
248
+
249
+ if (file.mimetype === 'application/pdf') {
250
+ fileLink.setAttribute('href', '#')
251
+ fileLink.classList.add('conversation-pdf')
252
+ fileLink.setAttribute('data-link', dataLink)
253
+ } else {
254
+ fileLink.setAttribute('href', dataLink)
255
+ fileLink.setAttribute('download', file.filename)
256
+ }
257
+ } else {
258
+ fileLink.remove()
259
+ }
260
+ }
230
261
231
262
// Update the message content
232
263
conversation.message = document.documentElement.innerHTML
0 commit comments