Compare commits

..

No commits in common. "c69c4cf3ddf611f9133c43ab07d43949cce592ae" and "f2ccec483f861950f29bf2d7b529ee4d7ef3a9f2" have entirely different histories.

4 changed files with 59 additions and 197 deletions

View File

@ -1254,13 +1254,13 @@ span.ant-skeleton-input.ant-skeleton-input-sm.text-skeleton {
mask-image: linear-gradient(
to right,
#000 0%,
#000 calc(100% - 0.5em),
#000 calc(100% - 0.8em),
transparent 100%
);
-webkit-mask-image: linear-gradient(
to right,
#000 0%,
#000 calc(100% - 0.5em),
#000 calc(100% - 0.8em),
transparent 100%
);
}
@ -1271,13 +1271,13 @@ span.ant-skeleton-input.ant-skeleton-input-sm.text-skeleton {
mask-image: linear-gradient(
to left,
#000 0%,
#000 calc(100% - 0.5em),
#000 calc(100% - 0.8em),
transparent 100%
);
-webkit-mask-image: linear-gradient(
to left,
#000 0%,
#000 calc(100% - 0.5em),
#000 calc(100% - 0.8em),
transparent 100%
);
}

View File

@ -8,7 +8,7 @@ import { useContext, useRef, useState } from 'react'
import dayjs from 'dayjs'
const NewDocumentJob = ({ onOk, defaultValues = {} }) => {
const { sendObjectAction, downloadTemplate, formatFileName } =
const { sendObjectAction, downloadTemplatePDF, formatFileName } =
useContext(ApiServerContext)
const [downloading, setDownloading] = useState(false)
@ -92,12 +92,11 @@ const NewDocumentJob = ({ onOk, defaultValues = {} }) => {
key: 'pdf',
onClick: () => {
setDownloading(true)
downloadTemplate(
downloadTemplatePDF(
objectData.documentTemplate._id,
objectData.documentTemplate.content,
objectData.object,
fileName,
'pdf',
() => {
setDownloading(false)
}
@ -106,54 +105,11 @@ const NewDocumentJob = ({ onOk, defaultValues = {} }) => {
},
{
label: 'PNG',
key: 'png',
onClick: () => {
setDownloading(true)
downloadTemplate(
objectData.documentTemplate._id,
objectData.documentTemplate.content,
objectData.object,
fileName,
'png',
() => {
setDownloading(false)
}
)
}
key: 'png'
},
{
label: 'JPEG',
key: 'jpeg',
onClick: () => {
setDownloading(true)
downloadTemplate(
objectData.documentTemplate._id,
objectData.documentTemplate.content,
objectData.object,
fileName,
'jpeg',
() => {
setDownloading(false)
}
)
}
},
{
label: 'SVG',
key: 'svg',
onClick: () => {
setDownloading(true)
downloadTemplate(
objectData.documentTemplate._id,
objectData.documentTemplate.content,
objectData.object,
fileName,
'svg',
() => {
setDownloading(false)
}
)
}
key: 'jpeg'
}
]
}

View File

@ -192,7 +192,9 @@ const ObjectDisplay = ({
if (!objectData?.name) return null
const textElement = (
<ElipsisText style={{ lineHeight: '1' }}>{objectData.name}</ElipsisText>
<ElipsisText style={{ lineHeight: '1', paddingBottom: '2px' }}>
{objectData.name}
</ElipsisText>
)
// If hyperlink is enabled

View File

@ -1750,30 +1750,6 @@ const ApiServerProvider = ({ children }) => {
}
}
const getTemplateErrorFromResponse = (err) => {
const data = err?.response?.data
if (data instanceof ArrayBuffer) {
try {
const parsed = JSON.parse(new TextDecoder().decode(data))
return parsed?.error || err.message
} catch {
return err.message
}
}
return data?.error || err.message
}
const triggerFileDownload = (blob, filename) => {
const fileUrl = URL.createObjectURL(blob)
const fileLink = document.createElement('a')
fileLink.href = fileUrl
fileLink.setAttribute('download', filename)
document.body.appendChild(fileLink)
fileLink.click()
fileLink.parentNode.removeChild(fileLink)
URL.revokeObjectURL(fileUrl)
}
const fetchTemplatePreview = async (
id,
content,
@ -1782,131 +1758,38 @@ const ApiServerProvider = ({ children }) => {
callback
) => {
logger.debug('Fetching preview...')
try {
const response = await axios.post(
`${config.backendUrl}/documenttemplates/${id}/preview`,
if (socketRef.current && socketRef.current.connected) {
return socketRef.current.emit(
'previewTemplate',
{
content,
testObject,
scale
_id: id,
content: content,
testObject: testObject,
scale: scale
},
{
headers: {
Accept: 'application/json',
Authorization: `Bearer ${token}`
}
}
callback
)
if (typeof callback === 'function') {
callback(response.data)
}
return response.data
} catch (err) {
const error = getTemplateErrorFromResponse(err)
logger.error('Error fetching template preview:', error)
if (typeof callback === 'function') {
callback({ error })
}
return { error }
}
}
const fetchTemplateDownload = async (id, content, object, type = 'pdf') => {
logger.debug(`Fetching template download as ${type}...`)
const response = await axios.post(
`${config.backendUrl}/documenttemplates/${id}/download`,
{
content,
object
},
{
params: { type },
responseType: 'arraybuffer',
headers: {
Authorization: `Bearer ${token}`
}
}
)
const contentType = response.headers['content-type'] || ''
if (contentType.includes('application/json')) {
return JSON.parse(new TextDecoder().decode(response.data))
}
return {
type,
mime: contentType,
buffer: response.data
if (typeof callback === 'function') {
callback({ error: 'Api Server disconnected' })
}
}
const fetchTemplatePDF = async (id, content, testObject, callback) => {
logger.debug('Fetching pdf template...')
try {
const result = await fetchTemplateDownload(id, content, testObject, 'pdf')
const payload = result.error ? result : { pdf: result.buffer || result }
if (typeof callback === 'function') {
callback(payload)
}
return payload
} catch (err) {
const error = getTemplateErrorFromResponse(err)
logger.error('Error fetching template PDF:', error)
if (typeof callback === 'function') {
callback({ error })
}
return { error }
if (socketRef.current && socketRef.current.connected) {
return socketRef.current.emit(
'renderTemplatePDF',
{
_id: id,
content: content,
object: testObject
},
callback
)
}
}
const downloadTemplate = async (
id,
content,
object,
filename,
type = 'pdf',
callback
) => {
logger.debug(`Downloading template as ${type}...`)
try {
const result = await fetchTemplateDownload(id, content, object, type)
if (result?.error) {
if (callback) {
callback(result.error)
}
return result
}
if (Array.isArray(result.images)) {
result.images.forEach((image, index) => {
const binary = atob(image)
const bytes = new Uint8Array(binary.length)
for (let i = 0; i < binary.length; i += 1) {
bytes[i] = binary.charCodeAt(i)
}
const blob = new Blob([bytes], { type: result.mime })
const suffix = result.images.length > 1 ? `-${index + 1}` : ''
triggerFileDownload(
blob,
`${filename}${suffix}.${result.extension || type}`
)
})
} else {
const blob = new Blob([result.buffer], {
type: result.mime || 'application/octet-stream'
})
const extension = type === 'jpeg' ? 'jpeg' : type
triggerFileDownload(blob, `${filename}.${extension}`)
}
if (callback) {
callback()
}
} catch (err) {
const error = getTemplateErrorFromResponse(err)
logger.error('Error downloading template:', error)
if (callback) {
callback(error)
}
return { error }
if (typeof callback === 'function') {
callback({ error: 'Api Server disconnected' })
}
}
@ -1917,7 +1800,29 @@ const ApiServerProvider = ({ children }) => {
filename,
callback
) => {
return downloadTemplate(id, content, object, filename, 'pdf', callback)
logger.debug('Downloading template PDF...')
fetchTemplatePDF(id, content, object, (result) => {
logger.debug('Downloading template PDF result:', result)
if (result?.error) {
console.error(result.error)
if (callback) {
callback(result.error)
}
} else {
const pdfBlob = new Blob([result.pdf], { type: 'application/pdf' })
const pdfUrl = URL.createObjectURL(pdfBlob)
const fileLink = document.createElement('a')
fileLink.href = pdfUrl
fileLink.setAttribute('download', `${filename}.pdf`)
document.body.appendChild(fileLink)
fileLink.click()
fileLink.parentNode.removeChild(fileLink)
if (callback) {
callback()
}
}
})
}
const fetchHostOTP = async (id, callback) => {
@ -2010,8 +1915,8 @@ const ApiServerProvider = ({ children }) => {
if (!userProfile?._id) return { data: [] }
const result = await fetchObjects('userNotifier', {
filter: {
'user._id': userProfile._id,
'object._id': objectId,
user: userProfile._id,
object: objectId,
objectType
},
limit: 1
@ -2022,7 +1927,7 @@ const ApiServerProvider = ({ children }) => {
const fetchAllUserNotifiersForObject = async (objectId, objectType) => {
const result = await fetchObjects('userNotifier', {
filter: {
'object._id': objectId,
object: objectId,
objectType
},
limit: 100
@ -2348,7 +2253,6 @@ const ApiServerProvider = ({ children }) => {
fetchTemplatePreview,
fetchTemplatePDF,
fetchNotes,
downloadTemplate,
downloadTemplatePDF,
fetchHostOTP,
sendObjectAction,