]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
3abbcb122865e8b2bd94b19a22f4ab8444263ee5
[ceph.git] /
1 import { Component, OnInit } from '@angular/core';
2
3 import _ from 'lodash';
4
5 import { HostService } from '~/app/shared/api/host.service';
6 import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
7 import { WizardStepsService } from '~/app/shared/services/wizard-steps.service';
8 import { InventoryDevice } from '../inventory/inventory-devices/inventory-device.model';
9
10 @Component({
11   selector: 'cd-create-cluster-review',
12   templateUrl: './create-cluster-review.component.html',
13   styleUrls: ['./create-cluster-review.component.scss']
14 })
15 export class CreateClusterReviewComponent implements OnInit {
16   hosts: object[] = [];
17   hostsDetails: object;
18   hostsByLabel: object;
19   hostsCount: number;
20   labelOccurrences = {};
21   hostsCountPerLabel: object[] = [];
22   uniqueLabels: Set<string> = new Set();
23   filteredDevices: InventoryDevice[] = [];
24   capacity = 0;
25
26   constructor(private hostService: HostService, public wizardStepService: WizardStepsService) {}
27
28   ngOnInit() {
29     this.hostsDetails = {
30       columns: [
31         {
32           prop: 'hostname',
33           name: $localize`Host Name`,
34           flexGrow: 2
35         },
36         {
37           name: $localize`Labels`,
38           prop: 'labels',
39           flexGrow: 1,
40           cellTransformation: CellTemplate.badge,
41           customTemplateConfig: {
42             class: 'badge-dark'
43           }
44         }
45       ]
46     };
47
48     this.hostsByLabel = {
49       columns: [
50         {
51           prop: 'label',
52           name: $localize`Labels`,
53           flexGrow: 1,
54           cellTransformation: CellTemplate.badge,
55           customTemplateConfig: {
56             class: 'badge-dark'
57           }
58         },
59         {
60           name: $localize`Number of Hosts`,
61           prop: 'hosts_per_label',
62           flexGrow: 1
63         }
64       ]
65     };
66
67     this.hostService.list().subscribe((resp: object[]) => {
68       this.hosts = resp;
69       this.hostsCount = this.hosts.length;
70
71       _.forEach(this.hosts, (hostKey) => {
72         const labels = hostKey['labels'];
73         _.forEach(labels, (label) => {
74           this.labelOccurrences[label] = (this.labelOccurrences[label] || 0) + 1;
75           this.uniqueLabels.add(label);
76         });
77       });
78
79       this.uniqueLabels.forEach((label) => {
80         this.hostsCountPerLabel.push({
81           label: label,
82           hosts_per_label: this.labelOccurrences[label]
83         });
84       });
85
86       this.hostsByLabel['data'] = [...this.hostsCountPerLabel];
87       this.hostsDetails['data'] = [...this.hosts];
88     });
89
90     this.filteredDevices = this.wizardStepService.osdDevices;
91     this.capacity = this.wizardStepService.osdCapacity;
92   }
93 }