annotate test_create/test_core.js @ 3141:335bc77627e0 tip

fixing discrete interface to allow labels to display
author Dave Moffat <me@davemoffat.com>
date Mon, 26 Jul 2021 12:15:24 +0100
parents 3dcdada1058f
children
rev   line source
nicholas@2885 1 /* globals document, angular, window, Promise, XMLHttpRequest, Specification, XMLSerializer, Blob, DOMParser, FileReader, $*/
nicholas@2851 2 function get(url) {
nicholas@2851 3 // Return a new promise.
nicholas@2851 4 return new Promise(function (resolve, reject) {
nicholas@2851 5 // Do the usual XHR stuff
nicholas@2851 6 var req = new XMLHttpRequest();
nicholas@2851 7 req.open('GET', url);
nickjillings@1370 8
nicholas@2851 9 req.onload = function () {
nicholas@2851 10 // This is called even on 404 etc
nicholas@2851 11 // so check the status
nicholas@2851 12 if (req.status == 200) {
nicholas@2851 13 // Resolve the promise with the response text
nicholas@2851 14 resolve(req.response);
nicholas@2851 15 } else {
nicholas@2851 16 // Otherwise reject with the status text
nicholas@2851 17 // which will hopefully be a meaningful error
nicholas@2851 18 reject(Error(req.statusText));
nicholas@2851 19 }
nicholas@2851 20 };
nicholas@2851 21
nicholas@2851 22 // Handle network errors
nicholas@2851 23 req.onerror = function () {
nicholas@2851 24 reject(Error("Network Error"));
nicholas@2851 25 };
nicholas@2851 26
nicholas@2851 27 // Make the request
nicholas@2851 28 req.send();
nicholas@2851 29 });
nickjillings@1370 30 }
nickjillings@1370 31
nicholas@2851 32 var AngularInterface = angular.module("creator", []);
nickjillings@1370 33
nicholas@3097 34 AngularInterface.directive("dropzone", function () {
nicholas@3097 35 return {
nicholas@3097 36 restrict: "A",
nicholas@3097 37 link: function (scope, elem) {
nicholas@3097 38 elem.bind('dragover', function (evt) {
nicholas@3097 39 evt.stopPropagation();
nicholas@3097 40 evt.preventDefault();
nicholas@3097 41 });
nicholas@3097 42 elem.bind('dragend', function (evt) {
nicholas@3097 43 console.log(evt);
nicholas@3097 44 evt.stopPropagation();
nicholas@3097 45 evt.preventDefault();
nicholas@3097 46 });
nicholas@3097 47 elem.bind('drop', function (event) {
nicholas@3097 48 var evt = event.originalEvent;
nicholas@3097 49 console.log(evt);
nicholas@3097 50 evt.stopPropagation();
nicholas@3097 51 evt.preventDefault();
nicholas@3097 52
nicholas@3097 53 var files = evt.dataTransfer.files;
nicholas@3097 54 for (var i = 0, f; f = files[i]; i++) {
nicholas@3097 55 var reader = new FileReader();
nicholas@3097 56 reader.readAsArrayBuffer(f);
nicholas@3097 57
nicholas@3097 58 reader.onload = (function (theFile) {
nicholas@3097 59 return function (e) {
nicholas@3099 60 scope.ondrop(theFile.name);
nicholas@3097 61 scope.$apply();
nicholas@3097 62 };
nicholas@3097 63 })(f);
nicholas@3097 64 }
nicholas@3097 65 });
nicholas@3097 66 }
nicholas@3097 67 }
nicholas@3097 68 });
nicholas@3097 69
nicholas@2851 70 var specification = new Specification();
nickjillings@1370 71
nicholas@2535 72 window.onload = function () {
nicholas@2851 73 // Get the test interface specifications
n@2911 74 toggleDropdowns();
nicholas@3098 75 $("#popupHolder").modal("show");
n@2911 76 };
n@2911 77
n@2911 78 function toggleDropdowns() {
nicholas@2884 79 $(function () {
nicholas@2884 80 $('[data-toggle="popover"]').popover();
nicholas@2884 81 });
n@2911 82 }
nicholas@2535 83
nicholas@2861 84 function handleFiles(event) {
nicholas@2861 85 var s = angular.element(event.currentTarget).scope();
nicholas@2861 86 s.handleFiles(event);
nicholas@2861 87 s.$apply();
nicholas@2861 88 }
nicholas@2861 89
nicholas@2851 90 AngularInterface.controller("view", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2864 91 $s.testSpecifications = {};
nicholas@2864 92
nicholas@2864 93 (function () {
nicholas@2864 94 new Promise(function (resolve, reject) {
nicholas@2864 95 var xml = new XMLHttpRequest();
nicholas@2864 96 xml.open("GET", "test_create/interfaces/specifications.json");
nicholas@2864 97 xml.onload = function () {
nicholas@2864 98 if (xml.status === 200) {
nicholas@2864 99 resolve(xml.responseText);
nicholas@2864 100 return;
nicholas@2864 101 }
nicholas@2864 102 reject(xml.status);
nicholas@2864 103 };
nicholas@2864 104 xml.onerror = function () {
nicholas@2864 105 reject(new Error("Network Error"));
nicholas@2864 106 };
nicholas@2864 107 xml.send();
nicholas@2864 108 }).then(JSON.parse).then(function (data) {
nicholas@2864 109 $s.testSpecifications = data;
nicholas@2864 110 $s.$apply();
nicholas@2865 111 });
nicholas@2864 112 })();
nickjillings@1370 113
nicholas@2851 114 $s.globalSchema = undefined;
nicholas@2851 115 get("xml/test-schema.xsd").then(function (text) {
nicholas@2851 116 specification.processSchema(text);
nicholas@2851 117 $s.globalSchema = specification.getSchema();
nicholas@2986 118 $s.$apply();
nicholas@2851 119 });
n@2912 120 $s.availableInterfaceModules = [];
n@2912 121 get("interfaces/interfaces.json").then(JSON.parse).then(function (d) {
n@2912 122 $s.availableInterfaceModules = d.interfaces;
n@2912 123 $s.$apply();
n@2912 124 });
nicholas@2851 125 $s.specification = specification;
nicholas@2886 126 $s.selectedTestPrototype = undefined;
nicholas@2886 127 $s.setTestPrototype = function (obj) {
nicholas@2886 128 $s.selectedTestPrototype = obj;
nicholas@2886 129 $w.specification.interface = obj.interface;
nicholas@2886 130 }
nicholas@2857 131
nicholas@2857 132 $s.addPage = function () {
nicholas@2857 133 $s.specification.createNewPage();
nicholas@2859 134 };
nicholas@2860 135
nicholas@2862 136 $s.removePage = function (page) {
nicholas@2862 137 var index = $s.specification.pages.findIndex(function (a) {
nicholas@2862 138 return a == page;
nicholas@2862 139 });
nicholas@2862 140 if (index === -1) {
nicholas@2862 141 throw ("Invalid Page");
nicholas@2862 142 }
nicholas@2862 143 $s.specification.pages.splice(index, 1);
nicholas@2862 144 };
nicholas@2862 145
nicholas@2860 146 $s.exportXML = function () {
nicholas@2860 147 var s = new XMLSerializer();
schlien@2961 148 var doc = specification.encode();
nicholas@2891 149 var xmlstr = s.serializeToString(doc);
schlien@2961 150 var bb = new Blob(["<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + s.serializeToString(doc)], {
nicholas@2860 151 type: 'application/xml'
nicholas@2860 152 });
nicholas@2860 153 var dnlk = window.URL.createObjectURL(bb);
nicholas@2891 154 var a = document.createElement("a");
n@2913 155 document.body.appendChild(a)
nicholas@2891 156 a.href = dnlk;
nicholas@2891 157 a.download = "test.xml";
nicholas@2891 158 a.click();
nicholas@2891 159 window.URL.revokeObjectURL(dnlk);
n@2913 160 document.body.removeChild(a);
nicholas@2861 161 };
nicholas@2887 162 $s.validated = false;
nicholas@2887 163 $s.showValidationMessages = false;
nicholas@2887 164 $s.validate = function () {
nicholas@2887 165 var s = new XMLSerializer();
nicholas@2887 166 var Module = {
nicholas@2959 167 xml: "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + s.serializeToString(specification.encode()),
nicholas@2887 168 schema: specification.getSchemaString(),
nicholas@2887 169 arguments: ["--noout", "--schema", 'test-schema.xsd', 'document.xml']
nicholas@2887 170 };
nicholas@2887 171 var xmllint = validateXML(Module);
nicholas@2887 172 console.log(xmllint);
nicholas@2887 173 if (xmllint != 'document.xml validates\n') {
nicholas@2887 174 $s.validated = false;
nicholas@2887 175 var list = $e[0].querySelector("#validation-error-list");
nicholas@2887 176 while (list.firstChild) {
nicholas@2887 177 list.removeChild(list.firstChild);
nicholas@2887 178 }
nicholas@2887 179 var errors = xmllint.split('\n');
nicholas@2887 180 errors = errors.slice(0, errors.length - 2);
nicholas@2887 181 errors.forEach(function (str) {
nicholas@2887 182 var li = document.createElement("li");
nicholas@2887 183 li.textContent = str;
nicholas@2887 184 list.appendChild(li);
nicholas@2887 185 });
nicholas@2887 186 } else {
nicholas@2887 187 $s.validated = true;
nicholas@2887 188 }
nicholas@2887 189 $s.showValidationMessages = true;
nicholas@2887 190 }
nicholas@2887 191 $s.hideValidationMessages = function () {
nicholas@2887 192 $s.showValidationMessages = false;
nicholas@2887 193 }
n@2911 194 $s.$watch(function () {
n@2911 195 return document.querySelectorAll("div.pageNode").length;
n@2911 196 }, $w.toggleDropdowns);
n@2911 197 $s.$watch(function () {
n@2911 198 return document.querySelectorAll("div.surveyentry").length;
n@2911 199 }, $w.toggleDropdowns);
n@2911 200 $s.$watch(function () {
n@2911 201 return document.querySelectorAll("div.interface").length;
n@2911 202 }, $w.toggleDropdowns);
n@2911 203 $s.$watch(function () {
n@2911 204 return document.querySelectorAll("div.audioelement").length;
n@2911 205 }, $w.toggleDropdowns);
nicholas@2851 206 }]);
nickjillings@1370 207
nicholas@2851 208 AngularInterface.controller("introduction", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2851 209 $s.state = 0;
n@2908 210 $s.selected = undefined;
nicholas@3099 211 $s.close = function () {
nicholas@3099 212 $($e[0]).modal('hide');
nicholas@3099 213 }
nicholas@2851 214 $s.next = function () {
nicholas@3108 215 if (($s.state === 1 && $s.file) || $s.state === 2) {
nicholas@3099 216 $s.initialise($s.selected);
nicholas@3099 217 if ($s.selected != "AB" && $s.selected != "ABX") {
nicholas@3099 218 $s.close();
nicholas@3099 219 }
nicholas@3108 220 } else if ($s.state === 3 && $s.audioFragments.length > 0) {
nicholas@3099 221 // Populate the audio pages by creating a pairwise set of pairs
nicholas@3099 222 $s.populatePages((function (a) {
nicholas@3099 223 var b = [];
nicholas@3099 224 a.forEach(function (e1, i1, a) {
nicholas@3099 225 a.forEach(function (e2, i2) {
nicholas@3099 226 var entry = [e1, e2];
nicholas@3099 227 if (i1 > i2) {
nicholas@3099 228 b.push(entry);
nicholas@3099 229 }
nicholas@3099 230 });
nicholas@3099 231 });
nicholas@3099 232 return b;
nicholas@3099 233 })($s.audioFragments));
nicholas@3099 234 $s.close();
nicholas@3108 235 } else if ($s.state > 3) {
nicholas@3099 236 $s.close();
nicholas@3099 237 }
nicholas@2851 238 $s.state++;
nicholas@3099 239 console.log("Modal state " + $s.state);
nicholas@2851 240 };
nicholas@3099 241 $s.skip = function () {
nicholas@3099 242 $s.close();
nicholas@3099 243 }
nicholas@2851 244 $s.back = function () {
nicholas@2851 245 $s.state--;
nicholas@2851 246 };
nicholas@2986 247
nicholas@2986 248 $s.$watch(function () {
nicholas@2986 249 return ($s.globalSchema !== undefined)
nicholas@2986 250 }, function () {
nicholas@2986 251 if ($s.globalSchema !== undefined && $s.state === 0) {
nicholas@2986 252 $s.state = 1;
nicholas@2986 253 }
nicholas@2986 254 })
nicholas@2986 255
nicholas@2851 256 $s.mouseover = function (name) {
nicholas@2864 257 var obj = $s.testSpecifications.interfaces.find(function (i) {
nicholas@2851 258 return i.name == name;
nicholas@2851 259 });
nicholas@2851 260 if (obj) {
nicholas@2851 261 $s.description = obj.description.en;
nicholas@2851 262 }
nicholas@2851 263 };
nicholas@2851 264 $s.initialise = function (name) {
nicholas@2885 265 var obj = $s.testSpecifications.interfaces.find(function (i) {
nicholas@2851 266 return i.name == name;
nicholas@2851 267 });
nicholas@2886 268 if (obj === undefined) {
nicholas@2886 269 throw ("Cannot find specification");
nicholas@2886 270 }
n@2908 271 if (typeof obj.template === "string") {
n@2908 272 get(obj.template).then(function (data) {
n@2908 273 $s.parseFile(data);
n@2908 274 }, function (err) {})
n@2908 275 } else {
n@2908 276 $s.setTestPrototype(obj);
n@2908 277 }
nicholas@2851 278 };
n@2908 279 $s.select = function (name) {
nicholas@3099 280 $s.selected = name;
nicholas@3099 281 };
nicholas@3099 282 // Get the test interface specifications
nicholas@2861 283 $s.file = undefined;
nicholas@2851 284 $s.description = "";
nicholas@2861 285
n@2908 286 $s.parseFile = function (f) {
n@2908 287 var p = new DOMParser();
n@2908 288 specification.decode(p.parseFromString(f, "text/xml"));
n@2908 289 $s.$apply();
n@2908 290 }
n@2908 291
nicholas@2861 292 $s.handleFiles = function ($event) {
nicholas@2861 293 $s.file = $event.currentTarget.files[0];
nicholas@2861 294 var r = new FileReader();
nicholas@2861 295 r.onload = function () {
n@2908 296 $s.parseFile(r.result);
nicholas@2862 297 };
nicholas@2861 298 r.readAsText($s.file);
nicholas@2861 299 };
nicholas@3099 300
nicholas@3099 301 $s.audioFragments = [];
nicholas@3099 302 $s.ondrop = function (filename) {
nicholas@3099 303 $s.audioFragments.push({
nicholas@3099 304 fname: filename,
nicholas@3099 305 name: "fragment-" + String($s.audioFragments.length)
nicholas@3099 306 });
nicholas@3099 307 };
nicholas@3099 308
nicholas@3099 309 $s.populatePages = function (structures) {
nicholas@3099 310 structures.forEach(function (p, i) {
nicholas@3099 311 var page = $w.specification.createNewPage();
nicholas@3099 312 page.id = "page-" + String(i);
nicholas@3099 313 p.forEach(function (a) {
nicholas@3099 314 var fragment = page.addAudioElement();
nicholas@3099 315 fragment.name = a.name;
nicholas@3099 316 fragment.id = a.name + "-p" + String(i);
nicholas@3099 317 fragment.url = a.fname;
nicholas@3099 318 });
nicholas@3099 319 page.addInterface();
nicholas@3099 320 });
nicholas@3099 321 }
nicholas@2851 322 }]);
nickjillings@1370 323
nicholas@2851 324 AngularInterface.controller("setup", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2851 325 function initialise() {
nicholas@2851 326 if ($s.globalSchema) {
nicholas@2851 327 $s.schema = $s.globalSchema.querySelector("[name=setup]");
nickjillings@1385 328 }
nickjillings@1370 329 }
nicholas@2851 330 $s.schema = undefined;
nicholas@2851 331 $s.attributes = [];
nickjillings@1370 332
nicholas@2851 333 $s.$watch("globalSchema", initialise);
nicholas@2853 334 $s.$watch("specification.metrics.enabled.length", function () {
nicholas@2853 335 var metricsNode = document.getElementById("metricsNode");
nicholas@2853 336 if (!$s.specification.metrics) {
nicholas@2853 337 return;
nicholas@2853 338 }
nicholas@2853 339 metricsNode.querySelectorAll("input").forEach(function (DOM) {
nicholas@2853 340 DOM.checked = false;
nicholas@2853 341 });
nicholas@2853 342 $s.specification.metrics.enabled.forEach(function (metric) {
nicholas@2853 343 var DOM = metricsNode.querySelector("[value=" + metric + "]");
nicholas@2853 344 if (DOM) {
nicholas@2853 345 DOM.checked = true;
nicholas@2853 346 }
nicholas@2853 347 });
nicholas@2855 348 });
nicholas@2853 349
nicholas@2853 350 $s.enableMetric = function ($event) {
nicholas@2853 351 var metric = $event.currentTarget.value;
nicholas@2853 352 var index = specification.metrics.enabled.findIndex(function (a) {
nicholas@2853 353 return a == metric;
nicholas@2853 354 });
nicholas@2853 355 if ($event.currentTarget.checked) {
nicholas@2853 356 if (index == -1) {
nicholas@2853 357 specification.metrics.enabled.push(metric);
nicholas@2853 358 }
nicholas@2853 359 } else {
nicholas@2853 360 if (index >= 0) {
nicholas@2853 361 specification.metrics.enabled.splice(index, 1);
nicholas@2853 362 }
nicholas@2853 363 }
nicholas@2855 364 };
nicholas@2886 365
nicholas@2886 366 $s.configure = function () {}
nicholas@2886 367
nicholas@2886 368 $s.$watch("selectedTestPrototype", $s.configure);
n@2907 369
n@2907 370 $s.placeholder = function (name) {
n@2908 371 if ($s.schema) {
n@2908 372 var spec = $s.schema.querySelector("attribute[name=\"" + name + "\"]") || $w.specification.schema.querySelector("attribute[name=\"" + name + "\"]");
n@2908 373 var attr = spec.getAttribute("default");
n@2912 374 if (attr === null) {
n@2912 375 return "Not set";
n@2908 376 }
n@2908 377 return attr;
n@2907 378 }
n@2907 379 }
nicholas@2851 380 }]);
nicholas@2853 381
nicholas@2858 382 AngularInterface.controller("survey", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2858 383 $s.addSurveyEntry = function () {
nicholas@2858 384 $s.survey.addOption();
nicholas@2858 385 };
nicholas@2858 386 $s.removeSurveyEntry = function (entry) {
nicholas@2858 387 var index = $s.survey.options.findIndex(function (a) {
nicholas@2858 388 return a == entry;
nicholas@2858 389 });
nicholas@2858 390 if (index === -1) {
nicholas@2858 391 throw ("Invalid Entry");
nicholas@2858 392 }
nicholas@2858 393 $s.survey.options.splice(index, 1);
nicholas@2858 394 };
nicholas@2858 395 }]);
nicholas@2858 396
nicholas@2853 397 AngularInterface.controller("surveyOption", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2853 398
nicholas@2853 399 $s.removeOption = function (option) {
nicholas@2853 400 var index = $s.opt.options.findIndex(function (a) {
nicholas@2853 401 return a == option;
nicholas@2853 402 });
nicholas@2853 403 if (index === -1) {
nicholas@2853 404 throw ("Invalid option");
nicholas@2853 405 }
nicholas@2853 406 $s.opt.options.splice(index, 1);
nicholas@2853 407 };
nicholas@2853 408 $s.addOption = function () {
nicholas@2853 409 $s.opt.options.push({
nicholas@2853 410 name: "",
nicholas@2853 411 text: ""
nicholas@2853 412 });
nicholas@2855 413 };
nicholas@2857 414
nicholas@2857 415 $s.addCondition = function () {
nicholas@2857 416 $s.opt.conditions.push({
nicholas@2857 417 check: "equals",
nicholas@2857 418 value: "",
nicholas@2857 419 jumpToOnPass: undefined,
nicholas@2857 420 jumpToOnFail: undefined
nicholas@2857 421 });
nicholas@2857 422 };
nicholas@2857 423
nicholas@2857 424 $s.removeCondition = function (condition) {
nicholas@2857 425 var index = $s.opt.conditions.findIndex(function (c) {
nicholas@2857 426 return c == condition;
nicholas@2857 427 });
nicholas@2857 428 if (index === -1) {
nicholas@2857 429 throw ("Invalid Condition");
nicholas@2857 430 }
nicholas@2857 431 $s.opt.conditions.splice(index, 1);
nicholas@2857 432 };
nicholas@2855 433 }]);
nicholas@2855 434
nicholas@2855 435 AngularInterface.controller("interfaceNode", ['$scope', '$element', '$window', function ($s, $e, $w) {
nicholas@2855 436 $s.$watch("interface.options.length", function () {
nicholas@2855 437 if (!$s.interface || !$s.interface.options) {
nicholas@2855 438 return;
nicholas@2855 439 }
nicholas@2855 440 var options = $e[0].querySelector(".interfaceOptions").querySelectorAll(".attribute");
nicholas@2855 441 options.forEach(function (option) {
nicholas@2855 442 var name = option.getAttribute("name");
nicholas@2855 443 var index = $s.interface.options.findIndex(function (io) {
nicholas@2855 444 return io.name == name;
nicholas@2855 445 });
nicholas@3136 446 if (name == "scalerange") {
nicholas@3136 447 $e[0].querySelector("[name=min]").value = option.getAttribute("min");
nicholas@3136 448 $e[0].querySelector("[name=max]").value = option.getAttribute("max");
nicholas@3136 449 }
nicholas@2855 450 option.querySelector("input").checked = (index >= 0);
nicholas@2855 451 });
nicholas@2855 452 });
nicholas@3136 453 $s.updateScaleRange = function() {
nicholas@3136 454 var obj = $s.interface.options.find(function(i) {
nicholas@3136 455 return i.name == "scalerange";
nicholas@3136 456 });
nicholas@3136 457 if (obj === undefined) {
nicholas@3136 458 return;
nicholas@3136 459 }
nicholas@3136 460 var min = $e[0].querySelector("[name=min]").value;
nicholas@3136 461 var max = $e[0].querySelector("[name=max]").value;
nicholas@3136 462 obj.min = min;
nicholas@3136 463 obj.max = max;
nicholas@3136 464 };
nicholas@2855 465 $s.enableInterfaceOption = function ($event) {
nicholas@2855 466 var name = $event.currentTarget.parentElement.getAttribute("name");
nicholas@2855 467 var type = $event.currentTarget.parentElement.getAttribute("type");
nicholas@2855 468 var index = $s.interface.options.findIndex(function (io) {
nicholas@2855 469 return io.name == name;
nicholas@2855 470 });
nicholas@2855 471 if (index == -1 && $event.currentTarget.checked) {
nicholas@3136 472 var obj = {
nicholas@2855 473 name: name,
nicholas@2855 474 type: type
nicholas@3136 475 };
nicholas@2855 476 if (name == "scalerange") {
nicholas@3136 477 $s.updateScaleRange();
nicholas@2855 478 }
nicholas@3136 479 $s.interface.options.push(obj);
nicholas@2855 480 } else if (index >= 0 && !$event.currentTarget.checked) {
nicholas@2855 481 $s.interface.options.splice(index, 1);
nicholas@2855 482 }
nicholas@2857 483 };
nicholas@2886 484 $s.scales = [];
nicholas@2857 485 $s.removeScale = function (scale) {
nicholas@2857 486 var index = $s.interface.scales.findIndex(function (s) {
nicholas@2857 487 return s == scale;
nicholas@2857 488 });
nicholas@2857 489 if (index >= 0) {
nicholas@2857 490 $s.interface.scales.splice(index, 1);
nicholas@2857 491 }
nicholas@2857 492 };
nicholas@2857 493 $s.addScale = function () {
nicholas@2857 494 $s.interface.scales.push({
nicholas@2857 495 position: undefined,
nicholas@2857 496 text: undefined
nicholas@2857 497 });
nicholas@2857 498 };
nicholas@2864 499 $s.clearScales = function () {
nicholas@2864 500 $s.interface.scales = [];
nicholas@2864 501 };
nicholas@2876 502 $s.useScales = function (scale) {
nicholas@2864 503 $s.clearScales();
nicholas@2876 504 scale.scales.forEach(function (s) {
nicholas@2864 505 $s.interface.scales.push(s);
nicholas@2864 506 });
nicholas@2886 507 $s.selectedScale = scale.name;
nicholas@2864 508 };
nicholas@2886 509 $s.selectedScale = undefined;
nicholas@2886 510
nicholas@2886 511 $s.configure = function () {
nicholas@2886 512 if ($s.selectedTestPrototype === undefined) {
nicholas@2886 513 return;
nicholas@2886 514 }
nicholas@2886 515 if ($s.selectedTestPrototype.checks && $s.selectedTestPrototype.checks.length >= 1) {
nicholas@2886 516 $s.selectedTestPrototype.checks.forEach(function (entry) {
nicholas@2886 517 var dom = $e[0].querySelector("[name=\"" + entry.name + "\"] input");
nicholas@2886 518 if (entry.support == "none") {
nicholas@2886 519 dom.checked = false;
nicholas@2886 520 dom.disabled = true;
nicholas@2886 521 }
nicholas@2886 522 });
nicholas@2886 523 }
nicholas@2886 524 if ($s.selectedTestPrototype.show && $s.selectedTestPrototype.show.length >= 1) {
nicholas@2886 525 $s.selectedTestPrototype.show.forEach(function (entry) {
nicholas@2886 526 var dom = $e[0].querySelector("[name=\"" + entry.name + "\"] input");
nicholas@2886 527 if (entry.support == "none") {
nicholas@2886 528 dom.checked = false;
nicholas@2886 529 dom.disabled = true;
nicholas@2886 530 }
nicholas@2886 531 });
nicholas@2886 532 }
nicholas@2886 533 if ($s.interface !== specification.interfaces) {
nicholas@2886 534 // Page specific interface nodes
nicholas@2886 535 if ($s.selectedTestPrototype.hasScales !== undefined && ($s.selectedTestPrototype.hasScales == "false" || $s.selectedTestPrototype.hasScales == false)) {
nicholas@2886 536 var elem = $e[0].querySelector("[name=\"scale-selection\"]")
nicholas@2886 537 elem.style.visibility = "hidden";
nicholas@2886 538 elem.style.height = "0px";
nicholas@2886 539 }
nicholas@2886 540 if ($s.selectedTestPrototype.scales && $s.selectedTestPrototype.show.length >= 1) {
nicholas@2886 541 $s.scales = [];
nicholas@2886 542 $s.selectedTestPrototype.scales.forEach(function (scalename) {
nicholas@2886 543 var obj = $s.testSpecifications.scales.find(function (a) {
nicholas@2886 544 return a.name == scalename;
nicholas@2886 545 });
nicholas@2886 546 $s.scales.push(obj);
nicholas@2886 547 });
nicholas@2886 548 if ($s.selectedTestPrototype.scales.includes($s.selectedScale) == false) {
nicholas@2886 549 $s.clearScales();
nicholas@2886 550 }
nicholas@2886 551 if ($s.scales.length == 1) {
nicholas@2886 552 $s.clearScales();
nicholas@2886 553 $s.useScales($s.scales[0]);
nicholas@2886 554 }
nicholas@2886 555 } else {
nicholas@2886 556 $s.scales = $s.testSpecifications.scales;
nicholas@2886 557 }
nicholas@2886 558 }
nicholas@2886 559 };
nicholas@2886 560
nicholas@2886 561 $s.$watch("selectedTestPrototype", $s.configure);
nicholas@2886 562 $s.configure();
nicholas@2853 563 }]);
nicholas@2859 564 AngularInterface.controller("page", ['$scope', '$element', '$window', function ($s, $e, $w) {
n@2907 565 $s.schema = $w.specification.schema.querySelector("element[name=\"page\"]");
n@2909 566 $s.page.label = $s.page.label || "default";
nicholas@2859 567 $s.addInterface = function () {
nicholas@2859 568 $s.page.addInterface();
nicholas@2859 569 };
nicholas@2859 570 $s.removeInterface = function (node) {
nicholas@2859 571 var index = $s.page.interfaces.findIndex(function (a) {
nicholas@2859 572 return a == node;
nicholas@2859 573 });
nicholas@2859 574 if (index === -1) {
nicholas@2859 575 throw ("Invalid node");
nicholas@2859 576 }
nicholas@2859 577 $s.page.interfaces.splice(index, 1);
nicholas@2859 578 };
nicholas@2859 579
nicholas@2859 580 $s.addCommentQuestion = function () {
nicholas@2859 581 $s.page.addCommentQuestion();
nicholas@2859 582 };
nicholas@2859 583 $s.removeCommentQuestion = function (node) {
nicholas@2859 584 var index = $s.page.commentQuestions.findIndex(function (a) {
nicholas@2859 585 return a == node;
nicholas@2859 586 });
nicholas@2859 587 if (index === -1) {
nicholas@2859 588 throw ("Invalid node");
nicholas@2859 589 }
nicholas@2859 590 $s.page.commentQuestions.splice(index, 1);
nicholas@2859 591 };
nicholas@2859 592 $s.addAudioElement = function () {
nicholas@2859 593 $s.page.addAudioElement();
nicholas@2859 594 };
nicholas@3099 595 $s.ondrop = function (filename) {
nicholas@3097 596 var fragment = $s.page.addAudioElement();
nicholas@3097 597 fragment.url = filename;
nicholas@3097 598 };
nicholas@2859 599 $s.removeAudioElement = function (element) {
nicholas@2859 600 var index = $s.page.audioElements.findIndex(function (a) {
nicholas@2859 601 return a == element;
nicholas@2859 602 });
nicholas@2859 603 if (index === -1) {
nicholas@2859 604 throw ("Invalid node");
nicholas@2859 605 }
nicholas@2859 606 $s.page.audioElements.splice(index, 1);
nicholas@2859 607 };
n@2907 608
n@2907 609 $s.placeholder = function (name) {
n@2907 610 var spec = $s.schema.querySelector("attribute[name=\"" + name + "\"]") || $w.specification.schema.querySelector("attribute[name=\"" + name + "\"]");
n@2907 611 var attr = spec.getAttribute("default");
n@2912 612 if (attr === null) {
n@2912 613 return "Not set";
n@2907 614 }
n@2907 615 return attr;
n@2907 616 }
nicholas@2859 617 }]);