Modify

Opened 14 months ago

Closed 6 weeks ago

Last modified 2 days 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 7 weeks ago.

Download all attachments as: .zip

Change History (21)

comment:1 Changed 14 months ago by Don-vip

Description: modified (diff)

comment:2 Changed 14 months ago by simon04

Component: CoreInternal preset

comment:3 Changed 13 months ago by skyper

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 Changed 13 months ago by simon04

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 Changed 13 months ago by Don-vip

Owner: changed from team to KorneySan
Status: newneedinfo

comment:6 in reply to:  5 ; Changed 12 months ago by KorneySan

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 Changed 12 months ago by simon04

Owner: changed from KorneySan to team
Status: needinfonew

comment:8 Changed 7 weeks ago by simon04

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 7 weeks ago by simon04 (previous) (diff)

comment:9 Changed 7 weeks ago by simon04

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

comment:10 Changed 7 weeks ago by simon04

In 17609/josm:

see #18949 - Extract class TaggingPresetItemGuiSupport

comment:11 Changed 7 weeks ago by simon04

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.

Changed 7 weeks ago by simon04

comment:12 Changed 7 weeks ago by simon04

  • 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 Changed 7 weeks ago by simon04

In 17611/josm:

see #18949 - Add TaggingPresetItemGuiSupportTest

comment:14 Changed 7 weeks ago by simon04

In 17639/josm:

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

comment:15 Changed 6 weeks ago by simon04

Resolution: fixed
Status: assignedclosed

comment:16 Changed 5 days ago by skyper

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?

comment:17 in reply to:  16 ; Changed 5 days ago by 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.

comment:18 in reply to:  17 Changed 4 days ago by skyper

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 days ago by skyper (previous) (diff)

comment:19 Changed 4 days ago by skyper

Still some issues, see #20851.

comment:20 in reply to:  6 Changed 2 days ago by skyper

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.

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.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.