maforget / ComicRackCE

A Community Edition for the legendary Comic Book Manager ComicRack. ComicRack is back from the dead.
GNU General Public License v2.0
295 stars 32 forks source link

Custom Fields in Virtual Tags? #93

Closed SenorSmartyPants closed 1 month ago

SenorSmartyPants commented 1 month ago

Describe the bug Can I use custom fields in virtual tags? I don't see the actual custom fields in the field DDL, but there is CustomValuesStore. If this is possible the syntax isn't documented

I have a "Event Year" field that I use to set the year for comics in an event that spans into the next year. (setting the "Event Year" to 2016 for a volume that started in 2017, but the event started in 2016)

I would like to make a virtual tag that uses "Event Year" if present, otherwise it uses Volume.

Version/Commit (check the about page, next to the version, for the string between brackets):

Additional context Add any other context about the problem here.

maforget commented 1 month ago

The list of values comes from the smart list insert value dropdown, it is auto-populated. I have no idea if the value CustomValuesStore is even useful in the smart list or Virtual Tags. The Virtual Tags right now uses the code that is used to format Caption, so any syntax may have been documented at one time. The best place to check right now is to read the Changes.txt.

I've had a look at the code and there is a way to have custom values be shown, not certain if it is intended or a hack. This method will work with the Caption setting, since it uses it's code.

You will need to modify the tags code manually. You only need to double the curly brackets and type the custom field name inside it. So instead of [ prefix { field } suffix ] it's [ prefix {{ customfield }} suffix ]. (spaces added for clarity).

Example:

[{{comicvine_volume}}][ - {{comicvine_issue}}]

I've updated the Wiki page to add this information.

Please keep in mind that if the resulting value are all empty, you will have some pretty big slowdown. It doesn't seem to happen if at least 1 in the page has a value. I will have to hunt for that bug.

SenorSmartyPants commented 1 month ago

Thank you. That got the custom value showing up.

Since there is no function support in VTags yet, I assume there is no way to suppress the output of a field based on the existence of a different field? Or output only if condition is true (not exists field)?

[{{Event Year}}][{volumeonly(!{{Event Year}})}]

Library organizer has a syntax like this: {{<volume0>}<?Custom(Event Year)(!^$)>}{{<Custom(Event Year)>}<!Custom(Event Year)(!^$)>}

maforget commented 1 month ago

I don't think there is a good solution for now. You can add a field inside either the prefix and suffix and it will appear even if the main field is empty. But both field will be shown if there is a value.

It seems that when you have square brackets inside the prefix or suffix, everything inside it will appear even if the main value is empty.

So for now your best bet might be to use Data Manager, but I get that's not the best solution. It is why I wanted Virtual Tags in the first place.

maforget commented 1 month ago

I've added some basic functions. But there is no UI to set it, it must be done manually for now. I've added all the documentation to the wiki.

I will probably add more functions as I think about them. Or if there is some requests.

SenorSmartyPants commented 1 month ago

Thanks! This works great for my problem.

Here's my example solution. Test if custom field is empty, displays volume number if it is, otherwise overrides with custom field

[$if<"{{Event Year}}".Length == 0, {volumeonly}, {{Event Year}}>]

maforget commented 1 month ago

You could also just have done [$if<"{{Event Year}}" == "", {volumeonly}, {{Event Year}}>]

Using the string.IsNullOrEmpty function is better. This checks if a string is empty or null, but in this case there shouldn't be a null, always empty. But you never know. [$if<string.IsNullOrEmpty("{{Event Year}}"), {volumeonly}, {{Event Year}}>]