changeset 2861:79258b2a8245

Completed file upload for test_create
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Thu, 27 Apr 2017 12:57:31 +0100
parents 65b8d9ad75cc
children b8795a6452f8
files test_create.html test_create/test_core.js
diffstat 2 files changed, 24 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/test_create.html	Thu Apr 27 12:19:20 2017 +0100
+++ b/test_create.html	Thu Apr 27 12:57:31 2017 +0100
@@ -1000,7 +1000,9 @@
                         <div>
                             <span>Welcome to the WAET test creator tool. This will allow you to create a new test from scratch to suit your testing needs. If you wish to update a test file, please drag and drop the XML document into the area below for processing, otherwise press 'Next' to start a new test. This tool generates files for the WAET 1.2.1 version.</span>
                         </div>
-                        <div class="drag-drop" id="introdragdrop"><span>Upload XML here</span></div>
+                        <div>
+                            <input type="file" id="files" ng-model="files" onchange="handleFiles(event)" />
+                        </div>
                     </div>
                     <div ng-switch-when="1">
                         <div>
--- a/test_create/test_core.js	Thu Apr 27 12:19:20 2017 +0100
+++ b/test_create/test_core.js	Thu Apr 27 12:57:31 2017 +0100
@@ -1,4 +1,4 @@
-/* globals document, angular, window, Promise, XMLHttpRequest, Specification */
+/* globals document, angular, window, Promise, XMLHttpRequest, Specification, XMLSerializer, Blob, DOMParser*/
 function get(url) {
     // Return a new promise.
     return new Promise(function (resolve, reject) {
@@ -38,6 +38,12 @@
 
 };
 
+function handleFiles(event) {
+    var s = angular.element(event.currentTarget).scope();
+    s.handleFiles(event);
+    s.$apply();
+}
+
 AngularInterface.controller("view", ['$scope', '$element', '$window', function ($s, $e, $w) {
     $s.popupVisible = true;
 
@@ -66,14 +72,14 @@
         });
         var dnlk = window.URL.createObjectURL(bb);
         window.location.href = dnlk;
-    }
+    };
 }]);
 
 AngularInterface.controller("introduction", ['$scope', '$element', '$window', function ($s, $e, $w) {
     $s.state = 0;
     $s.next = function () {
         $s.state++;
-        if ($s.state > 1) {
+        if ($s.state > 1 || $s.file) {
             $s.hidePopup();
         }
     };
@@ -96,6 +102,7 @@
     };
     // Get the test interface specifications
     $s.interfaces = {};
+    $s.file = undefined;
     $s.description = "";
     var interfaceCollection = new Promise(function (resolve, reject) {
         var xml = new XMLHttpRequest();
@@ -115,6 +122,17 @@
         $s.interfaces = data.interfaces;
         $s.$apply();
     });
+
+    $s.handleFiles = function ($event) {
+        $s.file = $event.currentTarget.files[0];
+        var r = new FileReader();
+        r.onload = function () {
+            var p = new DOMParser();
+            specification.decode(p.parseFromString(r.result, "text/xml"));
+            $s.$apply();
+        }
+        r.readAsText($s.file);
+    };
 }]);
 
 AngularInterface.controller("setup", ['$scope', '$element', '$window', function ($s, $e, $w) {