Merge branch '46-mvc' into 'master'

Resolve "Перевести на MVC контроллеры"

Closes #46

See merge request romanov73/ng-tracker!22
This commit is contained in:
Anton Romanov 2018-12-18 18:18:25 +00:00
commit 503f7f68bc
25 changed files with 615 additions and 446 deletions

View File

@ -116,6 +116,7 @@ dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7' compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
compile group: 'org.webjars', name: 'bootstrap', version: '4.1.0' compile group: 'org.webjars', name: 'bootstrap', version: '4.1.0'
compile group: 'org.webjars', name: 'bootstrap-select', version: '1.13.3'
compile group: 'org.webjars', name: 'jquery', version: '3.3.1-1' compile group: 'org.webjars', name: 'jquery', version: '3.3.1-1'
compile group: 'org.webjars.npm', name: 'jquery.easing', version: '1.4.1' compile group: 'org.webjars.npm', name: 'jquery.easing', version: '1.4.1'
compile group: 'org.webjars', name: 'font-awesome', version: '4.7.0' compile group: 'org.webjars', name: 'font-awesome', version: '4.7.0'

View File

@ -97,10 +97,4 @@ public class AdviceController {
public ResponseExtended<String> handleUserIsUndeadException(Throwable e) { public ResponseExtended<String> handleUserIsUndeadException(Throwable e) {
return handleException(ErrorConstants.USER_UNDEAD_ERROR, e.getMessage()); return handleException(ErrorConstants.USER_UNDEAD_ERROR, e.getMessage());
} }
@ExceptionHandler(Exception.class)
public ResponseExtended<String> handleUnknownException(Throwable e) {
e.printStackTrace();
return handleException(ErrorConstants.UNKNOWN, e.getMessage());
}
} }

View File

