From 5bfd527e3de7fefaaa7426fdd219c759dad60a2e Mon Sep 17 00:00:00 2001 From: Filip Drabant Date: Mon, 6 Nov 2023 21:34:23 +0100 Subject: [PATCH] users should not be able to add new options shortly before poll ends #167 --- src/app/poll.service.ts | 9 +++++++++ src/app/poll/poll.page.html | 12 +++++++++--- src/app/poll/poll.page.ts | 3 +++ src/assets/i18n/de.json | 3 ++- src/assets/i18n/en.json | 3 ++- src/assets/i18n/es.json | 3 ++- src/assets/i18n/fi.json | 3 ++- src/assets/i18n/hi.json | 3 ++- src/assets/i18n/it.json | 3 ++- src/assets/i18n/ko.json | 3 ++- src/assets/i18n/pl.json | 3 ++- src/environments/environment.ts | 1 + 12 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/app/poll.service.ts b/src/app/poll.service.ts index 67e109910..3ebf6324b 100644 --- a/src/app/poll.service.ts +++ b/src/app/poll.service.ts @@ -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; + } + } + + } diff --git a/src/app/poll/poll.page.html b/src/app/poll/poll.page.html index ccdec12f6..bf73592af 100644 --- a/src/app/poll/poll.page.html +++ b/src/app/poll/poll.page.html @@ -930,14 +930,20 @@

