[TIC-Web] fix the exports api 31/107231/2
authorChangHyun Lee <leechwin.lee@samsung.com>
Tue, 27 Dec 2016 07:54:28 +0000 (16:54 +0900)
committerChangHyun Lee <leechwin.lee@samsung.com>
Tue, 27 Dec 2016 07:56:57 +0000 (16:56 +0900)
- modified the RESTful API handled by the server

Change-Id: I6095aea908bbe4b1a8265fc37bb4a3b93ced1fc9
Signed-off-by: ChangHyun Lee <leechwin.lee@samsung.com>
app.js
public/src/js/page/image.js

diff --git a/app.js b/app.js
index 86d089d..085469b 100644 (file)
--- a/app.js
+++ b/app.js
@@ -67,6 +67,40 @@ app.post('/analysis', function(req, res) {
     ticCoreReq.end();
 });
 
+/**
+ * Get ks file path from tic-core via RESTful API
+ * @URI /exports
+ * @TYPE POST
+ */
+app.post('/exports', function(req, res) {
+    var postData = JSON.stringify(req.body);
+    var addr = server.address();
+
+    var options = {
+        host: addr.address,
+        port: Config.TIC_CORE.PORT || addr.port + 1,
+        method: 'POST',
+        path: '/exports',
+        headers: {
+            'Content-Type': 'application/json',
+            'Content-Length': Buffer.byteLength(postData)
+        }
+    };
+
+    var data = '';
+    var ticCoreReq = http.request(options, function (ticCoreRes) {
+        ticCoreRes.setEncoding('utf8');
+        ticCoreRes.on('data', function (chunk) {
+            data += chunk;
+        });
+        ticCoreRes.on('end', function () {
+            res.send(data);
+        });
+    });
+
+    ticCoreReq.write(postData);
+    ticCoreReq.end();
+});
 
 
 /**
index 9c82dca..4875f9d 100644 (file)
@@ -14,7 +14,7 @@ define([
     var checkedPackagesList;
 
     // template for the URL
-    var URL_EXPORTS = '<%= protocol %>//<%= hostname %>:<%= port %>/exports';
+    var URL_EXPORTS = '<%= url %>/exports';
 
     // the path for ks
     var PATH_TIC_KS = '/tmp/tic/ks/';
@@ -130,6 +130,7 @@ define([
             };
 
             tableDomElem = $('#tic-image-new-log');
+            tableDomElem.empty();
 
             client.emit('ws/fs/image/add/from', msgData);
 
@@ -137,6 +138,7 @@ define([
                 var elem = document.createElement('p');
                 elem.innerText = data;
                 tableDomElem.append(elem);
+
                 $('#tic-image-new').animate({ scrollTop : $('#tic-image-new').height() }, 'slow');
             });
 
@@ -150,12 +152,6 @@ define([
                 // button enabled
                 $('#tic-image-create').prop('disabled', false);
 
-                // the logs are removed
-                $('#tic-image-new-log').empty();
-
-                // creation was hidden when finished.
-                $('#tic-image-new-container').hide();
-
                 // upate the list of images
                 updateList(null);
             });
@@ -163,9 +159,7 @@ define([
 
         function getExportsUrl() {
             return _.template(URL_EXPORTS)({
-                protocol: location.protocol,
-                hostname: location.hostname,
-                port: parseInt(location.port) + 1
+                url: location.origin
             });
         }
 
@@ -179,14 +173,12 @@ define([
                     output: PATH_TIC_KS
                 };
 
-                // creation is shown when creation started.
-                $('#tic-image-new-container').show();
-
                 $.ajax({
                     type: 'POST',
-                    contentType: 'text/plain',
-                    data: JSON.stringify(msgData),
+                    contentType: 'application/json; charset=UTF-8',
                     dataType: 'json',
+                    data: JSON.stringify(msgData),
+                    processData: false,
                     url: getExportsUrl(),
                     success: function (res) {
                         resolve(res.data);
@@ -199,7 +191,7 @@ define([
         }
 
         // confirm
-        Util.showConfirmDialog('Are you sure?')
+        Util.showConfirmDialog('Are you sure want to create the image?')
         .then(function () {
             getKickstartRecipeFile()
             .then(createImage)
@@ -221,9 +213,6 @@ define([
         // button
         $('#tic-image-create').prop('disabled', true);
         $('#tic-image-create').click(confirmCreateImage);
-
-        // creation was hidden when started.
-        $('#tic-image-new-container').hide();
     }
 
     function init() {