-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from linea-it/205-update-product
Update product metadata and Auxiliary files.
- Loading branch information
Showing
15 changed files
with
611 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.0.2 on 2023-11-09 13:31 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0026_productcontent_alias'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='product', | ||
name='updated_at', | ||
field=models.DateTimeField(auto_now=True), | ||
), | ||
] |
25 changes: 25 additions & 0 deletions
25
backend/core/migrations/0028_productfile_created_productfile_updated.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 4.0.2 on 2023-11-09 13:45 | ||
|
||
from django.db import migrations, models | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0027_product_updated_at'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='productfile', | ||
name='created', | ||
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name='productfile', | ||
name='updated', | ||
field=models.DateTimeField(auto_now=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import CloseIcon from '@mui/icons-material/Close' | ||
import FormGroup from '@mui/material/FormGroup' | ||
import IconButton from '@mui/material/IconButton' | ||
import InputAdornment from '@mui/material/InputAdornment' | ||
import TextField from '@mui/material/TextField' | ||
import prettyBytes from 'pretty-bytes' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import { deleteProductFile } from '../services/product' | ||
|
||
export default function ProductFileTextField(props) { | ||
const { id, role, name, size, readOnly, onDelete } = props | ||
|
||
const handleRemoveFile = () => { | ||
deleteProductFile(id) | ||
.then(() => { | ||
// Forcar um reload dos arquivos | ||
onDelete(id) | ||
}) | ||
.catch(res => { | ||
if (res.response.status === 500) { | ||
// TODO: Tratamento erro no backend | ||
} | ||
}) | ||
} | ||
|
||
const getLabelByRole = role => { | ||
let label = '' | ||
switch (role) { | ||
case 0: | ||
label = 'Main File' | ||
break | ||
case 1: | ||
label = 'Description File' | ||
break | ||
case 2: | ||
label = 'Auxiliary File' | ||
break | ||
} | ||
return label | ||
} | ||
|
||
return ( | ||
<FormGroup row key={`display_file_${id}`}> | ||
<TextField | ||
value={name} | ||
label={getLabelByRole(role)} | ||
readOnly={true} | ||
fullWidth | ||
InputProps={ | ||
readOnly === false | ||
? { | ||
endAdornment: ( | ||
<InputAdornment position="end"> | ||
<IconButton | ||
onClick={handleRemoveFile} | ||
// onMouseDown={handleMouseDownPassword} | ||
edge="end" | ||
> | ||
<CloseIcon /> | ||
</IconButton> | ||
</InputAdornment> | ||
) | ||
} | ||
: {} | ||
} | ||
helperText={prettyBytes(Number(size))} | ||
/> | ||
</FormGroup> | ||
) | ||
} | ||
ProductFileTextField.propTypes = { | ||
id: PropTypes.number.isRequired, | ||
name: PropTypes.string.isRequired, | ||
size: PropTypes.number.isRequired, | ||
role: PropTypes.number.isRequired, | ||
onDelete: PropTypes.func.isRequired, | ||
readOnly: PropTypes.bool | ||
} | ||
ProductFileTextField.defaultProps = { | ||
readOnly: false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.