Skip to content

Commit

Permalink
added pretability
Browse files Browse the repository at this point in the history
  • Loading branch information
leopoldch committed Mar 15, 2024
1 parent 3e0b74c commit 83bb5ba
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 12 deletions.
2 changes: 1 addition & 1 deletion backend/app/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions backend/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion backend/app/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 5 additions & 1 deletion backend/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions src/components/FormAdd.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
Expand All @@ -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;
Expand All @@ -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 = {
Expand Down Expand Up @@ -160,6 +170,14 @@ const FormAdd = (props) => {
name='type'
onChange={(_, { value }) => setValues({ ...values, type: value })}
/>
<FormSelect
fluid
label='Pretable'
options={options3}
placeholder='Pretable'
name='pretable'
onChange={(_, { value }) => setValues({ ...values, pretable: value })}
/>
<FormTextArea
fluid
label='description'
Expand All @@ -168,6 +186,7 @@ const FormAdd = (props) => {
onChange={handleChange}
value={values.description}
/>

<ModalActions>
<div className={"form-add-actions"}>
<FormButton color='green' floated='right' content='Submit'>Valider</FormButton>
Expand Down
16 changes: 16 additions & 0 deletions src/components/FormEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,6 +34,7 @@ const FormEdit = (props) => {
type: props.type,
reason: props.reason,
state: props.state,
pretable : props.pretable,
});

const [errors, setErrors] = useState({});
Expand All @@ -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');

Expand Down Expand Up @@ -154,6 +161,14 @@ const FormEdit = (props) => {
onChange={(_, { value }) => setValues({ ...values, type: value })}
value={values.type} // Correction : Utilisation de values au lieu de props
/>
<FormSelect
fluid
label='Pretable'
options={options3}
placeholder='Pretable'
name='pretable'
onChange={(_, { value }) => setValues({ ...values, pretable: value })}
/>
<FormTextArea
fluid
label='description'
Expand All @@ -162,6 +177,7 @@ const FormEdit = (props) => {
onChange={handleChange}
value={values.description}
/>

<FormTextArea
fluid
label='reason'
Expand Down
2 changes: 1 addition & 1 deletion src/components/ModalEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function ModalEdit(props){
className={"form-edit"}
submission={props.submission}
closeModal={() => 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} />
</div>
</ModalContent>
</Modal>
Expand Down
21 changes: 13 additions & 8 deletions src/components/TableData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}



Expand All @@ -71,6 +73,7 @@ function TableData() {
setQte("Quantité");
setAction("Actions");
setSuppr("Date de suppression");
setPretable("Pretable");
} else {
setSelection(<Icon name="tasks" />);
setRef(<Icon name="address card outline" />);
Expand All @@ -79,6 +82,7 @@ function TableData() {
setQte(<Icon name="boxes" />);
setAction(<Icon name="edit outline" />);
setSuppr(<Icon name="delete calendar" />);
setPretable(<Icon name="paper plane outline"/>);
}
}, [isLargeScreen]);

Expand Down Expand Up @@ -603,7 +607,7 @@ const handleDeselectButton = () => {
<TableHeaderCell sorted={column === 'power' ? direction : null} onClick={() => dispatch({ type: 'CHANGE_SORT', column: 'power' })}>{power}</TableHeaderCell>
<TableHeaderCell sorted={column === 'price' ? direction : null} onClick={() => dispatch({ type: 'CHANGE_SORT', column: 'price' })}>{price}</TableHeaderCell>
<TableHeaderCell sorted={column === 'quantity' ? direction : null} onClick={() => dispatch({ type: 'CHANGE_SORT', column: 'quantity' })}>{qte}</TableHeaderCell>

<TableHeaderCell>{pretable}</TableHeaderCell>
{isLargeScreen && <><TableHeaderCell>Modification</TableHeaderCell><TableHeaderCell sorted={column === 'creation' ? direction : null} onClick={() => dispatch({ type: 'CHANGE_SORT', column: 'creation' })}>Date d'ajout</TableHeaderCell></>}
{showDeleted ? <TableHeaderCell sorted={column === 'removed' ? direction : null} onClick={() => dispatch({ type: 'CHANGE_SORT', column: 'removed' })} >{supp}</TableHeaderCell> :

Expand Down Expand Up @@ -643,6 +647,7 @@ const handleDeselectButton = () => {
<TableCell>{item.power}</TableCell>
<TableCell>{item.price}</TableCell>
<TableCell>{item.quantity}</TableCell>
<TableCell>{convertDataPret(item.pretable)}</TableCell>
{isLargeScreen && <>
<TableCell>{item.modification_reason ? item.modification_reason : '/'}</TableCell>
<TableCell>{convertDateFormat(item.creation)}</TableCell></>}
Expand All @@ -657,8 +662,8 @@ const handleDeselectButton = () => {
{!showDeleted && (userId !== 2) && isAuthenticated ?
<>
<TableCell>
<ModalEdit submission={handleSubmissionEdit} item_id={item.id} reason={item.modification_reason} state={item.state} power={item.power} name={item.name} brand={item.brand} type={item.type} description={item.description} price={item.price} quantity={item.quantity} date={item.creation} />
<ModalDelete submission={handleSubmission} item_id={item.id} reason={item.modification_reason} state={item.state} power={item.power} name={item.name} brand={item.brand} type={item.type} description={item.description} price={item.price} quantity={item.quantity} date={item.creation} />
<ModalEdit submission={handleSubmissionEdit} item_id={item.id} reason={item.modification_reason} state={item.state} power={item.power} name={item.name} brand={item.brand} type={item.type} description={item.description} pretable={item.pretable} price={item.price} quantity={item.quantity} date={item.creation} />
<ModalDelete submission={handleSubmission} item_id={item.id} reason={item.modification_reason} state={item.state} power={item.power} name={item.name} brand={item.brand} type={item.type} description={item.description} pretable={item.pretable} price={item.price} quantity={item.quantity} date={item.creation} />
</TableCell>
</> : null
}
Expand Down

0 comments on commit 83bb5ba

Please sign in to comment.