diff --git a/src/cards/NewPollFormCard.ts b/src/cards/NewPollFormCard.ts index 4dc50c1..0561d51 100644 --- a/src/cards/NewPollFormCard.ts +++ b/src/cards/NewPollFormCard.ts @@ -28,6 +28,7 @@ export default class NewPollFormCard extends BaseCard { if (this.config.autoClose) { this.buildAutoCloseSection(); } + this.buildMultipleVoteSection(); } buildTopicInputSection() { @@ -159,6 +160,67 @@ export default class NewPollFormCard extends BaseCard { }); } + buildMultipleVoteSection() { + const widgets: chatV1.Schema$GoogleAppsCardV1Widget[] = []; + + const items = [ + { + 'text': 'No Limit', + 'value': '0', + 'selected': false, + }, + { + 'text': '1', + 'value': '1', + 'selected': false, + }, + { + 'text': '2', + 'value': '2', + 'selected': false, + }, + { + 'text': '3', + 'value': '3', + 'selected': false, + }, + { + 'text': '4', + 'value': '4', + 'selected': false, + }, + { + 'text': '5', + 'value': '5', + 'selected': false, + }, + { + 'text': '6', + 'value': '6', + 'selected': false, + }, + ]; + // set selected item + if (this.config.voteLimit !== undefined && items?.[this.config.voteLimit]) { + items[this.config.voteLimit].selected = true; + } else { + items[1].selected = true; + } + widgets.push( + { + 'selectionInput': { + 'type': 'DROPDOWN', + 'label': 'Vote Limit (Max options that can be voted)', + 'name': 'vote_limit', + items, + }, + }); + + this.card.sections!.push({ + widgets, + }); + } + buildHelpText() { return { textParagraph: { diff --git a/src/helpers/state.ts b/src/helpers/state.ts index 34485b5..a7116a0 100644 --- a/src/helpers/state.ts +++ b/src/helpers/state.ts @@ -57,6 +57,7 @@ export function getConfigFromInput(formValues: PollFormInputs) { state.autoMention = getStringInputValue(formValues.auto_mention) === '1'; state.closedTime = parseInt(formValues.close_schedule_time?.dateTimeInput!.msSinceEpoch ?? '0'); state.choices = getChoicesFromInput(formValues); + state.voteLimit = parseInt(getStringInputValue(formValues.vote_limit) || '1'); return state; } diff --git a/tests/json/configuration_form.json b/tests/json/configuration_form.json index a4d8c1a..b9e2f87 100644 --- a/tests/json/configuration_form.json +++ b/tests/json/configuration_form.json @@ -174,6 +174,54 @@ } } ] + }, + { + "widgets": [ + { + "selectionInput": { + "type": "DROPDOWN", + "label": "Vote Limit (Max options that can be voted)", + "name": "vote_limit", + "items": [ + { + "text": "No Limit", + "value": "0", + "selected": false + }, + { + "text": "1", + "value": "1", + "selected": true + }, + { + "text": "2", + "value": "2", + "selected": false + }, + { + "text": "3", + "value": "3", + "selected": false + }, + { + "text": "4", + "value": "4", + "selected": false + }, + { + "text": "5", + "value": "5", + "selected": false + }, + { + "text": "6", + "value": "6", + "selected": false + } + ] + } + } + ] } ], "fixedFooter": {