@ -2,15 +2,20 @@ package ru.ulstu.deadline.model;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date; import java.util.Date;
public class DeadlineDto { public class DeadlineDto {
private final Integer id; private Integer id;
private final String description; private String description;
private final Date date; @DateTimeFormat(pattern = "yyyy-MM-dd")
private Date date;
public DeadlineDto() {
}
@JsonCreator @JsonCreator
public DeadlineDto(@JsonProperty("id") Integer id, public DeadlineDto(@JsonProperty("id") Integer id,
@ -38,4 +43,16 @@ public class DeadlineDto {
public Date getDate() { public Date getDate() {
return date; return date;
} }
public void setId(Integer id) {
this.id = id;
}
public void setDescription(String description) {
this.description = description;
}
public void setDate(Date date) {
this.date = date;
}
} }

View File

@ -20,7 +20,7 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static ru.ulstu.paper.controller.PaperController.URL; import static ru.ulstu.file.FileController.URL;
@RestController @RestController
@RequestMapping(URL) @RequestMapping(URL)

View File

@ -1,70 +1,117 @@
package ru.ulstu.paper.controller; package ru.ulstu.paper.controller;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.GetMapping; 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.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RequestParam;
import ru.ulstu.configuration.Constants; import ru.ulstu.deadline.model.DeadlineDto;
import ru.ulstu.core.model.response.Response; import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.model.PaperFilterDto; import ru.ulstu.paper.model.PaperFilterDto;
import ru.ulstu.paper.model.PaperStatusDto;
import ru.ulstu.paper.service.PaperService; import ru.ulstu.paper.service.PaperService;
import ru.ulstu.user.model.User;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import static ru.ulstu.paper.controller.PaperController.URL; import static org.springframework.util.StringUtils.isEmpty;
@RestController
@RequestMapping(URL) @Controller()
@RequestMapping(value = "/papers")
public class PaperController { public class PaperController {
public static final String URL = Constants.API_1_0 + "papers";
private final PaperService paperService; private final PaperService paperService;
public PaperController(PaperService paperService) { public PaperController(PaperService paperService) {
this.paperService = paperService; this.paperService = paperService;
} }
@GetMapping @GetMapping("/papers")
public Response<List<PaperDto>> getPapers() { public void getPapers(ModelMap modelMap) {
return new Response<>(paperService.findAllDto()); modelMap.put("filteredPapers", new PaperFilterDto(paperService.findAllDto(), null, null));
} }
@GetMapping("/{paper-id}") @PostMapping("/papers")
public Response<PaperDto> getPaper(@PathVariable("paper-id") Integer paperId){ public void filterPapers(@Valid PaperFilterDto paperFilterDto, ModelMap modelMap) {
return new Response(paperService.findPaper(paperId)); modelMap.put("filteredPapers", new PaperFilterDto(paperService.filter(paperFilterDto),
paperFilterDto.getFilterAuthorId(),
paperFilterDto.getYear()));
} }
@PostMapping @GetMapping("/dashboard")
public Response<Integer> createPaper(@RequestBody @Valid PaperDto paperDto) throws IOException { public void getDashboard(ModelMap modelMap) {
return new Response<>(paperService.create(paperDto)); modelMap.put("papers", paperService.findAllDto());
} }
@PutMapping @GetMapping("/paper")
public Response<Integer> updatePaper(@RequestBody @Valid PaperDto paperDto) throws IOException { public void getPapers(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
return new Response<>(paperService.update(paperDto)); if (id != null && id > 0) {
modelMap.put("paperDto", paperService.findOneDto(id));
} else {
modelMap.put("paperDto", new PaperDto());
}
} }
@DeleteMapping("/{paper-id}") @PostMapping(value = "/paper", params = "save")
public Response<Boolean> delete(@PathVariable("paper-id") Integer paperId) throws IOException { public String save(@Valid PaperDto paperDto, Errors errors) throws IOException {
filterEmptyDeadlines(paperDto);
if (paperDto.getDeadlines().isEmpty()) {
errors.rejectValue("deadlines", "errorCode","Не может быть пустым");
}
if (errors.hasErrors()) {
return "/papers/paper";
}
paperService.save(paperDto);
return "redirect:/papers/papers";
}
@PostMapping(value = "/paper", params = "addDeadline")
public String addDeadline(@Valid PaperDto paperDto, Errors errors) {
filterEmptyDeadlines(paperDto);
if (errors.hasErrors()) {
return "/papers/paper";
}
paperDto.getDeadlines().add(new DeadlineDto());
return "/papers/paper";
}
@GetMapping("/delete/{paper-id}")
public String delete(@PathVariable("paper-id") Integer paperId) throws IOException {
paperService.delete(paperId); paperService.delete(paperId);
return new Response<>(true); return "redirect:/papers/papers";
} }
@GetMapping("/statuses") @ModelAttribute("allStatuses")
public Response<List<PaperStatusDto>> getPaperStatuses() { public List<Paper.PaperStatus> getPaperStatuses() {
return new Response<>(paperService.getPaperStatuses()); return paperService.getPaperStatuses();
} }
@PostMapping("/filter") @ModelAttribute("allAuthors")
public Response<List<PaperDto>> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException { public List<User> getAllAuthors() {
return new Response<>(paperService.filter(paperFilterDto)); return paperService.getPaperAuthors();
}
@ModelAttribute("allYears")
public List<Integer> getAllYears() {
List<Integer> years = new ArrayList<>();
for (int i = Calendar.getInstance().get(Calendar.YEAR); i > 2010; i-- ) {
years.add(i);
}
return years;
}
private void filterEmptyDeadlines(PaperDto paperDto) {
paperDto.setDeadlines(paperDto.getDeadlines().stream()
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
.collect(Collectors.toList()));
} }
} }

View File

@ -0,0 +1,64 @@
package ru.ulstu.paper.controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
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.service.PaperService;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
import static ru.ulstu.paper.controller.PaperRestController.URL;
@RestController
@RequestMapping(URL)
public class PaperRestController {
public static final String URL = Constants.API_1_0 + "papers";
private final PaperService paperService;
public PaperRestController(PaperService paperService) {
this.paperService = paperService;
}
@GetMapping
public Response<List<PaperDto>> getPapers() {
return new Response<>(paperService.findAllDto());
}
@GetMapping("/{paper-id}")
public Response<PaperDto> getPaper(@PathVariable("paper-id") Integer paperId){
return new Response(paperService.findById(paperId));
}
@PostMapping
public Response<Integer> createPaper(@RequestBody @Valid PaperDto paperDto) throws IOException {
return new Response<>(paperService.create(paperDto));
}
@PutMapping
public Response<Integer> updatePaper(@RequestBody @Valid PaperDto paperDto) throws IOException {
return new Response<>(paperService.update(paperDto));
}
@DeleteMapping("/{paper-id}")
public Response<Boolean> delete(@PathVariable("paper-id") Integer paperId) throws IOException {
paperService.delete(paperId);
return new Response<>(true);
}
@PostMapping("/filter")
public Response<List<PaperDto>> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException {
return new Response<>(paperService.filter(paperFilterDto));
}
}

View File

@ -16,6 +16,8 @@ import javax.persistence.FetchType;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany; import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
@ -36,14 +38,14 @@ public class Paper extends BaseEntity implements UserContainer {
COMPLETED("Завершена"), COMPLETED("Завершена"),
FAILED("Провалены сроки"); FAILED("Провалены сроки");
private String name; private String statusName;
PaperStatus(String name) { PaperStatus(String name) {
this.name = name; this.statusName = name;
} }
public String getName() { public String getStatusName() {
return name; return statusName;
} }
} }
@ -54,12 +56,14 @@ public class Paper extends BaseEntity implements UserContainer {
private PaperStatus status = PaperStatus.DRAFT; private PaperStatus status = PaperStatus.DRAFT;
@Column(name = "create_date") @Column(name = "create_date")
@Temporal(TemporalType.TIMESTAMP)
private Date createDate = new Date(); private Date createDate = new Date();
@Column(name = "update_date") @Column(name = "update_date")
@Temporal(TemporalType.TIMESTAMP)
private Date updateDate = new Date(); private Date updateDate = new Date();
@OneToMany(cascade = CascadeType.ALL) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "paper_id") @JoinColumn(name = "paper_id")
private List<Deadline> deadlines = new ArrayList<>(); private List<Deadline> deadlines = new ArrayList<>();
@ -154,6 +158,7 @@ public class Paper extends BaseEntity implements UserContainer {
public Optional<Deadline> getNextDeadline() { public Optional<Deadline> getNextDeadline() {
return deadlines return deadlines
.stream() .stream()
.filter(deadline -> deadline.getDate() != null)
.sorted(Comparator.comparing(Deadline::getDate)) .sorted(Comparator.comparing(Deadline::getDate))
.filter(d -> d.getDate().after(new Date())) .filter(d -> d.getDate().after(new Date()))
.findFirst(); .findFirst();

View File

@ -6,7 +6,8 @@ import org.hibernate.validator.constraints.NotEmpty;
import ru.ulstu.deadline.model.DeadlineDto; import ru.ulstu.deadline.model.DeadlineDto;
import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserDto;
import javax.validation.constraints.NotNull; import javax.validation.constraints.Size;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -15,20 +16,28 @@ import java.util.stream.Collectors;
import static ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.core.util.StreamApiUtils.convert;
public class PaperDto { public class PaperDto {
private final Integer id; private Integer id;
@NotEmpty @NotEmpty
private final String title; @Size(min = 3, max = 100)
private final Paper.PaperStatus status; private String title;
private final Date createDate; private Paper.PaperStatus status;
private final Date updateDate; private Date createDate;
private final List<DeadlineDto> deadlines; private Date updateDate;
private final String comment; @NotEmpty
private final Boolean locked; private List<DeadlineDto> deadlines = new ArrayList<>();
private final String tmpFileName; private String comment;
private final Integer fileId; private Boolean locked;
private final String fileName; private String tmpFileName;
private final Date fileCreateDate; private Integer fileId;
private final Set<UserDto> authors; private String fileName;
private Date fileCreateDate;
private Set<Integer> authorIds;
private Set<UserDto> authors;
private Integer filterAuthorId;
public PaperDto() {
deadlines.add(new DeadlineDto());
}
@JsonCreator @JsonCreator
public PaperDto(@JsonProperty("id") Integer id, public PaperDto(@JsonProperty("id") Integer id,
@ -40,6 +49,7 @@ public class PaperDto {
@JsonProperty("comment") String comment, @JsonProperty("comment") String comment,
@JsonProperty("locked") Boolean locked, @JsonProperty("locked") Boolean locked,
@JsonProperty("tmpFileName") String tmpFileName, @JsonProperty("tmpFileName") String tmpFileName,
@JsonProperty("authorIds") Set<Integer> authorIds,
@JsonProperty("authors") Set<UserDto> authors) { @JsonProperty("authors") Set<UserDto> authors) {
this.id = id; this.id = id;
this.title = title; this.title = title;
@ -69,6 +79,7 @@ public class PaperDto {
this.fileId = paper.getFileData() == null ? null : paper.getFileData().getId(); this.fileId = paper.getFileData() == null ? null : paper.getFileData().getId();
this.fileName = paper.getFileData() == null ? null : paper.getFileData().getName(); this.fileName = paper.getFileData() == null ? null : paper.getFileData().getName();
this.fileCreateDate = paper.getFileData() == null ? null : paper.getFileData().getCreateDate(); this.fileCreateDate = paper.getFileData() == null ? null : paper.getFileData().getCreateDate();
this.authorIds = convert(paper.getAuthors(), user -> user.getId());
this.authors = convert(paper.getAuthors(), UserDto::new); this.authors = convert(paper.getAuthors(), UserDto::new);
} }
@ -76,58 +87,126 @@ public class PaperDto {
return id; return id;
} }
public void setId(Integer id) {
this.id = id;
}
public String getTitle() { public String getTitle() {
return title; return title;
} }
public void setTitle(String title) {
this.title = title;
}
public Paper.PaperStatus getStatus() { public Paper.PaperStatus getStatus() {
return status; return status;
} }
public void setStatus(Paper.PaperStatus status) {
this.status = status;
}
public Date getCreateDate() { public Date getCreateDate() {
return createDate; return createDate;
} }
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public Date getUpdateDate() { public Date getUpdateDate() {
return updateDate; return updateDate;
} }
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public List<DeadlineDto> getDeadlines() { public List<DeadlineDto> getDeadlines() {
return deadlines; return deadlines;
} }
public void setDeadlines(List<DeadlineDto> deadlines) {
this.deadlines = deadlines;
}
public String getComment() { public String getComment() {
return comment; return comment;
} }
public void setComment(String comment) {
this.comment = comment;
}
public Boolean getLocked() { public Boolean getLocked() {
return locked; return locked;
} }
public void setLocked(Boolean locked) {
this.locked = locked;
}
public String getTmpFileName() { public String getTmpFileName() {
return tmpFileName; return tmpFileName;
} }
public void setTmpFileName(String tmpFileName) {
this.tmpFileName = tmpFileName;
}
public Integer getFileId() { public Integer getFileId() {
return fileId; return fileId;
} }
public void setFileId(Integer fileId) {
this.fileId = fileId;
}
public String getFileName() { public String getFileName() {
return fileName; return fileName;
} }
public void setFileName(String fileName) {
this.fileName = fileName;
}
public Date getFileCreateDate() { public Date getFileCreateDate() {
return fileCreateDate; return fileCreateDate;
} }
public void setFileCreateDate(Date fileCreateDate) {
this.fileCreateDate = fileCreateDate;
}
public Set<UserDto> getAuthors() { public Set<UserDto> getAuthors() {
return authors; return authors;
} }
public void setAuthors(Set<UserDto> authors) {
this.authors = authors;
}
public Set<Integer> getAuthorIds() {
return authorIds;
}
public void setAuthorIds(Set<Integer> authorIds) {
this.authorIds = authorIds;
}
public String getAuthorsString() { public String getAuthorsString() {
return authors return authors
.stream() .stream()
.map(author -> author.getLastName() + author.getFirstName()) .map(author -> author.getLastName())
.collect(Collectors.joining(", ")); .collect(Collectors.joining(", "));
} }
public Integer getFilterAuthorId() {
return filterAuthorId;
}
public void setFilterAuthorId(Integer filterAuthorId) {
this.filterAuthorId = filterAuthorId;
}
} }

View File

@ -1,24 +1,42 @@
package ru.ulstu.paper.model; package ru.ulstu.paper.model;
import com.fasterxml.jackson.annotation.JsonCreator; import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
public class PaperFilterDto { public class PaperFilterDto {
private final Integer authorId; private List<PaperDto> papers;
private final Integer year; private Integer filterAuthorId;
private Integer year;
@JsonCreator public PaperFilterDto() {
public PaperFilterDto(@JsonProperty("authorId") Integer authorId, }
@JsonProperty("year") Integer year) {
this.authorId = authorId; public PaperFilterDto(List<PaperDto> paperDtos, Integer filterAuthorId, Integer year) {
this.papers = paperDtos;
this.filterAuthorId = filterAuthorId;
this.year = year; this.year = year;
} }
public Integer getAuthorId() { public List<PaperDto> getPapers() {
return authorId; return papers;
}
public void setPapers(List<PaperDto> papers) {
this.papers = papers;
}
public Integer getFilterAuthorId() {
return filterAuthorId;
}
public void setFilterAuthorId(Integer filterAuthorId) {
this.filterAuthorId = filterAuthorId;
} }
public Integer getYear() { public Integer getYear() {
return year; return year;
} }
public void setYear(Integer year) {
this.year = year;
}
} }

View File

@ -1,19 +0,0 @@
package ru.ulstu.paper.model;
public class PaperStatusDto {
private final String id;
private final String name;
public PaperStatusDto(Paper.PaperStatus status) {
this.id = status.name();
this.name = status.getName();
}
public String getId() {
return id;
}
public String getName() {
return name;
}
}

View File

@ -10,6 +10,6 @@ import java.util.List;
public interface PaperRepository extends JpaRepository<Paper, Integer> { public interface PaperRepository extends JpaRepository<Paper, Integer> {
@Query("SELECT p FROM Paper p WHERE (:author IS NULL OR :author MEMBER OF p.authors) AND YEAR(p.createDate) = :year OR :year IS NULL") @Query("SELECT p FROM Paper p WHERE (:author IS NULL OR :author MEMBER OF p.authors) AND (YEAR(p.createDate) = :year OR :year IS NULL)")
List<Paper> filter(@Param("author") User author, @Param("year") Integer year); List<Paper> filter(@Param("author") User author, @Param("year") Integer year);
} }

View File

@ -7,7 +7,7 @@ import org.springframework.stereotype.Service;
@Service @Service
public class PaperScheduler { public class PaperScheduler {
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true; private final static boolean IS_DEADLINE_NOTIFICATION_AFTER_WEEK = true;
private final Logger log = LoggerFactory.getLogger(PaperScheduler.class); private final Logger log = LoggerFactory.getLogger(PaperScheduler.class);
@ -24,14 +24,14 @@ public class PaperScheduler {
@Scheduled(cron = "0 0 8 * 1 ?") @Scheduled(cron = "0 0 8 * 1 ?")
public void checkDeadlineBeforeWeek() { public void checkDeadlineBeforeWeek() {
log.debug("PaperScheduler.checkDeadlineBeforeWeek started"); log.debug("PaperScheduler.checkDeadlineBeforeWeek started");
paperNotificationService.sendDeadlineNotifications(paperService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); paperNotificationService.sendDeadlineNotifications(paperService.findAll(), !IS_DEADLINE_NOTIFICATION_AFTER_WEEK);
log.debug("PaperScheduler.checkDeadlineBeforeWeek finished"); log.debug("PaperScheduler.checkDeadlineBeforeWeek finished");
} }
@Scheduled(cron = "0 0 8 * * ?") @Scheduled(cron = "0 0 8 * * ?")
public void checkDeadlineAfterWeek() { public void checkDeadlineAfterWeek() {
log.debug("PaperScheduler.checkDeadlineAfterWeek started"); log.debug("PaperScheduler.checkDeadlineAfterWeek started");
paperNotificationService.sendDeadlineNotifications(paperService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); paperNotificationService.sendDeadlineNotifications(paperService.findAll(), IS_DEADLINE_NOTIFICATION_AFTER_WEEK);
log.debug("PaperScheduler.checkDeadlineAfterWeek finished"); log.debug("PaperScheduler.checkDeadlineAfterWeek finished");
} }

View File

@ -8,7 +8,6 @@ import ru.ulstu.file.service.FileService;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.model.PaperFilterDto; import ru.ulstu.paper.model.PaperFilterDto;
import ru.ulstu.paper.model.PaperStatusDto;
import ru.ulstu.paper.repository.PaperRepository; import ru.ulstu.paper.repository.PaperRepository;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserService;
@ -16,9 +15,12 @@ import ru.ulstu.user.service.UserService;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.springframework.util.ObjectUtils.isEmpty;
import static ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.core.util.StreamApiUtils.convert;
import static ru.ulstu.paper.model.Paper.PaperStatus.ATTENTION; import static ru.ulstu.paper.model.Paper.PaperStatus.ATTENTION;
import static ru.ulstu.paper.model.Paper.PaperStatus.DRAFT; import static ru.ulstu.paper.model.Paper.PaperStatus.DRAFT;
@ -60,6 +62,10 @@ public class PaperService {
return convert(findAll(), PaperDto::new); return convert(findAll(), PaperDto::new);
} }
public PaperDto findOneDto(Integer id) {
return new PaperDto(paperRepository.findOne(id));
}
@Transactional @Transactional
public Integer create(PaperDto paperDto) throws IOException { public Integer create(PaperDto paperDto) throws IOException {
Paper newPaper = copyFromDto(new Paper(), paperDto); Paper newPaper = copyFromDto(new Paper(), paperDto);
@ -79,8 +85,9 @@ public class PaperService {
if (paperDto.getTmpFileName() != null) { if (paperDto.getTmpFileName() != null) {
paper.setFileData(fileService.createFileFromTmp(paperDto.getTmpFileName())); paper.setFileData(fileService.createFileFromTmp(paperDto.getTmpFileName()));
} }
if (paperDto.getAuthors() != null && !paperDto.getAuthors().isEmpty()) { paper.getAuthors().clear();
paperDto.getAuthors().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds.getId()))); if (paperDto.getAuthorIds() != null && !paperDto.getAuthorIds().isEmpty()) {
paperDto.getAuthorIds().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds)));
} }
return paper; return paper;
} }
@ -89,11 +96,18 @@ public class PaperService {
public Integer update(PaperDto paperDto) throws IOException { public Integer update(PaperDto paperDto) throws IOException {
Paper paper = paperRepository.findOne(paperDto.getId()); Paper paper = paperRepository.findOne(paperDto.getId());
Paper.PaperStatus oldStatus = paper.getStatus(); Paper.PaperStatus oldStatus = paper.getStatus();
Set<User> oldAuthors = new HashSet<>(paper.getAuthors());
if (paperDto.getTmpFileName() != null && paper.getFileData() != null) { if (paperDto.getTmpFileName() != null && paper.getFileData() != null) {
fileService.deleteFile(paper.getFileData()); fileService.deleteFile(paper.getFileData());
} }
paperRepository.save(copyFromDto(paper, paperDto)); paperRepository.save(copyFromDto(paper, paperDto));
paper.getAuthors().forEach(author -> {
if (!oldAuthors.contains(author)) {
paperNotificationService.sendCreateNotification(paper);
}
});
if (paper.getStatus() != oldStatus) { if (paper.getStatus() != oldStatus) {
paperNotificationService.statusChangeNotification(paper, oldStatus); paperNotificationService.statusChangeNotification(paper, oldStatus);
} }
@ -110,8 +124,8 @@ public class PaperService {
paperRepository.delete(paper); paperRepository.delete(paper);
} }
public List<PaperStatusDto> getPaperStatuses() { public List<Paper.PaperStatus> getPaperStatuses() {
return convert(Arrays.asList(Paper.PaperStatus.values()), PaperStatusDto::new); return Arrays.asList(Paper.PaperStatus.values());
} }
@Transactional @Transactional
@ -131,10 +145,12 @@ public class PaperService {
} }
public List<PaperDto> filter(PaperFilterDto filterDto) { public List<PaperDto> filter(PaperFilterDto filterDto) {
return convert(paperRepository.filter(userService.findById(filterDto.getAuthorId()), filterDto.getYear()), PaperDto::new); return convert(paperRepository.filter(
filterDto.getFilterAuthorId() == null ? null : userService.findById(filterDto.getFilterAuthorId()),
filterDto.getYear()), PaperDto::new);
} }
public PaperDto findPaper(int id){ public PaperDto findPaper(int id) {
return new PaperDto(paperRepository.getOne(id)); return new PaperDto(paperRepository.getOne(id));
} }
@ -154,4 +170,20 @@ public class PaperService {
paperNotificationService.sendFailedNotification(paper, oldStatus); paperNotificationService.sendFailedNotification(paper, oldStatus);
}); });
} }
public void save(PaperDto paperDto) throws IOException {
if (isEmpty(paperDto.getId())) {
create(paperDto);
} else {
update(paperDto);
}
}
public PaperDto findById(Integer paperId) {
return new PaperDto(paperRepository.findOne(paperId));
}
public List<User> getPaperAuthors() {
return userService.findAll();
}
} }

