Major Change Inputs & Co

This commit is contained in:
mr
2025-02-04 17:02:49 +01:00
parent 2c86e90b76
commit 05854c84d8
43 changed files with 2837 additions and 1809 deletions

View File

@@ -0,0 +1,222 @@
import 'package:flutter/material.dart';
import 'package:oc_front/core/services/enum_service.dart';
import 'package:oc_front/models/abstract.dart';
import 'package:oc_front/models/resources/processing.dart';
import 'package:oc_front/models/resources/resources.dart';
class ComputeItem extends AbstractItem<ComputePricing, ComputePartnership, ComputeInstance, ComputeItem> {
// special attributes
int? infrastructureEnum;
String? architecture;
ComputeItem({
this.infrastructureEnum,
this.architecture
}): super();
@override String get topic => "compute";
@override deserialize(dynamic data) {
try { data = data as Map<String, dynamic>;
} catch (e) { return ComputeItem(); }
var w = ComputeItem(
infrastructureEnum: data.containsKey("infrastructure") ? EnumService.get("infrastructure", data["infrastructure"]) : null,
architecture: data.containsKey("architecture") && data["architecture"] != null ? data["architecture"] : null,
);
w.mapFromJSON(data, ComputeInstance());
if (w.logo != null) { // get image dimensions
var image = Image.network(w.logo!);
image.image
.resolve(const ImageConfiguration())
.addListener(
ImageStreamListener(
(ImageInfo info, bool _) {
w.width = info.image.width.toDouble();
w.height = info.image.height.toDouble();
}));
}
return w;
}
@override
Map<String, dynamic> infos() {
return {
"infrastructure": EnumService.enums["infrastructure"] != null
&& EnumService.enums["infrastructure"]!["$infrastructureEnum"] != null ? EnumService.enums["infrastructure"]!["$infrastructureEnum"] : infrastructureEnum,
"architecture": architecture,
};
}
@override Map<String, dynamic> serialize() {
Map<String, dynamic> obj = infos();
obj["infrastructure"] = infrastructureEnum;
obj.addAll(toJSON());
return obj;
}
}
class ComputeInstance extends AbstractInstance<ComputePricing, ComputePartnership> {
String? securityLevel;
List<String>? powerSources = [];
double? annualEnergyConsumption;
Map<String,CPU> cpus = {};
Map<String,GPU> gpus = {};
List<ComputeNode> nodes = [];
ComputeInstance({
this.securityLevel,
this.powerSources = const [],
this.annualEnergyConsumption,
this.cpus = const {},
this.gpus = const {},
this.nodes = const [],
}): super();
@override
Map<String, dynamic> infos() {
return {
"security_level": securityLevel,
"power_sources": powerSources,
"annual_co2_emissions": annualEnergyConsumption,
"cpus": toMapJson(cpus),
"gpus": toMapJson(gpus),
"nodes": toListJson(nodes),
"inputs": toListJson(inputs),
"outputs": toListJson(outputs),
};
}
@override
ComputeInstance deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return ComputeInstance(); }
var w = ComputeInstance(
securityLevel: json.containsKey("security_level") && json["security_level"] != null ? json["security_level"] : null,
powerSources: json.containsKey("power_sources") && json["power_sources"] != null ? List<String>.from(json["power_sources"]) : [],
annualEnergyConsumption: json.containsKey("annual_co2_emissions") && json["annual_co2_emissions"] != null ? json["annual_co2_emissions"] : null,
//cpus: json.containsKey("cpus") && json["cpus"] != null ? fromMapJson(json["cpus"], CPU()) : {},
// gpus: json.containsKey("gpus") && json["gpus"] != null ? fromMapJson(json["gpus"], GPU()) : {},
//nodes: json.containsKey("nodes") && json["nodes"] != null ? fromListJson(json["nodes"], ComputeNode()) : [],
);
w.mapFromJSON(json, ComputePartnership());
return w;
}
@override
Map<String, dynamic> serialize() {
var obj = infos();
obj.addAll(toJSON());
return obj;
}
}
class ComputePartnership extends AbstractPartnerShip<ComputePricing> {
Map<String, dynamic> maxAllowedCPUsCores = {};
Map<String, dynamic> maxAllowedGPUsMemoryGB = {};
double? maxAllowedRAM;
ComputePartnership({
this.maxAllowedCPUsCores = const {},
this.maxAllowedGPUsMemoryGB = const {},
this.maxAllowedRAM,
}): super();
@override
ComputePartnership deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return ComputePartnership(); }
var w = ComputePartnership(
maxAllowedCPUsCores: json.containsKey("allowed_cpus") && json["allowed_cpus"] != null ? json["allowed_cpus"] : {},
maxAllowedGPUsMemoryGB: json.containsKey("allowed_gpus") && json["allowed_gpus"] != null ? json["allowed_gpus"] : {},
maxAllowedRAM: json.containsKey("allowed_ram") && json["allowed_ram"] != null ? double.parse("${json["allowed_ram"]}") : null,
);
w.mapFromJSON(json, ComputePricing());
return w;
}
@override
Map<String, dynamic> serialize() {
Map<String, dynamic> obj = {
"allowed_cpus": maxAllowedCPUsCores,
"allowed_gpus": maxAllowedGPUsMemoryGB,
"allowed_ram": maxAllowedRAM,
};
obj.addAll(toJSON());
return obj;
}
}
class ComputePricing extends AbstractPricing {
Map<String, dynamic> cpusPrice = {};
Map<String, dynamic> gpusPrice = {};
double? ramPrice;
ComputePricing({
this.cpusPrice = const {},
this.gpusPrice = const {},
this.ramPrice,
});
@override ComputePricing deserialize(json) {
var w = ComputePricing(
cpusPrice: json.containsKey("cpus") && json["cpus"] != null ? json["cpus"] : {},
gpusPrice: json.containsKey("gpus") && json["gpus"] != null ? json["gpus"] : {},
ramPrice: json.containsKey("ram") && json["ram"] != null ? json["ram"] : null,
);
w.mapFromJSON(json);
return w;
}
@override
Map<String, dynamic> serialize() {
var obj = {
"cpus": cpusPrice,
"gpus": gpusPrice,
"ram": ramPrice,
};
obj.addAll(toJSON());
return obj;
}
}
class ComputeNode extends SerializerDeserializer<ComputeNode> {
String? name;
int? quantity;
Map<String,dynamic> cpus = {};
Map<String,dynamic> gpus = {};
RAM? ram;
ComputeNode({
this.cpus = const {},
this.gpus = const {},
this.ram,
this.name,
this.quantity,
});
@override
ComputeNode deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return ComputeNode(); }
return ComputeNode(
name: json.containsKey("name") && json["name"] != null ? json["name"] : null,
quantity: json.containsKey("quantity") && json["quantity"] != null ? json["quantity"] : null,
cpus: json.containsKey("cpus") && json["cpus"] != null ? fromMapJson(json["cpus"], CPU()) : {},
gpus: json.containsKey("gpus") && json["gpus"] != null ? fromMapJson(json["gpus"], GPU()) : {},
ram: json.containsKey("ram") && json["ram"] != null ? RAM().deserialize(json["ram"]) : null,
);
}
@override
Map<String, dynamic> serialize() {
return {
"name": name,
"quantity": quantity,
"cpus": cpus,
"gpus": gpus,
"ram": ram!.serialize(),
};
}
}

View File

