Index: CHANGELOG.md =================================================================== diff -u -N -r7f9ffae3458e2f9994249398a1d526a3cbe861d6 -r9bbcb50a0fd738bf96b96418ce9735988b8103b3 --- CHANGELOG.md (.../CHANGELOG.md) (revision 7f9ffae3458e2f9994249398a1d526a3cbe861d6) +++ CHANGELOG.md (.../CHANGELOG.md) (revision 9bbcb50a0fd738bf96b96418ce9735988b8103b3) @@ -3,6 +3,7 @@ mobile app * [OLMIS-7654](https://openlmis.atlassian.net/browse/OLMIS-7654): Create template page for program/facility selection - mobile app * [OLMIS-7655](https://openlmis.atlassian.net/browse/OLMIS-7655): Enable selecting program and facility on program/facility selection page - mobile app +* [OLMIS-7656](https://openlmis.atlassian.net/browse/OLMIS-7656): Implement searching functionality in Stock on Hand - mobile app 2.1.3 / 2022-10-07 ================== Index: src/stock-on-hand-mobile/pages/program-select.jsx =================================================================== diff -u -N -r7f9ffae3458e2f9994249398a1d526a3cbe861d6 -r9bbcb50a0fd738bf96b96418ce9735988b8103b3 --- src/stock-on-hand-mobile/pages/program-select.jsx (.../program-select.jsx) (revision 7f9ffae3458e2f9994249398a1d526a3cbe861d6) +++ src/stock-on-hand-mobile/pages/program-select.jsx (.../program-select.jsx) (revision 9bbcb50a0fd738bf96b96418ce9735988b8103b3) @@ -14,13 +14,16 @@ */ import React, { useMemo, useEffect, useState } from 'react'; +import { useHistory } from 'react-router-dom'; import { useSelector } from 'react-redux'; import RadioButton from '../../react-components/buttons/radio-button'; import Select from '../../react-components/inputs/select'; import InputWithSuggestions from '../../react-components/inputs/input-with-suggestions'; const ProgramSelect = ({ offlineService }) => { + const history = useHistory(); + const convertIntoSelectOptions = (values) => { return values.map(({ id, name }) => ({ value: id, name })); }; @@ -36,109 +39,110 @@ const [supervisedFacilitiesOptions, setSupervisedFacilitiesOptions] = useState([]); const radioChangeHandler = (e) => { - if (facilityType !== e.target.value) { - if (e.target.value == 'MyFacility') { - setFacilityId(facility.id); - } else { - setFacilityId(null); - } - setFacilityType(e.target.value); + setFacilityId(null); setProgramId(null); - } + setFacilityType(e.target.value); }; const supervisedProgramsHandler = (value) => { setProgramId(value); setSupervisedFacilitiesOptions(supervisedFacilities[value]); }; + const handleSearch = (programId, facilityId) => { + history.push(`/stockOnHand/${facilityId}/${programId}`); + }; + const menu = document.getElementsByClassName('header ng-scope')[0]; useEffect(() => { - setFacilityId(facility.id); menu.style.display = ''; - }, [menu, programId]); + }, [menu]); return ( <> -
-

- Stock on Hand -

-
-
- -
- - -
-
-
- +
+

+ Stock on Hand +

+
+
+ +
+ + +
+
+
+ +
+ {facilityType !== 'SupervisedFacility' ? +
+ setProgramId(value)} - /> + : + <> +
+ setFacilityId(value.id)} + sortFunction={(a, b) => a.name.localeCompare(b.name)} />
-
- -
-
- setFacilityId(value.id)} - sortFunction={(a, b) => a.name.localeCompare(b.name)} - /> -
- - } -
- -
+ + } +
+ +
); }; Index: src/stock-on-hand-mobile/pages/stock-on-hand.jsx =================================================================== diff -u -N --- src/stock-on-hand-mobile/pages/stock-on-hand.jsx (revision 0) +++ src/stock-on-hand-mobile/pages/stock-on-hand.jsx (revision 9bbcb50a0fd738bf96b96418ce9735988b8103b3) @@ -0,0 +1,54 @@ +/* + * This program is part of the OpenLMIS logistics management information system platform software. + * Copyright © 2017 VillageReach + * + * This program is free software: you can redistribute it and/or modify it under the terms + * of the GNU Affero General Public License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + *   + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  + * See the GNU Affero General Public License for more details. You should have received a copy of + * the GNU Affero General Public License along with this program. If not, see + * http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org.  + */ + +import React, { useEffect } from 'react'; +import { useDispatch, useSelector } from 'react-redux'; +import { useParams } from 'react-router-dom'; +import { setFacilityStockOnHand } from '../reducers/facilities'; +import { setProgramStockOnHand } from '../reducers/programs'; + +const StockOnHand = ({ facilityService, programService }) => { + const { facilityId, programId } = useParams(); + const dispatch = useDispatch(); + + const facility = useSelector(state => state['facilitiesStockOnHand']['facilityStockOnHand']); + const program = useSelector(state => state['programsStockOnHand']['programStockOnHand']); + + const downloadFacilityData = () => { + return facilityService.get(facilityId).then((facility) => { + dispatch(setFacilityStockOnHand(facility)); + }); + }; + + const downloadProgramData = () => { + return programService.get(programId).then((program) => { + dispatch(setProgramStockOnHand(program)); + }); + }; + + useEffect(() => { + Promise.all([downloadFacilityData(), downloadProgramData()]); + },[facilityId, programId]); + + return ( +
+

+ { facility && program && `Stock on Hand - ${facility.name} - ${program.name}`} +

+
+ ); +}; + +export default StockOnHand; Index: src/stock-on-hand-mobile/reducers/facilities.jsx =================================================================== diff -u -N -r7f9ffae3458e2f9994249398a1d526a3cbe861d6 -r9bbcb50a0fd738bf96b96418ce9735988b8103b3 --- src/stock-on-hand-mobile/reducers/facilities.jsx (.../facilities.jsx) (revision 7f9ffae3458e2f9994249398a1d526a3cbe861d6) +++ src/stock-on-hand-mobile/reducers/facilities.jsx (.../facilities.jsx) (revision 9bbcb50a0fd738bf96b96418ce9735988b8103b3) @@ -19,18 +19,26 @@ name: 'facilitiesStockOnHand', initialState: { userHomeFacilityStockOnHand: null, - supervisedFacilitiesStockOnHand: [] + supervisedFacilitiesStockOnHand: [], + facilityStockOnHand: null }, reducers: { setUserHomeFacilityStockOnHand: (state, action) => { state.userHomeFacilityStockOnHand = action.payload; }, setSupervisedFacilitiesStockOnHand: (state, action) => { state.supervisedFacilitiesStockOnHand = action.payload; + }, + setFacilityStockOnHand: (state, action) => { + state.facilityStockOnHand = action.payload; } } }); -export const {setUserHomeFacilityStockOnHand, setSupervisedFacilitiesStockOnHand} = facilitiesStockOnHandSlice.actions; +export const { + setUserHomeFacilityStockOnHand, + setSupervisedFacilitiesStockOnHand, + setFacilityStockOnHand +} = facilitiesStockOnHandSlice.actions; export default facilitiesStockOnHandSlice.reducer; Index: src/stock-on-hand-mobile/reducers/programs.jsx =================================================================== diff -u -N -r7f9ffae3458e2f9994249398a1d526a3cbe861d6 -r9bbcb50a0fd738bf96b96418ce9735988b8103b3 --- src/stock-on-hand-mobile/reducers/programs.jsx (.../programs.jsx) (revision 7f9ffae3458e2f9994249398a1d526a3cbe861d6) +++ src/stock-on-hand-mobile/reducers/programs.jsx (.../programs.jsx) (revision 9bbcb50a0fd738bf96b96418ce9735988b8103b3) @@ -19,18 +19,26 @@ name: 'programsStockOnHand', initialState: { programsStockOnHand: [], - supervisedProgramsStockOnHand: [] + supervisedProgramsStockOnHand: [], + programStockOnHand: {} }, reducers: { setProgramsStockOnHand: (state, action) => { state.programsStockOnHand = action.payload; }, setSupervisedProgramsStockOnHand: (state, action) => { state.supervisedProgramsStockOnHand = action.payload; + }, + setProgramStockOnHand: (state, action) => { + state.programStockOnHand = action.payload; } } }); -export const {setProgramsStockOnHand, setSupervisedProgramsStockOnHand} = programsStockOnHandSlice.actions; +export const { + setProgramsStockOnHand, + setSupervisedProgramsStockOnHand, + setProgramStockOnHand +} = programsStockOnHandSlice.actions; export default programsStockOnHandSlice.reducer; Index: src/stock-on-hand-mobile/stock-on-hand-app.jsx =================================================================== diff -u -N -r7f9ffae3458e2f9994249398a1d526a3cbe861d6 -r9bbcb50a0fd738bf96b96418ce9735988b8103b3 --- src/stock-on-hand-mobile/stock-on-hand-app.jsx (.../stock-on-hand-app.jsx) (revision 7f9ffae3458e2f9994249398a1d526a3cbe861d6) +++ src/stock-on-hand-mobile/stock-on-hand-app.jsx (.../stock-on-hand-app.jsx) (revision 9bbcb50a0fd738bf96b96418ce9735988b8103b3) @@ -20,6 +20,7 @@ import { setSupervisedProgramsStockOnHand } from './reducers/programs'; import { setUserHomeFacilityStockOnHand, setSupervisedFacilitiesStockOnHand } from './reducers/facilities'; import ProgramSelect from './pages/program-select'; +import StockOnHand from './pages/stock-on-hand'; const StockOnHandApp = ({ asynchronousService, @@ -64,13 +65,13 @@ }); return result; - } + }; const getFacilityById = (facilities, id) => { return facilities.filter(function(facility) { return facility.id === id; })[0]; - } + }; const getSupervisedFacilities = (programId, permissions, facilities) => { const facilityIds = []; @@ -96,13 +97,13 @@ }); return result; - } + }; const dispatchData = (actions) => { actions.forEach((action) => { dispatch(action); - }) - } + }); + }; useEffect(() => { facilityFactory.getUserHomeFacility().then((facility) => { @@ -126,8 +127,6 @@ setSupervisedFacilitiesStockOnHand(supervisedFacilities) ]); - }).catch((error) => { - console.log(error); }); }); } ,[facilityFactory]); @@ -143,6 +142,15 @@ hashType='hashbang' > + + { + userHomeFacilityStore && + + } + { userHomeFacilityStore && Index: src/stock-on-hand-mobile/stock-on-hand.routes.js =================================================================== diff -u -N -rd337a0ac836544c6a7201f924878e2fd5f88370e -r9bbcb50a0fd738bf96b96418ce9735988b8103b3 --- src/stock-on-hand-mobile/stock-on-hand.routes.js (.../stock-on-hand.routes.js) (revision d337a0ac836544c6a7201f924878e2fd5f88370e) +++ src/stock-on-hand-mobile/stock-on-hand.routes.js (.../stock-on-hand.routes.js) (revision 9bbcb50a0fd738bf96b96418ce9735988b8103b3) @@ -45,6 +45,13 @@ } }, accessRights: [STOCKMANAGEMENT_RIGHTS.STOCK_CARDS_VIEW] - }); + }) + .state('openlmis.stockmanagement.stockOnHandMobile.stockOnHand', { + url: '/stockOnHand/:facilityId/:programId', + isOffline: true, + showInNavigation: false, + showInNavigationOnLowResolutions: false, + accessRights: [STOCKMANAGEMENT_RIGHTS.STOCK_CARDS_VIEW] + }); } })(); Index: src/stock-on-hand-mobile/stock-on-hand.wrapper.jsx =================================================================== diff -u -N -r7f9ffae3458e2f9994249398a1d526a3cbe861d6 -r9bbcb50a0fd738bf96b96418ce9735988b8103b3 --- src/stock-on-hand-mobile/stock-on-hand.wrapper.jsx (.../stock-on-hand.wrapper.jsx) (revision 7f9ffae3458e2f9994249398a1d526a3cbe861d6) +++ src/stock-on-hand-mobile/stock-on-hand.wrapper.jsx (.../stock-on-hand.wrapper.jsx) (revision 9bbcb50a0fd738bf96b96418ce9735988b8103b3) @@ -36,7 +36,7 @@ return { template: '
', replace: true, - link: function ($scope) { + link: function () { const app = document.getElementById('mobileApp'); ReactDOM.render(