changeset 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 998e05c5769a
files test_create.html test_create/test_core.js
diffstat 2 files changed, 79 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/test_create.html	Tue Jan 16 15:23:45 2018 +0000
+++ b/test_create.html	Tue Jan 16 16:11:35 2018 +0000
@@ -1093,8 +1093,8 @@
         <div class="modal-dialog modal-lg" role="document">
             <div class="modal-content">
                 <div class="modal-header">
-                    <h4>Test Creator</h4>
-                    <h4 class="label label-primary">v1.2.3</h4>
+                    <h3>Test Creator</h3>
+                    <h3 class="label label-primary">v1.2.3</h3>
                 </div>
                 <div class="modal-body" ng-switch="state">
                     <div ng-switch-when="0">
@@ -1110,7 +1110,7 @@
                             <span>Please select the interface you would like to use below. Selecting an interface will give a brief description of the interface type.</span>
                         </div>
                         <div class="row">
-                            <div class="col-md-6" style="overflow-y: scroll;height: 333px;">
+                            <div class="col-md-6">
                                 <div class="new-test" ng-repeat="i in testSpecifications.interfaces" ng-mouseover="mouseover(i.name)" ng-click="select(i.name)">
                                     <label style="cursor:pointer">
                                         <input type="radio" name="new-test" value="{{i.name}}" id="i.name" style="cursor:pointer" /> {{i.name}}
@@ -1122,9 +1122,28 @@
                             </div>
                         </div>
                     </div>
+                    <div ng-switch-when="2" dropzone>
+                        <div>
+                            <h4>Audio Files</h4>
+                            <p>{{selected}} is a pairwise test with only two fragments per page. To make it easy to add a lot of fragments (and therefore pages) you can automatically drop your fragments onto here, set a name for each and we will populate your page elements for you!</p>
+                        </div>
+                        <table class="table table-bordered">
+                            <tr>
+                                <td>Filename</td>
+                                <td>Name</td>
+                            </tr>
+                            <tr ng-repeat="elem in audioFragments">
+                                <td>{{elem.fname}}</td>
+                                <td>
+                                    <input type="text" ng-model="elem.name" required />
+                                </td>
+                            </tr>
+                        </table>
+                    </div>
                 </div>
                 <div class="modal-footer">
                     <button id="popupBack" type="button" class="btn btn-default" ng-show="state>0" ng-click="back()">Back</button>
+                    <button id="popupNext" type="button" class="btn btn-warning" ng-show="state>1" ng-click="skip()">Skip</button>
                     <button id="popupNext" type="button" class="btn btn-default" ng-click="next()">Next</button>
                 </div>
             </div>
--- a/test_create/test_core.js	Tue Jan 16 15:23:45 2018 +0000
+++ b/test_create/test_core.js	Tue Jan 16 16:11:35 2018 +0000
@@ -57,7 +57,7 @@
 
                     reader.onload = (function (theFile) {
                         return function (e) {
-                            scope.addAudioElementFromFile(theFile.name);
+                            scope.ondrop(theFile.name);
                             scope.$apply();
                         };
                     })(f);
@@ -207,13 +207,39 @@
 AngularInterface.controller("introduction", ['$scope', '$element', '$window', function ($s, $e, $w) {
     $s.state = 0;
     $s.selected = undefined;
+    $s.close = function () {
+        $($e[0]).modal('hide');
+    }
     $s.next = function () {
+        if (($s.state === 0 && $s.file) || $s.state === 1) {
+            $s.initialise($s.selected);
+            if ($s.selected != "AB" && $s.selected != "ABX") {
+                $s.close();
+            }
+        } else if ($s.state === 2 && $s.audioFragments.length > 0) {
+            // Populate the audio pages by creating a pairwise set of pairs
+            $s.populatePages((function (a) {
+                var b = [];
+                a.forEach(function (e1, i1, a) {
+                    a.forEach(function (e2, i2) {
+                        var entry = [e1, e2];
+                        if (i1 > i2) {
+                            b.push(entry);
+                        }
+                    });
+                });
+                return b;
+            })($s.audioFragments));
+            $s.close();
+        } else if ($s.state > 2) {
+            $s.close();
+        }
         $s.state++;
-        if ($s.state > 1 || $s.file) {
-            $($e[0]).modal('hide')
-            $s.initialise($s.selected);
-        }
+        console.log("Modal state " + $s.state);
     };
+    $s.skip = function () {
+        $s.close();
+    }
     $s.back = function () {
         $s.state--;
     };
@@ -241,9 +267,9 @@
         }
     };
     $s.select = function (name) {
-            $s.selected = name;
-        }
-        // Get the test interface specifications
+        $s.selected = name;
+    };
+    // Get the test interface specifications
     $s.file = undefined;
     $s.description = "";
 
@@ -261,6 +287,28 @@
         };
         r.readAsText($s.file);
     };
+
+    $s.audioFragments = [];
+    $s.ondrop = function (filename) {
+        $s.audioFragments.push({
+            fname: filename,
+            name: "fragment-" + String($s.audioFragments.length)
+        });
+    };
+
+    $s.populatePages = function (structures) {
+        structures.forEach(function (p, i) {
+            var page = $w.specification.createNewPage();
+            page.id = "page-" + String(i);
+            p.forEach(function (a) {
+                var fragment = page.addAudioElement();
+                fragment.name = a.name;
+                fragment.id = a.name + "-p" + String(i);
+                fragment.url = a.fname;
+            });
+            page.addInterface();
+        });
+    }
 }]);
 
 AngularInterface.controller("setup", ['$scope', '$element', '$window', function ($s, $e, $w) {
@@ -522,7 +570,7 @@
     $s.addAudioElement = function () {
         $s.page.addAudioElement();
     };
-    $s.addAudioElementFromFile = function (filename) {
+    $s.ondrop = function (filename) {
         var fragment = $s.page.addAudioElement();
         fragment.url = filename;
     };