Added file extesions for documents IO-525
This commit is contained in:
@@ -20,8 +20,10 @@ export const handleUpload = (ev, context) => {
|
|||||||
const { bodyshop, jobId } = context;
|
const { bodyshop, jobId } = context;
|
||||||
|
|
||||||
let key = `${bodyshop.id}/${jobId}/${ev.file.name.replace(/\.[^/.]+$/, "")}`;
|
let key = `${bodyshop.id}/${jobId}/${ev.file.name.replace(/\.[^/.]+$/, "")}`;
|
||||||
|
let extension = ev.file.name.split(".").pop();
|
||||||
uploadToCloudinary(
|
uploadToCloudinary(
|
||||||
key,
|
key,
|
||||||
|
extension,
|
||||||
ev.file.type,
|
ev.file.type,
|
||||||
ev.file,
|
ev.file,
|
||||||
onError,
|
onError,
|
||||||
@@ -33,6 +35,7 @@ export const handleUpload = (ev, context) => {
|
|||||||
|
|
||||||
export const uploadToCloudinary = async (
|
export const uploadToCloudinary = async (
|
||||||
key,
|
key,
|
||||||
|
extension,
|
||||||
fileType,
|
fileType,
|
||||||
file,
|
file,
|
||||||
onError,
|
onError,
|
||||||
@@ -94,7 +97,7 @@ export const uploadToCloudinary = async (
|
|||||||
formData.append("signature", signature);
|
formData.append("signature", signature);
|
||||||
|
|
||||||
const cloudinaryUploadResponse = await cleanAxios.post(
|
const cloudinaryUploadResponse = await cleanAxios.post(
|
||||||
`${process.env.REACT_APP_CLOUDINARY_ENDPOINT}/${DetermineFileType(
|
`${process.env.REACT_APP_CLOUDINARY_ENDPOINT_API}/${DetermineFileType(
|
||||||
fileType
|
fileType
|
||||||
)}/upload`,
|
)}/upload`,
|
||||||
formData,
|
formData,
|
||||||
@@ -129,6 +132,7 @@ export const uploadToCloudinary = async (
|
|||||||
key: key,
|
key: key,
|
||||||
billid: billId,
|
billid: billId,
|
||||||
type: fileType,
|
type: fileType,
|
||||||
|
extension: extension,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -164,6 +168,7 @@ export function DetermineFileType(filetype) {
|
|||||||
else if (filetype.startsWith("image")) return "image";
|
else if (filetype.startsWith("image")) return "image";
|
||||||
else if (filetype.startsWith("video")) return "video";
|
else if (filetype.startsWith("video")) return "video";
|
||||||
else if (filetype.startsWith("application/pdf")) return "image";
|
else if (filetype.startsWith("application/pdf")) return "image";
|
||||||
|
else if (filetype.startsWith("application")) return "raw";
|
||||||
|
|
||||||
return "auto";
|
return "auto";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
|
import { FileExcelFilled } from "@ant-design/icons";
|
||||||
import { Card, Space } from "antd";
|
import { Card, Space } from "antd";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import Gallery from "react-grid-gallery";
|
import Gallery from "react-grid-gallery";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import DocumentsUploadComponent from "../documents-upload/documents-upload.component";
|
import DocumentsUploadComponent from "../documents-upload/documents-upload.component";
|
||||||
|
import { DetermineFileType } from "../documents-upload/documents-upload.utility";
|
||||||
import JobsDocumentsDownloadButton from "./jobs-document-gallery.download.component";
|
import JobsDocumentsDownloadButton from "./jobs-document-gallery.download.component";
|
||||||
import JobsDocumentsDeleteButton from "./jobs-documents-gallery.delete.component";
|
import JobsDocumentsDeleteButton from "./jobs-documents-gallery.delete.component";
|
||||||
import JobsDocumentsGallerySelectAllComponent from "./jobs-documents-gallery.selectall.component";
|
import JobsDocumentsGallerySelectAllComponent from "./jobs-documents-gallery.selectall.component";
|
||||||
|
|
||||||
function JobsDocumentsComponent({
|
function JobsDocumentsComponent({
|
||||||
data,
|
data,
|
||||||
jobId,
|
jobId,
|
||||||
@@ -20,29 +21,47 @@ function JobsDocumentsComponent({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let documents = data.reduce(
|
let documents = data.reduce(
|
||||||
(acc, value) => {
|
(acc, value) => {
|
||||||
console.log("value", value);
|
const fileType = DetermineFileType(value.type);
|
||||||
if (value.type.includes("image")) {
|
if (value.type.startsWith("image")) {
|
||||||
acc.images.push({
|
acc.images.push({
|
||||||
src: `${process.env.REACT_APP_CLOUDINARY_IMAGE_ENDPOINT}/${value.key}`,
|
src: `${
|
||||||
thumbnail: `${process.env.REACT_APP_CLOUDINARY_IMAGE_ENDPOINT}/${process.env.REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS}/${value.key}`,
|
process.env.REACT_APP_CLOUDINARY_ENDPOINT
|
||||||
|
}/${DetermineFileType(value.type)}/upload/${value.key}`,
|
||||||
|
thumbnail: `${
|
||||||
|
process.env.REACT_APP_CLOUDINARY_ENDPOINT
|
||||||
|
}/${DetermineFileType(value.type)}/upload/${
|
||||||
|
process.env.REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS
|
||||||
|
}/${value.key}`,
|
||||||
thumbnailHeight: 225,
|
thumbnailHeight: 225,
|
||||||
thumbnailWidth: 225,
|
thumbnailWidth: 225,
|
||||||
isSelected: false,
|
isSelected: false,
|
||||||
key: value.key,
|
key: value.key,
|
||||||
|
extension: value.extension,
|
||||||
id: value.id,
|
id: value.id,
|
||||||
type: value.type,
|
type: value.type,
|
||||||
tags: [{ value: value.type, title: value.type }],
|
tags: [{ value: value.type, title: value.type }],
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
let thumb;
|
||||||
|
switch (fileType) {
|
||||||
|
case "video":
|
||||||
|
thumb = `${process.env.REACT_APP_CLOUDINARY_ENDPOINT}/${fileType}/upload/c_fill,f_png,h_250,w_250/${value.key}`;
|
||||||
|
break;
|
||||||
|
case "raw":
|
||||||
|
thumb = "";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
thumb = `${process.env.REACT_APP_CLOUDINARY_ENDPOINT}/${fileType}/upload/${process.env.REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS}/${value.key}`;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
acc.other.push({
|
acc.other.push({
|
||||||
src: `${
|
src: `${
|
||||||
value.type.startsWith("video")
|
process.env.REACT_APP_CLOUDINARY_ENDPOINT
|
||||||
? process.env.REACT_APP_CLOUDINARY_VIDEO_ENDPOINT
|
}/${fileType}/upload/${fileType === "video" ? "q_auto/" : ""}${
|
||||||
: process.env.REACT_APP_CLOUDINARY_IMAGE_ENDPOINT
|
value.key
|
||||||
}/q_auto/${value.key}`,
|
}${fileType === "raw" ? `.${value.extension}` : ""}`,
|
||||||
thumbnail: value.type.startsWith("video")
|
thumbnail: thumb,
|
||||||
? `${process.env.REACT_APP_CLOUDINARY_VIDEO_ENDPOINT}/c_fill,f_png,h_250,w_250/${value.key}`
|
|
||||||
: `${process.env.REACT_APP_CLOUDINARY_IMAGE_ENDPOINT}/${process.env.REACT_APP_CLOUDINARY_THUMB_TRANSFORMATIONS}/${value.key}`,
|
|
||||||
tags: [
|
tags: [
|
||||||
{ value: value.type, title: value.type },
|
{ value: value.type, title: value.type },
|
||||||
...(value.bill
|
...(value.bill
|
||||||
@@ -62,6 +81,7 @@ function JobsDocumentsComponent({
|
|||||||
thumbnailHeight: 225,
|
thumbnailHeight: 225,
|
||||||
thumbnailWidth: 225,
|
thumbnailWidth: 225,
|
||||||
isSelected: false,
|
isSelected: false,
|
||||||
|
extension: value.extension,
|
||||||
key: value.key,
|
key: value.key,
|
||||||
id: value.id,
|
id: value.id,
|
||||||
type: value.type,
|
type: value.type,
|
||||||
@@ -124,6 +144,13 @@ function JobsDocumentsComponent({
|
|||||||
images={galleryImages.other}
|
images={galleryImages.other}
|
||||||
backdropClosesModal={true}
|
backdropClosesModal={true}
|
||||||
enableLightbox={false}
|
enableLightbox={false}
|
||||||
|
thumbnailStyle={() => {
|
||||||
|
return {
|
||||||
|
backgroundImage: <FileExcelFilled />,
|
||||||
|
height: "100%",
|
||||||
|
width: "100%",
|
||||||
|
};
|
||||||
|
}}
|
||||||
onClickThumbnail={(index) => {
|
onClickThumbnail={(index) => {
|
||||||
window.open(
|
window.open(
|
||||||
galleryImages.other[index].src,
|
galleryImages.other[index].src,
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ export default function JobsDocumentsDeleteButton({
|
|||||||
|
|
||||||
cleanAxios
|
cleanAxios
|
||||||
.post(
|
.post(
|
||||||
`${process.env.REACT_APP_CLOUDINARY_ENDPOINT}/${DetermineFileType(
|
`${
|
||||||
image.type
|
process.env.REACT_APP_CLOUDINARY_ENDPOINT_API
|
||||||
)}/destroy`,
|
}/${DetermineFileType(image.type)}/destroy`,
|
||||||
formData,
|
formData,
|
||||||
options
|
options
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export const GET_DOCUMENTS_BY_JOB = gql`
|
|||||||
name
|
name
|
||||||
key
|
key
|
||||||
type
|
type
|
||||||
|
extension
|
||||||
bill {
|
bill {
|
||||||
id
|
id
|
||||||
invoice_number
|
invoice_number
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
- args:
|
||||||
|
cascade: false
|
||||||
|
read_only: false
|
||||||
|
sql: ALTER TABLE "public"."documents" DROP COLUMN "extension";
|
||||||
|
type: run_sql
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
- args:
|
||||||
|
cascade: false
|
||||||
|
read_only: false
|
||||||
|
sql: ALTER TABLE "public"."documents" ADD COLUMN "extension" text NULL;
|
||||||
|
type: run_sql
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
- args:
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: documents
|
||||||
|
schema: public
|
||||||
|
type: drop_insert_permission
|
||||||
|
- args:
|
||||||
|
permission:
|
||||||
|
check:
|
||||||
|
job:
|
||||||
|
bodyshop:
|
||||||
|
associations:
|
||||||
|
_and:
|
||||||
|
- user:
|
||||||
|
authid:
|
||||||
|
_eq: X-Hasura-User-Id
|
||||||
|
- active:
|
||||||
|
_eq: true
|
||||||
|
columns:
|
||||||
|
- id
|
||||||
|
- created_at
|
||||||
|
- updated_at
|
||||||
|
- uploaded_by
|
||||||
|
- jobid
|
||||||
|
- name
|
||||||
|
- key
|
||||||
|
- billid
|
||||||
|
- type
|
||||||
|
set: {}
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: documents
|
||||||
|
schema: public
|
||||||
|
type: create_insert_permission
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
- args:
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: documents
|
||||||
|
schema: public
|
||||||
|
type: drop_insert_permission
|
||||||
|
- args:
|
||||||
|
permission:
|
||||||
|
check:
|
||||||
|
job:
|
||||||
|
bodyshop:
|
||||||
|
associations:
|
||||||
|
_and:
|
||||||
|
- user:
|
||||||
|
authid:
|
||||||
|
_eq: X-Hasura-User-Id
|
||||||
|
- active:
|
||||||
|
_eq: true
|
||||||
|
columns:
|
||||||
|
- billid
|
||||||
|
- created_at
|
||||||
|
- extension
|
||||||
|
- id
|
||||||
|
- jobid
|
||||||
|
- key
|
||||||
|
- name
|
||||||
|
- type
|
||||||
|
- updated_at
|
||||||
|
- uploaded_by
|
||||||
|
set: {}
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: documents
|
||||||
|
schema: public
|
||||||
|
type: create_insert_permission
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
- args:
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: documents
|
||||||
|
schema: public
|
||||||
|
type: drop_select_permission
|
||||||
|
- args:
|
||||||
|
permission:
|
||||||
|
allow_aggregations: false
|
||||||
|
columns:
|
||||||
|
- key
|
||||||
|
- name
|
||||||
|
- type
|
||||||
|
- uploaded_by
|
||||||
|
- created_at
|
||||||
|
- updated_at
|
||||||
|
- id
|
||||||
|
- billid
|
||||||
|
- jobid
|
||||||
|
computed_fields: []
|
||||||
|
filter:
|
||||||
|
job:
|
||||||
|
bodyshop:
|
||||||
|
associations:
|
||||||
|
_and:
|
||||||
|
- user:
|
||||||
|
authid:
|
||||||
|
_eq: X-Hasura-User-Id
|
||||||
|
- active:
|
||||||
|
_eq: true
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: documents
|
||||||
|
schema: public
|
||||||
|
type: create_select_permission
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
- args:
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: documents
|
||||||
|
schema: public
|
||||||
|
type: drop_select_permission
|
||||||
|
- args:
|
||||||
|
permission:
|
||||||
|
allow_aggregations: false
|
||||||
|
columns:
|
||||||
|
- billid
|
||||||
|
- created_at
|
||||||
|
- extension
|
||||||
|
- id
|
||||||
|
- jobid
|
||||||
|
- key
|
||||||
|
- name
|
||||||
|
- type
|
||||||
|
- updated_at
|
||||||
|
- uploaded_by
|
||||||
|
computed_fields: []
|
||||||
|
filter:
|
||||||
|
job:
|
||||||
|
bodyshop:
|
||||||
|
associations:
|
||||||
|
_and:
|
||||||
|
- user:
|
||||||
|
authid:
|
||||||
|
_eq: X-Hasura-User-Id
|
||||||
|
- active:
|
||||||
|
_eq: true
|
||||||
|
role: user
|
||||||
|
table:
|
||||||
|
name: documents
|
||||||
|
schema: public
|
||||||
|
type: create_select_permission
|
||||||
@@ -1450,28 +1450,30 @@ tables:
|
|||||||
- active:
|
- active:
|
||||||
_eq: true
|
_eq: true
|
||||||
columns:
|
columns:
|
||||||
- id
|
- billid
|
||||||
- created_at
|
- created_at
|
||||||
|
- extension
|
||||||
|
- id
|
||||||
|
- jobid
|
||||||
|
- key
|
||||||
|
- name
|
||||||
|
- type
|
||||||
- updated_at
|
- updated_at
|
||||||
- uploaded_by
|
- uploaded_by
|
||||||
- jobid
|
|
||||||
- name
|
|
||||||
- key
|
|
||||||
- billid
|
|
||||||
- type
|
|
||||||
select_permissions:
|
select_permissions:
|
||||||
- role: user
|
- role: user
|
||||||
permission:
|
permission:
|
||||||
columns:
|
columns:
|
||||||
|
- billid
|
||||||
|
- created_at
|
||||||
|
- extension
|
||||||
|
- id
|
||||||
|
- jobid
|
||||||
- key
|
- key
|
||||||
- name
|
- name
|
||||||
- type
|
- type
|
||||||
- uploaded_by
|
|
||||||
- created_at
|
|
||||||
- updated_at
|
- updated_at
|
||||||
- id
|
- uploaded_by
|
||||||
- billid
|
|
||||||
- jobid
|
|
||||||
filter:
|
filter:
|
||||||
job:
|
job:
|
||||||
bodyshop:
|
bodyshop:
|
||||||
|
|||||||
Reference in New Issue
Block a user