diff --git a/client/src/app/site/assignments/components/assignment-poll-vote/assignment-poll-vote.component.html b/client/src/app/site/assignments/components/assignment-poll-vote/assignment-poll-vote.component.html index 397c82e45..23afcbe0f 100644 --- a/client/src/app/site/assignments/components/assignment-poll-vote/assignment-poll-vote.component.html +++ b/client/src/app/site/assignments/components/assignment-poll-vote/assignment-poll-vote.component.html @@ -5,49 +5,46 @@ - Your vote is valid! DANGER: Your vote is invalid! You have not give any voting here! -

- {{ 'Votes for this poll' | translate }}: {{ poll.votes_amount }} - +

+ {{ 'Votes for this poll' | translate }}: {{ getVotesCount() }}/{{ poll.votes_amount }}

-
- TODO: DO not show buttons, becuase, the user has already voted for this one -
-
-
- {{ option.user.getFullName() }} - {{ 'Unknown user' | translate }} -
+
+
+
+ {{ option.user.getFullName() }} + {{ 'Unknown user' | translate }} +
-
- - - {{ action.label | translate }} - +
+ + + {{ action.label | translate }} + +
+
-
diff --git a/client/src/app/site/assignments/components/assignment-poll-vote/assignment-poll-vote.component.ts b/client/src/app/site/assignments/components/assignment-poll-vote/assignment-poll-vote.component.ts index 1ea7d7821..874638b76 100644 --- a/client/src/app/site/assignments/components/assignment-poll-vote/assignment-poll-vote.component.ts +++ b/client/src/app/site/assignments/components/assignment-poll-vote/assignment-poll-vote.component.ts @@ -86,7 +86,13 @@ export class AssignmentPollVoteComponent extends BasePollVoteComponent this.currentVotes[key]).length; + } + protected updateVotes(): void { + console.log('currentVotes: ', this.currentVotes); + if (this.user && this.votes && this.poll) { const filtered = this.votes.filter( vote => vote.option.poll_id === this.poll.id && vote.user_id === this.user.id diff --git a/client/src/app/site/polls/components/poll-form/poll-form.component.html b/client/src/app/site/polls/components/poll-form/poll-form.component.html index 473edb4a3..043178315 100644 --- a/client/src/app/site/polls/components/poll-form/poll-form.component.html +++ b/client/src/app/site/polls/components/poll-form/poll-form.component.html @@ -81,7 +81,9 @@ formControlName="votes_amount" min="1" required + /> + {{ 'Multiple votes are disabled due to security reasons' | translate }} {{ PollPropertyVerbose.global_no | translate }} {{ diff --git a/client/src/app/site/polls/components/poll-form/poll-form.component.ts b/client/src/app/site/polls/components/poll-form/poll-form.component.ts index 695f1119a..63d6fa9a4 100644 --- a/client/src/app/site/polls/components/poll-form/poll-form.component.ts +++ b/client/src/app/site/polls/components/poll-form/poll-form.component.ts @@ -77,6 +77,8 @@ export class PollFormComponent extends BaseViewComponent implements OnInit { */ public publishImmediately = true; + public showSingleAmountHint = false; + /** * Constructor. Retrieves necessary metadata from the pollService, * injects the poll itself @@ -124,31 +126,61 @@ export class PollFormComponent extends BaseViewComponent implements OnInit { this.updatePollValues(this.contentForm.value); this.subscriptions.push( + // changes to whole form this.contentForm.valueChanges.subscribe(values => { this.updatePollValues(values); + }), + // poll method changes + this.contentForm.get('pollmethod').valueChanges.subscribe(method => { + let forbiddenBases: string[]; + if (method === 'YN') { + forbiddenBases = [PercentBase.YNA, PercentBase.Cast]; + } else if (method === 'YNA') { + forbiddenBases = [PercentBase.Cast]; + } else if (method === 'votes') { + forbiddenBases = [PercentBase.YN, PercentBase.YNA]; + + if (this.contentForm.get('type').value === PollType.Pseudoanonymous) { + this.setVotesAmountCtrl(); + } + } + + const percentBases = {}; + for (const [key, value] of Object.entries(PercentBaseVerbose)) { + if (!forbiddenBases.includes(key)) { + percentBases[key] = value; + } + } + this.percentBases = percentBases; + // TODO: update selected base + this.setVotesAmountCtrl(); + }), + // poll type changes + this.contentForm.get('type').valueChanges.subscribe(() => { + this.setVotesAmountCtrl(); }) ); + } - // update the percent bases when the poll method changes - this.contentForm.get('pollmethod').valueChanges.subscribe(method => { - let forbiddenBases: string[]; - if (method === 'YN') { - forbiddenBases = [PercentBase.YNA, PercentBase.Cast]; - } else if (method === 'YNA') { - forbiddenBases = [PercentBase.Cast]; - } else if (method === 'votes') { - forbiddenBases = [PercentBase.YN, PercentBase.YNA]; - } - - const percentBases = {}; - for (const [key, value] of Object.entries(PercentBaseVerbose)) { - if (!forbiddenBases.includes(key)) { - percentBases[key] = value; - } - } - this.percentBases = percentBases; - // TODO: update selected base - }); + /** + * Disable votes_amount form control if the poll type is anonymous + * and the poll method is votes. + * TODO: Enabling this requires at least another layout and some rework + */ + private setVotesAmountCtrl(): void { + // Disable "Amounts of votes" if anonymous and yes-method + const votesAmountCtrl = this.contentForm.get('votes_amount'); + if ( + this.contentForm.get('type').value === PollType.Pseudoanonymous && + this.contentForm.get('pollmethod').value === 'votes' + ) { + votesAmountCtrl.disable(); + votesAmountCtrl.setValue(1); + this.showSingleAmountHint = true; + } else { + votesAmountCtrl.enable(); + this.showSingleAmountHint = false; + } } public getValues(): Partial { @@ -193,8 +225,8 @@ export class PollFormComponent extends BaseViewComponent implements OnInit { majority_method: ['', Validators.required], votes_amount: [1, [Validators.required, Validators.min(1)]], groups_id: [], - global_no: [], - global_abstain: [] + global_no: [false], + global_abstain: [false] }); } } diff --git a/openslides/assignments/views.py b/openslides/assignments/views.py index 6ae7b7f06..0e7cb851d 100644 --- a/openslides/assignments/views.py +++ b/openslides/assignments/views.py @@ -473,11 +473,6 @@ class AssignmentPollViewSet(BasePollViewSet): ) amount_sum += amount - if amount_sum <= 0: - raise ValidationError( - {"detail": "You must give at least one vote"} - ) - if amount_sum > poll.votes_amount: raise ValidationError( {