Skip to content

Commit

Permalink
Implement real API calls, update forms and lists, add PositionList co…
Browse files Browse the repository at this point in the history
…mponent.
  • Loading branch information
kneoio committed Jul 25, 2024
1 parent bb7c96a commit 4cfc30f
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 15 deletions.
10 changes: 2 additions & 8 deletions src/components/forms/EmployeeForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<n-form-item label="Position">
<n-select
v-model:value="localFormData.position.id"
:options="categoryOptions"
:options="positionStore.getOptions"
style="width: 50%; max-width: 600px;"
/>
</n-form-item>
Expand Down Expand Up @@ -121,12 +121,6 @@ export default defineComponent({
phone: '',
rank: 0
});
const categoryOptions = computed(() =>
positionStore.getEntries.map(d => ({
label: d.identifier,
value: d.id
}))
);
const handleSave = async () => {
loadingBar.start();
Expand Down Expand Up @@ -186,12 +180,12 @@ export default defineComponent({
return {
store,
positionStore,
localFormData,
handleSave,
handleArchive,
activeTab,
goBack,
categoryOptions
};
},
});
Expand Down
4 changes: 3 additions & 1 deletion src/components/lists/EmployeeList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export default defineComponent({
return false;
}
},
{ title: 'Name', key: 'identifier' },
{ title: 'Name', key: 'localizedName.ENG' },
{ title: 'Identifier', key: 'identifier' },
{ title: 'Position', key: 'position.localizedName.ENG' },
{ title: 'Registered', key: 'regDate' }
]);
Expand Down
160 changes: 160 additions & 0 deletions src/components/lists/PositionList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<template>
<n-grid cols="24" x-gap="12" y-gap="12" class="p-4">
<n-gi>
<n-page-header>
<template #title>Positions</template>
<template #footer>
Total: {{ store.getPagination.itemCount }}
</template>
</n-page-header>
</n-gi>
<n-gi span="24">
<n-button-group>
<n-button @click="handleNewClick" type="primary" size="large">New</n-button>
<n-button @click="handleArchive" size="large" :disabled="!selectedRows.length">Archive</n-button>
</n-button-group>
</n-gi>
<n-gi span="24">
<n-data-table
remote
:columns="columns"
:row-key="rowKey"
:data="store.getEntries"
:pagination="store.getPagination"
:bordered="false"
:row-props="getRowProps"
@update:page="handlePageChange"
@update:page-size="handlePageSizeChange"
@update:checked-row-keys="handleCheckedRowKeysChange"

Check failure on line 28 in src/components/lists/PositionList.vue

View workflow job for this annotation

GitHub Actions / deploy

Type '(keys: string[]) => void' is not assignable to type 'MaybeArray<OnUpdateCheckedRowKeys> | undefined'.
/>
</n-gi>
</n-grid>
</template>

