[TIC-UI] Implementing image list in image page 24/105024/2
authorChangHyun Lee <leechwin.lee@samsung.com>
Thu, 15 Dec 2016 06:37:24 +0000 (15:37 +0900)
committerChangHyun Lee <leechwin.lee@samsung.com>
Thu, 15 Dec 2016 06:44:09 +0000 (15:44 +0900)
- Implementing prototype

Signed-off-by: ChangHyun Lee <leechwin.lee@samsung.com>
Change-Id: Id6230927f97d924e3a288866622dd856c210f4ac

app.js
public/src/index.html
public/src/js/main.js
public/src/js/page/image.js
resource/images/aa.img [new file with mode: 0644]
resource/images/bb.img [new file with mode: 0644]
resource/images/cc.img [new file with mode: 0644]
resource/images/dd.img [new file with mode: 0644]
server/fs/ws.filesystem.js [new file with mode: 0644]

diff --git a/app.js b/app.js
index 5025ec0..15ba9a5 100644 (file)
--- a/app.js
+++ b/app.js
@@ -6,20 +6,31 @@ var fs = require('fs');
 var express = require('express');
 var bodyParser = require('body-parser');
 
+var FileSystem = require('./server/fs/ws.filesystem');
+
 var app = express();
 var server = http.createServer(app);
 var io = socketio.listen(server);
 
 /* FIXME: change port
  @author: leechwin.lee@samsung.com
* @author: leechwin.lee@samsung.com
  */
 app.set('port', process.env.PORT || 59002);
 app.use(bodyParser.json());
 app.use(bodyParser.urlencoded());
 
-app.use(express.static(path.join(__dirname, '/public/src')));
+app.use(express.static(path.join(__dirname, '/public/src'))); //module directory
+
+/**
+ * TODO
+ *
+ * apply router
+ *
+ * var AppRouter = require('./routes');
+ * app.use(mount('/', AppRouter));
+ */
 
-server.listen(app.get('port'),  process.env.IP || "0.0.0.0", function(){
+server.listen(app.get('port'), process.env.IP || "0.0.0.0", function () {
     var addr = server.address();
     console.log('Server listening at', addr.address + ':' + addr.port);
 });
@@ -32,10 +43,29 @@ server.listen(app.get('port'),  process.env.IP || "0.0.0.0", function(){
 io.on('connection', function (socket) {
     console.log('socket connection');
 
+    socket.on('ws/fs/image/list/from', function (data) {
+        var msgData, fileList, targetDirectory;
+
+        msgData = {};
+        fileList = [];
+        targetDirectory = data.path;
+
+        // get the list of file
+        fileList = FileSystem.list(targetDirectory);
+
+        // set the list
+        msgData.list = fileList;
+
+        // send
+        socket.emit('ws/fs/image/list/to', msgData);
+    });
+
     socket.on('disconnect', function () {
         console.log('socket disconnect');
     });
+
     socket.on('message', function (msg) {
         console.log('socket message');
     });
-});
+
+});
\ No newline at end of file
index 0119138..cfbd630 100644 (file)
                         <div class="panel panel-primary">
                             <div class="panel-heading">Image List</div>
                             <div class="panel-body">
-                                <h1>TODO</h1>
                                 <h1>Image list and download</h1>
+                                <table id="tic-image-list"></table>
                             </div>
                         </div>
                     </div><!-- /End Image List Column -->
index 4406ade..8f4d7e2 100644 (file)
@@ -12,24 +12,28 @@ define([
     bootstrapTreeview,
     Util,
     Package,
-    Settings
+    Settings,
+    Image
 ) {
     'use strict';
 
+    var socket;
+
     function init() {
         console.log("main: init")
 
-        /* client - socket test */
-        var socket = io.connect();
-        socket.on('connect', function () {
-            console.log('client connect');
-        });
+        /* client */
+        socket = io.connect();
     }
 
     $(document).ready(function () {
         init();
 
+        // Image - the list of images
+        Image.updateList(socket);
+
         Util.showLoadingDialog(true);
+
         Settings.updatePackage()
         .then(Package.updatePackageTree)
         .then(function () {
index bfb0cd3..485c1ce 100644 (file)
@@ -7,6 +7,42 @@ define([
 ) {
     'use strict';
 
+    var client;
+
+    function updateList(socket) {
+        /**
+         * FIXME
+         *
+         * changed to be set the path dynamically
+         */
+        var msgData = {
+            path: './resource/images/'
+        };
+
+        /**
+         * TODO
+         * checks
+         */
+        client = socket;
+
+        client.emit('ws/fs/image/list/from', msgData);
+
+        client.on('ws/fs/image/list/to', function (data) {
+            var list, tableDomElem;
+
+            list = data.list;
+            tableDomElem = $('#tic-image-list');
+
+            /**
+             * FIXME
+             */
+            list.forEach(function (file) {
+                tableDomElem.append(file.name + ' (size:' + file.size + ')' + '</br>');
+            });
+        });
+
+    }
+
     function updateSummary() {
         var pacakgeImageSize = $('#tic-image-image-size').empty();
         var packageImageInstalledSize = $('#tic-image-image-installed-size').empty();
@@ -50,7 +86,8 @@ define([
          * Update summary in image page
          * @method updateSummary
          */
-        updateSummary: updateSummary
+        updateSummary: updateSummary,
+        updateList: updateList
     }
 
 });
\ No newline at end of file
diff --git a/resource/images/aa.img b/resource/images/aa.img
new file mode 100644 (file)
index 0000000..72943a1
--- /dev/null
@@ -0,0 +1 @@
+aaa
diff --git a/resource/images/bb.img b/resource/images/bb.img
new file mode 100644 (file)
index 0000000..3f07055
--- /dev/null
@@ -0,0 +1,10 @@
+aaakkkkkkkkkkkk
+dkfjakdjf'
+dkfjakdjf'
+dkfjakdjf'
+dkfjakdjf'
+dkfjakdjf'
+dkfjakdjf'
+dkfjakdjf'
+dkfjakdjf'
+
diff --git a/resource/images/cc.img b/resource/images/cc.img
new file mode 100644 (file)
index 0000000..17aa032
--- /dev/null
@@ -0,0 +1,47 @@
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
+aaa
diff --git a/resource/images/dd.img b/resource/images/dd.img
new file mode 100644 (file)
index 0000000..36d4f52
--- /dev/null
@@ -0,0 +1,4 @@
+aaa
+aaa
+aaa
+aaa
diff --git a/server/fs/ws.filesystem.js b/server/fs/ws.filesystem.js
new file mode 100644 (file)
index 0000000..736f115
--- /dev/null
@@ -0,0 +1,46 @@
+'use strict';
+
+var fs = require('fs');
+var path = require('path');
+
+var FileSystem = {};
+
+FileSystem.list = function (dirPath) {
+    var results, info, list;
+
+    results = [];
+
+    list = fs.readdirSync(dirPath);
+    list.forEach(function(file) {
+        var fileStat, filePath;
+
+        filePath = dirPath + file;
+
+        fileStat = fs.statSync(filePath);
+
+        if (fileStat && fileStat.isDirectory()) {
+            results = results.concat(FileSystem.list(filePath))
+        } else {
+            /**
+             * TODO
+             * to be extended .. 
+             */
+            info = {
+                name: filePath,
+                size: fileStat['size']
+            }
+            results.push(info);
+        }
+    });
+    return results;
+};
+
+FileSystem.remove = function () {
+    console.log('FileSystem.remove called');
+};
+
+FileSystem.download = function () {
+    console.log('FileSystem.download called');
+};
+
+module.exports = FileSystem;
\ No newline at end of file