[TIC-Web] add recipe export 08/125608/5
authorChangHyun Lee <leechwin.lee@samsung.com>
Tue, 18 Apr 2017 05:57:42 +0000 (14:57 +0900)
committerChangHyun Lee <leechwin.lee@samsung.com>
Tue, 18 Apr 2017 10:08:15 +0000 (19:08 +0900)
- add recipe export

Change-Id: I677eb0fc0a46e35d808a25f06746be14fc3360c5
Signed-off-by: ChangHyun Lee <leechwin.lee@samsung.com>
config.json
controller/router.js
controller/ticcore.js
public/src/index.html
public/src/js/page/export.js
public/src/js/page/job.js
public/src/js/page/package.js

index 639c576..6756b19 100644 (file)
@@ -55,6 +55,8 @@
         "PACKAGE": {
             "IMPORT": "/api/imports/",
             "EXPORT": "/api/exports/",
+            "EXPORT_KS": "ks",
+            "EXPORT_RECIPE": "recipe",
             "ANALYSIS": "/api/analysis",
             "RECIPE_UPLOAD": "/api/recipe/upload"
         },
index 1826f76..c779496 100644 (file)
@@ -221,10 +221,10 @@ var init = function (serv) {
 
     /**
      * Get ks file path from tic-core via RESTful API
-     * @URI /api/exports
+     * @URI /api/exports:format
      * @TYPE POST
      */
-    router.post('/exports', function (req, res) {
+    router.post('/exports/:format', function (req, res) {
         logger.info('an api called that /api/exports');
         core.getExports(req, res);
     });
index 429e49f..eaacc50 100644 (file)
@@ -19,6 +19,7 @@
 var JL = require('jsnlog').JL;
 var logger = JL('ticcore.js');
 var http = require('http');
+var _ = require('lodash');
 var AppConfig = require('../config.json');
 
 /**
@@ -31,6 +32,8 @@ var ticcore = {};
  */
 ticcore.server = null;
 
+var EXPORT_FORMAT = 'exports?format=<%= format %>';
+
 /**
  * initialize
  */
@@ -121,27 +124,26 @@ ticcore.getImports = function getImports (req, res) {
 };
 
 ticcore.getExports = function getExports(req, res) {
-    var postData, addr, options, data, ticCoreReq;
-
-    postData = JSON.stringify(req.body);
-
+    var postData = JSON.stringify(req.body);
     logger.info('getExports: ' + postData);
 
-    addr = this.server.address();
+    var addr = this.server.address();
 
-    options = {
+    var options = {
         host: addr.address,
         port: AppConfig.TIC_CORE.PORT || addr.port + 1,
         method: 'POST',
-        path: '/exports',
+        path: _.template(EXPORT_FORMAT)({
+            format: req.params.format
+        }),
         headers: {
             'Content-Type': 'application/json',
             'Content-Length': Buffer.byteLength(postData)
         }
     };
 
-    data = '';
-    ticCoreReq = http.request(options, function (ticCoreRes) {
+    var data = '';
+    var ticCoreReq = http.request(options, function (ticCoreRes) {
         ticCoreRes.setEncoding('utf8');
         ticCoreRes.on('data', function (chunk) {
             data += chunk;
index 7cdb5a4..03de3cb 100644 (file)
             </div>
         </div><!-- /End Import Dialog -->
 
+        <!-- Export -->
+        <div class="hidden">
+            <a id="tic-export-recipe" target="_blank" href="" download></a>
+        </div><!-- /End Export -->
+
         <!-- library loading -->
         <script src="/socket.io/socket.io.js"></script>
         <script src="/js/config.js"></script>
index 8f5d32d..1737898 100644 (file)
@@ -29,13 +29,38 @@ define([
 
     var logger = Logger('export.js');
 
+    var CONFIG = null;
+
     function showExportDialog() {
-        // TODO: show export dialog
-        Util.showAlertDialog('Not yet implemented');
+        Util.showConfirmDialog('Are you sure you want to export recipe?')
+        .then(function () {
+            return Util.POST(CONFIG.EVENT.PACKAGE.EXPORT + CONFIG.EVENT.PACKAGE.EXPORT_RECIPE, {
+                recipes: require('js/page/settings').getRecipeStore(),
+                packages: _.map(require('js/page/package').getCheckedPackages(), 'name'),
+                outdir: CONFIG.TIC_WEB.PATH_RECIPE_EXPORT
+            });
+        })
+        .then(function (res) {
+            if (res.result === 'false') {
+                return Promise.reject(res.message);
+            } else {
+                var recipePath = res.data.path.replace('var/tmp/tic-web', 'tic');
+                $('#tic-export-recipe').attr('href', recipePath)[0].click();
+            }
+        })
+        .catch(function (err) {
+            logger.error(err);
+            Util.showAlertDialog(err);
+        });
     }
 
     function _init() {
         logger.info('init');
+
+        Util.getAppConfig()
+        .then(function (conf) {
+            CONFIG = conf;
+        });
     }
 
     _init();
index 9948838..1e3faf5 100644 (file)
@@ -229,7 +229,7 @@ define([
                 job_pid: dataObj.jobProcessId,
                 job_updater: UserInfo.email
             };
-            logger.error('MIC_ADD_PID_JOB_TO: ' + JSON.stringify(msgObj));
+            logger.info('MIC_ADD_PID_JOB_TO: ' + JSON.stringify(msgObj));
             return Util.POST(AppConfig.EVENT.JOB.JOB_EDIT_ONE + dataObj.jobId, msgObj);
         });
 
index 6a7990b..2f72976 100644 (file)
@@ -140,7 +140,7 @@ define([
             }
 
             function getKickStartFile () {
-                return Util.POST(AppConfig.EVENT.PACKAGE.EXPORT, msgData);
+                return Util.POST(AppConfig.EVENT.PACKAGE.EXPORT + AppConfig.EVENT.PACKAGE.EXPORT_KS, msgData);
             }
 
             return getKickStartFile()