Add note field to tester.html WRIS-3
[mkws-moved-to-github.git] / examples / htdocs / tester.html
1 <!doctype html>
2 <html>
3
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <title>MKWS demo: Reference & Credo, and popup widget, development</title>
7 <link rel="stylesheet" type="text/css" href="tools/htdocs/mkws.css" />
8 <link rel="stylesheet" type="text/css" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" />
9 <link rel="stylesheet" type="text/css" href="mkws-widget-reference.css" />
10 <link rel="stylesheet" type="text/css" href="mkws-widget-credo.css" />
11
12 <script type="text/javascript">
13   var mkws_config = {
14     sp_auth_credentials: "mkwstest/mkwstest"
15   };
16 </script>
17
18 <script type="text/javascript" src="tools/htdocs/jquery-1.10.0.min.js"></script>
19 <script type="text/javascript" src="//code.jquery.com/ui/1.11.2/jquery-ui.min.js"></script>
20
21 <script type="text/javascript" src="tools/htdocs/pz2.js"></script>
22 <script type="text/javascript" src="tools/htdocs/handlebars-v2.0.0.js"></script>
23 <script type="text/javascript" src="tools/htdocs/jquery.json-2.4.js"></script>
24 <script type="text/javascript" src="tools/htdocs/jsnlog.min.js"></script>
25
26 <script type="text/javascript" src="src/mkws-handlebars.js"></script>
27 <script type="text/javascript" src="src/mkws-core.js"></script>
28 <script type="text/javascript" src="src/mkws-team.js"></script>
29 <script type="text/javascript" src="src/mkws-filter.js"></script>
30 <script type="text/javascript" src="src/mkws-widget.js"></script>
31 <script type="text/javascript" src="src/mkws-widget-main.js"></script>
32 <script type="text/javascript" src="src/mkws-widget-facets.js"></script>
33 <script type="text/javascript" src="src/mkws-widget-authname.js"></script>
34 <script type="text/javascript" src="src/mkws-widget-categories.js"></script>
35 <script type="text/javascript" src="src/mkws-widget-log.js"></script>
36 <script type="text/javascript" src="src/mkws-widget-record.js"></script>
37 <script type="text/javascript" src="src/mkws-widget-reference.js"></script>
38 <script type="text/javascript" src="src/mkws-widget-builder.js"></script>
39 <script type="text/javascript" src="src/mkws-templates.js"></script>
40 <script type="text/javascript" src="src/mkws-popup.js"></script>
41
42 <script type="text/javascript" src="mkws-widget-credo.js"></script>
43
44 <style>
45 .dialog > textarea {
46   height: 100%;
47   width: 100%;
48 }
49 html {
50   margin: 0;
51   height: 100%;
52 }
53 body {
54   background-color: #bbbbbb;
55   margin: 0;
56   padding: 0;
57   display: flex;
58   flex-direction: column;
59   height: 100%;
60 }
61 header {
62   font-size: 1.3em;
63 }
64 header button, #note > input {
65   margin-left: 1em;
66   border-radius: 4px;
67   background-color: #4368a1;
68   color: #dbe9ff;
69   font: inherit;
70   font-weight: normal;
71   border: 1px solid #7492c3;
72   padding: 0.15em 0.25em;
73 }
74 header button:hover, header button:active, header button:focus {
75   background-color: #2f5591;
76 }
77 #top-bar, #current-bar, #note {
78   display: flex;
79   flex-wrap: wrap;
80   align-items: center;
81   justify-content: space-between;
82 }
83 #top-bar {
84   background-color: #002868;
85   color: white;
86 }
87 #current-bar {
88   background-color: #54d8a8;
89   color: #002868;
90 }
91 #note {
92   width: 100%;
93   padding: .5em;
94 }
95 #note > input {
96   flex: 1;
97   background-color: #7de3be;
98   border-color: #7ed6b6;
99   color: #002868;
100 }
101 #maybe {
102   background-color: #F0AD4E;
103   border-color: #EEA236;
104   color: #664009;
105   color: white;
106 }
107 #maybe:hover, #maybe:active, #maybe:focus {
108   background-color: #EC971F;
109   border-color: #D58512;
110 }
111 #yes {
112   background-color: #5CB85C;
113   border-color: #4CAE4C;
114   color: #214d21;
115   color: white;
116 }
117 #yes:hover, #yes:focus, #yes:active {
118   background-color: #449D44;
119   border-color: #398439;
120 }
121 #no {
122   background-color: #D9534F;
123   border-color: #D43F3A;
124   color: #4f1311;
125   color: white;
126 }
127 #no:hover, #no:focus, #no:active {
128   background-color: #C9302C;
129   border-color: #AC2925;
130 }
131 #query {
132   font-weight: bold;
133   font-size: 110%;
134 }
135 #settings, #judiciary {
136   padding: .5em;
137   display: flex;
138   align-items: center;
139 }
140 #results, #query-info {
141   padding: .5em;
142   display: flex;
143   text-align: right;
144   align-items: center;
145   justify-content: flex-end;
146 }
147 #count {
148   font-size: 120%;
149 }
150 #test-area {
151   flex: 1;
152   padding: 2em;
153   display: flex;
154   justify-content: center;
155   overflow: auto;
156 }
157 #test-subject {
158   margin: auto;
159 }
160 #results-table {
161   flex: 1;
162   padding: 1em;
163   display: flex;
164   justify-content: center;
165 }
166 #results-table table {
167   border-collapse: collapse;
168   border-spacing: 0;
169 }
170 #results-table td, #results-table th {
171   padding: .25em 1.25em;
172   font-size: .9em;
173 }
174 #results-table tr:first-child {
175   border-bottom: 1px solid black;
176 }
177 #results-table tr {
178   border-bottom: 1px dotted black;
179 }
180 #results-table tr:last-child {
181   border-bottom: none;
182 }
183   
184 </style>
185
186 </head>
187
188 <body>
189 <header>
190   <div id="top-bar">
191     <span id="settings">
192       Settings:
193       <button id="widget-markup-button">Widget</button>
194       <button id="queries-button">Queries</button>
195     </span>
196     <span id="results">
197       Results:
198       <button id="results-table-button">Table</button>
199       <button id="results-csv-button">| delimited</button>
200     </span>
201   </div>
202 </header>
203
204 <header id="current-bar">
205   <span id="judiciary">
206     Relevant to query <span id="query"></span>?
207     <button id="yes" class="judgement">Yes</button>
208     <button id="no" class="judgement">No</button>
209     <button id="maybe" class="judgement">Maybe</button>
210   </span>
211   <span id="query-info">
212     <span id="count"></span>
213   </span>
214   <span id="note">
215     Note: <input type="text"></input>
216   </span>
217 </header>
218
219 <div id="widget-markup" class="dialog" title="Widget markup">
220   <textarea></textarea>
221 </div>
222 <div id="queries" class="dialog" title="Queries">
223   <textarea></textarea>
224 </div>
225 <div id="results-csv" class="dialog" title="| delimited results">
226   <textarea readonly></textarea>
227 </div>
228 <div id="results-table" class="dialog" title="Results as table">
229   <table></table>
230 </div>
231
232 <div id="test-area">
233   <div id="test-subject"></div>
234 </div>
235
236 <script>
237 (function () { // wrapper
238 // Initial data
239 this.queries = ["sushi", "wurst", "berlin", "hammer", "bristol", "copenhagen", "tea", "latte"];
240 this.widgetMarkup = '<div class="mkws-reference" autosearch="{{query}}">Loading..</div>';
241 if (localStorage.getItem('mkwstest-queries')) {
242   this.queries = JSON.parse(localStorage.getItem('mkwstest-queries'));
243 }
244 if (localStorage.getItem('mkwstest-widget-markup')) {
245   this.widgetMarkup = localStorage.getItem('mkwstest-widget-markup');
246 }
247 $("#queries > textarea").html(this.queries.join("\n"));
248 $("#widget-markup > textarea").html(this.widgetMarkup);
249
250 this.results = {};
251 var next = 0;
252 if (localStorage.getItem('mkwstest-results')) {
253   this.results = JSON.parse(localStorage.getItem('mkwstest-results'));
254 }
255 if (localStorage.getItem('mkwstest-next') !== null) {
256   next = parseInt(localStorage.getItem('mkwstest-next'));
257 }
258
259 var context = this;
260
261 var showNext = function () {
262   if (next <  this.queries.length) {
263     $('#note > input').val("");
264     $('#test-subject').html(this.widgetMarkup.replace("{{query}}", this.queries[next]));
265     $('#query').html('"' + this.queries[next] + '"');
266     localStorage.setItem("mkwstest-next", next);
267     next++;
268     $('#count').html(next + " / " + this.queries.length);
269     mkws.init('#test-subject');
270   } else {
271     $("#results-table").dialog("open");
272   }
273
274 var startEval = function () {
275   $(".dialog").dialog("close");
276   next = 0;
277   context.results = {};
278   showNext();
279 }
280 var judge = function (e) {
281   var query = $('#test-subject > div').attr('autosearch');
282   context.results[query] = {judgement: $(this).html(), note: $("#note > input").val() || ""};
283   localStorage.setItem("mkwstest-results", JSON.stringify(context.results));
284   showNext();
285 }
286
287 // Set up dialogs
288 $(".dialog").dialog({
289   autoOpen: false,
290   height: 600,
291   width: 600,
292   modal: true,
293   open: function(event, ui) {
294     $(this).parent().css('position', 'fixed');
295   }
296 });
297
298 // Markup dialog
299 var updateMarkup = function () {
300   context.widgetMarkup = $("#widget-markup > textarea").val();
301   localStorage.setItem("mkwstest-widget-markup", context.widgetMarkup);
302   startEval();
303 }
304 $("#widget-markup-button").click(function () {
305   $("#widget-markup").dialog("open");
306 });
307 $("#widget-markup").dialog("option", "buttons", [
308   {text: "Start new evaluation", click: updateMarkup},
309   {text: "Cancel", click: function() { $(this).dialog("close"); }}   
310 ]);
311
312 // Queries dialog
313 var updateQueries = function () {
314   context.queries = $("#queries > textarea").val().split("\n");
315   localStorage.setItem("mkwstest-queries", JSON.stringify(context.queries));
316   startEval();
317 }
318 $("#queries-button").click(function () {
319   $("#queries").dialog("open");
320 });
321 $("#queries").dialog("option", "buttons", [
322   {text: "Start new evaluation", click: updateQueries},
323   {text: "Cancel", click: function() { $(this).dialog("close"); }}   
324 ]);
325
326 // Results dialogs
327 $("#results-table-button").click(function () {
328   $("#results-table").dialog("open");
329 });
330 $("#results-csv-button").click(function () {
331   $("#results-csv").dialog("open");
332 });
333 $("#results-table").dialog("option", "open", function () {
334   var html = "<tr><th>Query</th><th>Relevant?</th><th>Note</th><tr>";
335   for (var i = 0; i < context.queries.length; i++) {
336     var q = context.queries[i];
337     var r = context.results;
338     if (r[q]) {
339       html += "<tr><td>" + q + "</td><td>" + r[q].judgement + "</td><td>" + r[q].note + "</td></tr>\n";
340     }
341   } 
342   $("#results-table > table").html(html);
343 });
344 $("#results-csv").dialog("option", "open", function () {
345   var csv = "Query|Relevant?|Note\n";
346   for (var i = 0; i < context.queries.length; i++) {
347     var q = context.queries[i];
348     var r = context.results;
349     if (r[q]) {
350       csv += [q, r[q].judgement, r[q].note].join("|") + "\n";
351     }
352   } 
353   $("#results-csv > textarea").html(csv);
354 });
355
356 $('button.judgement').click(judge);
357 showNext();
358 })();// wrapper
359 </script>
360
361 </body>
362 </html>
363