|
1 | 1 | export namespace hosts { |
2 | | - |
| 2 | + |
3 | 3 | export class Host { |
4 | | - id: number; |
5 | | - show: boolean; |
6 | | - ip: string; |
7 | | - hostName: string; |
8 | | - groupName: string; |
9 | | - |
10 | | - static createFrom(source: any = {}) { |
11 | | - return new Host(source); |
12 | | - } |
13 | | - |
14 | | - constructor(source: any = {}) { |
15 | | - if ('string' === typeof source) source = JSON.parse(source); |
16 | | - this.id = source["id"]; |
17 | | - this.show = source["show"]; |
18 | | - this.ip = source["ip"]; |
19 | | - this.hostName = source["hostName"]; |
20 | | - this.groupName = source["groupName"]; |
21 | | - } |
| 4 | + id: number; |
| 5 | + show: boolean; |
| 6 | + ip: string; |
| 7 | + hostName: string; |
| 8 | + groupName: string; |
| 9 | + |
| 10 | + static createFrom(source: any = {}) { |
| 11 | + return new Host(source); |
| 12 | + } |
| 13 | + |
| 14 | + constructor(source: any = {}) { |
| 15 | + if ('string' === typeof source) source = JSON.parse(source); |
| 16 | + this.id = source["id"]; |
| 17 | + this.show = source["show"]; |
| 18 | + this.ip = source["ip"]; |
| 19 | + this.hostName = source["hostName"]; |
| 20 | + this.groupName = source["groupName"]; |
| 21 | + } |
22 | 22 | } |
23 | | - |
24 | 23 | export class Group { |
25 | | - hostsText: string; |
26 | | - groupName: string; |
27 | | - showNum: number; |
28 | | - hideNum: number; |
29 | | - show: boolean; |
30 | | - list: { [key: number]: Host }; |
31 | | - |
32 | | - static createFrom(source: any = {}) { |
33 | | - return new Group(source); |
34 | | - } |
35 | | - |
36 | | - constructor(source: any = {}) { |
37 | | - if ('string' === typeof source) source = JSON.parse(source); |
38 | | - this.hostsText = source["hostsText"]; |
39 | | - this.groupName = source["groupName"]; |
40 | | - this.showNum = source["showNum"]; |
41 | | - this.hideNum = source["hideNum"]; |
42 | | - this.show = source["show"]; |
43 | | - this.list = source["list"]; |
44 | | - } |
| 24 | + hostsText: string; |
| 25 | + groupName: string; |
| 26 | + showNum: number; |
| 27 | + hideNum: number; |
| 28 | + show: boolean; |
| 29 | + list: {[key: number]: Host}; |
| 30 | + |
| 31 | + static createFrom(source: any = {}) { |
| 32 | + return new Group(source); |
| 33 | + } |
| 34 | + |
| 35 | + constructor(source: any = {}) { |
| 36 | + if ('string' === typeof source) source = JSON.parse(source); |
| 37 | + this.hostsText = source["hostsText"]; |
| 38 | + this.groupName = source["groupName"]; |
| 39 | + this.showNum = source["showNum"]; |
| 40 | + this.hideNum = source["hideNum"]; |
| 41 | + this.show = source["show"]; |
| 42 | + this.list = source["list"]; |
| 43 | + } |
45 | 44 | } |
46 | | - |
| 45 | + |
47 | 46 | export class MyHosts { |
48 | | - path: string; |
49 | | - hostsText: string; |
50 | | - inUseHostsText: string; |
51 | | - noInUseHostsText: string; |
52 | | - totalNum: number; |
53 | | - list: { [key: number]: Host }; |
54 | | - listByGroup: { [key: string]: Group }; |
55 | | - |
56 | | - static createFrom(source: any = {}) { |
57 | | - return new MyHosts(source); |
58 | | - } |
59 | | - |
60 | | - constructor(source: any = {}) { |
61 | | - if ('string' === typeof source) source = JSON.parse(source); |
62 | | - this.path = source["path"]; |
63 | | - this.hostsText = source["hostsText"]; |
64 | | - this.inUseHostsText = source["inUseHostsText"]; |
65 | | - this.noInUseHostsText = source["noInUseHostsText"]; |
66 | | - this.totalNum = source["totalNum"]; |
67 | | - this.list = source["list"]; |
68 | | - this.listByGroup = this.convertValues(source["listByGroup"], Group, true); |
69 | | - } |
70 | | - |
| 47 | + path: string; |
| 48 | + hostsText: string; |
| 49 | + inUseHostsText: string; |
| 50 | + noInUseHostsText: string; |
| 51 | + totalNum: number; |
| 52 | + list: {[key: number]: Host}; |
| 53 | + listByGroup: {[key: string]: Group}; |
| 54 | + |
| 55 | + static createFrom(source: any = {}) { |
| 56 | + return new MyHosts(source); |
| 57 | + } |
| 58 | + |
| 59 | + constructor(source: any = {}) { |
| 60 | + if ('string' === typeof source) source = JSON.parse(source); |
| 61 | + this.path = source["path"]; |
| 62 | + this.hostsText = source["hostsText"]; |
| 63 | + this.inUseHostsText = source["inUseHostsText"]; |
| 64 | + this.noInUseHostsText = source["noInUseHostsText"]; |
| 65 | + this.totalNum = source["totalNum"]; |
| 66 | + this.list = source["list"]; |
| 67 | + this.listByGroup = this.convertValues(source["listByGroup"], Group, true); |
| 68 | + } |
| 69 | + |
71 | 70 | convertValues(a: any, classs: any, asMap: boolean = false): any { |
72 | | - if (!a) { |
73 | | - return a; |
74 | | - } |
75 | | - if (a.slice && a.map) { |
76 | | - return (a as any[]).map(elem => this.convertValues(elem, classs)); |
77 | | - } else if ("object" === typeof a) { |
78 | | - if (asMap) { |
79 | | - for (const key of Object.keys(a)) { |
80 | | - a[key] = new classs(a[key]); |
81 | | - } |
82 | | - return a; |
83 | | - } |
84 | | - return new classs(a); |
85 | | - } |
86 | | - return a; |
| 71 | + if (!a) { |
| 72 | + return a; |
| 73 | + } |
| 74 | + if (a.slice && a.map) { |
| 75 | + return (a as any[]).map(elem => this.convertValues(elem, classs)); |
| 76 | + } else if ("object" === typeof a) { |
| 77 | + if (asMap) { |
| 78 | + for (const key of Object.keys(a)) { |
| 79 | + a[key] = new classs(a[key]); |
| 80 | + } |
| 81 | + return a; |
| 82 | + } |
| 83 | + return new classs(a); |
| 84 | + } |
| 85 | + return a; |
87 | 86 | } |
88 | 87 | } |
89 | 88 |
|
|
0 commit comments