Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion codegen/emit_ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,14 @@ def generate_appearances(registry: dict[str, Any], output: Path):
" /**",
" * LimeSurvey question theme the appearance selects: `name` goes to the Q row's",
" * `question_theme_name`, each of `attributes` to a column of its own.",
" * `emitOnlyAttributes` are written the same way but do not identify the",
" * appearance on the way back (presentation only).",
" */",
" lsQuestionTheme?: { name: string; attributes?: Record<string, string> };",
" lsQuestionTheme?: {",
" name: string;",
" attributes?: Record<string, string>;",
" emitOnlyAttributes?: Record<string, string>;",
" };",
"}",
"",
"export const APPEARANCES: Record<string, AppearanceSpec> = {",
Expand Down
3 changes: 3 additions & 0 deletions registry/root.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@
"name": "bootstrap_dropdown",
"attributes": {
"show_search": "true"
},
"emitOnlyAttributes": {
"width_entry": "true"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion registry/schema.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@
"consumedBy": [
"ls-transformer"
],
"description": "`{name, attributes?}`: the LimeSurvey question theme this appearance selects, written to the Q row as `question_theme_name` = `name`, plus each of `attributes` (theme attribute → value) as a column of its own; LimeSurvey's TSV import sets the theme from `question_theme_name` and stores the other columns as question attributes. Applies where `validForTypes` allows, together with `lsTypeOverride` if any (autocomplete: `!` + bootstrap_dropdown + show_search=true). The way back writes this appearance for a Q row whose `question_theme_name` and attributes match (and whose type is `lsTypeOverride`, when set); a row with the override but not the theme reads back as the appearance that has the override and no theme (minimal)."
"description": "`{name, attributes?, emitOnlyAttributes?}`: the LimeSurvey question theme this appearance selects, written to the Q row as `question_theme_name` = `name`, plus each of `attributes` (theme attribute → value) as a column of its own; LimeSurvey's TSV import sets the theme from `question_theme_name` and stores the other columns as question attributes. Applies where `validForTypes` allows, together with `lsTypeOverride` if any (autocomplete: `!` + bootstrap_dropdown + show_search=true). `emitOnlyAttributes` are written like `attributes` but are presentational: the way back ignores them, so a TSV without them (made by an earlier version) still reads back as this appearance (autocomplete: width_entry=true, so the closed dropdown is as wide as the selected entry, not the longest option). The way back writes this appearance for a Q row whose `question_theme_name` and `attributes` match (and whose type is `lsTypeOverride`, when set); a row with the override but not the theme reads back as the appearance that has the override and no theme (minimal)."
}
}
},
Expand Down
6 changes: 4 additions & 2 deletions src/conventions/questionTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
* An appearance can select a LimeSurvey question theme (registry Appearance
* `lsQuestionTheme`): `name` goes to the Q row's `question_theme_name`, each
* theme attribute to a column of its own. `autocomplete` → `!` +
* `bootstrap_dropdown` + `show_search=true`, LimeSurvey's searchable dropdown
* (#226). LimeSurvey's TSV import sets the theme from `question_theme_name`
* `bootstrap_dropdown` + `show_search=true` (+ `width_entry=true`), LimeSurvey's
* searchable dropdown (#226). Only `attributes` identify the appearance on the
* way back; `emitOnlyAttributes` (`width_entry`) are presentation, so TSVs
* from before they were emitted still read back. LimeSurvey's TSV import sets the theme from `question_theme_name`
* and stores the other columns as question attributes.
*/
import { APPEARANCES } from '../generated/Appearances.js';
Expand Down
10 changes: 8 additions & 2 deletions src/generated/Appearances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ export interface AppearanceSpec {
/**
* LimeSurvey question theme the appearance selects: `name` goes to the Q row's
* `question_theme_name`, each of `attributes` to a column of its own.
* `emitOnlyAttributes` are written the same way but do not identify the
* appearance on the way back (presentation only).
*/
lsQuestionTheme?: { name: string; attributes?: Record<string, string> };
lsQuestionTheme?: {
name: string;
attributes?: Record<string, string>;
emitOnlyAttributes?: Record<string, string>;
};
}

export const APPEARANCES: Record<string, AppearanceSpec> = {
Expand All @@ -33,7 +39,7 @@ export const APPEARANCES: Record<string, AppearanceSpec> = {
validForTypes: ["select_one", "select_one_from_file"],
lsEffect: "Override LS type from L to ! with LimeSurvey's core question theme bootstrap_dropdown and its show_search attribute: a dropdown the respondent can search by typing",
lsTypeOverride: "!",
lsQuestionTheme: {"name": "bootstrap_dropdown", "attributes": {"show_search": "true"}},
lsQuestionTheme: {"name": "bootstrap_dropdown", "attributes": {"show_search": "true"}, "emitOnlyAttributes": {"width_entry": "true"}},
},
"horizontal": {
supported: true,
Expand Down
6 changes: 4 additions & 2 deletions src/lstsv/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ export const BASE_COLUMNS = [
* - `other_replace_text`: the label of the native "other" answer's text box,
* carrying the XLSForm `<question>_other` companion's label (convention:other).
*
* - `question_theme_name`, `show_search`: the LimeSurvey question theme an
* - `question_theme_name`, `show_search`, `width_entry`: the LimeSurvey question theme an
* appearance selects and that theme's attributes (registry
* `lsQuestionTheme`): `autocomplete` → `bootstrap_dropdown` with
* `show_search=true`, a searchable dropdown. LimeSurvey's import sets the
* `show_search=true`, a searchable dropdown whose closed width follows the
* selected entry (`width_entry=true`), not the longest option. LimeSurvey's import sets the
* theme from `question_theme_name` and stores the other columns as
* question attributes.
*
Expand All @@ -81,6 +82,7 @@ export const ATTRIBUTE_COLUMNS = [
'other_replace_text',
'question_theme_name',
'show_search',
'width_entry',
] as const;

export type BaseColumn = (typeof BASE_COLUMNS)[number];
Expand Down
2 changes: 1 addition & 1 deletion src/pipelines/lstsv2xlsform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CLI: `formtransform lstsv2xlsform <input.tsv>`.
| `cssclass=cdlvocab-<id>` | `select_*_from_file <id>.csv`, inlined A rows dropped | shares `vocabFromCssClass` with the DDI path |
| `mandatory=Y` / `default` | `required: yes` / `default` | direct |
| type override `!` / `T` | `appearance: minimal` / `multiline` | inverts `APPEARANCES[*].lsTypeOverride` — registry-driven, not hardcoded |
| `question_theme_name` (+ theme attributes) | the appearance whose `lsQuestionTheme` matches: `!` + `bootstrap_dropdown` + `show_search=true` → `autocomplete` | inverts `APPEARANCES[*].lsQuestionTheme`; `bootstrap_dropdown` without `show_search=true` stays `minimal` |
| `question_theme_name` (+ theme attributes) | the appearance whose `lsQuestionTheme` matches: `!` + `bootstrap_dropdown` + `show_search=true` → `autocomplete` | inverts `APPEARANCES[*].lsQuestionTheme`; `bootstrap_dropdown` without `show_search=true` stays `minimal`; `emitOnlyAttributes` (`width_entry`) are not checked |
| F + SQ + A | `begin_group appearance=table-list` + child `select_one`s | inverts the grid → F encoding |
| SL welcome/end text | `note` named `welcome` / `end` | inverts note promotion |
| per-language rows | `label::<lang>` / `hint::<lang>` | direct |
Expand Down
1 change: 1 addition & 0 deletions src/pipelines/xlsform2lstsv/appearanceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class AppearanceHandler {
columns = {
[QUESTION_THEME_COLUMN]: theme.name,
...(theme.attributes ?? {}),
...(theme.emitOnlyAttributes ?? {}),
};
}
return columns;
Expand Down
1 change: 1 addition & 0 deletions tests/live/limesurvey/test_lstsv_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def test_long_file_list_dropdown_with_derived_codes(limesurvey_client: Client, t
props = limesurvey_client.get_question_properties(q["qid"], settings=["question_theme_name"])
assert props.get("question_theme_name") == "bootstrap_dropdown", props
assert _attributes(limesurvey_client, q["qid"]).get("show_search") == "true"
assert _attributes(limesurvey_client, q["qid"]).get("width_entry") == "true"
options = limesurvey_client.get_question_properties(q["qid"], settings=["answeroptions"])["answeroptions"]
# Every derived code arrived unchanged (LimeSurvey stores varchar(5)),
# and the mapping gives each one its file code back.
Expand Down
11 changes: 11 additions & 0 deletions tests/ts/unit/questionTheme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('appearance → LimeSurvey question theme (#226)', () => {
expect(q['type/scale']).toBe('!');
expect(q.question_theme_name).toBe('bootstrap_dropdown');
expect(q.show_search).toBe('true');
expect(q.width_entry).toBe('true');
},
);

Expand Down Expand Up @@ -139,6 +140,16 @@ describe('LimeSurvey question theme → appearance (#226)', () => {
expect(out.survey[0]).toMatchObject({ appearance: 'minimal' });
});

test('a 0.11.0 TSV without width_entry still reads back as autocomplete', async () => {
const tsv = withCell(
await toTsv('select_one land', 'autocomplete'),
'width_entry',
'',
);
const out = lstsvToXlsform(tsv, { skipValidation: true });
expect(out.survey[0]).toMatchObject({ appearance: 'autocomplete' });
});

test('show_search stored as 1 still reads back as autocomplete', async () => {
const tsv = withCell(
await toTsv('select_one land', 'autocomplete'),
Expand Down
Loading