2024-08-08 08:42:32 +02:00
|
|
|
import 'package:oc_front/models/abstract.dart';
|
|
|
|
import 'package:json_string/json_string.dart';
|
|
|
|
|
|
|
|
class LogsResult extends SerializerDeserializer<LogsResult> {
|
|
|
|
List<Logs> result;
|
|
|
|
LogsResult({
|
|
|
|
this.result = const [],
|
|
|
|
});
|
|
|
|
|
|
|
|
String getID() {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
@override deserialize(dynamic json) {
|
|
|
|
try { json = json as Map<String, dynamic>;
|
|
|
|
} catch (e) { return LogsResult(); }
|
|
|
|
return LogsResult(
|
|
|
|
result: json.containsKey("result") ? fromListJson(json["result"], Logs()) : [],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
@override Map<String, dynamic> serialize() {
|
2024-08-22 15:46:16 +02:00
|
|
|
return {
|
|
|
|
"result": toListJson(result),
|
|
|
|
};
|
2024-08-08 08:42:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Logs extends SerializerDeserializer<Logs> {
|
|
|
|
String? level;
|
|
|
|
List<Log> logs = [];
|
|
|
|
Logs({
|
|
|
|
this.level,
|
2024-08-22 15:46:16 +02:00
|
|
|
this.logs = const [],
|
2024-08-08 08:42:32 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
String getID() {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
@override deserialize(dynamic json) {
|
|
|
|
try { json = json as Map<String, dynamic>;
|
|
|
|
} catch (e) { return Logs(); }
|
|
|
|
return Logs(
|
|
|
|
level: json.containsKey("stream") && (json["stream"] as Map<String, dynamic>).containsKey("level") ? json["stream"]["level"] : "",
|
2024-08-22 15:46:16 +02:00
|
|
|
logs: json.containsKey("values") ? fromListJson(json["values"], Log()) : [],
|
2024-08-08 08:42:32 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
@override Map<String, dynamic> serialize() {
|
2024-08-22 15:46:16 +02:00
|
|
|
return {
|
|
|
|
"level": level,
|
|
|
|
};
|
2024-08-08 08:42:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Log extends SerializerDeserializer<Log> {
|
|
|
|
DateTime? timestamp;
|
|
|
|
String? message;
|
|
|
|
|
|
|
|
String? level;
|
2024-08-22 15:46:16 +02:00
|
|
|
String? rawMessage;
|
2024-08-08 08:42:32 +02:00
|
|
|
Map<String, dynamic> map = {};
|
|
|
|
Log({
|
|
|
|
this.timestamp,
|
|
|
|
this.message,
|
2024-08-22 15:46:16 +02:00
|
|
|
this.rawMessage,
|
2024-08-08 08:42:32 +02:00
|
|
|
this.level
|
|
|
|
});
|
|
|
|
|
|
|
|
String getID() {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
String getMessage(String mess) {
|
|
|
|
var jsonString = mess;
|
|
|
|
try {
|
|
|
|
var j = JsonString(mess.replaceAll("\\", "")).decodedValue as Map<String, dynamic>;
|
|
|
|
map = j;
|
|
|
|
if (j["Status"] == "Pending") {
|
|
|
|
jsonString = "${j["Name"]} : [${j["Namespace"]}] Status: ${j["Status"]}... \nCreated at ${j["Created"].toString().replaceAllMapped(RegExp(r'\(\w+\)'), (match) { return ''; }).replaceAllMapped(RegExp(r'\+\w+'), (match) { return ''; })}";
|
|
|
|
} else {
|
2024-08-22 15:46:16 +02:00
|
|
|
jsonString = "${j["Name"]} : [${j["Namespace"]}] ${j["Status"]} ${j["Progress"]} (${j["Duration"].toString()})\nCreated at ${j["Created"].toString().replaceAllMapped(RegExp(r'\(\w+\)'), (match) { return ''; }).replaceAllMapped(RegExp(r'\+\w+'), (match) { return ''; })}; Started at ${j["Created"].toString().replaceAllMapped(RegExp(r'\(\w+\)'), (match) { return ''; }).replaceAllMapped(RegExp(r'\+\w+'), (match) { return ''; })}";
|
2024-08-08 08:42:32 +02:00
|
|
|
}
|
|
|
|
} on JsonFormatException catch (e) { /* */ }
|
|
|
|
message = jsonString;
|
|
|
|
return jsonString;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override deserialize(dynamic json) {
|
|
|
|
try { json = json as List<dynamic>;
|
|
|
|
} catch (e) { return Log(); }
|
2024-08-22 15:46:16 +02:00
|
|
|
var l = Log(
|
|
|
|
timestamp: json.isNotEmpty ? DateTime.fromMillisecondsSinceEpoch(int.parse(json[0]) ~/ 1000) : null,
|
2024-08-08 08:42:32 +02:00
|
|
|
message: json.length > 1 ? getMessage(json[1].toString()) : null,
|
2024-08-22 15:46:16 +02:00
|
|
|
rawMessage : json.length > 1 ? json[1].toString() : null,
|
2024-08-08 08:42:32 +02:00
|
|
|
);
|
2024-08-22 15:46:16 +02:00
|
|
|
l.getMessage(l.message ?? "");
|
|
|
|
return l;
|
2024-08-08 08:42:32 +02:00
|
|
|
}
|
|
|
|
@override Map<String, dynamic> serialize() { return { }; }
|
|
|
|
}
|