-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcamomile-segmentation-table.html
69 lines (57 loc) · 2.31 KB
/
camomile-segmentation-table.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<link rel="import" href="bower_components/polymer/polymer-element.html">
<link rel="import" href="bower_components/polymer/lib/elements/dom-repeat.html">
<script src="getElementAt.js"></script>
<dom-module id="camomile-segmentation-table">
<template>
<table>
<tr><th>Beginning</th><th>End</th><th>Label</th></tr>
<template is="dom-repeat" items="{{annotations}}">
<tr><td>{{item.fragment.start}}</td><td>{{item.fragment.end}}</td><td>{{item.data}}</td></tr>
</template>
</table>
</template>
<script>
class CamomileSegmentationTable extends Polymer.Element {
static get is() {
return "camomile-segmentation-table";
}
constructor() {
super();
}
ready() {
super.ready();
const layerState = getElementAt(this.srcLayerState);
layerState.addEventListener("populate_annotations",({detail:{data}}) => {
this.annotations=JSON.parse(JSON.stringify(data));
this.annotations.sort((a,b) => a.fragment.start - b.fragment.start);
});
layerState.addEventListener("reset_annotations",() => {
this.annotations=null;
});
layerState.addEventListener("add_annotation",({detail:{data}}) => {
const annotationIndex=this.annotations.findIndex(annotation => annotation._id===data._id);
if(annotationIndex!==-1)
return;
this.push("annotations",data);
this.annotations.sort((a,b) => a.fragment.start - b.fragment.start);
});
layerState.addEventListener("update_annotation",({detail:{data}}) => {
const annotationIndex=this.annotations.findIndex(annotation => annotation._id===data._id);
this.splice("annotations", annotationIndex, 1,data);
this.annotations.sort((a,b) => a.fragment.start - b.fragment.start);
});
layerState.addEventListener("delete_annotation",({detail:{id}}) => {
const annotationIndex=this.annotations.findIndex(annotation => annotation._id===id);
this.splice("annotations", annotationIndex, 1);
});
}
static get properties() {
return {
srcLayerState: String,
id: String
};
}
}
customElements.define(CamomileSegmentationTable.is, CamomileSegmentationTable);
</script>
</dom-module>