APP REQUEST: Attribute Script Calculator *CODED*

Started by Jingo, July 08, 2017, 07:38:42 PM

Previous topic - Next topic

Jingo






Script Name  Description  Requested byDate of RequestProgrammed by  Completed on 
Attribute Script CalculatorScript that will create calculations for event purchase per imageSinus07.07.2017Thrinn


Synopsis from Sinus:

What I would like is a script for Attributes.
Say, we have two Attributes-Sets and some fields:

Address-set global:
Name
Company
City

Calculations-set per file:
Text
Amount
price for each
price for all
plus 8% tax (8% could be hard coded or a flexible field)
total tax
total price

(in reality I have more fields like car-miles, expenses, delivered and so on, but with a sample script I think, I would be able to add more fields)

- The script should display the values of all Attributes-fields.
- If there is no Attribute-entry, it should add one automatically
- Then we should be able to enter some numbers into the fields and the script would calculate the result.

I add a screenshot, but not exactly with these fields, but you see, what I mean (the red rectangles).

This means, for receive the total, the script should calculate

Amount * price for each = price for all
price for all + 8% tax = total tax
price for all + total tax = total price

If I had such an example with these fields, I think (but I am not sure), I could all more fields on my own and do maybe even some more calculations.

I use such a script with many fields more to calculate the prize for a shooting, how many files I delivered, when, number of delivery and so on.
I am sure, it is very bad scripted from me, but it works great since years.  :)

I like it because I can click on an image, push the button and can see all calculations about this event.  :D
All other infos (map, metadata) I have anyway.
For each photosession I have a "Info-master", what holds all this infos in the attributes for an event, and the event is stacked.

Creating this script was hard, but it worked (I tried for example to add the focussed thumb into the window, this I could not do, I was not able, but finally it is not necessary).
And  :-[ I was also not able to do it right with Visual Basic, the calculations does only count, if I closed the window. Then I must open the script a second time and then all correct numbers are there.
But finally it works very good and helps me a lot.

With these attributes fields I create then a real bill with a, well, second script  8) what opens Word and put each Attributes - field in the correct place in Word, but this is another "script-story".

I think, at the moment I am at a loss with JS to create such a script.
To be honest, I do not think, that someone wants write such a script, I could simply not.
But since we have a list here ...  ;D :D

This script is the main-reason, why I cannot change now to IMatch 2017.
And the second reason is a script, what does export theses fields into word for a bill, but this I could solve maybe with export as csv or with another way.


Jingo

#1
Sinus responded to Thrinn:

Quote
Quote from: thrinn on Today at 05:34:11 AM
I assume there should also be a Save button to write the result of the calculation (and all fields that may have changed) back to your Calculation attribute set?

Hi Thorsten
Yes, that would be cool.

QuoteQuote from: thrinn on Today at 05:34:11 AM

    I understand that you have put your customer master data in the global Address attribute set. Now, do you need an Calculation record for an image linked to a specific customer? Because then there should be a reference field customer in your calculation attribute set.


Phew, I see, you are very experienced. I envy you.  8)
Yes, I have a global set for adressess.
Then I have a set for files. In this set is also a reference field for an address-field of the global set (the name).

QuoteQuote from: thrinn on Today at 05:34:11 AM

    And we would have to deal with multiple attribute records per image (including the possibility to select a specific one for display in the App).

In my case I have only one attribute-record for an image.
Hm, I try to explain this at the end of this posting.

QuoteQuote from: thrinn on Today at 05:34:11 AM

    Is there only one Calculation record per image? How do you handle it if you sell an image to more than one customer? Or is the Calculation record somewhat temporary and can be overwritten when you sell the same image twice? Or to different customers?

Yes, there is only one calculation per image. I can (normaly) not sell such an image a second time.
In my case one sell-calculation for one customer would be enough good. Of course, the possibility for more than one sell for more then one customer would be very nice, but in my case it would not be necessary (for photographer with selling to stocks agencys your idea would be of course great).

QuoteQuote from: thrinn on Today at 05:34:11 AM

    If you also want to be able to change your customer master data in an app, there should be two different apps: One for the master data, one for the calculation. This is how regular business software for invoice management handles this usually. But I assume it is enough if the customer master data is only displayed in the calculation. Changing it (or adding customer records) can be done using the standard attribute functionality in IMatch, right?


To be he honest, you do know much more then me. My "idea" putting some calculations into a "info-master-image" came alone from me, I do not know, how regular business software does this handle.

I attache the window, what I have now with VB. But do not be shocked,  :-[  it is not very nice designed and has also too many fields .... bit it works.
And as I pointed out, I guess, if I have one working example with not that many fields, I think, I would be able to add more fields.

I have  made the important fields red.

1) The window, when I the first time let run the script

Number 1: fields (boolean), if this is for billing or already billed
Number 2: The address-fields from the address-set
Number 3: The calculation
Number 4: Textfield
Number 5: Date and number fields