@@ -0,0 +1,166 @@
import 'package:flutter/material.dart';
import 'package:oc_front/models/abstract.dart';
import 'package:oc_front/models/resources/resources.dart';
class DataItem extends AbstractItem<DataPricing, DataPartnership, DataInstance, DataItem> {
// special attributes
String? type;
String? source;
String? quality;
bool openData = false;
bool static = false;
bool personalData = false;
bool anonymizedPersonalData = false;
double? size;
String? example;
DateTime? updatePeriod;
DataItem({
this.type,
this.source,
this.quality,
this.openData = false,
this.static = false,
this.personalData = false,
this.anonymizedPersonalData = false,
this.size,
this.example,
this.updatePeriod,
}): super();
@override String get topic => "data";
@override deserialize(dynamic data) {
try { data = data as Map<String, dynamic>;
} catch (e) { return DataItem(); }
var w = DataItem(
type: data.containsKey("type") && data["type"] != null ? data["type"] : null,
source: data.containsKey("source") && data["source"] != null ? data["source"] : null,
quality: data.containsKey("quality") && data["quality"] != null ? data["quality"] : null,
openData: data.containsKey("open_data") && data["open_data"] != null ? data["open_data"] : false,
static: data.containsKey("static") && data["static"] != null ? data["static"] : false,
personalData: data.containsKey("personal_data") && data["l"] != null ? data["personal_data"] : false,
anonymizedPersonalData: data.containsKey("anonymized_personal_data") && data["anonymized_personal_data"] != null ? data["anonymized_personal_data"] : false,
size: data.containsKey("size") && data["size"] != null ? data["size"] : null,
example: data.containsKey("example") && data["example"] != null ? data["example"] : null,
updatePeriod: data.containsKey("update_period") && data["update_period"] != null ? DateTime.parse(data["update_period"]) : null,
);
w.mapFromJSON(data, DataInstance());
if (w.logo != null) { // get image dimensions
var image = Image.network(w.logo!);
image.image
.resolve(const ImageConfiguration())
.addListener(
ImageStreamListener(
(ImageInfo info, bool _) {
w.width = info.image.width.toDouble();
w.height = info.image.height.toDouble();
}));
}
return w;
}
@override
Map<String, dynamic> infos() {
return {
"type": type,
"quality": quality,
"open_data": openData,
"static": static,
"personal_data": personalData,
"anonymized_personal_data": anonymizedPersonalData,
"size": size,
"example": example,
"update_period": updatePeriod?.toIso8601String(),
};
}
@override Map<String, dynamic> serialize() {
var obj = infos();
obj.addAll(toJSON());
return obj;
}
}
class DataInstance extends AbstractInstance<DataPricing, DataPartnership> {
String? source;
DataInstance(
{this.source}
): super();
@override
Map<String, dynamic> infos() {
return {
"inputs": toListJson(inputs),
"outputs": toListJson(outputs),
};
}
@override
DataInstance deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return DataInstance(); }
var w = DataInstance(
source: json.containsKey("source") && json["source"] != null ? json["source"] : null,
);
w.mapFromJSON(json, DataPartnership());
return w;
}
@override
Map<String, dynamic> serialize() {
var obj = toJSON();
obj["source"] = source;
obj.addAll(infos());
return obj;
}
}
class DataPartnership extends AbstractPartnerShip<DataPricing> {
double? maxDownloadableGBAllowed;
bool personalDataAllowed = false;
bool anonymizedPersonalDataAllowed = false;
DataPartnership({
this.maxDownloadableGBAllowed,
this.personalDataAllowed = false,
this.anonymizedPersonalDataAllowed = false,
}): super();
@override
DataPartnership deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return DataPartnership(); }
var w = DataPartnership(
maxDownloadableGBAllowed: json.containsKey("max_downloadable_gb_allowed") && json["max_downloadable_gb_allowed"] != null ? json["max_downloadable_gb_allowed"] : null,
personalDataAllowed: json.containsKey("personal_data_allowed") && json["personal_data_allowed"] != null ? json["personal_data_allowed"] : false,
anonymizedPersonalDataAllowed: json.containsKey("anonymized_personal_data_allowed") && json["anonymized_personal_data_allowed"] != null ? json["anonymized_personal_data_allowed"] : false,
);
w.mapFromJSON(json, DataPricing());
return w;
}
@override
Map<String, dynamic> serialize() {
Map<String, dynamic> obj = {
"max_downloadable_gb_allowed": maxDownloadableGBAllowed,
"personal_data_allowed": personalDataAllowed,
"anonymized_personal_data_allowed": anonymizedPersonalDataAllowed,
};
obj.addAll(toJSON());
return obj;
}
}
class DataPricing extends AbstractPricing {
@override DataPricing deserialize(json) {
var w = DataPricing();
w.mapFromJSON(json);
return w;
}
@override
Map<String, dynamic> serialize() {
return toJSON();
}
}

View File

@@ -0,0 +1,357 @@
import 'package:flutter/material.dart';
import 'package:oc_front/core/services/enum_service.dart';
import 'package:oc_front/models/abstract.dart';
import 'package:oc_front/models/resources/resources.dart';
class ProcessingItem extends AbstractItem<ProcessingPricing, ProcessingPartnership, ProcessingInstance, ProcessingItem> {
// special attributes
int? infrastructureEnum;
bool isService = false;
bool openSource = false;
String? license;
String? maturity;
ProcessingUsage? usage;
ProcessingItem({
this.infrastructureEnum,
this.isService = false,
this.openSource = false,
this.license,
this.maturity,
this.usage,
}): super();
@override String get topic => "processing";
@override deserialize(dynamic data) {
try { data = data as Map<String, dynamic>;
} catch (e) { return ProcessingItem(); }
var w = ProcessingItem(
infrastructureEnum: data.containsKey("infrastructure") ? EnumService.get("infrastructure", data["infrastructure"]) : null,
isService: data.containsKey("is_service") && data["is_service"] != null ? data["is_service"] : false,
openSource: data.containsKey("open_source") && data["open_source"] != null ? data["open_source"] : false,
license: data.containsKey("license") && data["license"] != null ? data["license"] : null,
maturity: data.containsKey("maturity") && data["maturity"] != null ? data["maturity"] : null,
usage: data.containsKey("usage") && data["usage"] != null ? ProcessingUsage().deserialize(data["usage"]) : null,
);
w.mapFromJSON(data, ProcessingInstance());
if (w.logo != null) { // get image dimensions
var image = Image.network(w.logo!);
image.image
.resolve(const ImageConfiguration())
.addListener(
ImageStreamListener(
(ImageInfo info, bool _) {
w.width = info.image.width.toDouble();
w.height = info.image.height.toDouble();
}));
}
return w;
}
@override
Map<String, dynamic> infos() {
return {
"infrastructure": EnumService.enums["infrastructure"] != null
&& EnumService.enums["infrastructure"]!["$infrastructureEnum"] != null ?
EnumService.enums["infrastructure"]!["$infrastructureEnum"] : infrastructureEnum,
"is_service": isService,
"open_source": openSource,
"license": license,
"maturity": maturity,
};
}
@override Map<String, dynamic> serialize() {
var obj = infos();
obj["infrastructure"] = infrastructureEnum;
obj["usage"] = usage?.serialize();
obj.addAll(toJSON());
return obj;
}
}
class ProcessingAccess extends SerializerDeserializer<ProcessingAccess> {
Containered? container;
ProcessingAccess({
this.container,
});
@override ProcessingAccess deserialize(dynamic json) {
try {
json = json as Map<String, dynamic>;
} catch (e) {
return ProcessingAccess();
}
return ProcessingAccess(
container: json.containsKey("container") && json["container"] != null ? Containered().deserialize(json["container"]) : null,
);
}
@override Map<String, dynamic> serialize() {
return {
"container": container?.serialize(),
};
}
}
class ProcessingInstance extends AbstractInstance<ProcessingPricing, ProcessingPartnership> {
ProcessingAccess? access;
ProcessingInstance(
{this.access}
): super();
@override
ProcessingInstance deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return ProcessingInstance(); }
var w = ProcessingInstance();
w.access = json.containsKey("access") && json["access"] != null ? ProcessingAccess().deserialize(json['access']) : null;
w.mapFromJSON(json, ProcessingPartnership());
return w;
}
@override
Map<String, dynamic> serialize() {
var obj = toJSON();
obj["access"] = access?.serialize();
return obj;
}
@override
Map<String, dynamic> infos() {
return {
"inputs": toListJson(inputs),
"outputs": toListJson(outputs),
};
}
}
class ProcessingPartnership extends AbstractPartnerShip<ProcessingPricing> {
ProcessingPartnership(): super();
@override
ProcessingPartnership deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return ProcessingPartnership(); }
var w = ProcessingPartnership();
w.mapFromJSON(json, ProcessingPricing());
return w;
}
@override
Map<String, dynamic> serialize() {
return toJSON();
}
}
class ProcessingPricing extends AbstractPricing {
@override ProcessingPricing deserialize(json) {
var w = ProcessingPricing();
w.mapFromJSON(json);
return w;
}
@override
Map<String, dynamic> serialize() {
return toJSON();
}
}
class ProcessingUsage extends SerializerDeserializer<ProcessingUsage> {
Map<String,CPU> cpus = {};
Map<String,GPU> gpus = {};
RAM? ram;
double? storageSize;
String? hypothesis;
String? scalingModel;
ProcessingUsage({
this.cpus = const {},
this.gpus = const {},
this.ram,
this.storageSize,
this.hypothesis,
this.scalingModel,
});
@override
ProcessingUsage deserialize(json) {
return ProcessingUsage(
cpus: json.containsKey("cpus") && json["cpus"] != null ? fromMapJson(json["cpus"], CPU()) : {},
gpus: json.containsKey("gpus") && json["gpus"] != null ? fromMapJson(json["gpus"], GPU()) : {},
ram: json.containsKey("ram") && json["ram"] != null ? RAM().deserialize(json["ram"]) : null,
storageSize: json.containsKey("storage_size") && json["storage_size"] != null ? json["storage_size"]?.toDouble() : null,
hypothesis: json.containsKey("hypothesis") && json["hypothesis"] != null ? json["hypothesis"] : null,
scalingModel: json.containsKey("scaling_model") && json["scaling_model"] != null ? json["scaling_model"] : null,
);
}
@override
Map<String, dynamic> serialize() {
return {
"cpus": toMapJson(cpus),
"gpus": toMapJson(gpus),
"ram": ram?.serialize(),
"storage_size": storageSize,
"hypothesis": hypothesis,
"scaling_model": scalingModel,
};
}
}
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"] != null ? json["cores"]?.toDouble() : null,
platform: json.containsKey("platform") && json["platform"] != null ? json["platform"] : null,
architecture: json.containsKey("architecture") && json["architecture"] != null ? json["architecture"] : null,
minimumMemory: json.containsKey("minimumMemory") && json["minimumMemory"] != null ? json["minimumMemory"]?.toDouble() : null,
shared: json.containsKey("shared") && json["shared"] != null ? json["shared"] : false,
);
}
@override Map<String, dynamic> serialize() => {
"cores": cores,
"platform": platform,
"architecture": architecture,
"minimumMemory": minimumMemory,
"shared": shared,
};
}
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"] != null ? json["cuda_cores"]?.toDouble() : null,
memory: json.containsKey("memory") && json["memory"] != null ? json["memory"]?.toDouble() : null,
model: json.containsKey("model") && json["model"] != null ? json["model"] : null,
tensorCores: json.containsKey("tensor_cores") && json["tensor_cores"] != null ? json["tensor_cores"]?.toDouble() : null,
);
}
@override Map<String, dynamic> serialize() => {
"cuda_cores": cudaCores,
"memory": memory,
"model": model,
"tensor_cores": tensorCores,
};
}
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"] != null ? json["ecc"] : false,
size: json.containsKey("size") && json["size"] != null ? json["size"]?.toDouble() : null,
);
}
@override Map<String, dynamic> serialize() => {
"ecc": ecc,
"size": size,
};
}
class Expose extends SerializerDeserializer<Expose> {
Expose({
this.PAT,
this.port,
this.path,
});
int? port;
int? PAT;
String? path;
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Expose(); }
return Expose(
port: json.containsKey("port") && json["port"] != null ? json["port"] : null,
PAT: json.containsKey("PAT") && json["PAT"] != null ? json["PAT"] : null,
path: json.containsKey("reverse") && json["reverse"] != null ? json["reverse"] : null,
);
}
@override Map<String, dynamic> serialize() => {
"port": port,
"PAT": PAT,
"reverse": path,
};
}
class Containered extends SerializerDeserializer<Containered> {
Containered({
this.image,
this.args,
this.command,
this.env,
this.volumes,
this.exposes = const [],
});
String? args;
String? image;
String? command;
Map<String, dynamic>? env;
Map<String, dynamic>? volumes;
List<Expose> exposes = [];
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Containered(); }
return Containered(
args: json.containsKey("args") && json["args"] != null ? json["args"] : null,
image: json.containsKey("image") && json["image"] != null ? json["image"] : null,
command: json.containsKey("command") && json["command"] != null ? json["command"] : null,
env: json.containsKey("env") && json["env"] != null ? json["env"] : null,
volumes: json.containsKey("volumes") && json["volumes"] != null ? json["volumes"] : null,
exposes: json.containsKey("exposes") && json["exposes"] != null ? fromListJson(json["exposes"], Expose()) : [],
);
}
@override Map<String, dynamic> serialize() {
var w = {
"args": args,
"image": image,
"command": command,
"env": env,
"volumes": volumes,
"exposes": toListJson(exposes),
};
return w;
}
}

