From ae3eb935b361aadc0cfc0e4825e28752321d7d7b Mon Sep 17 00:00:00 2001 From: mgtennant <100305096+mgtennant@users.noreply.github.com> Date: Fri, 19 Jul 2024 17:03:04 -0700 Subject: [PATCH] add prefix variable to doc type --- backend/src/admin/admin.controller.ts | 13 ++++++- backend/src/admin/admin.service.ts | 3 +- .../document_type/document_type.controller.ts | 11 +++++- .../document_type/document_type.service.ts | 6 ++- .../entities/document_type.entity.ts | 3 ++ backend/src/report/report.service.ts | 38 ++++++++++--------- frontend/src/app/common/manage-doc-types.ts | 6 ++- .../manage-doc-types/AddDocTypeModal.tsx | 36 ++++++++++++++++-- .../manage-doc-types/EditDocTypeTable.tsx | 29 +++++++++----- .../app/content/pages/ManageDocumentsPage.tsx | 4 +- .../src/app/store/reducers/docTypeSlice.tsx | 2 + frontend/src/app/types/types.ts | 1 + ...18__nr_ticdi_add_doctype_prefix_column.sql | 8 ++++ 13 files changed, 119 insertions(+), 41 deletions(-) create mode 100644 migrations/sql/V1.0.18__nr_ticdi_add_doctype_prefix_column.sql diff --git a/backend/src/admin/admin.controller.ts b/backend/src/admin/admin.controller.ts index d27daf91..6c0db983 100644 --- a/backend/src/admin/admin.controller.ts +++ b/backend/src/admin/admin.controller.ts @@ -218,8 +218,17 @@ export class AdminController { } @Post('add-document-type') - addDocumentType(@User() user: IdirObject, @Body() data: { name: string; created_by: string; created_date: string }) { - return this.adminService.addDocumentType(data.name, data.created_by, data.created_date, user.idir_username); + addDocumentType( + @User() user: IdirObject, + @Body() data: { name: string; prefix: string; created_by: string; created_date: string } + ) { + return this.adminService.addDocumentType( + data.name, + data.prefix, + data.created_by, + data.created_date, + user.idir_username + ); } @Get('remove-document-type/:id') diff --git a/backend/src/admin/admin.service.ts b/backend/src/admin/admin.service.ts index 7d64cb81..a790ff18 100644 --- a/backend/src/admin/admin.service.ts +++ b/backend/src/admin/admin.service.ts @@ -322,9 +322,10 @@ export class AdminService { return this.provisionService.disable(id); } - async addDocumentType(name: string, created_by: string, created_date: string, create_userid: string) { + async addDocumentType(name: string, prefix: string, created_by: string, created_date: string, create_userid: string) { const documentType: DocumentType = await this.documentTypeService.add( name, + prefix, created_by, created_date, create_userid diff --git a/backend/src/document_type/document_type.controller.ts b/backend/src/document_type/document_type.controller.ts index 4d0f322d..52a14cc2 100644 --- a/backend/src/document_type/document_type.controller.ts +++ b/backend/src/document_type/document_type.controller.ts @@ -17,10 +17,17 @@ export class DocumentTypeController { @Post('update') update( - @Body() data: { id: number; name: string; created_by: string; created_date: string }, + @Body() data: { id: number; name: string; prefix: string; created_by: string; created_date: string }, @User() user: IdirObject ) { - return this.documentTypeService.update(data.id, data.name, data.created_by, data.created_date, user.idir_username); + return this.documentTypeService.update( + data.id, + data.name, + data.prefix, + data.created_by, + data.created_date, + user.idir_username + ); } @Get() diff --git a/backend/src/document_type/document_type.service.ts b/backend/src/document_type/document_type.service.ts index 45e7b9d4..a3620066 100644 --- a/backend/src/document_type/document_type.service.ts +++ b/backend/src/document_type/document_type.service.ts @@ -33,9 +33,10 @@ export class DocumentTypeService { return this.documentTypeRepository.find(); } - add(name: string, created_by: string, created_date: string, userid: string): Promise { + add(name: string, prefix: string, created_by: string, created_date: string, userid: string): Promise { const newDocumentType = this.documentTypeRepository.create({ name: name, + prefix: prefix, created_by: created_by, created_date: created_date, create_userid: userid, @@ -47,11 +48,12 @@ export class DocumentTypeService { async update( id: number, name: string, + prefix: string, created_by: string, created_date: string, userid: string ): Promise { - await this.documentTypeRepository.update(id, { name, created_by, created_date, update_userid: userid }); + await this.documentTypeRepository.update(id, { name, prefix, created_by, created_date, update_userid: userid }); const updatedDocumentType = await this.documentTypeRepository.findOneBy({ id }); if (!updatedDocumentType) { throw new Error('DocumentType not found'); diff --git a/backend/src/document_type/entities/document_type.entity.ts b/backend/src/document_type/entities/document_type.entity.ts index 54cbff8f..a77ff3ed 100644 --- a/backend/src/document_type/entities/document_type.entity.ts +++ b/backend/src/document_type/entities/document_type.entity.ts @@ -12,6 +12,9 @@ export class DocumentType { @Column() name: string; + @Column() + prefix: string; + @Column({ nullable: true }) created_by: string; diff --git a/backend/src/report/report.service.ts b/backend/src/report/report.service.ts index cccf22e5..b16961bc 100644 --- a/backend/src/report/report.service.ts +++ b/backend/src/report/report.service.ts @@ -44,24 +44,28 @@ export class ReportService { async generateReportName(dtid: number, tenure_file_number: string, document_type_id: number) { const version = await this.documentDataLogService.findNextVersion(dtid, document_type_id); const documentType = await this.documentTypeService.findById(document_type_id); - // probably a better way of doing this - let prefix = 'report'; + let prefix = 'report'; // fallback prefix if (documentType) { - if (documentType.name.toLowerCase().includes('notice of final review')) { - prefix = 'NFR'; - } else if (documentType.name.toLowerCase().includes('land use report')) { - prefix = 'LUR'; - } else if ( - documentType.name.toLowerCase().includes('grazing') || - documentType.name.toLowerCase().includes('lease') - ) { - prefix = 'Lease'; - } else if (documentType.name.toLowerCase().includes('standard licence')) { - prefix = 'Licence'; - } else if (documentType.name.toLowerCase().includes('assumption')) { - prefix = 'Assignment'; - } else if (documentType.name.toLowerCase().includes('modification')) { - prefix = 'Modification'; + prefix = documentType.prefix; + console.log('prefix pulled from db::: ' + prefix); + // fallback logic left in for now + if (prefix === '' || prefix === null || prefix === 'report') { + if (documentType.name.toLowerCase().includes('notice of final review')) { + prefix = 'NFR'; + } else if (documentType.name.toLowerCase().includes('land use report')) { + prefix = 'LUR'; + } else if ( + documentType.name.toLowerCase().includes('grazing') || + documentType.name.toLowerCase().includes('lease') + ) { + prefix = 'Lease'; + } else if (documentType.name.toLowerCase().includes('standard licence')) { + prefix = 'Licence'; + } else if (documentType.name.toLowerCase().includes('assumption')) { + prefix = 'Assignment'; + } else if (documentType.name.toLowerCase().includes('modification')) { + prefix = 'Modification'; + } } } return { diff --git a/frontend/src/app/common/manage-doc-types.ts b/frontend/src/app/common/manage-doc-types.ts index 5488da93..60c9b6b8 100644 --- a/frontend/src/app/common/manage-doc-types.ts +++ b/frontend/src/app/common/manage-doc-types.ts @@ -28,10 +28,11 @@ export const getDocumentTypes = () => { return api.get(getParameters); }; -export const addDocType = (name: string, created_by: string, created_date: string) => { +export const addDocType = (name: string, prefix: string, created_by: string, created_date: string) => { const url = `${config.API_BASE_URL}/admin/add-document-type`; const data = { name, + prefix, created_by, created_date, }; @@ -39,11 +40,12 @@ export const addDocType = (name: string, created_by: string, created_date: strin return api.post(postParameters); }; -export const updateDocType = (id: number, name: string, created_by: string, created_date: string) => { +export const updateDocType = (id: number, name: string, prefix: string, created_by: string, created_date: string) => { const url = `${config.API_BASE_URL}/document-type/update`; const data = { id, name, + prefix, created_by, created_date, }; diff --git a/frontend/src/app/components/modal/manage-doc-types/AddDocTypeModal.tsx b/frontend/src/app/components/modal/manage-doc-types/AddDocTypeModal.tsx index d9c48009..aeb81892 100644 --- a/frontend/src/app/components/modal/manage-doc-types/AddDocTypeModal.tsx +++ b/frontend/src/app/components/modal/manage-doc-types/AddDocTypeModal.tsx @@ -1,18 +1,20 @@ -import { FC, useEffect, useState } from 'react'; -import { Button, Col, Form, Modal, Row, Spinner } from 'react-bootstrap'; +import { FC, useState } from 'react'; +import { Button, Col, Form, Modal, OverlayTrigger, Row, Spinner, Tooltip } from 'react-bootstrap'; import { DocType } from '../../../types/types'; import UserService from '../../../service/user-service'; +import '@fortawesome/fontawesome-free/css/all.min.css'; interface AddDocTypeModalProps { allDocTypes: DocType[]; show: boolean; onHide: () => void; - onAdd: (name: string, created_by: string, created_date: string) => void; + onAdd: (name: string, prefix: string, created_by: string, created_date: string) => void; } const AddDocTypeModal: FC = ({ allDocTypes, show, onHide, onAdd }) => { const username = UserService.getUsername(); const [name, setName] = useState(''); + const [prefix, setPrefix] = useState(''); const [createdBy, setCreatedBy] = useState(username); const [createdDate, setCreatedDate] = useState(new Date().toISOString().substring(0, 10)); const [loading, setLoading] = useState(false); @@ -26,7 +28,7 @@ const AddDocTypeModal: FC = ({ allDocTypes, show, onHide, setShowError(false); const isNameUnique = !allDocTypes.some((docType) => docType.name === name); if (isNameUnique) { - onAdd(name, createdBy, createdDate); + onAdd(name, prefix, createdBy, createdDate); onHide(); } else { setError('That document type name already exists'); @@ -46,6 +48,11 @@ const AddDocTypeModal: FC = ({ allDocTypes, show, onHide, setName(e.target.value); }; + const handlePrefixChange = (e: React.ChangeEvent) => { + if (defaultDisabled) setDefaultDisabled(false); + setPrefix(e.target.value); + }; + const handleCreatedByChange = (e: React.ChangeEvent) => { setCreatedBy(e.target.value); }; @@ -69,6 +76,27 @@ const AddDocTypeModal: FC = ({ allDocTypes, show, onHide, + + + File Prefix: + + The file prefix is the value added to the beginning of the generated document's filename. + + } + > + + + + + + + + + + Created By: diff --git a/frontend/src/app/components/table/manage-doc-types/EditDocTypeTable.tsx b/frontend/src/app/components/table/manage-doc-types/EditDocTypeTable.tsx index 04a3d744..79307146 100644 --- a/frontend/src/app/components/table/manage-doc-types/EditDocTypeTable.tsx +++ b/frontend/src/app/components/table/manage-doc-types/EditDocTypeTable.tsx @@ -36,6 +36,7 @@ const EditDocTypeTable: FC = ({ refreshDocTypes }) => { await updateDocType( selectedDocType.id, currentDocType.name, + currentDocType.prefix, currentDocType.created_by, currentDocType.created_date ); @@ -67,7 +68,21 @@ const EditDocTypeTable: FC = ({ refreshDocTypes }) => { ), header: () => 'Document Type Name', enableSorting: false, - meta: { customCss: { width: '17%' }, type: 'text' }, + meta: { customCss: { width: '24%' }, type: 'text' }, + }), + columnHelper.accessor('prefix', { + id: 'prefix', + cell: ({ row }) => ( + row.original.prefix} + columnId="prefix" + onUpdate={updateHandler} + isEditing={isEditing} + /> + ), + header: () => 'File Prefix', + enableSorting: true, + meta: { customCss: { width: '12%' }, type: 'text' }, }), columnHelper.accessor('created_date', { id: 'created_date', @@ -81,7 +96,7 @@ const EditDocTypeTable: FC = ({ refreshDocTypes }) => { ), header: () => 'Date Created', enableSorting: false, - meta: { customCss: { width: '17%', margin: '0px' }, type: 'text' }, + meta: { customCss: { width: '12%', margin: '0px' }, type: 'text' }, }), columnHelper.accessor('created_by', { id: 'created_by', @@ -95,7 +110,7 @@ const EditDocTypeTable: FC = ({ refreshDocTypes }) => { ), header: () => 'Created By', enableSorting: false, - meta: { customCss: { width: '17%' }, type: 'text' }, + meta: { customCss: { width: '12%' }, type: 'text' }, }), columnHelper.accessor('update_timestamp', { id: 'update_timestamp', @@ -104,14 +119,14 @@ const EditDocTypeTable: FC = ({ refreshDocTypes }) => { ), header: () => 'Last Updated Date', enableSorting: false, - meta: { customCss: { width: '17%' }, type: 'text' }, + meta: { customCss: { width: '12%' }, type: 'text' }, }), columnHelper.accessor('update_userid', { id: 'update_userid', cell: (info) => , header: () => 'Last Updated By', enableSorting: false, - meta: { customCss: { width: '17%' }, type: 'text' }, + meta: { customCss: { width: '12%' }, type: 'text' }, }), columnHelper.display({ id: 'edit_and_save', @@ -156,9 +171,6 @@ interface TableCellProps { } const TableCell: FC> = ({ getValue, columnId, onUpdate, isEditing }) => { - // const dispatch = useDispatch(); - // const updatedDocType = useSelector((state: RootState) => state.docType.updatedDocType); - // const initialValue = getValue() ? (columnId === 'created_date' ? getValue().substring(0, 10) : getValue()) : ''; let initialValue = getValue() ? getValue() : ''; const [value, setValue] = useState(initialValue); @@ -167,7 +179,6 @@ const TableCell: FC> = ({ getValue, columnId, onUpdate, }, [initialValue]); const handleBlur = () => { - // dispatch(setUpdatedDocType({ ...updatedDocType, [columnId]: value })); onUpdate({ [columnId]: value }); }; diff --git a/frontend/src/app/content/pages/ManageDocumentsPage.tsx b/frontend/src/app/content/pages/ManageDocumentsPage.tsx index e6de3596..92151436 100644 --- a/frontend/src/app/content/pages/ManageDocumentsPage.tsx +++ b/frontend/src/app/content/pages/ManageDocumentsPage.tsx @@ -118,10 +118,10 @@ const ManageDocumentsPage: FC = () => { setShowAddDocTypeModal(true); }; - const addDocTypeHandler = async (name: string, created_by: string, created_date: string) => { + const addDocTypeHandler = async (name: string, prefix: string, created_by: string, created_date: string) => { try { setLoading(true); - await addDocType(name, created_by, created_date); + await addDocType(name, prefix, created_by, created_date); refreshDocTypes(); } catch (err) { console.log('Error adding doc type'); diff --git a/frontend/src/app/store/reducers/docTypeSlice.tsx b/frontend/src/app/store/reducers/docTypeSlice.tsx index 8d8bc618..a18c04e3 100644 --- a/frontend/src/app/store/reducers/docTypeSlice.tsx +++ b/frontend/src/app/store/reducers/docTypeSlice.tsx @@ -12,6 +12,7 @@ const initialState: DocumentTypeObjectState = { selectedDocType: { id: -1, name: '', + prefix: '', created_by: '', created_date: '', create_userid: '', @@ -22,6 +23,7 @@ const initialState: DocumentTypeObjectState = { updatedDocType: { id: -1, name: '', + prefix: '', created_by: '', created_date: '', create_userid: '', diff --git a/frontend/src/app/types/types.ts b/frontend/src/app/types/types.ts index 206fabf0..ffdfbe7a 100644 --- a/frontend/src/app/types/types.ts +++ b/frontend/src/app/types/types.ts @@ -261,6 +261,7 @@ export type SearchData = { export type DocType = { id: number; name: string; + prefix: string; created_by: string; created_date: string; create_userid: string; diff --git a/migrations/sql/V1.0.18__nr_ticdi_add_doctype_prefix_column.sql b/migrations/sql/V1.0.18__nr_ticdi_add_doctype_prefix_column.sql new file mode 100644 index 00000000..bdb691ed --- /dev/null +++ b/migrations/sql/V1.0.18__nr_ticdi_add_doctype_prefix_column.sql @@ -0,0 +1,8 @@ +ALTER TABLE document_type ADD COLUMN prefix VARCHAR(50) DEFAULT ''; +UPDATE document_type SET prefix = 'Lease' WHERE name ILIKE 'Standard Lease'; +UPDATE document_type SET prefix = 'Licence' WHERE name ILIKE 'Standard Licence'; +UPDATE document_type SET prefix = 'Assumption' WHERE name ILIKE 'Assignment Assumption'; +UPDATE document_type SET prefix = 'Modification' WHERE name ILIKE 'Modification Agreement'; +UPDATE document_type SET prefix = 'NFR' WHERE name ILIKE 'Notice of Final Review%'; +UPDATE document_type SET prefix = 'LUR' WHERE name ILIKE 'Land Use Report'; +UPDATE document_type SET prefix = 'Lease' WHERE name ILIKE 'Grazing Lease';