Skip to content
Snippets Groups Projects
Commit 664e8341 authored by imranasghar96@hotmail.com's avatar imranasghar96@hotmail.com
Browse files

Update img input dialog style, fix linting errors

parent a160f11d
Branches
No related tags found
No related merge requests found
...@@ -29,7 +29,7 @@ import DialogContentText from '@material-ui/core/DialogContentText'; ...@@ -29,7 +29,7 @@ import DialogContentText from '@material-ui/core/DialogContentText';
import DialogActions from '@material-ui/core/DialogActions'; import DialogActions from '@material-ui/core/DialogActions';
import TextField from '@material-ui/core/TextField'; import TextField from '@material-ui/core/TextField';
import Checkbox from '@material-ui/core/Checkbox'; import Checkbox from '@material-ui/core/Checkbox';
import FormControlLabel from "@material-ui/core/FormControlLabel"; import FormControlLabel from '@material-ui/core/FormControlLabel';
import ClickAwayListener from '@material-ui/core/ClickAwayListener'; import ClickAwayListener from '@material-ui/core/ClickAwayListener';
import { SketchPicker } from 'react-color'; import { SketchPicker } from 'react-color';
import { v4 as uuid } from 'uuid'; import { v4 as uuid } from 'uuid';
...@@ -83,35 +83,35 @@ class AnnotationCreation extends Component { ...@@ -83,35 +83,35 @@ class AnnotationCreation extends Component {
this.state = { this.state = {
activeTool: 'cursor', activeTool: 'cursor',
textBody: '',
closedMode: 'closed', closedMode: 'closed',
colorPopoverOpen: false, colorPopoverOpen: false,
currentColorType: false, currentColorType: false,
fillColor: null, fillColor: null,
imgConstrain: false,
lineWeightPopoverOpen: false, lineWeightPopoverOpen: false,
popoverAnchorEl: null, popoverAnchorEl: null,
popoverLineWeightAnchorEl: null, popoverLineWeightAnchorEl: null,
strokeColor: '#00BFFF', strokeColor: '#00BFFF',
strokeWidth: 1, strokeWidth: 1,
svg: null, svg: null,
textBody: '',
xywh: null, xywh: null,
imgConstrain: false, imgHeight: {
imgWidth: {
value: '',
srcValue: '',
lastSubmittedValue: '', lastSubmittedValue: '',
srcValue: '',
validity: 0, validity: 0,
},
imgHeight: {
value: '', value: '',
srcValue: '', },
imgWidth: {
lastSubmittedValue: '', lastSubmittedValue: '',
srcValue: '',
validity: 0, validity: 0,
value: '',
}, },
imgUrl: { imgUrl: {
value: '',
lastSubmittedValue: '', lastSubmittedValue: '',
validity: 0, validity: 0,
value: '',
}, },
openAddImgDialog: false, openAddImgDialog: false,
...annoState, ...annoState,
...@@ -206,12 +206,12 @@ class AnnotationCreation extends Component { ...@@ -206,12 +206,12 @@ class AnnotationCreation extends Component {
let open = true; let open = true;
const { imgUrl, imgHeight, imgWidth } = this.state; const { imgUrl, imgHeight, imgWidth } = this.state;
const expression = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi; const expression = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/;
const regex = new RegExp(expression); const regex = new RegExp(expression);
const urlValidity = imgUrl.value.match(regex) ? 1 : 2; const urlValidity = imgUrl.value.match(regex) ? 1 : 2;
const widthValidity = imgWidth.value > 0 ? 1 : 2; const widthValidity = imgWidth.value > 0 ? 1 : 2;
const heightValidity = imgHeight.value > 0 ? 1 : 2; const heightValidity = imgHeight.value > 0 ? 1 : 2;
if (urlValidity == 1 && widthValidity == 1 && heightValidity == 1) { if (urlValidity === 1 && widthValidity === 1 && heightValidity === 1) {
open = false; open = false;
} }
...@@ -220,19 +220,19 @@ class AnnotationCreation extends Component { ...@@ -220,19 +220,19 @@ class AnnotationCreation extends Component {
...imgUrl, ...imgUrl,
value: imgUrl.value, value: imgUrl.value,
validity: urlValidity, validity: urlValidity,
lastSubmittedValue: urlValidity == 1 ? imgUrl.value : imgUrl.lastSubmittedValue, lastSubmittedValue: urlValidity === 1 ? imgUrl.value : imgUrl.lastSubmittedValue,
}, },
imgHeight: { imgHeight: {
...imgHeight, ...imgHeight,
value: imgHeight.value, value: imgHeight.value,
validity: heightValidity, validity: heightValidity,
lastSubmittedValue: heightValidity == 1 ? imgHeight.value : imgHeight.lastSubmittedValue, lastSubmittedValue: heightValidity === 1 ? imgHeight.value : imgHeight.lastSubmittedValue,
}, },
imgWidth: { imgWidth: {
...imgWidth, ...imgWidth,
value: imgWidth.value, value: imgWidth.value,
validity: widthValidity, validity: widthValidity,
lastSubmittedValue: widthValidity == 1 ? imgWidth.value : imgWidth.lastSubmittedValue, lastSubmittedValue: widthValidity === 1 ? imgWidth.value : imgWidth.lastSubmittedValue,
}, },
openAddImgDialog: open, openAddImgDialog: open,
}); });
...@@ -286,6 +286,7 @@ class AnnotationCreation extends Component { ...@@ -286,6 +286,7 @@ class AnnotationCreation extends Component {
this.setState({ this.setState({
imgUrl: { imgUrl: {
...imgUrl, ...imgUrl,
validity: 1,
value: url, value: url,
}, },
imgHeight: { imgHeight: {
...@@ -300,7 +301,13 @@ class AnnotationCreation extends Component { ...@@ -300,7 +301,13 @@ class AnnotationCreation extends Component {
}, },
}); });
} catch (e) { } catch (e) {
console.error('Error! Dimensions could not be retrieved from image.'); this.setState({
imgUrl: {
...imgUrl,
validity: 2,
value : url,
},
});
} }
} }
...@@ -579,35 +586,37 @@ class AnnotationCreation extends Component { ...@@ -579,35 +586,37 @@ class AnnotationCreation extends Component {
</ToggleButton> </ToggleButton>
</Grid> </Grid>
<Dialog open={openAddImgDialog} fullWidth minWidth="20%" onClose={() => this.handleImgDialogChange(false)} aria-labelledby="form-dialog-title"> <Dialog open={openAddImgDialog} fullWidth minWidth="20%" onClose={() => this.handleImgDialogChange(false)} aria-labelledby="form-dialog-title">
<DialogTitle id="form-dialog-title">Insert/Edit Image</DialogTitle> <DialogTitle id="form-dialog-title">
<Typography variant="h2">Insert image</Typography>
</DialogTitle>
<DialogContent> <DialogContent>
<DialogContentText> <DialogTitle id="form-dialog-subtitle-1" style={{paddingLeft: 0}}>
Source <Typography variant="MuiTypography-h3">Image source</Typography>
</DialogContentText> </DialogTitle>
<TextField <TextField
value={imgUrl.value} value={imgUrl.value}
onChange={e => this.setImgUrl(e.target.value)} onChange={e => this.setImgUrl(e.target.value)}
onBlur={e => this.getImgDimensions(e.target.value)} onBlur={e => this.getImgDimensions(e.target.value)}
error={imgUrl.validity == 2} error={imgUrl.validity == 2}
helperText={imgUrl.validity == 2 ? "Url Invalid" : ""} helperText={imgUrl.validity === 2 ? "Invalid URL" : ""}
margin="dense" margin="dense"
id="source" id="source"
label="Image Url" label="Image URL"
type="url" type="url"
fullWidth fullWidth
/> />
</DialogContent> </DialogContent>
<DialogContent> <DialogContent>
<DialogContentText> <DialogTitle id="form-dialog-subtitle-2" style={{paddingLeft: 0}}>
Dimensions <Typography variant="MuiTypography-h3">Image dimensions</Typography>
</DialogContentText> </DialogTitle>
<TextField <TextField
value={imgWidth.value} value={imgWidth.value}
style = {{width: 100, marginRight: 10}} style = {{width: 100, marginRight: 10}}
onChange={e => this.setImgWidth(e.target.value)} onChange={e => this.setImgWidth(e.target.value)}
onBlur={(e) => this.isConstrained(e)} onBlur={(e) => this.isConstrained(e)}
error={imgWidth.validity == 2} error={imgWidth.validity == 2}
helperText={imgWidth.validity == 2 ? "Invalid Width" : ""} helperText={imgWidth.validity === 2 ? "Invalid width" : ""}
margin="dense" margin="dense"
id="width" id="width"
label="Width" label="Width"
...@@ -619,8 +628,8 @@ class AnnotationCreation extends Component { ...@@ -619,8 +628,8 @@ class AnnotationCreation extends Component {
style = {{width: 100, marginLeft: 10 }} style = {{width: 100, marginLeft: 10 }}
onChange={e => this.setImgHeight(e.target.value)} onChange={e => this.setImgHeight(e.target.value)}
onBlur={(e) => this.isConstrained(e)} onBlur={(e) => this.isConstrained(e)}
error={imgHeight.validity == 2} error={imgHeight.validity === 2}
helperText={imgHeight.validity == 2 ? "Negative or invalid height." : ""} helperText={imgHeight.validity === 2 ? "Invalid height" : ""}
margin="dense" margin="dense"
id="height" id="height"
label="Height" label="Height"
...@@ -633,19 +642,15 @@ class AnnotationCreation extends Component { ...@@ -633,19 +642,15 @@ class AnnotationCreation extends Component {
checked={imgConstrain} checked={imgConstrain}
onChange={(e) => this.handleConstrainCheck(e)} onChange={(e) => this.handleConstrainCheck(e)}
inputProps={{ 'aria-label': 'primary checkbox' }} inputProps={{ 'aria-label': 'primary checkbox' }}
style = {{ marginLeft: 10 }} style = {{ marginLeft: 30 }}
/> />
} }
label="Constrain Proportions" label="Constrain proportions"
/> />
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button onClick={() => this.handleImgDialogChange(false)} color="primary"> <Button onClick={() => this.handleImgDialogChange(false)}>Cancel</Button>
Cancel <Button variant="contained" onClick={this.handleImgDialogSubmit} color="primary">Add</Button>
</Button>
<Button onClick={this.handleImgDialogSubmit} color="primary">
Add
</Button>
</DialogActions> </DialogActions>
</Dialog> </Dialog>
<Grid item xs={12}> <Grid item xs={12}>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment