OSDN Git Service

Bind HeaderMenuController to HeaderMenu directive
[eos/zephyr.git] / front-end / app / scripts / directives / HeaderMenu.ts
index 17b153b..f01abb2 100644 (file)
@@ -5,6 +5,9 @@ namespace app.directives {
         public restrict: string;
         public replace: boolean;
         public templateUrl: string;
+        public controller: string;
+        public controllerAs: string;
+        public scope: boolean;
 
         /**
          * constructor
@@ -15,6 +18,9 @@ namespace app.directives {
             this.restrict = 'E';
             this.replace = true;
             this.templateUrl = 'templates/header-menu.html';
+            this.controller = 'HeaderMenuController';
+            this.controllerAs = 'hmc';
+            this.scope = true;
         }
 
         /**
@@ -24,9 +30,28 @@ namespace app.directives {
          */
         public static Factory(): ng.IDirectiveFactory {
             var directive = () => {
-            return new HeaderMenu();
+                return new HeaderMenu();
             };
             return directive;
         }
     }
+
+    export class HeaderMenuController {
+
+        public static $inject = ['$state'];
+
+        private isExecution: boolean;
+        private isWorkspace: boolean;
+        private isHistory: boolean;
+
+        constructor(private $state: ng.ui.IStateService) {
+            this.isExecution = this.$state.current.name === 'execution';
+            this.isWorkspace = this.$state.current.name === 'workspace';
+            this.isHistory = this.$state.current.name === 'history';
+        }
+
+        private transit(state:string) {
+            this.$state.go(state);
+        }
+    }
 }