OSDN Git Service

[Develop and Manual Test] show help with websocket
[eos/zephyr.git] / front-end / app / scripts / services / APIEndPoint.ts
1 namespace app.services {
2     export class APIEndPoint {
3
4         private $resource: ng.resource.IResourceService;
5         private $http: ng.IHttpService;
6
7         constructor($resource: ng.resource.IResourceService, $http: ng.IHttpService) {
8             this.$resource = $resource;
9             this.$http = $http;
10         }
11
12         private resource(endPoint: string, data: any) {
13             /**
14              * setting custom action
15              */
16             var customAction: ng.resource.IActionDescriptor = {
17                 method: 'GET',
18                 isArray: false
19             };
20
21             var execute: ng.resource.IActionDescriptor = {
22                 method: 'POST',
23                 //transformRequest: data,
24                 headers: {'Content-Type':undefined, enctype:'multipart/form-data'}
25             };
26
27             return <declares.IResponseResource> this.$resource(endPoint, {}, { execute: execute});
28         }
29
30         public getOptionControlFile(command: string): ng.resource.IResource<declares.IResponse> {
31             var endPoint = '/api/v1/optionControlFile/' + command;
32             return <declares.IResponseOption>this.resource(endPoint, {}).get();
33         }
34
35         public getFiles(fileId: string): ng.resource.IResource<declares.IResponse> {
36             var endPoint = '/api/v1/workspace'; 
37
38             if(fileId) {
39                 endPoint += '/' + fileId;
40             }
41             return <declares.IResponseFileInfo>this.resource(endPoint,{}).get();
42         }
43
44         public getDirectories(): ng.resource.IResource<declares.IResponse> {
45             var endPoint = '/api/v1/all/workspace/directory';
46
47             return this.resource(endPoint,{}).get();
48         }
49
50         public getTags(): ng.resource.IResource<declares.IResponse> {
51             var endPoint = '/api/v1/tagList';
52             return this.resource(endPoint, {}).get();
53         }
54
55         public getCommands(): ng.resource.IResource<declares.IResponse> {
56             var endPoint = '/api/v1/commandList';
57             return this.resource(endPoint, {}).get();
58         }
59
60         public execute(data: any): ng.IHttpPromise<{}> {
61             var endPoint = '/api/v1/execution';
62             var fd = new FormData()
63             fd.append('data', data);
64             return this.$http.post(endPoint,
65             fd, 
66             {
67                 headers: {'Content-Type': undefined },
68                 transformRequest: angular.identity
69             });
70         }
71
72         public debug(): ng.IHttpPromise<string> {
73             var endPoint = '/api/v1/debug';
74             return this.$http.get(endPoint);
75         }
76         public help(command:string): ng.IHttpPromise<string> {
77             var endPoint = '/api/v1/help/' + command;
78             return this.$http.get(endPoint);
79         }
80
81     }
82 }