100 lines
3.1 KiB
Dart
100 lines
3.1 KiB
Dart
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() {
|
|
return {
|
|
"result": toListJson(result),
|
|
};
|
|
}
|
|
}
|
|
|
|
class Logs extends SerializerDeserializer<Logs> {
|
|
String? level;
|
|
List<Log> logs = [];
|
|
Logs({
|
|
this.level,
|
|
this.logs = const [],
|
|
});
|
|
|
|
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"] : "",
|
|
logs: json.containsKey("values") ? fromListJson(json["values"], Log()) : [],
|
|
);
|
|
}
|
|
@override Map<String, dynamic> serialize() {
|
|
return {
|
|
"level": level,
|
|
};
|
|
}
|
|
}
|
|
|
|
class Log extends SerializerDeserializer<Log> {
|
|
DateTime? timestamp;
|
|
String? message;
|
|
|
|
String? level;
|
|
String? rawMessage;
|
|
Map<String, dynamic> map = {};
|
|
Log({
|
|
this.timestamp,
|
|
this.message,
|
|
this.rawMessage,
|
|
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 {
|
|
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 ''; })}";
|
|
}
|
|
} on JsonFormatException catch (e) { /* */ }
|
|
message = jsonString;
|
|
return jsonString;
|
|
}
|
|
|
|
@override deserialize(dynamic json) {
|
|
try { json = json as List<dynamic>;
|
|
} catch (e) { return Log(); }
|
|
var l = Log(
|
|
timestamp: json.isNotEmpty ? DateTime.fromMillisecondsSinceEpoch(int.parse(json[0]) ~/ 1000) : null,
|
|
message: json.length > 1 ? getMessage(json[1].toString()) : null,
|
|
rawMessage : json.length > 1 ? json[1].toString() : null,
|
|
);
|
|
l.getMessage(l.message ?? "");
|
|
return l;
|
|
}
|
|
@override Map<String, dynamic> serialize() { return { }; }
|
|
} |