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