Added filter search

This commit is contained in:
Patrick Alvin Alcala 2025-10-30 16:33:54 +08:00
parent 596c11cd23
commit 6a5ef64d35

View file

@ -3,7 +3,7 @@ import { Logo, Page, Row, Padding, ModalButton, Button, Clickable, Link, Modal,
import { FiLogOut } from 'solid-icons/fi' import { FiLogOut } from 'solid-icons/fi'
import { Tabs } from '@kobalte/core/tabs' import { Tabs } from '@kobalte/core/tabs'
import { ofetch } from 'ofetch' import { ofetch } from 'ofetch'
import { onMount, createSignal, Show } from 'solid-js' import { onMount, createSignal, Show, createEffect } from 'solid-js'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { checkConnection, createPdf } from '../../utils/functions' import { checkConnection, createPdf } from '../../utils/functions'
import { FaSolidThumbsUp } from 'solid-icons/fa' import { FaSolidThumbsUp } from 'solid-icons/fa'
@ -55,18 +55,18 @@ export default () => {
} }
} }
const handleFilterChange = (value: string) => { // const handleFilterChange = (value: string) => {
// setFilter(value) // // setFilter(value)
if (value.trim() === '') { // if (value.trim() === '') {
setApplicationList(fullIDList()) // setApplicationList(fullIDList())
setNameList(fullNameList()) // setNameList(fullNameList())
} else { // } else {
const filteredApplications = fullIDList().filter((app) => app.toLowerCase().includes(value.toLowerCase())) // const filteredApplications = fullIDList().filter((app) => app.toLowerCase().includes(value.toLowerCase()))
const filteredNames = fullNameList().slice(0, filteredApplications.length) // const filteredNames = fullNameList().slice(0, filteredApplications.length)
setApplicationList(filteredApplications) // setApplicationList(filteredApplications)
setNameList(filteredNames) // setNameList(filteredNames)
} // }
} // }
const getPrintDetails = async (id: number) => { const getPrintDetails = async (id: number) => {
const response = await ofetch(API + 'get-printdetails-electrical/' + id) const response = await ofetch(API + 'get-printdetails-electrical/' + id)
@ -161,8 +161,8 @@ export default () => {
const approversignId = await geteSignId(276) const approversignId = await geteSignId(276)
getApprovedDate(approversignId, applicationNo) getApprovedDate(approversignId, applicationNo)
const assessorId = await getEmployeeId(op.result7[0]) // const assessorId = await getEmployeeId(op.result7[0])
const assessorsignId = await geteSignId(assessorId) // const assessorsignId = await geteSignId(assessorId)
getAssessedDate(op.result11[0]) getAssessedDate(op.result11[0])
} }
@ -171,22 +171,20 @@ export default () => {
return total return total
} }
const getListForPrinting = async (query?: string) => { const getListForPrinting = async () => {
try { try {
const response = await ofetch(API + 'get-listopprinting-electrical', { parseResponse: JSON.parse }) const response = await ofetch(API + 'get-listopprinting-electrical', { parseResponse: JSON.parse })
const filteredApplications = response.result.filter((item: any) =>
item if (filter() !== '' && filter().trim().length !== 0) {
.toString() const filteredApplications = response.result.filter((item: string) => item.includes(filter()))
.toLowerCase() const filteredIndices = response.result.map((item: string, index: number) => (item.includes(filter()) ? index : -1)).filter((index: number) => index !== -1)
.includes((query ?? '').toLowerCase()) const filteredNames = filteredIndices.map((index: number) => response.result2[index])
)
const filteredNames = response.result2.filter((item: any) =>
item.toString().toLowerCase().includes((query ?? '').toLowerCase())
)
// setApplicationList(response.result)
// setNameList(response.result2)
setApplicationList(filteredApplications) setApplicationList(filteredApplications)
setNameList(filteredNames) setNameList(filteredNames)
return
}
setApplicationList(response.result)
setNameList(response.result2)
} catch (error) { } catch (error) {
console.error(error) console.error(error)
} }
@ -352,6 +350,14 @@ export default () => {
} }
}) })
createEffect(async () => {
if (filter() !== '') {
await getListForPrinting()
} else if (filter() === '') {
await getListForPrinting()
}
})
return ( return (
<> <>
<Page alignment="column"> <Page alignment="column">
@ -451,7 +457,7 @@ export default () => {
<Padding top={0} bottom={0} right={10} left={10}> <Padding top={0} bottom={0} right={10} left={10}>
<Row content="split"> <Row content="split">
<Input label="aa" value={filter()} onChange={getListForPrinting} /> <Input value={filter()} onChange={setFilter} placeholder="Filter Application Number" />
<Button label="Refresh Data" edges="curved" design="bo-primary" icon={VsRefresh} onClick={refresh}></Button> <Button label="Refresh Data" edges="curved" design="bo-primary" icon={VsRefresh} onClick={refresh}></Button>
</Row> </Row>
</Padding> </Padding>