Skip to content

Instantly share code, notes, and snippets.

@jbsarrodie
Last active May 23, 2022 12:44
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbsarrodie/45a312cff559d23cf55ed102422e8af7 to your computer and use it in GitHub Desktop.
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)
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;
}
load(__DIR__+"/../ConvertConcept.lib.js");
convert(selection, getTypeFromFilename());
function getTypeFromFilename() {
return __FILE__.replace(/^.*\//, '').replace(/.ajs$/, '').replace(/%20|\s/g, '-').toLowerCase();
}
load(__DIR__+"/../ConvertConcept.lib.js");
convert(selection, getTypeFromFilename());
function getTypeFromFilename() {
return __FILE__.replace(/^.*\//, '').replace(/.ajs$/, '').replace(/%20|\s/g, '-').toLowerCase();
}
@rchevallier
Copy link

rchevallier commented Jan 7, 2021

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