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'];
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
73 var controller = this;
75 // Get OptionControlFile and bind it to $scope.options
77 //.getOptionControlFile('mrcImageNoiseAdd')
78 .getOptionControlFile(this.name)
80 .then(function(result) {
81 controller.options = result.info;
87 .then(function(result) {
88 controller.dirs = result.info;
91 this.heading = "[" + this.index + "]: dcdFilePrint";
94 // When call add button at executeController, all accordion close.
95 this.$scope.$on('close', () => {
96 controller.isOpen = false;
99 this.WebSocket.on('console', function(msg) {
101 var messages = msg.split('\n');
102 if(messages[0].substr(0,6) === 'Usage:') {
103 controller.messages = msg.split('\n');
111 angular.forEach(this.options, (option) => {
118 angular.forEach(option.arg, (arg) => {
120 if(typeof arg.input === 'object') {
121 obj.arguments.push(arg.input.name);
123 obj.arguments.push(arg.input);
128 if(obj.arguments.length > 0) {
135 workspace: this.workspace.fileId,
139 //console.log(JSON.stringify(execObj,null,'\t'));
141 .execute(JSON.stringify(execObj))
147 public removeMySelf(index:number) {
148 this.remove()(index,this.list);
151 private reloadFiles() {
152 var fileId = this.workspace.fileId;
157 var status = result.status;
158 if(status === 'success') {
159 this.files = result.info;
161 console.log(result.message);
167 var div = angular.element(this.$window.document).find("div");
170 angular.forEach(div,function(v) {
171 if(v.className === "panel-body console") {
173 } else if(v.className === "row parameters-console") {
178 // Adjust console area from CSS styling positoning information
179 var consoleHeight = parseInt(parametersTag.clientHeight.toString().replace('px','')) - 150 + 'px';
180 var consoleWidth = parseInt(parametersTag.clientWidth.toString().replace('px','')) / 3 * 2 - 150 + 'px';
181 consoleTag.style.height = consoleHeight;
182 consoleTag.style.width = consoleWidth;