View File

@@ -0,0 +1,497 @@
import 'package:flutter/material.dart';
import 'package:flutter_flow_chart/flutter_flow_chart.dart';
import 'package:oc_front/main.dart';
import 'package:oc_front/models/abstract.dart';
import 'package:oc_front/models/resources/compute.dart';
import 'package:oc_front/models/resources/data.dart';
import 'package:oc_front/models/resources/processing.dart';
import 'package:oc_front/models/resources/storage.dart';
import 'package:oc_front/models/resources/workflow.dart';
class Resource implements SerializerDeserializer<Resource> {
List<DataItem> datas = [];
List<ProcessingItem> processings = [];
List<StorageItem> storages = [];
List<ComputeItem> computes = [];
List<WorkflowItem> workflows = [];
Resource({
this.datas = const [],
this.processings = const [],
this.storages = const [],
this.computes = const [],
this.workflows = const [],
});
@override Resource deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Resource(); }
return Resource(
computes: json.containsKey("compute_resource") ? fromListJson(json["compute_resource"], ComputeItem()) : [],
datas: json.containsKey("data_resource") ? fromListJson(json["data_resource"], DataItem()) : [],
processings: json.containsKey("processing_resource") ? fromListJson(json["processing_resource"], ProcessingItem()) : [],
storages: json.containsKey("storage_resource") ? fromListJson(json["storage_resource"], StorageItem()) : [],
workflows: json.containsKey("workflow_resource") ? fromListJson(json["workflow_resource"], WorkflowItem()) : [],
);
}
@override Map<String, dynamic> serialize() {
return {
"compute_resource": toListJson<ComputeItem>(computes),
"data_resource": toListJson<DataItem>(datas),
"processing_resource": toListJson<ProcessingItem>(processings),
"storage_resource": toListJson<StorageItem>(storages),
"workflow_resource": toListJson<WorkflowItem>(workflows),
};
}
}
class Owner extends SerializerDeserializer<Owner> {
String? name;
String? logo;
Owner({
this.name,
this.logo,
});
@override Owner deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Owner(); }
return Owner(
name: json.containsKey("name") ? json["name"] : null,
logo: json.containsKey("logo") ? json["logo"] : null,
);
}
@override Map<String, dynamic> serialize() {
return {
"name": name,
"logo": logo,
};
}
}
abstract class Infos {
Map<String, dynamic> infos();
}
class Artifact extends SerializerDeserializer<Artifact> {
String? attrPath;
String? attrFrom;
bool readOnly = true;
Artifact({
this.attrPath,
this.attrFrom,
this.readOnly = true,
});
@override Artifact deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Artifact(); }
return Artifact(
attrPath: json.containsKey("attr_path") ? json["attr_path"] : null,
attrFrom: json.containsKey("attr_from") ? json["attr_from"] : null,
readOnly: json.containsKey("readonly") ? json["readonly"] : true,
);
}
@override Map<String, dynamic> serialize() {
return {
"attr_path": attrPath,
"attr_from": attrFrom,
"readonly": readOnly,
};
}
}
class Param extends SerializerDeserializer<Param> {
String? name;
String? attr;
dynamic value;
String? origin;
bool optionnal = false;
bool readOnly = true;
Param({
this.name,
this.attr,
this.value,
this.origin,
this.optionnal = false,
this.readOnly = true,
});
@override Param deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Param(); }
return Param(
name: json.containsKey("name") ? json["name"] : null,
attr: json.containsKey("attr") ? json["attr"] : null,
value: json.containsKey("value") ? json["value"] : null,
origin: json.containsKey("origin") ? json["origin"] : null,
optionnal: json.containsKey("optionnal") ? json["optionnal"] : false,
readOnly: json.containsKey("readonly") ? json["readonly"] : false,
);
}
@override Map<String, dynamic> serialize() {
return {
"name": name,
"attr": attr,
"value": value,
"origin": origin,
"optionnal": optionnal,
"readonly": readOnly,
};
}
}
abstract class AbstractItem<X extends AbstractPricing, Y extends AbstractPartnerShip<X>, S extends AbstractInstance<X,Y>, T extends FlowData> extends FlowData implements SerializerDeserializer<T>, Infos {
String? id;
String? name;
String? logo;
String? type;
String? creatorID;
String? updaterID;
DateTime? createdAt;
DateTime? updatedAt;
List<Owner> owners;
String? description;
String? restrictions;
String? shortDescription;
int selectedInstance = -1;
List<AbstractInstance<X,Y>> instances = [];
String get topic => "";
AbstractItem({
this.id,
this.type,
this.name,
this.logo,
this.creatorID,
this.updaterID,
this.createdAt,
this.updatedAt,
this.description,
this.shortDescription,
this.owners = const [],
this.selectedInstance = -1,
});
void addEnv(List<dynamic> infos) {
var inst = getSelectedInstance();
if (inst == null) { return; }
inst.env = [];
for (var info in infos) {
inst.env.add(Param(name: info["name"], attr: info["attr"], value: info["value"],
origin: info["origin"], optionnal: info["optionnal"], readOnly: info["readonly"]));
}
}
AbstractInstance<X,Y>? getSelectedInstance() {
if (selectedInstance == -1) { return instances.isEmpty ? null : instances[0]; }
return instances[selectedInstance];
}
@override String getID() {
return id ?? "";
}
@override String getType() {
return type ?? "";
}
@override String getName() {
return name ?? "";
}
@override
Map<String, dynamic> infos();
double? width;
double? height;
@override
double? getWidth() {
return width;
}
@override
double? getHeight() {
return height;
}
Map<String, dynamic> setVariable(String key, dynamic value, Map<String, dynamic> map) {
map[key] = value;
return map;
}
dynamic getVariable(String key, Map<String, dynamic> map) {
return map[key];
}
Map<String, dynamic> toJSON() {
return {
"id": id,
"type": type ?? topic,
"name": name,
"logo": logo,
"owners": toListJson(owners),
"creator_id": creatorID,
"updater_id": updaterID,
"creation_date": createdAt?.toIso8601String(),
"update_date": updatedAt?.toIso8601String(),
"description": description,
"short_description": shortDescription,
"selected_instance": selectedInstance,
"instances": instances.map((e) => e.serialize()).toList(),
};
}
void mapFromJSON(dynamic json, S ex) {
try { json = json as Map<String, dynamic>;
} catch (e) { return; }
this.id = json.containsKey("id") ? json["id"] : null;
this.type = json.containsKey("type") ? json["type"] : topic;
this.name = json.containsKey("name") ? json["name"] : null;
this.logo = json.containsKey("logo") ? json["logo"] : null;
this.creatorID = json.containsKey("creator_id") ? json["creator_id"] : null;
this.updaterID = json.containsKey("updater_id") ? json["updater_id"] : null;
this.description = json.containsKey("description") ? json["description"] : null;
this.owners = json.containsKey("owners") ? fromListJson(json["owners"], Owner()) : [];
this.instances = json.containsKey("instances") ? fromListJson(json["instances"], ex) : [];
this.updatedAt = json.containsKey("update_date") ? DateTime.parse(json["update_date"]) : null;
this.selectedInstance = json.containsKey("selected_instance") ? json["selected_instance"] : -1;
this.shortDescription = json.containsKey("short_description") ? json["short_description"] : null;
this.createdAt = json.containsKey("creation_date") ? DateTime.parse(json["creation_date"]) : null;
}
}
class Location extends SerializerDeserializer<Location> {
double? latitude;
double? longitude;
Location({
this.latitude,
this.longitude,
});
@override
Location deserialize(json) {
return Location(
latitude: json.containsKey("latitude") ? json["latitude"] : null,
longitude: json.containsKey("longitude") ? json["longitude"] : null,
);
}
@override
Map<String, dynamic> serialize() {
return {
"latitude": latitude,
"longitude": longitude,
};
}
}
abstract class AbstractInstance<X extends AbstractPricing, S extends AbstractPartnerShip<X>> extends SerializerDeserializer<AbstractInstance<X,S>> implements Infos {
String? id;
String? name;
int? countryCode;
Location? location;
List<S> partnerships = [];
List<Param> env = [];
List<Param> inputs = [];
List<Param> outputs = [];
bool isEnv(String key) {
for (var e in env) {
if (e.name?.contains(key) ?? false || key.contains(e.name ?? "none")) { return true; }
}
return false;
}
bool isEnvAttr(String attr, String origin, bool isOrigin) {
for (var e in env) {
if (e.attr == attr && ((isOrigin && e.origin != null) || (!isOrigin && e.origin == origin))) { return true; }
}
return false;
}
@override
Map<String, dynamic> infos();
void mapFromJSON(dynamic json, S ex) {
try { json = json as Map<String, dynamic>;
} catch (e) { return; }
this.countryCode = json.containsKey("country_code") ? json["country_code"] : null;
this.id = json.containsKey("id") ? json["id"] : null;
this.name = json.containsKey("name") ? json["name"] : null;
this.env = json.containsKey("env") ? fromListJson(json["env"], Param()) : [];
this.inputs = json.containsKey("inputs") ? fromListJson(json["inputs"], Param()) : [];
this.outputs = json.containsKey("outputs") ? fromListJson(json["outputs"], Param()) : [];
this.location = json.containsKey("location") ? Location().deserialize(json["location"]) : null;
this.partnerships = json.containsKey("partnerships") ? fromListJson(json["partnerships"], ex) : [];
}
Map<String, dynamic> toJSON() {
return {
"country_code": countryCode,
"id": id,
"name": name,
"location": location?.serialize(),
"env": toListJson(env),
"inputs": toListJson(inputs),
"outputs": toListJson(outputs),
"partnerships": partnerships.map((e) => e.serialize()).toList(),
};
}
}
abstract class AbstractPartnerShip<S extends AbstractPricing> extends SerializerDeserializer<AbstractPartnerShip<S>> {
String? namespace;
List<AbstractPricing> pricings = [];
void mapFromJSON(dynamic json, S ex) {
try { json = json as Map<String, dynamic>;
} catch (e) { return; }
this.namespace = json.containsKey("namespace") ? json["namespace"] : null;
this.pricings = json.containsKey("pricings") ? fromListJson(json["pricings"], ex) : [];
}
Map<String, dynamic> toJSON() {
return {
"namespace": namespace,
"pricings": pricings,
};
}
}
abstract class AbstractPricing extends SerializerDeserializer<AbstractPricing> {
PricingStrategy? pricing;
int? refundTypeEnum;
int? refundRatio;
List<dynamic> additionnalRefundTypeEnum = [];
int? privilegeStrategyEnum;
int? garantedDelaySecond;
bool exceeding = false;
int? exceedingRatio;
void mapFromJSON(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return; }
pricing = json.containsKey("pricing") ? PricingStrategy().deserialize(json["pricing"]) : null;
refundTypeEnum = json.containsKey("refund_type") ? json["refund_type"] : null;
refundRatio = json.containsKey("refund_ratio") ? json["refund_ratio"] : null;
additionnalRefundTypeEnum = json.containsKey("additionnal_refund_type") ? json["additionnal_refund_type"] : [];
privilegeStrategyEnum = json.containsKey("privilege_strategy") ? json["privilege_strategy"] : null;
garantedDelaySecond = json.containsKey("garanted_delay") ? json["garanted_delay"] : null;
exceeding = json.containsKey("exceeding") ? json["exceeding"] : false;
exceedingRatio = json.containsKey("exceeding_ratio") ? json["exceeding_ratio"] : null;
}
Map<String, dynamic> toJSON() {
return {
"pricing": pricing?.serialize(),
"refund_type": refundTypeEnum,
"refund_ratio": refundRatio,
"additionnal_refund_type": additionnalRefundTypeEnum,
"privilege_strategy": privilegeStrategyEnum,
"garanted_delay": garantedDelaySecond,
"exceeding": exceeding,
"exceeding_ratio": exceedingRatio,
};
}
}
class PricingStrategy extends SerializerDeserializer<PricingStrategy> {
double? price;
String? currency;
int? buyingStrategyEnum;
int? timeStrategyEnum;
int? overrideStrategyEnum;
PricingStrategy({
this.price,
this.currency,
this.buyingStrategyEnum,
this.timeStrategyEnum,
this.overrideStrategyEnum,
});
@override
PricingStrategy deserialize(dynamic json) {
return PricingStrategy(
price: json.containsKey("price") && json["price"] != null ? json["price"] : null,
currency: json.containsKey("currency") && json["currency"] != null ? json["currency"] : null,
buyingStrategyEnum: json.containsKey("buying_strategy") ? json["buying_strategy"] : null,
timeStrategyEnum: json.containsKey("time_strategy") ? json["time_strategy"] : null,
overrideStrategyEnum: json.containsKey("override_strategy") ? json["override_strategy"] : null,
);
}
@override
Map<String, dynamic> serialize() {
return {
"price": price,
"currency": currency,
"buying_strategy": buyingStrategyEnum,
"time_strategy": timeStrategyEnum,
"override_strategy": overrideStrategyEnum,
};
}
}
class Model extends SerializerDeserializer<Model> {
dynamic value;
String? type;
bool readonly = false;
Model({
this.value,
this.type,
this.readonly = false,
});
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Model(); }
return Model(
value: json.containsKey("value") ? json["value"] : null,
type: json.containsKey("type") ? json["type"] : null,
readonly: json.containsKey("readonly") ? json["readonly"] : false,
);
}
@override Map<String, dynamic> serialize() => {
"value": value,
"type": type,
"readonly": readonly,
};
}
Type? getTopicType(String topic) {
if (topic == "processing") { return ProcessingItem; }
else if (topic == "data") { return DataItem; }
else if (topic == "compute") { return ComputeItem; }
else if (topic == "storage") { return StorageItem; }
else if (topic == "workflow") { return WorkflowItem; }
else { return null; }
}
String getTopic(Type type) {
if (type == AbstractItem) { return "resource"; }
if (type == ProcessingItem) { return "processing"; }
if (type == DataItem) { return "data"; }
if (type == ComputeItem) { return "compute"; }
if (type == StorageItem) { return "storage"; }
if (type == WorkflowItem) { return "workflow"; }
return "";
}
bool isComputing(String topic) => topic == "processing";
bool isData(String topic) => topic == "data";
bool isCompute(String topic) => topic == "compute";
bool isStorage(String topic) => topic == "storage";
bool isWorkflow(String topic) => topic == "workflow";
Color getColor(String topic) => isData(topic) ? Colors.blue : isComputing(topic) ? Colors.green :
isCompute(topic) ? Colors.orange : isStorage(topic) ? redColor : Colors.grey;

