forked from MapComplete/MapComplete
refactoring: slight cleanup of tests
This commit is contained in:
parent
2e9b1016de
commit
f8d34648a0
28 changed files with 252 additions and 353 deletions
|
@ -15,10 +15,19 @@
|
|||
|
||||
let dispatch = createEventDispatcher<{ "selected" }>();
|
||||
</script>
|
||||
<Inline key={config.freeform.key} {tags} template={config.render}>
|
||||
<ValidatedInput {feedback} type={config.freeform.type}
|
||||
{value} on:selected={() => dispatch("selected")}></ValidatedInput>
|
||||
</Inline>
|
||||
|
||||
{#if config.freeform.inline}
|
||||
<Inline key={config.freeform.key} {tags} template={config.render}>
|
||||
<ValidatedInput {feedback} on:selected={() => dispatch("selected")}
|
||||
type={config.freeform.type} {value}></ValidatedInput>
|
||||
</Inline>
|
||||
{:else}
|
||||
<ValidatedInput {feedback} on:selected={() => dispatch("selected")}
|
||||
type={config.freeform.type} {value}></ValidatedInput>
|
||||
|
||||
{/if}
|
||||
|
||||
|
||||
{#if $feedback !== undefined}
|
||||
<div class="alert">
|
||||
<Tr t={$feedback} />
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
let htmlElem: HTMLElement;
|
||||
if (highlightedRendering) {
|
||||
onDestroy(highlightedRendering.addCallbackAndRun(highlighted => {
|
||||
$: onDestroy(highlightedRendering.addCallbackAndRun(highlighted => {
|
||||
console.log("Highlighted rendering is", highlighted)
|
||||
if(htmlElem === undefined){
|
||||
return
|
||||
|
|
|
@ -28,21 +28,12 @@
|
|||
let selectedMapping: number = undefined;
|
||||
let checkedMappings: boolean[];
|
||||
$: {
|
||||
|
||||
if (config.mappings?.length > 0) {
|
||||
if (config.mappings?.length > 0 && (checkedMappings === undefined || checkedMappings?.length < config.mappings.length)) {
|
||||
checkedMappings = [...config.mappings.map(_ => false), false /*One element extra in case a freeform value is added*/];
|
||||
}
|
||||
}
|
||||
$: console.log("Checked mappings:", checkedMappings)
|
||||
let selectedTags: TagsFilter = undefined;
|
||||
$: {
|
||||
try {
|
||||
|
||||
selectedTags = config?.constructChangeSpecification($freeformInput, selectedMapping, checkedMappings);
|
||||
} catch (e) {
|
||||
console.debug("Could not calculate changeSpecification:", e);
|
||||
selectedTags = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function mappingIsHidden(mapping: Mapping): boolean {
|
||||
if (mapping.hideInAnswer === undefined || mapping.hideInAnswer === false) {
|
||||
|
@ -54,6 +45,18 @@
|
|||
return (<TagsFilter>mapping.hideInAnswer).matchesProperties(tags.data);
|
||||
}
|
||||
|
||||
let mappings: Mapping[];
|
||||
$: {
|
||||
mappings = config.mappings?.filter(m => !mappingIsHidden(m));
|
||||
try {
|
||||
selectedTags = config?.constructChangeSpecification($freeformInput, selectedMapping, checkedMappings);
|
||||
} catch (e) {
|
||||
console.debug("Could not calculate changeSpecification:", e);
|
||||
selectedTags = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let dispatch = createEventDispatcher<{
|
||||
"saved": {
|
||||
config: TagRenderingConfig,
|
||||
|
@ -122,15 +125,14 @@
|
|||
</div>
|
||||
{/if}
|
||||
|
||||
{#if config.freeform?.key && !(config.mappings?.length > 0)}
|
||||
{#if config.freeform?.key && !(mappings?.length > 0)}
|
||||
<!-- There are no options to choose from, simply show the input element: fill out the text field -->
|
||||
<FreeformInput {config} {tags} value={freeformInput} />
|
||||
{/if}
|
||||
|
||||
{#if config.mappings !== undefined && !config.multiAnswer}
|
||||
{:else if mappings !== undefined && !config.multiAnswer}
|
||||
<!-- Simple radiobuttons as mapping -->
|
||||
<div class="flex flex-col">
|
||||
{#each config.mappings as mapping, i (mapping.then)}
|
||||
<!-- Even though we have a list of 'mappings' already, we still iterate over the list as to keep the original indices-->
|
||||
{#if !mappingIsHidden(mapping) }
|
||||
<label>
|
||||
<input type="radio" bind:group={selectedMapping} name={"mappings-radio-"+config.id} value={i}>
|
||||
|
@ -147,19 +149,15 @@
|
|||
</label>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
{#if config.mappings !== undefined && config.multiAnswer}
|
||||
{:else if mappings !== undefined && config.multiAnswer}
|
||||
<!-- Multiple answers can be chosen: checkboxes -->
|
||||
<div class="flex flex-col">
|
||||
{#each config.mappings as mapping, i (mapping.then)}
|
||||
{#if !mappingIsHidden(mapping) }
|
||||
{#if !mappingIsHidden(mapping)}
|
||||
<label>
|
||||
<input type="checkbox" name={"mappings-checkbox-"+config.id+"-"+i} bind:checked={checkedMappings[i]}>
|
||||
<TagRenderingMapping {mapping} {tags} {state} {selectedElement}></TagRenderingMapping>
|
||||
</label>
|
||||
{/if}
|
||||
</label>{/if}
|
||||
{/each}
|
||||
{#if config.freeform?.key}
|
||||
<label>
|
||||
|
|
|
@ -83,10 +83,10 @@ export default class SpecialVisualizations {
|
|||
* Note that _normal_ substitutions are ignored.
|
||||
*
|
||||
* // Return empty list on empty input
|
||||
* SubstitutedTranslation.ExtractSpecialComponents("") // => []
|
||||
* SubstitutedTranslation.constructSpecification("") // => []
|
||||
*
|
||||
* // Advanced cases with commas, braces and newlines should be handled without problem
|
||||
* const templates = SubstitutedTranslation.ExtractSpecialComponents("{send_email(&LBRACEemail&RBRACE,Broken bicycle pump,Hello&COMMA\n\nWith this email&COMMA I'd like to inform you that the bicycle pump located at https://mapcomplete.osm.be/cyclofix?lat=&LBRACE_lat&RBRACE&lon=&LBRACE_lon&RBRACE&z=18#&LBRACEid&RBRACE is broken.\n\n Kind regards,Report this bicycle pump as broken)}")
|
||||
* const templates = SubstitutedTranslation.constructSpecification("{send_email(&LBRACEemail&RBRACE,Broken bicycle pump,Hello&COMMA\n\nWith this email&COMMA I'd like to inform you that the bicycle pump located at https://mapcomplete.osm.be/cyclofix?lat=&LBRACE_lat&RBRACE&lon=&LBRACE_lon&RBRACE&z=18#&LBRACEid&RBRACE is broken.\n\n Kind regards,Report this bicycle pump as broken)}")
|
||||
* const templ = templates[0]
|
||||
* templ.special.func.funcName // => "send_email"
|
||||
* templ.special.args[0] = "{email}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue