Last active
August 21, 2024 06:22
-
-
Save jbsarrodie/45a312cff559d23cf55ed102422e8af7 to your computer and use it in GitHub Desktop.
#jArchi script to change concepts' type (and optionally convert no more valid relationships to association)
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
function convert(selection, convertToType) { | |
var relaxed = window.confirm('By default, selected concepts are converted, and relationships involving them that would no more be valid are converted to associations. Click Ok for this behavior or Cancel if you want a "strict" mode where relationships are not changed.'); | |
$(selection).each(function(o) { | |
$(concept(o)).outRels().each(function(r) { | |
if (! $.model.isAllowedRelationship(r.type, convertToType, r.target.type)) { | |
checkAndConvertRelationship(r, relaxed); | |
} | |
}); | |
$(concept(o)).inRels().each(function(r) { | |
if (! $.model.isAllowedRelationship(r.type, r.source.type, convertToType)) { | |
checkAndConvertRelationship(r, relaxed); | |
} | |
}); | |
concept(o).concept.type = convertToType; | |
}); | |
} | |
function checkAndConvertRelationship(r, relaxed) { | |
if (relaxed) { | |
r.documentation = 'This relationship has been converted from "'+r.type.replace(/-relationship$/, '')+'" to "association"\n'+r.documentation; | |
r.type = "association-relationship"; | |
} else { | |
window.alert('Relationship "'+r.name+'" from "'+r.source.name+'" to "'+r.target.name+'" will no more be valid after convertion and "strict" mode is on. Convertion aborted.'); | |
exit(); | |
} | |
} | |
function concept(o) { | |
return o.concept ? o.concept : o; | |
} |
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
load(__DIR__+"/../ConvertConcept.lib.js"); | |
convert(selection, getTypeFromFilename()); | |
function getTypeFromFilename() { | |
return __FILE__.replace(/^.*\//, '').replace(/.ajs$/, '').replace(/%20|\s/g, '-').toLowerCase(); | |
} |
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
load(__DIR__+"/../ConvertConcept.lib.js"); | |
convert(selection, getTypeFromFilename()); | |
function getTypeFromFilename() { | |
return __FILE__.replace(/^.*\//, '').replace(/.ajs$/, '').replace(/%20|\s/g, '-').toLowerCase(); | |
} |
With the latest jArchi v1.0.0 and support GraalVM, because of __FILE__
change in path format, to support both ES5, ES6 and Graal:
function getTypeFromFilename() {
return __FILE__.replace(/^.*[\/\\]/, '').replace(/\.ajs$/, '').replace(/(%20|\s)/g, '-').toLowerCase();
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also, we may be able to remove
selection
as an argument:Edit - that works, so updated the code above.