How to get the sources and targets in JsPlumb - javascript

I want to save my workFlow and then load it, For this I have to save all the sources and targets for all connections. Can anyone tell me how can I get all sources and targets against one node.

Thankx buddy but I found a link that is very simple in syntax wise. Also that worked for me.
I'm going to share this for future references...
Can we export a JsPlumb flowchart as a JSON or XML?

For this you need to get all the connections first and then save each connection source and target id in an array. While restoring first you need to create DOM elements with same id's and then use the array to restore connections:
var con=jsPlumb.getAllConnections();
var list=[];
for(var i=0;i<con.length;i++)
{
list[i]=new Array(2);
list[i][0]=con[i].sourceId;
list[i][1]=con[i].targetId;
}
For connecting elements based on id's make use of syntax:
jsPlumb.connect({source:list[1][0], target:list[1][1]});

Related

How do you add multiple documents at once to a collection in Firestore?

I am somewhat new to Firebase and looking for the ability to write multiple JSON objects into a collection under random IDs in one operation. I am just using firestore and auth(not shown) along with react.
So far I have
Function TestDocs () {
{addDoc(collection(db, 'randomData'), {**object 1 example data**},{**object 2 more example data**}
)
}
I have a button on a webpage which adds the data into the DB. When I check Firestore only the first object is loaded and not the second... on top of this, assuming that I wanted to add hundreds of objects(not just 2), how would I go about this?
I was looking through the documentation for Firestore batch writes but it only lists set(), update() and delete() as permitted operations so I am not sure how it would work. Thanks in advance
You'll want to do this in two steps:
Create a reference to a new document with a new unique ID:
// Generate two new document references with a generated ids
const newRef1 = doc(collection(db, "randomData"));
const newRef2 = doc(collection(db, "randomData"));
Write to that reference in your batch or transaction.
Also see:
Firestore - batch.add is not a function (which contains the older namespaced syntax for doing the same).
The last snippet in the documentation on adding a document, which shows this approach.
I found another way to do this without using Firebases batch function. Each transaction or batch of writes can write to a maximum of 500 documents. I was looking to update my app with more than 500 and found a video on YouTube showing another way to do this.
I had to tweak the script a bit to get what I needed but the idea is there.
https://www.youtube.com/watch?v=Qg2_VFFcAI8

Alfresco: Write workflow script to copy document in same folder and continue workflow with new document

For one of my workflows, I want to be able to select a document in my start task. Then, I would like to execute a script to make a copy of this document in the same folder, and continue the workflow with the new document (if this is possible). I don't have much java experience but I'm trying to achieve something along the lines of:
<script>
var path = bpm_package.children[0].displayPath;
var newdoc = bpm_package.children[0].copy(path);
newdoc.save();
bpm_package = newdoc;
</script>
Any help would be greatly appreciated!
Marcus
Basically the argument in copy function is the object of parent node and not a path to parent node.
So the below code will do the work.
bpm_package.children[0].copy(bpm_package.children[0].parent);
You do not need to call save or any other function after that.Basically this are javascript api of alfresco.
You can take a look on below link for more details.
http://docs.alfresco.com/4.1/references/API-JS-Scripting-API.html
Thanks to Krutik for answering the first part of the answer. I'm adding the solution to changing the document in the workflow. This is done by adding and removing documents from the bpm_package property. The whole script is as below:
var newdoc = bpm_package.children[0].copy(bpm_package.children[0].parent);
bpm_package.removeNode(bpm_package.children[0]);
bpm_package.addNode(newdoc);

Need to get ID tags of my page and display them for a Chrome Exstension

I could not find any question similar to mine, so I decided to ask, how do I fetch some pictures from my own website, they all have the id tag post_p.
I assume I have to use:
XMLHttpRequest
But do I fetch the content of my page via the client or via my website? I'm a little clueless here. Help would be greatly appreciated!
to get an element by it's ID do this :
document.getElementById("id");
or as a function with :
var ge = function(id){
return document.getElementById(id);
}
var element1 = ge("element1");
Chrome extensions are run locally (ie client-side) so looking into server-side ways to get the id's is pretty pointless. If you want to get the id's of all images in the DOM, this can be quite easily done like so:
var allIds = [],
allImgs = document.getElementsByTagName('img');//returns a array-like object, referencing all img elements
for (var i=0;i<allImgs.length;i++)
{
allIds.push(allImgs[i].id);
}
If you needn't scan the entire DOM, you can select a particular (block) element in which to look:
var allImgs = document.getElementById('container').getElementsByTagName('img');
//the rest is the same...
Just a personal note: Not sure if getting stuck in with AJAX calls and chrome extensions prior to getting to grips with JS basics is the best of ideas, though... but best of luck all the same

Accessing newly added tracks in iTunes with COM interface

I am trying to add track information to newly added tracks in iTunes using the COM interface and JavaScript. I am able to successfully add files, but am unable to grab them using OperationStatus.Tracks(). I know that OperationStatus.Tracks() is unavailable until after OperationStatus.InProgress() returns false. However, when I try to call InProgress() on what I expect to be an OperationStatus object, I receive the error: "Object doesn't support this property or method."
var iTunesApp = WScript.CreateObject("iTunes.Application");
var status = iTunesApp.LibraryPlaylist.AddFile('newfile.mp4');
WScript.Echo(status.InProgress());
Can anyone shed some light on to what is going wrong here?
I have since been able to answer my own question. I was simply adding empty parens when no parameters were necessary. As such, the methods and properties were not being recognized. The last line mentioned above will work in the following form:WScript.Echo(status.InProgress);To access the tracks that have been recently added can be done using var newtracks = status.Tracks; Then to access properties about an individual track can be done as follows: var newtrack = newtracks.ItemByName('filename');WScript.Echo(newtrack.Name);
Don't forget the result from the AddFile is asynchronous, so you will need to loop and wait before you can access the data.
var results = iTunesApp.AddFile( filepath );
// wait for the result to be available
while( results.InProgress )
Thread.Yield();
foreach( var it in results.Tracks )
{
tune = it as IITFileOrCDTrack;
Console.WriteLine( "Track '{0} - {1}' was added to itunes library", tune.Artist, tune.Name );
}
To get the latest added tracks, i guess you could create a smart playlist, sorted by the added date and access cycle through, this will probably be faster than accessing the whole itunes DB.

How do you clear a tree in ExtJs?

I have managed to create an Ext.tree.TreePanel that loads child nodes dynamically, but I'm having a difficult time clearing the tree and loading it with new data. Can someone help me with the code to do this?
From the wonderful blog of Saki an ExtJS guru.
while (node.firstChild) {
node.removeChild(node.firstChild);
}
http://blog.extjs.eu/know-how/how-to-remove-all-children-of-a-tree-node/
In Ext JS 4:
if you want to reload the data of the tree panel, you need to reload the tree store:
getCmp('treeId').getStore().load();
where treeId is the id of the tree. If you have a store id, you may directly use load() on store id.
to remove all child nodes:
getCmp('treeId').getRootNode().removeAll();
However, removing child nodes is not necessary for reloading the tree nodes from its store.
In my case, my Ext tree has a hidden root node of type AsyncTreeNode. If I want to clear the tree and repopulate from the server, it's pretty simple:
tree.getRootNode().reload();
I finally found an answer in their forums. For anyone interested it is here:
if (tree)
{
var delNode;
while (delNode = tree.root.childNodes[0])
tree.root.removeChild(delNode);
}
you can simply use node.removeAll() to remove all child nodes from this node.
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.NodeInterface-method-removeAll
I ran into a similar problem and the solution i came up with was to 'tag' the node has having not loaded when it was collapsed thus forcing a reload when it was re-expanded.
listeners: {
collapsenode: function(node){
node.loaded = false;
},
if (tree) { var delNode; while (delNode = tree.root.childNodes[0]) tree.root.removeChild(delNode); }
I don't know Ext, but I'm guessing that they have DOM abstraction that might make that easier. An equivalent in Prototype would be something like:
tree.root.immediateDescendants().invoke('remove'); // or
tree.root.select('> *').invoke('remove');
Unless tree.root refers to a collection object rather than the tree's root DOM node, but is borrowing DOM API method names? That seems really unlikely, especially for a modern JS library.

Categories