1 namespace app.directives {
2 export class Command implements ng.IDirective {
4 public restrict: string;
5 public replace: boolean;
6 public templateUrl: string;
8 public controller: string;
9 public controllerAs: string;
10 public bindToController: Object;
21 this.controller = 'commandController';
22 this.controllerAs = 'ctrl';
23 this.bindToController = {
29 this.templateUrl = 'templates/command.html';
34 * @returns {function(): HeaderMenu}
37 public static Factory(): ng.IDirectiveFactory {
38 var directive = () => {
41 directive.$inject = [];
46 export class CommandController {
48 public static $inject = ['APIEndPoint', '$scope', 'MyModal', 'WebSocket', '$window', '$rootScope'];
50 // From parent directive bindToController property
51 private index: string;
53 private remove: Function;
54 private list: declares.CommandInfo[];
55 private workspace: declares.IFileInfo;
57 // property of ui.bootstrap uib-accordion directive
58 private isOpen: boolean;
59 private heading: string;
61 // property about Option directive
63 private options: declares.IOption[];
65 private messages: any;
67 constructor(private APIEndPoint: services.APIEndPoint,
68 private $scope: ng.IScope,
69 private MyModal: services.MyModal,
70 private WebSocket: services.WebSocket,
71 private $window: ng.IWindowService,
72 private $rootScope: ng.IRootScopeService
74 var controller = this;
76 // Get OptionControlFile and bind it to $scope.options
78 //.getOptionControlFile('mrcImageNoiseAdd')
79 .getOptionControlFile(this.name)
81 .then(function(result) {
82 controller.options = result.info;
88 .then(function(result) {
89 controller.dirs = result.info;
92 this.heading = "[" + this.index + "]: dcdFilePrint";
95 // When call add button at executeController, all accordion close.
96 this.$scope.$on('close', () => {
97 controller.isOpen = false;
101 * ここではCommandディレクティブが受け取る可能性のあるイベントを登録する。
102 * 例えば、コマンドのヘルプやEosコマンドの実行時のCLIの出力はWebSocketサービスで受け取るので、
103 WebSocketサービスからこのCommandディレクティブに対してemitされたメッセージをこのイベントハンドラで受け取る。
105 イベントネームは生成されたCommandディレクティブにユニークなidをディレクティブが生成されるたびに生成し、
106 Commandディレクティブが削除されるたびにそのイベントハンドラを破棄することとする。
110 return Math.floor((1 + Math.random()) * 0x10000)
114 return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
115 s4() + '-' + s4() + s4() + s4();
121 this.WebSocket.add(uuid);
122 this.$rootScope.on(uuid, function(msg) {
125 var messages = msg.split('\n');
126 if(messages[0].substr(0,6) === 'Usage:') {
127 controller.messages = msg.split('\n');
135 angular.forEach(this.options, (option) => {
142 angular.forEach(option.arg, (arg) => {
144 if(typeof arg.input === 'object') {
145 obj.arguments.push(arg.input.name);
147 obj.arguments.push(arg.input);
152 if(obj.arguments.length > 0) {
159 workspace: this.workspace.fileId,
163 //console.log(JSON.stringify(execObj,null,'\t'));
165 .execute(JSON.stringify(execObj))
171 public removeMySelf(index:number) {
172 this.$scope.$destroy();
173 this.remove()(index,this.list);
176 private reloadFiles() {
177 var fileId = this.workspace.fileId;
182 var status = result.status;
183 if(status === 'success') {
184 this.files = result.info;
186 console.log(result.message);
192 console.log(this.$rootScope);
194 /* Create console area
198 var div = angular.element(this.$window.document).find("div");
201 angular.forEach(div,function(v) {
202 if(v.className === "panel-body console") {
204 } else if(v.className === "row parameters-console") {
209 // Adjust console area from CSS styling positoning information
210 var consoleHeight = parseInt(parametersTag.clientHeight.toString().replace('px','')) - 150 + 'px';
211 var consoleWidth = parseInt(parametersTag.clientWidth.toString().replace('px','')) / 3 * 2 - 150 + 'px';
212 consoleTag.style.height = consoleHeight;
213 consoleTag.style.width = consoleWidth;
214 /* Create console area