changeset 3007:37923d45f298

Add sort to discrete #119
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Thu, 03 Aug 2017 15:06:29 +0200
parents 50f5e11a38b7
children 166c5aef020c
files interfaces/discrete.js
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/interfaces/discrete.js	Thu Aug 03 15:01:52 2017 +0200
+++ b/interfaces/discrete.js	Thu Aug 03 15:06:29 2017 +0200
@@ -67,9 +67,19 @@
     submit.onclick = buttonSubmitClick;
     submit.id = 'submit-button';
     submit.style.float = 'left';
+
+    // Create the sort button
+    var sort = document.createElement("button");
+    sort.id = "sort-fragments";
+    sort.textContent = "Sort";
+    sort.style.display = "inline-block";
+    sort.style.visibility = "hidden";
+    sort.onclick = buttonSortFragmentClick;
+
     // Append the interface buttons into the interfaceButtons object.
     interfaceButtons.appendChild(playback);
     interfaceButtons.appendChild(submit);
+    interfaceButtons.appendChild(sort);
 
     // Create a slider box
     var sliderBox = document.createElement('div');
@@ -187,6 +197,10 @@
                 case "comments":
                     interfaceContext.commentBoxes.showCommentBoxes(feedbackHolder, true);
                     break;
+                case "fragmentSort":
+                    var button = document.getElementById('sort-fragments');
+                    button.style.visibility = "visible";
+                    break;
             }
         }
     });
@@ -539,6 +553,22 @@
     }
 }
 
+function buttonSortFragmentClick() {
+    var sortIndex = interfaceContext.sortFragmentsByScore();
+    var sliderBox = document.getElementById("slider-holder");
+    var nodes = audioEngineContext.audioObjects.filter(function (ao) {
+        return ao.specification.type !== "outside-reference";
+    });
+    var i;
+    nodes.forEach(function (ao) {
+        sliderBox.removeChild(ao.interfaceDOM.holder);
+    });
+    for (i = 0; i < nodes.length; i++) {
+        var j = sortIndex[i];
+        sliderBox.appendChild(nodes[j].interfaceDOM.holder);
+    }
+}
+
 function pageXMLSave(store, pageSpecification) {
     // MANDATORY
     // Saves a specific test page