The second attachment, I write now some numbers and text in the calculations-field (and the text-field)
As you can see the Total will not be calculated immadiataly, simply because I was not able to do it in Visual Basic.  :-\ :-[


Attachment 3
Hence I close the window and let run the script a second time.
Now you can see, the calculations are made and these values are written into the attributes.

If I want now change something, I can do it now. Every time. But I have then always to close the script and open again, that the calculations does take in place. Of course it would be better, if I change something, that the calculations would be immediately view able, but it is not that important.

Attachement4
If I close the script, the amount of total (without tax and expenses) are displayed under the image.
And the icon (a thick pencil) shows me, that this image should be billed. (This icon changes, if I change later the boolean of number 1 (first attachment)

On this way I can quickly see, how much money an event (or an image) gives and can see, if it is billed already or not.
And I can change the numbers or text every time, for this I have to let run the script again.

These values are now in the attributes - fields and it is only left to "transferring" these values into an excel or word, but this is another story. And I think, this can be done by an export (csv) or something else.

Thorsten, sorry for the mess here, but I hope, you understand what I mean.
Thanks a lot for thinking about it.

BTW: of course your idea or script could be completely designed in another way, I showed here only, like I have it now and this works fine at least.

thrinn

Hi all,
I have finished a first version of the Attribute Calculator app. At last... Took more effort than I thought. The basic logic was not a problem, but a lot of small things to try. (I am still very much in the trial & error stage of building IMatch Apps).

How does it look?
Have a look at the User interface screenshot.
- Top left I display information about the focused file. At the moment, only thumbnail and filename are displayed. But you can easily add additional fields.
- Top right I display customer information from the global Customer attribute set referenced in the Calculation set. Again, only three fields at the moment, but easy to adapt.
- After that, a table with some input fields follows where you can enter Quantity, Description, and Price. The Total can not be edited but is calculated automatically whenever one of the other fields changes.
- The same goes for Tax (%) where you can enter the tax rate. Tax amount and Grand Total are calculated automatica

How to install
Unzip the archive into your webroot/user directory. This can normally be found at %PROGRAMDATA%\photools.com\imatch6\webroot\user. The App "Attribute Calculator" should automatically appear in the App Wizard (possibly after restarting IMatch).
To make the app work, you need two attribute sets in  your test(!) database, one file based (used to store calculation attributes per file), one global (which holds the customer database).
If you want to get going out of the box, you can import the attached Attribute Calculator Schema.imas. It contains a Calculation schema and a global Customer with some fields.

How does it work?
- Whenever the focused file changes, all attribute data is read from the (newly) focused file and presented in the user interface.
- Some input fields are open to be changed by the user. Others are deactivated because they are calculated automatically. But all of them are written back to the attributes if you click on "Save".
- The "Save" should be self-explanatory.
- The "Cancel" button just rereads the attribute info from the database.

How to adapt to your needs
Presumably your attribute sets are named differently, or you want to include more or other fields. There is no configuration dialog, you have to implement the changes in the app itself. But I put some effort into documenting the places where changes have to be made. For the general structure of this app, there are two files you will need to change accordingly:

  • The index.html contains only the user interface. I used a table-based layout. If you e.g. want to use addtional attributes, you will need to add some rows and / or columns to the table in this file, containing input fields for each of the new attributes.
  • app.js contains the application logic. There is a configuration area at the top, where you can provide the names of the attribute sets, which attributes to use etc. Please read the comments provided in the file to understand what you need to configure.

If you change/add attributes, you will have to also adapt some of the coding. Functions that depend on the attribute settings are commented with USER-SPECIFIC:
- performCalculation calculates Total, Grand Total, Tax amount at the moment.
- displayFileInfo is responsible for the info in the top left corner.
- displayCustomer is responsible for the customer info in the top right corner.
All other functions should work even if you change the attribute settings. (Hopefully....)

Markus, please try it out, and if there are any questions, don't hesitate to ask!
Thorsten
Win 10 / 64, IMatch 2018, IMA

Mario

This looks neat. Cudos.

I wonder how many users will ever have use for that, except for sinus of course  ;)
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

thrinn

Well, yes :)
But I learned a lot on the way which was more important for me than the app itself.
Thorsten
Win 10 / 64, IMatch 2018, IMA

Mario

#5
Quote from: thrinn on July 16, 2017, 08:22:32 PM
Well, yes :)
But I learned a lot on the way which was more important for me than the app itself.
I know.

But I think that this was actually a consulting project (sinus is using this for his business) and I would not have done this for free  ;D  ;)
Probably this app and all its specifics is so unique that it will only ever be used by Markus. Good for him, though.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

sinus

Quote from: thrinn on July 16, 2017, 08:06:55 PM
Hi all,
I have finished a first version of the Attribute Calculator app. At last... Took more effort than I thought. The basic logic was not a problem, but a lot of small things to try. (I am still very much in the trial & error stage of building IMatch Apps).

Hi Thorsten

Before anything else I have to thank you very much!

This is simply very, very cool!
THANKS A LOT!
And it is very good and simple.

Gratuliere Dir echt, suuuuper!

If you are once in the near of Zurich-Basel-Aarau, let it me know, a beer or two or three  8) with a something to eat is yours, for sure! (And Andy is also welcome of course!)
I appreciate your help very much.

Vielen Dank, Thorsten!
Best wishes from Switzerland! :-)
Markus

sinus

#7
Quote from: thrinn on July 16, 2017, 08:06:55 PM

How does it look?
Have a look at the User interface screenshot.
- Top left I display information about the focused file. At the moment, only thumbnail and filename are displayed. But you can easily add additional fields.
- Top right I display customer information from the global Customer attribute set referenced in the Calculation set. Again, only three fields at the moment, but easy to adapt.
- After that, a table with some input fields follows where you can enter Quantity, Description, and Price. The Total can not be edited but is calculated automatically whenever one of the other fields changes.
- The same goes for Tax (%) where you can enter the tax rate. Tax amount and Grand Total are calculated automatica

Markus, please try it out, and if there are any questions, don't hesitate to ask!

As you can see in my screenshots, your app works perfect ... except one question, what I do wrong.

I click on the thumb and then the you app.
First BIG positive suprise:

Even the thumb is there, cool, that you could manage this.
And, if I do some edits, the fields does change immatiately, great. This is a big advantage over my old VB-script. It has much more fields, but to be honest, I have no doubt, that I will be able, to add fields after fields (about 10 or so).

So your script is simply really very nice.
Since we here in Switzerland does not count* with 1 cents (we have only 5 Rappen, 10, 15, 20 and so on), I have to look, that the total is rounded down or up to 5. But I found also for VB some "formula", I am also sure, that I can do that.

So the only small problem is, that the 3 customer fields will not be displayed here like your example.

1) Attachement 1: I did select a thumb, enter some numbers and it works. But I cannot choose the customer in your app, so I change to the Attributes-panel
2) Attachement 2: and choose a customber, But this customer does not display in your app.

But because in your example there is a customer displayed (a company from Köln), I must do something wrong.

Maybe you see my fault. But if not, this is really not that important, Thorsten.
But the chances are here, that you see my error very quickly.
Best wishes from Switzerland! :-)
Markus

sinus

Quote from: Mario on July 16, 2017, 08:30:52 PM
Quote from: thrinn on July 16, 2017, 08:22:32 PM
Well, yes :)
But I learned a lot on the way which was more important for me than the app itself.
I know.

But I think that this was actually a consulting project (sinus is using this for his business) and I would not have done this for free  ;D  ;)
Probably this app and all its specifics is so unique that it will only ever be used by Markus. Good for him, though.

Yes, Mario, I know.
But this is a community and even a very good and helpful one. And there have been and are people out there, who wants simply help without money in mind.
I use this for my business, that is true.

But IMatch is your business and you earn also some money with it (hopefully enough).
And a lot of people did and do help you, and they do it for free. Like Thorsten did.
You have some people who does translate, and as far as I know, for free. And this is also not done in 5 minutes.
People does help you for Alpha- and Betatesting.
And some do write reviews (I did also) for IMatch and spread the world, as you say.

And all these people does not earn some money from you (as far as I know), the do it because they like IMatch, they like you, they becomes also a better IMatch and so the circle does close.

Not at least, people help each other here.
And you helps of course also people, what has problems or questions. Because you have a superiour support.

Hence you should also better thank for Thorsten (what you did in fact with your cudos), instead write, you would not have done this for free.

Thorsten himself, I think and he wrotes also, has for sure also lerned a lot. So I have profited for sure, but he also and in the future other will profites too.
Earlier or later, people will do some stuff with Attributes and Apps, and I am quite sure, then they will see Thorsten scripts and can lern from it.

I could not have done this script at my own. My knowledge is simply far too limited.   :-[ True.
And my knowledge is so limited, that also your Attributes - example, what comes with IMatch, did not help me, because they are for me as a beginner too complicated and not "finnished".
For skilled users your examples are super, I am sure, but for me they are too difficult.

That is why I asked in a thread https://www.photools.com/community/index.php?topic=6840.msg47571#msg47571 for such small, but finnished, easy scripts.
And voila, Thorsten helped me out. He has "only" some example fields like here in this Attributes-app, but because it is for me finnished (the app does read, I can edit, I can store), I am able to work with this app and expand it with the time, step by step.

And after all, back to business, only thanks to Thorsten and Andy, how has also created a lot of effort here on the community (thanks also of course!) I can really switch to IM2017 and have in the mean time bought your IMatch 2017.  ;)

And now I have profited, but I think, I could also help some other people in the last 16 years and I will help, if I can, in the next, well, say 5 years.  ;D




Best wishes from Switzerland! :-)
Markus

thrinn

Quote
1) Attachement 1: I did select a thumb, enter some numbers and it works. But I cannot choose the customer in your app, so I change to the Attributes-panel
2) Attachement 2: and choose a customber, But this customer does not display in your app.
Does it work if you change the focus in the file window to another file and then back to the file in question?
Thorsten
Win 10 / 64, IMatch 2018, IMA

thrinn

OK, I think the app has to listen for some IMWS events regarding attribute changes. At the moment, the User Interface only updates if the focused file changes, not if an attribute value is updated.
I will upload an updated version tomorrow or the day after that.
Thorsten
Win 10 / 64, IMatch 2018, IMA

sinus

Quote from: thrinn on July 17, 2017, 06:45:31 PM
OK, I think the app has to listen for some IMWS events regarding attribute changes. At the moment, the User Interface only updates if the focused file changes, not if an attribute value is updated.
I will upload an updated version tomorrow or the day after that.

No, I tried that, if I change the focus and back, it does not help.

But the idea is this:

1) I can add a new entry (mostly the first one) with your app
2) I can change the numbers
3) to add a customer, I change to the Attribute-panel

Is this correct?
Best wishes from Switzerland! :-)
Markus

thrinn

Hi Markus,
yes, that is how it should work (and it does here). ???

- Did you test it with the attribute schemas I attached or with your own ones?

Could you please try the following:
- In IMatch preferences -> Application -> Developer Options, set the "Remote Debugging Port" to 50520.
- Load the Attribute Calculator App in one of the app panels.
- Start a (external) browser. If you have chrome installed, preferably Chrome (because I know how it looks like), But Firefox or Internet Explorer will also do.
- Enter "http://localhost:50520/" in the browser address line. You will get a (very simple) page with one or more links, one of them "Attribute Calculator" (see screenshot).
- Click the "Attribute Calculator" link. This connects the browser to the Attribute Calculator app. Switch to the Console (maybe already visible e.g. at the bottom of the screen?).
- In IMatch, refresh the app using F5 or change the focus to another file.
- In the browser, check if there any (error) messages in the console.
Thorsten
Win 10 / 64, IMatch 2018, IMA

sinus

Thorsten,

I tried it with your schema, what you have uploaded.

I am going to do what you wrote now.
Best wishes from Switzerland! :-)
Markus

sinus

Quote from: thrinn on July 17, 2017, 09:22:35 PM

Could you please try the following:
- In IMatch preferences -> Application -> Developer Options, set the "Remote Debugging Port" to 50520.
- Load the Attribute Calculator App in one of the app panels.

Päng. Now it works, the customer infos are displayed.  :D

Quote
- Start a (external) browser. If you have chrome installed, preferably Chrome (because I know how it looks like), But Firefox or Internet Explorer will also do.
- Enter "http://localhost:50520/" in the browser address line. You will get a (very simple) page with one or more links, one of them "Attribute Calculator" (see screenshot).
Done. (you have not added the screenshot, but I guess, it is ok, like I did).
see my screenshot, how it looks like.

Quote
- Click the "Attribute Calculator" link. This connects the browser to the Attribute Calculator app. Switch to the Console (maybe already visible e.g. at the bottom of the screen?).
- In IMatch, refresh the app using F5 or change the focus to another file.
- In the browser, check if there any (error) messages in the console.

I have done this, see my attachements.

The "Deferred exception ...." I do not know, if this is important.

Hey, Thorsten, but it works now.
I tried it again:

An image with no entry (Attributes).
Select it.
Use your app, fill with numbers.
Because I have (maybe) changed (sorry, I do not know this anymore) the default value to 0 (in the prefs for CustomerID), there in the app panel the customer with the ID 0 is displayed (Sonnenboy, Bern) attachement 4.

