Author Topic: jArchi issue  (Read 571 times)

AdGerrits

  • Newbie
  • *
  • Posts: 9
jArchi issue
« on: August 16, 2018, 21:47:01 PM »
Hi Phil, I'm not experienced enough in using javascript/jArchi so great chance it's not a bug but an error on my side.
I've been trying to understand whats going on in this short script but I rest my case...

Why is 'type' not replaced in the first selection as expected ( as  'name' is) just like in the second selection?
btw: I select the goal-element with name '1' before running the code.

$(selection).each(function(e){
   console.log('Before Name=', e.name, '-Type=', e.type);
   e.name = '2';
   e.type = 'principle';
   console.log('After Name=', e.name, '-Type=', e.type);
});
/* output:
Before Name=1-Type=goal
After Name=2-Type=goal  => (huh?)
*/

console.log('------');
$('.2').each(function(e){
   console.log('Before Name=', e.name, '-Type=', e.type);
   e.name = '3';
   e.type = 'principle';
   console.log('After Name=', e.name, '-Type=', e.type);
});
/* output:
Before Name=2-Type=goal
After Name=3-Type=principle  => (as expected)
*/




Phil Beauvoir

  • Administrator
  • Hero Member
  • *****
  • Posts: 1619
  • Code Punk
    • Archi
Re: jArchi issue
« Reply #1 on: August 16, 2018, 21:52:37 PM »
Hi Ad,

it depends on the "selection". If you are selecting visual objects in a diagram then you have to access the underlying ArchiMate concept in order to set its type. So:

$(selection).each(function(e){
   console.log('Before Name=', e.name, '-Type=', e.type);
   e.name = '2';
   e.concept.type = 'principle';
   console.log('After Name=', e.name, '-Type=', e.type);
});

If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

AdGerrits

  • Newbie
  • *
  • Posts: 9
Re: jArchi issue
« Reply #2 on: August 17, 2018, 08:48:47 AM »
Thanks. Difference between visual elements and concepts is much clearer now.
One additional remark: 'API-overview' says "visual objects inherit name, description and properties if they are linked to an underlying ArchiMate concept". But it looks like  "type" is also inherited but read-only (I can display type via 'selected-element.type' but cannot change it).

Phil Beauvoir

  • Administrator
  • Hero Member
  • *****
  • Posts: 1619
  • Code Punk
    • Archi
Re: jArchi issue
« Reply #3 on: August 17, 2018, 10:06:18 AM »
Yes, in the case of a visual object, "type" returns the type of the underlying ArchiMate object as a convenience method (and not something like "diagram-model-archimate-object"). It is the equivalent of:

var type = visualArchiMateObject.concept.type;

is the same as:

var type = visualArchiMateObject.type;

And so setType(type) does not work on a visual object directly because setType() is only a method on an ArchiMate concept type (element or relationship).

To change the underlying type (and this will change all instances of it in all diagrams) then you need to do:

visualObject.concept.type = "node";
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

AdGerrits

  • Newbie
  • *
  • Posts: 9
Re: jArchi issue
« Reply #4 on: August 17, 2018, 10:39:53 AM »
Understood. One last question after experimenting for a while: is there a way to exit a script early? Return doesn't seem to work (and exit() is a bit rough...).

Phil Beauvoir

  • Administrator
  • Hero Member
  • *****
  • Posts: 1619
  • Code Punk
    • Archi
Re: jArchi issue
« Reply #5 on: August 17, 2018, 10:42:25 AM »
You could throw an exception?
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

Jean-Baptiste Sarrodie

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 716
  • Archi Evangelist and Contributor. Visionary.
    • About me...
Re: jArchi issue
« Reply #6 on: August 17, 2018, 19:21:50 PM »
Hi,

It's true that exit is a bit hard (it simply kills Archi itself). We should make it unavailable (see this post).

Instead, we could write a 'buitin' exit function that simply throw an exception...

Regards,

JB
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

Phil Beauvoir

  • Administrator
  • Hero Member
  • *****
  • Posts: 1619
  • Code Punk
    • Archi
Re: jArchi issue
« Reply #7 on: August 17, 2018, 20:03:37 PM »
Done and done.  8)

Next version of jArchi redefines exit() to throw an exception which is caught by jArchi and a nice, polite message is written to the console:

"Exited at line 13 - have a nice day, Ad!"

(OK, maybe not the "have a nice day" bit...)
If you value and use Archi please consider making a donation! https://www.archimatetool.com/donate

AdGerrits

  • Newbie
  • *
  • Posts: 9
Re: jArchi issue
« Reply #8 on: August 24, 2018, 07:58:31 AM »
Nice. Even without the 'have a nice day' part more than satisfied ;)