View File

@@ -0,0 +1,166 @@
import 'package:flutter/material.dart';
import 'package:oc_front/core/services/enum_service.dart';
import 'package:oc_front/models/abstract.dart';
import 'package:oc_front/models/resources/resources.dart';
class StorageItem extends AbstractItem<StoragePricing, StoragePartnership, StorageInstance, StorageItem> {
StorageItem({
this.acronym,
this.typeEnum,
}): super();
@override String get topic => "storage";
// special attributes
String? acronym;
int? typeEnum;
@override deserialize(dynamic data) {
try { data = data as Map<String, dynamic>;
} catch (e) { return StorageItem(); }
var w = StorageItem(
acronym: data.containsKey("acronym") && data["acronym"] != null ? data["acronym"] : null,
typeEnum: data.containsKey("storage_type") && data["storage_type"] != null ? EnumService.get("storage/type", data["storage_type"]) : null,
);
w.mapFromJSON(data, StorageInstance());
if (w.logo != null) { // get image dimensions
var image = Image.network(w.logo!);
image.image
.resolve(const ImageConfiguration())
.addListener(
ImageStreamListener(
(ImageInfo info, bool _) {
w.width = info.image.width.toDouble();
w.height = info.image.height.toDouble();
}));
}
return w;
}
@override
Map<String, dynamic> infos() {
return {
"acronym": acronym,
"storage_type": EnumService.enums["storage/type"] != null
&& EnumService.enums["storage/type"]!["$typeEnum"] != null ?
EnumService.enums["storage/type"]!["$typeEnum"] : typeEnum,
};
}
@override Map<String, dynamic> serialize() {
var obj = infos();
obj.addAll(toJSON());
return obj;
}
}
class StorageInstance extends AbstractInstance<StoragePricing, StoragePartnership> {
String? source;
bool local = false;
String? securityLevel;
int? storageSizeEnum;
int? size;
bool encryption = false;
String? redundancy;
String? throughput;
StorageInstance({
this.source,
this.local = false,
this.securityLevel,
this.storageSizeEnum,
this.size,
this.encryption = false,
this.redundancy,
this.throughput,
}): super();
@override
StorageInstance deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return StorageInstance(); }
var w = StorageInstance(
source: json.containsKey("source") && json["source"] != null ? json["source"] : null,
local: json.containsKey("local") && json["local"] != null ? json["local"] : false,
securityLevel: json.containsKey("security_level") && json["security_level"] != null ? json["security_level"] : null,
storageSizeEnum: json.containsKey("size_type") ? EnumService.get("storage/size", json["size_type"]) : null,
size: json.containsKey("size") && json["size"] != null ? json["size"] : null,
encryption: json.containsKey("encryption") && json["encryption"] != null ? json["encryption"] : false,
redundancy: json.containsKey("redundancy") && json["redundancy"] != null ? json["redundancy"] : null,
throughput: json.containsKey("throughput") && json["throughput"] != null ? json["throughput"] : null,
);
w.mapFromJSON(json, StoragePartnership());
return w;
}
@override
Map<String, dynamic> infos() {
return {
"local": local,
"security_level": securityLevel,
"size_type": EnumService.enums["storage/size"] != null
&& EnumService.enums["storage/size"]!["$storageSizeEnum"] != null ?
EnumService.enums["storage/size"]!["$storageSizeEnum"] : storageSizeEnum,
"size": size,
"encryption": encryption,
"redundancy": redundancy,
"throughput": throughput,
"inputs": toListJson(inputs),
"outputs": toListJson(outputs),
};
}
@override
Map<String, dynamic> serialize() {
var obj = infos();
obj["source"] = source;
obj["size_type"] = storageSizeEnum;
obj.addAll(toJSON());
return obj;
}
}
class StoragePartnership extends AbstractPartnerShip<StoragePricing> {
double? maxSizeGBAllowed;
bool onlyEncryptedAllowed = false;
StoragePartnership({
this.maxSizeGBAllowed,
this.onlyEncryptedAllowed = false,
}): super();
@override
StoragePartnership deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return StoragePartnership(); }
var w = StoragePartnership(
maxSizeGBAllowed: json.containsKey("allowed_gb") && json["allowed_gb"] != null ? json["allowed_gb"] : null,
onlyEncryptedAllowed: json.containsKey("personal_data_allowed") && json["personal_data_allowed"] != null ? json["personal_data_allowed"] : false,
);
w.mapFromJSON(json, StoragePricing());
return w;
}
@override
Map<String, dynamic> serialize() {
Map<String, dynamic> obj = {
"allowed_gb": maxSizeGBAllowed,
"personal_data_allowed": onlyEncryptedAllowed,
};
obj.addAll(toJSON());
return obj;
}
}
class StoragePricing extends AbstractPricing {
@override StoragePricing deserialize(json) {
var w = StoragePricing();
w.mapFromJSON(json);
return w;
}
@override
Map<String, dynamic> serialize() {
return toJSON();
}
}