+ size="small" (click)="add_option($event)" fill="clear" color="primary" + [disabled]="!p.can_add_option()"> + - + [innerHtml]="'poll.add-option' | translate" + [disabled]="!p.can_add_option()"> + + + diff --git a/src/app/poll/poll.page.ts b/src/app/poll/poll.page.ts index 7a84e6908..79085c878 100644 --- a/src/app/poll/poll.page.ts +++ b/src/app/poll/poll.page.ts @@ -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) { diff --git a/src/assets/i18n/de.json b/src/assets/i18n/de.json index 48c98d1d4..c6dbf23e1 100644 --- a/src/assets/i18n/de.json +++ b/src/assets/i18n/de.json @@ -595,7 +595,8 @@ "explain": "Erklären", "add-option": "Option hinzufügen", "add-option-info": "Wenn Du denkst, eine wichtige Option fehlt noch und ist nicht von den anderen Optionen mit abgedeckt, kannst Du sie hinzufügen. Einmal hinzugefügte Optionen kann allerdings niemand mehr verändern oder löschen.", - "sorting": "Optionen werden neu sortiert..." + "sorting": "Optionen werden neu sortiert...", + "add-option-expired": "Time to add new options has expired." }, "previewpoll": { "_COMMENT_SECTION_": "[COMMENT] strings used on the Please Check (Poll Preview) page:", diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 31edb345f..bb6700e8a 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -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:", diff --git a/src/assets/i18n/es.json b/src/assets/i18n/es.json index 0e2198b7b..1e5a778f6 100644 --- a/src/assets/i18n/es.json +++ b/src/assets/i18n/es.json @@ -598,7 +598,8 @@ "explain": "Explicar", "add-option": "Añadir opción", "add-option-info": "Si crees que falta alguna opción importante y no está cubierta por ninguna de las anteriores, puedes añadirla. Una vez añadida, las opciones no podrán ser editadas o eliminadas.", - "sorting": "Ordenando opciones según su aprobación..." + "sorting": "Ordenando opciones según su aprobación...", + "add-option-expired": "Time to add new options has expired." }, "previewpoll": { "_COMMENT_SECTION_": "[COMMENT] strings used on the Please Check (Poll Preview) page:", diff --git a/src/assets/i18n/fi.json b/src/assets/i18n/fi.json index cd2c0ec79..fe451ad4c 100644 --- a/src/assets/i18n/fi.json +++ b/src/assets/i18n/fi.json @@ -596,7 +596,8 @@ "explain": "Selitä", "add-option": "Lisää vaihtoehto", "add-option-info": "Jos tärkeä vaihtoehto mielestäsi puuttuu vielä eikä yksikään muista vaihtoehdoista kata sitä, voit lisätä sen. Kun vaihtoehto on lisätty, sitä ei voi kuitenkaan enää muokata tai poistaa.", - "sorting": "Järjestetään vaihtoehtoja kannatuksen perusteella..." + "sorting": "Järjestetään vaihtoehtoja kannatuksen perusteella...", + "add-option-expired": "Time to add new options has expired." }, "previewpoll": { "_COMMENT_SECTION_": "[COMMENT] strings used on the Please Check (Poll Preview) page:", diff --git a/src/assets/i18n/hi.json b/src/assets/i18n/hi.json index c6111ec55..f5cbcee2b 100644 --- a/src/assets/i18n/hi.json +++ b/src/assets/i18n/hi.json @@ -598,7 +598,8 @@ "explain": "समझाएँ", "add-option": "विकल्प जोड़ें", "add-option-info": "यदि आपको लगता है कि कुछ महत्वपूर्ण विकल्प गायब है और सूचीबद्ध विकल्पों में से किसी के द्वारा कवर नहीं किया गया है, तो आप इसे जोड़ सकते हैं। एक बार जोड़ने के बाद, विकल्पों को संपादित या फिर से हटाया नहीं जा सकता है।", - "sorting": "स्वीकृति के आधार पर विकल्पों को क्रमित किया जा रहा है..." + "sorting": "स्वीकृति के आधार पर विकल्पों को क्रमित किया जा रहा है...", + "add-option-expired": "Time to add new options has expired." }, "previewpoll": { "_COMMENT_SECTION_": "[COMMENT] strings used on the Please Check (Poll Preview) page:", diff --git a/src/assets/i18n/it.json b/src/assets/i18n/it.json index e25bd25b9..a6f28d257 100644 --- a/src/assets/i18n/it.json +++ b/src/assets/i18n/it.json @@ -598,7 +598,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:", diff --git a/src/assets/i18n/ko.json b/src/assets/i18n/ko.json index 84751544d..cdf7a3be3 100644 --- a/src/assets/i18n/ko.json +++ b/src/assets/i18n/ko.json @@ -598,7 +598,8 @@ "explain": "설명", "add-option": "선택지 추가", "add-option-info": "중요한 선택지가 위에 목록에 없다고 생각된다면 추가 할 수 있습니다. 하지만 추가된 이후에는 수정되거나 삭제할 수 없음을 유의해 주십시오.", - "sorting": "승인 수에 따라 선택지 정렬중..." + "sorting": "승인 수에 따라 선택지 정렬중...", + "add-option-expired": "Time to add new options has expired." }, "previewpoll": { "_COMMENT_SECTION_": "[COMMENT] strings used on the Please Check (Poll Preview) page:", diff --git a/src/assets/i18n/pl.json b/src/assets/i18n/pl.json index d85340d10..5e5f9329b 100644 --- a/src/assets/i18n/pl.json +++ b/src/assets/i18n/pl.json @@ -598,7 +598,8 @@ "explain": "Wyjaśnij", "add-option": "Dodaj opcję", "add-option-info": "Jeśli uważasz, że brakuje jakiejś ważnej opcji i nie pokrywa się ona z żadną z już wymienionych, możesz ją dodać. Jednak po dodaniu opcji nie można jej ponownie edytować ani usunąć.", - "sorting": "Sortowanie opcji według poziomu akceptacji..." + "sorting": "Sortowanie opcji według poziomu akceptacji...", + "add-option-expired": "Time to add new options has expired." }, "previewpoll": { "_COMMENT_SECTION_": "[COMMENT] strings used on the Please Check (Poll Preview) page:", diff --git a/src/environments/environment.ts b/src/environments/environment.ts index d17c562d5..f5bc645d1 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -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/",