View File

@ -23,4 +23,10 @@
constraintName="fk_event_child_event" referencedTableName="event" constraintName="fk_event_child_event" referencedTableName="event"
referencedColumnNames="id"/> referencedColumnNames="id"/>
</changeSet> </changeSet>
<changeSet author="orion" id="20181126_000000-4">
<modifyDataType
columnName="deadline_date"
newDataType="date"
tableName="paper"/>
</changeSet>
</databaseChangeLog> </databaseChangeLog>

View File

@ -11,7 +11,7 @@
</p> </p>
<p> <p>
Статус статьи "<span th:text="${paper.title}">Title</span>" сменился с Статус статьи "<span th:text="${paper.title}">Title</span>" сменился с
"<span th:text="${oldStatus.name}">oldStatus</span>" на "<span th:text="${paper.status.name}">newStatus</span>". "<span th:text="${oldStatus.statusName}">oldStatus</span>" на "<span th:text="${paper.status.statusName}">newStatus</span>".
</p> </p>
<p> <p>
Regards, Regards,

View File

@ -50,7 +50,7 @@ section {
} }
section h2.section-heading { section h2.section-heading {
font-size: 40px; font-size: 3.5vw;
margin-top: 0; margin-top: 0;
margin-bottom: 15px; margin-bottom: 15px;
} }

