Created
May 15, 2019 18:41
-
-
Save cgillis-aras/1d07f278874ba57168df3a2106d97b35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var scopeIds = {}; | |
// Use a simple lookup table to get the value of the | |
var asilLookup = getAsilLookupTable(); | |
// We want to style the ASIL value based on how important it is | |
var qmStyle = inArgs.factory.createCmfStyle(); | |
qmStyle.textColor = "#000000"; | |
qmStyle.textDecoration = "none"; | |
qmStyle.fontWeight = "normal"; | |
var asilA_style = inArgs.factory.createCmfStyle(); | |
asilA_style.textColor = "#000088"; | |
asilA_style.textDecoration = "underline"; | |
asilA_style.fontWeight = "bold"; | |
var asilB_style = inArgs.factory.createCmfStyle(); | |
asilB_style.textColor = "#008800"; | |
asilB_style.textDecoration = "underline"; | |
asilB_style.fontWeight = "bold"; | |
var asilC_style = inArgs.factory.createCmfStyle(); | |
asilC_style.textColor = "#ff0000"; | |
asilC_style.textDecoration = "underline"; | |
asilC_style.fontWeight = "bold"; | |
var asilD_style = inArgs.factory.createCmfStyle(); | |
asilD_style.textColor = "#80000"; | |
asilD_style.textDecoration = "underline"; | |
asilD_style.fontWeight = "bold"; | |
var asilStyles = { | |
'' : qmStyle, | |
'QM' : qmStyle, | |
'ASIL A': asilA_style, | |
'ASIL B': asilB_style, | |
'ASIL C': asilC_style, | |
'ASIL D': asilD_style | |
}; | |
for (var i = 0; i < inArgs.changedPropertyItems.length; i++) | |
{ | |
var currentAction = inArgs.changedPropertyItems[i].getElement(); | |
if (scopeIds[currentAction.id]) { | |
continue; | |
} | |
// Get the current values for the Severity, Exposure, Controllability, and ASIL from the current row | |
var severity = currentAction.getPropertyItem("Severity"); | |
var exposure = currentAction.getPropertyItem("Exposure"); | |
var controllability = currentAction.getPropertyItem("Controllability"); | |
var asil = currentAction.getPropertyItem("Risk ASIL"); | |
var resultValue = ""; | |
if (severity.value && exposure.value && controllability.value) | |
{ | |
resultValue = asilLookup[parseInt(severity.value)][parseInt(exposure.value)][parseInt(controllability.value)]; | |
} | |
// This is how you update the value of a cell | |
inArgs.resultBuilder.markToUpdateValue(asil.id, resultValue); | |
// This is how you update the style of a cell | |
inArgs.resultBuilder.markToUpdateStyle(asil.id, asilStyles[resultValue]); | |
} | |
// Returns a table that can be used to lookup the correct ASIL value based on the severity, exposure, and controllability of the risk | |
var getAsilLookupTable = function() | |
{ | |
return { | |
0: { | |
0 : { | |
0: '', | |
1: '', | |
2: '', | |
3: '' | |
}, | |
1: { | |
0: '', | |
1: '', | |
2: '', | |
3: '' | |
}, | |
2: { | |
0: '', | |
1: '', | |
2: '', | |
3: '' | |
}, | |
3: { | |
0: '', | |
1: '', | |
2: '', | |
3: '' | |
}, | |
4: { | |
0: '', | |
1: '', | |
2: '', | |
3: '' | |
} | |
}, | |
1: { | |
0: { | |
0: '', | |
1: '', | |
2: '', | |
3: '' | |
}, | |
1: { | |
0: '', | |
1: 'QM', | |
2: 'QM', | |
3: 'QM' | |
}, | |
2: { | |
0: '', | |
1: 'QM', | |
2: 'QM', | |
3: 'QM' | |
}, | |
3: { | |
0: '', | |
1: 'QM', | |
2: 'QM', | |
3: 'ASIL A' | |
}, | |
4: { | |
0: '', | |
1: 'QM', | |
2: 'ASIL A', | |
3: 'ASIL B' | |
} | |
}, | |
2: { | |
0: { | |
0: '', | |
1: '', | |
2: '', | |
3: '' | |
}, | |
1: { | |
0: '', | |
1: 'QM', | |
2: 'QM', | |
3: 'QM' | |
}, | |
2: { | |
0: '', | |
1: 'QM', | |
2: 'QM', | |
3: 'ASIL A' | |
}, | |
3: { | |
0: '', | |
1: 'QM', | |
2: 'ASIL A', | |
3: 'ASIL B' | |
}, | |
4: { | |
0: '', | |
1: 'ASIL A', | |
2: 'ASIL B', | |
3: 'ASIL C' | |
} | |
}, | |
3: { | |
0: { | |
0: '', | |
1: '', | |
2: '', | |
3: '' | |
}, | |
1: { | |
0: '', | |
1: 'QM', | |
2: 'QM', | |
3: 'ASIL A' | |
}, | |
2: { | |
0: '', | |
1: 'QM', | |
2: 'ASIL A', | |
3: 'ASIL B' | |
}, | |
3: { | |
0: '', | |
1: 'ASIL A', | |
2: 'ASIL B', | |
3: 'ASIL C' | |
}, | |
4: { | |
0: '', | |
1: 'ASIL B', | |
2: 'ASIL C', | |
3: 'ASIL D' | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment