Widget tester WRIS-3
authorJason Skomorowski <jason@indexdata.com>
Thu, 4 Dec 2014 21:27:58 +0000 (16:27 -0500)
committerJason Skomorowski <jason@indexdata.com>
Thu, 4 Dec 2014 21:27:58 +0000 (16:27 -0500)
examples/htdocs/tester.html [new file with mode: 0644]

diff --git a/examples/htdocs/tester.html b/examples/htdocs/tester.html
new file mode 100644 (file)
index 0000000..3c2f5a4
--- /dev/null
@@ -0,0 +1,187 @@
+<!doctype html>
+<html>
+
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title>MKWS demo: Reference & Credo, and popup widget, development</title>
+<link rel="stylesheet" type="text/css" href="tools/htdocs/mkws.css" />
+<link rel="stylesheet" type="text/css" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" />
+<link rel="stylesheet" type="text/css" href="mkws-widget-reference.css" />
+<link rel="stylesheet" type="text/css" href="mkws-widget-credo.css" />
+
+<script type="text/javascript">
+  var mkws_config = {
+    sp_auth_credentials: "mkwstest/mkwstest"
+  };
+</script>
+
+<script type="text/javascript" src="tools/htdocs/jquery-1.10.0.min.js"></script>
+<script type="text/javascript" src="//code.jquery.com/ui/1.11.2/jquery-ui.min.js"></script>
+
+<script type="text/javascript" src="tools/htdocs/pz2.js"></script>
+<script type="text/javascript" src="tools/htdocs/handlebars-v2.0.0.js"></script>
+<script type="text/javascript" src="tools/htdocs/jquery.json-2.4.js"></script>
+<script type="text/javascript" src="tools/htdocs/jsnlog.min.js"></script>
+
+<script type="text/javascript" src="src/mkws-handlebars.js"></script>
+<script type="text/javascript" src="src/mkws-core.js"></script>
+<script type="text/javascript" src="src/mkws-team.js"></script>
+<script type="text/javascript" src="src/mkws-filter.js"></script>
+<script type="text/javascript" src="src/mkws-widget.js"></script>
+<script type="text/javascript" src="src/mkws-widget-main.js"></script>
+<script type="text/javascript" src="src/mkws-widget-facets.js"></script>
+<script type="text/javascript" src="src/mkws-widget-authname.js"></script>
+<script type="text/javascript" src="src/mkws-widget-categories.js"></script>
+<script type="text/javascript" src="src/mkws-widget-log.js"></script>
+<script type="text/javascript" src="src/mkws-widget-record.js"></script>
+<script type="text/javascript" src="src/mkws-widget-reference.js"></script>
+<script type="text/javascript" src="src/mkws-widget-builder.js"></script>
+<script type="text/javascript" src="src/mkws-templates.js"></script>
+<script type="text/javascript" src="src/mkws-popup.js"></script>
+
+<script type="text/javascript" src="mkws-widget-credo.js"></script>
+
+<style>
+.dialog > textarea {
+  height: 100%;
+  width: 100%;
+}
+</style>
+
+</head>
+
+<body>
+Relevant?
+<button id="yes" class="judgement">Yes</button>
+<button id="no" class="judgement">No</button>
+<button id="maybe" class="judgement">Maybe</button>
+Settings:
+<button id="widget-markup-button">Widget</button>
+<button id="queries-button">Queries</button>
+Results:
+<button id="results-table-button">Table</button>
+<button id="results-csv-button">CSV</button>
+
+<div id="widget-markup" class="dialog" title="Widget markup">
+  <textarea></textarea>
+</div>
+<div id="queries" class="dialog" title="Queries">
+  <textarea></textarea>
+</div>
+<div id="results-csv" class="dialog" title="Results as CSV">
+  <textarea readonly></textarea>
+</div>
+<div id="results-table" class="dialog" title="Results as table">
+  <table></table>
+</div>
+
+<hr>
+
+<div id="test-subject"></div>
+
+<script>
+(function () { // wrapper
+// Initial data
+this.queries = ["sushi", "wurst", "berlin", "hammer", "bristol", "copenhagen", "tea", "latte"];
+$("#queries > textarea").html(this.queries.join("\n"));
+this.widgetMarkup = '<div class="mkws-reference" autosearch="{{query}}">Loading..</div>';
+$("#widget-markup > textarea").html(this.widgetMarkup);
+
+this.results = {};
+var next;
+var context = this;
+
+var showNext = function () {
+  if (next <  this.queries.length) {
+    $('#test-subject').html(this.widgetMarkup.replace("{{query}}", this.queries[next]));
+    next++;
+    mkws.init('#test-subject');
+  }
+} 
+var startEval = function () {
+  $(".dialog").dialog("close");
+  next = 0;
+  context.results = {};
+  showNext();
+}
+var judge = function (e) {
+  var query = $('#test-subject > div').attr('autosearch');
+  context.results[query] = {judgement: $(this).html()};
+  showNext();
+}
+
+// Set up dialogs
+$(".dialog").dialog({
+  autoOpen: false,
+  height: 600,
+  width: 600,
+  modal: true,
+  open: function(event, ui) {
+    $(this).parent().css('position', 'fixed');
+  }
+});
+
+// Markup dialog
+var updateMarkup = function () {
+  context.widgetMarkup = $("#widget-markup > textarea").val();
+  startEval();
+}
+$("#widget-markup-button").click(function () {
+  $("#widget-markup").dialog("open");
+});
+$("#widget-markup").dialog("option", "buttons", [
+  {text: "Start new evaluation", click: updateMarkup},
+  {text: "Cancel", click: function() { $(this).dialog("close"); }}   
+]);
+
+// Queries dialog
+var updateQueries = function () {
+  context.queries = $("#queries > textarea").val().split("\n");
+  startEval();
+}
+$("#queries-button").click(function () {
+  $("#queries").dialog("open");
+});
+$("#queries").dialog("option", "buttons", [
+  {text: "Start new evaluation", click: updateQueries},
+  {text: "Cancel", click: function() { $(this).dialog("close"); }}   
+]);
+
+// Results dialogs
+$("#results-table-button").click(function () {
+  $("#results-table").dialog("open");
+});
+$("#results-csv-button").click(function () {
+  $("#results-csv").dialog("open");
+});
+$("#results-table").dialog("option", "open", function () {
+  var html = "<tr><th>Query</th><th>Relevant?</th><tr>";
+  for (var i = 0; i < context.queries.length; i++) {
+    var q = context.queries[i];
+    var r = context.results;
+    if (r[q]) {
+      html += "<tr><td>" + q + "</td><td>" + r[q].judgement + "</td></tr>\n";
+    }
+  } 
+  $("#results-table > table").html(html);
+});
+$("#results-csv").dialog("option", "open", function () {
+  var csv = "Query|Relevant?\n";
+  for (var i = 0; i < context.queries.length; i++) {
+    var q = context.queries[i];
+    var r = context.results;
+    if (r[q]) {
+      csv += [q, r[q].judgement].join("|") + "\n";
+    }
+  } 
+  $("#results-csv > textarea").html(csv);
+});
+
+$('button.judgement').click(judge);
+startEval();
+})();// wrapper
+</script>
+
+</body>
+</html>
+