Improvements to add new Ethernet switch ports

This commit is contained in:
grossmj 2025-02-15 18:16:21 +10:00
parent 64cc001512
commit cd483e047b
No known key found for this signature in database
GPG Key ID: 1E7DD6DBB53FF3D7

View File

@ -1,6 +1,7 @@
import { Component, Input, OnInit } from '@angular/core';
import { PortsMappingEntity } from '../../../../models/ethernetHub/ports-mapping-enity';
import { BuiltInTemplatesConfigurationService } from '../../../../services/built-in-templates-configuration.service';
import { ToasterService } from "@services/toaster.service";
@Component({
selector: 'app-ports',
@ -12,16 +13,23 @@ export class PortsComponent implements OnInit {
newPort: PortsMappingEntity = {
name: '',
port_number: 0,
vlan: 1,
type: 'access',
ethertype: '0x8100',
};
portTypes: string[] = [];
etherTypes: string[] = [];
displayedColumns: string[] = ['port_number', 'vlan', 'type', 'ethertype', 'action'];
constructor(private builtInTemplatesConfigurationService: BuiltInTemplatesConfigurationService) {}
constructor(
private builtInTemplatesConfigurationService: BuiltInTemplatesConfigurationService,
private toasterService: ToasterService,
) {}
ngOnInit() {
this.getConfiguration();
this.newPort.port_number = this.ethernetPorts.length;
}
getConfiguration() {
@ -30,13 +38,18 @@ export class PortsComponent implements OnInit {
}
onAdd() {
this.newPort.name = "Ethernet" + this.newPort.port_number;
this.ethernetPorts.push(this.newPort);
this.newPort = {
name: '',
port_number: 0,
};
const portExists = this.ethernetPorts.some(p => p.port_number === this.newPort.port_number);
if (portExists) {
this.toasterService.error(`Port number ${this.newPort.port_number} already exists.`);
return;
}
const port: PortsMappingEntity = { ...this.newPort };
port.name = "Ethernet" + port.port_number;
this.ethernetPorts.push(port);
this.ethernetPorts = [].concat(this.ethernetPorts); // this forces the refresh of the table
this.newPort.port_number = this.ethernetPorts.length;
}
delete(port: PortsMappingEntity) {