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

Revert 46b5896a

One target FragmentSelector may contains multiple MediaFragment; instead of
multiples FragmentSelectors for one target
parent 08c7b91b
Branches
No related tags found
No related merge requests found
...@@ -5,11 +5,10 @@ function createSubject(args = {}) { ...@@ -5,11 +5,10 @@ function createSubject(args = {}) {
return new WebAnnotation({ return new WebAnnotation({
body: 'body', body: 'body',
canvasId: 'canvasId', canvasId: 'canvasId',
fragsel: { t: '5,10', xywh: 'xywh' },
id: 'id', id: 'id',
svg: 'svg', svg: 'svg',
tags: ['tags'], tags: ['tags'],
timing: [1, 3],
xywh: 'xywh',
...args, ...args,
}); });
} }
...@@ -18,14 +17,14 @@ describe('WebAnnotation', () => { ...@@ -18,14 +17,14 @@ describe('WebAnnotation', () => {
let subject = createSubject(); let subject = createSubject();
describe('constructor', () => { describe('constructor', () => {
it('sets instance accessors', () => { it('sets instance accessors', () => {
['body', 'canvasId', 'id', 'svg', 'xywh'].forEach((prop) => { ['body', 'canvasId', 'id', 'svg'].forEach((prop) => {
expect(subject[prop]).toBe(prop); expect(subject[prop]).toBe(prop);
}); });
expect(subject.timing).toStrictEqual([1, 3]); expect(subject.fragsel).toStrictEqual({ t: '5,10', xywh: 'xywh' });
}); });
}); });
describe('target', () => { describe('target', () => {
it('with svg, xywh and timing', () => { it('with svg and xywh', () => {
expect(subject.target()).toEqual({ expect(subject.target()).toEqual({
selector: [ selector: [
{ {
...@@ -34,18 +33,14 @@ describe('WebAnnotation', () => { ...@@ -34,18 +33,14 @@ describe('WebAnnotation', () => {
}, },
{ {
type: 'FragmentSelector', type: 'FragmentSelector',
value: 'xywh=xywh', value: 't=5,10&xywh=xywh',
},
{
type: 'FragmentSelector',
value: 't=1,3',
}, },
], ],
source: 'canvasId', source: 'canvasId',
}); });
}); });
it('with svg only', () => { it('with svg only', () => {
subject = createSubject({ timing: null, xywh: null }); subject = createSubject({ fragsel: null });
expect(subject.target()).toEqual({ expect(subject.target()).toEqual({
selector: { selector: {
type: 'SvgSelector', type: 'SvgSelector',
...@@ -54,8 +49,28 @@ describe('WebAnnotation', () => { ...@@ -54,8 +49,28 @@ describe('WebAnnotation', () => {
source: 'canvasId', source: 'canvasId',
}); });
}); });
it('with time interval only', () => {
subject = createSubject({ fragsel: { t: '5,10' }, svg: null });
expect(subject.target()).toEqual({
selector: {
type: 'FragmentSelector',
value: 't=5,10',
},
source: 'canvasId',
});
});
it('with time interval only - xywh present but null', () => {
subject = createSubject({ fragsel: { t: '5,10', xywh: null }, svg: null });
expect(subject.target()).toEqual({
selector: {
type: 'FragmentSelector',
value: 't=5,10',
},
source: 'canvasId',
});
});
it('with xywh only', () => { it('with xywh only', () => {
subject = createSubject({ svg: null, timing: null }); subject = createSubject({ fragsel: { xywh: 'xywh' }, svg: null });
expect(subject.target()).toEqual({ expect(subject.target()).toEqual({
selector: { selector: {
type: 'FragmentSelector', type: 'FragmentSelector',
...@@ -64,18 +79,18 @@ describe('WebAnnotation', () => { ...@@ -64,18 +79,18 @@ describe('WebAnnotation', () => {
source: 'canvasId', source: 'canvasId',
}); });
}); });
it('with timing only', () => { it('with xywh only - time interval present but null', () => {
subject = createSubject({ svg: null, xywh: null }); subject = createSubject({ fragsel: { t: null, xywh: 'xywh' }, svg: null });
expect(subject.target()).toEqual({ expect(subject.target()).toEqual({
selector: { selector: {
type: 'FragmentSelector', type: 'FragmentSelector',
value: 't=1,3', value: 'xywh=xywh',
}, },
source: 'canvasId', source: 'canvasId',
}); });
}); });
it('with no xywh, svg or timing', () => { it('with no xywh or svg', () => {
subject = createSubject({ svg: null, timing: null, xywh: null }); subject = createSubject({ fragsel: null, svg: null });
expect(subject.target()).toBe('canvasId'); expect(subject.target()).toBe('canvasId');
}); });
}); });
......
...@@ -242,18 +242,16 @@ class AnnotationCreation extends Component { ...@@ -242,18 +242,16 @@ 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 timing = (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 ? `${secondsToHMS(tstart)} -> ${secondsToHMS(tend)}` : annoBody,
canvasId: canvas.id, canvasId: canvas.id,
fragsel: { t: `${tstart},${tend}`, xywh },
id: (annotation && annotation.id) || `${uuid()}`, id: (annotation && annotation.id) || `${uuid()}`,
manifestId: canvas.options.resource.id, manifestId: canvas.options.resource.id,
svg, svg,
tags, tags,
timing,
xywh,
}).toJson(); }).toJson();
if (annotation) { if (annotation) {
storageAdapter.update(anno).then((annoPage) => { storageAdapter.update(anno).then((annoPage) => {
......
...@@ -2,12 +2,11 @@ ...@@ -2,12 +2,11 @@
export default class WebAnnotation { export default class WebAnnotation {
/** */ /** */
constructor({ constructor({
canvasId, id, xywh, timing, body, tags, svg, manifestId, canvasId, id, fragsel, body, tags, svg, manifestId,
}) { }) {
this.id = id; this.id = id;
this.canvasId = canvasId; this.canvasId = canvasId;
this.xywh = xywh; this.fragsel = fragsel;
this.timing = timing;
this.body = body; this.body = body;
this.tags = tags; this.tags = tags;
this.svg = svg; this.svg = svg;
...@@ -49,30 +48,24 @@ export default class WebAnnotation { ...@@ -49,30 +48,24 @@ export default class WebAnnotation {
/** */ /** */
target() { target() {
if (!this.svg && !this.xywh && !this.timing) { if (!this.svg && !this.fragsel) {
return this.canvasId; return this.canvasId;
} }
const target = { source: this.source() };
const selectors = []; const selectors = [];
const target = {
source: this.source(),
};
if (this.svg) { if (this.svg) {
selectors.push({ selectors.push({
type: 'SvgSelector', type: 'SvgSelector',
value: this.svg, value: this.svg,
}); });
} }
if (this.xywh) { if (this.fragsel) {
selectors.push({
type: 'FragmentSelector',
value: `xywh=${this.xywh}`,
});
}
if (this.timing) {
const [start, end] = this.timing;
selectors.push({ selectors.push({
type: 'FragmentSelector', type: 'FragmentSelector',
value: `t=${start},${end}`, value: Object.entries(this.fragsel)
.filter((kv) => kv[1])
.map((kv) => `${kv[0]}=${kv[1]}`)
.join('&'),
}); });
} }
target.selector = selectors.length === 1 ? selectors[0] : selectors; target.selector = selectors.length === 1 ? selectors[0] : selectors;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment