Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DeveloperContestController(
): String {
val webUser = loginData.validate(redirectAttributes) ?: return "redirect:$LOGIN_PATH"

if (!contestView.duration.isLocalTimeFormatted()) {
if (contestView.isOpenEnded == false && !contestView.duration.isLocalTimeFormatted()) {
redirectAttributes.addPopupMessage("Время на выполнение Тура должно быть в формате HH:mm.")
return "redirect:$CONTESTS_PATH"
}
Expand All @@ -63,7 +63,9 @@ class DeveloperContestController(
return "redirect:$CONTESTS_PATH"
}

if (contest.startDate.isEqual(contest.endDate) || contest.duration == LocalTime.of(0, 0)) {
if (contestView.isOpenEnded == false &&
(contest.startDate.isEqual(contest.endDate) || contest.duration == LocalTime.of(0, 0))
) {
redirectAttributes.addPopupMessage("Время на выполнение Тура должно быть положительным.")
return "redirect:$CONTESTS_PATH"
}
Expand Down Expand Up @@ -132,7 +134,7 @@ class DeveloperContestController(
}


if (!contestView.duration.isLocalTimeFormatted()) {
if (contestView.isOpenEnded == false && !contestView.duration.isLocalTimeFormatted()) {
redirectAttributes.addPopupMessage("Время на выполнение Тура должно быть в формате HH:mm.")
return "redirect:$CONTEST_PATH/$contestId"
}
Expand All @@ -146,7 +148,9 @@ class DeveloperContestController(
return "redirect:$CONTEST_PATH/$contestId"
}

if (contest.startDate.isEqual(contest.endDate) || contest.duration == LocalTime.of(0, 0)) {
if (contestView.isOpenEnded == false &&
(contest.startDate.isEqual(contest.endDate) || contest.duration == LocalTime.of(0, 0))
) {
redirectAttributes.addPopupMessage("Время на выполнение Тура должно быть положительным.")
return "redirect:$CONTEST_PATH/$contestId"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Contest(
val now = LocalDateTime.now(DEFAULT_ZONE_ID)
val lastSeconds = endDate.toEpochSecond() - now.toEpochSecond() + 1

return min(duration.toSecondOfDay().toLong(), lastSeconds)
return if (isOpenEnded) lastSeconds else min(duration.toSecondOfDay().toLong(), lastSeconds)
}

@ElementCollection
Expand All @@ -93,6 +93,12 @@ class Contest(
@ManyToMany(mappedBy = "contests")
val tasks: MutableSet<Task> = mutableSetOf()

/**
* @author Roman Shishkin
* @since %CURRENT_VERSION%
*/
var isOpenEnded: Boolean = false

enum class Visibility(override val dbkey: String) : Enum {

PUBLIC("PLC"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Student(
val nowInSeconds = now.toEpochSecond()
val contestLastSeconds = contest.lastSeconds

if (contest.isOpenEnded && contestLastSeconds > 0) return LocalTime.MAX

val startTime = startTimesByContestId[contest.id!!] ?: return LocalTime.ofSecondOfDay(contestLastSeconds)
val startTimeInSeconds = startTime.toEpochSecond()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import trik.testsys.webclient.entity.user.impl.Developer
import trik.testsys.webclient.util.convertToLocalTime
import trik.testsys.webclient.util.fromTimeZone
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.format.DateTimeFormatter

/**
Expand All @@ -20,17 +21,19 @@ data class ContestCreationView(
val startDate: LocalDateTime,
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")
val endDate: LocalDateTime,
val duration: String
val duration: String,
val isOpenEnded: Boolean?,
) {

fun toEntity(developer: Developer, timeZoneId: String?) = Contest(
name,
startDate.fromTimeZone(timeZoneId), endDate.fromTimeZone(timeZoneId),
duration.convertToLocalTime()
if (isOpenEnded == true) LocalTime.MIN else duration.convertToLocalTime()
).also {
it.additionalInfo = additionalInfo
it.note = note
it.developer = developer
it.isOpenEnded = isOpenEnded ?: false
}

val formattedStartDate: String
Expand All @@ -43,7 +46,8 @@ data class ContestCreationView(

fun empty() = ContestCreationView(
"", "", "",
LocalDateTime.now(), LocalDateTime.now(), "01:00"
LocalDateTime.now(), LocalDateTime.now(), "",
false
)
}
}
14 changes: 9 additions & 5 deletions src/main/kotlin/trik/testsys/webclient/view/impl/ContestView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import trik.testsys.webclient.util.format
import trik.testsys.webclient.util.fromTimeZone
import trik.testsys.webclient.view.NotedEntityView
import java.time.LocalDateTime
import java.time.LocalTime

/**
* @author Roman Shishkin
Expand All @@ -24,16 +25,19 @@ data class ContestView(
val startDate: LocalDateTime,
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")
val endDate: LocalDateTime,
val duration: String
val duration: String,
var isOpenEnded: Boolean?,
) : NotedEntityView<Contest> {

override fun toEntity(timeZoneId: String?) = Contest(
name, startDate.fromTimeZone(timeZoneId), endDate.fromTimeZone(timeZoneId), duration.convertToLocalTime()
name, startDate.fromTimeZone(timeZoneId), endDate.fromTimeZone(timeZoneId),
if (isOpenEnded == true) LocalTime.MIN else duration.convertToLocalTime()
).also {
it.id = id
it.additionalInfo = additionalInfo
it.note = note
it.visibility = visibility
it.isOpenEnded = isOpenEnded ?: false
}

val formattedStartDate: String
Expand All @@ -42,8 +46,7 @@ data class ContestView(
val formattedEndDate: String
get() = endDate.format()

val formattedDuration: String
get() = duration.format()
val formattedDuration = if (isOpenEnded == true) "Неограниченно" else duration

companion object {

Expand All @@ -56,7 +59,8 @@ data class ContestView(
visibility = this.visibility,
startDate = this.startDate.atTimeZone(timeZone),
endDate = this.endDate.atTimeZone(timeZone),
duration = this.duration.toString()
duration = this.duration.toString(),
isOpenEnded = this.isOpenEnded,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ data class StudentContestView(
additionalInfo = this.additionalInfo,
creationDate = this.creationDate?.atTimeZone(timeZone),
name = this.name,
lastTime = lastTime.format(DateTimeFormatter.ofPattern("HH:mm:ss")),
lastTime = if (isOpenEnded) "Неограниченно" else lastTime.format(DateTimeFormatter.ofPattern("HH:mm:ss")),
startDate = this.startDate.atTimeZone(timeZone),
endDate = this.endDate.atTimeZone(timeZone),
isGoingOn = this.isGoingOn(),
Expand Down
19 changes: 19 additions & 0 deletions src/main/resources/static/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,23 @@ function copy(id) {
textArea.select();
document.execCommand("Copy");
textArea.remove();
}

function toggleVisibility(dependencyId, labelId, fieldId) {
let dependency = document.getElementById(dependencyId);
let label = document.getElementById(labelId);
let field = document.getElementById(fieldId);


if (dependency.checked) {
label.setAttribute("hidden", ""); // Скрываем поле
field.setAttribute("hidden", ""); // Скрываем поле

field.removeAttribute("required"); // Убираем обязательность
} else {
label.removeAttribute("hidden"); // Показываем поле
field.removeAttribute("hidden"); // Показываем поле

field.setAttribute("required", ""); // Делаем обязательным
}
}
4 changes: 2 additions & 2 deletions src/main/resources/templates/admin/group.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ <h1>Список прикрепленных Туров</h1>
<th style="width: 12%">
Дата и время окончания
</th>
<th style="width: 8%">
<th style="width: 12%">
Время на выполнение
</th>
<th style="width: 7%">
Expand Down Expand Up @@ -159,7 +159,7 @@ <h1>Список доступных к прикреплению Туров</h1>
<th style="width: 12%">
Дата и время окончания
</th>
<th style="width: 8%">
<th style="width: 12%">
Время на выполнение
</th>
<th style="width: 7%">
Expand Down
40 changes: 28 additions & 12 deletions src/main/resources/templates/developer/contest.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,47 @@ <h1>Информация о Туре</h1>
size='50',
isReadonly='true', isRequired='true', isAccessToken='false')">
</div>
<div class="form-field" style="flex-basis: 40%">
<div class="form-label" style="flex-basis: 25%">
<div class="form-field" style="flex-basis: 35%">
<div class="form-label" style="flex-basis: 57%">
<label for="contest.startDate">Дата и время начала</label>
</div>
<div class="form-input" style="flex-basis: 75%">
<div class="form-input" style="flex-basis: 43%">
<input name="startDate"
th:value="${contest.startDate}"
type="datetime-local" id="contest.startDate" readonly required/>
</div>
</div>
<div class="form-field" style="flex-basis: 40%">
<div class="form-label" style="flex-basis: 25%">
<div class="form-field" style="flex-basis: 35%">
<div class="form-label" style="flex-basis: 57%">
<label for="contest.endDate">Дата и время окончания</label>
</div>
<div class="form-input" style="flex-basis: 75%">
<div class="form-input" style="flex-basis: 43%">
<input name="endDate" th:value="${contest.endDate}"
type="datetime-local" id="contest.endDate" readonly required/>
</div>
</div>
<div th:replace="fragments/form.html
:: formField(id='contest.duration', type='text',
labelName='Время на прохождение', labelSize='50',
fieldName='duration', fieldSize='50',
size='20',
isReadonly='false', isRequired='true', isAccessToken='false')">

<div class="form-field" style="flex-basis: 10%">
<div class="form-label" style="flex-basis: 90%">
<label for="contest.isOpenEnded">Бессрочный</label>
</div>
<div class="form-input" style="flex-basis: 10%">
<input name="isOpenEnded" th:field="*{isOpenEnded}" th:checked="${contest.isOpenEnded}"
onclick="toggleVisibility(this.id, 'contest.duration-label', 'contest.duration')"
type="checkbox" id="contest.isOpenEnded" readonly/>
</div>
</div>
<div class="form-field" style="flex-basis: 20%">
<div class="form-label" style="flex-basis: 50%">
<label for="contest.duration" id="contest.duration-label"
th:hidden="${contest.isOpenEnded}">Время на прохождение</label>
</div>
<div class="form-input" style="flex-basis: 50%">
<input name="duration" th:value="${contest.duration}"
placeholder="01:00"
th:hidden="${contest.isOpenEnded}" th:required="${!contest.isOpenEnded}"
type="text" id="contest.duration" readonly/>
</div>
</div>
<div th:replace="fragments/form.html
:: formField(id='contest.additionalInfo', type='text',
Expand Down
43 changes: 30 additions & 13 deletions src/main/resources/templates/developer/contests.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,47 @@ <h1>Создание Тура</h1>
size='100',
isReadonly='false', isRequired='true', isAccessToken='false')">
</div>
<div class="form-field" style="flex-basis: 40%">
<div class="form-label" style="flex-basis: 25%">
<div class="form-field" style="flex-basis: 35%">
<div class="form-label" style="flex-basis: 57%">
<label for="contest.startDate">Дата и время начала</label>
</div>
<div class="form-input" style="flex-basis: 75%">
<div class="form-input" style="flex-basis: 43%">
<input name="startDate"
th:value="${contest.startDate}"
type="datetime-local" id="contest.startDate" readonly required/>
</div>
</div>
<div class="form-field" style="flex-basis: 40%">
<div class="form-label" style="flex-basis: 25%">
<div class="form-field" style="flex-basis: 35%">
<div class="form-label" style="flex-basis: 57%">
<label for="contest.endDate">Дата и время окончания</label>
</div>
<div class="form-input" style="flex-basis: 75%">
<input name="endDate"
<div class="form-input" style="flex-basis: 43%">
<input name="endDate" th:value="${contest.endDate}"
type="datetime-local" id="contest.endDate" readonly required/>
</div>
</div>
<div th:replace="fragments/form.html
:: formField(id='contest.duration', type='text',
labelName='Время на прохождение', labelSize='50',
fieldName='duration', fieldSize='50',
size='20',
isReadonly='false', isRequired='true', isAccessToken='false')">

<div class="form-field" style="flex-basis: 10%">
<div class="form-label" style="flex-basis: 90%">
<label for="contest.isOpenEnded">Бессрочный</label>
</div>
<div class="form-input" style="flex-basis: 10%">
<input name="isOpenEnded" th:field="*{isOpenEnded}" th:checked="${contest.isOpenEnded}"
onclick="toggleVisibility(this.id, 'contest.duration-label', 'contest.duration')"
type="checkbox" id="contest.isOpenEnded" readonly/>
</div>
</div>
<div class="form-field" style="flex-basis: 20%">
<div class="form-label" style="flex-basis: 50%">
<label for="contest.duration" id="contest.duration-label"
th:hidden="${contest.isOpenEnded}">Время на прохождение</label>
</div>
<div class="form-input" style="flex-basis: 50%">
<input name="duration" th:value="${contest.duration}"
placeholder="01:00"
th:hidden="${contest.isOpenEnded}" th:required="${!contest.isOpenEnded}"
type="text" id="contest.duration" readonly/>
</div>
</div>
<div th:replace="fragments/form.html
:: formField(id='contest.additionalInfo', type='text',
Expand Down
15 changes: 12 additions & 3 deletions src/main/resources/templates/student/contest.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@ <h1>Информация о Туре</h1>
size='50',
isReadonly='true', isRequired='true', isAccessToken='false')">
</div>
<div class="form-field" style="flex-basis: 25%">
<div class="form-label" style="flex-basis: 50%">
<label for="contest.endDate">Дата и время окончания</label>
</div>
<div class="form-input" style="flex-basis: 50%">
<input name="endDate" th:value="${contest.endDate}"
type="datetime-local" id="contest.endDate" readonly required/>
</div>
</div>
<div th:replace="fragments/form.html
:: formField(id='contest.lastTime', type='text',
labelName='Оставшееся время', labelSize='20',
fieldName='lastTime', fieldSize='80',
size='50',
labelName='Оставшееся время', labelSize='50',
fieldName='lastTime', fieldSize='50',
size='25',
isReadonly='true', isRequired='false', isAccessToken='false')">
</div>
<div th:replace="fragments/form.html
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/templates/student/contests.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h1>Список доступных Туров</h1>
<th style="width: 12%">
Дата и время окончания
</th>
<th style="width: 8%">
<th style="width: 12%">
Время на выполнение
</th>
<th>
Expand Down Expand Up @@ -101,7 +101,7 @@ <h1>Список оконченных Туров</h1>
<th style="width: 12%">
Дата и время окончания
</th>
<th style="width: 8%">
<th style="width: 12%">
Время на выполнение
</th>
<th>
Expand Down