Last active
September 20, 2024 04:11
-
-
Save jbsarrodie/9bcab008be7f7e75b737e43bfab43048 to your computer and use it in GitHub Desktop.
#jArchi script to add all possible relationships to a view
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
// Find DiagramComponents for a given element in a given view | |
var getDiagramComponents = function(v, e) { | |
return $(v).find("concept").filter(function(o) { | |
return o.concept.id == e.id; | |
}); | |
} | |
// Checks if a view contains a visual connection from src and tgt visual objects | |
var contains = function(r, src, tgt) { | |
found = false; | |
$(r).objectRefs().each(function(o) { | |
if (o.source.id == src.id && o.target.id == tgt.id) { | |
found = true; | |
} | |
}); | |
return found;; | |
} | |
// Iterate through selected views to add relationships which exist in the model but not in the view | |
$(selection).filter("archimate-diagram-model").each(function(v) { | |
$(v).find("element").each(function(e) { | |
$(e.concept).rels().each(function(r) { | |
getDiagramComponents(v,r.source).each(function(src) { | |
getDiagramComponents(v,r.target).each(function(tgt) { | |
if (! contains(r, src, tgt)) { | |
v.add(r, src, tgt); | |
} | |
}); | |
}); | |
}); | |
}); | |
}); |
Hi,
This can happen if you have some notes or visual groups (ie. non ArchiMate concepts). I did fix this some time ago but have never updated this gist, this is now done (one of the first call to "find" now filter on concepts).
Does this fix your issue ?
Works fine now. Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good catch, I'll try to reproduce and update my script.I've just tried and it works as expected: if you have all needed elements (including junctions) then relationships will be added, but if you only have source and target without intermediary junction, then this script will not add them. That might be some additional feature at some point...