Skip to content

Commit

Permalink
feat: add ControlEntrySample form screen (#382)
Browse files Browse the repository at this point in the history
* RM#74578
  • Loading branch information
gca-axelor authored Feb 9, 2024
1 parent cbb5ad3 commit bafd096
Show file tree
Hide file tree
Showing 36 changed files with 1,248 additions and 88 deletions.
25 changes: 25 additions & 0 deletions packages/apps/quality/src/api/control-entry-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {
axiosApiProvider,
createStandardFetch,
createStandardSearch,
getEndOfDay,
Expand Down Expand Up @@ -80,3 +81,27 @@ export async function fetchControlEntryById({controlEntryId}) {
fieldKey: 'quality_controlEntry',
});
}

export async function updateControlEntry({controlEntry}) {
return axiosApiProvider.post({
url: '/ws/rest/com.axelor.apps.quality.db.ControlEntry/',
data: {
data: controlEntry,
},
});
}

export async function getProgressValues({
controlEntryId,
characteristicId,
sampleId,
}) {
return axiosApiProvider.post({
url: 'ws/aos/controlentry/progressValues',
data: {
controlEntryId,
characteristicId,
sampleId,
},
});
}
54 changes: 53 additions & 1 deletion packages/apps/quality/src/api/control-entry-sample-line-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import {createStandardSearch} from '@axelor/aos-mobile-core';
import {
createStandardSearch,
createStandardFetch,
axiosApiProvider,
} from '@axelor/aos-mobile-core';

