impl get position over detail divions

wip: detail division

for entry new division position

finish v1 divison-position
This commit is contained in:
Khafid Prayoga
2025-10-24 12:48:05 +07:00
parent 1042fd4923
commit df27262bd1
13 changed files with 675 additions and 6 deletions
@@ -0,0 +1,192 @@
<script setup lang="ts">
// Components
import Block from '~/components/pub/my-ui/doc-entry/block.vue'
import Cell from '~/components/pub/my-ui/doc-entry/cell.vue'
import Field from '~/components/pub/my-ui/doc-entry/field.vue'
import Label from '~/components/pub/my-ui/doc-entry/label.vue'
import Combobox from '~/components/pub/my-ui/combobox/combobox.vue'
// Types
import type { DivisionPositionFormData } from '~/schemas/division-position.schema'
// Helpers
import type z from 'zod'
import { toTypedSchema } from '@vee-validate/zod'
import { useForm } from 'vee-validate'
import { genBase } from '~/models/_base'
import { genDivisionPosition } from '~/models/division-position'
interface Props {
schema: z.ZodSchema<any>
divisionId: number
employees: any[]
values: any
isLoading?: boolean
isReadonly?: boolean
}
const props = defineProps<Props>()
const isLoading = props.isLoading !== undefined ? props.isLoading : false
const isReadonly = props.isReadonly !== undefined ? props.isReadonly : false
const emit = defineEmits<{
submit: [values: DivisionPositionFormData, resetForm: () => void]
cancel: [resetForm: () => void]
}>()
const { defineField, errors, meta } = useForm({
validationSchema: toTypedSchema(props.schema),
initialValues: genDivisionPosition() as Partial<DivisionPositionFormData>,
})
const [code, codeAttrs] = defineField('code')
const [name, nameAttrs] = defineField('name')
const [employee, employeeAttrs] = defineField('employee_id')
const [headStatus, headStatusAttrs] = defineField('headStatus')
// RadioGroup uses string values; expose a string computed that maps to the boolean field
const headStatusStr = computed<string>({
get() {
if (headStatus.value === true) return 'true'
if (headStatus.value === false) return 'false'
return ''
},
set(v: string) {
if (v === 'true') headStatus.value = true
else if (v === 'false') headStatus.value = false
else headStatus.value = undefined
},
})
// Fill fields from props.values if provided
if (props.values) {
if (props.values.code !== undefined) code.value = props.values.code
if (props.values.name !== undefined) name.value = props.values.name
if (props.values.employee_id !== undefined)
employee.value = props.values.employee_id ? Number(props.values.employee_id) : null
if (props.values.headStatus !== undefined) headStatus.value = !!props.values.headStatus
}
const resetForm = () => {
code.value = ''
name.value = ''
employee.value = null
headStatus.value = false
}
// Form submission handler
function onSubmitForm() {
const formData: DivisionPositionFormData = {
...genBase(),
name: name.value || '',
code: code.value || '',
// readonly based on detail division
division_id: props.divisionId,
employee_id: employee.value || null,
headStatus: headStatus.value !== undefined ? headStatus.value : undefined,
}
emit('submit', formData, resetForm)
}
// Form cancel handler
function onCancelForm() {
emit('cancel', resetForm)
}
</script>
<template>
<form
id="form-division-position"
@submit.prevent
>
<Block
labelSize="thin"
class="!mb-2.5 !pt-0 xl:!mb-3"
:colCount="1"
>
<Cell>
<Label height="compact">Kode Jabatan</Label>
<Field :errMessage="errors.code">
<Input
id="code"
v-model="code"
v-bind="codeAttrs"
:disabled="isLoading || isReadonly"
/>
</Field>
</Cell>
<Cell>
<Label height="compact">Nama Jabatan</Label>
<Field :errMessage="errors.name">
<Input
id="name"
v-model="name"
v-bind="nameAttrs"
:disabled="isLoading || isReadonly"
/>
</Field>
</Cell>
<Cell>
<Label height="compact">Pengisi Jabatan</Label>
<Field :errMessage="errors.employee_id">
<Combobox
id="employee"
v-model="employee"
v-bind="employeeAttrs"
:items="employees"
:is-disabled="isLoading || isReadonly"
placeholder="Pilih Karyawan"
search-placeholder="Cari Karyawan"
empty-message="Item tidak ditemukan"
/>
</Field>
</Cell>
<Cell>
<Label height="compact">Status Kepala</Label>
<Field :errMessage="errors.headStatus">
<RadioGroup
v-model="headStatusStr"
v-bind="headStatusAttrs"
class="flex gap-4"
>
<div class="flex items-center space-x-2">
<RadioGroupItem
id="head-yes"
value="true"
/>
<Label for="head-yes">Ya</Label>
</div>
<div class="flex items-center space-x-2">
<RadioGroupItem
id="head-no"
value="false"
/>
<Label for="head-no">Tidak</Label>
</div>
</RadioGroup>
</Field>
</Cell>
</Block>
<div class="my-2 flex justify-end gap-2 py-2">
<Button
type="button"
variant="secondary"
class="w-[120px]"
@click="onCancelForm"
>
Kembali
</Button>
<Button
v-if="!isReadonly"
type="button"
class="w-[120px]"
:disabled="isLoading || !meta.valid"
@click="onSubmitForm"
>
Simpan
</Button>
</div>
</form>
</template>
@@ -0,0 +1,34 @@
<script setup lang="ts">
import type { Division } from '~/models/division'
import DetailRow from '~/components/pub/my-ui/form/view/detail-row.vue'
// #region Props & Emits
defineProps<{
division: Division
}>()
// #endregion
// #region State & Computed
// #region Lifecycle Hooks
// #endregion
// #region Functions
// #endregion region
// #region Utilities & event handlers
// #endregion
// #region Watchers
// #endregion
</script>
<template>
<DetailRow label="Kode">{{ division.code || '-' }}</DetailRow>
<DetailRow label="Nama">{{ division.name || '-' }}</DetailRow>
</template>
<style scoped></style>
@@ -0,0 +1,62 @@
import type { Config, RecComponent } from '~/components/pub/my-ui/data-table'
import { defineAsyncComponent } from 'vue'
import type { DivisionPosition } from '~/models/division-position'
type SmallDetailDto = any
const action = defineAsyncComponent(() => import('~/components/pub/my-ui/data/dropdown-action-ud.vue'))
export const config: Config = {
cols: [{}, {}, {}, {}, {}, { width: 50 }],
headers: [
[
{ label: 'Kode Jabatan' },
{ label: 'Nama Jabatan' },
{ label: 'Pengisi Jabatan' },
{ label: 'Status Kepala' },
{ label: '' },
],
],
keys: ['code', 'name', 'employee', 'head', 'action'],
delKeyNames: [
{ key: 'code', label: 'Kode' },
{ key: 'name', label: 'Nama' },
],
parses: {
division: (rec: unknown): unknown => {
const recX = rec as SmallDetailDto
return recX.division?.name || '-'
},
employee: (rec: unknown): unknown => {
const recX = rec as DivisionPosition
const fullName =
`${recX.employee?.person.frontTitle} ${recX.employee?.person.name} ${recX.employee?.person.endTitle}`.trim()
return fullName || '-'
},
head: (rec: unknown): unknown => {
const recX = rec as SmallDetailDto
return recX.headStatus ? 'Ya' : 'Tidak'
},
},
components: {
action(rec, idx) {
const res: RecComponent = {
idx,
rec: rec as object,
component: action,
props: {
size: 'sm',
},
}
return res
},
},
htmls: {},
}
@@ -0,0 +1,39 @@
<script setup lang="ts">
// Components
import PaginationView from '~/components/pub/my-ui/pagination/pagination-view.vue'
// Types
import type { PaginationMeta } from '~/components/pub/my-ui/pagination/pagination.type'
// Configs
import { config } from './list-cfg'
interface Props {
data: any[]
paginationMeta: PaginationMeta
}
defineProps<Props>()
const emit = defineEmits<{
pageChange: [page: number]
}>()
function handlePageChange(page: number) {
emit('pageChange', page)
}
</script>
<template>
<div class="space-y-4">
<PubMyUiDataTable
v-bind="config"
:rows="data"
:skeleton-size="paginationMeta?.pageSize"
/>
<PaginationView
:pagination-meta="paginationMeta"
@page-change="handlePageChange"
/>
</div>
</template>
+214
View File
@@ -0,0 +1,214 @@
<script setup lang="ts">
import { ActionEvents, type HeaderPrep } from '~/components/pub/my-ui/data/types'
import RecordConfirmation from '~/components/pub/my-ui/confirmation/record-confirmation.vue'
// Components
import Header from '~/components/pub/my-ui/nav-header/prep.vue'
// Service
import type { Division } from '~/models/division'
import { getDetail as getDetailDivision } from '~/services/division.service'
// #region division positions
import { config } from '~/components/app/division/detail/list-cfg'
// Helpers
import { usePaginatedList } from '~/composables/usePaginatedList'
import { toast } from '~/components/pub/ui/toast'
import Dialog from '~/components/pub/my-ui/modal/dialog.vue'
// Types
import { DivisionPositionSchema, type DivisionPositionFormData } from '~/schemas/division-position.schema'
// Handlers
import {
recId,
recAction,
recItem,
isReadonly,
isProcessing,
isFormEntryDialogOpen,
isRecordConfirmationOpen,
onResetState,
handleActionSave,
handleActionEdit,
handleActionRemove,
handleCancelForm,
} from '~/handlers/division-position.handler'
// Services
import { getList, getDetail as getDetailDivisionPosition } from '~/services/division-position.service'
import { getValueLabelList as getEmployeeLabelList } from '~/services/employee.service'
const employees = ref<{ value: string | number; label: string }[]>([])
const title = ref('')
// #endregion
// #region Props & Emits
const props = defineProps<{
divisionId: number
}>()
const division = ref<Division>({} as Division)
// #endregion
// #region State & Computed
const {
data,
isLoading,
paginationMeta,
searchInput,
handlePageChange,
handleSearch,
fetchData: getDivisionPositionList,
} = usePaginatedList({
fetchFn: async (params: any) => {
const result = await getList({
'division-id': props.divisionId,
includes: 'Employee.Person',
search: params.search,
sort: 'createdAt:asc',
'page-number': params['page-number'] || 0,
'page-size': params['page-size'] || 10,
})
return { success: result.success || false, body: result.body || {} }
},
entityName: 'division-position',
})
const headerPrep: HeaderPrep = {
title: 'Detail Divisi',
icon: 'i-lucide-user',
refSearchNav: {
placeholder: 'Cari (min. 3 karakter)...',
minLength: 3,
debounceMs: 500,
showValidationFeedback: true,
onInput: (value: string) => {
searchInput.value = value
},
onClick: () => {},
onClear: () => {},
},
addNav: {
label: 'Tambah Jabatan',
icon: 'i-lucide-plus',
onClick: () => {
recItem.value = null
recId.value = 0
isFormEntryDialogOpen.value = true
isReadonly.value = false
},
},
}
// #endregion
// #region Lifecycle Hooks
onMounted(async () => {
const result = await getDetailDivision(props.divisionId)
if (result.success) {
division.value = result.body.data || {}
}
employees.value = await getEmployeeLabelList({ sort: 'createdAt:asc', 'page-size': 100, includes: 'person' })
})
// #endregion
// #region Functions
// #endregion region
// #region Utilities & event handlers
// #endregion
// #region Watchers
// #endregion
provide('rec_id', recId)
provide('rec_action', recAction)
provide('rec_item', recItem)
provide('table_data_loader', isLoading)
// Watch for row actions when recId or recAction changes
watch([recId, recAction], () => {
console.log(recId, recAction)
switch (recAction.value) {
case ActionEvents.showEdit:
getDetailDivisionPosition(recId.value)
title.value = 'Edit Jabatan'
isReadonly.value = false
isFormEntryDialogOpen.value = true
break
case ActionEvents.showConfirmDelete:
isRecordConfirmationOpen.value = true
break
}
})
</script>
<template>
<Header
:prep="headerPrep"
:ref-search-nav="headerPrep.refSearchNav"
/>
<AppDivisionDetail :division="division" />
<div class="h-6"></div>
<LazyAppDivisionDetailList
:data="data"
:pagination-meta="paginationMeta"
@page-change="handlePageChange"
/>
<Dialog
v-model:open="isFormEntryDialogOpen"
:title="!!recItem ? title : 'Tambah Jabatan'"
size="lg"
prevent-outside
@update:open="
(value: any) => {
onResetState()
isFormEntryDialogOpen = value
}
"
>
<AppDivisionPositionEntry
:schema="DivisionPositionSchema"
:division-id="divisionId"
:employees="employees"
:values="recItem"
:is-loading="isProcessing"
:is-readonly="isReadonly"
@submit="
(values: DivisionPositionFormData | Record<string, any>, resetForm: () => void) => {
console.log(values)
if (recId > 0) {
handleActionEdit(recId, values, getDivisionPositionList, onResetState, toast)
return
}
handleActionSave(values, getDivisionPositionList, onResetState, toast)
}
"
@cancel="handleCancelForm"
/>
</Dialog>
<RecordConfirmation
v-model:open="isRecordConfirmationOpen"
action="delete"
:record="recItem"
@confirm="() => handleActionRemove(recId, getDivisionPositionList, toast)"
@cancel=""
>
<template #default="{ record }">
<div class="space-y-1 text-sm">
<p
v-for="field in config.delKeyNames"
:key="field.key"
:v-if="record?.[field.key]"
>
<span class="font-semibold">{{ field.label }}:</span>
{{ record[field.key] }}
</p>
</div>
</template>
</RecordConfirmation>
</template>
+3 -1
View File
@@ -1,11 +1,13 @@
import { type Base, genBase } from './_base'
import type { Employee } from './employee'
export interface DivisionPosition extends Base {
code: string
name: string
headStatus?: boolean
division_id: number
employee_id?: number
employee?: Employee | null
}
export function genDivisionPosition(): DivisionPosition {
+5 -2
View File
@@ -1,10 +1,13 @@
import { type Base, genBase } from "./_base"
import { type Base, genBase } from './_base'
import type { DivisionPosition } from './division-position'
export interface Division extends Base {
code: string
name: string
parent_id?: number | null
childrens?: Division[] | null
// preload
divisionPosition?: DivisionPosition[] | null
}
export function genDivision(): Division {
+20
View File
@@ -0,0 +1,20 @@
import { type Base, genBase } from './_base'
export interface InstallationPosition extends Base {
installation_id: number
code: string
name: string
headStatus?: boolean
employee_id?: number
}
export function genInstallationPosition(): InstallationPosition {
return {
...genBase(),
installation_id: 0,
code: '',
name: '',
headStatus: false,
employee_id: 0,
}
}
+20
View File
@@ -0,0 +1,20 @@
import { type Base, genBase } from './_base'
export interface SpecialistPosition extends Base {
specialist_id: number
code: string
name: string
headStatus?: boolean
employee_id?: number
}
export function genSpecialistPosition(): SpecialistPosition {
return {
...genBase(),
specialist_id: 0,
code: '',
name: '',
headStatus: false,
employee_id: 0,
}
}
+20
View File
@@ -0,0 +1,20 @@
import { type Base, genBase } from './_base'
export interface SubSpecialistPosition extends Base {
subspecialist_id: number
code: string
name: string
headStatus?: boolean
employee_id?: number
}
export function genSubSpecialistPosition(): SubSpecialistPosition {
return {
...genBase(),
subspecialist_id: 0,
code: '',
name: '',
headStatus: false,
employee_id: 0,
}
}
+20
View File
@@ -0,0 +1,20 @@
import { type Base, genBase } from './_base'
export interface UnitPosition extends Base {
unit_id: number
code: string
name: string
headStatus?: boolean
employee_id?: number
}
export function genUnitPosition(): UnitPosition {
return {
...genBase(),
unit_id: 0,
code: '',
name: '',
headStatus: false,
employee_id: 0,
}
}
@@ -0,0 +1,42 @@
<script setup lang="ts">
// import type { PagePermission } from '~/models/role'
import Error from '~/components/pub/my-ui/error/error.vue'
// import { PAGE_PERMISSIONS } from '~/lib/page-permission'
definePageMeta({
// middleware: ['rbac'],
roles: ['doctor', 'nurse', 'admisi', 'pharmacy', 'billing', 'management'],
title: 'Detail Divisi',
contentFrame: 'cf-container-lg',
})
const route = useRoute()
useHead({
title: () => route.meta.title as string,
})
// const roleAccess: PagePermission = PAGE_PERMISSIONS['/patient']
// const { checkRole, hasReadAccess } = useRBAC()
// // Check if user has access to this page
// const hasAccess = checkRole(roleAccess)
// if (!hasAccess) {
// navigateTo('/403')
// }
// Define permission-based computed properties
// const canRead = hasReadAccess(roleAccess)
const canRead = true
</script>
<template>
<template v-if="canRead">
<ContentDivisionDetail :division-id="Number(route.params.id)" />
</template>
<Error
v-else
:status-code="403"
/>
</template>
+4 -3
View File
@@ -1,4 +1,5 @@
// Base
import type { Employee } from '~/models/employee'
import * as base from './_crud-base'
const path = '/api/v1/employee'
@@ -29,9 +30,9 @@ export async function getValueLabelList(params: any = null): Promise<{ value: st
const result = await getList(params)
if (result.success) {
const resultData = result.body?.data || []
data = resultData.map((item: any) => ({
value: item.id ? Number(item.id) : item.code,
label: item.name,
data = resultData.map((item: Employee) => ({
value: item.id,
label: `${item.person.frontTitle} ${item.person.name} ${item.person.endTitle}`.trim(),
}))
}
return data