flibbles / tw5-relink

Tiddlywiki5 plugin to better update all other tiddlers when renaming a tiddler.
https://flibbles.github.io/tw5-relink/
BSD 3-Clause "New" or "Revised" License
121 stars 6 forks source link

Doubt: Can relink update the fields of current tiddler on renaming(?saving) the tiddler #40

Closed arunnbabu81 closed 2 years ago

arunnbabu81 commented 2 years ago

In a project of mine to create a budget manger based on tiddlytables task manger, there is a button to create new tiddlers based on a template using tm-new-tiddler widget.

Click on the new year + button

This button is based on thetbl-caption field of $:/plugins/aaldrich/budget-manager/year-table

The newly created tiddler based on the template tiddler Year will open in story river. It has a field called debit which has a filter as shown in the image below as content (with filter containing the template tiddler's title Year within the it).

<$list filter=" [year[Year]input_type[debit]get[amount]sum[]]"/>
image

If I save the tiddler as Budget2023, will the field debit also get updated with Budget2023 instead of Year. Can relink do this ??

I made some changes to the configuration tab of relink plug in like this

But the fields were not updated on saving the tiddler as Budget2023

Is there any way it can be made to work

flibbles commented 2 years ago

Relink handles updating the renamed tiddler just fine (unless you're updating the title field itself, in which case Jesus takes the wheel).

The problem you have is that you don't have your "debit" field configured correctly. In the whitelist, you have it set as a "filter", which would be something like [year[Year]input_type[debit]get[amount]sum[]]. But what you have is <$list filter=" [year[Year]input_type[debit]get[amount]sum[]]"/>, which is "wikitext" of a list widget with a filter attribute. Set your "debit" field to wikitext, and it will work.

But you also need to be sure to add "year" as a whitelisted operator of type "title", or else Relink won't know that [year[Year]] is something to update.

Edit: You can open this again if my advice doesn't fix the issue for you.

flibbles commented 2 years ago

Oh wait, now that I think about it. This might not solve it, because the tiddler "Year" isn't being renamed to "Budget2023". You're creating a new tiddler, which TiddlyWiki initially calls "Year 1", and that gets renamed to "Budget2023".

I see that you're using [year<currentTiddler>]. Does that not work for you? If not, you can just use the tm-new-tiddler action to customize those fields. Something like,

\define new-debit(title) <$list filter=" [year[$title$]input_type[debit]get[amount]sum[]]"/>
<$action-sendmessage
    $message="tm-new-tiddler"
    $param="Year"
    title=Budget2023
    debit=<<new-debit Budget2023>> />

Haven't tested this, and it'd need to know the title beforehand, which might not be possible, but I'm sure some variation of this might work.

Still think the [year<currentTiddler>] bit should be enough though.

arunnbabu81 commented 2 years ago

Thank you for all the suggestions. I will test it out and report back.

arunnbabu81 commented 2 years ago

I tried your suggestions. It works but with one condition - first I have to save a dummy tiddler and then rename it. I have uploaded the file here

flibbles commented 2 years ago

Yeah. I figured something like that would happen. Since the new tiddler never existed in the first place, it's not being renamed.

In that case, Relink can't do anything for you unless you do what you just described. I recommend going the [year<currentTiddler>] route. I'm not sure how you're using the debit and credit fields, but wherever you're transcluding them, "currentTiddler" is either defined already, or it should be because that would be the most intuitive. As a user, I'd assume currentTiddler would be defined.

arunnbabu81 commented 2 years ago

I wanted the debit credit fields to be seen in a dynamic table columns. When I was using the [year] , debit and credit columns in the dynamic table were showing 0 as value. That's why started using the current method.

flibbles commented 2 years ago

I checked out your project, and I'm not seeing that. I edited your Budget2022 file's debit field to use <currentTiddler>, and it works fine.

Maybe you thought it wasn't working because you relied solely on the preview? It doesn't work in the preview because there the "currentTiddler" is "Draft of 'Budget2022'", but once you save, it works just fine.

arunnbabu81 commented 2 years ago

I checked out your project, and I'm not seeing that. I edited your Budget2022 file's debit field to use <currentTiddler>, and it works fine.

Maybe you thought it wasn't working because you relied solely on the preview? It doesn't work in the preview because there the "currentTiddler" is "Draft of 'Budget2022'", but once you save, it works just fine.

I tried now also. Value doesn’t get updated in the dynamic table. Yes it does work in the transclusion of the fields I made in the body of the same tiddler. I was wondering why it’s working in one place and not in the other.

I even asked in the talk tiddlywiki forum. But no one replied to it. See this post in that thread.

flibbles commented 2 years ago

I tried looking at the dynamic table stuff. Got as far as $:/plugins/aaldrich/tables. Looks like it's setting each row to <<currentRecord>> instead of using <<currentTiddler>>. Since I'm guessing you don't want to override that plugin, what you'd need to do is have your debit and credit fields use [year<currentRecord>.... And then in the body of your Budget2022 tiddler (and all such tiddlers), define that.

<$vars currentRecord=<<currentTiddler>> >

* Yearly credit= {{!!credit}}
* Yearly debit= {{!!debit}}
* Yearly balance = {{!!balance}}

Then everything works.

arunnbabu81 commented 2 years ago

I tried looking at the dynamic table stuff. Got as far as $:/plugins/aaldrich/tables. Looks like it's setting each row to <<currentRecord>> instead of using <<currentTiddler>>. Since I'm guessing you don't want to override that plugin, what you'd need to do is have your debit and credit fields use [year<currentRecord>.... And then in the body of your Budget2022 tiddler (and all such tiddlers), define that.

<$vars currentRecord=<<currentTiddler>> >

* Yearly credit= {{!!credit}}
* Yearly debit= {{!!debit}}
* Yearly balance = {{!!balance}}

Then everything works.

I think I have modified the tiddlers as you have mentioned, still the values are not coming in the dynamic table. See the zero in debit, credit and balance columns of the year table.

Check here

Did I miss something?

flibbles commented 2 years ago

Yeah. You didn't switch over your debit, credit, and balance fields to use currentRecord. For instance, your budget2020 debit field should be: <$list filter=" [year<currentRecord>input_type[credit]get[amount]sum[]]"/>

arunnbabu81 commented 2 years ago

Now it works. Thank you so much @flibbles for all your help. I would have wasted many more days behind this if I hadn't got your help

flibbles commented 2 years ago

Glad it works. Glad you're enjoying Relink.