Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

users should not be able to add new options shortly before poll ends … #263

Merged
merged 2 commits into from
Dec 19, 2023
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
12 changes: 10 additions & 2 deletions src/app/addoption-dialog/addoption-dialog.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ <h1 [innerHtml]="'addoption.header'|translate"></h1>
: 'draftpoll.target-name-placeholder') | translate"
type="text" required [maxlength]="E.max_len.name"
style="font-weight: bold; font-style: italic;">
</ion-input>
</ion-input>
</ion-item>
<div class="validation-errors">
<ng-container *ngFor="let validation of validation_messages.option_name">
Expand Down Expand Up @@ -125,14 +125,22 @@ <h1 [innerHtml]="'addoption.header'|translate"></h1>
<ion-icon name="arrow-back-outline"></ion-icon>&nbsp;
<span [innerHtml]="'cancel'|translate"></span>
</ion-button>&nbsp;&nbsp;
<ion-button color="primary" [disabled]="!formGroup.valid"
<ion-button color="primary" [disabled]="isAddButtonDisabled()"
shape="round" fill="solid"
(click)="OK_button_clicked()"><!--type="submit" button-type="submit"-->
<ion-icon name="checkmark"></ion-icon>&nbsp;
<span [innerHtml]="'add'|translate"></span>
</ion-button>
</ion-buttons>
</ion-item>
<div class="validation-errors">
<ng-container>
<div class="error-message"
*ngIf="!this.p.can_add_option()"
[innerHtml]="'poll.add-option-expired'|translate">
</div>
</ng-container>
</div>
<ion-item lines="none">
<small [innerHtml]="'addoption.info' | translate"></small>
</ion-item>
Expand Down
5 changes: 5 additions & 0 deletions src/app/addoption-dialog/addoption-dialog.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ export class AddoptionDialogPage implements OnInit {
setTimeout(() => this.focus_element.setFocus(), 100);
}

isAddButtonDisabled(): boolean {
// Combine both conditions here
return !this.formGroup.valid || !this.p.can_add_option();
}

OK_button_clicked() {
/** add the option */
const name = this.formGroup.get('option_name').value,
Expand Down
9 changes: 9 additions & 0 deletions src/app/poll.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1914,6 +1914,15 @@ export class Poll {
this.final_rand = rand;
}

can_add_option(): boolean {
if (this.remaining_time_fraction > environment.no_more_options_time_fraction){
return true;
} else {
return false;
}
}



}

Expand Down
9 changes: 6 additions & 3 deletions src/app/poll/poll.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -930,12 +930,15 @@ <h3><b>
<ng-container *ngIf="p.allow_voting">
<ion-item lines="none" class="ion-no-padding" style="padding-left: 10px; padding-top: 10px;">
<ion-fab-button
size="small" (click)="add_option($event)" fill="clear" color="primary">
size="small" (click)="add_option($event)" fill="clear" color="primary"
[disabled]="!p.can_add_option()">
<ion-icon name="add"></ion-icon>

</ion-fab-button>
<ion-button
<ion-button
class="ion-no-padding ion-no-margin" fill="clear" (click)="add_option($event)"
[innerHtml]="'poll.add-option' | translate">
[innerHtml]="'poll.add-option' | translate"
[disabled]="!p.can_add_option()">
</ion-button>
</ion-item>
<ion-item lines="none" style="padding-bottom: 10px!important;">
Expand Down
3 changes: 3 additions & 0 deletions src/app/poll/poll.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,9 @@ export class PollPage implements OnInit {
}

add_option(event: Event) {
if(!this.p.can_add_option()){
return;
}
/** open the add option dialog popover */
this.p.end_if_past_due();
if (this.p.allow_voting) {
Expand Down
3 changes: 2 additions & 1 deletion src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,8 @@
"explain": "Explain",
"add-option": "Add option",
"add-option-info": "If you believe some important option is missing and is not covered by any of the listed options, you can add it. Once added, options cannot be edited or removed again, however.",
"sorting": "Sorting options by approval..."
"sorting": "Sorting options by approval...",
"add-option-expired": "Time to add new options has expired."
},
"previewpoll": {
"_COMMENT_SECTION_": "[COMMENT] strings used on the Please Check (Poll Preview) page:",
Expand Down
1 change: 1 addition & 0 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const environment = {
enabled: false,
max_weight: 3
},
no_more_options_time_fraction: 1/14,
db_put_retry_delay_ms: 100,
default_lang: "en",
github_url: "https://github.com/pik-gane/vodle/",
Expand Down