const createControlEntrySampleLineCriteria = controlEntrySampleId => {
return [
Expand All @@ -40,3 +44,51 @@ export async function searchControlEntrySampleLine({
page: page,
});
}

const createSampleLineOfControlEntryCriteria = controlEntryId => {
return [
{
fieldName: 'controlEntrySample.controlEntry.id',
operator: '=',
value: controlEntryId,
},
];
};

export async function searchControlEntrySampleLineOfControlEntry({
controlEntryId,
}) {
return createStandardSearch({
model: 'com.axelor.apps.quality.db.ControlEntryPlanLine',
criteria: createSampleLineOfControlEntryCriteria(controlEntryId),
fieldKey: 'quality_controlEntrySampleLine',
sortKey: 'quality_controlEntrySampleLine',
numberElementsByPage: null,
page: 0,
});
}

export async function fetchControlEntrySampleLine({id}) {
return createStandardFetch({
model: 'com.axelor.apps.quality.db.ControlEntryPlanLine',
id,
fieldKey: 'quality_controlEntrySampleLine',
});
}

export async function checkComformity({object}) {
return axiosApiProvider.post({
url: 'ws/action',
data: {
action:
'action-quality-control-entry-line-method-control-conformity,save',
data: {
context: {
...object,
_model: 'com.axelor.apps.quality.db.ControlEntryPlanLine',
},
},
model: 'com.axelor.apps.quality.db.ControlEntryPlanLine',
},
});
}
27 changes: 27 additions & 0 deletions packages/apps/quality/src/api/control-plan-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2024 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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/>.
*/

import {createStandardFetch} from '@axelor/aos-mobile-core';

export async function fetchControlPlanById({id}) {
return createStandardFetch({
model: 'com.axelor.apps.quality.db.ControlPlan',
id,
fieldKey: 'quality_controlPlan',
});
}
10 changes: 9 additions & 1 deletion packages/apps/quality/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
export {
fetchControlEntryById as fetchControlEntryByIdApi,
searchControlEntry as searchControlEntryApi,
updateControlEntry as updateControlEntryApi,
getProgressValues as getProgressValuesApi,
} from './control-entry-api';
export {searchControlEntrySample as searchControlEntrySampleApi} from './control-entry-sample-api';
export {searchControlEntrySampleLine as searchControlEntrySampleLineApi} from './control-entry-sample-line-api';
export {
checkComformity,
fetchControlEntrySampleLine as fetchControlEntrySampleLineApi,
searchControlEntrySampleLine as searchControlEntrySampleLineApi,
searchControlEntrySampleLineOfControlEntry as searchControlEntrySampleLineOfControlEntryApi,
} from './control-entry-sample-line-api';
export {fetchControlPlanById as fetchControlPlanByIdApi} from './control-plan-api';
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const ControlEntryCard = ({
<DateDisplay date={entryDateTime} />
</View>
<View style={styles.childrenContainer}>
<Text>{`${I18n.t('Quality_Sample')} : ${sampleCount}`}</Text>
<Text>{`${I18n.t('Quality_SampleCount')} : ${sampleCount}`}</Text>
<ProgressBar
style={styles.progressBar}
value={numberSampleFilled}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2024 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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/>.
*/

import React from 'react';
import {StyleSheet, View} from 'react-native';
import {DateDisplay, useSelector, useTranslator} from '@axelor/aos-mobile-core';
import {Badge, Text, useThemeColor} from '@axelor/aos-mobile-ui';
import {ControlEntry} from '../../../types';

const ControlEntryHeader = ({}) => {
const I18n = useTranslator();
const Colors = useThemeColor();

const {controlEntry} = useSelector((state: any) => state.controlEntry);

return (
<View>
<View style={styles.row}>
<Text writingType="title">{controlEntry.name}</Text>
<Badge
color={ControlEntry.getStatusColor(controlEntry.statusSelect, Colors)}
title={ControlEntry.getStatus(controlEntry.statusSelect, I18n)}
/>
</View>
<View style={styles.row}>
<Text>{`${I18n.t('Quality_SampleCount')} : ${
controlEntry.sampleCount
}`}</Text>
<DateDisplay date={controlEntry.entryDateTime} />
</View>
<Text>{`${I18n.t('Quality_ControlPlan')} : ${
controlEntry.controlPlan?.name
}`}</Text>
</View>
);
};

const styles = StyleSheet.create({
row: {
justifyContent: 'space-between',
flexDirection: 'row',
alignItems: 'center',
},
});

export default ControlEntryHeader;
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2024 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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/>.
*/

import React from 'react';
import {StyleSheet, View} from 'react-native';
import {useSelector, useTranslator} from '@axelor/aos-mobile-core';
import {Badge, Text, useThemeColor} from '@axelor/aos-mobile-ui';
import {ControlEntry} from '../../../types';

const ControlEntrySampleLineHeader = ({}) => {
const I18n = useTranslator();
const Colors = useThemeColor();

const {sampleLine} = useSelector(
(state: any) => state.controlEntrySampleLine,
);

if (sampleLine?.id == null) {
return null;
}

return (
<View>
<View style={styles.row}>
<Text>{`${I18n.t('Quality_Sample')} : ${
sampleLine.controlEntrySample?.fullName
}`}</Text>
<Badge
color={ControlEntry.getSampleResultColor(
sampleLine.resultSelect,
Colors,
)}
title={ControlEntry.getSampleResultTitle(
sampleLine.resultSelect,
I18n,
)}
/>
</View>
<Text>{`${I18n.t('Quality_Characteristic')} : ${
sampleLine.controlPlanLine?.characteristic?.name
}`}</Text>
</View>
);
};

const styles = StyleSheet.create({
row: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
},
badge: {
margin: 0,
width: null,
},
});

export default ControlEntrySampleLineHeader;
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Axelor Business Solutions
*
* Copyright (C) 2024 Axelor (<http://axelor.com>).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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/>.
*/

import React, {useMemo} from 'react';
import {StyleSheet, View} from 'react-native';
import {Button, Icon, useThemeColor} from '@axelor/aos-mobile-ui';

const NavigationButton = ({position, onPress, icon, disabled}) => {
const Colors = useThemeColor();

const positionStyle = useMemo(() => ({[position]: '15%'}), [position]);

return (
<View style={styles.buttonContainer}>
<Button
onPress={onPress}
color={Colors.priorityColor}
disabled={disabled}
iconName={icon}
/>
<Icon
name={`chevron-${position}`}
style={[styles.chevron, positionStyle]}
/>
</View>
);
};

const styles = StyleSheet.create({
buttonContainer: {
width: '45%',
alignItems: 'center',
justifyContent: 'center',
},
chevron: {
position: 'absolute',
},
});

export default NavigationButton;
3 changes: 3 additions & 0 deletions packages/apps/quality/src/components/atoms/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
*/

export {default as ControlEntryCard} from './ControlEntryCard/ControlEntryCard';
export {default as ControlEntryHeader} from './ControlEntryHeader/ControlEntryHeader';
export {default as ControlEntrySampleCard} from './ControlEntrySampleCard/ControlEntrySampleCard';
export {default as ControlEntrySampleLineHeader} from './ControlEntrySampleLineHeader/ControlEntrySampleLineHeader';
export {default as NavigationButton} from './NavigationButton/NavigationButton';
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,33 @@
*/

import React from 'react';
import {useTranslator} from '@axelor/aos-mobile-core';
import {useDispatch, useSelector, useTranslator} from '@axelor/aos-mobile-core';
import {Button} from '@axelor/aos-mobile-ui';
import {updateControlEntry} from '../../../features/controlEntrySlice';
import {ControlEntry} from '../../../types';

const ControlEntryDetailsButtons = () => {
const dispatch = useDispatch();
const I18n = useTranslator();

const {controlEntry} = useSelector((state: any) => state.controlEntry);

return (
<Button title={I18n.t('Quality_MarkAsCompleted')} iconName="check-lg" />
<Button
title={I18n.t('Quality_MarkAsCompleted')}
onPress={() => {
dispatch(
(updateControlEntry as any)({
controlEntry: {
...controlEntry,
statusSelect: ControlEntry.status.Completed,
},
controlEntryId: controlEntry.id,
}),
);
}}
iconName="check-lg"
/>
);
};

Expand Down
Loading

0 comments on commit bafd096

Please sign in to comment.