View File

@@ -0,0 +1,101 @@
import 'package:flutter/material.dart';
import 'package:oc_front/models/resources/resources.dart';
class WorkflowItem extends AbstractItem<WorkflowPricing, WorkflowPartnership, WorkflowInstance, WorkflowItem> {
// special attributes
String? workflowID;
WorkflowItem({
this.workflowID,
}): super();
@override String get topic => "workflow";
@override deserialize(dynamic data) {
try { data = data as Map<String, dynamic>;
} catch (e) { return WorkflowItem(); }
var w = WorkflowItem(
workflowID: data.containsKey("workflow_id") && data["workflow_id"] != null ? data["workflow_id"] : null,
);
w.mapFromJSON(data, WorkflowInstance());
if (w.logo != null) { // get image dimensions
var image = Image.network(w.logo!);
image.image
.resolve(const ImageConfiguration())
.addListener(
ImageStreamListener(
(ImageInfo info, bool _) {
w.width = info.image.width.toDouble();
w.height = info.image.height.toDouble();
}));
}
return w;
}
@override
Map<String, dynamic> infos() {
return {};
}
@override Map<String, dynamic> serialize() {
Map<String, dynamic> obj ={
"workflow_id": workflowID,
};
obj.addAll(toJSON());
return obj;
}
}
class WorkflowInstance extends AbstractInstance<WorkflowPricing, WorkflowPartnership> {
WorkflowInstance(): super();
@override
WorkflowInstance deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return WorkflowInstance(); }
var w = WorkflowInstance();
w.mapFromJSON(json, WorkflowPartnership());
return w;
}
@override
Map<String, dynamic> infos() {
return {};
}
@override
Map<String, dynamic> serialize() {
return toJSON();
}
}
class WorkflowPartnership extends AbstractPartnerShip<WorkflowPricing> {
WorkflowPartnership(): super();
@override
WorkflowPartnership deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return WorkflowPartnership(); }
var w = WorkflowPartnership();
w.mapFromJSON(json, WorkflowPricing());
return w;
}
@override
Map<String, dynamic> serialize() {
return toJSON();
}
}
class WorkflowPricing extends AbstractPricing {
@override WorkflowPricing deserialize(json) {
var w = WorkflowPricing();
w.mapFromJSON(json);
return w;
}
@override
Map<String, dynamic> serialize() {
return toJSON();
}
}

