Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/sr7 cond conflit #52

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public enum BlinkingSpeed
public AdvancedConditions()
: base()
{
BackgroundColor = "";
BackgroundColor = "None";
IsVisible = true;
Blinking = BlinkingSpeed.None;
Rotation = null;
}

[DisplayName("Background Color"), Category(Categories.Appearance)]
Expand All @@ -41,17 +42,24 @@ public override void LoadFromXml(XmlNode xmlNode)
base.LoadFromXml(xmlNode);
BackgroundColor = xmlNode.GetChildAsString("BackgroundColor");
IsVisible = xmlNode.GetChildAsBool("IsVisible");
Rotation = xmlNode.GetChildAsInt("Rotation");
Blinking = xmlNode.GetChildAsEnum<BlinkingSpeed>("Blinking");

// If the rotation node is not null, parse the value and assign it to the Rotation property
XmlNode rotationNode = xmlNode.SelectSingleNode("Rotation");
Rotation = rotationNode != null ? (int?)int.Parse(rotationNode.InnerText) : null;
}

public override void SaveToXml(XmlElement xmlElem)
{
base.SaveToXml(xmlElem);
xmlElem.AppendElem("BackgroundColor", BackgroundColor);
xmlElem.AppendElem("Rotation", Rotation);
xmlElem.AppendElem("BackgroundColor", string.IsNullOrEmpty(BackgroundColor) ? "None" : BackgroundColor);
xmlElem.AppendElem("IsVisible", IsVisible);
xmlElem.AppendElem("Blinking", Blinking);

if (Rotation.HasValue)
{
xmlElem.AppendElem("Rotation", Rotation.Value);
}
}

public override object Clone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class BarGraphConditions : AdvancedConditions

public BarGraphConditions() : base()
{
FillColor = "";
FillColor = "None";
}

[DisplayName("Fill Color"), Category(Categories.Appearance)]
Expand All @@ -26,7 +26,7 @@ public override void LoadFromXml(XmlNode xmlNode)
public override void SaveToXml(XmlElement xmlElem)
{
base.SaveToXml(xmlElem);
xmlElem.AppendElem("FillColor", FillColor);
xmlElem.AppendElem("FillColor", string.IsNullOrEmpty(FillColor) ? "None" : FillColor);
}

public override object Clone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,40 @@ public class BasicShapeConditions : AdvancedConditions
public BasicShapeConditions()
: base()
{
IsVisible = true;
Blinking = BlinkingSpeed.None;
BackgroundColor = "";
Height = "";
Width = "";

Height = null;
Width = null;
}

[DisplayName("Height"), Category(Categories.Appearance)]
public string Height { get; set; }
public int? Height { get; set; }

[DisplayName("Width"), Category(Categories.Appearance)]
public string Width { get; set; }
public int? Width { get; set; }



public override void LoadFromXml(XmlNode xmlNode)
{
base.LoadFromXml(xmlNode);
Height = xmlNode.GetChildAsString("Height");
Width = xmlNode.GetChildAsString("Width");
XmlNode heightNode = xmlNode.SelectSingleNode("Height");
Height = heightNode != null ? (int?)int.Parse(heightNode.InnerText) : null;

XmlNode widthNode = xmlNode.SelectSingleNode("Width");
Width = widthNode != null ? (int?)int.Parse(widthNode.InnerText) : null;
}

