How to Add a Folder to the Database?

Started by nordkapp, August 31, 2018, 11:11:01 PM

Previous topic - Next topic

nordkapp

I still use IMatch 5.8 because I have too much scripts running there. This is now my third attempt to learn javascript. this time with some success. So I hope I will use the new version soon (I only really need three of my old vb-scripts the others are nice-to-have).

I copied the sample folders app to create the folders I need for a new photo session. Usually this are 6 to 10 folders. I created the folders successfully via javascript but they don't show up automatically. So I have to do a rescan of nearly the whole Database because the folders lay under different nodes very high up in some hierachies.

Is there a way to tell IMatch that there a new folders and add that folders to the database? In the sample script I didn't find anything.

And can I change the color of that folders via scripting?

Thanks
Ralph


Mario

I understand that you use one of the file-system endpoints exposed by IMatch (IMWS) to create new folders in the file system.
You don't give us much details to work with.

I recommend you use the folders/create endpoint to create a new folder and add it to the database. Or the folders/add endpoint to add an already existing folder to the database.
Just open the IMWS Documentation app and search for folder to find the corresponding endpoint documentation. There is also a sample app which shows how to use these endpoints.

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ubacher

V1/folder/create creates the folder if it does not exist. I use this and it adds it to the db.

nordkapp

