forked from ISA-tools/OntoMaton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnnotatorSidebar.html
329 lines (266 loc) · 8.27 KB
/
AnnotatorSidebar.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css">
<!-- The CSS package above applies Google styling to buttons and other elements. -->
<style>
@import url(http://weloveiconfonts.com/api/?family=entypo);
/* entypo */
[class*="entypo-"]:before {
font-family: 'entypo', sans-serif;
}
.branding-above {
padding: 0;
top: 0;
}
.hidden {
display:none;
}
.branding-below {
bottom: 56px;
position: fixed;
background-color: #fff;
top: 0;
}
.branding-text {
left: 7px;
position: relative;
font-size: .9em;
top: 3px;
}
.ontomaton-header{
padding-top: 5px;
background: #f6f7f6;
height: 75px;
}
.expand-icon {
cursor: pointer;
}
.col-contain {
overflow: hidden;
}
h3 {
margin-left: 0px;
height: 30px;
margin-top: -10px;
text-align: left;
font-size: 0.9em;
background-color: #f6f7f6;
padding-top: 13px;
padding-bottom:11px;
padding-left: 6px;
border-bottom: 2px solid #ccc;
cursor:pointer;
}
.col-one {
float: left;
width: 50%;
}
.logo {
vertical-align: middle;
}
.radio-spacer {
height: 20px;
}
.pull-left {
float:left;
}
.pull-right {
float:right;
}
.width-100 {
width: 100%;
}
.service-selection {
font-size: 0.9em;
color: #414241;
}
.search-results ul {
list-style:none;
margin-left: -30px;
text-align: left;
}
.term-info {
float:left;
width: 69%;
margin-top:2%;
}
.term-buttons {
float:right;
width: 31%;
}
.search-results ul li{
width:95%;
padding: 4px;
font-weight: bolder;
padding-top: 3px;
font-size: .9em;
padding-bottom: 3px;
background-color: #fff;
margin-bottom:2px;
}
.ontology-result {
background-color: #fafafa;
padding: 5px;
margin: 5px;
}
.search-results ul li a{
color: #5A9C43;
}
.freetext-term {
text-align:left;
font-weight: bolder;
font-size: 1em;
color: #414241;
}
.ontology-abbr {
margin-left: 10px;
text-align:left;
font-weight: bolder;
font-size: .9em;
color: #414241;
}
.ontology-name {
text-align:left;
font-weight: bolder;
font-size: .8em;
color: #95A5A5;
}
.term-count {
text-align:right;
padding: 7px 5px;
background-color: #4FBA6F;
color: #fff;
border-radius:50%;
font-size: .8em;
}
ul {
-webkit-padding-start: 5px;
}
.clearfix:after {
content: " "; /* Older browser do not support empty content */
visibility: hidden;
display: block;
height: 0;
clear: both;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
/**
* On document load, assign click handlers to each button and try to load the
* user's origin and destination language preferences if previously set.
*/
$(function() {
$('#run-annotator').click(runAnnotator);
});
/**
* Taken from http://www.mustbebuilt.co.uk/2012/04/20/replaceall-function-for-javascript-and-actionscript/
*/
function replaceAll(oldStr, removeStr, replaceStr, caseSenitivity){
var cs = "gi"
if(caseSenitivity == 1){
cs = "g";
}
var myPattern=new RegExp(removeStr,cs);
return oldStr.replace(myPattern,replaceStr);
}
/**
* Inserts the term in to the spreadsheet.
*/
function insertTerm(term_id) {
google.script.run
.withSuccessHandler(
function(result, element) {
}).withFailureHandler(
function(msg, element) {
showError(msg, $('#button-bar'));
element.disabled = false;
})
.withUserObject(this)
.replaceTermWithSelectedValue(term_id)
}
function toggle(id) {
$("#"+id).toggleClass("hidden");
var isHidden = $("#" + id).hasClass( "hidden" );
console.log("Is hidden? " + isHidden);
$("#expand-icon-" + id).removeClass(isHidden ? "entypo-minus" : "entypo-plus");
$("#expand-icon-" + id).addClass(isHidden ? "entypo-plus" : "entypo-minus");
}
/**
* Runs a server-side function to translate the user-selected text and update
* the sidebar UI with the resulting translation.
*/
function runAnnotator() {
this.disabled = true;
$('#search-results').html('<div id="spinner"><img src="http://l4.yimg.com/dh/ap/default/130116/spinner_white_working.gif"/></div>');
$('#error').remove();
google.script.run
.withSuccessHandler(
function(result, element) {
// process results
console.log(result);
var html='<div id="result-accordion" class="accordion">';
var count= 0;
for(var term_key in result) {
html += '<h3 onclick="toggle(\'results-' + count + '\')"><span id="expand-icon-results-' + count + '" class="entypo-plus expand-icon" style="font-size: 1.2em"> </span><span class="freetext-term">' + term_key + '</span> - <span class="ontology-name">Results from ' + Object.keys(result[term_key]["results"]).length + ' ontologies.</span></h3>' +
'<div id="results-' + count + '" class="hidden">';
for(var ontology_source_key in result[term_key]["results"]) {
var ontology_name = result[term_key]["results"][ontology_source_key]["ontology-name"];
html += '<div class="clearfix"></div>';
html += '<div class="ontology-result"><p style="text-align:left" onclick="toggle(\'ont-' + count + ontology_source_key + '\')"><span id="expand-icon-ont-' + count + ontology_source_key + '" class="entypo-plus expand-icon"></span><span class="ontology-abbr">' + ontology_source_key + '</span> - <span class="ontology-name">' + ontology_name + '</span></p>';
html += '<div id="ont-' + count + ontology_source_key + '" class="hidden ont-results">';
html += "<ul>";
for(var term_index in result[term_key]["results"][ontology_source_key].terms) {
var term = result[term_key]["results"][ontology_source_key].terms[term_index];
var label = term["label"];
html+= '<li>'+
'<div class="term-info">' +
'<a href="'+term["id"] + '" target="_blank">' + term["label"] + '</a>' +
'</div>' +
'<div class="term-buttons"><button onclick="insertTerm(\'' + term["id"] + '\')" style="margin-left:-5px">Insert Term</button></div>' +
'<div class="clearfix"></div>'+
'</li>';
}
html += "</div></ul></div>";
}
html +='</div>';
count += 1;
}
html += "</div>";
$('#search-results').html(html);
element.disabled = false;
$('#spinner').addClass("hidden");
})
.withFailureHandler(
function(msg, element) {
$('#spinner').addClass("hidden");
showError(msg, $('#button-bar'));
element.disabled = false;
})
.withUserObject(this)
.runAnnotator();
}
/**
* Inserts a div that contains an error message after a given element.
*
* @param msg The error message to display.
* @param element The element after which to display the error.
*/
function showError(msg, element) {
var div = $('<div id="error" class="error">' + msg + '</div>');
$(element).after(div);
}
</script>
<div class="sidebar branding-above" align="center">
<div class="ontomaton-header">
<img src="http://isatab.sf.net/assets/img/tools/ontomaton-tagging.png"/>
</div>
<div class="block" id="button-bar" style="margin-top:20px">
<button class="share" id="run-annotator">Tag Terms</button>
</div>
<div id="search-results" class="block form-group search-results" style="height:390px; overflow: scroll; border-top: 1px solid #ccc; padding-top: 10px">
</div>
</div>
<div class="sidebar bottom">
<img alt="Add-on logo" class="logo"
src="http://isatab.sourceforge.net/assets/img/isatools-sml.png">
<span class="gray branding-text">Created by the <a href="http://isa-tools.org" target="_blank">ISA tools</a> team</span>
</div>