View File

@ -1,144 +1,42 @@
var urlPapers = "/api/1.0/papers"; /*<![CDATA[*/
var urlPaperStatuses = "/api/1.0/papers/statuses"; $(document).ready(function () {
var urlDeletePaper = "/api/1.0/papers/"; $(".paper-row").mouseenter(function (event) {
var urlFilterPaper = "/api/1.0/papers/filter" var paperRow = $(event.target).closest(".paper-row");
$(paperRow).css("background-color", "#f8f9fa");
$(paperRow).find(".remove-paper").removeClass("d-none");
function showPapers(papersElement, paperRowClass) {
getFromRest(urlPapers, function (paperList) {
paperList.forEach(function (paper, index) {
$(papersElement).parent().append("<div class='row text-left paper-row'>" +
" <div class='col'>" +
" <span class='fa-stack fa-1x'>\n" +
" <i class='fa fa-circle fa-stack-2x " + getPaperStatusClass(paper.status) + "'></i>" +
" <i class='fa fa-file-text-o fa-stack-1x fa-inverse'></i>" +
" </span>" +
" <a href='paper?id=" + paper.id + "" +
"'><span>" + (index + 1) + ". " + paper.title + "</span></a>" +
"<span class='remove-paper d-none pull-right' onclick=\"deletePaper(" + paper.id + ",'" + papersElement + "', '" + paperRowClass + "')\">" +
"<i class=\"fa fa-trash\" aria-hidden=\"true\"></i></span>" +
"</div></div>");
});
$(paperRowClass).mouseenter(function (event) {
var paperRow = $(event.target).closest(paperRowClass);
$(paperRow).css("background-color", "#f8f9fa");
$(paperRow).find(".remove-paper").removeClass("d-none");
});
$(paperRowClass).mouseleave(function (event) {
var paperRow = $(event.target).closest(paperRowClass);
$(paperRow).css("background-color", "white");
$(paperRow).closest(paperRowClass).find(".remove-paper").addClass("d-none");
});
}); });
} $(".paper-row").mouseleave(function (event) {
var paperRow = $(event.target).closest(".paper-row");
function filterPapers(papersElement, paperRowClass, authorId, year) { $(paperRow).css("background-color", "white");
var paperData = JSON.stringify({ $(paperRow).closest(".paper-row").find(".remove-paper").addClass("d-none");
"authorId": authorId,
"year": year
});
postToRest(urlFilterPaper, paperData, function (data) {
$(paperRowClass).remove();
if(data.length > 0){
data.forEach(function (paper, index) {
$(papersElement).parent().append("<div class='row text-left paper-row'>" +
" <div class='col-md-11'>" +
" <span class='fa-stack fa-1x'>\n" +
" <i class='fa fa-circle fa-stack-2x " + getPaperStatusClass(paper.status) + "'></i>" +
" <i class='fa fa-file-text-o fa-stack-1x fa-inverse'></i>" +
" </span>" +
" <a href='paper?id=" + paper.id + "" +
"'><span>" + paper.title + "</span></a></div>" +
"<div class='col-md-1'>" +
"<span class='remove-paper d-none' onclick=\"deletePaper(" + paper.id + ",'" + papersElement + "', '" + paperRowClass + "')\">" +
"<i class=\"fa fa-trash\" aria-hidden=\"true\"></i></span>" +
" </div></div>");
});
$(paperRowClass).mouseenter(function (event) {
var paperRow = $(event.target).closest(paperRowClass);
$(paperRow).css("background-color", "#f8f9fa");
$(paperRow).find(".remove-paper").removeClass("d-none");
});
$(paperRowClass).mouseleave(function (event) {
var paperRow = $(event.target).closest(paperRowClass);
$(paperRow).css("background-color", "white");
$(paperRow).closest(paperRowClass).find(".remove-paper").addClass("d-none");
});
}
}); });
$('a[data-confirm]').click(function(ev) {
var href = $(this).attr('href');
if (!$('#dataConfirmModal').length) {
$('#modalDelete').append('<div class="modal fade" id="dataConfirmModal" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true"\n' +
' >\n' +
' <div class="modal-dialog modal-sm">\n' +
' <div class="modal-content">\n' +
' <div class="modal-header">\n' +
' <h8 class="modal-title" id="myModalLabel">Удалить статью?</h8>\n' +
' <button type="button" class="close" data-dismiss="modal" aria-label="Закрыть"><span\n' +
' aria-hidden="true">&times;</span></button>\n' +
' </div>\n' +
} ' <div class="modal-footer">\n' +
' <a class="btn btn-primary" id="dataConfirmOK">Да</a>'+
function deletePaper(id, papersElement, paperRowClass) { ' <button class="btn primary" data-dismiss="modal" aria-hidden="true">Нет</button>'+
$("#remove-paper-modal").modal('show'); ' </div>\n' +
' </div>\n' +
$("#modal-btn-yes").on("click", function () { ' </div>\n' +
deleteFromRest(urlDeletePaper + id, function () { ' </div>');
showFeedbackMessage("Статья удалена"); }
$(paperRowClass).remove(); $('#dataConfirmModal').find('#myModalLabel').text($(this).attr('data-confirm'));
showPapers(papersElement, paperRowClass); $('#dataConfirmOK').attr('href', href);
}); $('#dataConfirmModal').modal({show:true});
$("#remove-paper-modal").modal('hide'); return false;
}); });
});
$("#modal-btn-no").on("click", function () { /*]]>*/
$("#remove-paper-modal").modal('hide');
});
}
function addPaper(title, status, datePublish, dateUpdate, deadline, comment, locked, tmpFileName, authors) {
var paperData = JSON.stringify({
"title": title,
"status": status,
"deadlineDate":deadline,
"comment": comment
});
postToRest(urlPapers, paperData, function (data) {
alert(data);
});
}
function getPaperStatusClass(status) {
switch (status) {
case 'DRAFT':
return "text-draft"
case 'ON_PREPARATION':
return "text-primary";
case 'ON_REVIEW':
return "text-primary";
case 'COMPLETED':
return "text-success";
case 'ATTENTION':
return "text-warning";
case 'FAILED':
return "text-failed";
default:
return "";
}
}
function showPaperDashboard(dashboardElement) {
getFromRest(urlPapers, function (paperList) {
paperList.forEach(function (paper, index) {
$(dashboardElement).append("<div class=\"col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3 dashboard-card\">" +
"<div class=\"row\">" +
"<div class=\"col-2\">" +
"<span class=\"fa-stack fa-1x\">" +
"<i class=\"fa fa-circle fa-stack-2x " + getPaperStatusClass(paper.status) + "\"></i>" +
"<i class=\"fa fa-file-text-o fa-stack-1x fa-inverse\"></i>" +
"</span>" +
"</div>" +
"<div class=\"col col-10 text-right\">" +
"<h7 class=\"service-heading\">" + paper.title + "</h7>" +
"<p class=\"text-muted\">" + paper.authorsString + "</p>" +
"</div>" +
"</div>" +
"</div>");
});
});
}