View File

@@ -1,5 +1,10 @@
import 'package:oc_front/models/abstract.dart';
import 'package:oc_front/models/logs.dart';
import 'package:oc_front/models/resources/compute.dart';
import 'package:oc_front/models/resources/data.dart';
import 'package:oc_front/models/resources/processing.dart';
import 'package:oc_front/models/resources/resources.dart';
import 'package:oc_front/models/resources/storage.dart';
import 'package:oc_front/models/search.dart';
import 'package:oc_front/models/shared.dart';
import 'package:oc_front/models/workflow.dart';
@@ -20,6 +25,7 @@ Map<Type, SerializerDeserializer> refs = <Type, SerializerDeserializer> {
Check: Check(),
CollaborativeArea: CollaborativeArea(),
SimpleData: SimpleData(),
EnumData: EnumData(),
};
class APIResponse<T extends SerializerDeserializer> {
@@ -53,7 +59,9 @@ class APIResponse<T extends SerializerDeserializer> {
code: j.containsKey("code") && j["code"] != null ? j["code"] : 200,
error: j.containsKey("error") && j["error"] != null ? j["error"] : "",
);
} catch (e) { return APIResponse<T>( data: refs[T]!.deserialize(data), ); }
} catch (e) {
return APIResponse<T>( data: refs[T]?.deserialize(data), );
}
}
}
@@ -66,17 +74,34 @@ class SimpleData extends SerializerDeserializer<SimpleData> {
@override Map<String, dynamic> serialize() => { };
}
class EnumData extends SerializerDeserializer<EnumData> {
EnumData({ this.value = const {} });
Map<String, dynamic> value = {};
@override deserialize(dynamic json) {
return EnumData(value: json as Map<String, dynamic>);
}
@override Map<String, dynamic> serialize() => { };
}
class RawData extends SerializerDeserializer<RawData> {
RawData({ this.values = const []});
List<dynamic> values = [];
@override deserialize(dynamic json) {
return RawData(values: json ?? []); }
try {
return RawData(values: json ?? []);
} catch (e) {
print(e);
print(json);
return RawData();
}
}
@override Map<String, dynamic> serialize() => { };
}
abstract class ShallowData {
String getID();
String getName();
Map<String, dynamic> serialize();
}
class Shallow {

37
lib/models/schedule.dart Normal file
View File

@@ -0,0 +1,37 @@
import 'package:oc_front/models/abstract.dart';
class Scheduler extends SerializerDeserializer<Scheduler> {
DateTime? start;
DateTime? end;
double? duration;
String? cron;
Scheduler({
this.start,
this.end,
this.duration,
this.cron,
});
@override
Scheduler deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Scheduler(); }
var w = Scheduler(
start: json.containsKey("start") && json["start"] != null ? DateTime.parse(json["start"]) : null,
end: json.containsKey("end") && json["end"] != null ? DateTime.parse(json["end"]) : null,
duration: json.containsKey("duration_s") && json["duration_s"] != null ? json["duration_s"] : -1,
cron: json.containsKey("cron") && json["cron"] != null ? json["cron"] : null,
);
return w;
}
@override Map<String, dynamic> serialize() {
return {
"start": start?.toIso8601String(),
"end": end?.toIso8601String(),
"duration_s": duration,
"cron": cron,
};
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -79,13 +79,14 @@ class CollaborativeArea extends SerializerDeserializer<CollaborativeArea> {
rule : json.containsKey("collaborative_area") ? CollaborativeAreaRule().deserialize(json["collaborative_area"]) : CollaborativeAreaRule(),
id: json.containsKey("id") ? json["id"] : null,
name: json.containsKey("name") ? json["name"] : null,
creatorID: json.containsKey("creator_id") ? json["creator_id"] : null,
description: json.containsKey("description") ? json["description"] : null,
version: json.containsKey("version") ? json["version"] : null,
attributes: json.containsKey("attributes") ? json["attributes"] : {},
workspaces: json.containsKey("shared_workspaces") ? fromListJson(json["shared_workspaces"], Workspace()) : [],
workflows: json.containsKey("shared_workflows") ? fromListJson(json["shared_workflows"], Workflow()) : [],
peers: json.containsKey("shared_peers") ? fromListJson(json["shared_peers"], Peer()) : [],
rules: json.containsKey("rules") ? json["rules"] : [],
workspaces: json.containsKey("shared_workspaces") && json["shared_workspaces"] != null ? fromListJson(json["shared_workspaces"], Workspace()) : [],
workflows: json.containsKey("shared_workflows") && json["shared_workflows"] != null ? fromListJson(json["shared_workflows"], Workflow()) : [],
peers: json.containsKey("shared_peers") && json["shared_peers"] != null ? fromListJson(json["shared_peers"], Peer()) : [],
rules: json.containsKey("shared_rules") && json["shared_rules"] != null ? json["shared_rules"] : [],
);
}
@override

View File

@@ -1,40 +1,41 @@
import 'package:flutter/material.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
import 'package:flutter_flow_chart/flutter_flow_chart.dart';
import 'package:oc_front/core/models/workspace_local.dart';
import 'package:oc_front/models/abstract.dart';
import 'package:oc_front/models/logs.dart';
import 'package:oc_front/models/resources/compute.dart';
import 'package:oc_front/models/resources/data.dart';
import 'package:oc_front/models/resources/processing.dart';
import 'package:oc_front/models/resources/resources.dart';
import 'package:oc_front/models/resources/storage.dart';
import 'package:oc_front/models/resources/workflow.dart';
import 'package:oc_front/models/response.dart';
import 'package:oc_front/models/search.dart';
import 'package:oc_front/widgets/forms/sub_keys_forms.dart';
class Check extends SerializerDeserializer<Check> {
bool is_available = false;
bool isAvailable = false;
Check({
this.is_available = false,
this.isAvailable = false,
});
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Check(); }
return Check(
is_available: json.containsKey("is_available") ? json["is_available"] : false,
isAvailable: json.containsKey("is_available") ? json["is_available"] : false,
);
}
@override Map<String, dynamic> serialize() {
return {
"is_available": is_available,
"is_available": isAvailable,
};
}
}
class WorkflowExecutions extends SerializerDeserializer<WorkflowExecutions> {
List<WorkflowExecution> executions = [];
String? executionData;
int? status;
String? workflowId;
WorkflowExecutions({
this.executions = const [],
});
@@ -56,7 +57,7 @@ class WorkflowExecutions extends SerializerDeserializer<WorkflowExecutions> {
class WorkflowExecution extends SerializerDeserializer<WorkflowExecution> {
String? id;
String? name;
String? executionData;
String? startDate;
String? endDate;
int? status;
String? workflowId;
@@ -66,7 +67,7 @@ class WorkflowExecution extends SerializerDeserializer<WorkflowExecution> {
WorkflowExecution({
this.id,
this.executionData,
this.startDate,
this.status,
this.workflowId,
this.name,
@@ -79,7 +80,7 @@ class WorkflowExecution extends SerializerDeserializer<WorkflowExecution> {
return WorkflowExecution(
id: json.containsKey("id") ? json["id"] : "",
endDate: json.containsKey("end_date") ? json["end_date"] : "",
executionData: json.containsKey("execution_date") ? json["execution_date"] : "",
startDate: json.containsKey("execution_date") ? json["execution_date"] : "",
status: json.containsKey("state") ? json["state"] : 1,
workflowId: json.containsKey("workflow_id") ? json["workflow_id"] : "",
name: json.containsKey("name") ? json["name"] : "",
@@ -91,7 +92,7 @@ class WorkflowExecution extends SerializerDeserializer<WorkflowExecution> {
"id": id,
"name": name,
"end_date": endDate,
"execution_data": executionData,
"execution_data": startDate,
"status": status,
"workflow_id": workflowId,
};
@@ -108,8 +109,6 @@ class Workflow extends SerializerDeserializer<Workflow> implements ShallowData
List<dynamic> processing;
List<dynamic> workflows;
Graph? graph;
Scheduler? schedule;
bool scheduleActive = false;
List<dynamic> shared;
Workflow({
@@ -121,14 +120,12 @@ class Workflow extends SerializerDeserializer<Workflow> implements ShallowData
this.processing = const [],
this.workflows = const [],
this.graph,
this.schedule,
this.scheduleActive = false,
this.shared = const [],
});
@override String getID() => id ?? "";
@override String getName() => name ?? "";
@override String getDescription() => "";
String getDescription() => "";
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
@@ -140,11 +137,9 @@ class Workflow extends SerializerDeserializer<Workflow> implements ShallowData
processing: json.containsKey("processings") ? json["processings"] : [],
compute: json.containsKey("computes") ? json["computes"] : [],
data: json.containsKey("datas") ? json["datas"] : [],
scheduleActive: json.containsKey("schedule_active") ? json["schedule_active"] : false,
storage: json.containsKey("storages") ? json["storages"] : [],
shared: json.containsKey("shared") ? json["shared"] : [],
graph: json.containsKey("graph") ? Graph().deserialize(json["graph"]) : null,
schedule: json.containsKey("schedule") ? Scheduler().deserialize(json["schedule"]) : null,
);
}
@override Map<String, dynamic> serialize() {
@@ -152,12 +147,10 @@ class Workflow extends SerializerDeserializer<Workflow> implements ShallowData
"id": id,
"name": name,
"datas": data,
"computes" : compute,
"storages": storage,
"processings": processing,
"computes" : compute,
"workflows": workflows,
"schedule_active": scheduleActive,
"schedule": schedule?.serialize(),
"processings": processing,
};
if (graph != null) {
obj["graph"] = graph!.serialize();
@@ -168,24 +161,17 @@ class Workflow extends SerializerDeserializer<Workflow> implements ShallowData
void fromDashboard(Map<String, dynamic> j) {
id = j["id"];
name = j["name"];
scheduleActive = j["schedule_active"];
if (j.containsKey("graph")) {
graph = Graph();
graph!.fromDashboard(j["graph"]);
}
if (j.containsKey("schedule")) {
schedule = Scheduler();
schedule!.fromDashboard(j["schedule"]);
}
}
Map<String, dynamic> toDashboard() {
return {
"id": id,
"name": name,
"graph": graph?.toDashboard(),
"schedule_active": scheduleActive,
"schedule": schedule?.toDashboard(),
"shared": shared,
"graph": graph?.toDashboard(),
};
}
}
@@ -221,7 +207,7 @@ class Scheduler extends SerializerDeserializer<Scheduler> {
end = DateTime.parse(j["end"]);
}
} catch (e) {}
} catch (e) { /**/ }
}
Map<String, dynamic> toDashboard() {
return {
@@ -279,6 +265,159 @@ class Graph extends SerializerDeserializer<Graph> {
this.links = const [],
});
Map<String, List<dynamic>> getInfosToUpdate(SubMapFormsType type) {
Map<String, List<dynamic>> infos = {};
for (var item in items.values) {
var inst = item.getElement()?.getSelectedInstance();
if (inst == null) { return infos; }
infos[item.id ?? ""] = (type == SubMapFormsType.INPUT ? inst.inputs : (
type == SubMapFormsType.OUTPUT ? inst.outputs : inst.env)).map( (e) => e.serialize()).toList();
}
return infos;
}
Map<String, List<dynamic>> getEnvToUpdate() {
return getInfosToUpdate(SubMapFormsType.ENV);
}
Map<String, List<dynamic>> getInputToUpdate() {
return getInfosToUpdate(SubMapFormsType.INPUT);
}
Map<String, List<dynamic>> getOutputToUpdate() {
return getInfosToUpdate(SubMapFormsType.OUTPUT);
}
GraphItem getItemByElementID(String id) {
return items[id] ?? GraphItem();
}
Map<String,GraphItem?> getArrowByElementID(String id) {
Map<String,GraphItem?> arr = {};
for (var link in links) {
var nested = false;
var reverse = false;
String? from = link.source?.id;
String? to = link.destination?.id;
bool isInLink = (from?.contains(id) ?? false) || (to?.contains(id) ?? false);
if (isInLink && (["storage", "compute"].contains(getItemByElementID(from ?? "").getElement()?.getType())
|| ["storage", "compute"].contains(getItemByElementID(to ?? "").getElement()?.getType()))) {
nested = true;
reverse = link.source?.id?.contains(id) ?? false;
}
if (nested || isInLink) {
arr[reverse ? (to ?? "") : (from ?? "") ] = getItemByElementID(reverse ? (to ?? "") : (from ?? "") );
}
}
return arr;
}
void fillEnv(AbstractItem? mainItem, GraphItem? item, SubMapFormsType type, Map<String,int> alreadySeen) {
if (mainItem == null || item == null) {
return;
}
AbstractItem? el = item.getElement();
if (el?.getSelectedInstance() == null) {
return;
}
var inst = el!.getSelectedInstance()!;
var inst2 = mainItem.getSelectedInstance()!;
var what = type == SubMapFormsType.INPUT ? inst.inputs : (
type == SubMapFormsType.OUTPUT ? inst.outputs : inst.env);
var what2 = type == SubMapFormsType.INPUT ? inst2.inputs : (
type == SubMapFormsType.OUTPUT ? inst2.outputs : inst2.env);
for (var e in what2) {
if (e.attr != null && e.value == null) {
e.value = inst2.serialize()[e.attr!];
}
}
// should find arrow env info and add it to the env
List<Param> extParams = [];
var arrows = links.where( (e) => (e.source?.id?.contains(item.id ?? "") ?? false) || (e.destination?.id?.contains(item.id ?? "") ?? false));
for (var arrow in arrows) {
for (var info in arrow.infos) {
var i = info as Map<String, dynamic>;
for (var entry in i.entries) {
if (entry.value == null) { continue; }
var varName = "LINK_${el.getName().toUpperCase().replaceAll(" ", "_")}_${entry.key.toUpperCase()}";
/*alreadySeen[varName] = (alreadySeen[varName] ?? -1) + 1;
if ((alreadySeen[varName] ?? 0) > 1) {
varName = "${varName}_${alreadySeen[varName]}";
}*/
if ((entry.value is String) && !isEnvAttr(entry.value, what2)) {
extParams.add(Param( name: varName,
attr: entry.key, value: entry.value, origin: item.id, readOnly: true));
}
}
}
}
for ( var param in what) {
if (param.attr == null) { continue; }
var varName = param.name != null && (param.name!.contains("LINK_")
|| param.name!.contains("DATA_")
|| param.name!.contains("PROCESSING_")
|| param.name!.contains("STORAGE_")
|| param.name!.contains("WORKFLOW_")
|| param.name!.contains("COMPUTE") ) ? param.name : "${el.topic.toUpperCase()}_${el.getName().toUpperCase().replaceAll(" ", "_")}_${param.attr!.toUpperCase()}";
/*alreadySeen[varName] = (alreadySeen[varName] ?? -1) + 1;
if ((alreadySeen[varName] ?? 0) > 0) {
varName = "${varName}_${alreadySeen[varName]}";
}*/
dynamic env;
if (param.value == null) {
var s = el.serialize();
s.addAll(el.getSelectedInstance()?.serialize() ?? {});
env = s[param.attr!];
} else {
env = param.value;
}
// bool isSrc = param.origin == null;
//if (isSrc) { continue; }
if (!isEnvAttr(env, what2)) {
extParams.add(Param( name: varName,
attr: param.attr, value: env, origin: item.id, readOnly: true));
}
}
for (var param in extParams) {
what2.add(param);
}
}
bool isEnvAttr(String value, List<Param> params) {
for (var e in params) {
if (value == e.value) { return true; }
}
return false;
}
void fill() {
Map<String, int> alreadySeen = {};
var its = items.values.toList();
for (var type in [SubMapFormsType.INPUT, SubMapFormsType.OUTPUT, SubMapFormsType.ENV]) {
for (var item in its) {
var envs = type == SubMapFormsType.INPUT ? item.getElement()?.getSelectedInstance()?.inputs : (
type == SubMapFormsType.OUTPUT ? item.getElement()?.getSelectedInstance()?.outputs : item.getElement()?.getSelectedInstance()?.env);
if (envs != null) {
envs.removeWhere( (e) => e.readOnly && e.name != null
&& (e.name!.contains("LINK_")
|| e.name!.contains("DATA_")
|| e.name!.contains("PROCESSING_")
|| e.name!.contains("STORAGE_")
|| e.name!.contains("WORKFLOW_")
|| e.name!.contains("COMPUTE") ));
}
}
for (var item in [...its, ...its.reversed]) {
var itss = getArrowByElementID(item.id ?? "");
for (var i in itss.values) {
fillEnv(item.getElement(), i, type, alreadySeen);
}
}
}
}
void fromDashboard(Map<String, dynamic> j) {
items = {};
for (var el in (j["elements"] as Map<dynamic, dynamic>).values) {
@@ -292,9 +431,11 @@ class Graph extends SerializerDeserializer<Graph> {
return d;
}).toList();
j["zoom"] = zoom;
fill();
}
Map<String, dynamic> toDashboard() {
fill();
List<Map<String, dynamic>> elements = [];
List<Map<String, dynamic>> arrows = [];
for (var el in items.values) {
@@ -313,28 +454,70 @@ class Graph extends SerializerDeserializer<Graph> {
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Graph(); }
return Graph(
var g = Graph(
zoom: json.containsKey("zoom") ? double.parse(json["zoom"].toString()) : 0,
links: json.containsKey("links") ? fromListJson(json["links"], GraphLink()) : [],
items: json.containsKey("items") ? fromMapJson<GraphItem>(json["items"], GraphItem()) : {},
);
g.fill();
return g;
}
@override Map<String, dynamic> serialize() {
fill();
return {
"zoom": zoom,
"items": toMapJson(items),
"links": toListJson(links),
};
}
}
class StorageProcessingGraphLink extends SerializerDeserializer<StorageProcessingGraphLink> {
bool write = false;
String? source;
String? destination;
String? filename;
StorageProcessingGraphLink({
this.write = false,
this.source,
this.destination,
this.filename,
});
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return StorageProcessingGraphLink(); }
return StorageProcessingGraphLink(
write: json.containsKey("write") ? json["write"] : false,
source: json.containsKey("source") ? json["source"] : "",
destination: json.containsKey("destination") ? json["destination"] : "",
filename: json.containsKey("filename") && json["filename"] != null ? json["filename"] : "",
);
}
@override Map<String, dynamic> serialize() {
return {
"write": write,
"source": source,
"destination": destination,
"filename": filename,
};
}
@override Map<String, dynamic> serialize() => {
"zoom": zoom,
"items": toMapJson(items),
"links": toListJson(links),
};
}
class GraphLink extends SerializerDeserializer<GraphLink> {
Position? source;
Position? destination;
GraphLinkStyle? style;
List<StorageProcessingGraphLink> infos = [];
List<Param> env = [];
GraphLink({
this.source,
this.destination,
this.style,
this.infos = const [],
this.env = const [],
});
void fromDashboard(Map<String, dynamic> j) {
@@ -342,6 +525,8 @@ class GraphLink extends SerializerDeserializer<GraphLink> {
destination = Position(id: j["to"]["id"], x: j["to"]["x"], y: j["to"]["y"]);
style = GraphLinkStyle();
style!.fromDashboard(j["params"]);
infos = fromListJson(j["infos"], StorageProcessingGraphLink());
env = fromListJson(j["env"], Param());
}
Map<String, dynamic> toDashboard() {
@@ -357,6 +542,8 @@ class GraphLink extends SerializerDeserializer<GraphLink> {
"y": destination?.y ?? 0,
},
"params": style?.toDashboard(),
"infos": toListJson(infos),
"env": env.map( (el) => el.serialize()).toList(),
};
}
@@ -364,9 +551,11 @@ class GraphLink extends SerializerDeserializer<GraphLink> {
try { json = json as Map<String, dynamic>;
} catch (e) { return GraphLink(); }
return GraphLink(
source: json.containsKey("source") ? Position().deserialize(json["source"]) : null,
destination: json.containsKey("destination") ? Position().deserialize(json["destination"]) : null,
style: json.containsKey("style") ? GraphLinkStyle().deserialize(json["style"]) : null,
source: json.containsKey("source") && json["source"] != null ? Position().deserialize(json["source"]) : null,
destination: json.containsKey("destination") && json["destination"] != null ? Position().deserialize(json["destination"]) : null,
style: json.containsKey("style") && json["style"] != null ? GraphLinkStyle().deserialize(json["style"]) : null,
infos: json.containsKey("storage_link_infos") && json["storage_link_infos"] != null ? fromListJson(json["storage_link_infos"], StorageProcessingGraphLink()) : [],
env: json.containsKey("env") && json["env"] != null ? fromListJson(json["env"], Param()) : [],
);
}
@override Map<String, dynamic> serialize() {
@@ -380,6 +569,8 @@ class GraphLink extends SerializerDeserializer<GraphLink> {
if (style != null) {
obj["style"] = style!.serialize();
}
obj["storage_link_infos"] = toListJson(infos);
obj["env"] = toListJson(env);
return obj;
}
}
@@ -521,33 +712,19 @@ class GraphItem extends SerializerDeserializer<GraphItem> {
return null;
}
void fromDashboard(Map<String, dynamic> j) {
id = j["id"];
position = Position(x: j["x"], y: j["y"]);
width = j["width"];
height = j["height"];
var abs = WorkspaceLocal.getItem(j["element"]?["id"] ?? "", true) as AbstractItem<FlowData>?;
if (abs != null) {
if (abs.topic == "data") {
data = DataItem().deserialize(abs.serialize());
data!.model = ResourceModel().deserialize(j["element"]["resource_model"]);
} else if (abs.topic == "processing") {
processing = ProcessingItem().deserialize(abs.serialize());
processing!.model = ResourceModel().deserialize(j["element"]["resource_model"]);
if ((j["element"] as Map<String, dynamic>).containsKey("container")) {
processing!.container = Containered().deserialize(j["element"]["container"]);
processing!.container?.env?.removeWhere((key, value) => key == "" || value == "");
processing!.container?.volumes?.removeWhere((key, value) => key == "" || value == "");
processing!.expose.removeWhere((element) => element.port == null || element.port == 0 || (element.PAT == 0 && element.path == ""));
}
} else if (abs.topic == "compute") {
compute = ComputeItem().deserialize(abs.serialize());
} else if (abs.topic == "storage") {
storage = StorageItem().deserialize(abs.serialize());
} else if (abs.topic == "workflow") {
workflow = WorkflowItem().deserialize(abs.serialize());
if (j["element"] != null) {
if (j["element"]["type"] == "data") { data = DataItem().deserialize(j["element"]);
} else if (j["element"]["type"] == "processing") { processing = ProcessingItem().deserialize(j["element"]);
} else if (j["element"]["type"] == "compute") { compute = ComputeItem().deserialize(j["element"]);
} else if (j["element"]["type"] == "storage") { storage = StorageItem().deserialize(j["element"]);
} else if (j["element"]["type"] == "workflow") { workflow = WorkflowItem().deserialize(j["element"]);
} else {
compute = null;
data = null;
@@ -566,7 +743,8 @@ class GraphItem extends SerializerDeserializer<GraphItem> {
Map<String, dynamic> toDashboard() {
Map<String, dynamic> element = {};
for(var el in [data, processing, storage, compute, workflow]) {
List<AbstractItem?> items = [data, processing, storage, compute, workflow];
for(var el in items) {
if (el != null && el.getID() != "") {
element = el.serialize();
break;

View File

@@ -1,7 +1,10 @@
import 'package:flutter_flow_chart/flutter_flow_chart.dart';
import 'package:oc_front/models/abstract.dart';
import 'package:oc_front/models/resources/compute.dart';
import 'package:oc_front/models/resources/data.dart';
import 'package:oc_front/models/resources/processing.dart';
import 'package:oc_front/models/resources/storage.dart';
import 'package:oc_front/models/resources/workflow.dart';
import 'package:oc_front/models/response.dart';
import 'package:oc_front/models/search.dart';
class Workspace extends SerializerDeserializer<Workspace> implements ShallowData {
String? id;
@@ -44,13 +47,15 @@ class Workspace extends SerializerDeserializer<Workspace> implements ShallowData
workflows: json.containsKey("workflow_resources") ? fromListJson(json["workflow_resources"], WorkflowItem()) : []
);
}
@override Map<String, dynamic> serialize() => {
"id": id,
"name": name,
"processings": processings.map((e) => e.id).toList(),
"storages": storages.map((e) => e.id).toList(),
"computes": computes.map((e) => e.id).toList(),
"datas": datas.map((e) => e.id).toList(),
"workflows": workflows.map((e) => e.id).toList(),
};
@override Map<String, dynamic> serialize() {
return {
"id": id,
"name": name,
"processings": processings.map((e) => e.id).toList(),
"storages": storages.map((e) => e.id).toList(),
"computes": computes.map((e) => e.id).toList(),
"datas": datas.map((e) => e.id).toList(),
"workflows": workflows.map((e) => e.id).toList(),
};
}
}