Skip to content

Commit

Permalink
Unit Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz committed Dec 9, 2024
1 parent 9e4b9aa commit 721863b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ qx.Class.define("osparc.data.model.PricingUnit", {
cost: parseFloat(pricingUnitData.currentCostPerUnit),
isDefault: pricingUnitData.default,
extraInfo: pricingUnitData.unitExtraInfo,
specificInfo: pricingUnitData.specificInfo || null,
});
},

Expand Down Expand Up @@ -77,7 +78,14 @@ qx.Class.define("osparc.data.model.PricingUnit", {
check: "Object",
nullable: false,
init: null,
event: "changeExtraInfo"
event: "changeExtraInfo",
},

specificInfo: {
check: "Object",
nullable: true,
init: null,
event: "changeSpecificInfo",
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
qx.Class.define("osparc.pricing.UnitEditor", {
extend: qx.ui.core.Widget,

construct: function(pricingUnitData) {
construct: function(pricingUnit) {
this.base(arguments);

this._setLayout(new qx.ui.layout.VBox(10));
Expand Down Expand Up @@ -46,16 +46,19 @@ qx.Class.define("osparc.pricing.UnitEditor", {
manager.add(specificInfo);
manager.add(unitExtraInfo);

if (pricingUnitData) {
if (pricingUnit) {
this.set({
pricingUnitId: pricingUnitData.pricingUnitId,
unitName: pricingUnitData.unitName,
costPerUnit: parseFloat(pricingUnitData.currentCostPerUnit),
comment: pricingUnitData.comment ? pricingUnitData.comment : "",
specificInfo: pricingUnitData.specificInfo && pricingUnitData.specificInfo["aws_ec2_instances"] ? pricingUnitData.specificInfo["aws_ec2_instances"].toString() : "",
default: pricingUnitData.default
pricingUnitId: pricingUnit.getPricingUnitId(),
unitName: pricingUnit.getName(),
costPerUnit: pricingUnit.getCost(),
});
const extraInfo = osparc.utils.Utils.deepCloneObject(pricingUnitData.unitExtraInfo);
if (pricingUnit.getClassification() === "TIER") {
this.set({
specificInfo: pricingUnit.getSpecificInfo() && pricingUnit.getSpecificInfo()["aws_ec2_instances"] ? pricingUnit.getSpecificInfo()["aws_ec2_instances"].toString() : "",
default: pricingUnit.getIsDefault(),
});
}
const extraInfo = osparc.utils.Utils.deepCloneObject(pricingUnit.getExtraInfo());
// extract the required fields from the unitExtraInfo
this.set({
unitExtraInfoCPU: extraInfo["CPU"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ qx.Class.define("osparc.study.PricingUnit", {
this.setUnitData(pricingUnit);
},

events: {
"editPricingUnit": "qx.event.type.Event",
},

properties: {
unitData: {
check: "osparc.data.model.PricingUnit",
Expand Down Expand Up @@ -65,6 +69,10 @@ qx.Class.define("osparc.study.PricingUnit", {
break;
case "edit-button":
control = new qx.ui.form.Button(qx.locale.Manager.tr("Edit"));
this.bind("showEditButton", control, "visibility", {
converter: show => show ? "visible" : "excluded"
});
control.addListener("execute", () => this.fireEvent("editPricingUnit"));
this._add(control);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ qx.Class.define("osparc.study.PricingUnitLicense", {
appearance: "strong-button",
center: true,
});
this.bind("showRentButton", control, "visibility", {
converter: show => show ? "visible" : "excluded"
});
control.addListener("execute", () => this.fireEvent("rentPricingUnit"));
this._add(control);
break;
}
Expand All @@ -57,18 +61,10 @@ qx.Class.define("osparc.study.PricingUnitLicense", {
});

// add edit button
const editButton = this.getChildControl("edit-button");
this.bind("showEditButton", editButton, "visibility", {
converter: show => show ? "visible" : "excluded"
})
editButton.addListener("execute", () => this.fireEvent("editPricingUnit"));
this.getChildControl("edit-button");

// add rent button
const rentButton = this.getChildControl("rent-button");
this.bind("showRentButton", rentButton, "visibility", {
converter: show => show ? "visible" : "excluded"
})
rentButton.addListener("execute", () => this.fireEvent("rentPricingUnit"));
this.getChildControl("rent-button");
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ qx.Class.define("osparc.study.PricingUnitTier", {
extend: osparc.study.PricingUnit,

events: {
"editPricingUnit": "qx.event.type.Event",
},

properties: {
Expand All @@ -46,13 +45,19 @@ qx.Class.define("osparc.study.PricingUnitTier", {
control = new qx.ui.basic.Label().set({
font: "text-14"
});
this.bind("showAwsSpecificInfo", control, "visibility", {
converter: show => show ? "visible" : "excluded"
})
this._add(control);
break;
case "unitExtraInfo":
control = new qx.ui.basic.Label().set({
font: "text-13",
rich: true,
});
this.bind("showUnitExtraInfo", control, "visibility", {
converter: show => show ? "visible" : "excluded"
});
this._add(control);
break;
}
Expand All @@ -75,9 +80,6 @@ qx.Class.define("osparc.study.PricingUnitTier", {
pricingUnit.bind("awsSpecificInfo", specificInfo, "value", {
converter: v => qx.locale.Manager.tr("EC2") + ": " + v,
});
this.bind("showAwsSpecificInfo", specificInfo, "visibility", {
converter: show => show ? "visible" : "excluded"
})
}

// add pricing unit extra info
Expand All @@ -87,16 +89,9 @@ qx.Class.define("osparc.study.PricingUnitTier", {
text += `${key}: ${value}<br>`;
});
unitExtraInfo.setValue(text);
this.bind("showUnitExtraInfo", unitExtraInfo, "visibility", {
converter: show => show ? "visible" : "excluded"
});

// add edit button
const editButton = this.getChildControl("edit-button");
this.bind("showEditButton", editButton, "visibility", {
converter: show => show ? "visible" : "excluded"
})
editButton.addListener("execute", () => this.fireEvent("editPricingUnit"));
this.getChildControl("edit-button");
}
}
});

0 comments on commit 721863b

Please sign in to comment.