Archi Forum

Archi Plug-ins => jArchi => Topic started by: Manj75 on December 11, 2019, 15:16:11 PM

Title: JArchi finding a visual note with a property
Post by: Manj75 on December 11, 2019, 15:16:11 PM
Hi,

I have a number of views where I have used a Visual Note concept - these do not have any name property that can be assigned to the concept, however there is a properties tab to define key/value properties.  So I have a Note concept with a property name 'modelName' = 'test'.

What I want to do using JArchi script to to find that Note concept and update the text.

Issue I am having is that I and unable to successfully find the concept using as basic:

$('diagram-model-note').each(function(o) {
  console.log("> concept: " + o.name + " modelName=" + o.prop('modelName') + " [type:" + o.type + "]");
});


This does not even show the log line indicating that it is not even finding diagram-model-note.  To further support this I changed the type to a 'capability', having added the property to one capability concept in my model the same line succeeds and actually shows a log line for each 'capability' found.

$('capability').each(function(o) {
  console.log("> concept: " + o.name + " modelName=" + o.prop('modelName') + " [type:" + o.type + "]");
});


Result:

> concept: Browse and Shop modelName=null [type:capability]
> concept: Mobile/Apps modelName=null [type:capability]
> concept: Search modelName=null [type:capability]
> concept: Image Service modelName=null [type:capability]
> concept: Reviews modelName=null [type:capability]
> concept: Product Information Management modelName=null [type:capability]
> concept: Spreads modelName=null [type:capability]
> concept: My Account modelName=null [type:capability]
> concept: Innovation modelName=null [type:capability]
> concept: Checkout modelName=null [type:capability]
> concept: Platform Modernisation modelName=null [type:capability]
> concept: Payments modelName=null [type:capability]
> concept: Google Tag Manager modelName=null [type:capability]
> concept: CRM modelName=null [type:capability]
> concept: CMS modelName=null [type:capability]
> concept: Ordering modelName=null [type:capability]
> concept: Technical Enablement modelName=test [type:capability]


Is Visual Note and other visual concepts not supported in this way within JArchi or am I doing something wrong?

Appreciate your assistance.

Thanks,
Manjit
Title: Re: JArchi finding a visual note with a property
Post by: Manj75 on December 11, 2019, 15:32:49 PM
Update:

I've created a new empty model and just added a Capability and Visual Note concepts to the Default View, but this time I parse all objects, and it confirms that Visual * elements are not supported - is there any reason for this as this is not stated in the JArchi guide and really should be supported.

$("*").each(function(o) {
  console.log("> concept: " + o.name + " modelName=" + o.prop('modelName') + " [type:" + o.type + "]");
});


Result:

Test Archi Script
Model name: Test
> Found model dashboard property, modelDashboardViewName = Default View
> Number of views in model: 1
> concept: Strategy modelName=null [type:folder]
> concept: Capability modelName=null [type:capability]
> concept: Business modelName=null [type:folder]
> concept: Application modelName=null [type:folder]
> concept: Technology & Physical modelName=null [type:folder]
> concept: Motivation modelName=null [type:folder]
> concept: Implementation & Migration modelName=null [type:folder]
> concept: Other modelName=null [type:folder]
> concept: Relations modelName=null [type:folder]
> concept: Views modelName=null [type:folder]
> concept: Default View modelName=null [type:archimate-diagram-model]
>>
Title: Re: JArchi finding a visual note with a property
Post by: Phil Beauvoir on December 11, 2019, 15:37:22 PM
Visual objects can be found something like this:

$('view').find('diagram-model-note').each(function(note) {
    console.log(note.text);
});


Get all views in the current model and find notes and then print each text.
Title: Re: JArchi finding a visual note with a property
Post by: Manj75 on December 11, 2019, 15:49:46 PM
Fantastic Phil 8)

So, to confirm it seems that 'diagram-model-note' has to be searched within a 'view' collection using find method - is this correct?

It's a shame that it is not consistent in that the wiki guide states that a Selector using type can be used and I'd have thought that $('diagram-model-note') would work.  It would be good to understand the reason why this does not work.

Many thanks for the resolution.

Title: Re: JArchi finding a visual note with a property
Post by: Phil Beauvoir on December 11, 2019, 15:55:32 PM
There's probably a lot of documentation in the wiki that could be improved and re-organised or clarified. But that's why we made it an open wiki for folks to improve it.  :)
Title: Re: JArchi finding a visual note with a property
Post by: Phil Beauvoir on December 11, 2019, 19:46:58 PM
Quote from: Manj75 on December 11, 2019, 15:49:46 PM
Fantastic Phil 8)

