Skip to content
Snippets Groups Projects
Verified Commit ef26ae0c authored by Loïs Poujade's avatar Loïs Poujade
Browse files

Fix annotations on images

- set tsart/tend to null if currentTime is null (which mean we're not on
  a video)
- don't put default message if no time selector
- don't use null values if no annotations found
- avoid to create blank Fragment Selector
parent 3cd11bef
No related branches found
No related tags found
No related merge requests found
Pipeline #1272 canceled
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { import {
IconButton, Button, Paper, Grid, Popover, Divider, Button, Paper, Grid, Popover, Divider,
MenuList, MenuItem, ClickAwayListener, MenuList, MenuItem, ClickAwayListener,
} from '@material-ui/core'; } from '@material-ui/core';
import { Alarm, LastPage } from '@material-ui/icons'; import { Alarm, LastPage } from '@material-ui/icons';
...@@ -108,17 +108,20 @@ class AnnotationCreation extends Component { ...@@ -108,17 +108,20 @@ class AnnotationCreation extends Component {
...(props.config.annotation.defaults || {}), ...(props.config.annotation.defaults || {}),
}; };
const timeState = props.currentTime !== null
? { tend: Math.floor(props.currentTime) + 10, tstart: Math.floor(props.currentTime) }
: { tend: null, tstart: null };
this.state = { this.state = {
...toolState, ...toolState,
...timeState,
annoBody: '', annoBody: '',
colorPopoverOpen: false, colorPopoverOpen: false,
lineWeightPopoverOpen: false, lineWeightPopoverOpen: false,
popoverAnchorEl: null, popoverAnchorEl: null,
popoverLineWeightAnchorEl: null, popoverLineWeightAnchorEl: null,
svg: null, svg: null,
tend: Math.floor(props.currentTime) + 10,
textEditorStateBustingKey: 0, textEditorStateBustingKey: 0,
tstart: Math.floor(props.currentTime),
xywh: null, xywh: null,
...annoState, ...annoState,
}; };
...@@ -242,12 +245,13 @@ class AnnotationCreation extends Component { ...@@ -242,12 +245,13 @@ class AnnotationCreation extends Component {
const { const {
annoBody, tags, xywh, svg, tstart, tend, textEditorStateBustingKey, annoBody, tags, xywh, svg, tstart, tend, textEditorStateBustingKey,
} = this.state; } = this.state;
const t = (tstart && tend) ? `${tstart},${tend}` : null;
canvases.forEach((canvas) => { canvases.forEach((canvas) => {
const storageAdapter = config.annotation.adapter(canvas.id); const storageAdapter = config.annotation.adapter(canvas.id);
const anno = new WebAnnotation({ const anno = new WebAnnotation({
body: !annoBody.length ? `${secondsToHMS(tstart)} -> ${secondsToHMS(tend)}` : annoBody, body: (!annoBody.length && t) ? `${secondsToHMS(tstart)} -> ${secondsToHMS(tend)}` : annoBody,
canvasId: canvas.id, canvasId: canvas.id,
fragsel: { t: `${tstart},${tend}`, xywh }, fragsel: { t, xywh },
id: (annotation && annotation.id) || `${uuid()}`, id: (annotation && annotation.id) || `${uuid()}`,
manifestId: canvas.options.resource.id, manifestId: canvas.options.resource.id,
svg, svg,
...@@ -267,9 +271,9 @@ class AnnotationCreation extends Component { ...@@ -267,9 +271,9 @@ class AnnotationCreation extends Component {
this.setState({ this.setState({
annoBody: '', annoBody: '',
svg: null, svg: null,
tend: 0, tend: null,
textEditorStateBustingKey: textEditorStateBustingKey + 1, textEditorStateBustingKey: textEditorStateBustingKey + 1,
tstart: 0, tstart: null,
xywh: null, xywh: null,
}); });
} }
...@@ -586,7 +590,7 @@ AnnotationCreation.propTypes = { ...@@ -586,7 +590,7 @@ AnnotationCreation.propTypes = {
), ),
}), }),
}).isRequired, }).isRequired,
currentTime: PropTypes.number, currentTime: PropTypes.oneOfType([PropTypes.number, PropTypes.instanceOf(null)]),
id: PropTypes.string.isRequired, id: PropTypes.string.isRequired,
paused: PropTypes.bool, paused: PropTypes.bool,
receiveAnnotation: PropTypes.func.isRequired, receiveAnnotation: PropTypes.func.isRequired,
...@@ -599,7 +603,7 @@ AnnotationCreation.defaultProps = { ...@@ -599,7 +603,7 @@ AnnotationCreation.defaultProps = {
annotation: null, annotation: null,
canvases: [], canvases: [],
closeCompanionWindow: () => {}, closeCompanionWindow: () => {},
currentTime: 0, currentTime: null,
paused: true, paused: true,
setCurrentTime: () => {}, setCurrentTime: () => {},
setSeekTo: () => {}, setSeekTo: () => {},
......
...@@ -46,9 +46,10 @@ export default class WebAnnotation { ...@@ -46,9 +46,10 @@ export default class WebAnnotation {
return bodies; return bodies;
} }
/** */ /** Fill target object with selectors (if any), else returns target url */
target() { target() {
if (!this.svg && !this.fragsel) { if (!this.svg
&& (!this.fragsel || !Object.values(this.fragsel).find((e) => e !== null))) {
return this.canvasId; return this.canvasId;
} }
const target = { source: this.source() }; const target = { source: this.source() };
......
...@@ -25,7 +25,7 @@ function mapStateToProps(state, { id: companionWindowId, windowId }) { ...@@ -25,7 +25,7 @@ function mapStateToProps(state, { id: companionWindowId, windowId }) {
const canvases = getVisibleCanvases(state, { windowId }); const canvases = getVisibleCanvases(state, { windowId });
const annotation = getPresentAnnotationsOnSelectedCanvases(state, { windowId }) const annotation = getPresentAnnotationsOnSelectedCanvases(state, { windowId })
.flatMap((annoPage) => annoPage.json.items) .flatMap((annoPage) => annoPage.json.items || [])
.find((annot) => annot.id === annotationid); .find((annot) => annot.id === annotationid);
return { return {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment