Skip to content
Snippets Groups Projects
Commit 7bfadd24 authored by Anthony's avatar Anthony
Browse files

Dumb annotation

parent 2c8661d1
Branches
No related tags found
1 merge request!10Draft: MigratingAnnotationCreation to MUI5.
...@@ -11,6 +11,7 @@ const config = { ...@@ -11,6 +11,7 @@ const config = {
exportLocalStorageAnnotations: false, // display annotation JSON export button exportLocalStorageAnnotations: false, // display annotation JSON export button
}, },
catalog: [ catalog: [
{ manifestIf: 'https://files.tetras-libre.fr/dev/Clock/manifest.json'},
{ manifestId: 'https://files.tetras-libre.fr/dev/Hakanai/manifest/manifest.json' }, { manifestId: 'https://files.tetras-libre.fr/dev/Hakanai/manifest/manifest.json' },
{ manifestId: 'https://dzkimgs.l.u-tokyo.ac.jp/videos/iiif_in_japan_2017/manifest.json' }, { manifestId: 'https://dzkimgs.l.u-tokyo.ac.jp/videos/iiif_in_japan_2017/manifest.json' },
{ manifestId: 'https://iiif.io/api/cookbook/recipe/0219-using-caption-file/manifest.json' }, { manifestId: 'https://iiif.io/api/cookbook/recipe/0219-using-caption-file/manifest.json' },
......
...@@ -57,24 +57,42 @@ export async function getSvg(windowId) { ...@@ -57,24 +57,42 @@ export async function getSvg(windowId) {
return svg; return svg;
}; };
const dumbAnnotation = {
"id": "https://preview.iiif.io/cookbook/master/recipe/0003-mvm-video/canvas/annotation/1",
"type": "Annotation",
"motivation": "commenting",
"body": {
"id": "https://files.tetras-libre.fr/dev/Hakanai/media/02_HKN-couv.jpg",
"type": "Image",
"format": "image/jpg",
"value": "Test image annotation"
},
"target": "https://preview.iiif.io/cookbook/master/recipe/0003-mvm-video/canvas#xywh=0,0,301,400&t=0,1000"
}
;
export function saveAnnotation(canvases, config, receiveAnnotation, annotation, body, t, xywh, image, drawingStateSerialized, svg, tags){ export function saveAnnotation(canvases, config, receiveAnnotation, annotation, body, t, xywh, image, drawingStateSerialized, svg, tags){
// TODO promises not handled. Use promiseAll ? // TODO promises not handled. Use promiseAll ?
canvases.forEach(async (canvas) => { canvases.forEach(async (canvas) => {
const storageAdapter = config.annotation.adapter(canvas.id); const storageAdapter = config.annotation.adapter(canvas.id);
const anno = new WebAnnotation({ // const anno = new WebAnnotation({
body, // body,
canvasId: canvas.id, // canvasId: canvas.id,
fragsel: { // fragsel: {
t, // t,
xywh, // xywh,
}, // },
id: (annotation && annotation.id) || `${uuid()}`, // id: (annotation && annotation.id) || `${uuid()}`,
image, // image,
drawingStateSerialized, // drawingStateSerialized,
manifestId: canvas.options.resource.id, // manifestId: canvas.options.resource.id,
svg, // svg,
tags, // tags,
}).toJson(); // }).toJson();
const anno = dumbAnnotation;
anno.drawingState = drawingStateSerialized;
if (annotation) { if (annotation) {
storageAdapter.update(anno) storageAdapter.update(anno)
......
...@@ -2,32 +2,31 @@ ...@@ -2,32 +2,31 @@
export default class WebAnnotation { export default class WebAnnotation {
/** */ /** */
constructor({ constructor({
canvasId, id, fragsel, image, body, tags, svg, manifestId, drawingStateSerialized id, body, drawingStateSerialized, motivation, target,
}) { }) {
this.id = id; this.id = id;
this.canvasId = canvasId; this.type = 'Annotation';
this.fragsel = fragsel; this.motivation = motivation;
this.body = body; this.body = body;
this.tags = tags;
this.svg = svg;
//this.image = image;
this.image = image;
this.manifestId = manifestId;
this.drawingState = drawingStateSerialized; this.drawingState = drawingStateSerialized;
this.target = target;
console.log('WebAnnotation constructor', this); console.log('WebAnnotation constructor', this);
} }
/** */ /** */
toJson() { toJson() {
const result = { // const result = {
body: this.createBody(), // body: this.createBody(),
id: this.id, // drawingState: this.drawingState,
motivation: 'commenting', // id: this.id,
target: this.target(), // motivation: 'commenting',
type: 'Annotation', // target: this.target(),
drawingState: this.drawingState, // type: 'Annotation',
}; // };
const result = this;
console.log('WebAnnotation toJson', result); console.log('WebAnnotation toJson', result);
return result; return result;
} }
......
/** */
export default class WebAnnotation {
/** */
constructor({
canvasId, id, fragsel, image, body, tags, svg, manifestId, drawingStateSerialized
}) {
this.id = id;
this.canvasId = canvasId;
this.fragsel = fragsel;
this.body = body;
this.tags = tags;
this.svg = svg;
//this.image = image;
this.image = image;
this.manifestId = manifestId;
this.drawingState = drawingStateSerialized;
console.log('WebAnnotation constructor', this);
}
/** */
toJson() {
const result = {
body: this.createBody(),
id: this.id,
motivation: 'commenting',
target: this.target(),
type: 'Annotation',
drawingState: this.drawingState,
};
console.log('WebAnnotation toJson', result);
return result;
}
/** */
createBody() {
let bodies = [];
if (this.body && this.body.value !== '') {
const textBody = {
type: 'TextualBody',
value: this.body.value,
};
bodies.push(textBody);
}
if (this.image) {
// TODO dumb image { this.image.id}
const imgBody = {
id: 'https://tetras-libre.fr/themes/tetras/img/logo.svg',
type: 'Image',
format: 'image/svg+xml',
};
//bodies.push(imgBody);
const testImageBody = {
"id": "https://files.tetras-libre.fr/dev/Hakanai/media/10_HKN-Garges_A2B4243.JPG",
"type": "Image",
"format": "image/jpg"
};
bodies.push(testImageBody);
}
// if (this.tags) {
// bodies = bodies.concat(this.tags.map((tag) => ({
// purpose: 'tagging',
// type: 'TextualBody',
// value: tag,
// })));
// }
if (bodies.length === 1) {
return bodies[0];
}
return bodies;
}
/** Fill target object with selectors (if any), else returns target url */
target() {
if (!this.svg
&& (!this.fragsel || !Object.values(this.fragsel).find((e) => e !== null))) {
return this.canvasId;
}
const target = { source: this.source() };
const selectors = [];
if (this.svg) {
selectors.push({
type: 'SvgSelector',
value: this.svg,
});
}
if (this.fragsel) {
selectors.push({
type: 'FragmentSelector',
value: Object.entries(this.fragsel)
.filter((kv) => kv[1])
.map((kv) => `${kv[0]}=${kv[1]}`)
.join('&'),
});
}
target.selector = selectors.length === 1 ? selectors[0] : selectors;
return target;
}
/** */
source() {
let source = this.canvasId;
if (this.manifest) {
source = {
id: this.canvasId,
partOf: {
id: this.manifest.id,
type: 'Manifest',
},
type: 'Canvas',
};
}
return source;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment