oc-search porting to flutter (missing compose + workflow editor)
This commit is contained in:
43
lib/models/abstract.dart
Normal file
43
lib/models/abstract.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer' as developer;
|
||||
|
||||
abstract class SerializerDeserializer<T> {
|
||||
T deserialize(dynamic json);
|
||||
Map<String, dynamic> serialize();
|
||||
}
|
||||
|
||||
Map<String, List<T>> fromMapListJson<T extends SerializerDeserializer>(Map<String, dynamic> j, SerializerDeserializer ref) {
|
||||
var map = <String, List<T>>{};
|
||||
for (var key in j.keys) {
|
||||
if(j[key] != null) { map[key] = fromListJson(j[key], ref); }
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
Map<String, T> fromMapJson<T extends SerializerDeserializer>(Map<String, dynamic> j, SerializerDeserializer ref) {
|
||||
var map = <String, T>{};
|
||||
for (var key in j.keys) {
|
||||
if(j[key] != null) { map[key] = ref.deserialize(json.decode(json.encode(j[key]))); }
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
List<T> fromListJson<T extends SerializerDeserializer>(List<dynamic> jss, SerializerDeserializer ref) {
|
||||
var list = <T>[];
|
||||
for (var js in jss) { list.add(ref.deserialize(json.decode(json.encode(js)))); }
|
||||
return list;
|
||||
}
|
||||
|
||||
Map<String, Map<String, dynamic>> toMapJson<T extends SerializerDeserializer>(Map<String, T> json) {
|
||||
var map = <String, Map<String, dynamic>>{};
|
||||
for (var key in json.keys) {
|
||||
if(json[key] != null) { map[key] = json[key]!.serialize(); }
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>> toListJson<T extends SerializerDeserializer>(List<T> obj) {
|
||||
var list = <Map<String, dynamic>>[];
|
||||
for (var js in obj) { list.add(js.serialize()); }
|
||||
return list;
|
||||
}
|
||||
45
lib/models/response.dart
Normal file
45
lib/models/response.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:oc_front/models/abstract.dart';
|
||||
import 'package:oc_front/models/search.dart';
|
||||
import 'package:oc_front/models/workspace.dart';
|
||||
|
||||
Map<Type, SerializerDeserializer> refs = <Type, SerializerDeserializer> {
|
||||
RawData: RawData(),
|
||||
Search: Search(),
|
||||
Workspace: Workspace(),
|
||||
DataItem: DataItem(),
|
||||
DataCenterItem: DataCenterItem(),
|
||||
StorageItem: StorageItem(),
|
||||
ComputingItem: ComputingItem(),
|
||||
};
|
||||
|
||||
class APIResponse<T extends SerializerDeserializer> {
|
||||
APIResponse({
|
||||
this.data,
|
||||
this.error = "",
|
||||
this.offset = 0,
|
||||
});
|
||||
int offset = 0;
|
||||
T? data ;
|
||||
String? error = "";
|
||||
|
||||
SerializerDeserializer? getTypeString() {
|
||||
try { return refs[refs.keys.firstWhere((ref) => '$ref' == '$T')];
|
||||
} catch (e) { return null; }
|
||||
}
|
||||
|
||||
APIResponse<T> deserialize(dynamic j) {
|
||||
try {
|
||||
return APIResponse<T>(
|
||||
data: refs[T]!.deserialize(j),
|
||||
error: j.containsKey("error") && j["error"] != null ? j["error"] : "",
|
||||
);
|
||||
} catch (e) { return APIResponse<T>( data: refs[T]!.deserialize(j), ); }
|
||||
|
||||
}
|
||||
}
|
||||
class RawData extends SerializerDeserializer<RawData> {
|
||||
RawData({ this.values = const []});
|
||||
dynamic values;
|
||||
@override deserialize(dynamic json) { return RawData(values: json); }
|
||||
@override Map<String, dynamic> serialize() => { };
|
||||
}
|
||||
381
lib/models/search.dart
Normal file
381
lib/models/search.dart
Normal file
@@ -0,0 +1,381 @@
|
||||
import 'package:oc_front/models/abstract.dart';
|
||||
|
||||
const List<ComputingItem> _emptyComputing = [];
|
||||
const List<DataItem> _emptyData = [];
|
||||
const List<DataCenterItem> _emptyDataCenter = [];
|
||||
const List<StorageItem> _emptyStorage = [];
|
||||
class Search extends SerializerDeserializer<Search> {
|
||||
Search({
|
||||
this.computing = _emptyComputing,
|
||||
this.datacenter = _emptyDataCenter,
|
||||
this.data = _emptyData,
|
||||
this.storage = _emptyStorage,
|
||||
});
|
||||
List<ComputingItem> computing;
|
||||
List<DataCenterItem> datacenter;
|
||||
List<DataItem> data;
|
||||
List<StorageItem> storage;
|
||||
@override deserialize(dynamic json) {
|
||||
json = json as Map<String, dynamic>;
|
||||
return Search(
|
||||
computing: json.containsKey("computing") ? fromListJson(json["computing"], ComputingItem()) : [],
|
||||
datacenter: json.containsKey("datacenter") ? fromListJson(json["datacenter"], DataCenterItem()) : [],
|
||||
data: json.containsKey("data") ? fromListJson(json["data"], DataItem()) : [],
|
||||
storage: json.containsKey("storage") ? fromListJson(json["storage"], StorageItem()) : [],
|
||||
);
|
||||
}
|
||||
@override Map<String, dynamic> serialize() => {};
|
||||
}
|
||||
const List<String> _empty = [];
|
||||
abstract class AbstractItem {
|
||||
String? id;
|
||||
String? name;
|
||||
String? logo;
|
||||
String? type;
|
||||
String? owner;
|
||||
String? description;
|
||||
String? shortDescription;
|
||||
String topic = "";
|
||||
}
|
||||
|
||||
Type? getTopicType(String topic) {
|
||||
if (topic == "computing") { return ComputingItem; }
|
||||
else if (topic == "data") { return DataItem; }
|
||||
else if (topic == "datacenter") { return DataCenterItem; }
|
||||
else if (topic == "storage") { return StorageItem; }
|
||||
else { return null; }
|
||||
}
|
||||
|
||||
String getTopic(Type type) {
|
||||
if (type == ComputingItem) { return "computing"; }
|
||||
if (type == DataItem) { return "data"; }
|
||||
if (type == DataCenterItem) { return "datacenter"; }
|
||||
if (type == StorageItem) { return "storage"; }
|
||||
return "";
|
||||
}
|
||||
|
||||
bool isComputing(String topic) => topic == "computing";
|
||||
bool isData(String topic) => topic == "data";
|
||||
bool isDataCenter(String topic) => topic == "datacenter";
|
||||
bool isStorage(String topic) => topic == "storage";
|
||||
|
||||
class ComputingItem extends SerializerDeserializer<ComputingItem> implements AbstractItem {
|
||||
ComputingItem({
|
||||
this.id,
|
||||
this.name,
|
||||
this.logo,
|
||||
this.type,
|
||||
this.owner,
|
||||
this.price,
|
||||
this.image,
|
||||
this.command,
|
||||
this.licence,
|
||||
this.description,
|
||||
this.requirements,
|
||||
this.ports = _empty,
|
||||
this.shortDescription,
|
||||
this.dinputs = _empty,
|
||||
this.doutputs = _empty,
|
||||
this.arguments = _empty,
|
||||
this.environment = _empty,
|
||||
});
|
||||
@override String? id;
|
||||
@override String? name;
|
||||
@override String? logo;
|
||||
@override String? type;
|
||||
@override String? owner;
|
||||
@override String topic = "computing";
|
||||
double? price;
|
||||
String? image;
|
||||
String? command;
|
||||
String? licence;
|
||||
List<dynamic> ports;
|
||||
List<dynamic> dinputs;
|
||||
List<dynamic> doutputs;
|
||||
List<dynamic> arguments;
|
||||
@override String? description;
|
||||
@override String? shortDescription;
|
||||
List<dynamic> environment;
|
||||
ExecRequirements? requirements;
|
||||
|
||||
@override deserialize(dynamic json) {
|
||||
try { json = json as Map<String, dynamic>;
|
||||
} catch (e) { return ComputingItem(); }
|
||||
return ComputingItem(
|
||||
id: json.containsKey("ID") ? json["ID"] : null,
|
||||
name: json.containsKey("name") ? json["name"] : null,
|
||||
logo: json.containsKey("logo") ? json["logo"] : null,
|
||||
type: json.containsKey("type") ? json["type"] : null,
|
||||
owner: json.containsKey("owner") ? json["owner"] : null,
|
||||
price: json.containsKey("price") ? json["price"]?.toDouble() : null,
|
||||
image: json.containsKey("image") ? json["image"] : null,
|
||||
command: json.containsKey("command") ? json["command"] : null,
|
||||
licence: json.containsKey("licence") ? json["licence"] : null,
|
||||
description: json.containsKey("description") ? json["description"] : null,
|
||||
ports: json["ports"] ?? [],
|
||||
shortDescription: json.containsKey("short_description") ? json["short_description"] : null,
|
||||
dinputs: json["dinputs"] ?? [],
|
||||
doutputs: json["doutputs"] ?? [],
|
||||
arguments: json["arguments"] ?? [],
|
||||
environment: json["environment"] ?? [],
|
||||
requirements: json.containsKey("requirements") ? ExecRequirements().deserialize(json["execution_requirements"]) : null,
|
||||
);
|
||||
}
|
||||
@override Map<String, dynamic> serialize() => {};
|
||||
}
|
||||
|
||||
class ExecRequirements extends SerializerDeserializer<ExecRequirements> {
|
||||
ExecRequirements({
|
||||
this.ram,
|
||||
this.cpus,
|
||||
this.gpus,
|
||||
this.diskIO,
|
||||
this.scallingModel,
|
||||
this.parallel = false,
|
||||
});
|
||||
double? ram;
|
||||
double? cpus;
|
||||
double? gpus;
|
||||
String? diskIO;
|
||||
bool parallel = false;
|
||||
double? scallingModel;
|
||||
|
||||
@override deserialize(dynamic json) {
|
||||
try { json = json as Map<String, dynamic>;
|
||||
} catch (e) { return ExecRequirements(); }
|
||||
return ExecRequirements(
|
||||
ram: json.containsKey("ram") ? json["ram"]?.toDouble() : null,
|
||||
cpus: json.containsKey("cpus") ? json["cpus"]?.toDouble() : null,
|
||||
gpus: json.containsKey("gpus") ? json["gpus"]?.toDouble() : null,
|
||||
diskIO: json.containsKey("disk_io") ? json["disk_io"] : null,
|
||||
scallingModel: json.containsKey("scaling_model") ? json["scaling_model"]?.toDouble() : null,
|
||||
parallel: json.containsKey("parallel") ? json["parallel"] : false,
|
||||
);
|
||||
}
|
||||
@override Map<String, dynamic> serialize() => {};
|
||||
}
|
||||
|
||||
class DataItem extends SerializerDeserializer<DataItem> implements AbstractItem {
|
||||
DataItem({
|
||||
this.id,
|
||||
this.name,
|
||||
this.logo,
|
||||
this.type,
|
||||
this.dtype,
|
||||
this.owner,
|
||||
this.example,
|
||||
this.location,
|
||||
this.description,
|
||||
this.protocol = _empty,
|
||||
this.shortDescription,
|
||||
});
|
||||
@override String? id;
|
||||
@override String? name;
|
||||
@override String? logo;
|
||||
@override String? type;
|
||||
@override String topic = "data";
|
||||
String? dtype;
|
||||
String? example;
|
||||
String? location;
|
||||
@override String? description;
|
||||
List<dynamic> protocol;
|
||||
@override String? shortDescription;
|
||||
@override String? owner;
|
||||
|
||||
@override deserialize(dynamic json) {
|
||||
try { json = json as Map<String, dynamic>;
|
||||
} catch (e) { return DataItem(); }
|
||||
return DataItem(
|
||||
id: json.containsKey("ID") ? json["ID"] : null,
|
||||
name: json.containsKey("name") ? json["name"] : null,
|
||||
logo: json.containsKey("logo") ? json["logo"] : null,
|
||||
type: json.containsKey("type") ? json["type"] : null,
|
||||
owner: json.containsKey("owner") ? json["owner"] : null,
|
||||
dtype: json.containsKey("dtype") ? json["dtype"] : null,
|
||||
example: json.containsKey("example") ? json["example"] : null,
|
||||
location: json.containsKey("location") ? json["location"] : null,
|
||||
description: json.containsKey("description") ? json["description"] : null,
|
||||
protocol: json["protocol"] ?? [],
|
||||
shortDescription: json.containsKey("short_description") ? json["short_description"] : null
|
||||
);
|
||||
}
|
||||
@override Map<String, dynamic> serialize() => {};
|
||||
}
|
||||
const List<GPU> _emptyGPU = [];
|
||||
class DataCenterItem extends SerializerDeserializer<DataCenterItem> implements AbstractItem {
|
||||
DataCenterItem({
|
||||
this.id,
|
||||
this.cpu,
|
||||
this.ram,
|
||||
this.name,
|
||||
this.logo,
|
||||
this.type,
|
||||
this.owner,
|
||||
this.acronym,
|
||||
this.bookingPrice,
|
||||
this.description,
|
||||
this.hosts = _empty,
|
||||
this.gpus = _emptyGPU,
|
||||
this.shortDescription,
|
||||
});
|
||||
CPU? cpu;
|
||||
RAM? ram;
|
||||
@override String? id;
|
||||
@override String? name;
|
||||
@override String? logo;
|
||||
@override String? type;
|
||||
@override String? owner;
|
||||
@override String topic = "datacenter";
|
||||
String? acronym;
|
||||
List<GPU> gpus = [];
|
||||
@override String? description;
|
||||
List<dynamic> hosts;
|
||||
double? bookingPrice;
|
||||
@override String? shortDescription;
|
||||
|
||||
@override deserialize(dynamic json) {
|
||||
try { json = json as Map<String, dynamic>;
|
||||
} catch (e) { return DataCenterItem(); }
|
||||
return DataCenterItem(
|
||||
id: json.containsKey("ID") ? json["ID"] : null,
|
||||
ram: json.containsKey("ram") ? RAM().deserialize(json["ram"]) : null,
|
||||
cpu: json.containsKey("cpu") ? CPU().deserialize(json["cpu"]) : null,
|
||||
acronym: json.containsKey("acronym") ? json["acronym"] : null,
|
||||
name: json.containsKey("name") ? json["name"] : null,
|
||||
logo: json.containsKey("logo") ? json["logo"] : null,
|
||||
type: json.containsKey("type") ? json["type"] : null,
|
||||
owner: json.containsKey("owner") ? json["owner"] : null,
|
||||
bookingPrice: json.containsKey("bookingPrice") ? json["bookingPrice"]?.toDouble() : null,
|
||||
description: json.containsKey("description") ? json["description"] : null,
|
||||
hosts: json["hosts"] ?? [],
|
||||
shortDescription: json.containsKey("short_description") ? json["short_description"] : null,
|
||||
gpus: json.containsKey("gpus") ? fromListJson(json["gpus"] ?? [], GPU()) : [],
|
||||
);
|
||||
}
|
||||
@override Map<String, dynamic> serialize() => {};
|
||||
}
|
||||
class CPU extends SerializerDeserializer<CPU> {
|
||||
CPU({
|
||||
this.cores,
|
||||
this.platform,
|
||||
this.architecture,
|
||||
this.minimumMemory,
|
||||
this.shared = false,
|
||||
});
|
||||
double? cores;
|
||||
String? platform;
|
||||
bool shared = false;
|
||||
String? architecture;
|
||||
double? minimumMemory;
|
||||
|
||||
@override deserialize(dynamic json) {
|
||||
try { json = json as Map<String, dynamic>;
|
||||
} catch (e) { return CPU(); }
|
||||
return CPU(
|
||||
cores: json.containsKey("cores") ? json["cores"]?.toDouble() : null,
|
||||
platform: json.containsKey("platform") ? json["platform"] : null,
|
||||
architecture: json.containsKey("architecture") ? json["architecture"] : null,
|
||||
minimumMemory: json.containsKey("minimumMemory") ? json["minimumMemory"]?.toDouble() : null,
|
||||
shared: json.containsKey("shared") ? json["shared"] : false,
|
||||
);
|
||||
}
|
||||
@override Map<String, dynamic> serialize() => {};
|
||||
}
|
||||
class GPU extends SerializerDeserializer<GPU> {
|
||||
GPU({
|
||||
this.cudaCores,
|
||||
this.memory,
|
||||
this.model,
|
||||
this.tensorCores,
|
||||
});
|
||||
double? cudaCores;
|
||||
double? memory;
|
||||
String? model;
|
||||
double? tensorCores;
|
||||
|
||||
@override deserialize(dynamic json) {
|
||||
try { json = json as Map<String, dynamic>;
|
||||
} catch (e) { return GPU(); }
|
||||
return GPU(
|
||||
cudaCores: json.containsKey("cuda_cores") ? json["cuda_cores"]?.toDouble() : null,
|
||||
memory: json.containsKey("memory") ? json["memory"]?.toDouble() : null,
|
||||
model: json.containsKey("model") ? json["model"] : null,
|
||||
tensorCores: json.containsKey("tensor_cores") ? json["tensor_cores"]?.toDouble() : null,
|
||||
);
|
||||
}
|
||||
@override Map<String, dynamic> serialize() => {};
|
||||
}
|
||||
class RAM extends SerializerDeserializer<RAM> {
|
||||
RAM({
|
||||
this.ecc = false,
|
||||
this.size,
|
||||
});
|
||||
bool ecc = false;
|
||||
double? size;
|
||||
|
||||
@override deserialize(dynamic json) {
|
||||
try { json = json as Map<String, dynamic>;
|
||||
} catch (e) { return RAM(); }
|
||||
return RAM(
|
||||
ecc: json.containsKey("ecc") ? json["ecc"] : false,
|
||||
size: json.containsKey("size") ? json["size"]?.toDouble() : null,
|
||||
);
|
||||
}
|
||||
@override Map<String, dynamic> serialize() => {};
|
||||
}
|
||||
class StorageItem extends SerializerDeserializer<StorageItem> implements AbstractItem {
|
||||
StorageItem({
|
||||
this.id,
|
||||
this.url,
|
||||
this.size,
|
||||
this.name,
|
||||
this.logo,
|
||||
this.type,
|
||||
this.owner,
|
||||
this.acronym,
|
||||
this.throughput,
|
||||
this.redundancy,
|
||||
this.description,
|
||||
this.bookingPrice,
|
||||
this.shortDescription,
|
||||
this.encryption = false,
|
||||
});
|
||||
@override String? id;
|
||||
String? url;
|
||||
@override String? name;
|
||||
@override String? logo;
|
||||
@override String? type;
|
||||
@override String topic = "storage";
|
||||
double? size;
|
||||
@override String? owner;
|
||||
String? acronym;
|
||||
String? redundancy;
|
||||
String? throughput;
|
||||
@override String? description;
|
||||
double? bookingPrice;
|
||||
bool encryption = false;
|
||||
@override String? shortDescription;
|
||||
|
||||
|
||||
@override deserialize(dynamic json) {
|
||||
try { json = json as Map<String, dynamic>;
|
||||
} catch (e) { return StorageItem(); }
|
||||
return StorageItem(
|
||||
id: json.containsKey("ID") ? json["ID"] : null,
|
||||
url: json.containsKey("URL") ? json["URL"] : null,
|
||||
size: json.containsKey("size") ? json["size"]?.toDouble() : null,
|
||||
name: json.containsKey("name") ? json["name"] : null,
|
||||
logo: json.containsKey("logo") ? json["logo"] : null,
|
||||
type: json.containsKey("type") ? json["type"] : null,
|
||||
owner: json.containsKey("owner") ? json["owner"] : null,
|
||||
acronym: json.containsKey("DCacronym") ? json["DCacronym"] : null,
|
||||
bookingPrice: json.containsKey("bookingPrice") ? json["bookingPrice"]?.toDouble() : null,
|
||||
description: json.containsKey("description") ? json["description"] : null,
|
||||
throughput: json.containsKey("throughput") ? json["throughput"] : [],
|
||||
shortDescription: json.containsKey("short_description") ? json["short_description"] : null,
|
||||
redundancy: json.containsKey("redundancy") ? json["redundancy"] : [],
|
||||
encryption: json.containsKey("encryption") ? json["encryption"] : false,
|
||||
);
|
||||
}
|
||||
@override Map<String, dynamic> serialize() => {};
|
||||
}
|
||||
29
lib/models/workspace.dart
Normal file
29
lib/models/workspace.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:oc_front/models/abstract.dart';
|
||||
|
||||
class Workspace extends SerializerDeserializer<Workspace> {
|
||||
String? id;
|
||||
List<dynamic> data;
|
||||
List<dynamic> datacenter;
|
||||
List<dynamic> storage;
|
||||
List<dynamic> computing;
|
||||
|
||||
Workspace({
|
||||
this.id,
|
||||
this.computing = const [],
|
||||
this.data = const [],
|
||||
this.datacenter = const [],
|
||||
this.storage = const [],
|
||||
});
|
||||
|
||||
@override deserialize(dynamic json) {
|
||||
try { json = json as Map<String, dynamic>;
|
||||
} catch (e) { return Workspace(); }
|
||||
return Workspace(
|
||||
computing: json.containsKey("computing") ? json["computing"] : [],
|
||||
datacenter: json.containsKey("datacenter") ? json["datacenter"] : [],
|
||||
data: json.containsKey("data") ? json["data"] : [],
|
||||
storage: json.containsKey("storage") ? json["storage"] : [],
|
||||
);
|
||||
}
|
||||
@override Map<String, dynamic> serialize() => {};
|
||||
}
|
||||
Reference in New Issue
Block a user