157 lines
4.5 KiB
Dart
157 lines
4.5 KiB
Dart
import 'dart:convert';
|
|
|
|
class PaginatedResult<T> {
|
|
final int pageNumber;
|
|
final int pageSize;
|
|
final int totalCount;
|
|
final List<T> items;
|
|
|
|
PaginatedResult({
|
|
required this.pageNumber,
|
|
required this.pageSize,
|
|
required this.totalCount,
|
|
required this.items,
|
|
});
|
|
|
|
factory PaginatedResult.fromJson(
|
|
Map<String, dynamic> json, T Function(Map<String, dynamic>) fromJsonT) {
|
|
return PaginatedResult<T>(
|
|
pageNumber: json['pageNumber'],
|
|
pageSize: json['pageSize'],
|
|
totalCount: json['totalCount'],
|
|
items: List<T>.from(json['items'].map((item) => fromJsonT(item))),
|
|
);
|
|
}
|
|
}
|
|
|
|
class Device {
|
|
final int id;
|
|
final String? computerName;
|
|
final String? deviceType;
|
|
final String? serialNumber;
|
|
final String? location;
|
|
final String? processor;
|
|
final String? ram;
|
|
final String? osVersion;
|
|
final DateTime lastSeen;
|
|
final List<MonitorInfo> monitors;
|
|
final List<PrinterInfo> printers;
|
|
final List<StorageDeviceInfo> storageDevices;
|
|
final List<DriveHealthInfo> driveHealth;
|
|
final List<LocalAdminInfo> localAdmins;
|
|
|
|
Device({
|
|
required this.id,
|
|
this.computerName,
|
|
this.deviceType,
|
|
this.serialNumber,
|
|
this.location,
|
|
this.processor,
|
|
this.ram,
|
|
this.osVersion,
|
|
required this.lastSeen,
|
|
required this.monitors,
|
|
required this.printers,
|
|
required this.storageDevices,
|
|
required this.driveHealth,
|
|
required this.localAdmins,
|
|
});
|
|
|
|
factory Device.fromJson(Map<String, dynamic> json) {
|
|
return Device(
|
|
id: json['id'],
|
|
computerName: json['computerName'],
|
|
deviceType: json['deviceType'],
|
|
serialNumber: json['serialNumber'],
|
|
location: json['location'],
|
|
processor: json['processor'],
|
|
ram: json['ram'],
|
|
osVersion: json['osVersion'],
|
|
lastSeen: DateTime.parse(json['lastSeen']),
|
|
monitors:
|
|
_parseJsonList(json['monitors'], (j) => MonitorInfo.fromJson(j)),
|
|
printers:
|
|
_parseJsonList(json['printers'], (j) => PrinterInfo.fromJson(j)),
|
|
storageDevices: _parseJsonList(
|
|
json['storageDevices'], (j) => StorageDeviceInfo.fromJson(j)),
|
|
driveHealth: _parseJsonList(
|
|
json['driveHealth'], (j) => DriveHealthInfo.fromJson(j)),
|
|
localAdmins: _parseJsonList(
|
|
json['localAdmins'], (j) => LocalAdminInfo.fromJson(j)),
|
|
);
|
|
}
|
|
|
|
static List<T> _parseJsonList<T>(
|
|
String? jsonString, T Function(Map<String, dynamic>) fromJson) {
|
|
if (jsonString == null || jsonString.isEmpty) return [];
|
|
try {
|
|
final List<dynamic> decoded = json.decode(jsonString);
|
|
return decoded
|
|
.map((item) => fromJson(item as Map<String, dynamic>))
|
|
.toList();
|
|
} catch (e) {
|
|
return [];
|
|
}
|
|
}
|
|
}
|
|
|
|
class MonitorInfo {
|
|
final String? model;
|
|
final String? serialNumber;
|
|
MonitorInfo({this.model, this.serialNumber});
|
|
factory MonitorInfo.fromJson(Map<String, dynamic> json) =>
|
|
MonitorInfo(model: json['Model'], serialNumber: json['SerialNumber']);
|
|
}
|
|
|
|
class PrinterInfo {
|
|
final String? name;
|
|
final String? serialNumber;
|
|
final bool isNetwork;
|
|
PrinterInfo({this.name, this.serialNumber, required this.isNetwork});
|
|
factory PrinterInfo.fromJson(Map<String, dynamic> json) => PrinterInfo(
|
|
name: json['Name'],
|
|
serialNumber: json['SerialNumber'],
|
|
isNetwork: json['IsNetwork']);
|
|
}
|
|
|
|
class StorageDeviceInfo {
|
|
final String? model;
|
|
final String? serialNumber;
|
|
final String? mediaType;
|
|
final int size;
|
|
StorageDeviceInfo(
|
|
{this.model, this.serialNumber, this.mediaType, required this.size});
|
|
factory StorageDeviceInfo.fromJson(Map<String, dynamic> json) =>
|
|
StorageDeviceInfo(
|
|
model: json['Model'],
|
|
serialNumber: json['SerialNumber'],
|
|
mediaType: json['MediaType'],
|
|
size: json['Size'] ?? 0,
|
|
);
|
|
}
|
|
|
|
class DriveHealthInfo {
|
|
final String? model;
|
|
final bool? isFailing;
|
|
final double? healthPercentage;
|
|
DriveHealthInfo({this.model, this.isFailing, this.healthPercentage});
|
|
factory DriveHealthInfo.fromJson(Map<String, dynamic> json) =>
|
|
DriveHealthInfo(
|
|
model: json['Model'],
|
|
isFailing: json['IsFailing'],
|
|
healthPercentage: (json['HealthPercentage'] as num?)?.toDouble(),
|
|
);
|
|
}
|
|
|
|
class LocalAdminInfo {
|
|
final String? name;
|
|
final String? accountType;
|
|
final String? source;
|
|
LocalAdminInfo({this.name, this.accountType, this.source});
|
|
factory LocalAdminInfo.fromJson(Map<String, dynamic> json) => LocalAdminInfo(
|
|
name: json['Name'],
|
|
accountType: json['AccountType'],
|
|
source: json['Source'],
|
|
);
|
|
}
|