I used
                            IMatch.folderCreate({
                                // We can create multiple folder levels at once!
                                path: newFolder
                            }).then(function(response) {
                                result.text(JSON.stringify(response,null,2));
                                data.text('Folder ' + newFolder + ' created successfully.');
                                lastFolder += '\\imatch-demo-root';
                            },

from the sample app "folders"

seems to be the wrong way. I will give the v1/folder/create a try tomorrow and report back.

Mario

The documentation of the method folderCreate of the IMatch wrapper class says:

This method creates one or more folders in the file system.

If you step though your code in the debugger or look at the source code of the method, you see that it uses the

v1/filesystem/folder/create

endpoint. This endpoint creates one or more folder in the file system but does not do anything to the database. It's totally independent and can be used by a script to create folders when needed.
The /filesystem endpoints are all independent from the database.

Use the IMWS endpoints to create folders and add them to your database.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

nordkapp

#5
Thanks for your help Mario and ubacher.

I tried v1/folder/create and it works (mostly) - and it gives me more questions to solve/learn

My first attempt was to stay with folderCreate and put v1/folder/add in the then function after the folder was created in the file system. It works, but it only adds the last child folder to the database which was in my case the name "RAW". So I end up with a lot "RAW" folder names without the also created parent folders. Is there anything I can do so the parent folders are also added to the database?

Then I changed the coding to v1/folder/create and it I got an error: POST http://127.0.0.1:50519/v1/folders/create 400 (Bad Request)

This was because the parent folder exists in the filesystem but NOT in IMatch. After adding the missing parent folder in IMatch all works fine. The subfolders all were successfully created.

Is it a good way to first check if the parent folder exists in the DB via v1/folder and if it does not exists to add it first via v1/folders/add and afterwards use v1/folder/create to create all child folders?

Or can I try something better? Maybe not to create the whole hierarchy in one go instead go folder to folder down and check if it exists in the DB and then create only one folder at a time? (but this is far out of my actual knowledge of javascript)

edit: just thought about it again. The POST error was a fault of my test-app where I hard coded the parent folder name which lays a little bit out of my normal folder hierarchy. So I think I will get my script working tomorrow with v1/folders/create

One question actual remains: for color coding the folder I saw an filed value colorcodesettings under v1/folders. Can I change it to a color I would like to have or is the v1/folders endpoint read only because I have to call it via IMatch.get
If I can change it the I assume I have to do it for each folder in the hierarchy step by step (for which I must improve my javascript skills) or is it actually not changeable via scripting?

Mario

I don't understand your question.

The /create endpoint creates the folder (hierarchy) in the file system and adds the folder to your database.
To include existing folders in your database, use the /add en endpoint. The /add endpoint will not add parent folders of course. Pay attention to the includesubfolders parameter of the /add endpoint. Adding an already existing folder again will do nothing, but will add new sub-folders if this parameter is set.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

nordkapp

thanks for your quick reply. I just edited my post while you were answering, because I think I've made a mistake.

for clarity I post my remaining question here again:

for color coding the folder I saw an filed value colorcodesettings under v1/folders. Can I change it to a color I would like to have or is the v1/folders endpoint read only because I have to call it via IMatch.get
If I can change it the I assume I have to do it for each folder in the hierarchy step by step (for which I must improve my javascript skills) or is it actually not changeable via scripting?

Mario

GET requests never change data.
There is currently no endpoint which allows you to change the color-coding of a folder, or other properties. Please use the corresponding commands in IMatch for this purpose.
Feel free to post a feature request if you want to extend the /add /create endpoints or a new endpoint to change folder properties. So far there was never a need for that and hence it is not implemented.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

nordkapp

Hi Mario,

If I remember right, I've posted a feature request for color coding folder in IMatch 5 and you implemented it. (I only find some of my older posts to this forum, so I am not sure). Actually I use the color coding to mark the workflow state of a session i.e. red is todo green is done and some other colors. Maybe in IMatch 2018 there are other ways to see in what state a session is (?). I will be happy if you implement it in the future but I also can live without this.

My actual priority is to write the three apps I really needed (the one with the folder creation already works) and for all my other scripts I will try to change my workflow to the standard functionality of IMatch.

For my other two scripts I want to replace I used the IMDictionary functionality in vb. Is the an alternative for that in javascript. If so, is it used by some of your apps so I can have a look at?

Thanks
Ralph




Mario

#10
That was implemented in Basic. Now it's 5 years later and IMWS has no such feature. It was never needed and you are probably the only user who needs this.
Add a feature request and I may add this at some later time.

JavaScript has dictionaries. I recommend a JavaScript tutorial of your choice to learn about them.
See the links in the links section in the Developer Center: https://www.photools.com/developer-center/ or just google for JavaScript dictionary to find tons of info.

let myDictionary = {
"apples" : 10,
"banana": 20,
"Sunday": true
}


-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

jch2103

#11
Quote from: nordkapp on September 02, 2018, 07:48:42 PM
Actually I use the color coding to mark the workflow state of a session i.e. red is todo green is done and some other colors. Maybe in IMatch 2018 there are other ways to see in what state a session is (?). I will be happy if you implement it in the future but I also can live without this.

If I understand correctly, you should be able to use data-driven categories to track workflow status (e.g, see sample IMatch Workflow Categories, although you'll likely want to change the specifics). You can easily add color coding to get what you want. I do this for quality control reviews. No Basic required. 
John

Mario

QuoteActually I use the color coding to mark the workflow state of a session i.e. red is todo green is done and some other colors. Maybe in IMatch 2018 there are other ways to see in what state a session is (?). I will be happy if you implement it in the future but I also can live without this.

One of the standard ways to track workflow state are XMP labels. You can use the standard labels or setup your own labels named like "to-do" or "final".
Labels are color-coded and show directly in the file window.
There are automatic collections which group files by their label, which allows you to see all files in the "to-do" state at a glance.

You can use the Edit > Preferences > Indexing options to automatically add a label to files coming new into the database, for example a "review" label.
New files show up in the "Recently Added" collection and then also in the "Review" collection. From there you can review them in the Viewer , reject losers and more keepers into your "to-do" label collection.
After processing you move them to the "final" label. This always allows you to keep track and to see the state of each file in the file window and the collection views.
You can even use the collections in category formulas or data-driven categories if you like.

Another typical workflow is based on the freely usable collections Flag, Pin or Dot to mark files for various states of processing.

In IMatch 2018 you usually don't need to fiddle with custom scripts to do this kind of thing. All this works since IMatch 5.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook