diff --git a/backend/app/admin.py b/backend/app/admin.py index 53557db..9dc2a39 100644 --- a/backend/app/admin.py +++ b/backend/app/admin.py @@ -3,7 +3,7 @@ # Register your models here. class ItemAdmin(admin.ModelAdmin): - list_display = ('id','name' , 'brand','state','power', 'price','type', 'quantity','description', 'modification_reason', 'creation', 'removed', 'modification_date') + list_display = ('id','name' , 'brand','state','power', 'price','type', 'quantity','description','pretable', 'modification_reason', 'creation', 'removed', 'modification_date') # Register your models here. diff --git a/backend/app/models.py b/backend/app/models.py index d9fffa6..ecdb8e0 100644 --- a/backend/app/models.py +++ b/backend/app/models.py @@ -40,6 +40,7 @@ class Item(models.Model): description = models.CharField(max_length = 10000, null=True, blank=True) modification_reason = models.CharField(max_length = 500, null=True, blank=True) type = models.CharField(max_length=20, choices=TYPES_CHOICES1) + pretable = models.BooleanField( default=False) creation = models.DateTimeField(auto_now_add=True) removed = models.DateTimeField(null=True, blank=True) modification_date = models.DateTimeField(auto_now=True) diff --git a/backend/app/serializer.py b/backend/app/serializer.py index 6d34707..7cc9588 100644 --- a/backend/app/serializer.py +++ b/backend/app/serializer.py @@ -7,7 +7,7 @@ class ItemSerializer(serializers.ModelSerializer): class Meta: model = Item - fields = ['id','name' , 'brand','state','power', 'price','type', 'quantity','description', 'modification_reason', 'creation', 'removed', 'modification_date'] + fields = ['id','name' , 'brand','state','power', 'price','type', 'quantity','description','pretable', 'modification_reason', 'creation', 'removed', 'modification_date'] class LoginSerializer(serializers.Serializer): diff --git a/backend/app/views.py b/backend/app/views.py index ce7c9c1..26da5e8 100644 --- a/backend/app/views.py +++ b/backend/app/views.py @@ -155,6 +155,7 @@ def get(self, request): "quantity": item.quantity, "description" : item.description, "modification_reason": item.modification_reason, + "pretable" : item.pretable, "creation": item.creation, "removed": item.removed, "modification_date": item.modification_date, @@ -217,7 +218,9 @@ def put(self, request, pk): if (request.data.get("type") != None): item.type = request.data.get("type") if (request.data.get("description") != None): - item.description = request.data.get("description") + item.description = request.data.get("description") + if (request.data.get("pretable") != None): + item.pretable = request.data.get("pretable") if (request.data.get("quantity") != None): item.quantity = int(request.data.get("quantity")) if item.quantity == 0: @@ -267,6 +270,7 @@ def put(self, request, pk): "type": item.type, "description" :item.description, "state": item.state, + "pretable" : item.pretable, "quantity": item.quantity, "modification_reason": item.modification_reason, "creation": item.creation, diff --git a/src/components/FormAdd.jsx b/src/components/FormAdd.jsx index f5dd5a5..898b090 100644 --- a/src/components/FormAdd.jsx +++ b/src/components/FormAdd.jsx @@ -24,6 +24,12 @@ const options2 = [ { key: 'casse', text: 'Cassé', value: 'casse' }, ]; + +const options3 = [ + { key: 'true', text: 'Yes', value: true }, + { key: 'false', text: 'No', value: false }, +] + const FormAdd = (props) => { const [values, setValues] = useState({}); const [errors, setErrors] = useState({}); @@ -44,6 +50,9 @@ const FormAdd = (props) => { if (!values.type) { newErrors.type = "Type obligatoire"; } + if(!values.pretable){ + newErrors.type = "Prétabilité obligatoire"; + } setErrors(newErrors); return Object.keys(newErrors).length === 0; @@ -66,6 +75,7 @@ const FormAdd = (props) => { quantity: values.quantity, state: values.state, power: values.power, + pretable: values.pretable }; const token = localStorage.getItem('token'); const requestOptions = { @@ -160,6 +170,14 @@ const FormAdd = (props) => { name='type' onChange={(_, { value }) => setValues({ ...values, type: value })} /> + setValues({ ...values, pretable: value })} + /> { onChange={handleChange} value={values.description} /> +
Valider diff --git a/src/components/FormEdit.jsx b/src/components/FormEdit.jsx index cccea2c..87137bb 100644 --- a/src/components/FormEdit.jsx +++ b/src/components/FormEdit.jsx @@ -18,6 +18,11 @@ const options2 = [ { key: 'casse', text: 'Cassé', value: 'casse' }, ]; +const options3 = [ + { key: 'true', text: 'Yes', value: true }, + { key: 'false', text: 'No', value: false }, +] + const FormEdit = (props) => { const [values, setValues] = useState({ reference: props.name, @@ -29,6 +34,7 @@ const FormEdit = (props) => { type: props.type, reason: props.reason, state: props.state, + pretable : props.pretable, }); const [errors, setErrors] = useState({}); @@ -55,6 +61,7 @@ const FormEdit = (props) => { power : values.power, modification_reason : values.reason, state: values.state, + pretable : values.pretable, }; const token = localStorage.getItem('token'); @@ -154,6 +161,14 @@ const FormEdit = (props) => { onChange={(_, { value }) => setValues({ ...values, type: value })} value={values.type} // Correction : Utilisation de values au lieu de props /> + setValues({ ...values, pretable: value })} + /> { onChange={handleChange} value={values.description} /> + dispatch({ type: 'close' })} - state={props.state} description={props.description} power={props.power} item_id={props.item_id} name={props.name} brand={props.brand} type={props.type} quantity={props.quantity} price = {props.price} date={props.date} /> + state={props.state} description={props.description} power={props.power} item_id={props.item_id} pretable={props.pretable} name={props.name} brand={props.brand} type={props.type} quantity={props.quantity} price = {props.price} date={props.date} />
diff --git a/src/components/TableData.jsx b/src/components/TableData.jsx index e5741d6..ec2548f 100644 --- a/src/components/TableData.jsx +++ b/src/components/TableData.jsx @@ -52,13 +52,15 @@ function TableData() { const [qte, setQte] = useState('Quantité'); const [action, setAction] = useState('Actions'); const [supp, setSuppr] = useState('Date de suppression'); + const [pretable, setPretable] = useState('Pretable'); - - - useEffect(() => { - // actualiser userID - }, []); + function convertDataPret(my_var){ + if(my_var){ + return "Yes"; + } + return "No"; + } @@ -71,6 +73,7 @@ function TableData() { setQte("Quantité"); setAction("Actions"); setSuppr("Date de suppression"); + setPretable("Pretable"); } else { setSelection(); setRef(); @@ -79,6 +82,7 @@ function TableData() { setQte(); setAction(); setSuppr(); + setPretable(); } }, [isLargeScreen]); @@ -603,7 +607,7 @@ const handleDeselectButton = () => { dispatch({ type: 'CHANGE_SORT', column: 'power' })}>{power} dispatch({ type: 'CHANGE_SORT', column: 'price' })}>{price} dispatch({ type: 'CHANGE_SORT', column: 'quantity' })}>{qte} - + {pretable} {isLargeScreen && <>Modification dispatch({ type: 'CHANGE_SORT', column: 'creation' })}>Date d'ajout} {showDeleted ? dispatch({ type: 'CHANGE_SORT', column: 'removed' })} >{supp} : @@ -643,6 +647,7 @@ const handleDeselectButton = () => { {item.power} {item.price} {item.quantity} + {convertDataPret(item.pretable)} {isLargeScreen && <> {item.modification_reason ? item.modification_reason : '/'} {convertDateFormat(item.creation)}} @@ -657,8 +662,8 @@ const handleDeselectButton = () => { {!showDeleted && (userId !== 2) && isAuthenticated ? <> - - + + : null }