Skip to content

Commit

Permalink
Merge pull request #12692 from germanocaumo/qp-maxcustom-23
Browse files Browse the repository at this point in the history
fix(poll): Respect maxCustom property in quick-polls
  • Loading branch information
antobinary committed Jun 30, 2021
2 parents 4a1e43c + bd29d15 commit a53917e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import DropdownList from '/imports/ui/components/dropdown/list/component';
import DropdownListItem from '/imports/ui/components/dropdown/list/item/component';
import { styles } from '../styles';

const POLL_SETTINGS = Meteor.settings.public.poll;
const MAX_CUSTOM_FIELDS = POLL_SETTINGS.maxCustom;

const intlMessages = defineMessages({
quickPollLabel: {
id: 'app.poll.quickPollTitle',
Expand Down Expand Up @@ -47,14 +50,24 @@ const getAvailableQuickPolls = (slideId, parsedSlides, startPoll, pollTypes) =>
const pollItemElements = parsedSlides.map((poll) => {
let { poll: label, type } = poll;
let itemLabel = label;
let answers = null;
let letterAnswers = [];

if (type !== pollTypes.YesNo &&
type !== pollTypes.YesNoAbstention &&
type !== pollTypes.TrueFalse)
{
const { options } = itemLabel;
itemLabel = options.join('/').replace(/[\n.)]/g, '');
if (type === pollTypes.Custom) {
for (const option of options) {
const letterOption = option.replace(/[\r.)]/g, '');
if (letterAnswers.length < MAX_CUSTOM_FIELDS) {
letterAnswers.push(letterOption);
} else {
break;
}
}
}
}

// removes any whitespace from the label
Expand All @@ -72,7 +85,8 @@ const getAvailableQuickPolls = (slideId, parsedSlides, startPoll, pollTypes) =>
<DropdownListItem
label={itemLabel}
key={_.uniqueId('quick-poll-item')}
onClick={() => startPoll(type, slideId, answers)}
onClick={() => startPoll(type, slideId, letterAnswers)}
answers={letterAnswers}
/>
);
});
Expand Down Expand Up @@ -112,14 +126,15 @@ class QuickPollDropdown extends Component {

if (quickPollOptions.length === 0) return null;

let answers = null;
let quickPollLabel = '';
if (quickPolls.length > 0) {
const { props: pollProps } = quickPolls[0];
quickPollLabel = pollProps.label;
answers = pollProps.answers;
}

let singlePollType = null;
let answers = null;
if (quickPolls.length === 1 && quickPollOptions.length) {
const { type } = quickPollOptions[0];
singlePollType = type;
Expand Down
4 changes: 2 additions & 2 deletions bigbluebutton-html5/imports/ui/components/poll/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const intlMessages = defineMessages({

const POLL_SETTINGS = Meteor.settings.public.poll;

const MAX_CUSTOM_FIELDS = POLL_SETTINGS.max_custom;
const MAX_CUSTOM_FIELDS = POLL_SETTINGS.maxCustom;
const MAX_INPUT_CHARS = POLL_SETTINGS.maxTypedAnswerLength;
const QUESTION_MAX_INPUT_CHARS = 400;
const FILE_DRAG_AND_DROP_ENABLED = POLL_SETTINGS.allowDragAndDropFile;
Expand Down Expand Up @@ -494,7 +494,7 @@ class Poll extends Component {
label={intl.formatMessage(intlMessages.addOptionLabel)}
color="default"
icon="add"
disabled={optList.length === MAX_CUSTOM_FIELDS}
disabled={optList.length >= MAX_CUSTOM_FIELDS}
onClick={() => this.handleAddOption()}
/>
)}
Expand Down
25 changes: 20 additions & 5 deletions bigbluebutton-html5/imports/ui/components/presentation/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { Slides, SlidePositions } from '/imports/api/slides';
import Auth from '/imports/ui/services/auth';
import PollService from '/imports/ui/components/poll/service';

const POLL_SETTINGS = Meteor.settings.public.poll;
const MAX_CUSTOM_FIELDS = POLL_SETTINGS.maxCustom;

const getCurrentPresentation = podId => Presentations.findOne({
podId,
current: true,
Expand Down Expand Up @@ -81,7 +84,7 @@ const parseCurrentSlideContent = (yesValue, noValue, abstentionValue, trueValue,
content,
} = currentSlide;

const pollRegex = /[1-6A-Fa-f][.)].*/g;
const pollRegex = /[1-9A-Ia-i][.)].*/g;
let optionsPoll = content.match(pollRegex) || [];
if (optionsPoll) optionsPoll = optionsPoll.map(opt => `\r${opt[0]}.`);

Expand Down Expand Up @@ -120,10 +123,22 @@ const parseCurrentSlideContent = (yesValue, noValue, abstentionValue, trueValue,
return acc;
}, []).filter(({
options,
}) => options.length > 1 && options.length < 7).forEach(poll => quickPollOptions.push({
type: `${pollTypes.Letter}${poll.options.length}`,
poll,
}));
}) => options.length > 1 && options.length < 10).forEach(poll => {
if (poll.options.length <= 5 || MAX_CUSTOM_FIELDS <= 5) {
const maxAnswer = poll.options.length > MAX_CUSTOM_FIELDS
? MAX_CUSTOM_FIELDS
: poll.options.length
quickPollOptions.push({
type: `${pollTypes.Letter}${maxAnswer}`,
poll,
})
} else {
quickPollOptions.push({
type: pollTypes.Custom,
poll,
})
}
});

if (quickPollOptions.length > 0) {
content = content.replace(new RegExp(pollRegex), '');
Expand Down
2 changes: 1 addition & 1 deletion bigbluebutton-html5/private/config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public:
toggleSelfVoice: false
poll:
enabled: true
max_custom: 5
maxCustom: 5
allowDragAndDropFile: false
maxTypedAnswerLength: 45
captions:
Expand Down

0 comments on commit a53917e

Please sign in to comment.