OSDN Git Service

Implemeted Console service
[eos/zephyr.git] / front-end / app / scripts / directives / Command.ts
index 150e3ad..edfca2b 100644 (file)
@@ -45,7 +45,7 @@ namespace app.directives {
 
     export class CommandController {
 
-        public static $inject = ['APIEndPoint', '$scope', 'MyModal', 'WebSocket', '$window', '$rootScope'];
+        public static $inject = ['APIEndPoint', '$scope', 'MyModal', 'WebSocket', '$window', '$rootScope', 'Console'];
 
         // From parent directive bindToController property
         private index: string;
@@ -64,12 +64,15 @@ namespace app.directives {
         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 $rootScope: ng.IRootScopeService,
+                    private Console: services.Console
                    ) {
                        var controller = this;
 
@@ -97,14 +100,6 @@ namespace app.directives {
                            controller.isOpen = false;
                        });
 
-                       /** Add EventHandler
-                        * ここではCommandディレクティブが受け取る可能性のあるイベントを登録する。
-                        * 例えば、コマンドのヘルプやEosコマンドの実行時のCLIの出力はWebSocketサービスで受け取るので、
-                        WebSocketサービスからこのCommandディレクティブに対してemitされたメッセージをこのイベントハンドラで受け取る。
-
-                        イベントネームは生成されたCommandディレクティブにユニークなidをディレクティブが生成されるたびに生成し、
-                        Commandディレクティブが削除されるたびにそのイベントハンドラを破棄することとする。
-                        */
                        function guid() {
                            function s4() {
                                return Math.floor((1 + Math.random()) * 0x10000)
@@ -115,19 +110,15 @@ namespace app.directives {
                                s4() + '-' + s4() + s4() + s4();
                        }
 
-                       var uuid = guid();
+                       this.uuid = guid();
 
+                       this.Console.addDirective(this.uuid);
+                       this.Console.showIDs();
                        /*
-                       this.WebSocket.add(uuid);
                        this.$rootScope.on(uuid, function(msg) {
                            console.log(msg);
-                           /*
-                              var messages = msg.split('\n');
-                              if(messages[0].substr(0,6) === 'Usage:') {
-                              controller.messages = msg.split('\n');
-                              }
                        });
-                            */
+                       */
                    }
 
                    public submit() {
@@ -170,7 +161,9 @@ namespace app.directives {
 
                    public removeMySelf(index:number) {
                        this.$scope.$destroy();
+                       this.Console.removeDirective(this.uuid);
                        this.remove()(index,this.list);
+                       this.Console.showIDs();
                    }
 
                    private reloadFiles() {
@@ -189,8 +182,6 @@ namespace app.directives {
                    }
 
                    public debug() {
-                       console.log(this.$rootScope);
-
                        /*   Create console area
                         * 
                         */