Merge pull request #142 from bipproduction/amalia/23-agustus-24

upd: document
This commit is contained in:
Amalia
2024-08-23 12:32:40 +08:00
committed by GitHub
3 changed files with 146 additions and 20 deletions

View File

@@ -30,16 +30,56 @@ export async function GET(request: Request) {
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 != "") {
const cekPath = await prisma.divisionDocumentFolderFile.count({
where: {
isActive: true,
id: String(path)
id: String(path),
idDivision: String(idDivision)
}
})
if (cekPath == 0) {
return NextResponse.json({ success: false, message: "Gagal mendapatkan item, data tidak ditemukan" }, { status: 404 });
const cekSharePath = await prisma.divisionDocumentShare.count({
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
}
let formatDataShare: any[] = [];
if (category == "folder") {
kondisi = {
isActive: true,
@@ -57,6 +99,52 @@ export async function GET(request: Request) {
path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path,
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"]),
createdBy: v.User.name,
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 jalur = []
@@ -100,13 +194,14 @@ export async function GET(request: Request) {
}
})
if (dataPath) {
if (dataPath && (dataPath.idDivision == idDivision || path == pathNow || pathNow == aksesPath)) {
const fix = {
id: String(pathNow),
name: dataPath.name,
}
jalur.push(fix)
pathNow = dataPath.path
} else {
pathNow = "home"
}
@@ -117,7 +212,7 @@ export async function GET(request: Request) {
jalur.push({ id: 'home', name: 'home' })
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) {
console.log(error);

View File

@@ -4,6 +4,7 @@ export interface IDataDocument {
extension: string;
category: string;
path: string;
share: boolean;
createdBy: string;
createdAt: string;
updatedAt: string;

View File

@@ -1,6 +1,6 @@
'use client'
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 { HiMenu } from 'react-icons/hi';
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 { GoChevronRight } from 'react-icons/go';
import DrawerShareDocument from './drawer_share_document';
import { FaSlideshare } from 'react-icons/fa6';
export default function NavbarDocumentDivision() {
const router = useRouter()
@@ -33,6 +34,7 @@ export default function NavbarDocumentDivision() {
const [rename, setRename] = useState(false)
const [share, setShare] = useState(false)
const [more, setMore] = useState(false)
const [shareSelected, setShareSelected] = useState(false)
const searchParams = useSearchParams()
const path = searchParams.get('path')
const [dataDocument, setDataDocument] = useState<IDataDocument[]>([])
@@ -62,6 +64,7 @@ export default function NavbarDocumentDivision() {
path: dataDocument[index].path,
extension: dataDocument[index].extension,
category: dataDocument[index].category,
share: dataDocument[index].share,
}
])
}
@@ -74,6 +77,13 @@ export default function NavbarDocumentDivision() {
} else {
setSelectAll(false)
}
const shareSelected = selectedFiles.some((i: any) => i?.share == true)
if (shareSelected) {
setShareSelected(true)
} else {
setShareSelected(false)
}
}
const handleSelectAll = () => {
@@ -87,6 +97,7 @@ export default function NavbarDocumentDivision() {
path: dataDocument[index].path,
extension: dataDocument[index].extension,
category: dataDocument[index].category,
share: dataDocument[index].share,
}
setSelectedFiles((selectedFiles: any) => [...selectedFiles, newArr])
}
@@ -154,6 +165,8 @@ export default function NavbarDocumentDivision() {
setDataJalur(respon.jalur);
} else {
toast.error(respon.message);
setDataDocument([]);
setDataJalur([]);
}
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>
</Flex>
<Flex onClick={() => setIsDelete(true)} justify={'center'} align={'center'} direction={'column'}>
<AiOutlineDelete size={20} color={(selectedFiles.length > 0) ? 'white' : 'grey'} />
<Text fz={12} c={(selectedFiles.length > 0) ? 'white' : 'grey'}>Hapus</Text>
<AiOutlineDelete size={20} color={(selectedFiles.length > 0 && !shareSelected) ? 'white' : 'grey'} />
<Text fz={12} c={(selectedFiles.length > 0 && !shareSelected) ? 'white' : 'grey'}>Hapus</Text>
</Flex>
<Flex onClick={() => {
if (selectedFiles.length == 1) {
onChooseRename()
}
}} justify={'center'} align={'center'} direction={'column'}>
<CgRename size={20} color={(selectedFiles.length == 1) ? 'white' : 'grey'} />
<Text fz={12} c={(selectedFiles.length == 1) ? 'white' : 'grey'}>Ganti Nama</Text>
<CgRename size={20} color={(selectedFiles.length == 1 && !shareSelected) ? 'white' : 'grey'} />
<Text fz={12} c={(selectedFiles.length == 1 && !shareSelected) ? 'white' : 'grey'}>Ganti Nama</Text>
</Flex>
<Flex onClick={() => setShare(true)} justify={'center'} align={'center'} direction={'column'}>
<LuShare2 size={20} color={(selectedFiles.length > 0) ? 'white' : 'grey'} />
<Text fz={12} c={(selectedFiles.length > 0) ? 'white' : 'grey'}>Bagikan</Text>
<LuShare2 size={20} color={(selectedFiles.length > 0 && !shareSelected) ? 'white' : 'grey'} />
<Text fz={12} c={(selectedFiles.length > 0 && !shareSelected) ? 'white' : 'grey'}>Bagikan</Text>
</Flex>
<Flex onClick={() => setMore(true)} justify={'center'} align={'center'} direction={'column'}>
<MdOutlineMoreHoriz size={20} color={(selectedFiles.length > 0) ? 'white' : 'grey'} />
<Text fz={12} c={(selectedFiles.length > 0) ? 'white' : 'grey'}>Lainnya</Text>
<MdOutlineMoreHoriz size={20} color={(selectedFiles.length > 0 && !shareSelected) ? 'white' : 'grey'} />
<Text fz={12} c={(selectedFiles.length > 0 && !shareSelected) ? 'white' : 'grey'}>Lainnya</Text>
</Flex>
</SimpleGrid>
</Flex>
@@ -295,12 +308,29 @@ export default function NavbarDocumentDivision() {
<Group gap={20}>
<Box>
{
(v.category == "FOLDER") ?
<FcFolder size={60} /> :
(v.extension == "pdf" || v.extension == "csv") ?
<FcDocument size={60} /> :
<FcImageFile size={60} />
(v.share) ?
<Indicator offset={15} withBorder inline color={WARNA.borderBiruMuda} position="bottom-end" label={<FaSlideshare />} size={25}>
{
(v.category == "FOLDER") ?
<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>
<Flex direction={'column'}>
<Text>{(v.category == "FOLDER") ? v.name : v.name + '.' + v.extension}</Text>