Then I have also changed the Customer in the Attribute panel (CustomerID 1) and did quickly change the focus and back:

And also here: success, the changed customer is also here!
:) :D

Cool, I think you found it!
Maybe I can simply let be thes entry on "Port 50520", or is this in a way unsecure?

You found very quickly a solution, thanks really.



Best wishes from Switzerland! :-)
Markus

thrinn

QuoteThe "Deferred exception ...." I do not know, if this is important.
This happened if the GET attributes call returned no result. A missing check I will add for version 1.1.

I think I will also add the possibility to select the customer directly in the app. But not today ;)

Great that it now works for you, whatever the reason was. I do not think the debugging port poses a security risk as long as IMatch is note exposed to the internet. But you only need it for debugging, so feel free to set it back to 0.
Thorsten
Win 10 / 64, IMatch 2018, IMA

sinus

Quote from: thrinn on July 17, 2017, 10:12:31 PM
QuoteThe "Deferred exception ...." I do not know, if this is important.
This happened if the GET attributes call returned no result. A missing check I will add for version 1.1.

I think I will also add the possibility to select the customer directly in the app. But not today ;)

Great that it now works for you, whatever the reason was. I do not think the debugging port poses a security risk as long as IMatch is note exposed to the internet. But you only need it for debugging, so feel free to set it back to 0.

Thanks, Thorsten, I appreciate your effort really.
Of course it would be great to be able the customer in the app itself. Then the Attribute - panel could be closed totally, what would be of course great (open the Attribute-panel, change the customer, flip back to your app).
If you like doing it, great, if not, does not matter.

I am happy, thanks to  you (my bad English, means "Dank Dir"  8)) I can work to change my workflow using daily IMatch2017, because this app, what you coded.

Best wishes from Switzerland! :-)
Markus

Jingo

Quote from: sinus on July 17, 2017, 06:08:13 PM

If you are once in the near of Zurich-Basel-Aarau, let it me know, a beer or two or three  8) with a something to eat is yours, for sure! (And Andy is also welcome of course!)
I appreciate your help very much.

Vielen Dank, Thorsten!

Thx Markus.. always nice to have a friend in the world!!  You never know when life might put you together... and I'm always glad to help!

Thorsten... amazing app coding... very well done!

sinus

Quote from: Jingo on July 18, 2017, 03:39:26 PM
Quote from: sinus on July 17, 2017, 06:08:13 PM

If you are once in the near of Zurich-Basel-Aarau, let it me know, a beer or two or three  8) with a something to eat is yours, for sure! (And Andy is also welcome of course!)
I appreciate your help very much.

Vielen Dank, Thorsten!

Thx Markus.. always nice to have a friend in the world!!  You never know when life might put you together... and I'm always glad to help!

Thorsten... amazing app coding... very well done!

I agree with all your statements!  :D ... it seems sometimes, that the world is getting smaller.  ;D Must be the "global stuff".
Thanks to you, Andy!
Best wishes from Switzerland! :-)
Markus

thrinn

QuoteOf course it would be great to be able the customer in the app itself.
Good news, Markus: I had some success to implement a drop down list to select the customer directly in the app. Please find the update in the attachement.
The visual appearance may need some overhaul, but at least it works in my tests.

I also added an event listener so that changing an attribute in the attribute panel should trigger an update in the app. But this was before I implemented the Customer Drop Down, where a change of the customer in the attribute panel was necessary.

An additional remark: Mario has announced a small change, how numerical values are interpreted when POSTing attribute (see https://www.photools.com/community/index.php?topic=6908.msg47883#msg47883). As soon as the new update is shipped, I will have to make a small change in my code, too. So there will be a V1.2 of this app in the near future :-)



Thorsten
Win 10 / 64, IMatch 2018, IMA

thrinn

QuoteIf you are once in the near of Zurich-Basel-Aarau, let it me know, a beer or two or three  8) with a something to eat is yours, for sure!
Thank you! I will keep that in mind!  :D

QuoteEven the thumb is there, cool, that you could manage this.
This was easier than I thought because I could steal the code shamelessly from the Sample App File Window. One needs a while to appreciate all that is provided in the sample apps...
Thorsten
Win 10 / 64, IMatch 2018, IMA

sinus

Quote from: thrinn on July 18, 2017, 10:13:04 PM
QuoteOf course it would be great to be able the customer in the app itself.
Good news, Markus: I had some success to implement a drop down list to select the customer directly in the app. Please find the update in the attachement.
The visual appearance may need some overhaul, but at least it works in my tests.

I also added an event listener so that changing an attribute in the attribute panel should trigger an update in the app. But this was before I implemented the Customer Drop Down, where a change of the customer in the attribute panel was necessary.

An additional remark: Mario has announced a small change, how numerical values are interpreted when POSTing attribute (see https://www.photools.com/community/index.php?topic=6908.msg47883#msg47883). As soon as the new update is shipped, I will have to make a small change in my code, too. So there will be a V1.2 of this app in the near future :-)

Super, Thorsten,

that are indeed good news.
I am not at my IMatch-machine, unfortunately, and will try your update tomorrow evening (I have to take pictures tomorrow from 8 pm (uhh) till the evening.

I am curious to try it out!  :D
Best wishes from Switzerland! :-)
Markus

sinus

Quote from: thrinn on July 18, 2017, 10:23:47 PM
QuoteIf you are once in the near of Zurich-Basel-Aarau, let it me know, a beer or two or three  8) with a something to eat is yours, for sure!
Thank you! I will keep that in mind!  :D

Yep, do that, sometimes there are moments... where things or persons are on the right time at the right place.  ;D

QuoteEven the thumb is there, cool, that you could manage this.
This was easier than I thought because I could steal the code shamelessly from the Sample App File Window. One needs a while to appreciate all that is provided in the sample apps...
[/quote]

It looks really cool.
What me impresses most, though the whole app is cool, is the immediately calculations, this is great.  :)
Best wishes from Switzerland! :-)
Markus

sinus

Quote from: thrinn on July 18, 2017, 10:13:04 PM
QuoteOf course it would be great to be able the customer in the app itself.
Good news, Markus: I had some success to implement a drop down list to select the customer directly in the app. Please find the update in the attachement.
The visual appearance may need some overhaul, but at least it works in my tests.

I also added an event listener so that changing an attribute in the attribute panel should trigger an update in the app. But this was before I implemented the Customer Drop Down, where a change of the customer in the attribute panel was necessary.

An additional remark: Mario has announced a small change, how numerical values are interpreted when POSTing attribute (see https://www.photools.com/community/index.php?topic=6908.msg47883#msg47883). As soon as the new update is shipped, I will have to make a small change in my code, too. So there will be a V1.2 of this app in the near future :-)

Hi Thorsten

I could not resist to try it out.  :D
(still 15 minutes before I have to take a lot of pictures the whole day)

I tried your app out.
It works wunderful.

If I do all in your app, it is perfect. What I will do!

One small thing is, I guess, not as it should be.
But for me you must not change this, because I will surely only work with your app, because from my point of view the Attributes-panel is not flexibel enough.

But I think, you like to know it:

If I change things in your app, all works perfect.
If I change later the customer in the Attribute-panel, the adress in your app does correct change, but not the name itself.


You can see this in my attachements.
I choosed in your app "Sonnenboy" as customer, address "Firma X, Bern" was correct.
(Attachement 1)

Then I changed the customer in the Attributes-panel to "Hässig".
And the result in your app is like my second attachement:

The changed adresse (sinus, Aarau) has correct changed in your app, but the customer stays as "Sonnenboy", instead "Hässig".

Means, all does change correct in your app, except the Customer Name.

But Thorsten, as I said, for me you must not change this. Since I will not change the customer change in the Attributes-panel, if I have such a comfortable way like your App.  :)



Best wishes from Switzerland! :-)
Markus

sinus

Thorsten

only say thanks again, specialy because you did write some very good remarks for me in the code.
I am trying! to change your code now (slowly, step by step  :D) to my real attributes, and for this your remarks does help a lot!  :)
Best wishes from Switzerland! :-)
Markus

sinus

#25
And, Thorsten, as you can see in my attachement, I make progress.

I was able to take instead your attribute-fields my own fields and ... it worked!  :D

Really great.
The only thing, what remains, is the customer name, what stays, if I change the image. But the address changes correct. I tried this with port 0 and 50520, what you proposed.

But finally this is not very bad, I know it, and then I can live with that.

In the next step I will try to add one more field from my attributes (no relations, a simple number field).
If that works, I am positive to add some more fields -maybe later even an additional calculation (adding some expenses/Spesen)

It this takes time for me, I guess, I will have several monthes to do all, what my VB-script does now.
But finally this is not important, because I work still with IMatch 5. I hope, that at the end of the year or next year, I am ready to change really to IMatch 2017.

Best wishes from Switzerland! :-)
Markus

thrinn

QuoteI was able to take instead your attribute-fields my own fields and ... it worked!
Glad to hear it!

QuoteThe only thing, what remains, is the customer name, what stays
I think I have found the reason for this: The customer drop down does not reset the selected state of the previous selected entry when I set another entry to selected. Still learning HTML, I am  :-[
It works when I reset the selected state of all entries before selecting a new entry.
Because I expect IM 2017.8.2 to be released in the not-so-far future, I will wait for that before updating the App. I can then also include the small code change for numerical attributes we will need for 2017.8.2.
Thorsten
Win 10 / 64, IMatch 2018, IMA

sinus

QuoteThe only thing, what remains, is the customer name, what stays
I think I have found the reason for this: The customer drop down does not reset the selected state of the previous selected entry when I set another entry to selected. Still learning HTML, I am  :-[
It works when I reset the selected state of all entries before selecting a new entry.
Because I expect IM 2017.8.2 to be released in the not-so-far future, I will wait for that before updating the App. I can then also include the small code change for numerical attributes we will need for 2017.8.2.
[/quote]

Oh, that would be great. Thanks in advance.
I have looked on your code and files, phew, simply overhelming. I could have not create this.
But with your help I am able to do something.  :D

Best wishes from Switzerland! :-)
Markus

thrinn

Ok, here we go: Please find attached a small update of the Attribute Calculator App (V1.2).

  • The Customer Drop Down should now update if you change the focused file
  • Floating point values are POSTed with a decimal point always, as necessary after the last update
  • The Message Box that appears if you change the focuse to a file with multiple attribute records now closes automatically when the focus changes

This version has been tested with the 64bit version of IMatch. Won't go back to 32bit!
Thorsten
Win 10 / 64, IMatch 2018, IMA

Mario

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

sinus

Quote from: thrinn on August 01, 2017, 09:36:12 PM
Ok, here we go: Please find attached a small update of the Attribute Calculator App (V1.2).

  • The Customer Drop Down should now update if you change the focused file
  • Floating point values are POSTed with a decimal point always, as necessary after the last update
  • The Message Box that appears if you change the focuse to a file with multiple attribute records now closes automatically when the focus changes

This version has been tested with the 64bit version of IMatch. Won't go back to 32bit!

Great, Thorsten, thanks a lot!


I have tried your script also with the 64bit-IMatch and it does very well.
It is cool, if I can change something in your script and has immediatly the change in the attribute-panel ... and vice versa.

In the mean time I tried to expand your script with some fields and it worked great!
I was even able to add a calculated field (expenses) and add this to the total.

Now I am optimistic, that I can do some other field too.
And I am glad, that you did not simple lost your time, but you also lerned something about JS!


Best wishes from Switzerland! :-)
Markus

thrinn

QuoteAnd I am glad, that you did not simple lost your time, but you also lerned something about JS!
For learning, this was a reasonably complex app request: Reading and writing of attributes, event handling for on-the-fly calculation of totals, thumbnail display, input fields, drop down...
It helped me a lot to get familiar with all these concepts. Mario delivers a very comprehensive and well documented set of examples, but I always have to try for myself to really understand what is going on.
So, in fact this was a win-win deal.
Thorsten
Win 10 / 64, IMatch 2018, IMA

