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', 'Console'];
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 private uuid: string; // uuid of Instance of Command directive
69 constructor(private APIEndPoint: services.APIEndPoint,
70 private $scope: ng.IScope,
71 private MyModal: services.MyModal,
72 private WebSocket: services.WebSocket,
73 private $window: ng.IWindowService,
74 private $rootScope: ng.IRootScopeService,
75 private Console: services.Console
77 var controller = this;
79 // Get OptionControlFile and bind it to $scope.options
81 //.getOptionControlFile('mrcImageNoiseAdd')
82 .getOptionControlFile(this.name)
84 .then(function(result) {
85 controller.options = result.info;
91 .then(function(result) {
92 controller.dirs = result.info;
95 this.heading = "[" + this.index + "]: dcdFilePrint";
98 // When call add button at executeController, all accordion close.
99 this.$scope.$on('close', () => {
100 controller.isOpen = false;
105 return Math.floor((1 + Math.random()) * 0x10000)
109 return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
110 s4() + '-' + s4() + s4() + s4();
115 this.Console.addDirective(this.uuid);
116 this.Console.showIDs();
118 this.$rootScope.on(uuid, function(msg) {
126 angular.forEach(this.options, (option) => {
133 angular.forEach(option.arg, (arg) => {
135 if(typeof arg.input === 'object') {
136 obj.arguments.push(arg.input.name);
138 obj.arguments.push(arg.input);
143 if(obj.arguments.length > 0) {
150 workspace: this.workspace.fileId,
154 //console.log(JSON.stringify(execObj,null,'\t'));
156 .execute(JSON.stringify(execObj))
162 public removeMySelf(index:number) {
163 this.$scope.$destroy();
164 this.Console.removeDirective(this.uuid);
165 this.remove()(index,this.list);
166 this.Console.showIDs();
169 private reloadFiles() {
170 var fileId = this.workspace.fileId;
175 var status = result.status;
176 if(status === 'success') {
177 this.files = result.info;
179 console.log(result.message);
185 /* Create console area
189 var div = angular.element(this.$window.document).find("div");
192 angular.forEach(div,function(v) {
193 if(v.className === "panel-body console") {
195 } else if(v.className === "row parameters-console") {
200 // Adjust console area from CSS styling positoning information
201 var consoleHeight = parseInt(parametersTag.clientHeight.toString().replace('px','')) - 150 + 'px';
202 var consoleWidth = parseInt(parametersTag.clientWidth.toString().replace('px','')) / 3 * 2 - 150 + 'px';
203 consoleTag.style.height = consoleHeight;
204 consoleTag.style.width = consoleWidth;
205 /* Create console area