public override void SaveToXml(XmlElement xmlElem)
{
base.SaveToXml(xmlElem);
xmlElem.AppendElem("Height", Height);
xmlElem.AppendElem("Width", Width);
if (Width.HasValue)
{
xmlElem.AppendElem("Width", Width.Value);
}
if (Height.HasValue)
{
xmlElem.AppendElem("Height", Height.Value);
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ public class DynamicTextConditions : AdvancedConditions
public DynamicTextConditions()
: base()
{
IsVisible = true;
Blinking = BlinkingSpeed.None;
TextContent = "";
FontSize = "";

TextContent = "None";
FontSize = null;
}

[DisplayName("FontSize"), Category(Categories.Appearance)]
public string FontSize { get; set; }
public int? FontSize { get; set; }

[DisplayName("Text Content"), Category(Categories.Appearance)]
public string TextContent { get; set; }
Expand All @@ -26,14 +25,19 @@ public override void LoadFromXml(XmlNode xmlNode)
{
base.LoadFromXml(xmlNode);
TextContent = xmlNode.GetChildAsString("TextContent");
FontSize = xmlNode.GetChildAsString("FontSize");

XmlNode fontSizeNode = xmlNode.SelectSingleNode("FontSize");
FontSize = fontSizeNode != null ? (int?)int.Parse(fontSizeNode.InnerText) : null;
}

public override void SaveToXml(XmlElement xmlElem)
{
base.SaveToXml(xmlElem);
xmlElem.AppendElem("TextContent", TextContent);
xmlElem.AppendElem("FontSize", FontSize);
xmlElem.AppendElem("TextContent", string.IsNullOrEmpty(TextContent) ? "None" : TextContent);
if (FontSize.HasValue)
{
xmlElem.AppendElem("FontSize", FontSize.Value);
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ public PictureConditions()
{
IsVisible = true;
Blinking = BlinkingSpeed.None;
Rotation = null;
}

[DisplayName("Rotation"), Category(Categories.Appearance)]
[Description("The rotation angle of the shape in degrees.")]
public string Rotation { get; set; }
public int? Rotation { get; set; }



Expand All @@ -33,14 +34,19 @@ public override void LoadFromXml(XmlNode xmlNode)
{
base.LoadFromXml(xmlNode);
IsVisible = xmlNode.GetChildAsBool("IsVisible");
Rotation = xmlNode.GetChildAsString("Rotation");
Blinking = xmlNode.GetChildAsEnum<BlinkingSpeed>("Blinking");

XmlNode rotationNode = xmlNode.SelectSingleNode("Rotation");
Rotation = rotationNode != null ? (int?)int.Parse(rotationNode.InnerText) : null;
}

public override void SaveToXml(XmlElement xmlElem)
{
base.SaveToXml(xmlElem);
xmlElem.AppendElem("Rotation", Rotation);
if (Rotation.HasValue)
{
xmlElem.AppendElem("Rotation", Rotation.Value);
}
xmlElem.AppendElem("IsVisible", IsVisible);
xmlElem.AppendElem("Blinking", Blinking);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,30 @@ scada.scheme.updateStyles = function (divComp, cond, bool) {
divComp.css("transform", "rotate(" + cond.rotation + "deg)");
}

if ("backgroundColor" in cond) {
if (bool) {
divComp.css("background-color", cond.backgroundColor);
if ("backgroundColor" in cond || "backColor" in cond) {
var lineChild = divComp.find(".line");

if (lineChild.length > 0) {
if (bool) {
lineChild.css("background-color", cond.backgroundColor);
} else {
lineChild.css(
"background-color",
cond.backColor ? String(cond.backColor) : "",
);
}
} else {
divComp.css(
"background-color",
cond.backColor ? String(cond.backColor) : "",
);
if (bool) {
divComp.css("background-color", cond.backgroundColor);
} else {
divComp.css(
"background-color",
cond.backColor ? String(cond.backColor) : "",
);
}
}
}

if ("isVisible" in cond) {
if (bool) {
divComp.css("visibility", cond.isVisible ? "visible" : "hidden");
Expand All @@ -74,7 +88,7 @@ scada.scheme.updateStyles = function (divComp, cond, bool) {
};

scada.scheme.applyRotation = function (divComp, props) {
if (props.rotation && props.rotation > 0) {
if (props.rotation) {
divComp.css({
transform: "rotate(" + props.rotation + "deg)",
});
Expand All @@ -97,55 +111,35 @@ scada.scheme.updateColors = function (divComp, cnlDataExt, isHovered, props) {
setBackColor(divComp, backColor, true, statusColor);
setBorderColor(divComp, borderColor, true, statusColor);
};
function mergeAndModifyConditions(conditions) {
let result = [];
const criteriaFields = [
"compareOperator1",
"compareArgument1",
"logicalOperator",
"compareOperator2",
"compareArgument2",
];

let groups = conditions.reduce((acc, condition) => {
const criteriaKey = criteriaFields
.map((field) => condition[field])
.join("_");
if (!acc[criteriaKey]) acc[criteriaKey] = [];
acc[criteriaKey].push(condition);
return acc;
}, {});

// Fusion of each group
Object.values(groups).forEach((group) => {
let mergedCondition = group.reduce(
(acc, condition) => {
Object.keys(condition).forEach((key) => {
if (!criteriaFields.includes(key)) {
if (
typeof condition[key] === "string" &&
condition[key] &&
!acc[key]
)
acc[key] = condition[key];
if (
typeof condition[key] === "number" &&
condition[key] > (acc[key] || 0)
)
acc[key] = condition[key];
}
});
return acc;
},
{ ...group[0] },
);

result.push(mergedCondition);
});
function mergeWithPriorityToFirst(conditions) {
let mergedCondition = {};

for (let condition of conditions) {
Object.keys(condition).forEach((key) => {
if (
key === "compareOperator1" ||
key === "compareArgument1" ||
key === "logicalOperator" ||
key === "compareOperator2" ||
key === "compareArgument2"
) {
return;
}
if (
mergedCondition[key] === undefined ||
mergedCondition[key] === null ||
mergedCondition[key] === "" ||
mergedCondition[key] === "None" ||
(key === "isVisible" && typeof condition[key] === "boolean")
) {
mergedCondition[key] = condition[key];
}
});
}

return result;
return mergedCondition;
}

scada.scheme.updateComponentData = function (component, renderContext) {
var props = component.props;
if (props.inCnlNum <= 0) {
Expand All @@ -156,23 +150,24 @@ scada.scheme.updateComponentData = function (component, renderContext) {

if (props.conditions && cnlDataExt.d.stat > 0) {
var cnlVal = cnlDataExt.d.val;
var mergedAndModifiedConditions = mergeAndModifyConditions(
props.conditions,
);
let count = 0;

for (var cond of mergedAndModifiedConditions) {
let condSastifieds = [];
let notSatisfieds = [];
for (var cond of props.conditions) {
if (scada.scheme.calc.conditionSatisfied(cond, cnlVal)) {
scada.scheme.updateStyles(divComp, cond, true);
scada.scheme.handleBlinking(divComp, cond.blinking, true);
count = count + 1;
condSastifieds.push(cond);
} else {
if (count < 0) {
scada.scheme.updateStyles(divComp, props, false);
scada.scheme.handleBlinking(divComp, cond.blinking, false);
}
notSatisfieds.push(cond);
}
}
let mergeWithPriority = mergeWithPriorityToFirst(condSastifieds);
scada.scheme.updateStyles(divComp, mergeWithPriority, true);
scada.scheme.handleBlinking(divComp, mergeWithPriority.blinking, true);

notSatisfieds.forEach((notScondSastified) => {
scada.scheme.updateStyles(divComp, props, false);
scada.scheme.handleBlinking(divComp, notScondSastified.blinking, false);
});
}
};

Expand Down
Loading