| author | ymh <ymh.work@gmail.com> |
| Wed, 04 Sep 2024 17:32:50 +0200 | |
| changeset 1072 | ac1eacb3aa33 |
| parent 1068 | 7623f9af9272 |
| permissions | -rw-r--r-- |
| 998 | 1 |
/* ldt_annotate serializer: Used when Putting annotations on the platform */ |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
2 |
import _ from "lodash"; |
| 904 | 3 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
4 |
const ldt_annotate = function(IriSP) { return { |
| 974 | 5 |
serializeAnnotation : function(_data, _source) { |
6 |
var _annType = _data.getAnnotationType(); |
|
7 |
return { |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
8 |
id: _data.id, |
| 974 | 9 |
begin: _data.begin.milliseconds, |
10 |
end: _data.end.milliseconds, |
|
11 |
content: { |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
12 |
data: (_data.content ? _data.content.data || {} : {}), |
| 975 | 13 |
description: _data.description, |
14 |
title: _data.title, |
|
| 974 | 15 |
audio: _data.audio |
16 |
}, |
|
|
1045
b06345320ffb
Altered ldt_annotate serializer to allow for serializing id for editing annotation + Added Markers widget that allows to make and edit 0 duration annotations.
durandn
parents:
1035
diff
changeset
|
17 |
id: _data.id ? _data.id : "", // If annotation is new, id will be undefined |
| 974 | 18 |
tags: _data.getTagTexts(), |
19 |
media: _data.getMedia().id, |
|
|
1035
c1bc8a2b1468
Allow the annotation serializer to extract project_id for use in some widget when it is provided in the data
durandn
parents:
1013
diff
changeset
|
20 |
project: _data.project_id, |
| 974 | 21 |
type_title: _annType.title, |
22 |
type: ( typeof _annType.dont_send_id !== "undefined" && _annType.dont_send_id ? "" : _annType.id ), |
|
23 |
meta: { |
|
24 |
created: _data.created, |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
25 |
creator: _data.creator, |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
26 |
modified: _data.modified, |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
27 |
contributor: _data.contributor |
| 904 | 28 |
} |
| 1013 | 29 |
}; |
| 904 | 30 |
}, |
| 979 | 31 |
deserializeAnnotation : function(_anndata, _source) { |
32 |
var _ann = new IriSP.Model.Annotation(_anndata.id, _source); |
|
33 |
_ann.description = _anndata.content.description || ""; |
|
34 |
_ann.title = _anndata.content.title || ""; |
|
35 |
_ann.creator = _anndata.meta.creator || ""; |
|
36 |
_ann.created = new Date(_anndata.meta.created); |
|
37 |
_ann.setMedia(_anndata.media, _source); |
|
38 |
var _anntype = _source.getElement(_anndata.type); |
|
39 |
if (!_anntype) { |
|
40 |
_anntype = new IriSP.Model.AnnotationType(_anndata.type, _source); |
|
41 |
_anntype.title = _anndata.type_title; |
|
42 |
_source.getAnnotationTypes().push(_anntype); |
|
43 |
} |
|
44 |
_ann.setAnnotationType(_anntype.id); |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
45 |
var _tagIds = _(_anndata.tags).map(function(_title) { |
| 979 | 46 |
var _tags = _source.getTags(true).searchByTitle(_title, true); |
47 |
if (_tags.length) { |
|
48 |
var _tag = _tags[0]; |
|
49 |
} |
|
50 |
else { |
|
51 |
_tag = new IriSP.Model.Tag(_title.replace(/\W/g,'_'),_source); |
|
52 |
_tag.title = _title; |
|
53 |
_source.getTags().push(_tag); |
|
54 |
} |
|
55 |
return _tag.id; |
|
56 |
}); |
|
57 |
_ann.setTags(_tagIds); |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
58 |
_ann.setBeginEnd(_anndata.begin, _anndata.end); |
| 979 | 59 |
if (typeof _anndata.content.audio !== "undefined" && _anndata.content.audio.href) { |
60 |
_ann.audio = _anndata.content.audio; |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
61 |
}; |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
62 |
if (_anndata.content.data) { |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
63 |
_ann.content = { data: _anndata.content.data }; |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
64 |
}; |
| 979 | 65 |
_source.getAnnotations().push(_ann); |
66 |
}, |
|
| 904 | 67 |
serialize : function(_source) { |
| 979 | 68 |
return JSON.stringify(this.serializeAnnotation(_source.getAnnotations()[0], _source)); |
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
69 |
}, |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
70 |
deSerialize : function(_data, _source) { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
71 |
if (typeof _data == "string") { |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
72 |
_data = JSON.parse(_data); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
73 |
} |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
74 |
|
|
908
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
75 |
_source.addList('tag', new IriSP.Model.List(_source.directory)); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
76 |
_source.addList('annotationType', new IriSP.Model.List(_source.directory)); |
|
f56199193fad
CreateAnnotation widget now posts annotations, Tagcloud can be made segment-dependent
veltr
parents:
904
diff
changeset
|
77 |
_source.addList('annotation', new IriSP.Model.List(_source.directory)); |
| 979 | 78 |
this.deserializeAnnotation(_data, _source); |
| 904 | 79 |
} |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
80 |
}}; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
81 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
82 |
export default ldt_annotate; |
| 998 | 83 |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1045
diff
changeset
|
84 |
/* End ldt_annotate serializer */ |