Modify

Opened 5 years ago

Closed 4 years ago

Last modified 3 years ago

#18949 closed enhancement (fixed)

[TaggingPreset] Make templates available for formatting key values, like for item names

Reported by: KorneySan Owned by: simon04
Priority: normal Milestone: 21.03
Component: Core Version:
Keywords: preset, template_for_key_value, name_template Cc:

Description (last modified by Don-vip)

Proposal is to make formatting by template available for key values like it done for item names.

This is especially usable for public transport routes naming.

In TaggingPresets there is an example for item naming:

<?xml version="1.0" encoding="UTF-8"?>
<presets>
        <item name="Public transportation" type="relation"
                name_template="Bus({operator} {ref} ?{'{from} - {via} - {to}' | '{from} - {to}' | '{from}' | '{to}'})"
                name_template_filter="type=route route=bus">
        </item>
</presets>

which set JOSM to DISPLAY a route relation name by that template. But the same is suitable for the route name by default:

    <text
        key="name"
        text="Name"
        default_template="Bus {ref}?{: '{from} → {to}'}"
        default_template_filter="type=route route=bus">
        />

The value set event should happen for example on route creation dialogue OK button press.

Attachments (1)

Screenshot 2021-03-20 at 23.07.24.png (684.7 KB ) - added by simon04 4 years ago.

Download all attachments as: .zip

Change History (23)

comment:1 by Don-vip, 5 years ago

Description: modified (diff)

comment:2 by simon04, 5 years ago

Component: CoreInternal preset

comment:3 by skyper, 5 years ago

Component: Internal presetCore
Keywords: name_template added

name_template is only defined for <item>, atm. E.g., this is a an enhancement for core.

comment:4 by simon04, 5 years ago

I'm confused: the title says "formatting key values", the description says "formatting by template" (meaning for display purposes?), the description says "value set event" (change something?). Please provide the following details.

Having default_template="Bus {ref}?{: '{from} → {to}'}" in place, when creating a new relation (using the preset dialog only) without providing a name, the template should be evaluated based on the other values (which in turn might trigger a default_template as well??) and the result be set as name?

comment:5 by Don-vip, 5 years ago

Owner: changed from team to KorneySan
Status: newneedinfo

in reply to:  5 ; comment:6 by KorneySan, 5 years ago

Replying to Don-vip:

Having default_template="Bus {ref}?{: '{from} → {to}'}" in place, when creating a new relation (using the preset dialog only) without providing a name, the template should be evaluated based on the other values (which in turn might trigger a default_template as well??) and the result be set as name?

Exactly!
On preset dialog closing by OK button the engine should check the name value and if it is empty AND default_template is set, it should evaluate default_template and set the result to the name.

comment:7 by simon04, 5 years ago

Owner: changed from KorneySan to team
Status: needinfonew

comment:8 by simon04, 4 years ago

Ticket #20049 has been marked as a duplicate of this ticket.

Use case: in a multilingual region we have to fill in the attributes name, name:de, and name:it. name is a string concatenation of name:de and name:it. It would save a lot of keystrokes if name could be calculated from name:de and name:it.

Another use case: osmc:symbol could be calculated from operator and ref.

Last edited 4 years ago by simon04 (previous) (diff)

comment:9 by simon04, 4 years ago

Milestone: 21.03
Owner: changed from team to simon04
Status: newassigned

comment:10 by simon04, 4 years ago

In 17609/josm:

see #18949 - Extract class TaggingPresetItemGuiSupport

comment:11 by simon04, 4 years ago

In 17610/josm:

see #18949 - Tagging presets: value_template="..." for <text>

Use value_template to generate the value automatically based on other <text> values of this preset. For instance, "Bus {ref}: {from} → {to}" can be used to generate the name of a bus route relation.

comment:12 by simon04, 4 years ago

  • resources/data/defaultpresets.xml

    diff --git a/resources/data/defaultpresets.xml b/resources/data/defaultpresets.xml
    index 51be7b0ce..309de2e6b 100644
    a b  
    28342834        </item> <!-- Public Transport Route (Rail) -->
    28352835        <item name="Public Transport Route (Bus)" icon="presets/misc/route.svg" type="relation" preset_name_label="true">
    28362836            <link wiki="Public_transport#Service_routes" />
    28372837            <space />
    28382838            <key key="type" value="route" />
    28392839            <combo key="route" text="Route type" values="bus,share_taxi,trolleybus" values_searchable="true" match="keyvalue!" />
    28402840            <key key="public_transport:version" value="2" /> <!-- only validate marked relations in order to avoid false positives -->
    2841             <reference ref="name_ref" />
     2841            <text key="name" text="Name" value_template="Bus {ref}: {from} → {to}" />
     2842            <text key="ref" text="Reference" />
    28422843            <optional>
    28432844                <reference ref="public_transport_route_optionals" />
    28442845                <combo key="reservation" text="Reservation" values="yes,no,required,recommended" />
    28452846            </optional>
    28462847            <roles>
    28472848                <role key="stop" text="stop position" requisite="optional" type="node" member_expression="public_transport=stop_position (bus=yes OR share_taxi=yes OR trolleybus=yes)" />
    28482849                <role key="stop_exit_only" text="stop position (exit only)" requisite="optional" type="node" member_expression="public_transport=stop_position (bus=yes OR share_taxi=yes OR trolleybus=yes)" />


comment:13 by simon04, 4 years ago

In 17611/josm:

see #18949 - Add TaggingPresetItemGuiSupportTest

comment:14 by simon04, 4 years ago

In 17639/josm:

see #18949 - Tagging presets: trigger value_template="..." from <combo> and <multiselect> changes

comment:15 by simon04, 4 years ago

Resolution: fixed
Status: assignedclosed

comment:16 by skyper, 4 years ago

Thanks for this feature but sadly it does not work that nicely with defaultpresets.

  • We have lots of route relations' presets with a combo for route=*. How can I get the value of route=* with a capital, first letter or even in local language?
  • I often have more than one value for via. How can I split the string at the semicolon and add some chars in between?

in reply to:  16 ; comment:17 by skyper, 4 years ago

Replying to skyper:

  • We have lots of route relations' presets with a combo for route=*. How can I get the value of route=* with a capital, first letter or even in local language?

Tried to solve this with the syntax of name_template="" but it does not work: #20842.

in reply to:  17 comment:18 by skyper, 4 years ago

Replying to skyper:

Replying to skyper:

  • We have lots of route relations' presets with a combo for route=*. How can I get the value of route=* with a capital, first letter or even in local language?

Tried to solve this with the syntax of name_template="" but it does not work: #20842.

Thanks, now it works with r17860.

Replying to simon04:

Documentation: TaggingPresets?action=diff&version=179

As far as I understand it, the syntax of name_template="" is used which means it is not limited to values of <text /> and not even to only the object tags as e.g. parent relations and their tags could be used. Am I right?

Last edited 4 years ago by skyper (previous) (diff)

comment:19 by skyper, 4 years ago

Still some issues, see #20851.

in reply to:  6 comment:20 by skyper, 4 years ago

Replying to KorneySan:

On preset dialog closing by OK button the engine should check the name value and if it is empty AND default_template is set, it should evaluate default_template and set the result to the name.

See #20861.

comment:21 by simon04, 4 years ago

In 17899/josm:

fix #20888, see #18949 - Tagging presets (value_template): fix IllegalStateException: Attempt to mutate in notification

comment:22 by Don-vip, 3 years ago

In 18023/josm:

fix #21117 - see #18949 - avoid infinite loop with presets with several value_template items

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain simon04.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.