OSDN Git Service

Modified: Upload, Command execution
[eos/zephyr.git] / front-end / app / scripts / directives / Directory.ts
1 namespace app.directives {
2
3     export class Directory implements ng.IDirective {
4
5         public restrict: string;
6         public replace: boolean;
7         public templateUrl: string;
8         private fileInfo: declares.IFileInfo;
9         public controller: string;
10         public controllerAs: string;
11         public bindToController: Object;
12
13         /**
14          * constructor
15          *
16          * @param 
17          */
18         constructor() {
19             this.restrict = 'E';
20             this.replace = true;
21             this.controller = 'directoryController';
22             this.controllerAs = 'ctrl';
23             this.bindToController = {
24                 info: '=',
25                 add: '&',
26                 list: '=',
27                 files: '='
28             };
29             this.templateUrl = 'templates/directory.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 Directory();
40             };
41             return directive;
42         }
43     }
44
45     export class DirectoryController {
46
47         public static $inject = ['APIEndPoint', '$scope'];
48
49         // From parent directive bindToController property
50         public info: declares.IDirectoryInfo;
51         public files:declares.IFileInfo[];
52         public add: Function;
53         public list: declares.IDirectoryInfo[];
54
55         constructor(private APIEndPoint: services.APIEndPoint, private $scope: ng.IScope) {
56             var controller = this;
57
58             this.APIEndPoint
59                 .getFiles(this.info.fileId)
60                 .$promise
61                 .then((result) => {
62                     if(result.status === 'success') {
63                         controller.files = result.info;
64                         angular.forEach(result.info, (file) => {
65                             if(file.fileType === '0') {
66                                 var o = file;
67                                 if(controller.info.path === '/') {
68                                     o.path = '/' + file.name;
69                                 } else {
70                                     o.path = controller.info.path + '/' + file.name;
71                                 }
72
73                                 controller.add()(o, controller.list);
74                             }
75                         });
76                     };
77                 });
78         }
79     }
80 }