Network map enhancements and fixes
This commit is contained in:
@@ -1,6 +1,52 @@
|
||||
import 'package:brick_offline_first_with_supabase/brick_offline_first_with_supabase.dart';
|
||||
import 'package:brick_supabase/brick_supabase.dart';
|
||||
|
||||
enum NetworkDeviceStatus {
|
||||
online,
|
||||
offline,
|
||||
warning,
|
||||
unknown;
|
||||
|
||||
String get wire {
|
||||
switch (this) {
|
||||
case NetworkDeviceStatus.online:
|
||||
return 'online';
|
||||
case NetworkDeviceStatus.offline:
|
||||
return 'offline';
|
||||
case NetworkDeviceStatus.warning:
|
||||
return 'warning';
|
||||
case NetworkDeviceStatus.unknown:
|
||||
return 'unknown';
|
||||
}
|
||||
}
|
||||
|
||||
String get label {
|
||||
switch (this) {
|
||||
case NetworkDeviceStatus.online:
|
||||
return 'Online';
|
||||
case NetworkDeviceStatus.offline:
|
||||
return 'Offline';
|
||||
case NetworkDeviceStatus.warning:
|
||||
return 'Warning';
|
||||
case NetworkDeviceStatus.unknown:
|
||||
return 'Unknown';
|
||||
}
|
||||
}
|
||||
|
||||
static NetworkDeviceStatus fromWire(String? value) {
|
||||
switch (value) {
|
||||
case 'online':
|
||||
return NetworkDeviceStatus.online;
|
||||
case 'offline':
|
||||
return NetworkDeviceStatus.offline;
|
||||
case 'warning':
|
||||
return NetworkDeviceStatus.warning;
|
||||
default:
|
||||
return NetworkDeviceStatus.unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum NetworkDeviceKind {
|
||||
router,
|
||||
switchDevice,
|
||||
@@ -173,6 +219,7 @@ class NetworkDevice extends OfflineFirstWithSupabaseModel {
|
||||
final String? mac;
|
||||
final String? locationId;
|
||||
final NetworkImportSource importSource;
|
||||
final NetworkDeviceStatus status;
|
||||
final String? notes;
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
@@ -189,6 +236,7 @@ class NetworkDevice extends OfflineFirstWithSupabaseModel {
|
||||
this.mac,
|
||||
this.locationId,
|
||||
this.importSource = NetworkImportSource.manual,
|
||||
this.status = NetworkDeviceStatus.unknown,
|
||||
this.notes,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
@@ -207,6 +255,7 @@ class NetworkDevice extends OfflineFirstWithSupabaseModel {
|
||||
mac: map['mac']?.toString(),
|
||||
locationId: map['location_id'] as String?,
|
||||
importSource: NetworkImportSource.fromWire(map['import_source'] as String?),
|
||||
status: NetworkDeviceStatus.fromWire(map['status'] as String?),
|
||||
notes: map['notes'] as String?,
|
||||
createdAt:
|
||||
DateTime.tryParse(map['created_at']?.toString() ?? '') ?? DateTime.now(),
|
||||
@@ -226,6 +275,7 @@ class NetworkDevice extends OfflineFirstWithSupabaseModel {
|
||||
if (mac != null) 'mac': mac,
|
||||
if (locationId != null) 'location_id': locationId,
|
||||
'import_source': importSource.wire,
|
||||
'status': status.wire,
|
||||
if (notes != null) 'notes': notes,
|
||||
};
|
||||
|
||||
@@ -239,6 +289,7 @@ class NetworkDevice extends OfflineFirstWithSupabaseModel {
|
||||
'mgmt_ip': mgmtIp,
|
||||
'mac': mac,
|
||||
'location_id': locationId,
|
||||
'status': status.wire,
|
||||
'notes': notes,
|
||||
};
|
||||
|
||||
@@ -252,6 +303,7 @@ class NetworkDevice extends OfflineFirstWithSupabaseModel {
|
||||
String? mgmtIp,
|
||||
String? mac,
|
||||
String? locationId,
|
||||
NetworkDeviceStatus? status,
|
||||
String? notes,
|
||||
}) {
|
||||
return NetworkDevice(
|
||||
@@ -266,6 +318,7 @@ class NetworkDevice extends OfflineFirstWithSupabaseModel {
|
||||
mac: mac ?? this.mac,
|
||||
locationId: locationId ?? this.locationId,
|
||||
importSource: importSource,
|
||||
status: status ?? this.status,
|
||||
notes: notes ?? this.notes,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt,
|
||||
|
||||
Reference in New Issue
Block a user