sinus

Quote from: thrinn on August 02, 2017, 09:41:42 PM
QuoteAnd I am glad, that you did not simple lost your time, but you also lerned something about JS!
For learning, this was a reasonably complex app request: Reading and writing of attributes, event handling for on-the-fly calculation of totals, thumbnail display, input fields, drop down...
It helped me a lot to get familiar with all these concepts. Mario delivers a very comprehensive and well documented set of examples, but I always have to try for myself to really understand what is going on.
So, in fact this was a win-win deal.

Thanks, Thorsten!
Makes me feel better.  :)

I believe you, that is was complex. If I look into the code and all the files, my head does crack from side to side, confusion total.  8)
Have a good day, and do not forget, if you once are here, beer is waiting!  :D

Best wishes from Switzerland! :-)
Markus

sinus

And this addition

    // Just a nice visual effect (from jQuery UI): Flash all fields that have been updated

from you is really very nice!
Best wishes from Switzerland! :-)
Markus

sinus

Thorsten,

the last update (hope not to stress you).
You see at my attachement, that I was able to add some fields inclusive some calculations.
It works all perfect.

I need still add some fields (not more many) and then finally I will try to order the fields better and change maybe some colors in html.
But you can see, your script and your explanations did the job really great:

An almost beginner user is able to "fiddle" a bit with your code and it works. This is what I call "a perfect teacher".  ;D :)
Best wishes from Switzerland! :-)
Markus

sinus

Sorry, Thorsten,

one question arised for me, I think, a last one for this script.

You have specified the set here:

  const ATTR_SET_CALC = 'Calculation';

If I want add some fields from another set (NOT referenced, NO calculations, only Text and boolean fields), how would be the correct name?

I tried simply to add this:
 
  // wäre das zweite Set
  const ATTR_SET_ANMERKUNGEN = 'Anmerkungen';


Then in these lines I added one line from this other set:
const ATTR = {
    DESCR: { attr: 'RgText', id: 'attr_descr' },
    QUANT: { attr: 'Anzahl Einh', id: 'attr_quant', decimals: 2 },
    RG_INFOS: { attr: 'RG-Infos', id: 'attr_rg_infos'}


If I then add this field in the html-file, it works fine.
I can see the field, and I can write into the field.

But the values does not store in the real attributes-fields.

I guess, I think too easy.  :-\

Must I add something to reach this?
Like    
RG_INFOS: { attr: 'Anmerkungen.RG-Infos', id: 'attr_rg_infos'}


If this is too complicated, then I change my attributes and try to "take over" the values of my already created-attributes.


Best wishes from Switzerland! :-)
Markus

thrinn

Hello Markus,
unfortunately, it is not that easy. At the moment, the App coding can only deal with one attribute set (plus one master data set).
If you want to use more than one attribute set changes have to be made at least in the following areas:

  • Reading the attribute values. v1/attributes GET can only retrieve values from one set, so the coding has to be enhanced e.g. to loop over an array of attribute sets to read. If you want to try that, be careful that you have to wait for all GET calls to return before updating the UI.
  • Attribute write back. Same reason as above. In addition, the logic at the moment does not "know" to which attribute set to write. Or more precisely, the attribute set is always the same, specified as a constant. Therefore, part 3:
  • Enhancement of the ATTR configuration object: Somehow the set an attribute belongs to must be specified, e.g. by an additional set property. After all, you could have the same attribute name in two different sets, so the attribute name alone would not be unique any more. And this additional property has to be taken into account at all places where the ATTR object is used.
You see, this would make the App way more complex. It's a general problem: The more flexible an App must be, the more complex the coding becomes. It is doable, but not without rewriting parts of the code.

So, if it is feasible for you to put all information into a single attribute set, I would recommend that approach.
Thorsten
Win 10 / 64, IMatch 2018, IMA

sinus

Quote from: thrinn on August 04, 2017, 11:05:51 AM
So, if it is feasible for you to put all information into a single attribute set, I would recommend that approach.

Thanks, Thorsten

for your detailed answer.
I agree with you, so it is much easier to do like you wrote.

I will add in the attribute-set, used in your script, the fields (about 5), what are in the others.
Then I will "copy" the values in this fields.

For doing this, I think, IMatch offers enough possibilities (filtering the attributes, copy-paste or I do not know now, but I am very sure, that I can do this with IMatch).

So, problem solved and all is fine for me.
To be honest, your script makes a lot of fun, specialy also this "schnell aufleuchten" after some editing of the values. Very nice.  :D

Best wishes from Switzerland! :-)
Markus

sinus

Hi Thorsten

No question
for changing your script or another script!  :D

It would be interesting for me having your opinion, because you made this script here (what works wunderful!), hence I guess, you can decide good, is this possible or not.

With help of your script I can add and edit numbers of the attributes-fields for a file.
At the end I have some attributes-fields, some of them with a calculated value (BTW: nice, that red "no entry-icon")

Because scripting the export into Word, like I do it now with VB/IM5, is not easy possible, I did an export to "Design & Print".
This works very good and will be a replacement of my script, it will create a pdf.

I have only one problem.
If I select more than one file, each file has correct values (made by your script).
But at the end I must have the total values of all selected files (mostly 2-5 files) from one attribute-field.

When I have this total, I can calculate the tax and I would have the final total of all selected files.

For example:
file 1:
total-field: 50.00
tax-field: 4.00
Grand-Total: 54.00

file 2:
total-field: 100.00
tax-field: 8.00
Grand-Total: 108.00

To calculate I must only adding one field, the total-field.
This values would go in a third file, what I could use in D&P.
total-field-all-files: 150.00
calculate 8% tax: 12.00
TOTAL-of-all-files: 162.00

I can do this now by calculate and adding this "by hand".

Hence my question:
Would this be possible with a script or not?
I ask, because if this is not possible, I will think about another possibility to solve my "export-problem".

If yes, I would do this "by hand" (what is in fact not that bad).
And I could try making progress for scripting and one day script this myself.  :D
(at least with edit your script I have lerned already quite a lot).

BTW: export the attribute-fields in D&P is great, I can even add a picture (of the event) in it.



