Initial Commit : Network Map
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
import 'package:brick_offline_first_with_supabase/brick_offline_first_with_supabase.dart';
|
||||
import 'package:brick_supabase/brick_supabase.dart';
|
||||
|
||||
enum NetworkPortKind {
|
||||
rj45,
|
||||
sfp,
|
||||
sfpPlus,
|
||||
console,
|
||||
power,
|
||||
wireless,
|
||||
virtual,
|
||||
other;
|
||||
|
||||
String get wire {
|
||||
switch (this) {
|
||||
case NetworkPortKind.rj45:
|
||||
return 'rj45';
|
||||
case NetworkPortKind.sfp:
|
||||
return 'sfp';
|
||||
case NetworkPortKind.sfpPlus:
|
||||
return 'sfp_plus';
|
||||
case NetworkPortKind.console:
|
||||
return 'console';
|
||||
case NetworkPortKind.power:
|
||||
return 'power';
|
||||
case NetworkPortKind.wireless:
|
||||
return 'wireless';
|
||||
case NetworkPortKind.virtual:
|
||||
return 'virtual';
|
||||
case NetworkPortKind.other:
|
||||
return 'other';
|
||||
}
|
||||
}
|
||||
|
||||
String get label {
|
||||
switch (this) {
|
||||
case NetworkPortKind.rj45:
|
||||
return 'RJ45';
|
||||
case NetworkPortKind.sfp:
|
||||
return 'SFP';
|
||||
case NetworkPortKind.sfpPlus:
|
||||
return 'SFP+';
|
||||
case NetworkPortKind.console:
|
||||
return 'Console';
|
||||
case NetworkPortKind.power:
|
||||
return 'Power';
|
||||
case NetworkPortKind.wireless:
|
||||
return 'Wireless';
|
||||
case NetworkPortKind.virtual:
|
||||
return 'Virtual';
|
||||
case NetworkPortKind.other:
|
||||
return 'Other';
|
||||
}
|
||||
}
|
||||
|
||||
static NetworkPortKind? fromWire(String? value) {
|
||||
switch (value) {
|
||||
case 'rj45':
|
||||
return NetworkPortKind.rj45;
|
||||
case 'sfp':
|
||||
return NetworkPortKind.sfp;
|
||||
case 'sfp_plus':
|
||||
return NetworkPortKind.sfpPlus;
|
||||
case 'console':
|
||||
return NetworkPortKind.console;
|
||||
case 'power':
|
||||
return NetworkPortKind.power;
|
||||
case 'wireless':
|
||||
return NetworkPortKind.wireless;
|
||||
case 'virtual':
|
||||
return NetworkPortKind.virtual;
|
||||
case 'other':
|
||||
return NetworkPortKind.other;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ConnectOfflineFirstWithSupabase(
|
||||
supabaseConfig: SupabaseSerializable(tableName: 'network_ports'),
|
||||
)
|
||||
class NetworkPort extends OfflineFirstWithSupabaseModel {
|
||||
final String id;
|
||||
final String deviceId;
|
||||
final String portNumber;
|
||||
final NetworkPortKind? portKind;
|
||||
final int? speedMbps;
|
||||
final int? accessVlan;
|
||||
final bool isTrunk;
|
||||
final List<int> trunkVlans;
|
||||
final String? notes;
|
||||
|
||||
NetworkPort({
|
||||
required this.id,
|
||||
required this.deviceId,
|
||||
required this.portNumber,
|
||||
this.portKind,
|
||||
this.speedMbps,
|
||||
this.accessVlan,
|
||||
this.isTrunk = false,
|
||||
this.trunkVlans = const [],
|
||||
this.notes,
|
||||
});
|
||||
|
||||
factory NetworkPort.fromMap(Map<String, dynamic> map) {
|
||||
final rawTrunk = map['trunk_vlans'];
|
||||
final trunk = <int>[];
|
||||
if (rawTrunk is List) {
|
||||
for (final v in rawTrunk) {
|
||||
if (v is int) {
|
||||
trunk.add(v);
|
||||
} else if (v is num) {
|
||||
trunk.add(v.toInt());
|
||||
} else {
|
||||
final parsed = int.tryParse(v?.toString() ?? '');
|
||||
if (parsed != null) trunk.add(parsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NetworkPort(
|
||||
id: map['id'] as String,
|
||||
deviceId: map['device_id'] as String,
|
||||
portNumber: (map['port_number'] as String?) ?? '',
|
||||
portKind: NetworkPortKind.fromWire(map['port_kind'] as String?),
|
||||
speedMbps: map['speed_mbps'] is int
|
||||
? map['speed_mbps'] as int
|
||||
: int.tryParse(map['speed_mbps']?.toString() ?? ''),
|
||||
accessVlan: map['access_vlan'] is int
|
||||
? map['access_vlan'] as int
|
||||
: int.tryParse(map['access_vlan']?.toString() ?? ''),
|
||||
isTrunk: (map['is_trunk'] as bool?) ?? false,
|
||||
trunkVlans: trunk,
|
||||
notes: map['notes'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toInsertMap() => {
|
||||
'device_id': deviceId,
|
||||
'port_number': portNumber,
|
||||
if (portKind != null) 'port_kind': portKind!.wire,
|
||||
if (speedMbps != null) 'speed_mbps': speedMbps,
|
||||
if (accessVlan != null) 'access_vlan': accessVlan,
|
||||
'is_trunk': isTrunk,
|
||||
if (trunkVlans.isNotEmpty) 'trunk_vlans': trunkVlans,
|
||||
if (notes != null) 'notes': notes,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user