Merged in feature/IO-3452-Documents-Adjustments (pull request #2678)
IO-3452 Documents Adjustments Approved-by: Dave Richer
This commit is contained in:
@@ -35,16 +35,14 @@ export function JobsDocumentsImgproxyDownloadButton({ galleryImages, identifier,
|
|||||||
...galleryImages.other.filter((image) => image.isSelected)
|
...galleryImages.other.filter((image) => image.isSelected)
|
||||||
];
|
];
|
||||||
|
|
||||||
function downloadProgress(progressEvent) {
|
const downloadProgress = ({ loaded }) => {
|
||||||
setDownload((currentDownloadState) => {
|
setDownload((currentDownloadState) => ({
|
||||||
return {
|
downloaded: loaded ?? 0,
|
||||||
downloaded: progressEvent.loaded || 0,
|
speed: (loaded ?? 0) - (currentDownloadState?.downloaded ?? 0)
|
||||||
speed: (progressEvent.loaded || 0) - ((currentDownloadState && currentDownloadState.downloaded) || 0)
|
}));
|
||||||
};
|
};
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function standardMediaDownload(bufferData) {
|
const standardMediaDownload = (bufferData) => {
|
||||||
try {
|
try {
|
||||||
const a = document.createElement("a");
|
const a = document.createElement("a");
|
||||||
const url = window.URL.createObjectURL(new Blob([bufferData]));
|
const url = window.URL.createObjectURL(new Blob([bufferData]));
|
||||||
@@ -55,29 +53,26 @@ export function JobsDocumentsImgproxyDownloadButton({ galleryImages, identifier,
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
setDownload(null);
|
setDownload(null);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const handleDownload = async () => {
|
const handleDownload = async () => {
|
||||||
logImEXEvent("jobs_documents_download");
|
logImEXEvent("jobs_documents_download");
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const response = await axios({
|
const { data } = await axios({
|
||||||
url: "/media/imgproxy/download",
|
url: "/media/imgproxy/download",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
responseType: "blob",
|
responseType: "blob",
|
||||||
data: { jobId, documentids: imagesToDownload.map((_) => _.id) },
|
data: { jobId, documentids: imagesToDownload.map((_) => _.id) },
|
||||||
onDownloadProgress: downloadProgress
|
onDownloadProgress: downloadProgress
|
||||||
});
|
});
|
||||||
|
|
||||||
setLoading(false);
|
|
||||||
setDownload(null);
|
|
||||||
|
|
||||||
// Use the response data (Blob) to trigger download
|
// Use the response data (Blob) to trigger download
|
||||||
standardMediaDownload(response.data);
|
standardMediaDownload(data);
|
||||||
} catch {
|
} catch {
|
||||||
|
// handle error (optional)
|
||||||
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setDownload(null);
|
setDownload(null);
|
||||||
// handle error (optional)
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -76,14 +76,14 @@ function JobsDocumentsImgproxyComponent({
|
|||||||
<SyncOutlined />
|
<SyncOutlined />
|
||||||
</Button>
|
</Button>
|
||||||
<JobsDocumentsGallerySelectAllComponent galleryImages={galleryImages} setGalleryImages={setGalleryImages} />
|
<JobsDocumentsGallerySelectAllComponent galleryImages={galleryImages} setGalleryImages={setGalleryImages} />
|
||||||
|
{!billId && (
|
||||||
|
<JobsDocumentsGalleryReassign galleryImages={galleryImages} callback={fetchThumbnails || refetch} />
|
||||||
|
)}
|
||||||
<JobsDocumentsDownloadButton galleryImages={galleryImages} identifier={downloadIdentifier} jobId={jobId} />
|
<JobsDocumentsDownloadButton galleryImages={galleryImages} identifier={downloadIdentifier} jobId={jobId} />
|
||||||
<JobsDocumentsDeleteButton
|
<JobsDocumentsDeleteButton
|
||||||
galleryImages={galleryImages}
|
galleryImages={galleryImages}
|
||||||
deletionCallback={billsCallback || fetchThumbnails || refetch}
|
deletionCallback={billsCallback || fetchThumbnails || refetch}
|
||||||
/>
|
/>
|
||||||
{!billId && (
|
|
||||||
<JobsDocumentsGalleryReassign galleryImages={galleryImages} callback={fetchThumbnails || refetch} />
|
|
||||||
)}
|
|
||||||
</Space>
|
</Space>
|
||||||
</Col>
|
</Col>
|
||||||
{!hasMediaAccess && (
|
{!hasMediaAccess && (
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export default function JobsDocumentsImgproxyDeleteButton({ galleryImages, delet
|
|||||||
okButtonProps={{ danger: true }}
|
okButtonProps={{ danger: true }}
|
||||||
cancelText={t("general.actions.cancel")}
|
cancelText={t("general.actions.cancel")}
|
||||||
>
|
>
|
||||||
<Button disabled={imagesToDelete.length < 1} loading={loading}>
|
<Button danger disabled={imagesToDelete.length < 1} loading={loading}>
|
||||||
{t("documents.actions.delete")}
|
{t("documents.actions.delete")}
|
||||||
</Button>
|
</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
|
|||||||
@@ -107,8 +107,8 @@ export function JobsDocumentsLocalGallery({
|
|||||||
<a href={CreateExplorerLinkForJob({ jobid: job.id })}>
|
<a href={CreateExplorerLinkForJob({ jobid: job.id })}>
|
||||||
<Button>{t("documents.labels.openinexplorer")}</Button>
|
<Button>{t("documents.labels.openinexplorer")}</Button>
|
||||||
</a>
|
</a>
|
||||||
<JobsDocumentsLocalGalleryReassign jobid={job.id} />
|
|
||||||
<JobsDocumentsLocalGallerySelectAllComponent jobid={job.id} />
|
<JobsDocumentsLocalGallerySelectAllComponent jobid={job.id} />
|
||||||
|
<JobsDocumentsLocalGalleryReassign jobid={job.id} />
|
||||||
<JobsLocalGalleryDownloadButton job={job} />
|
<JobsLocalGalleryDownloadButton job={job} />
|
||||||
<JobsDocumentsLocalDeleteButton jobid={job.id} />
|
<JobsDocumentsLocalDeleteButton jobid={job.id} />
|
||||||
</Space>
|
</Space>
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ export function JobsDocumentsLocalDeleteButton({ bodyshop, getJobMedia, allMedia
|
|||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const imagesToDelete = (allMedia?.[jobid] || []).filter((i) => i.isSelected);
|
||||||
|
|
||||||
const handleDelete = async () => {
|
const handleDelete = async () => {
|
||||||
logImEXEvent("job_documents_delete");
|
logImEXEvent("job_documents_delete");
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -36,7 +38,7 @@ export function JobsDocumentsLocalDeleteButton({ bodyshop, getJobMedia, allMedia
|
|||||||
`${bodyshop.localmediaserverhttp}/jobs/delete`,
|
`${bodyshop.localmediaserverhttp}/jobs/delete`,
|
||||||
{
|
{
|
||||||
jobid: jobid,
|
jobid: jobid,
|
||||||
files: (allMedia?.[jobid] || []).filter((i) => i.isSelected).map((i) => i.filename)
|
files: imagesToDelete.map((i) => i.filename)
|
||||||
},
|
},
|
||||||
{ headers: { ims_token: bodyshop.localmediatoken } }
|
{ headers: { ims_token: bodyshop.localmediatoken } }
|
||||||
);
|
);
|
||||||
@@ -60,14 +62,17 @@ export function JobsDocumentsLocalDeleteButton({ bodyshop, getJobMedia, allMedia
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
|
disabled={imagesToDelete.length < 1}
|
||||||
icon={<QuestionCircleOutlined style={{ color: "red" }} />}
|
icon={<QuestionCircleOutlined style={{ color: "red" }} />}
|
||||||
onConfirm={handleDelete}
|
onConfirm={handleDelete}
|
||||||
title={t("documents.labels.confirmdelete")}
|
title={t("documents.labels.confirmdelete")}
|
||||||
okText={t("general.actions.delete")}
|
okText={t("general.actions.delete")}
|
||||||
okButtonProps={{ type: "danger" }}
|
okButtonProps={{ danger: true }}
|
||||||
cancelText={t("general.actions.cancel")}
|
cancelText={t("general.actions.cancel")}
|
||||||
>
|
>
|
||||||
<Button loading={loading}>{t("documents.actions.delete")}</Button>
|
<Button danger disabled={imagesToDelete.length < 1} loading={loading}>
|
||||||
|
{t("documents.actions.delete")}
|
||||||
|
</Button>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Button } from "antd";
|
import { Button, Space } from "antd";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import cleanAxios from "../../utils/CleanAxios";
|
import cleanAxios from "../../utils/CleanAxios";
|
||||||
|
import formatBytes from "../../utils/formatbytes";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { selectAllMedia } from "../../redux/media/media.selectors";
|
import { selectAllMedia } from "../../redux/media/media.selectors";
|
||||||
@@ -19,45 +19,63 @@ export default connect(mapStateToProps, mapDispatchToProps)(JobsLocalGalleryDown
|
|||||||
|
|
||||||
export function JobsLocalGalleryDownloadButton({ bodyshop, allMedia, job }) {
|
export function JobsLocalGalleryDownloadButton({ bodyshop, allMedia, job }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [download, setDownload] = useState(null);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [download, setDownload] = useState(false);
|
||||||
|
|
||||||
function downloadProgress(progressEvent) {
|
const imagesToDownload = (allMedia?.[job.id] || []).filter((i) => i.isSelected);
|
||||||
setDownload((currentDownloadState) => {
|
|
||||||
return {
|
const downloadProgress = ({ loaded }) => {
|
||||||
downloaded: progressEvent.loaded || 0,
|
setDownload((currentDownloadState) => ({
|
||||||
speed: (progressEvent.loaded || 0) - (currentDownloadState?.downloaded || 0)
|
downloaded: loaded || 0,
|
||||||
};
|
speed: (loaded || 0) - (currentDownloadState?.downloaded || 0)
|
||||||
});
|
}));
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const standardMediaDownload = (bufferData, filename) => {
|
||||||
|
try {
|
||||||
|
const a = document.createElement("a");
|
||||||
|
const url = window.URL.createObjectURL(new Blob([bufferData]));
|
||||||
|
a.href = url;
|
||||||
|
a.download = `${filename}.zip`;
|
||||||
|
a.click();
|
||||||
|
} catch {
|
||||||
|
setLoading(false);
|
||||||
|
setDownload(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleDownload = async () => {
|
const handleDownload = async () => {
|
||||||
const theDownloadedZip = await cleanAxios.post(
|
const { localmediaserverhttp, localmediatoken } = bodyshop;
|
||||||
`${bodyshop.localmediaserverhttp}/jobs/download`,
|
const { id, ro_number } = job;
|
||||||
{
|
setLoading(true);
|
||||||
jobid: job.id,
|
try {
|
||||||
files: (allMedia?.[job.id] || []).filter((i) => i.isSelected).map((i) => i.filename)
|
const response = await cleanAxios.post(
|
||||||
},
|
`${localmediaserverhttp}/jobs/download`,
|
||||||
{
|
{
|
||||||
headers: { ims_token: bodyshop.localmediatoken },
|
jobid: id,
|
||||||
responseType: "arraybuffer",
|
files: imagesToDownload.map((i) => i.filename)
|
||||||
onDownloadProgress: downloadProgress
|
},
|
||||||
}
|
{
|
||||||
);
|
headers: { ims_token: localmediatoken },
|
||||||
setDownload(null);
|
responseType: "arraybuffer",
|
||||||
standardMediaDownload(theDownloadedZip.data, job.ro_number);
|
onDownloadProgress: downloadProgress
|
||||||
|
}
|
||||||
|
);
|
||||||
|
standardMediaDownload(response.data, ro_number);
|
||||||
|
} catch {
|
||||||
|
// handle error (optional)
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
setDownload(null);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button loading={!!download} onClick={handleDownload}>
|
<Button disabled={imagesToDownload < 1} loading={download || loading} onClick={handleDownload}>
|
||||||
{t("documents.actions.download")}
|
<Space>
|
||||||
|
<span>{t("documents.actions.download")}</span>
|
||||||
|
{download && <span>{`(${formatBytes(download.downloaded)} @ ${formatBytes(download.speed)} / second)`}</span>}
|
||||||
|
</Space>
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function standardMediaDownload(bufferData, filename) {
|
|
||||||
const a = document.createElement("a");
|
|
||||||
const url = window.URL.createObjectURL(new Blob([bufferData]));
|
|
||||||
a.href = url;
|
|
||||||
a.download = `${filename}.zip`;
|
|
||||||
a.click();
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user