1 import { Component, OnInit } from '@angular/core';
3 import _ from 'lodash';
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';
11 selector: 'cd-create-cluster-review',
12 templateUrl: './create-cluster-review.component.html',
13 styleUrls: ['./create-cluster-review.component.scss']
15 export class CreateClusterReviewComponent implements OnInit {
20 labelOccurrences = {};
21 hostsCountPerLabel: object[] = [];
22 uniqueLabels: Set<string> = new Set();
23 filteredDevices: InventoryDevice[] = [];
26 constructor(private hostService: HostService, public wizardStepService: WizardStepsService) {}
33 name: $localize`Host Name`,
37 name: $localize`Labels`,
40 cellTransformation: CellTemplate.badge,
41 customTemplateConfig: {
52 name: $localize`Labels`,
54 cellTransformation: CellTemplate.badge,
55 customTemplateConfig: {
60 name: $localize`Number of Hosts`,
61 prop: 'hosts_per_label',
67 this.hostService.list().subscribe((resp: object[]) => {
69 this.hostsCount = this.hosts.length;
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);
79 this.uniqueLabels.forEach((label) => {
80 this.hostsCountPerLabel.push({
82 hosts_per_label: this.labelOccurrences[label]
86 this.hostsByLabel['data'] = [...this.hostsCountPerLabel];
87 this.hostsDetails['data'] = [...this.hosts];
90 this.filteredDevices = this.wizardStepService.osdDevices;
91 this.capacity = this.wizardStepService.osdCapacity;