Best wishes from Switzerland! :-)
Markus

thrinn

Hi Markus,
nothing (well, nearly nothing) is impossible with IMatch and scripting. But let's see how one could implement this, just as an idea for now:
If we take your example, you have 2 "source" files with some values and 1 "target" file where the total should be stored, right?
One approach would be: Select all 3 files, but make sure that the "target" file has the focus. This is important because the focus would specify where the "all files" total should be stored.
Then, the script (via a button like "Calculate total over all files") could read the attribute values of all selected files. The v1/attributes endpoint can read from multiple files in one go, so this is no problem. Using IMatch.idlist.fileWindowSelection would do the trick.
The result is an array of all selected files, together with the respective attribute values. Loop over the array, add the values of the attribute fields you are interested in, storing them in local variables. Be careful to skip the focused file (you only want to add file 1 + 2, right?). At the end of the loop, put the sums into the corresponding input fields of the input form (which is linked to the "target").

The advantage is: This could be implemented as an additional button/function of the existing app. No need for a different app or to implement a complex selection logic.
The disadvantage: You would have to be careful when selecting the files, especially which of them has the focus.

Thorsten
Win 10 / 64, IMatch 2018, IMA

sinus

Quote from: thrinn on August 09, 2017, 06:34:15 PM
Hi Markus,
nothing (well, nearly nothing) is impossible with IMatch and scripting. But let's see how one could implement this, just as an idea for now:
If we take your example, you have 2 "source" files with some values and 1 "target" file where the total should be stored, right?

This is correct, Thorsten.
But sometimes I have 2-maximal 10 source files.
With your app, if I have only 1 source file, this is perfect!!! I use your app and use Print & Design. Absolutely perfect!

It is, if you buy 1 apple in a suppermarekt, you get a bill with this apple, tax added and tha's it.
If you buy additionally a bottle of mineral and a cake, you will have also 1 bill, but with the apple, bottle and cake on the same bill and at the end comes the total plus the tax and then the final total.

This is, what I have, sometimes I have to bill one single event (can be a photo or an event like a report-photo), sometimes a client buys 2 or more different photos or events.

To calculate this (adding all total, calculate tax and end with one final-total) I could use a separate file or I could also use one of the selected files.

I use a lot stacks. Say, I made photos of a zoo. I end up with 100 images. 1 image is my "info-master". This means, that I store some infos like phone-numbers, longer text, name of involved persons and so on, not in all images (what would use a lot of memory and surely not necessary), but in this "info-master".
And in this info-master I store also the things for the bill, with your app.

I thought about it, finally, I could simply also add 3 more field in the file-attributes, like
Big-Total of all total of the selected files
Tax of this big-Total
END-Total with tax

Hence I could also store this 3 fields only in this "info-master" (what would be itself also a member of the selected files).
Or, if this is easier, I could really use a third (new) file.

Finally it does not matter, if I think about it, storing it in the "info-master" would be even be better.

(Sorry for the long explanation)

Quote from: thrinn on August 09, 2017, 06:34:15 PM
One approach would be: Select all 3 files, but make sure that the "target" file has the focus. This is important because the focus would specify where the "all files" total should be stored.
Would be no problem.

Quote from: thrinn on August 09, 2017, 06:34:15 PM
Then, the script (via a button like "Calculate total over all files") could read the attribute values of all selected files. The v1/attributes endpoint can read from multiple files in one go, so this is no problem. Using IMatch.idlist.fileWindowSelection would do the trick.
The result is an array of all selected files, together with the respective attribute values. Loop over the array, add the values of the attribute fields you are interested in, storing them in local variables. Be careful to skip the focused file (you only want to add file 1 + 2, right?). At the end of the loop, put the sums into the corresponding input fields of the input form (which is linked to the "target").

The advantage is: This could be implemented as an additional button/function of the existing app. No need for a different app or to implement a complex selection logic.
This sounds great. I will try this, as quick as I have more time, because I must use of course much much more time than you.  :-[

Quote from: thrinn on August 09, 2017, 06:34:15 PM
The disadvantage: You would have to be careful when selecting the files, especially which of them has the focus.
This would be not a problem, really not.

Your question (you only want to add file 1 + 2, right?) I hope explained above. Sometimes it is one single file, then all is perfect.
Sometimes I must calculate 2 files, sometimes 3 ... up to maximal 10 files.

Since you wrote your explanations, I think, this is doable and hence this will be my workflow.

I ask so "stubborn", because your script solved step 1 for me. This was, from my point of view, the most difficult thing and you did this really great!

My 2. step was to export such values into Word. This is not possible easy with scripts, as Andy (I think) pointed out, hence I tried csv- and text-export, but this gave new problems, what I was not able to solve.
Hence I came on the idea using Print & Design for this (what I know quite good) and it turned out, that P&D works very well for this. I end up with a pdf, but thats ok anyway.

But I did not think at this 3. step, where I need to calculate this, when more then 1 file is involved.
And this seems to be doable, hence I will go this way.
Hence, if this problem is solved, I will be ready for changing really to IMatch 2017!   :D
(I work still with IM5)





Best wishes from Switzerland! :-)
Markus

sinus

So, I do start with add a new app, out of the box from Mario via App-Manager.

Then I will read and try
https://www.photools.com/dev-center/doc/imatch/tutorial-recipes.html

Let's look, if I cannot do here something, then I am for sure too silly.  ;D
Best wishes from Switzerland! :-)
Markus

sinus

Quote from: thrinn on August 09, 2017, 06:34:15 PM
Hi Markus,
nothing (well, nearly nothing) is impossible with IMatch and scripting. But let's see how one could implement this, just as an idea for now:
If we take your example, you have 2 "source" files with some values and 1 "target" file where the total should be stored, right?
One approach would be: Select all 3 files, but make sure that the "target" file has the focus. This is important because the focus would specify where the "all files" total should be stored.
Then, the script (via a button like "Calculate total over all files") could read the attribute values of all selected files. The v1/attributes endpoint can read from multiple files in one go, so this is no problem. Using IMatch.idlist.fileWindowSelection would do the trick.
The result is an array of all selected files, together with the respective attribute values. Loop over the array, add the values of the attribute fields you are interested in, storing them in local variables. Be careful to skip the focused file (you only want to add file 1 + 2, right?). At the end of the loop, put the sums into the corresponding input fields of the input form (which is linked to the "target").