View File

@ -12,6 +12,7 @@
<!-- Bootstrap core CSS --> <!-- Bootstrap core CSS -->
<link rel="stylesheet" href="/webjars/bootstrap/4.1.0/css/bootstrap.min.css"/> <link rel="stylesheet" href="/webjars/bootstrap/4.1.0/css/bootstrap.min.css"/>
<link rel="stylesheet" href="/webjars/bootstrap-select/1.13.3/css/bootstrap-select.min.css"/>
<link rel="stylesheet" href="/webjars/font-awesome/4.7.0/css/font-awesome.min.css"/> <link rel="stylesheet" href="/webjars/font-awesome/4.7.0/css/font-awesome.min.css"/>
<!-- Custom fonts for this template --> <!-- Custom fonts for this template -->
@ -25,6 +26,7 @@
<!-- Bootstrap core JavaScript --> <!-- Bootstrap core JavaScript -->
<script src="/webjars/jquery/3.3.1-1/jquery.min.js"></script> <script src="/webjars/jquery/3.3.1-1/jquery.min.js"></script>
<script src="/webjars/bootstrap/4.1.0/js/bootstrap.bundle.min.js"></script> <script src="/webjars/bootstrap/4.1.0/js/bootstrap.bundle.min.js"></script>
<script src="/webjars/bootstrap-select/1.13.3/js/bootstrap-select.min.js"></script>
<!-- Plugin JavaScript --> <!-- Plugin JavaScript -->
<script src="/webjars/jquery.easing/1.4.1/jquery.easing.js"></script> <script src="/webjars/jquery.easing/1.4.1/jquery.easing.js"></script>
@ -88,8 +90,6 @@
</div> </div>
</footer> </footer>
<!-- Custom scripts for this template -->
<script src="/js/agency.js"></script>
<script src="/js/core.js"></script> <script src="/js/core.js"></script>
<!-- Yandex.Metrika counter --> <!-- Yandex.Metrika counter -->
<script type="text/javascript" > <script type="text/javascript" >

