changeset 2864:df1823dbfb93

Add use scale to test_create
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Thu, 27 Apr 2017 14:19:25 +0100
parents 7b1c05a9514a
children d5e7f45b15e7
files test_create.html test_create/test_core.js
diffstat 2 files changed, 44 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/test_create.html	Thu Apr 27 13:55:40 2017 +0100
+++ b/test_create.html	Thu Apr 27 14:19:25 2017 +0100
@@ -839,7 +839,17 @@
                 </div>
                 <div class="node">
                     <h3>Axis Scales</h3>
-                    <button type="button" class="btn btn-default" ng-click="addScale();">Add</button>
+                    <button type="button" class="btn btn-success" ng-click="addScale();">Add</button>
+                    <button type="button" class="btn btn-danger" ng-click="clearScales()" ng-show="interface.scales.length > 0">Clear Scales</button>
+                    <div class="dropdown" style="display: inline-block;">
+                        <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
+                            Use scale...
+                            <span class="caret"></span>
+                        </button>
+                        <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
+                            <li ng-repeat="scale in testSpecifications.scales" ng-click="useScales(scale.scales)"><a href="#">{{scale.name}}</a></li>
+                        </ul>
+                    </div>
                     <div class="node" ng-repeat="scale in interface.scales">
                         <div class="attributes">
                             <div class="attribute">
@@ -1011,7 +1021,7 @@
                         </div>
                         <div class="row">
                             <div class="col-md-6" style="overflow-y: scroll;height: 333px;">
-                                <div class="new-test" ng-repeat="i in interfaces" ng-mouseover="mouseover(i.name)" ng-click="initialise(i.name)">
+                                <div class="new-test" ng-repeat="i in testSpecifications.interfaces" ng-mouseover="mouseover(i.name)" ng-click="initialise(i.name)">
                                     <label style="cursor:pointer">
                                         <input type="radio" name="new-test" value="{{i.name}}" id="i.name" style="cursor:pointer" /> {{i.name}}
                                     </label>
--- a/test_create/test_core.js	Thu Apr 27 13:55:40 2017 +0100
+++ b/test_create/test_core.js	Thu Apr 27 14:19:25 2017 +0100
@@ -46,6 +46,28 @@
 
 AngularInterface.controller("view", ['$scope', '$element', '$window', function ($s, $e, $w) {
     $s.popupVisible = true;
+    $s.testSpecifications = {};
+
+    (function () {
+        new Promise(function (resolve, reject) {
+            var xml = new XMLHttpRequest();
+            xml.open("GET", "test_create/interfaces/specifications.json");
+            xml.onload = function () {
+                if (xml.status === 200) {
+                    resolve(xml.responseText);
+                    return;
+                }
+                reject(xml.status);
+            };
+            xml.onerror = function () {
+                reject(new Error("Network Error"));
+            };
+            xml.send();
+        }).then(JSON.parse).then(function (data) {
+            $s.testSpecifications = data;
+            $s.$apply();
+        })
+    })();
 
     $s.showPopup = function () {
         $s.popupVisible = true;
@@ -97,7 +119,7 @@
         $s.state--;
     };
     $s.mouseover = function (name) {
-        var obj = $s.interfaces.find(function (i) {
+        var obj = $s.testSpecifications.interfaces.find(function (i) {
             return i.name == name;
         });
         if (obj) {
@@ -111,27 +133,8 @@
         specification.interface = obj.interface;
     };
     // Get the test interface specifications
-    $s.interfaces = {};
     $s.file = undefined;
     $s.description = "";
-    var interfaceCollection = new Promise(function (resolve, reject) {
-        var xml = new XMLHttpRequest();
-        xml.open("GET", "test_create/interfaces/specifications.json");
-        xml.onload = function () {
-            if (xml.status === 200) {
-                resolve(xml.responseText);
-                return;
-            }
-            reject(xml.status);
-        };
-        xml.onerror = function () {
-            reject(new Error("Network Error"));
-        };
-        xml.send();
-    }).then(JSON.parse).then(function (data) {
-        $s.interfaces = data.interfaces;
-        $s.$apply();
-    });
 
     $s.handleFiles = function ($event) {
         $s.file = $event.currentTarget.files[0];
@@ -292,6 +295,15 @@
             text: undefined
         });
     };
+    $s.clearScales = function () {
+        $s.interface.scales = [];
+    };
+    $s.useScales = function (scales) {
+        $s.clearScales();
+        scales.forEach(function (s) {
+            $s.interface.scales.push(s);
+        });
+    };
 }]);
 AngularInterface.controller("page", ['$scope', '$element', '$window', function ($s, $e, $w) {
     $s.addInterface = function () {