Skip to content

Instantly share code, notes, and snippets.

@jbsarrodie
Last active March 8, 2023 14:35
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbsarrodie/9bcab008be7f7e75b737e43bfab43048 to your computer and use it in GitHub Desktop.
Save jbsarrodie/9bcab008be7f7e75b737e43bfab43048 to your computer and use it in GitHub Desktop.
#jArchi script to add all possible relationships to a view
// 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);
}
});
});
});
});
});
@evlibra
Copy link

evlibra commented Aug 21, 2019

Works fine now. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment