diff --git a/docs/API_v3.md b/docs/API_v3.md index 645211cfd..7a1272103 100644 --- a/docs/API_v3.md +++ b/docs/API_v3.md @@ -376,7 +376,7 @@ Returns the questions and options of the given form (without submissions). | Parameter | Type | Optional | Description | |-----------|---------|----------|-------------| | _type_ | [QuestionType](DataStructure.md#question-types) | | The question-type of the new question | - | _subtype_ | String | yes | _Optional_ The cell type of a `grid` question, stored as `extraSettings.questionType`: `checkbox`, `number` or `radio`. Any other value is rejected. | + | _subtype_ | String | yes | _Optional_ The sub type, stored as `extraSettings.questionType`: the cell type for `grid` (`checkbox`, `number` or `radio`), `rating` for `linearscale` (a 1 to N scale drawn as icons). Any other value is rejected. | | _text_ | String | yes | _Optional_ The text of the new question. | | _position_ | Integer | yes | _(optional)_ 1-based position to insert the new question. When omitted the question is appended at the end. | - Restrictions: A `grid` question needs its cell type as _subtype_. A _subtype_ for a question type without sub types is rejected with **400 Bad Request**. diff --git a/docs/DataStructure.md b/docs/DataStructure.md index 7d861565d..e84c665ee 100644 --- a/docs/DataStructure.md +++ b/docs/DataStructure.md @@ -263,13 +263,15 @@ Optional extra settings for some [Question Types](#question-types) | `timeMax` | `time` | string | - | Maximum allowed time to be chosen (as `HH:mm` string) | | `timeMin` | `time` | string | - | Minimum allowed time to be chosen (as `HH:mm` string) | | `timeRange` | `time` | Boolean | `true/false` | The time picker should query a time range | -| `optionsLowest` | `linearscale` | Integer | `0, 1` | Set the lowest value of the scale, default: `1` | +| `optionsLowest` | `linearscale` | Integer | `0, 1` | Set the lowest value of the scale, default: `1`; always `1` for the `rating` sub type | | `optionsHighest` | `linearscale` | Integer | `2, 3, 4, 5, 6, 7, 8, 9, 10` | Set the highest value of the scale, default: `5` | -| `optionsLabelLowest` | `linearscale` | string | - | Set the label of the lowest value, default: `'Strongly disagree'` | -| `optionsLabelHighest` | `linearscale` | string | - | Set the label of the highest value, default: `'Strongly agree'` | +| `optionsLabelLowest` | `linearscale` | string | - | Set the label of the lowest value, default: `'Strongly disagree'`; not allowed for the `rating` sub type | +| `optionsLabelHighest` | `linearscale` | string | - | Set the label of the highest value, default: `'Strongly agree'`; not allowed for the `rating` sub type | | `columns` | `grid` | Array | - | Array of column identifiers / labels for grid questions | | `rows` | `grid` | Array | - | Array of row identifiers / labels for grid questions | | `questionType` | `grid` | String | `checkbox`, `number`, `radio` | Type of cell for grid questions (checkbox, numeric input, or radio) | +| `questionType` | `linearscale` | String | `rating` | Sub type, fixed at creation; `rating` is a 1 to N scale drawn as icons; absent for a plain scale | +| `ratingIcon` | `linearscale` with `questionType` `rating` | string | `'star', 'heart', 'thumb'` | Set the icon of the rating, default: `'star'` | ### Option Types diff --git a/lib/Constants.php b/lib/Constants.php index 0766c108a..f74d2f3be 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -118,6 +118,8 @@ class Constants { public const ANSWER_GRID_TYPE_NUMBER = 'number'; public const ANSWER_GRID_TYPE_RADIO = 'radio'; + public const ANSWER_LINEARSCALE_TYPE_RATING = 'rating'; + // Option types public const OPTION_TYPE_CHOICE = 'choice'; public const OPTION_TYPE_ROW = 'row'; @@ -237,6 +239,14 @@ class Constants { 'optionsHighest' => ['integer', 'NULL'], 'optionsLabelLowest' => ['string', 'NULL'], 'optionsLabelHighest' => ['string', 'NULL'], + 'questionType' => ['string'], + 'ratingIcon' => ['string', 'NULL'], + ]; + + public const RATING_ICONS = [ + 'star', + 'heart', + 'thumb', ]; public const EXTRA_SETTINGS_GRID = [ @@ -255,6 +265,10 @@ class Constants { self::ANSWER_GRID_TYPE_RADIO, ]; + public const EXTRA_SETTINGS_LINEARSCALE_QUESTION_TYPE = [ + self::ANSWER_LINEARSCALE_TYPE_RATING, + ]; + /** * !! Keep in sync with src/mixins/ShareTypes.js !! */ diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 4c5258287..de5e3c44f 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -67,7 +67,7 @@ * @psalm-import-type FormsPartialForm from ResponseDefinitions * @psalm-import-type FormsQuestion from ResponseDefinitions * @psalm-import-type FormsQuestionType from ResponseDefinitions - * @psalm-import-type FormsQuestionGridCellType from ResponseDefinitions + * @psalm-import-type FormsQuestionSubtype from ResponseDefinitions * @psalm-import-type FormsSubmission from ResponseDefinitions * @psalm-import-type FormsSubmissions from ResponseDefinitions * @psalm-import-type FormsUploadedFile from ResponseDefinitions @@ -530,7 +530,7 @@ public function getQuestion(int $formId, int $questionId): DataResponse { * * @param int $formId the form id * @param FormsQuestionType $type the new question type - * @param FormsQuestionGridCellType $subtype the new question subtype + * @param FormsQuestionSubtype $subtype the new question subtype * @param string $text the new question title * @param ?int $fromId (optional) id of the question that should be cloned * @param ?int $position (optional) the position of the new question diff --git a/lib/ResponseDefinitions.php b/lib/ResponseDefinitions.php index 17fac6599..c50e12f15 100644 --- a/lib/ResponseDefinitions.php +++ b/lib/ResponseDefinitions.php @@ -35,6 +35,7 @@ * optionsLimitMax?: int, * optionsLimitMin?: int, * optionsLowest?: 0|1, + * ratingIcon?: "star"|"heart"|"thumb", * shuffleOptions?: bool, * timeMax?: string, * timeMin?: string, @@ -45,7 +46,7 @@ * } * * @psalm-type FormsQuestionType = "dropdown"|"multiple"|"multiple_unique"|"date"|"time"|"short"|"long"|"file"|"datetime"|"grid"|"linearscale"|"color"|"ranking" - * @psalm-type FormsQuestionGridCellType = "checkbox"|"number"|"radio" + * @psalm-type FormsQuestionSubtype = "checkbox"|"number"|"radio"|"rating" * * @psalm-type FormsQuestion = array{ * id: int, diff --git a/lib/Service/FormsService.php b/lib/Service/FormsService.php index ea6499414..e6a8d110b 100644 --- a/lib/Service/FormsService.php +++ b/lib/Service/FormsService.php @@ -1051,6 +1051,25 @@ public function areExtraSettingsValid(array $extraSettings, string $questionType || isset($extraSettings['optionsHighest']) && ($extraSettings['optionsHighest'] < 2 || $extraSettings['optionsHighest'] > 10)) { return false; } + + $subtype = $extraSettings['questionType'] ?? null; + if ($subtype !== null && !in_array($subtype, Constants::EXTRA_SETTINGS_LINEARSCALE_QUESTION_TYPE, true)) { + return false; + } + + if ($subtype === Constants::ANSWER_LINEARSCALE_TYPE_RATING && ($extraSettings['optionsLowest'] ?? 1) !== 1) { + return false; + } + + if (isset($extraSettings['ratingIcon']) + && ($subtype !== Constants::ANSWER_LINEARSCALE_TYPE_RATING || !in_array($extraSettings['ratingIcon'], Constants::RATING_ICONS, true))) { + return false; + } + + if ($subtype === Constants::ANSWER_LINEARSCALE_TYPE_RATING + && (isset($extraSettings['optionsLabelLowest']) || isset($extraSettings['optionsLabelHighest']))) { + return false; + } } elseif ($questionType === Constants::ANSWER_TYPE_GRID) { if (isset($extraSettings['questionType']) && !in_array($extraSettings['questionType'], Constants::EXTRA_SETTINGS_GRID_QUESTION_TYPE, true)) { diff --git a/openapi.json b/openapi.json index 45ef51791..19baa5d42 100644 --- a/openapi.json +++ b/openapi.json @@ -575,6 +575,14 @@ 1 ] }, + "ratingIcon": { + "type": "string", + "enum": [ + "star", + "heart", + "thumb" + ] + }, "shuffleOptions": { "type": "boolean" }, @@ -598,12 +606,13 @@ } } }, - "QuestionGridCellType": { + "QuestionSubtype": { "type": "string", "enum": [ "checkbox", "number", - "radio" + "radio", + "rating" ] }, "QuestionType": { @@ -1700,7 +1709,7 @@ "description": "the new question type" }, "subtype": { - "$ref": "#/components/schemas/QuestionGridCellType", + "$ref": "#/components/schemas/QuestionSubtype", "default": null, "description": "the new question subtype" }, diff --git a/playwright/e2e/a11y-question-inputs.spec.ts b/playwright/e2e/a11y-question-inputs.spec.ts index 740058127..a318010ac 100644 --- a/playwright/e2e/a11y-question-inputs.spec.ts +++ b/playwright/e2e/a11y-question-inputs.spec.ts @@ -9,7 +9,11 @@ import { test as appNavigationTest } from '../support/fixtures/navigation.ts' import { test as randomUserTest } from '../support/fixtures/random-user.ts' import { test as topBarTest } from '../support/fixtures/topBar.ts' import { waitForApiResponse } from '../support/helpers.ts' -import { GridSubtype, QuestionType } from '../support/sections/QuestionType.ts' +import { + GridSubtype, + LinearScaleSubtype, + QuestionType, +} from '../support/sections/QuestionType.ts' import { FormsView } from '../support/sections/TopBarSection.ts' const test = mergeTests(randomUserTest, appNavigationTest, formTest, topBarTest) @@ -228,7 +232,7 @@ test.describe('Accessibility: aria attributes on question inputs', () => { await appNavigation.clickNewForm() await form.fillTitle('Test form') - await form.addQuestion(QuestionType.LinearScale) + await form.addQuestion(QuestionType.LinearScale, LinearScaleSubtype.Numbers) const questions = await form.getQuestions() await questions[0].fillTitle('Rate your experience') await questions[0].fillDescription('From 1 to 5') diff --git a/playwright/e2e/question-editing.spec.ts b/playwright/e2e/question-editing.spec.ts index cfa6650ae..28369f7ce 100644 --- a/playwright/e2e/question-editing.spec.ts +++ b/playwright/e2e/question-editing.spec.ts @@ -7,7 +7,10 @@ import { expect, mergeTests } from '@playwright/test' import { test as formTest } from '../support/fixtures/form.ts' import { test as appNavigationTest } from '../support/fixtures/navigation.ts' import { test as randomUserTest } from '../support/fixtures/random-user.ts' -import { QuestionType } from '../support/sections/QuestionType.ts' +import { + LinearScaleSubtype, + QuestionType, +} from '../support/sections/QuestionType.ts' const test = mergeTests(randomUserTest, appNavigationTest, formTest) @@ -32,7 +35,12 @@ test.describe('Question editing lifecycle', () => { for (const type of questionTypes) { test(`Add a ${type} question`, async ({ form }) => { - await form.addQuestion(type) + await form.addQuestion( + type, + type === QuestionType.LinearScale + ? LinearScaleSubtype.Numbers + : undefined, + ) const questions = await form.getQuestions() expect(questions).toHaveLength(1) @@ -91,7 +99,7 @@ test.describe('Question editing lifecycle', () => { form, page, }) => { - await form.addQuestion(QuestionType.LinearScale) + await form.addQuestion(QuestionType.LinearScale, LinearScaleSubtype.Numbers) const question = (await form.getQuestions())[0] await question.openActionsMenu() const highest = page.getByRole('combobox', { name: 'Highest value' }) diff --git a/playwright/e2e/rating-question.spec.ts b/playwright/e2e/rating-question.spec.ts new file mode 100644 index 000000000..62e720204 --- /dev/null +++ b/playwright/e2e/rating-question.spec.ts @@ -0,0 +1,261 @@ +/** + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { expect, mergeTests } from '@playwright/test' +import { test as formTest } from '../support/fixtures/form.ts' +import { test as appNavigationTest } from '../support/fixtures/navigation.ts' +import { test as randomUserTest } from '../support/fixtures/random-user.ts' +import { test as resultsTest } from '../support/fixtures/results.ts' +import { test as submitTest } from '../support/fixtures/submit.ts' +import { test as topBarTest } from '../support/fixtures/topBar.ts' +import { api, waitForApiResponse } from '../support/helpers.ts' +import { + LinearScaleSubtype, + QuestionType, +} from '../support/sections/QuestionType.ts' +import { FormsView } from '../support/sections/TopBarSection.ts' + +const test = mergeTests( + randomUserTest, + appNavigationTest, + formTest, + topBarTest, + submitTest, + resultsTest, +) + +test.describe('Rating question', () => { + test.beforeEach(async ({ page, appNavigation, form }) => { + await page.goto('apps/forms') + await page.waitForURL(/apps\/forms\/?$/) + await appNavigation.clickNewForm() + await form.fillTitle('Rating test form') + + await form.addQuestion(QuestionType.LinearScale, LinearScaleSubtype.Rating) + const questions = await form.getQuestions() + await questions[0].fillTitle('Rate the service') + await questions[0].fillDescription('One star is poor') + }) + + test('Names the rating by its question and each option by its value', async ({ + page, + topBar, + submitView, + }) => { + await expect( + page.getByRole('group', { name: 'Rate the service' }), + ).toBeVisible() + await topBar.toggleView(FormsView.View) + + const group = submitView.getQuestion('Rate the service').getByRole('group') + await expect(group).toHaveAccessibleName('Rate the service') + await expect(group).toHaveAccessibleDescription('One star is poor') + const options = group.getByRole('radio') + await expect(options).toHaveCount(5) + for (let value = 1; value <= 5; value++) { + await expect(options.nth(value - 1)).toHaveAccessibleName(`${value}`) + } + }) + + test('Restores the rating from local storage on reload', async ({ + topBar, + submitView, + page, + }) => { + await topBar.toggleView(FormsView.View) + await submitView.checkRadio('Rate the service', '4') + + await page.reload() + + await expect( + submitView + .getQuestion('Rate the service') + .getByRole('radio', { name: '4', exact: true }), + ).toBeChecked() + }) + + test('Restores the rating when editing a submission', async ({ + topBar, + submitView, + resultsView, + page, + }) => { + await topBar.toggleView(FormsView.View) + await submitView.checkRadio('Rate the service', '4') + await submitView.submit() + await expect(submitView.successMessage).toBeVisible() + + await page.goto(page.url().replace(/\/submit.*$/, '/results')) + await expect(page.getByText('Linear scale (Rating)')).toBeVisible() + await resultsView.switchToResponses() + await resultsView.editSubmission() + + await expect( + submitView + .getQuestion('Rate the service') + .getByRole('radio', { name: '4', exact: true }), + ).toBeChecked() + }) + + test('Shows an error when a required rating is left empty', async ({ + form, + topBar, + submitView, + }) => { + const questions = await form.getQuestions() + await questions[0].toggleRequired() + await topBar.toggleView(FormsView.View) + + await submitView.submitButton.click() + + const question = submitView.getQuestion('Rate the service') + await expect( + question.getByText('You must answer this question'), + ).toBeVisible() + await expect(question.getByRole('radio').first()).toHaveAttribute( + 'aria-invalid', + 'true', + ) + + await submitView.checkRadio('Rate the service', '3') + await expect( + question.getByText('You must answer this question'), + ).toBeHidden() + await expect(question.getByRole('radio').first()).not.toHaveAttribute( + 'aria-invalid', + ) + }) + + test('Moves on to the submit button on Enter instead of submitting', async ({ + topBar, + submitView, + }) => { + await topBar.toggleView(FormsView.View) + await submitView.checkRadio('Rate the service', '5') + await submitView + .getQuestion('Rate the service') + .getByRole('radio', { name: '5', exact: true }) + .press('Enter') + + await expect(submitView.submitButton).toBeFocused() + await expect(submitView.successMessage).toBeHidden() + }) + + test('Focuses a new rating question and offers to insert a question after it', async ({ + form, + page, + }) => { + await form.addQuestion(QuestionType.LinearScale, LinearScaleSubtype.Rating) + + const questions = await form.getQuestions() + await expect(questions[1].titleInput).toBeFocused() + await expect( + page.getByRole('button', { + name: 'Insert question after question 1', + }), + ).toHaveCount(1) + }) + + test('Offers as many options as the highest rating chosen in the editor', async ({ + form, + page, + topBar, + submitView, + }) => { + const questions = await form.getQuestions() + await questions[0].openActionsMenu() + const saved = waitForApiResponse(page, 'PATCH') + await page.getByRole('combobox', { name: 'Highest rating' }).click() + await page.getByRole('option', { name: '7', exact: true }).click() + await saved + await page.keyboard.press('Escape') + await topBar.toggleView(FormsView.View) + + const options = submitView.getQuestion('Rate the service').getByRole('radio') + await expect(options).toHaveCount(7) + await expect(options.last()).toHaveAccessibleName('7') + }) + + test('Saves the icon chosen last in the editor', async ({ form, page }) => { + const questions = await form.getQuestions() + await questions[0].openActionsMenu() + const savedIcon = (icon: string | null) => + page.waitForResponse( + (response) => + response.request().method() === 'PATCH' + && response.request().postDataJSON()?.keyValuePairs + ?.extraSettings?.ratingIcon === icon, + ) + const iconInput = page.getByRole('combobox', { name: 'Icon' }) + + const savedHearts = savedIcon('heart') + await iconInput.click() + await page.getByRole('option', { name: 'Hearts' }).click() + expect((await savedHearts).ok()).toBeTruthy() + const savedStars = savedIcon(null) + await iconInput.click() + await page.getByRole('option', { name: 'Stars' }).click() + expect((await savedStars).ok()).toBeTruthy() + await expect( + page.getByRole('listitem').filter({ has: iconInput }), + ).toContainText('Stars') + }) +}) + +test('The results show the average rating', async ({ page, resultsView }) => { + const created = await api(page.request, 'POST', '/forms') + await api(page.request, 'PATCH', `/forms/${created.id}`, { + keyValuePairs: { submitMultiple: true }, + }) + const rating = await api( + page.request, + 'POST', + `/forms/${created.id}/questions`, + { + type: 'linearscale', + subtype: 'rating', + text: 'Rate the service', + }, + ) + for (const answer of ['5', '4', '4']) { + await api(page.request, 'POST', `/forms/${created.id}/submissions`, { + answers: { [rating.id]: [answer] }, + }) + } + await api(page.request, 'POST', `/forms/${created.id}/submissions`, { + answers: {}, + }) + const ratingUrl = `/forms/${created.id}/questions/${rating.id}` + await api(page.request, 'PATCH', ratingUrl, { + keyValuePairs: { + extraSettings: { questionType: 'rating', optionsHighest: 7 }, + }, + }) + await api(page.request, 'POST', `/forms/${created.id}/submissions`, { + answers: { [rating.id]: ['7'] }, + }) + await api(page.request, 'PATCH', ratingUrl, { + keyValuePairs: { extraSettings: { questionType: 'rating' } }, + }) + await page.goto(`apps/forms/${created.hash}/results`) + await page.waitForURL(/\/results\/summary$/) + + const summary = resultsView.getSummaryForQuestion('Rate the service') + await expect(summary.getByText('4.3 of 5', { exact: true })).toBeVisible() + await expect(summary.getByText('3 ratings', { exact: true })).toBeVisible() + await expect( + summary.getByText('1 rating outside the scale is not counted'), + ).toBeVisible() + await expect( + summary.getByText('Average rating 4.3 of 5, from 3 ratings'), + ).toHaveCount(1) + const bars = summary.getByRole('meter') + await expect(bars).toHaveCount(7) + await expect(bars.nth(0)).toHaveAccessibleName('0 (0%): 1') + await expect(bars.nth(3)).toHaveAccessibleName('2 (40%): 4') + await expect(bars.nth(4)).toHaveAccessibleName('1 (20%): 5') + await expect(bars.nth(5)).toHaveAccessibleName('1 (20%): 7') + await expect(bars.nth(6)).toHaveAccessibleName('1 (20%): No response') +}) diff --git a/playwright/support/sections/FormSection.ts b/playwright/support/sections/FormSection.ts index ab7d3e8d0..b2c3b8a93 100644 --- a/playwright/support/sections/FormSection.ts +++ b/playwright/support/sections/FormSection.ts @@ -4,7 +4,11 @@ */ import type { Locator, Page } from '@playwright/test' -import type { GridSubtype, QuestionType } from './QuestionType.ts' +import type { + GridSubtype, + LinearScaleSubtype, + QuestionType, +} from './QuestionType.ts' import { waitForApiResponse } from '../helpers.ts' import { QuestionSection } from './QuestionSection.ts' @@ -43,7 +47,7 @@ export class FormSection { public async addQuestion( type: QuestionType, - subtype?: GridSubtype, + subtype?: GridSubtype | LinearScaleSubtype, ): Promise { const created = waitForApiResponse(this.page, 'POST') await this.newQuestionButton.click() diff --git a/playwright/support/sections/QuestionType.ts b/playwright/support/sections/QuestionType.ts index 1f51c8f70..5d8a57b74 100644 --- a/playwright/support/sections/QuestionType.ts +++ b/playwright/support/sections/QuestionType.ts @@ -26,3 +26,11 @@ export enum GridSubtype { Number = 'Number', RadioButtons = 'Radio buttons', } + +/** + * Labels of the entries in the linear scale subtype menu. + */ +export enum LinearScaleSubtype { + Numbers = 'Numbers', + Rating = 'Rating', +} diff --git a/src/components/AddQuestionMenu.vue b/src/components/AddQuestionMenu.vue index a2e8c9d2e..3ac6973af 100644 --- a/src/components/AddQuestionMenu.vue +++ b/src/components/AddQuestionMenu.vue @@ -42,18 +42,23 @@ - {{ t('forms', 'Grid') }} + {{ answerTypesFilter[activeQuestionType].label }} + @click=" + onSubtypeClick( + activeQuestionType, + answer.extraSettings.questionType ?? null, + position, + ) + "> @@ -146,7 +151,7 @@ export default defineComponent({ const onSubtypeClick = ( type: string, - subtype: string | number, + subtype: string | null, position: number | null, ) => { emit('addQuestion', type, subtype, position) @@ -174,7 +179,6 @@ export default defineComponent({ onPrimaryClick, onSubtypeClick, backLabel, - t, IconChevronLeft, IconPlus, } diff --git a/src/components/Questions/QuestionLinearScale.vue b/src/components/Questions/QuestionLinearScale.vue index fae0b360c..1deafe8d7 100644 --- a/src/components/Questions/QuestionLinearScale.vue +++ b/src/components/Questions/QuestionLinearScale.vue @@ -13,6 +13,7 @@ v-on="commonListeners"> + + + +
+ +
+import type { RatingIcon } from '../../models/RatingIcons.ts' + import IconPencil from '@material-symbols/svg-400/outlined/edit.svg?raw' import { t } from '@nextcloud/l10n' import { computed, defineComponent, nextTick, onMounted, ref } from 'vue' @@ -156,12 +209,16 @@ import { QUESTION_PROPS, useQuestion, } from '../../composables/useQuestion.ts' +import { LinearScaleType } from '../../models/Constants.ts' +import { getRatingIcon, RATING_ICONS } from '../../models/RatingIcons.ts' type LinearScaleExtraSettings = { optionsLowest?: number | null optionsHighest?: number | null optionsLabelLowest?: string | null optionsLabelHighest?: string | null + questionType?: string + ratingIcon?: string | null } export default defineComponent({ @@ -189,6 +246,23 @@ export default defineComponent({ (props.extraSettings as LinearScaleExtraSettings | undefined) ?? {} ) }) + const isRating = computed( + () => extraSettings.value.questionType === LinearScaleType.Rating, + ) + const ratingIcon = computed(() => + getRatingIcon(extraSettings.value.ratingIcon), + ) + const ratingValue = computed( + () => parseInt(values.value?.[0] ?? '') || 0, + ) + // TRANSLATORS Label of the choice between stars, hearts and thumbs up as the icons of a rating + const ratingIconLabel = t('forms', 'Icon') + const highestLabel = computed(() => + isRating.value + ? // TRANSLATORS Label of the choice of how many icons a rating offers, the highest rating that can be given + t('forms', 'Highest rating') + : t('forms', 'Highest value'), + ) const lowest = ref<{ $refs: { input: HTMLTextAreaElement } } | null>(null) const highest = ref<{ $refs: { input: HTMLTextAreaElement } } | null>(null) @@ -305,7 +379,7 @@ export default defineComponent({ } onMounted(() => { - if (!props.readOnly) { + if (!props.readOnly && !isRating.value) { resizeLabel('lowest') resizeLabel('highest') } @@ -329,6 +403,19 @@ export default defineComponent({ question.errorMessage.value = null } + /** + * The id of a rating icon, the value the icon dropdown stands for + * + * @param icon the rating icon + */ + const ratingIconId = (icon: RatingIcon): RatingIcon['id'] => icon.id + + const onRatingIconChange = (icon: RatingIcon['id']): void => { + question.onExtraSettingsChange({ + ratingIcon: icon === RATING_ICONS[0].id ? null : icon, + }) + } + const onOptionsLowestChange = (value: number): void => { optionsLowest.value = value } @@ -382,6 +469,14 @@ export default defineComponent({ optionsHighest, optionsLabelLowest, optionsLabelHighest, + isRating, + highestLabel, + ratingIcon, + ratingIconLabel, + ratingIconId, + ratingIcons: RATING_ICONS, + ratingValue, + onRatingIconChange, validate, onChange, onOptionsLowestChange, @@ -396,6 +491,64 @@ export default defineComponent({