Skip to content

Commit

Permalink
adjusted existing close esup permit modal, and added closed_by to esu…
Browse files Browse the repository at this point in the history
…p table
  • Loading branch information
asinn134 authored and matbusby committed Oct 20, 2023
1 parent 64c1443 commit 4a767ad
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE
explosives_permit
ADD
COLUMN IF NOT EXISTS "closed_by" varchar(60);
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ export interface IExplosivesPermit {
documents: IExplosivesPermitDocument[];
mines_permit_number: string;
now_number: string;
closed_by: string;
explosives_permit_amendments: IExplosivesPermitAmendment[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.schema import FetchedValue, Sequence
from sqlalchemy import and_, func

from app.api.utils.models_mixins import SoftDeleteMixin, AuditMixin, PermitMixin, Base
from app.extensions import db
from app.api.mines.explosives_permit.models.explosives_permit_document_type import ExplosivesPermitDocumentType
from app.api.mines.explosives_permit.models.explosives_permit_magazine import ExplosivesPermitMagazine
from app.api.mines.explosives_permit.models.explosives_permit_document_xref import ExplosivesPermitDocumentXref
from app.api.mines.documents.models.mine_document import MineDocument
from app.api.parties.party.models.party import Party
from app.api.utils.include.user_info import User


class ExplosivesPermit(SoftDeleteMixin, AuditMixin, PermitMixin, Base):
Expand All @@ -24,6 +34,18 @@ class ExplosivesPermit(SoftDeleteMixin, AuditMixin, PermitMixin, Base):

permit_number = db.Column(db.String, unique=True)

closed_by = db.Column(db.String(60))

explosive_magazines = db.relationship(
'ExplosivesPermitMagazine',
lazy='select',
primaryjoin='and_(ExplosivesPermitMagazine.explosives_permit_id == ExplosivesPermit.explosives_permit_id, ExplosivesPermitMagazine.explosives_permit_magazine_type_code == "EXP", ExplosivesPermitMagazine.deleted_ind == False)'
)
detonator_magazines = db.relationship(
'ExplosivesPermitMagazine',
lazy='select',
primaryjoin='and_(ExplosivesPermitMagazine.explosives_permit_id == ExplosivesPermit.explosives_permit_id, ExplosivesPermitMagazine.explosives_permit_magazine_type_code == "DET", ExplosivesPermitMagazine.deleted_ind == False)'
)
explosives_permit_amendments = db.relationship('ExplosivesPermitAmendment', lazy='select',
primaryjoin='ExplosivesPermit.explosives_permit_id == ExplosivesPermitAmendment.explosives_permit_id',
back_populates='explosives_permit')
Expand Down Expand Up @@ -67,6 +89,7 @@ def update(self, permit_guid, now_application_guid, issuing_inspector_party_guid
self.expiry_date = expiry_date
self.latitude = latitude
self.longitude = longitude
self.closed_by = User().get_user_username()

# Check for permit closed changes.
self.is_closed = is_closed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ class ExplosivesPermitResource(Resource, UserMixin):
store_missing=False,
required=False,
)
parser.add_argument(
'closed_by',
type=str,
store_missing=False,
required=False,
)
parser.add_argument(
'closed_timestamp',
type=lambda x: inputs.datetime_from_iso8601(x) if x else None,
Expand Down Expand Up @@ -187,6 +193,7 @@ def put(self, mine_guid, explosives_permit_guid):
data.get('letter_body'),
data.get('explosive_magazines', []),
data.get('detonator_magazines', []), data.get('documents', []))


explosives_permit.save()
return explosives_permit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
'documents': fields.List(fields.Nested(EXPLOSIVES_PERMIT_DOCUMENT_MODEL)),
'mines_permit_number': fields.String(attribute='mines_act_permit.permit_no'),
'now_number': fields.String(attribute='now_application_identity.now_number'),
'closed_by': fields.String,
'now_number': fields.String(attribute='now_application_identity.now_number'),
'explosives_permit_amendments': fields.List(fields.Nested(EXPLOSIVES_PERMIT_AMENDMENT_MODEL))
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import PropTypes from "prop-types";
import { Field, reduxForm } from "redux-form";
import { Form } from "@ant-design/compatible";
import "@ant-design/compatible/assets/index.css";
import { Button, Col, Row, Popconfirm } from "antd";
import { requiredRadioButton } from "@common/utils/Validate";
import { Button, Col, Row, Popconfirm, Typography } from "antd";
import { dateTimezoneRequired, dateNotInFutureTZ, required } from "@common/utils/Validate";
import { resetForm } from "@common/utils/helpers";
import * as FORM from "@/constants/forms";
import RenderRadioButtons from "@/components/common/RenderRadioButtons";
import RenderDate from "@/components/common/RenderDate";
import RenderAutoSizeField from "@/components/common/RenderAutoSizeField";
import RenderDateTimeTz from "@/components/common/RenderDateTimeTz";
import { normalizeDatetime } from "@common/utils/helpers";

const propTypes = {
handleSubmit: PropTypes.func.isRequired,
Expand All @@ -18,42 +18,33 @@ const propTypes = {
title: PropTypes.string.isRequired,
};

const options = [
{
value: false,
label: "Open",
},
{
value: true,
label: "Closed",
},
];

export const ExplosivesPermitCloseForm = (props) => {
return (
<Form layout="vertical" onSubmit={props.handleSubmit}>
<Row gutter={16}>
<Col span={24}>
<Form.Item>
<Field
id="is_closed"
name="is_closed"
label="Permit Status*"
component={RenderRadioButtons}
customOptions={options}
validate={[requiredRadioButton]}
/>
</Form.Item>
<Typography.Title level={2}>Close Permit</Typography.Title>
<Typography.Paragraph>
If you perform this action there will no longer be an active explosive use and storage
permit for this notice of work. If you still want to have an amendment active, consider
creating an amendment for this permit before performing this action.
</Typography.Paragraph>
</Col>
</Row>
<Row gutter={16}>
<Col span={24}>
<Form.Item>
<Form.Item label="Date Permit was Closed" required>
<Field
id="closed_timestamp"
name="closed_timestamp"
label="Date Permit was Closed"
component={RenderDate}
normalize={normalizeDatetime}
component={RenderDateTimeTz}
validate={[
dateNotInFutureTZ,
required,
dateTimezoneRequired("esup_permit_close_timezone"),
]}
props={{ timezoneFieldProps: { name: "esup_permit_close_timezone" } }}
/>
</Form.Item>
</Col>
Expand All @@ -64,7 +55,7 @@ export const ExplosivesPermitCloseForm = (props) => {
<Field
id="closed_reason"
name="closed_reason"
label="Reason"
label="Reason for closure"
component={RenderAutoSizeField}
/>
</Form.Item>
Expand All @@ -84,7 +75,7 @@ export const ExplosivesPermitCloseForm = (props) => {
</Button>
</Popconfirm>
<Button className="full-mobile" type="primary" htmlType="submit" loading={props.submitting}>
{props.title}
Close Permit
</Button>
</div>
</Form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,15 @@ export const ExplosivesPermit: FC<ExplosivesPermitProps> = ({
};

const handleOpenExplosivesPermitCloseModal = (event, record = null) => {
const initialValues = record || {};
let initialValues = record || {};
event.preventDefault();
if (Object.keys(initialValues).length > 0) {
initialValues = { ...initialValues, is_closed: true };
}
props.openModal({
props: {
onSubmit: handleUpdateExplosivesPermit,
title: "Update Explosives Permit Status",
title: "Close Permit",
initialValues,
mineGuid,
},
Expand Down Expand Up @@ -162,6 +165,7 @@ export const ExplosivesPermit: FC<ExplosivesPermitProps> = ({
parentPermit,
mine,
closeModal: props.closeModal,
handleOpenExplosivesPermitCloseModal,
},
content: modalConfig.EXPLOSIVES_PERMIT_VIEW_MODAL,
isViewOnly: true,
Expand Down Expand Up @@ -255,7 +259,6 @@ export const ExplosivesPermit: FC<ExplosivesPermitProps> = ({
explosivesPermitDocumentTypeOptionsHash={props.explosivesPermitDocumentTypeOptionsHash}
handleOpenExplosivesPermitStatusModal={handleOpenExplosivesPermitStatusModal}
handleDeleteExplosivesPermit={handleDeleteExplosivesPermit}
handleOpenExplosivesPermitCloseModal={handleOpenExplosivesPermitCloseModal}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ interface MineExplosivesPermitTableProps {
record: IExplosivesPermit
) => void;
handleOpenViewMagazineModal: (event, record: IExplosivesPermit, type: string) => void;
handleOpenExplosivesPermitCloseModal: (event, record: IExplosivesPermit) => void;
handleOpenViewExplosivesPermitModal: (event, record: IExplosivesPermit) => void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ interface ExplosivesPermitViewModalProps {
title: string;
closeModal: () => void;
openDocument: (document_manager_guid: string, mine_document_guid: string) => void;
handleOpenExplosivesPermitCloseModal: (event, record: IExplosivesPermit) => void;
}

export const ExplosivesPermitViewModal: FC<ExplosivesPermitViewModalProps> = (props) => {
Expand Down Expand Up @@ -332,7 +333,13 @@ export const ExplosivesPermitViewModal: FC<ExplosivesPermitViewModalProps> = (pr
{formatDate(currentPermit.closed_timestamp)}
</Typography.Paragraph>
) : (
<Button type="ghost" className="close-permit-button">
<Button
onClick={(event) =>
props.handleOpenExplosivesPermitCloseModal(event, explosivesPermit)
}
type="ghost"
className="close-permit-button"
>
Close Permit
</Button>
)}
Expand Down

0 comments on commit 4a767ad

Please sign in to comment.