View File

@ -175,7 +175,6 @@
</div> </div>
</section> </section>
<script type="text/javascript" src="/js/file-loader.js"></script> <script type="text/javascript" src="/js/file-loader.js"></script>
<script src="/js/papers.js"></script>
<script> <script>
/*<![CDATA[*/ /*<![CDATA[*/
$(document).ready(function () { $(document).ready(function () {

View File

@ -1,45 +1,25 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" <html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="default"> layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml">
<head> <head>
</head> </head>
<body> <body>
<div class="container" layout:fragment="content"> <div class="container" layout:fragment="content">
<!-- Services -->
<section id="services"> <section id="services">
<div class="container"> <div class="container">
<div class="col-lg-12 text-center"> <div class="col-lg-12 text-center">
<h2 class="section-heading text-uppercase">Статьи</h2> <h2 class="section-heading text-uppercase">Статьи</h2>
<div th:replace="papers/fragments/paperNavigationFragment"/>
<div class="row justify-content-center">
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3">
<a href="./papers" class="btn btn-light toolbar-button"><i class="fa fa-list-alt"></i>
Список</a>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3">
<a href="./dashboard" class="btn btn-light toolbar-button"><i class="fa fa-newspaper-o"
aria-hidden="true"></i> Панель управления</a>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3">
<a href="./paper" class="btn btn-light toolbar-button"><i class="fa fa-plus-circle" aria-hidden="true"></i>
Добавить статью</a>
</div>
</div>
</div> </div>
<div class="row justify-content-center" id="dashboard"> <div class="row justify-content-center" id="dashboard">
<th:block th:each="paper : ${papers}">
<div th:replace="papers/fragments/paperDashboardFragment :: titleLine(paper=${paper})"/>
</th:block>
</div> </div>
</div> </div>
</section> </section>
<script src="/js/papers.js"></script>
<script>
$(document).ready(function () {
showPaperDashboard("#dashboard");
});
</script>
</div> </div>
</body> </body>
</html> </html>

View File

@ -0,0 +1,43 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head th:fragment="headerfiles">
<meta charset="UTF-8"/>
</head>
<body>
<div th:fragment="titleLine (paper)" class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3 dashboard-card">
<div class="row">
<div class="col-2">
<span class="fa-stack fa-1x">
<th:block th:switch="${paper.status.name()}">
<div th:case="'ATTENTION'">
<i class="fa fa-circle fa-stack-2x text-warning"></i>
</div>
<div th:case="'DRAFT'">
<i class="fa fa-circle fa-stack-2x text-draft"></i>
</div>
<div th:case="'ON_PREPARATION'">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
</div>
<div th:case="'ON_REVIEW'">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
</div>
<div th:case="'COMPLETED'">
<i class="fa fa-circle fa-stack-2x text-success"></i>
</div>
<div th:case="'FAILED'">
<i class="fa fa-circle fa-stack-2x text-failed"></i>
</div>
</th:block>
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
</span>
</div>
<div class="col col-10 text-right">
<h7 class="service-heading" th:text="${paper.title}"> title</h7>
<p class="text-muted" th:text="${paper.authorsString}">authors</p>
</div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,46 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head th:fragment="headerfiles">
<meta charset="UTF-8"/>
</head>
<body>
<div th:fragment="titleLine (paper)" class="row text-left paper-row" style="background-color: white;">
<div class="col">
<span class="fa-stack fa-1x">
<th:block th:switch="${paper.status.name()}">
<div th:case="'ATTENTION'">
<i class="fa fa-circle fa-stack-2x text-warning"></i>
</div>
<div th:case="'DRAFT'">
<i class="fa fa-circle fa-stack-2x text-draft"></i>
</div>
<div th:case="'ON_PREPARATION'">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
</div>
<div th:case="'ON_REVIEW'">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
</div>
<div th:case="'COMPLETED'">
<i class="fa fa-circle fa-stack-2x text-success"></i>
</div>
<div th:case="'FAILED'">
<i class="fa fa-circle fa-stack-2x text-failed"></i>
</div>
</th:block>
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
</span>
<a th:href="@{'paper?id='+${paper.id}}">
<span class="h6" th:text="${paper.title}"/>
<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="Удалить статью?">
<i class="fa fa-trash" aria-hidden="true"></i>
</a>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,27 @@
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head th:fragment="headerfiles">
<meta charset="UTF-8"/>
</head>
<body>
<div class="row justify-content-center">
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3">
<a href="./papers" class="btn btn-light toolbar-button"><i class="fa fa-list-alt"></i>
Список</a>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3">
<a href="./dashboard" class="btn btn-light toolbar-button"><i class="fa fa-newspaper-o"
aria-hidden="true"></i> Панель
управления</a>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3">
<a href="./paper?id=0" class="btn btn-light toolbar-button"><i class="fa fa-plus-circle"
aria-hidden="true"></i>
Добавить статью</a>
</div>
</div>
</body>
</html>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" <html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="default"> layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
<head> <head>
</head> </head>
@ -14,127 +14,100 @@
<div class="row"> <div class="row">
<div class="col-lg-12 text-center"> <div class="col-lg-12 text-center">
<h2 class="section-heading text-uppercase">Редактирование статьи</h2> <h2 class="section-heading text-uppercase">Редактирование статьи</h2>
</div> <div th:replace="papers/fragments/paperNavigationFragment"/>
</div>
<div class="row">
<div class="col-lg-10 text-center">
</div>
<div class="col-lg-2 text-center">
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
<form id="contactForm" name="sentMessage" novalidate=""> <form id="paper-form" method="post" th:action="@{'/papers/paper?id='+ *{id == null ? '' : id} + ''}"
th:object="${paperDto}">
<div class="row"> <div class="row">
<div class="col-md-6 col-sm-12"> <div class="col-md-6 col-sm-12">
<input type="hidden" name="id" th:field="*{id}"/>
<div class="form-group"> <div class="form-group">
<label for="name">Название:</label> <label for="title">Название:</label>
<input class="form-control" id="name" type="text" placeholder="Название статьи" <input class="form-control" id="title" type="text"
required="" data-validation-required-message="Введите название статьи"/> placeholder="Название статьи"
th:field="*{title}"/>
<p th:if="${#fields.hasErrors('title')}" th:errors="*{title}"
class="alert alert-danger">Incorrect title</p>
<p class="help-block text-danger"></p> <p class="help-block text-danger"></p>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="status">Статус:</label> <label for="status">Статус:</label>
<select class="form-control" id="status"> <select class="form-control" th:field="*{status}" id="status">
<option th:each="status : ${allStatuses}" th:value="${status}"
th:text="${status.statusName}">Status
</option>
</select> </select>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="comment">Комментарий:</label> <label for="comment">Комментарий:</label>
<textarea class="form-control" rows="5" id="comment"></textarea> <textarea class="form-control" rows="5" id="comment"
th:field="*{comment}"></textarea>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Дедлайн:</label> <label>Дедлайны:</label>
<input type="date" class="form-control" name="deadline" id="deadline"/> <div class="row" th:each="deadline, rowStat : *{deadlines}">
<input type="hidden" th:field="*{deadlines[__${rowStat.index}__].id}"/>
<div class="col-6">
<input type="date" class="form-control" name="deadline"
th:field="*{deadlines[__${rowStat.index}__].date}"/>
</div>
<div class="col-4">
<input class="form-control" type="text" placeholder="Описание"
th:field="*{deadlines[__${rowStat.index}__].description}"/>
</div>
<div class="col-2">
<a class="btn btn-danger float-right"
th:onclick="|$('#deadlines${rowStat.index}\\.description').val('');
$('#deadlines${rowStat.index}\\.date').val('');
$('#addDeadline').click();|"><span
aria-hidden="true"><i class="fa fa-times"/></span>
</a>
</div>
</div>
<p th:if="${#fields.hasErrors('deadlines')}" th:errors="*{deadlines}"
class="alert alert-danger">Incorrect title</p>
</div>
<div class="form-group">
<input type="submit" id="addDeadline" name="addDeadline" class="btn btn-primary" value="Добавить
дедлайн"/>
</div> </div>
<div class="form-check"> <div class="form-check">
<input type="checkbox" class="form-check-input" id="locked"/> <input type="checkbox" class="form-check-input" id="locked"
th:field="*{locked}"/>
<label class="form-check-label" for="locked">Заблокирована</label> <label class="form-check-label" for="locked">Заблокирована</label>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="loader" id="loader">Загрузить статью:</label> <label for="loader">Загрузить статью:</label>
<!--<div id="loader"> <div id="loader">
</div>--> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Дата публикации:</label> <label>Дата создания:</label>
<input type="date" class="form-control" name="date-publish" id="date-publish"/> <span th:text="${paperDto.createDate == null ? '' : #dates.format(paperDto.createDate, 'dd.MM.yyyy HH:mm')}">text</span>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Последнее изменение:</label> <label>Последнее изменение:</label>
<input type="date" class="form-control" name="date-update" id="date-update"/> <span th:text="${paperDto.updateDate == null ? '' : #dates.format(paperDto.updateDate, 'dd.MM.yyyy HH:mm')}">text</span>
</div> </div>
<p><a href="#myModal1" class="btn btn-primary" data-toggle="modal">Редактировать авторов <div class="form-group">
статьи</a></p> <label>Редактировать авторов статьи:</label>
<div id="myModal1" class="modal fade"> <select class="selectpicker form-control" multiple="true" data-live-search="true"
<div class="modal-dialog"> title="-- Выберите авторов --"
<div class="modal-content"> th:field="*{authorIds}">
<div class="modal-header"> <option th:each="author: ${allAuthors}" th:value="${author.id}"
<button type="button" class="close" data-dismiss="modal" th:text="${author.lastName}">Status
aria-hidden="true">× </option>
</button> </select>
<h4 class="modal-title">Авторы статьи</h4> <p th:if="${#fields.hasErrors('authorIds')}" th:errors="*{authorIds}"
</div> class="alert alert-danger">Incorrect title</p>
<div class="modal-body">
<table class="table">
<thead>
<tr>
<th>Фамилия</th>
<th>Имя</th>
<th>Отчество</th>
</tr>
</thead>
<tbody>
<tr>
<td>Иванов</td>
<td>Иван</td>
<td>Иванович</td>
<td>
<span class="table-remove"><button type="button"
class="btn btn-danger btn-rounded btn-sm my-0">Remove</button></span>
</td>
</tr>
<tr>
<td>text</td>
<td>text</td>
<td>text</td>
<td>
<span class="table-remove"><button type="button"
class="btn btn-danger btn-rounded btn-sm my-0">Remove</button></span>
</td>
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle"
type="button" data-toggle="dropdown">Выберите автора
<span class="caret"></span></button>
<ul class="dropdown-menu">
<input class="form-control" id="myInput" type="text"
placeholder="Search.."/>
<li><a href="#">Иванов</a></li>
<li><a href="#">Смирнов</a></li>
<li><a href="#">Кузнецов</a></li>
</ul>
</div>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Сохранить изменения
</button>
<button type="button" class="btn btn-default" data-dismiss="modal">
Отмена
</button>
</div>
</div>
</div>
</div> </div>
</div> </div>
<div class="col-md-3 offset-md-3 col-sm-12 offset-sm-0"> <div class="col-md-3 offset-md-3 col-sm-12 offset-sm-0">
@ -148,14 +121,15 @@
<div class="clearfix"></div> <div class="clearfix"></div>
<div class="col-lg-12"> <div class="col-lg-12">
<div class="form-group"> <div class="form-group">
<button id="sendMessageButton" class="btn btn-success text-uppercase" <button id="sendMessageButton" name="save" class="btn btn-success text-uppercase"
type="button" onclick="savePaper();" > type="submit">
Сохранить Сохранить
</button> </button>
<button id="cancelButton" class="btn btn-default text-uppercase" type="button"> <a id="cancelButton" class="btn btn-default text-uppercase" href="/papers/papers">
Отмена Отмена
</button> </a>
</div> </div>
</div> </div>
</div> </div>
</form> </form>
@ -164,7 +138,6 @@
</div> </div>
</section> </section>
<script type="text/javascript" src="/js/file-loader.js"></script> <script type="text/javascript" src="/js/file-loader.js"></script>
<script src="/js/papers.js"></script>
<script> <script>
/*<![CDATA[*/ /*<![CDATA[*/
$(document).ready(function () { $(document).ready(function () {
@ -178,25 +151,8 @@
console.debug(response); console.debug(response);
} }
}); });
$('.selectpicker').selectpicker();
getFromRest(urlPaperStatuses, function (response) {
fillSelect($("#status"), response);
});
}); });
function savePaper(){
var title = document.getElementById("name").value;
var status = document.getElementById("status").value;
var datePublish = document.getElementById("date-publish").value;
var dateUpdate = document.getElementById("date-update").value;
var deadline = document.getElementById("deadline").value;
var comment = document.getElementById("comment").value;
var locked = document.getElementById("locked").value;
var tmpFileName = document.getElementById("loader").value;
var authors = document.getElementById("myInput").value;
addPaper(title,status,datePublish,dateUpdate,deadline,comment,locked,tmpFileName,authors);
}
/*]]>*/ /*]]>*/
</script> </script>
</div> </div>

