OSDN Git Service

Implemeted Console service
[eos/zephyr.git] / front-end / app / scripts / directives / Command.ts
index a40614f..edfca2b 100644 (file)
@@ -36,7 +36,7 @@ namespace app.directives {
          */
         public static Factory(): ng.IDirectiveFactory {
             var directive = () => {
-            return new Command();
+                return new Command();
             };
             directive.$inject = [];
             return directive;
@@ -45,66 +45,175 @@ namespace app.directives {
 
     export class CommandController {
 
-        public static $inject = ['APIEndPoint', '$scope'];
+        public static $inject = ['APIEndPoint', '$scope', 'MyModal', 'WebSocket', '$window', '$rootScope', 'Console'];
 
-        // From parent directive.show bindToController property
+        // From parent directive bindToController property
         private index: string;
         private name: string;
         private remove: Function;
         private list: declares.CommandInfo[];
+        private workspace: declares.IFileInfo;
 
         // property of ui.bootstrap uib-accordion directive
         private isOpen: boolean;
         private heading: string;
 
         // property about Option directive
-        private files: string[];
+        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) {
-            var controller = this;
-
-            // Get OptionControlFile and bind it to $scope.options
-            this.APIEndPoint
-                .getOptionControlFile('dcdFilePrint')
-                .$promise
-                .then(function(result) {
-                    console.log(result);
-                    controller.options = result.info;
-                });
-
-            this.files = ['a.file', 'b.file', 'c.file'];
-
-            this.heading = "[" + this.index + "]: dcdFilePring";
-            this.isOpen = true;
-
-            // When call add button at executeController, all accordion close.
-            this.$scope.$on('close', () => {
-               controller.isOpen = false;
-            });
-        }
-
-        public submit() {
-            var params = {};
-            angular.forEach(this.options, (option) => {
-
-                var inputs = [];
-
-                angular.forEach(option.arg, (arg) => {
-                    if(arg.input) {
-                        inputs.push(arg.input);
-                    }
-                });
-
-                if(inputs.length > 0) {
-                    params[option.option] = inputs;
-                }
-            });
-            console.log(params);
-        }
-
-        public removeMySelf(index:number) {
-            this.remove()(index,this.list);
-        }
     } 
 }