<script lang="ts">
import {computed, defineComponent, onMounted, ref} from 'vue';
import {
DataTableColumns,
NButton,
NButtonGroup,
NDataTable,
NGi,
NGrid,
NH2,
NPageHeader,
NPagination,
NSpace,
useMessage
} from 'naive-ui';
import {useRouter} from 'vue-router';
import {usePositionStore} from "../../stores/of/positionStore";
import {Position} from "../../types/officeFrameTypes";
export default defineComponent({
components: {NPageHeader, NSpace, NH2, NDataTable, NPagination, NButtonGroup, NButton, NGi, NGrid},
setup() {
const router = useRouter();
const msgPopup = useMessage();
const store = usePositionStore();
const isMobile = ref(window.innerWidth < 768);
const selectedRows = ref<string[]>([]);
async function preFetch() {
try {
await store.fetchAll();
} catch (error) {
console.error('Failed to fetch initial data:', error);
}
}
preFetch();
onMounted(async () => {
window.addEventListener('resize', () => {
isMobile.value = window.innerWidth < 768;
});
});
const columns = computed<DataTableColumns<Position>>(() => [
{
type: 'selection',
disabled: (row: Position) => !row.id,
options: ['none', 'all'],
onSelect: (value: string | number | boolean, row: Position) => {
const checked = !!value;
if (row.id) {
const index = selectedRows.value.indexOf(row.id);
if (checked && index === -1) {
selectedRows.value.push(row.id);
} else if (!checked && index > -1) {
selectedRows.value.splice(index, 1);
}
}
return false;
}
},
{title: 'Name', key: 'localizedName["ENG"]'},
{title: 'Identifier', key: 'identifier'},
{title: 'Registered', key: 'regDate'},
{title: 'Author', key: 'author'}
]);
const handlePageChange = (page: number) => {
store.fetchAll(page, store.getPagination.pageSize);
};
const handlePageSizeChange = (pageSize: number) => {
store.fetchAll(1, pageSize);
};
const handleNewClick = () => {
router.push({name: 'NewPositionForm'}).catch(err => {
console.error('Navigation error:', err);
});
};
const handleArchive = async () => {
msgPopup.info(`Mock archive action for rows: ${selectedRows.value.join(', ')}`);
selectedRows.value = [];
}
const getRowProps = (row: Position) => {
return {
style: 'cursor: pointer;',
onClick: (e: MouseEvent) => {
if (!(e.target as HTMLElement).closest('.n-checkbox')) {
const routeTo = {name: 'PositionForm', params: {id: row.id}};
router.push(routeTo).catch(err => {
console.error('Navigation error:', err);
});
}
}
};
};
const handleCheckedRowKeysChange = (keys: string[]) => {
selectedRows.value = keys;
};
return {
store,
columns,
rowKey: (row: any) => row.id,
isMobile,
handleNewClick,
handleArchive,
getRowProps,
handlePageChange,
handlePageSizeChange,
handleCheckedRowKeysChange,
selectedRows,
};
}
});
</script>

<style scoped>
.cursor-pointer:hover {
cursor: pointer;
}
</style>
27 changes: 25 additions & 2 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import OrganizationsList from "../components/lists/OrganizationsList.vue";
import EmployeeList from "../components/lists/EmployeeList.vue";
import EmployeeForm from "../components/forms/EmployeeForm.vue";
import OrganizationForm from "../components/forms/OrganizationForm.vue";
import PositionList from "../components/lists/PositionList.vue";

const routes: Array<RouteRecordRaw> = [
{
Expand Down Expand Up @@ -87,9 +88,31 @@ const routes: Array<RouteRecordRaw> = [
},
{
path: 'lookups',
component: EmployeeList
children: [
{
path: 'languages',
component: PositionList
},
{
path: 'labels',
component: PositionList
},
{
path: 'org_categories',
component: PositionList
},
{
path: 'positions',
component: PositionList
},
{
path: 'task_types',
component: PositionList
}
]
}
]},
]
},
{
path: 'ai',
component: AiAssistant,
Expand Down
16 changes: 12 additions & 4 deletions src/stores/of/positionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ export const usePositionStore = defineStore('positionStore', () => {
};
});

const fetchOrgCategories = async (page = 1, pageSize = 10) => {
const getOptions = computed(() => {
return getEntries.value.map(position => ({
label: position.localizedName.ENG,
value: position.id
}));
});

const fetchPositions = async (page = 1, pageSize = 10) => {
const response = await apiClient.get(`/positions?page=${page}&size=${pageSize}`);
if (response && response.data && response.data.payload) {
apiViewResponse.value = response.data.payload;
Expand All @@ -53,7 +60,7 @@ export const usePositionStore = defineStore('positionStore', () => {
}
};

const fetchOrgCategory = async (id: string) => {
const fetchPosition = async (id: string) => {
const response = await apiClient.get(`/positions/${id}`);
if (response && response.data && response.data.payload) {
apiFormResponse.value = response.data.payload;
Expand Down Expand Up @@ -84,8 +91,9 @@ export const usePositionStore = defineStore('positionStore', () => {
apiViewResponse,
apiFormResponse,
setupApiClient,
fetchAll: fetchOrgCategories,
fetch: fetchOrgCategory,
getOptions,
fetchAll: fetchPositions,
fetch: fetchPosition,
save,
getEntries,
getPagination,
Expand Down

0 comments on commit 4cfc30f

Please sign in to comment.