Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticdi 81 provision list #232

Merged
merged 7 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions backend/src/provision/dto/create-provision.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import { ProvisionDto } from './provision.dto';
export class CreateProvisionDto extends PickType(ProvisionDto, [
'dtid',
'type',
// 'provision_group',
// 'provision_group_text',
// 'max',
'provision_name',
'free_text',
'list_items',
'list_enabled',
'help_text',
'category',
'sequence_value',
Expand Down
5 changes: 2 additions & 3 deletions backend/src/provision/dto/provision.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
export class ProvisionDto {
dtid?: number;
type?: string;
// provision_group?: number;
// provision_group_text?: string;
// max?: number;
provision_name?: string;
free_text?: string;
list_items?: string[];
list_enabled?: boolean;
help_text?: string;
category?: string;
sequence_value?: number;
Expand Down
5 changes: 2 additions & 3 deletions backend/src/provision/dto/update-provision.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import { ProvisionDto } from './provision.dto';
export class UpdateProvisionDto extends PickType(ProvisionDto, [
'dtid',
'type',
// 'provision_group',
// 'provision_group_text',
// 'max',
'provision_name',
'free_text',
'list_items',
'list_enabled',
'help_text',
'category',
'sequence_value',
Expand Down
10 changes: 10 additions & 0 deletions backend/src/provision/entities/provision.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ export class Provision {
@Column({ nullable: true })
free_text: string;

@Column({ type: 'text', array: true, default: '{}' })
list_items: string[];

@Column({ nullable: true })
list_enabled: boolean;

@Column({ nullable: true })
help_text: string;

Expand Down Expand Up @@ -59,13 +65,17 @@ export class Provision {
constructor(
provision_name?: string,
free_text?: string,
list_items?: string[],
list_enabled?: boolean,
category?: string,
active_flag?: boolean,
create_userid?: string,
update_userid?: string
) {
this.provision_name = provision_name || '';
this.free_text = free_text || '';
this.list_items = list_items || [];
this.list_enabled = list_enabled || false;
this.category = category || '';
this.active_flag = active_flag || true;
this.create_userid = create_userid || '';
Expand Down
2 changes: 2 additions & 0 deletions backend/src/provision/provision.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export class ProvisionController {
id: number;
provision: string;
free_text: string;
list_items: string[];
list_enabled: boolean;
help_text: string;
category: string;
},
Expand Down
4 changes: 4 additions & 0 deletions backend/src/provision/provision.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export class ProvisionService {
const existingProvision: Provision = await this.provisionRepository.findOneBy({ id });
existingProvision.provision_name = provision.provision_name;
existingProvision.free_text = provision.free_text;
existingProvision.list_items = provision.list_items;
existingProvision.list_enabled = provision.list_enabled;
existingProvision.help_text = provision.help_text;
existingProvision.category = provision.category;
existingProvision.update_userid = provision.update_userid;
Expand Down Expand Up @@ -272,6 +274,8 @@ export class ProvisionService {
type: docTypeProvision.type,
provision_name: docTypeProvision.provision.provision_name,
free_text: docTypeProvision.provision.free_text,
list_items: docTypeProvision.provision.list_items,
list_enabled: docTypeProvision.provision.list_enabled,
help_text: docTypeProvision.provision.help_text,
category: docTypeProvision.provision.category,
active_flag: docTypeProvision.provision.active_flag,
Expand Down
38 changes: 35 additions & 3 deletions backend/src/report/report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@
}
return a.provision_group - b.provision_group;
});
let provisions: { [key: string]: { provision_name: string; free_text: string }[] } = {};
provisionJson.forEach(({ provision_name, provision_group, free_text }) => {
let provisions: {
[key: string]: { provision_name: string; free_text: string; list: { item: string }[] }[];
} = {};
provisionJson.forEach(({ provision_name, provision_group, free_text, list_items, list_enabled }) => {
if (free_text.includes('«')) {
// regex which converts «DB_TENURE_TYPE» to {d.DB_Tenure_Type}, also works for VAR_
free_text = free_text.replace(/«([^»]+)»/g, function (match, innerText) {
Expand All @@ -161,11 +163,41 @@
free_text = free_text.replace(/db_name_tenant:convcrlf\(\)}/gi, 'DB_NAME_TENANT:convCRLF()}');
}

// do same conversions for list items
let list = list_items.map((item) => {
if (item.includes('«')) {
// regex which converts «DB_TENURE_TYPE» to {d.DB_Tenure_Type}, also works for VAR_
item = item.replace(/«([^»]+)»/g, function (match, innerText) {
innerText = convertToSpecialCamelCase(innerText);
return '{d.' + innerText + '}';
});
} else if (item.includes('<<')) {
// regex which converts <<DB_TENURE_TYPE>> to {d.DB_Tenure_Type}, also works for VAR_
item = item.replace(/<<([^>>]+)>>/g, function (match, innerText) {
innerText = convertToSpecialCamelCase(innerText);
return '{d.' + innerText + '}';
});
Dismissed Show dismissed Hide dismissed
}

if (item.toLowerCase().includes('db_name_tenant}')) {
item = item.replace(/db_name_tenant}/gi, 'DB_NAME_TENANT:convCRLF()}');
} else if (item.toLowerCase().includes('db_name_tenant:convcrlf()}')) {
item = item.replace(/db_name_tenant:convcrlf\(\)}/gi, 'DB_NAME_TENANT:convCRLF()}');
}
return { item };
});

const key = `SECTION_${provision_group}`;
if (!provisions[key]) {
provisions[key] = [];
}
provisions[key].push({ provision_name, free_text });

// for now, only pass free_text or list, not both
if (list_enabled) {
provisions[key].push({ provision_name, free_text: null, list });
} else {
provisions[key].push({ provision_name, free_text, list: [] });
}
});

// get the TTLS DB_ variables
Expand Down
4 changes: 4 additions & 0 deletions backend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export type ProvisionJSON = {
provision_name: string;
provision_group: number;
free_text: string;
list_items: string[];
list_enabled: boolean;
provision_id: number;
sequence_value: number;
doc_type_provision_id: number;
Expand Down Expand Up @@ -59,6 +61,8 @@ export type ManageDocTypeProvision = {
type: string;
provision_name: string;
free_text: string;
list_items: string[];
list_enabled: boolean;
help_text: string;
category: string;
active_flag: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { useState } from 'react';
import { ProvisionUpload } from '../../../types/types';
import { Button, Col, Form, Modal, Spinner } from 'react-bootstrap';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faPlus, faMinus } from '@fortawesome/free-solid-svg-icons';

interface AddProvisionModalProps {
show: boolean;
addProvisionHandler: (provision: ProvisionUpload) => void;
addProvisionHandler: (provision: ProvisionUpload) => Promise<void>;
onHide: () => void;
refreshTables: () => void;
}

const AddProvisionModal: React.FC<AddProvisionModalProps> = ({ show, addProvisionHandler, onHide, refreshTables }) => {
const AddProvisionModal: React.FC<AddProvisionModalProps> = ({ show, addProvisionHandler, onHide }) => {
const [loading, setLoading] = useState<boolean>(false);
const [provisionName, setProvisionName] = useState<string>('');
const [freeText, setFreeText] = useState<string>('');
const [listItems, setListItems] = useState<string[]>(['']);
const [listEnabled, setListEnabled] = useState<boolean>(false);
const [helpText, setHelpText] = useState<string>('');
const [category, setCategory] = useState<string>('');

Expand All @@ -32,19 +35,41 @@ const AddProvisionModal: React.FC<AddProvisionModalProps> = ({ show, addProvisio
setCategory(e.target.value);
};

const handleSaveButton = () => {
const handleListEnabledChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setListEnabled(e.target.checked);
};

const handleListItemChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>, index: number) => {
const newListItems = [...listItems];
newListItems[index] = e.target.value;
setListItems(newListItems);
};

const handleAddListItem = () => {
setListItems([...listItems, '']);
};

const handleRemoveListItem = (index: number) => {
const newListItems = [...listItems];
newListItems.splice(index, 1);
setListItems(newListItems);
};

const handleSaveButton = async () => {
try {
setLoading(true);

const provisionUpload: ProvisionUpload = {
provision_name: provisionName,
free_text: freeText,
list_items: listEnabled ? listItems : [],
list_enabled: listEnabled,
help_text: helpText,
category: category,
};
addProvisionHandler(provisionUpload);

await addProvisionHandler(provisionUpload);
onHide();
refreshTables();
} catch (err) {
console.log('Error adding provision');
console.log(err);
Expand Down Expand Up @@ -81,15 +106,50 @@ const AddProvisionModal: React.FC<AddProvisionModalProps> = ({ show, addProvisio
</Col>
</Form.Group>

<Form.Group className="mb-3">
<Form.Label column sm="12">
Free Text
</Form.Label>
<Col sm="10">
<Form.Control as="textarea" rows={3} name="free_text" onChange={handleFreeTextChange} />
</Col>
<Form.Group className="mb-3" style={{ marginLeft: '15px', marginTop: '30px' }}>
<Form.Check type="checkbox" label="Enable List" checked={listEnabled} onChange={handleListEnabledChange} />
</Form.Group>

{listEnabled ? (
<Form.Group className="mb-3">
<Form.Label column sm="12">
List Items
</Form.Label>
{listItems.map((item, index) => (
<div key={index} style={{ display: 'flex', alignItems: 'center', marginBottom: '10px' }}>
<Col sm="10">
<Form.Control
as="input"
type="text"
name={`list_item_${index}`}
value={item}
onChange={(e) => handleListItemChange(e, index)}
/>
</Col>
<Col sm="2">
<Button variant="link" onClick={() => handleRemoveListItem(index)}>
<FontAwesomeIcon icon={faMinus} />
</Button>
</Col>
</div>
))}
<div style={{ marginLeft: '15px' }}>
<Button variant="success" onClick={handleAddListItem}>
<FontAwesomeIcon icon={faPlus} />
</Button>
</div>
</Form.Group>
) : (
<Form.Group className="mb-3">
<Form.Label column sm="12">
Free Text
</Form.Label>
<Col sm="10">
<Form.Control as="textarea" rows={3} name="free_text" onChange={handleFreeTextChange} />
</Col>
</Form.Group>
)}

<Form.Group className="mb-3">
<Form.Label column sm="12">
Help Text
Expand Down
Loading
Loading