Merge branch '61-adding-deadline' into 'dev'

Resolve "Добавление дедлайна для конференции"

Closes #61

See merge request romanov73/ng-tracker!49
This commit is contained in:
Anton Romanov 2019-04-09 12:34:06 +00:00
commit d1813f656e
3 changed files with 19 additions and 5 deletions

View File

@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceDto;
import ru.ulstu.conference.model.ConferenceFilterDto; import ru.ulstu.conference.model.ConferenceFilterDto;
import ru.ulstu.conference.service.ConferenceService; import ru.ulstu.conference.service.ConferenceService;
import ru.ulstu.deadline.model.Deadline;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import javax.validation.Valid; import javax.validation.Valid;
@ -21,7 +22,6 @@ import static org.springframework.util.StringUtils.isEmpty;
import static ru.ulstu.core.controller.Navigation.CONFERENCES_PAGE; import static ru.ulstu.core.controller.Navigation.CONFERENCES_PAGE;
import static ru.ulstu.core.controller.Navigation.CONFERENCE_PAGE; import static ru.ulstu.core.controller.Navigation.CONFERENCE_PAGE;
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO; import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
import static ru.ulstu.core.controller.Navigation.hasErrors;
@Controller() @Controller()
@ -55,12 +55,22 @@ public class ConferenceController {
if (conferenceDto.getDeadlines().isEmpty()) { if (conferenceDto.getDeadlines().isEmpty()) {
errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); errors.rejectValue("deadlines", "errorCode", "Не может быть пустым");
} }
hasErrors(errors, CONFERENCE_PAGE); if (errors.hasErrors())
return CONFERENCE_PAGE;
conferenceService.save(conferenceDto); conferenceService.save(conferenceDto);
return String.format(REDIRECT_TO, CONFERENCES_PAGE); return String.format(REDIRECT_TO, CONFERENCES_PAGE);
} }
@PostMapping(value = "/conference", params = "addDeadline")
public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) {
filterEmptyDeadlines(conferenceDto);
if (errors.hasErrors())
return CONFERENCE_PAGE;
conferenceDto.getDeadlines().add(new Deadline());
return CONFERENCE_PAGE;
}
private void filterEmptyDeadlines(ConferenceDto conferenceDto) { private void filterEmptyDeadlines(ConferenceDto conferenceDto) {
conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream() conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))

View File

@ -30,6 +30,9 @@
<label for="title">Название:</label> <label for="title">Название:</label>
<input class="form-control" th:field="*{title}" id="title" type="text" <input class="form-control" th:field="*{title}" id="title" type="text"
placeholder="Название конференции"/> placeholder="Название конференции"/>
<p th:if="${#fields.hasErrors('title')}" th:errors="*{title}"
class="alert alert-danger">Incorrect title</p>
<p class="help-block text-danger"></p>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -61,14 +64,15 @@
$('#deadlines${rowStat.index}\\.date').val(''); $('#deadlines${rowStat.index}\\.date').val('');
$('#addDeadline').click();|"/> $('#addDeadline').click();|"/>
</div> </div>
</div> </div>
</div> </div>
<p th:if="${#fields.hasErrors('deadlines')}" th:errors="*{deadlines}" <p th:if="${#fields.hasErrors('deadlines')}" th:errors="*{deadlines}"
class="alert alert-danger">Incorrect title</p> class="alert alert-danger">Incorrect title</p>
<p class="help-block text-danger"></p>
<div class="form-group d-flex justify-content-end"> <div class="form-group d-flex justify-content-end">
<input type="submit" id="add-deadline" name="add-deadline" <input type="submit" id="addDeadline" name="addDeadline"
class="btn btn-primary" class="btn btn-primary"
value="Добавить дедлайн"/> value="Добавить дедлайн"/>
</div> </div>

View File

@ -21,7 +21,7 @@
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3"> <div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3">
<a href="./conference?id=0" class="btn btn-light toolbar-button"> <a href="./conference?id=0" class="btn btn-light toolbar-button">
<i class="fa fa-plus-circle" aria-hidden="true"></i> <i class="fa fa-plus-circle" aria-hidden="true"></i>
Добавить конференцию</a> Новая конференцию</a>
</div> </div>
</div> </div>