Merge pull request #142 from bipproduction/amalia/23-agustus-24
upd: document
This commit is contained in:
@@ -30,16 +30,56 @@ export async function GET(request: Request) {
|
|||||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan" }, { status: 404 });
|
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan" }, { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let statusAkses = false
|
||||||
|
let aksesPath = String(path)
|
||||||
if (path != "home" && path != "null" && path != "undefined" && path != "") {
|
if (path != "home" && path != "null" && path != "undefined" && path != "") {
|
||||||
const cekPath = await prisma.divisionDocumentFolderFile.count({
|
const cekPath = await prisma.divisionDocumentFolderFile.count({
|
||||||
where: {
|
where: {
|
||||||
isActive: true,
|
isActive: true,
|
||||||
id: String(path)
|
id: String(path),
|
||||||
|
idDivision: String(idDivision)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (cekPath == 0) {
|
const cekSharePath = await prisma.divisionDocumentShare.count({
|
||||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan item, data tidak ditemukan" }, { status: 404 });
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
idDivision: String(idDivision),
|
||||||
|
idDocument: String(path)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (cekPath == 0 && cekSharePath == 0) {
|
||||||
|
do {
|
||||||
|
const dataPath = await prisma.divisionDocumentFolderFile.findUnique({
|
||||||
|
where: {
|
||||||
|
id: String(aksesPath)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (dataPath) {
|
||||||
|
const cekShare = await prisma.divisionDocumentShare.count({
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
idDivision: String(idDivision),
|
||||||
|
idDocument: String(aksesPath)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (cekShare == 0) {
|
||||||
|
statusAkses = false
|
||||||
|
aksesPath = dataPath.path
|
||||||
|
} else {
|
||||||
|
statusAkses = true
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
aksesPath = "home"
|
||||||
|
}
|
||||||
|
} while (aksesPath != "home" && statusAkses == false);
|
||||||
|
|
||||||
|
if (statusAkses == false) {
|
||||||
|
return NextResponse.json({ success: false, message: "Data tidak ditemukan / tidak memilik hak akses" }, { status: 404 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +90,8 @@ export async function GET(request: Request) {
|
|||||||
path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path
|
path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let formatDataShare: any[] = [];
|
||||||
|
|
||||||
if (category == "folder") {
|
if (category == "folder") {
|
||||||
kondisi = {
|
kondisi = {
|
||||||
isActive: true,
|
isActive: true,
|
||||||
@@ -57,6 +99,52 @@ export async function GET(request: Request) {
|
|||||||
path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path,
|
path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path,
|
||||||
category: "FOLDER"
|
category: "FOLDER"
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (path == "home" || path == "null" || path == "undefined") {
|
||||||
|
const dataShare = await prisma.divisionDocumentShare.findMany({
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
idDivision: String(idDivision),
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
DivisionDocumentFolderFile: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
category: true,
|
||||||
|
name: true,
|
||||||
|
extension: true,
|
||||||
|
path: true,
|
||||||
|
User: {
|
||||||
|
select: {
|
||||||
|
name: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
formatDataShare = dataShare.map((v: any) => ({
|
||||||
|
..._.omit(v, ["DivisionDocumentFolderFile"]),
|
||||||
|
id: v.DivisionDocumentFolderFile.id,
|
||||||
|
category: v.DivisionDocumentFolderFile.category,
|
||||||
|
name: v.DivisionDocumentFolderFile.name,
|
||||||
|
extension: v.DivisionDocumentFolderFile.extension,
|
||||||
|
path: v.DivisionDocumentFolderFile.path,
|
||||||
|
createdBy: v.DivisionDocumentFolderFile.User.name,
|
||||||
|
createdAt: moment(v.DivisionDocumentFolderFile.createdAt).format("DD-MM-YYYY HH:mm"),
|
||||||
|
updatedAt: moment(v.DivisionDocumentFolderFile.updatedAt).format("DD-MM-YYYY HH:mm"),
|
||||||
|
share: true
|
||||||
|
}))
|
||||||
|
|
||||||
|
} else {
|
||||||
|
kondisi = {
|
||||||
|
isActive: true,
|
||||||
|
path: (path == "undefined" || path == "null" || path == null) ? "home" : path
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -85,9 +173,15 @@ export async function GET(request: Request) {
|
|||||||
..._.omit(v, ["User", "createdAt", "updatedAt"]),
|
..._.omit(v, ["User", "createdAt", "updatedAt"]),
|
||||||
createdBy: v.User.name,
|
createdBy: v.User.name,
|
||||||
createdAt: moment(v.createdAt).format("DD-MM-YYYY HH:mm"),
|
createdAt: moment(v.createdAt).format("DD-MM-YYYY HH:mm"),
|
||||||
updatedAt: moment(v.updatedAt).format("DD-MM-YYYY HH:mm")
|
updatedAt: moment(v.updatedAt).format("DD-MM-YYYY HH:mm"),
|
||||||
|
share: false
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
if (formatDataShare.length > 0) {
|
||||||
|
allData.push(...formatDataShare)
|
||||||
|
}
|
||||||
|
|
||||||
|
const formatData = _.orderBy(allData, ['category', 'name'])
|
||||||
|
|
||||||
let pathNow = path
|
let pathNow = path
|
||||||
let jalur = []
|
let jalur = []
|
||||||
@@ -100,13 +194,14 @@ export async function GET(request: Request) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (dataPath) {
|
if (dataPath && (dataPath.idDivision == idDivision || path == pathNow || pathNow == aksesPath)) {
|
||||||
const fix = {
|
const fix = {
|
||||||
id: String(pathNow),
|
id: String(pathNow),
|
||||||
name: dataPath.name,
|
name: dataPath.name,
|
||||||
}
|
}
|
||||||
jalur.push(fix)
|
jalur.push(fix)
|
||||||
pathNow = dataPath.path
|
pathNow = dataPath.path
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
pathNow = "home"
|
pathNow = "home"
|
||||||
}
|
}
|
||||||
@@ -117,7 +212,7 @@ export async function GET(request: Request) {
|
|||||||
jalur.push({ id: 'home', name: 'home' })
|
jalur.push({ id: 'home', name: 'home' })
|
||||||
jalur = [...jalur].reverse()
|
jalur = [...jalur].reverse()
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan item", data: allData, jalur }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil mendapatkan item", data: formatData, jalur }, { status: 200 });
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export interface IDataDocument {
|
|||||||
extension: string;
|
extension: string;
|
||||||
category: string;
|
category: string;
|
||||||
path: string;
|
path: string;
|
||||||
|
share: boolean;
|
||||||
createdBy: string;
|
createdBy: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { LayoutDrawer, LayoutNavbarNew, WARNA } from '@/module/_global';
|
import { LayoutDrawer, LayoutNavbarNew, WARNA } from '@/module/_global';
|
||||||
import { ActionIcon, Anchor, Box, Breadcrumbs, Button, Checkbox, Divider, Flex, Grid, Group, Modal, Select, SimpleGrid, Text, TextInput } from '@mantine/core';
|
import { ActionIcon, Anchor, Box, Breadcrumbs, Button, Checkbox, Divider, Flex, Grid, Group, Indicator, Modal, Select, SimpleGrid, Text, TextInput } from '@mantine/core';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { HiMenu } from 'react-icons/hi';
|
import { HiMenu } from 'react-icons/hi';
|
||||||
import { FcDocument, FcFolder, FcImageFile } from 'react-icons/fc';
|
import { FcDocument, FcFolder, FcImageFile } from 'react-icons/fc';
|
||||||
@@ -23,6 +23,7 @@ import { globalRefreshDocument } from '../lib/val_document';
|
|||||||
import { RiListCheck } from 'react-icons/ri';
|
import { RiListCheck } from 'react-icons/ri';
|
||||||
import { GoChevronRight } from 'react-icons/go';
|
import { GoChevronRight } from 'react-icons/go';
|
||||||
import DrawerShareDocument from './drawer_share_document';
|
import DrawerShareDocument from './drawer_share_document';
|
||||||
|
import { FaSlideshare } from 'react-icons/fa6';
|
||||||
|
|
||||||
export default function NavbarDocumentDivision() {
|
export default function NavbarDocumentDivision() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -33,6 +34,7 @@ export default function NavbarDocumentDivision() {
|
|||||||
const [rename, setRename] = useState(false)
|
const [rename, setRename] = useState(false)
|
||||||
const [share, setShare] = useState(false)
|
const [share, setShare] = useState(false)
|
||||||
const [more, setMore] = useState(false)
|
const [more, setMore] = useState(false)
|
||||||
|
const [shareSelected, setShareSelected] = useState(false)
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const path = searchParams.get('path')
|
const path = searchParams.get('path')
|
||||||
const [dataDocument, setDataDocument] = useState<IDataDocument[]>([])
|
const [dataDocument, setDataDocument] = useState<IDataDocument[]>([])
|
||||||
@@ -62,6 +64,7 @@ export default function NavbarDocumentDivision() {
|
|||||||
path: dataDocument[index].path,
|
path: dataDocument[index].path,
|
||||||
extension: dataDocument[index].extension,
|
extension: dataDocument[index].extension,
|
||||||
category: dataDocument[index].category,
|
category: dataDocument[index].category,
|
||||||
|
share: dataDocument[index].share,
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
@@ -74,6 +77,13 @@ export default function NavbarDocumentDivision() {
|
|||||||
} else {
|
} else {
|
||||||
setSelectAll(false)
|
setSelectAll(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const shareSelected = selectedFiles.some((i: any) => i?.share == true)
|
||||||
|
if (shareSelected) {
|
||||||
|
setShareSelected(true)
|
||||||
|
} else {
|
||||||
|
setShareSelected(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSelectAll = () => {
|
const handleSelectAll = () => {
|
||||||
@@ -87,6 +97,7 @@ export default function NavbarDocumentDivision() {
|
|||||||
path: dataDocument[index].path,
|
path: dataDocument[index].path,
|
||||||
extension: dataDocument[index].extension,
|
extension: dataDocument[index].extension,
|
||||||
category: dataDocument[index].category,
|
category: dataDocument[index].category,
|
||||||
|
share: dataDocument[index].share,
|
||||||
}
|
}
|
||||||
setSelectedFiles((selectedFiles: any) => [...selectedFiles, newArr])
|
setSelectedFiles((selectedFiles: any) => [...selectedFiles, newArr])
|
||||||
}
|
}
|
||||||
@@ -154,6 +165,8 @@ export default function NavbarDocumentDivision() {
|
|||||||
setDataJalur(respon.jalur);
|
setDataJalur(respon.jalur);
|
||||||
} else {
|
} else {
|
||||||
toast.error(respon.message);
|
toast.error(respon.message);
|
||||||
|
setDataDocument([]);
|
||||||
|
setDataJalur([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await funGetDivisionById(param.id);
|
const res = await funGetDivisionById(param.id);
|
||||||
@@ -231,24 +244,24 @@ export default function NavbarDocumentDivision() {
|
|||||||
<Text fz={12} c={(selectedFiles.length > 0) ? 'white' : 'grey'}>Unduh</Text>
|
<Text fz={12} c={(selectedFiles.length > 0) ? 'white' : 'grey'}>Unduh</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Flex onClick={() => setIsDelete(true)} justify={'center'} align={'center'} direction={'column'}>
|
<Flex onClick={() => setIsDelete(true)} justify={'center'} align={'center'} direction={'column'}>
|
||||||
<AiOutlineDelete size={20} color={(selectedFiles.length > 0) ? 'white' : 'grey'} />
|
<AiOutlineDelete size={20} color={(selectedFiles.length > 0 && !shareSelected) ? 'white' : 'grey'} />
|
||||||
<Text fz={12} c={(selectedFiles.length > 0) ? 'white' : 'grey'}>Hapus</Text>
|
<Text fz={12} c={(selectedFiles.length > 0 && !shareSelected) ? 'white' : 'grey'}>Hapus</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Flex onClick={() => {
|
<Flex onClick={() => {
|
||||||
if (selectedFiles.length == 1) {
|
if (selectedFiles.length == 1) {
|
||||||
onChooseRename()
|
onChooseRename()
|
||||||
}
|
}
|
||||||
}} justify={'center'} align={'center'} direction={'column'}>
|
}} justify={'center'} align={'center'} direction={'column'}>
|
||||||
<CgRename size={20} color={(selectedFiles.length == 1) ? 'white' : 'grey'} />
|
<CgRename size={20} color={(selectedFiles.length == 1 && !shareSelected) ? 'white' : 'grey'} />
|
||||||
<Text fz={12} c={(selectedFiles.length == 1) ? 'white' : 'grey'}>Ganti Nama</Text>
|
<Text fz={12} c={(selectedFiles.length == 1 && !shareSelected) ? 'white' : 'grey'}>Ganti Nama</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Flex onClick={() => setShare(true)} justify={'center'} align={'center'} direction={'column'}>
|
<Flex onClick={() => setShare(true)} justify={'center'} align={'center'} direction={'column'}>
|
||||||
<LuShare2 size={20} color={(selectedFiles.length > 0) ? 'white' : 'grey'} />
|
<LuShare2 size={20} color={(selectedFiles.length > 0 && !shareSelected) ? 'white' : 'grey'} />
|
||||||
<Text fz={12} c={(selectedFiles.length > 0) ? 'white' : 'grey'}>Bagikan</Text>
|
<Text fz={12} c={(selectedFiles.length > 0 && !shareSelected) ? 'white' : 'grey'}>Bagikan</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Flex onClick={() => setMore(true)} justify={'center'} align={'center'} direction={'column'}>
|
<Flex onClick={() => setMore(true)} justify={'center'} align={'center'} direction={'column'}>
|
||||||
<MdOutlineMoreHoriz size={20} color={(selectedFiles.length > 0) ? 'white' : 'grey'} />
|
<MdOutlineMoreHoriz size={20} color={(selectedFiles.length > 0 && !shareSelected) ? 'white' : 'grey'} />
|
||||||
<Text fz={12} c={(selectedFiles.length > 0) ? 'white' : 'grey'}>Lainnya</Text>
|
<Text fz={12} c={(selectedFiles.length > 0 && !shareSelected) ? 'white' : 'grey'}>Lainnya</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
</SimpleGrid>
|
</SimpleGrid>
|
||||||
</Flex>
|
</Flex>
|
||||||
@@ -295,12 +308,29 @@ export default function NavbarDocumentDivision() {
|
|||||||
<Group gap={20}>
|
<Group gap={20}>
|
||||||
<Box>
|
<Box>
|
||||||
{
|
{
|
||||||
(v.category == "FOLDER") ?
|
(v.share) ?
|
||||||
<FcFolder size={60} /> :
|
<Indicator offset={15} withBorder inline color={WARNA.borderBiruMuda} position="bottom-end" label={<FaSlideshare />} size={25}>
|
||||||
(v.extension == "pdf" || v.extension == "csv") ?
|
{
|
||||||
<FcDocument size={60} /> :
|
(v.category == "FOLDER") ?
|
||||||
<FcImageFile size={60} />
|
<FcFolder size={60} /> :
|
||||||
|
(v.extension == "pdf" || v.extension == "csv") ?
|
||||||
|
<FcDocument size={60} /> :
|
||||||
|
<FcImageFile size={60} />
|
||||||
|
}
|
||||||
|
</Indicator>
|
||||||
|
:
|
||||||
|
<>
|
||||||
|
{
|
||||||
|
(v.category == "FOLDER") ?
|
||||||
|
<FcFolder size={60} /> :
|
||||||
|
(v.extension == "pdf" || v.extension == "csv") ?
|
||||||
|
<FcDocument size={60} /> :
|
||||||
|
<FcImageFile size={60} />
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
<Flex direction={'column'}>
|
<Flex direction={'column'}>
|
||||||
<Text>{(v.category == "FOLDER") ? v.name : v.name + '.' + v.extension}</Text>
|
<Text>{(v.category == "FOLDER") ? v.name : v.name + '.' + v.extension}</Text>
|
||||||
|
|||||||
Reference in New Issue
Block a user