View File

@ -1,82 +1,58 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" <html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="default"> layout:decorator="default" xmlns:th="">
<head> <head>
</head> </head>
<body> <body>
<div class="container" layout:fragment="content"> <div class="container" layout:fragment="content">
<section id="papers"> <form id="papers-form" method="post" th:action="@{'/papers/papers'}">
<div class="container"> <input th:type="hidden" name="paperDeleteId" id="paperDeleteId"/>
<div class="row" id="paper-list"> <section id="papers">
<div class="col-lg-12 text-center"> <div class="container">
<h2 class="section-heading text-uppercase">Статьи</h2> <div class="row" id="paper-list">
<div class="col-lg-12 text-center">
<div class="row justify-content-center"> <h2 class="section-heading text-uppercase">Статьи</h2>
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3"> <div th:replace="papers/fragments/paperNavigationFragment"/>
<a href="./papers" class="btn btn-light toolbar-button"><i class="fa fa-list-alt"></i>
Список</a>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3">
<a href="./dashboard" class="btn btn-light toolbar-button"><i class="fa fa-newspaper-o"
aria-hidden="true"></i> Панель управления</a>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3">
<a href="./paper" class="btn btn-light toolbar-button"><i class="fa fa-plus-circle" aria-hidden="true"></i>
Добавить статью</a>
</div>
</div> </div>
<div class = "filter"> </div>
<h5>Фильтровать по:</h5> <div class="row">
<select id = "author"> <div class="col-md-9 col-sm-12">
<option value = "1">Алёна</option> <th:block th:each="paper : ${filteredPapers.papers}">
<option value = "2">Маша</option> <div th:replace="papers/fragments/paperLineFragment :: titleLine(paper=${paper})"/>
<option value = "3">Петя</option> </th:block>
</select> </div>
<select id = "index score"> <div class="col-md-3 col-sm-12">
<option >РИНЦ</option> <div class="filter">
<option>Scopus</option> <h5>Фильтр:</h5>
<option>Web of science</option> <select class="form-control" th:field="${filteredPapers.filterAuthorId}" id="author"
</select> onchange="this.form.submit();">
<select id = "year"> <option value="">Все авторы </option>
<option>2018</option> <option th:each="author: ${allAuthors}" th:value="${author.id}"
<option>2017</option> th:text="${author.lastName}">lastName
<option>2016</option> </option>
</select> </select>
<select class="form-control" id="year" th:field="${filteredPapers.year}" onchange="this.form.submit();">
<option value="">Все годы</option>
<option th:each="year: ${allYears}" th:value="${year}"
th:text="${year}">year
</option>
</select>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </section>
</section>
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" id="remove-paper-modal"> <div id="modalDelete"/>
<div class="modal-dialog modal-sm"> </form>
<div class="modal-content">
<div class="modal-header">
<h8 class="modal-title" id="myModalLabel">Удалить статью?</h8>
<button type="button" class="close" data-dismiss="modal" aria-label="Закрыть"><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" id="modal-btn-yes">Да</button>
<button type="button" class="btn btn-primary" id="modal-btn-no">Нет</button>
</div>
</div>
</div>
</div>
<script src="/js/papers.js"></script> <script src="/js/papers.js"></script>
<script>
$(document).ready(function () {
showPapers("#paper-list", ".paper-row");
jQuery('.filter').on('change','#year',function(){
filterPapers("#paper-list", ".paper-row",'1','2018'); <script type="text/javascript">
});
});
</script> </script>
</div> </div>
</body> </body>