So, to confirm it seems that 'diagram-model-note' has to be searched within a 'view' collection using find method - is this correct?

Yep.

QuoteIt would be good to understand the reason why this does not work.

$('selector') works on the current model and valid selectors are "view", "folder" or "concept".
Title: Re: JArchi finding a visual note with a property
Post by: Jean-Baptiste Sarrodie on December 11, 2019, 20:26:28 PM
Hi,

The main goal of the API is to navigate the model tree, thus focusing on real ArchiMate concepts (folders and views are added because they are seen as "containers"). That's why $() function has several guardrails included, and thus why $('*') returns a collection with only ArchiMate related objects, so no visual things like notes.

But... there's a trick ;-)

The model is itself an object that you can work on, so if you create a collection containing the model object (and not the model content), then you can use the API on it... unfiltered:


$(model).find('diagram-model-note').each(function(o) {
  console.log("> concept: " + o.text);
});


Regards,

JB
Title: Re: JArchi finding a visual note with a property
Post by: Phil Beauvoir on December 11, 2019, 20:28:38 PM
Quote from: Jean-Baptiste Sarrodie on December 11, 2019, 20:26:28 PM
But... there's a trick ;-)

The model is itself an object that you can work on, so if you create a collection containing the model object (and not the model content), then you can use the API on it... unfiltered:


$(model).find('diagram-model-note').each(function(o) {
  console.log("> concept: " + o.text);
});


Good grief, that's clever. I didn't know that.  ;)
Title: Re: JArchi finding a visual note with a property
Post by: Jean-Baptiste Sarrodie on December 11, 2019, 20:40:47 PM
Hi,

;D

That's also useful to get toptevel folders: $(model).children('folder.Strategy')

JB
Title: Re: JArchi finding a visual note with a property
Post by: Phil Beauvoir on December 11, 2019, 20:43:32 PM
Quote from: Jean-Baptiste Sarrodie on December 11, 2019, 20:40:47 PM
Hi,

;D

That's also useful to get toptevel folders: $(model).children('folder.Strategy')

JB

We should make jArchi open source then people could add these useful tips to a wiki!  (just kidding ;) )
Title: Re: JArchi finding a visual note with a property
Post by: Manj75 on December 12, 2019, 08:00:25 AM
This is all great stuff and really handy for what I need - a better understanding of how the API works really helps.

To give some context I am creating a Dashboard view for the Architecture department model, which will show model statistics as well as view links, and the primary objective is to incorporate the example Statistics.ajs to populate diagram-model-note boxes that have a property to name it.  I search for the property to identify it and then update the text with statistics, number of archimate elements, relationship and views and model name.

I am slowly but surely moving towards a means to have a scheduled, daily or weekly, generate HTML report and publish and will find out if I hit any other hurdles.  The aim is to have a read-only view of the model accessible to a broader audience in the business.

I have not yet used the Archi CLI, but I intend to use that to write a powershell script that is run on a schedule to:

It would also be good to have Markdown reporting supported, but I notice some people have produced jarchi scripts for this and I'll look into these.

Future improvements that I'm looking at are:

The model becomes much for dynamic rather than just static views.

Another request I posted on the forum was to have jArchi scripts run on startup of Archi, but you are looking the see if this would be popular with the community to implement it.  If this was available it would enable me for example to find a model dashboard view and if one exists have it opened as a landing page for the model.  Will see if this gets put on the roadmap.

Things are progressing very well with the changes I am putting in place and Archi tool is just brilliant for what is needed.

Thanks,

Manjit
Title: Re: JArchi finding a visual note with a property
Post by: Manj75 on December 12, 2019, 09:53:34 AM
Hi Phil/JB,

I've now decided that instead of an ArchiMate View I will create the dashboard as a Canvas, where I can use the canvas-model-block and canvas-model-sticky.  These objects offer more functionality in terms of embedding images, adding hints, etc, than a View diagram-model-note.

However, the issue I now face is that there is nothing documented in the jarchi wiki about how to get/set the attributes of these elements:

Sticky: How to get and set the Content and Notes on the Main tab
Block: How to get and set the Content on the Main tab

If there is a way to do the above that I'm good to complete what I plan to do.

Thanks
Title: Re: JArchi finding a visual note with a property
Post by: Phil Beauvoir on December 12, 2019, 09:59:32 AM
Hi Manjit,

Creating Canvas and Sketch objects is not implemented yet in jArchi. I think you can get them as objects to get bounds, color etc but no getters/setter for text hints image etc.

Phil
Title: Re: JArchi finding a visual note with a property
Post by: Manj75 on December 12, 2019, 10:51:16 AM
I'll revert back to using a View then - thanks for confirming this.