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

OLMIS-7987: Added delete functionality and pagination in form #55

Merged
merged 1 commit into from
Oct 21, 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
40 changes: 29 additions & 11 deletions src/requisition-order-create/order-create-form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ const OrderCreateForm = () => {

const ADMINISTRATION_RIGHTS = useMemo(() => getService('ADMINISTRATION_RIGHTS'), []);
const programService = useMemo(() => getService('programService'), []);
const { formatMessage } = useMemo(() => getService('messageService'), []);
const facilityService = useMemo(() => getService('facilityService'), []);
const orderService = useMemo(() => getService('orderCreateService'), []);
const { formatMessage } = useMemo(() => getService('messageService'), []);
const columns = useMemo(() => orderCreateFormTableColumns(formatMessage), []);

const userId = useMemo(
Expand Down Expand Up @@ -100,7 +100,7 @@ const OrderCreateForm = () => {

useEffect(
() => {
facilityService.getUserFacilitiesForRight(userId, ADMINISTRATION_RIGHTS.ORDER_CREATE)
facilityService.getUserFacilitiesForRight(userId, ADMINISTRATION_RIGHTS.ORDER_CREATE, true)
.then((facilities) => {
setRequestingFacilityOptions(_.map(facilities, facility => ({ name: facility.name, value: facility.id })));
});
Expand Down Expand Up @@ -140,36 +140,54 @@ const OrderCreateForm = () => {
return (
<div className="page-container">
<div className="page-header-responsive">
<h2>{ formatMessage('requisition.orderCreate.create') }</h2>
<h2> {formatMessage('requisition.orderCreate.create')} </h2>
</div>
<div className="page-content order-create-form">
<div className={'section'}>
<div><strong className="is-required">{ formatMessage('requisition.orderCreate.program') }</strong></div>
<div>
<strong className='is-required'>
{formatMessage('requisition.orderCreate.program')}
</strong>
</div>
<SearchSelect
options={programOptions}
value={selectedProgram}
onChange={value => setSelectedProgram(value)}
placeholder={ formatMessage('requisition.orderCreate.program.placeholder')}
placeholder={formatMessage('requisition.orderCreate.program.placeholder')}
/>
</div>
<div className={'section'}>
<div><strong className="is-required">{ formatMessage('requisition.orderCreate.reqFacility') }</strong></div>
<div>
<strong className='is-required'>
{formatMessage('requisition.orderCreate.reqFacility')}
</strong>
</div>
<SearchSelect
options={requestingFacilityOptions}
value={selectedRequestingFacilities.at(-1)}
onChange={value => setSelectedRequestingFacilities(prevState => [...prevState, value])}
placeholder={ formatMessage('requisition.orderCreate.reqFacility.placeholder')}
onChange={(value) => {
setSelectedRequestingFacilities((prevState) => {
if (!prevState.includes(value) && value) {
return [...prevState, value];
}
return prevState;
});
}}
placeholder={formatMessage('requisition.orderCreate.reqFacility.placeholder')}
/>
<EditableTable
additionalTableClass='facilities-table'
updateData={updateTableData}
columns={columns}
data={filteredRequestingFacilities || []}
displayPagination={false}
/>
</div>
<div className={'section'}>
<div><strong className="is-required">{ formatMessage('requisition.orderCreate.supFacility') }</strong></div>
<div>
<strong className='is-required'>
{formatMessage('requisition.orderCreate.supFacility')}
</strong>
</div>
<SearchSelect
options={supplyingFacilityOptions}
value={selectedSupplyingFacility}
Expand All @@ -186,7 +204,7 @@ const OrderCreateForm = () => {
disabled={!selectedProgram || !selectedRequestingFacilities || !selectedSupplyingFacility}
onClick={createOrders}
>
{ formatMessage('requisition.orderCreate.create') }
{formatMessage('requisition.orderCreate.create')}
</button>
</div>
</div>
Expand Down
18 changes: 16 additions & 2 deletions src/requisition-order-create/order-create.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
.module('requisition-order-create')
.service('orderCreateService', service);

service.$inject = ['$resource', 'openlmisUrlFactory'];
service.$inject = ['$resource', '$http', 'openlmisUrlFactory'];

function service($resource, openlmisUrlFactory) {
function service($resource, $http, openlmisUrlFactory) {

var resource = $resource(openlmisUrlFactory('/api/orders/:id'), {}, {
update: {
Expand All @@ -50,6 +50,7 @@
this.create = create;
this.update = update;
this.send = send;
this.delete = deleteOrders;

function get(orderId) {
return resource.get({
Expand All @@ -72,5 +73,18 @@
id: order.id
}, order).$promise;
}

function deleteOrders(orderIds) {
return $http({
method: 'DELETE',
url: openlmisUrlFactory('/api/orders'),
data: {
ids: orderIds
},
headers: {
'Content-Type': 'application/json;charset=utf-8'
}
});
}
}
})();
Loading