The advantage is: This could be implemented as an additional button/function of the existing app. No need for a different app or to implement a complex selection logic.
The disadvantage: You would have to be careful when selecting the files, especially which of them has the focus.

Well, Thorsten
One of the last info-updates!  ;D

I could do with your script almost all, what I wanted.

1) If I have to create one single bill, then all is fine. I can calculate it with your script, and the output I will do with Print & Design.

2) If I have to create a bill with several files (1 up to 10), I have added 3 more attribute-fields:

- END-Calculator (real)
- END-Tax (real)
- END-TOTAL (real)

Then I had only to select some files and in the new field "END-Calculator" there would be a new calculated final sum of the field "Total" of all selected files.
The "END-Tax" does calculate the Tax and the "END-TOTAL" is the addition from the END-Calculator and END-Tax.


So finally only the focused file would hold the values of these 3 fields.

Easy and that does work, well, in theory.  ;D
I tried to do this, also with very good tips from Mario. I made some progress, I could see the output of the different fields of all selected files, like in the attachement 1.

But I was not able to adding this one field (Zw-Total) of all selected files and store the value in the focused files into the "END-Calculator".

I tried the whole weekend without success.  :-[
Sometimes we have to accept some limits.  8)

But I will work in the near future with also a workable solution.
Since I am not able to add all values from one field from maximal 10 files automatically, I will calculate this single field by myself (with an old-fashioned calculator on the table) and write this sum in the field "END-Calculator".


The script will calculate the tax and the END-Total.
See attachement 2.
This is not too bad, because mostly I must calculate only 3-5 files.

So your script works for me, not that elegant liky you would do it. But it works and I can work with it.

Thanks a lot, Thorsten, you helped me really a lot.  :)




Best wishes from Switzerland! :-)
Markus

thrinn

UPDATED VERSION

This update contains an example how to make use of a boolean attribute. Search for "START EXAMPLE: boolean attribute" in index.html and app.js to find what has been added.
For testing, I use a attribute named "testBoolean" in the Calculation attribute set.

Some notes:
To display a boolean attribute, I use a checkbox. In HTML, this is a form input element of type = "checkbox".
<label class="checkbox-inline"><input type="checkbox" id="attr_yesno" oninput="app.recalculate()">a boolean attribute</label>
To display the label on the same line as the checkbox (and not above or beneath), I use the Bootstrap checkbox-inline class.
For index.html, that's all.

In the application logic, there are changes at three places.
First, you have to add the new attribute in the configuration section (ATTR object). Because the logic has to know if it should be displayed as a checkbox, I just added a new property "asCheckbox" to the configuration object. Of course, it would also be possible to check the data type of the attribute, displaying all bool attributes as checkbox, but... keep it simple.

Second, you have to add some code piece to function displayAttributeValues. IMatch returns "0" or "1" for boolean attributes. This must be "translated" to setting the "checked" property of the HTML checkbox to false or true. You can not use val for this, use jQuery prop instead.

Third, when saving the entered values, you have to add some code, basically to "translate" the "checked" state back to "0" or "1". You will find these two lines of coding in function fillTaskData.
Thorsten
Win 10 / 64, IMatch 2018, IMA

sinus

Hi Thorsten

before I check this out, again: THANK YOU!
Great, that you jumped in in the other thread ... I wanted not always ask you.  8)
But you guessed right, I want use this for your script, I forgot to mention at the beginning, that I have also a Boolean-field.
It says simply for me, if the image is billed or not.
And this yes or no I can see also in the thumb layout, what is really cool.

I will now check your update out with your explanations and I am sure, it will work.  :D
Best wishes from Switzerland! :-)
Markus

sinus

Thorsten,

SUCCESS!   :D


Great, thanks for this, it is cool.
I doubt very much, that I would have done this alone.

At first, I thought, it is easy, instead of a number or text I write something like "boolean" or "yes/no" ... but nonsense.

As you pointed out, it is necessary to add some intelligent logic into the code!

You should be a teacher, or are you one?  ;D  Because your explanations are very clear and perfect!
Best wishes from Switzerland! :-)
Markus

Mario

#46
QuoteI doubt very much, that I would have done this alone.

(Almot) nobody can. That's why resources for learning HTML and JavaScript so important.
If you look at the checkbox tutorial on W3Schools, it becomes clear how to add a check box to HTML:

https://www.w3schools.com/html/html_form_input_types.asp

And if you need to check/uncheck from JavaScript, do a quick Google to find:

Setting "checked" for a checkbox with jQuery?

https://stackoverflow.com/questions/426258/setting-checked-for-a-checkbox-with-jquery

That's what I did/do when I don't know how something works. When I use something for the first time. Or have not used something for a long time...
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Jingo

Quote from: Mario on August 16, 2017, 03:14:06 PM
That's why I did/do when I don't know how something works. When I use something for the first time. Or have not used something for a long time...

That's what I do too and its the beauty of working with a widely used and support language like JS.... a pleasure to work with!

sinus

An update (also for me as a reminder  ;D)

In attachement 1 you see the sample app from Mario.
Where several selected files are displayed.

From this sample - app from Mario (File Window) took also Thorsten some stuff, hence I thought, it is a good idea to look here.

At least I could manage (attachement 2) some small success.

The app from Thorsten does work with the focussed file (what is very good).

But because I must have the total sum of several files (2-10) from one attributes-field (the total from one attribute-field of all selected files stored in one attribute field of the focussed file),
I could manage, that the app does read the filenames from all selected files.

For me this is a success.  :D
Sucess from step to step.  :)
Best wishes from Switzerland! :-)
Markus

Mario

How to get all selected files and to iterate over them (e.g., to calculate something) is explained on the Code Recipe Page under the Iterating over All Selected Files headline. You can just copy and paste that example and it will list each file name in the console.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook