This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 42 - Pages: 3 [ Previous | 1 2 3 ] - Last Post: 22 Mar 16, 22:43 Last Post By: drmikey Threads: [ Previous | Next ]
drmikey

Posts: 208
Registered: 22-Dec-2006
Re: A variable for setting a "folderNum" similar to imageNum?
Posted: 27 Jun 15, 06:40   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Thanks! One question I have is why have 2 separate json files? It seems that one file that contains both the tree as well as the associated image data would be more useful and streamlined. By combining them, you would get the folders and subfolders from the tree as well as all the info about the images within each one of those folders all organized in json format. It would make it easier to access that data from the 1 file, and since the tree.son file is less than 1kb,the size of the one file is not an issue. Just a thought.

Edited by: drmikey on 26-Jun-2015 21:41
drmikey

Posts: 208
Registered: 22-Dec-2006
Re: A variable for setting a "folderNum" similar to imageNum?
Posted: 26 Oct 15, 23:24   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Still wondering if there is a way to alter this code or maybe use it in a Skin so it can write all the json data to just one file rather than the 2 separate files it currently is set up to do? The reason I ask this, is, many compilers (an example would be handlebars.js ) are not able to load 2 separate json files to use in a template, only one is possible. Not being able to ustilize the tree.json data in a template is a handicap. Since json files are small, one file would be more efficient as well.
Any help on this would be appreciated!

Mike
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: A variable for setting a "folderNum" similar to imageNum?
Posted: 27 Oct 15, 10:22   in response to: drmikey in response to: drmikey
 
  Click to reply to this thread Reply
drmikey wrote:
Thanks! One question I have is why have 2 separate json files? It seems that one file that contains both the tree as well as the associated image data would be more useful and streamlined. By combining them, you would get the folders and subfolders from the tree as well as all the info about the images within each one of those folders all organized in json format. It would make it easier to access that data from the 1 file, and since the tree.son file is less than 1kb,the size of the one file is not an issue. Just a thought.

Edited by: drmikey on 26-Jun-2015 21:41


Sorry for missing your question. We'll consider making one single json file. The reason for keeping separate files is to avoid too huge json files for huge albums.
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: A variable for setting a "folderNum" similar to imageNum?
Posted: 27 Oct 15, 14:05   in response to: drmikey in response to: drmikey
 
  Click to reply to this thread Reply
drmikey wrote:
Still wondering if there is a way to alter this code or maybe use it in a Skin so it can write all the json data to just one file rather than the 2 separate files it currently is set up to do? The reason I ask this, is, many compilers (an example would be handlebars.js ) are not able to load 2 separate json files to use in a template, only one is possible. Not being able to ustilize the tree.json data in a template is a handicap. Since json files are small, one file would be more efficient as well.
Any help on this would be appreciated!

Mike


This idea was raised by our current German intern too. With such overwhelming request for this idea, I just had to do something about it ;-). The latest jAlbum 13 beta now has a new API to generate a JSON metadata tree to a JavaScript variable. You can then use jQuery to parse it. Here's what you need to do in your skin:
  • Delete data-config.json (not needed anymore)
  • In init.bsh, add the following code
    jm = new JSONMaker(engine);
    dataTree = jm.getTreeAsString(rootFolder);
    

This will generate a full JSON formatted data tree to the variable "dataTree". Now, this variable is only known during album-build time. You therefore need to pass it to a client-side javascript variable. To do so, in your index.htt, add the following:
<script>dataTree = ${dataTree};</script>
Now, just continue referring to javascript code snippets, like this:
<script src="res/js/main.js" type="text/javascript"></script>
. These snippets can now simply refer to the dataTree variable via jQuery for instance.

I hope this new "JSONMaker" API will make it far easier to produce skins.
If you like to have other custom variables added to the generated tree, just call setIncludes() on the JSONMaker and pass a string array of variable names. If you wish to switch off the recursive behavior of the generated tree, i.e. so it only lists objects in the current folder, call setMakeTree(false); prior to calling getTreeAsString().

You can also call getTree() which delivers an object tree that can be manipulated on the Java side (in init.bsh). When you're happy with the manipulation, call toJSONString() on the object returned by getTree().
drmikey

Posts: 208
Registered: 22-Dec-2006
Re: A variable for setting a "folderNum" similar to imageNum?
Posted: 27 Oct 15, 14:50   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Great news! I knew those hordes of json advocates would change your ming.....
I'll check it out but I need a link to the Mac beta version.
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: A variable for setting a "folderNum" similar to imageNum?
Posted: 27 Oct 15, 14:50   in response to: drmikey in response to: drmikey
 
  Click to reply to this thread Reply
drmikey wrote:
Great news! I knew those hordes of json advocates would change your ming.....
I'll check it out but I need a link to the Mac beta version.

Great! It's at http://jalbum.net/download/13b/MacOSX/jAlbum.dmg
drmikey

Posts: 208
Registered: 22-Dec-2006
Re: A variable for setting a "folderNum" similar to imageNum?
Posted: 19 Mar 16, 17:22   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
I am wondering if one can use setIncludes() with the data-config.json method using the JSONMaker API similar to how one can with datatree:

jm = new JSONMaker(engine);
jm.setIncludes(new String[] { "enableCartItem" });
tree = jm.getTree(rootFolder);
dataTree = tree.toJSONString();


Thanks
davidekholm

Posts: 3,442
Registered: 18-Oct-2002
Re: A variable for setting a "folderNum" similar to imageNum?
Posted: 21 Mar 16, 11:52   in response to: drmikey in response to: drmikey
 
  Click to reply to this thread Reply
Yes, just add the "include" property and set an array of strings as value.
drmikey

Posts: 208
Registered: 22-Dec-2006
Re: A variable for setting a "folderNum" similar to imageNum?
Posted: 21 Mar 16, 18:52   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Thanks, but not enough info for me with my lack of knowledge. Could you be able to provide a simple example as to how to add "include" and where? In init.bsh?
Thanks
drmikey

Posts: 208
Registered: 22-Dec-2006
Re: A variable for setting a "folderNum" similar to imageNum?
Posted: 21 Mar 16, 19:20   in response to: drmikey in response to: drmikey
 
  Click to reply to this thread Reply
I figured it out :-). Thanks for the help!
in data-config.json:
{"paging":0, "include":["enableCartItems"]}
drmikey

Posts: 208
Registered: 22-Dec-2006
Re: A variable for setting a "folderNum" similar to imageNum?
Posted: 21 Mar 16, 19:46   in response to: drmikey in response to: drmikey
 
  Click to reply to this thread Reply
Getting value undefined when I reference "object.enableCartItems" yet I can see it in data1.json:
"enableCartItems":false,


It seems any variable I add in this way is undefined when I try to reference it with "object.userVarialbe". They are present in the output file in proper format.

Edited by: drmikey on 21-Mar-2016 13:01
AnCa

Posts: 399
Registered: 25-Mar-2005
Re: A variable for setting a "folderNum" similar to imageNum?
Posted: 22 Mar 16, 10:56   in response to: drmikey in response to: drmikey
 
  Click to reply to this thread Reply
Can you give a more complete example of the json-file and the Javascript that reads it?
drmikey

Posts: 208
Registered: 22-Dec-2006
Re: A variable for setting a "folderNum" similar to imageNum?
Posted: 22 Mar 16, 22:38   in response to: AnCa in response to: AnCa
 
  Click to reply to this thread Reply
I can't explain it, but now it works as it should. Maybe the javascript was being stubborn and needed some time to accept my demands!

Here is the code. I needed it to only write out the shopping cart code if the enableCartItems value in JSON was true. Otherwise I got a shopping cart icon for every image.

 item += (object.enableCartItems == undefined ? "" : "
<a class=\"waves-effect ${waves} modal-trigger\" title=\"Add to Cart\"
 href=\"#shop" + num +  "\"><i class="\"cart_button" ${colorIconFont} fa fa-cart-plus fa-lg pull-left\"></i></a>");


Edited by: drmikey on 22-Mar-2016 14:40
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums