comparison test_create/test_core.js @ 3099:fc9718756d55

#200 Auto-pair fragments for AB and ABX in test create.
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Tue, 16 Jan 2018 16:11:35 +0000
parents 348d59ab726e
children 1ae8c03dd6a6
comparison
equal deleted inserted replaced
3098:348d59ab726e 3099:fc9718756d55
55 var reader = new FileReader(); 55 var reader = new FileReader();
56 reader.readAsArrayBuffer(f); 56 reader.readAsArrayBuffer(f);
57 57
58 reader.onload = (function (theFile) { 58 reader.onload = (function (theFile) {
59 return function (e) { 59 return function (e) {
60 scope.addAudioElementFromFile(theFile.name); 60 scope.ondrop(theFile.name);
61 scope.$apply(); 61 scope.$apply();
62 }; 62 };
63 })(f); 63 })(f);
64 } 64 }
65 }); 65 });
205 }]); 205 }]);
206 206
207 AngularInterface.controller("introduction", ['$scope', '$element', '$window', function ($s, $e, $w) { 207 AngularInterface.controller("introduction", ['$scope', '$element', '$window', function ($s, $e, $w) {
208 $s.state = 0; 208 $s.state = 0;
209 $s.selected = undefined; 209 $s.selected = undefined;
210 $s.close = function () {
211 $($e[0]).modal('hide');
212 }
210 $s.next = function () { 213 $s.next = function () {
214 if (($s.state === 0 && $s.file) || $s.state === 1) {
215 $s.initialise($s.selected);
216 if ($s.selected != "AB" && $s.selected != "ABX") {
217 $s.close();
218 }
219 } else if ($s.state === 2 && $s.audioFragments.length > 0) {
220 // Populate the audio pages by creating a pairwise set of pairs
221 $s.populatePages((function (a) {
222 var b = [];
223 a.forEach(function (e1, i1, a) {
224 a.forEach(function (e2, i2) {
225 var entry = [e1, e2];
226 if (i1 > i2) {
227 b.push(entry);
228 }
229 });
230 });
231 return b;
232 })($s.audioFragments));
233 $s.close();
234 } else if ($s.state > 2) {
235 $s.close();
236 }
211 $s.state++; 237 $s.state++;
212 if ($s.state > 1 || $s.file) { 238 console.log("Modal state " + $s.state);
213 $($e[0]).modal('hide') 239 };
214 $s.initialise($s.selected); 240 $s.skip = function () {
215 } 241 $s.close();
216 }; 242 }
217 $s.back = function () { 243 $s.back = function () {
218 $s.state--; 244 $s.state--;
219 }; 245 };
220 $s.mouseover = function (name) { 246 $s.mouseover = function (name) {
221 var obj = $s.testSpecifications.interfaces.find(function (i) { 247 var obj = $s.testSpecifications.interfaces.find(function (i) {
239 } else { 265 } else {
240 $s.setTestPrototype(obj); 266 $s.setTestPrototype(obj);
241 } 267 }
242 }; 268 };
243 $s.select = function (name) { 269 $s.select = function (name) {
244 $s.selected = name; 270 $s.selected = name;
245 } 271 };
246 // Get the test interface specifications 272 // Get the test interface specifications
247 $s.file = undefined; 273 $s.file = undefined;
248 $s.description = ""; 274 $s.description = "";
249 275
250 $s.parseFile = function (f) { 276 $s.parseFile = function (f) {
251 var p = new DOMParser(); 277 var p = new DOMParser();
259 r.onload = function () { 285 r.onload = function () {
260 $s.parseFile(r.result); 286 $s.parseFile(r.result);
261 }; 287 };
262 r.readAsText($s.file); 288 r.readAsText($s.file);
263 }; 289 };
290
291 $s.audioFragments = [];
292 $s.ondrop = function (filename) {
293 $s.audioFragments.push({
294 fname: filename,
295 name: "fragment-" + String($s.audioFragments.length)
296 });
297 };
298
299 $s.populatePages = function (structures) {
300 structures.forEach(function (p, i) {
301 var page = $w.specification.createNewPage();
302 page.id = "page-" + String(i);
303 p.forEach(function (a) {
304 var fragment = page.addAudioElement();
305 fragment.name = a.name;
306 fragment.id = a.name + "-p" + String(i);
307 fragment.url = a.fname;
308 });
309 page.addInterface();
310 });
311 }
264 }]); 312 }]);
265 313
266 AngularInterface.controller("setup", ['$scope', '$element', '$window', function ($s, $e, $w) { 314 AngularInterface.controller("setup", ['$scope', '$element', '$window', function ($s, $e, $w) {
267 function initialise() { 315 function initialise() {
268 if ($s.globalSchema) { 316 if ($s.globalSchema) {
520 $s.page.commentQuestions.splice(index, 1); 568 $s.page.commentQuestions.splice(index, 1);
521 }; 569 };
522 $s.addAudioElement = function () { 570 $s.addAudioElement = function () {
523 $s.page.addAudioElement(); 571 $s.page.addAudioElement();
524 }; 572 };
525 $s.addAudioElementFromFile = function (filename) { 573 $s.ondrop = function (filename) {
526 var fragment = $s.page.addAudioElement(); 574 var fragment = $s.page.addAudioElement();
527 fragment.url = filename; 575 fragment.url = filename;
528 }; 576 };
529 $s.removeAudioElement = function (element) { 577 $s.removeAudioElement = function (element) {
530 var index = $s.page.audioElements.findIndex(function (a) { 578 var index = $s.page.audioElements.findIndex(function (a) {