OSDN Git Service

Typescript, rearrangement project directory, develop zephyr command
[eos/zephyr.git] / front-end / app / scripts / directives / Command.ts
1 namespace app.directives {
2     export class Command implements ng.IDirective {
3
4         public restrict: string;
5         public replace: boolean;
6         public templateUrl: string;
7         public scope: boolean;
8         public controller: string;
9         public controllerAs: string;
10         public bindToController: Object;
11
12         /** 
13          * constructor
14          *
15          * @param
16          */
17         constructor() {
18             this.restrict = 'E';
19             this.replace = true; 
20             this.scope = true;
21             this.controller = 'commandController';
22             this.controllerAs = 'ctrl';
23             this.bindToController = {
24                 index: '=',
25                 name: '=',
26                 remove: '&',
27                 list: '='
28             };
29             this.templateUrl = 'templates/command.html';
30         }
31
32         /**
33          * instance生成
34          * @returns {function(): HeaderMenu}
35          * @constructor
36          */
37         public static Factory(): ng.IDirectiveFactory {
38             var directive = () => {
39             return new Command();
40             };
41             directive.$inject = [];
42             return directive;
43         }
44     }
45
46     export class CommandController {
47
48         public static $inject = ['APIEndPoint', '$scope'];
49
50         // From parent directive.show bindToController property
51         private index: string;
52         private name: string;
53         private remove: Function;
54         private list: declares.CommandInfo[];
55
56         // property of ui.bootstrap uib-accordion directive
57         private isOpen: boolean;
58         private heading: string;
59
60         // property about Option directive
61         private files: string[];
62         private options: declares.IOption[];
63
64         constructor(private APIEndPoint: services.APIEndPoint, private $scope: ng.IScope) {
65             var controller = this;
66
67             // Get OptionControlFile and bind it to $scope.options
68             this.APIEndPoint
69                 .getOptionControlFile()
70                 .$promise
71                 .then(function(result) {
72                     controller.options = result;
73                 });
74
75             this.files = ['a.file', 'b.file', 'c.file'];
76
77             this.heading = "[" + this.index + "]: dcdFilePring";
78             this.isOpen = true;
79
80             // When call add button at executeController, all accordion close.
81             this.$scope.$on('close', () => {
82                controller.isOpen = false;
83             });
84         }
85
86         public submit() {
87             var params = {};
88             angular.forEach(this.options, (option) => {
89
90                 var inputs = [];
91
92                 angular.forEach(option.arg, (arg) => {
93                     if(arg.input) {
94                         inputs.push(arg.input);
95                     }
96                 });
97
98                 if(inputs.length > 0) {
99                     params[option.option] = inputs;
100                 }
101             });
102             console.log(params);
103         }
104
105         public removeMySelf(index:number) {
106             this.remove()(index,this.list);
107         }
108     } 
109 }