1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
import {Component, NgZone, OnInit} from '@angular/core';
import {ClientService} from 'src/app/api/client.service';
import {Client} from 'src/app/model/client';
import {ActivatedRoute, ParamMap, Router} from '@angular/router';
import {Observable} from 'rxjs';
import {NetbootService} from '../../api/netboot.service';
import {ToasterService} from '../../service/toaster.service';
import {RepositoryService} from '../../api/repository.service';
import {HardwareProfileService} from '../../api/hardware-profile.service';
import {Repository} from '../../model/repository';
import {HardwareProfile} from '../../model/hardware-profile';
import {OgCommonService} from '../../service/og-common.service';
import {ClientFormType} from '../../form-type/client.form-type';
import {GlobunetFormType} from '../../form-type/globunet.form-type';
@Component({
selector: 'app-client',
templateUrl: './client.component.html',
styleUrls: ['./client.component.scss']
})
export class ClientComponent implements OnInit {
public client: Client;
public netboots: any = [];
public repositories: Repository[] = [];
public hardwareProfiles: HardwareProfile[] = [];
public oglives: any[] = [];
private formType: ClientFormType;
public form;
// this tells the tabs component which Pages
// should be each tab's root Page
constructor(private router: Router,
private activatedRouter: ActivatedRoute,
private clientService: ClientService,
private netbootService: NetbootService,
private toaster: ToasterService,
private repositoryService: RepositoryService,
private hardwareProfileService: HardwareProfileService,
private ogCommonService: OgCommonService) {
this.client = new Client();
this.formType = new ClientFormType();
this.form = this.formType.getForm();
}
ngOnInit(): void {
this.loadNetboots();
this.loadOgLives();
this.loadRepositories();
this.loadHardwareProfiles();
// Comprobar por un lado si es edicion o un nuevo cliente
this.activatedRouter.paramMap.subscribe(
(data: ParamMap) => {
if (data.get('id')) {
// @ts-ignore
const id: number = data.get('id');
this.clientService.read(id).subscribe(
client => {
this.client = client;
}
);
}
this.activatedRouter.queryParams.subscribe(
query => {
this.client.organizationalUnit = query.ou;
}
);
},
error => {
console.log(error);
}
);
}
private loadOgLives() {
this.ogCommonService.loadEngineConfig().subscribe(
data => {
this.oglives = data.constants.ogliveinfo;
this.formType.getField(this.form, 'oglive').options.items = this.oglives;
}
);
}
private loadNetboots() {
this.netbootService.list().subscribe(
(result) => {
this.netboots = result;
this.formType.getField(this.form, 'netboot').options.items = this.netboots;
},
(error) => {
this.toaster.pop({type: 'error', title: 'error', body: error});
}
);
}
private loadRepositories() {
this.repositoryService.list().subscribe(
list => {
this.repositories = list;
this.formType.getField(this.form, 'repository').options.items = this.repositories;
},
error => {
this.toaster.pop({type: 'error', title: 'error', body: error});
}
);
}
private loadHardwareProfiles() {
this.hardwareProfileService.list().subscribe(
list => {
this.hardwareProfiles = list;
this.formType.getField(this.form, 'hardwareProfile').options.items = this.hardwareProfiles;
},
error => {
this.toaster.pop({type: 'error', title: 'error', body: error});
}
);
}
save() {
let request: Observable<Client>;
if (this.client.id !== 0) {
request = this.clientService.update(this.client);
} else {
request = this.clientService.create(this.client);
}
request.subscribe(
data => {
this.toaster.pop({type: 'success', title: 'success', body: 'Successfully saved'});
this.router.navigate(['/app/ous']);
},
error => {
this.toaster.pop({type: 'error', title: 'error', body: error});
}
);
}
getSizeInGB(size) {
size = size / (1024 * 1024);
return Math.round(size * 100) / 100;
}
}
|