OSDN Git Service

Implemeted Console service
[eos/zephyr.git] / front-end / app / scripts / directives / Command.ts
index c9ff0ba..edfca2b 100644 (file)
@@ -45,7 +45,7 @@ namespace app.directives {
 
     export class CommandController {
 
-        public static $inject = ['APIEndPoint', '$scope', 'MyModal', 'WebSocket'];
+        public static $inject = ['APIEndPoint', '$scope', 'MyModal', 'WebSocket', '$window', '$rootScope', 'Console'];
 
         // From parent directive bindToController property
         private index: string;
@@ -62,99 +62,158 @@ namespace app.directives {
         private files: any;
         private options: declares.IOption[];
         private dirs: any;
+        private messages: any;
+
+        private uuid: string; // uuid of Instance of Command directive
+
+        constructor(private APIEndPoint: services.APIEndPoint, 
+                    private $scope: ng.IScope, 
+                    private MyModal: services.MyModal, 
+                    private WebSocket: services.WebSocket,
+                    private $window: ng.IWindowService,
+                    private $rootScope: ng.IRootScopeService,
+                    private Console: services.Console
+                   ) {
+                       var controller = this;
+
+                       // Get OptionControlFile and bind it to $scope.options
+                       this.APIEndPoint
+                       //.getOptionControlFile('mrcImageNoiseAdd')
+                       .getOptionControlFile(this.name)
+                       .$promise
+                       .then(function(result) {
+                           controller.options = result.info;
+                       });
+
+                       this.APIEndPoint
+                       .getDirectories()
+                       .$promise
+                       .then(function(result) {
+                           controller.dirs = result.info;
+                       });
+
+                       this.heading = "[" + this.index + "]: dcdFilePrint";
+                       this.isOpen = true;
+
+                       // When call add button at executeController, all accordion close.
+                       this.$scope.$on('close', () => {
+                           controller.isOpen = false;
+                       });
+
+                       function guid() {
+                           function s4() {
+                               return Math.floor((1 + Math.random()) * 0x10000)
+                               .toString(16)
+                               .substring(1);
+                           }
+                           return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
+                               s4() + '-' + s4() + s4() + s4();
+                       }
+
+                       this.uuid = guid();
+
+                       this.Console.addDirective(this.uuid);
+                       this.Console.showIDs();
+                       /*
+                       this.$rootScope.on(uuid, function(msg) {
+                           console.log(msg);
+                       });
+                       */
+                   }
+
+                   public submit() {
+                       var opt = [];
+                       angular.forEach(this.options, (option) => {
+
+                           var obj = {
+                               name: option.option,
+                               arguments: []
+                           };
+
+                           angular.forEach(option.arg, (arg) => {
+                               if(arg.input) {
+                                   if(typeof arg.input === 'object') {
+                                       obj.arguments.push(arg.input.name);
+                                   } else {
+                                       obj.arguments.push(arg.input);
+                                   }
+                               }
+                           });
+
+                           if(obj.arguments.length > 0) {
+                               opt.push(obj);
+                           }
+                       });
+
+                       var execObj = {
+                           command: this.name,
+                           workspace: this.workspace.fileId,
+                           options: opt
+                       };
+
+                       //console.log(JSON.stringify(execObj,null,'\t'));
+                       this.APIEndPoint
+                       .execute(JSON.stringify(execObj))
+                       .then((result) => {
+                           console.log(result);
+                       })
+                   }
+
+                   public removeMySelf(index:number) {
+                       this.$scope.$destroy();
+                       this.Console.removeDirective(this.uuid);
+                       this.remove()(index,this.list);
+                       this.Console.showIDs();
+                   }
+
+                   private reloadFiles() {
+                       var fileId = this.workspace.fileId;
+                       this.APIEndPoint
+                       .getFiles(fileId)
+                       .$promise
+                       .then((result) => { 
+                           var status = result.status;
+                           if(status === 'success') {
+                               this.files = result.info;
+                           } else {
+                               console.log(result.message);
+                           }
+                       });
+                   }
+
+                   public debug() {
+                       /*   Create console area
+                        * 
+                        */
+
+                       var div = angular.element(this.$window.document).find("div");
+                       var consoleTag;
+                       var parametersTag;
+                       angular.forEach(div,function(v) {
+                           if(v.className === "panel-body console") {
+                               consoleTag = v;
+                           } else if(v.className === "row parameters-console") {
+                               parametersTag = v;
+                           }
+                       });
+
+                       // Adjust console area from CSS styling positoning information
+                       var consoleHeight = parseInt(parametersTag.clientHeight.toString().replace('px','')) - 150 + 'px';
+                       var consoleWidth = parseInt(parametersTag.clientWidth.toString().replace('px','')) / 3 * 2 - 150 + 'px';
+                       consoleTag.style.height = consoleHeight;
+                       consoleTag.style.width = consoleWidth;
+                       /*   Create console area
+                        * 
+                        */
+                   }
+
+                   public help() {
+                       this.APIEndPoint
+                       .help(this.name)
+                       .then((result) => {
+                           console.log(result);
+                       });
+                   }
 
-        constructor(private APIEndPoint: services.APIEndPoint, private $scope: ng.IScope, private MyModal: services.MyModal, private WebSocket: services.WebSocket) {
-            var controller = this;
-
-            // Get OptionControlFile and bind it to $scope.options
-            this.APIEndPoint
-            .getOptionControlFile('mrcImageNoiseAdd')
-            .$promise
-            .then(function(result) {
-                controller.options = result.info;
-            });
-
-            this.APIEndPoint
-            .getDirectories()
-            .$promise
-            .then(function(result) {
-                controller.dirs = result.info;
-            });
-
-            this.heading = "[" + this.index + "]: dcdFilePring";
-            this.isOpen = true;
-
-            // When call add button at executeController, all accordion close.
-            this.$scope.$on('close', () => {
-                controller.isOpen = false;
-            });
-
-            this.WebSocket.on('test', function(data) {
-                console.log("HOGEHOGEHOGEHOHGOEHGOH");
-            });
-        }
-
-        public submit() {
-            var opt = [];
-            angular.forEach(this.options, (option) => {
-
-                var obj = {
-                    name: option.option,
-                    arguments: []
-                };
-
-                angular.forEach(option.arg, (arg) => {
-                    if(arg.input) {
-                        if(typeof arg.input === 'object') {
-                            obj.arguments.push(arg.input.name);
-                        } else {
-                            obj.arguments.push(arg.input);
-                        }
-                    }
-                });
-
-                if(obj.arguments.length > 0) {
-                    opt.push(obj);
-                }
-            });
-
-            var execObj = {
-                command: this.name,
-                workspace: this.workspace.fileId,
-                options: opt
-            };
-
-            //console.log(JSON.stringify(execObj,null,'\t'));
-            this.APIEndPoint
-            .execute(JSON.stringify(execObj))
-            .then((result) => {
-                console.log(result);
-            })
-        }
-
-        public removeMySelf(index:number) {
-            this.remove()(index,this.list);
-        }
-
-        private reloadFiles() {
-            var fileId = this.workspace.fileId;
-            this.APIEndPoint
-            .getFiles(fileId)
-            .$promise
-            .then((result) => { 
-                var status = result.status;
-                if(status === 'success') {
-                    this.files = result.info;
-                } else {
-                    console.log(result.message);
-                }
-            });
-        }
-
-        public debug() {
-            this.MyModal.preview();
-        }
-
-        
     } 
 }