#64 show global message

merge-requests/70/head
Anton Romanov 5 years ago
parent 6d6ea3136d
commit 8f2f6adc3b

@ -16,4 +16,7 @@ public interface ConferenceRepository extends JpaRepository<Conference, Integer>
@Query("SELECT c FROM Conference c WHERE c.beginDate > :date")
List<Conference> findAllActive(@Param("date") Date date);
@Query("SELECT case when count(c) > 0 then true else false end FROM Conference c JOIN c.papers p WHERE p.id = :paperId")
boolean isPaperAttached(@Param("paperId") Integer paperId);
}

@ -184,4 +184,8 @@ public class ConferenceService {
public List<Conference> findAllActive() {
return conferenceRepository.findAllActive(new Date());
}
public boolean isAttachedToConference(Integer paperId) {
return conferenceRepository.isPaperAttached(paperId);
}
}

@ -39,6 +39,11 @@ public class AdviceController {
return userService.getCurrentUser().getUserAbbreviate();
}
@ModelAttribute("flashMessage")
public String getFlashMessage() {
return null;
}
private Response<Void> handleException(ErrorConstants error) {
log.warn(error.toString());
return new Response<>(error);

@ -1,6 +1,5 @@
package ru.ulstu.paper.controller;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -9,14 +8,14 @@ import org.springframework.ui.ModelMap;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import ru.ulstu.conference.service.ConferenceService;
import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.model.PaperFilterDto;
import ru.ulstu.paper.model.PaperListDto;
import ru.ulstu.paper.service.LatexService;
import ru.ulstu.paper.service.PaperService;
import ru.ulstu.user.model.User;
@ -39,23 +38,34 @@ import static org.springframework.util.StringUtils.isEmpty;
@ApiIgnore
public class PaperController {
private final PaperService paperService;
private final ConferenceService conferenceService;
private final LatexService latexService;
public PaperController(PaperService paperService, LatexService latexService) {
public PaperController(PaperService paperService,
ConferenceService conferenceService,
LatexService latexService) {
this.paperService = paperService;
this.conferenceService = conferenceService;
this.latexService = latexService;
}
@GetMapping("/papers")
public void getPapers(ModelMap modelMap) {
modelMap.put("filteredPapers", new PaperFilterDto(paperService.findAllDto(), null, null));
modelMap.put("filteredPapers", new PaperListDto(paperService.findAllDto(), null, null));
}
@PostMapping("/papers")
public void filterPapers(@Valid PaperFilterDto paperFilterDto, ModelMap modelMap) {
modelMap.put("filteredPapers", new PaperFilterDto(paperService.filter(paperFilterDto),
paperFilterDto.getFilterAuthorId(),
paperFilterDto.getYear()));
public void listPapers(@Valid PaperListDto paperListDto, ModelMap modelMap) {
if (paperListDto.getPaperDeleteId() != null) {
if (conferenceService.isAttachedToConference(paperListDto.getPaperDeleteId())) {
modelMap.put("flashMessage", "Статью нельзя удалить, она прикреплена к конференции");
} else {
paperService.delete(paperListDto.getPaperDeleteId());
}
}
modelMap.put("filteredPapers", new PaperListDto(paperService.filter(paperListDto),
paperListDto.getFilterAuthorId(),
paperListDto.getYear()));
}
@GetMapping("/dashboard")
@ -95,19 +105,6 @@ public class PaperController {
return "/papers/paper";
}
@GetMapping("/delete/{paper-id}")
public String delete(@Valid PaperFilterDto paperFilterDto,
@PathVariable("paper-id") Integer paperId,
Errors errors) throws IOException {
try {
paperService.delete(paperId);
} catch (DataIntegrityViolationException e) {
errors.reject("relationExist", "Статья прикреплена к конференции");
return "/papers/papers";
}
return "redirect:/papers/papers";
}
@ModelAttribute("allStatuses")
public List<Paper.PaperStatus> getPaperStatuses() {
return paperService.getPaperStatuses();

@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RestController;
import ru.ulstu.configuration.Constants;
import ru.ulstu.core.model.response.Response;
import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.model.PaperFilterDto;
import ru.ulstu.paper.model.PaperListDto;
import ru.ulstu.paper.service.PaperService;
import javax.validation.Valid;
@ -58,8 +58,8 @@ public class PaperRestController {
}
@PostMapping("/filter")
public Response<List<PaperDto>> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException {
return new Response<>(paperService.filter(paperFilterDto));
public Response<List<PaperDto>> filter(@RequestBody @Valid PaperListDto paperListDto) throws IOException {
return new Response<>(paperService.filter(paperListDto));
}
@GetMapping("formatted-list")

@ -2,15 +2,16 @@ package ru.ulstu.paper.model;
import java.util.List;
public class PaperFilterDto {
public class PaperListDto {
private List<PaperDto> papers;
private Integer filterAuthorId;
private Integer paperDeleteId;
private Integer year;
public PaperFilterDto() {
public PaperListDto() {
}
public PaperFilterDto(List<PaperDto> paperDtos, Integer filterAuthorId, Integer year) {
public PaperListDto(List<PaperDto> paperDtos, Integer filterAuthorId, Integer year) {
this.papers = paperDtos;
this.filterAuthorId = filterAuthorId;
this.year = year;
@ -39,4 +40,12 @@ public class PaperFilterDto {
public void setYear(Integer year) {
this.year = year;
}
public Integer getPaperDeleteId() {
return paperDeleteId;
}
public void setPaperDeleteId(Integer paperDeleteId) {
this.paperDeleteId = paperDeleteId;
}
}

@ -9,7 +9,7 @@ import ru.ulstu.file.model.FileDataDto;
import ru.ulstu.file.service.FileService;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.model.PaperFilterDto;
import ru.ulstu.paper.model.PaperListDto;
import ru.ulstu.paper.repository.PaperRepository;
import ru.ulstu.timeline.service.EventService;
import ru.ulstu.user.model.User;
@ -181,7 +181,7 @@ public class PaperService {
return paper;
}
public List<PaperDto> filter(PaperFilterDto filterDto) {
public List<PaperDto> filter(PaperListDto filterDto) {
return convert(sortPapers(paperRepository.filter(
filterDto.getFilterAuthorId() == null ? null : userService.findById(filterDto.getFilterAuthorId()),
filterDto.getYear())), PaperDto::new);

@ -13,7 +13,8 @@ $(document).ready(function () {
});
$('a[data-confirm]').click(function(ev) {
var href = $(this).attr('href');
var id = $(this).parent().parent().find('.id-class').val();
if (!$('#dataConfirmModal').length) {
$('#modalDelete').append('<div class="modal fade" id="dataConfirmModal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true"\n' +
' >\n' +
@ -34,7 +35,10 @@ $(document).ready(function () {
' </div>');
}
$('#dataConfirmModal').find('#myModalLabel').text($(this).attr('data-confirm'));
$('#dataConfirmOK').attr('href', href);
$('#dataConfirmOK').click(function () {
$("#paperDeleteId").val(id);
$('form').submit();
});
$('#dataConfirmModal').modal({show:true});
return false;
});

@ -55,7 +55,8 @@
<a class="nav-link js-scroll-trigger" target="_blank" href="http://is.ulstu.ru">Сайт кафедры</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" target="_blank" th:href="@{'http://timetable.athene.tech?filter='+${currentUser}}">Расписание</a>
<a class="nav-link js-scroll-trigger" target="_blank"
th:href="@{'http://timetable.athene.tech?filter='+${currentUser}}">Расписание</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" target="_blank" href="https://kias.rfbr.ru/">КИАС РФФИ</a>
@ -97,36 +98,53 @@
<script src="/js/core.js"></script>
<script src="/js/config.js"></script>
<script src="/js/odin.js"></script>
<script th:inline="javascript">
/*<![CDATA[*/
var message = /*[[${flashMessage}]]*/ "";
if (message && message.length > 0) {
showFeedbackMessage(message, MessageTypesEnum.DANGER);
}
/*]]>*/
</script>
<th:block layout:fragment="scripts">
</th:block>
<!-- Yandex.Metrika counter -->
<script type="text/javascript" >
<script type="text/javascript">
(function (d, w, c) {
(w[c] = w[c] || []).push(function() {
(w[c] = w[c] || []).push(function () {
try {
w.yaCounter49387279 = new Ya.Metrika2({
id:49387279,
clickmap:true,
trackLinks:true,
accurateTrackBounce:true,
webvisor:true
id: 49387279,
clickmap: true,
trackLinks: true,
accurateTrackBounce: true,
webvisor: true
});
} catch(e) { }
} catch (e) {
}
});
var n = d.getElementsByTagName("script")[0],
s = d.createElement("script"),
f = function () { n.parentNode.insertBefore(s, n); };
f = function () {
n.parentNode.insertBefore(s, n);
};
s.type = "text/javascript";
s.async = true;
s.src = "https://mc.yandex.ru/metrika/tag.js";
if (w.opera == "[object Opera]") {
d.addEventListener("DOMContentLoaded", f, false);
} else { f(); }
} else {
f();
}
})(document, window, "yandex_metrika_callbacks2");
</script>
<noscript><div><img src="https://mc.yandex.ru/watch/49387279" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
<noscript>
<div><img src="https://mc.yandex.ru/watch/49387279" style="position:absolute; left:-9999px;" alt=""/></div>
</noscript>
<!-- /Yandex.Metrika counter -->
</body>
</html>

@ -12,8 +12,7 @@
<span class="text-muted" th:text="${paper.authorsString}"/>
</a>
<input class="id-class" type="hidden" th:value="${paper.id}"/>
<a class="remove-paper pull-right d-none" th:href="@{'/papers/delete/'+${paper.id}}"
data-confirm="Удалить статью?">
<a class="remove-paper pull-right d-none" href="#" data-confirm="Удалить статью?">
<i class="fa fa-trash" aria-hidden="true"></i>
</a>
</div>

Loading…
Cancel
Save