From 90799356abb70d879df883f4000c9b876b29e44a Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Sun, 19 May 2019 00:42:24 +0400 Subject: [PATCH 01/13] 89 password reset --- .../ru/ulstu/configuration/Constants.java | 1 + .../configuration/SecurityConfiguration.java | 3 +- .../core/controller/AdviceController.java | 10 +- .../ru/ulstu/core/model/ErrorConstants.java | 4 +- .../ulstu/user/controller/UserController.java | 11 +-- .../user/model/UserResetPasswordDto.java | 8 ++ .../ru/ulstu/user/service/MailService.java | 4 +- .../ru/ulstu/user/service/UserService.java | 19 ++-- .../mail_templates/passwordResetEmail.html | 12 +-- src/main/resources/public/css/base.css | 3 + .../resources/public/img/main/ajax-loader.gif | Bin 0 -> 673 bytes src/main/resources/public/js/users.js | 78 +++++++++++++++- .../resources/templates/resetRequest.html | 86 +++++++++--------- 13 files changed, 162 insertions(+), 77 deletions(-) create mode 100644 src/main/resources/public/css/base.css create mode 100644 src/main/resources/public/img/main/ajax-loader.gif diff --git a/src/main/java/ru/ulstu/configuration/Constants.java b/src/main/java/ru/ulstu/configuration/Constants.java index f910108..77a9a4d 100644 --- a/src/main/java/ru/ulstu/configuration/Constants.java +++ b/src/main/java/ru/ulstu/configuration/Constants.java @@ -21,4 +21,5 @@ public class Constants { public static final String PASSWORD_RESET_REQUEST_PAGE = "/resetRequest"; public static final String PASSWORD_RESET_PAGE = "/reset"; + public static final int RESET_KEY_LENGTH = 6; } \ No newline at end of file diff --git a/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java b/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java index 591fa0c..894cf39 100644 --- a/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/SecurityConfiguration.java @@ -104,7 +104,8 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .antMatchers("/css/**") .antMatchers("/js/**") .antMatchers("/templates/**") - .antMatchers("/webjars/**"); + .antMatchers("/webjars/**") + .antMatchers("/img/**"); } @Autowired diff --git a/src/main/java/ru/ulstu/core/controller/AdviceController.java b/src/main/java/ru/ulstu/core/controller/AdviceController.java index 27c9d5b..37078b9 100644 --- a/src/main/java/ru/ulstu/core/controller/AdviceController.java +++ b/src/main/java/ru/ulstu/core/controller/AdviceController.java @@ -34,11 +34,11 @@ public class AdviceController { public AdviceController(UserService userService) { this.userService = userService; } - - @ModelAttribute("currentUser") - public String getCurrentUser() { - return userService.getCurrentUser().getUserAbbreviate(); - } +// +// @ModelAttribute("currentUser") +// public String getCurrentUser() { +// return userService.getCurrentUser().getUserAbbreviate(); +// } @ModelAttribute("flashMessage") public String getFlashMessage() { diff --git a/src/main/java/ru/ulstu/core/model/ErrorConstants.java b/src/main/java/ru/ulstu/core/model/ErrorConstants.java index 55832f3..017725a 100644 --- a/src/main/java/ru/ulstu/core/model/ErrorConstants.java +++ b/src/main/java/ru/ulstu/core/model/ErrorConstants.java @@ -9,9 +9,9 @@ public enum ErrorConstants { USER_EMAIL_EXISTS(102, "Пользователь с таким почтовым ящиком уже существует"), USER_LOGIN_EXISTS(103, "Пользователь с таким логином уже существует"), USER_PASSWORDS_NOT_VALID_OR_NOT_MATCH(104, "Пароли введены неверно"), - USER_NOT_FOUND(105, "User is not found"), + USER_NOT_FOUND(105, "Аккаунт не найден"), USER_NOT_ACTIVATED(106, "User is not activated"), - USER_RESET_ERROR(107, "Invalid reset key"), + USER_RESET_ERROR(107, "Некорректный ключ подтверждения"), USER_UNDEAD_ERROR(108, "Can't edit/delete that user"), FILE_UPLOAD_ERROR(110, "File upload error"), USER_SENDING_MAIL_EXCEPTION(111, "Во время отправки приглашения пользователю произошла ошибка"); diff --git a/src/main/java/ru/ulstu/user/controller/UserController.java b/src/main/java/ru/ulstu/user/controller/UserController.java index 59e023b..c40ed8f 100644 --- a/src/main/java/ru/ulstu/user/controller/UserController.java +++ b/src/main/java/ru/ulstu/user/controller/UserController.java @@ -148,16 +148,15 @@ public class UserController extends OdinController { } @PostMapping(PASSWORD_RESET_REQUEST_URL) - public Response requestPasswordReset(@RequestParam("email") String email) { + public void requestPasswordReset(@RequestParam("email") String email) { log.debug("REST: UserController.requestPasswordReset( {} )", email); - return new Response<>(userService.requestUserPasswordReset(email)); + userService.requestUserPasswordReset(email); } @PostMapping(PASSWORD_RESET_URL) - public Response finishPasswordReset(@RequestParam("key") String key, - @RequestBody UserResetPasswordDto userResetPasswordDto) { - log.debug("REST: UserController.requestPasswordReset( {} )", key); - return new Response<>(userService.completeUserPasswordReset(key, userResetPasswordDto)); + public Response finishPasswordReset(@RequestBody UserResetPasswordDto userResetPasswordDto) { + log.debug("REST: UserController.requestPasswordReset( {} )", userResetPasswordDto.getResetKey()); + return new Response<>(userService.completeUserPasswordReset(userResetPasswordDto)); } @PostMapping("/changePassword") diff --git a/src/main/java/ru/ulstu/user/model/UserResetPasswordDto.java b/src/main/java/ru/ulstu/user/model/UserResetPasswordDto.java index 33d84bc..58e7462 100644 --- a/src/main/java/ru/ulstu/user/model/UserResetPasswordDto.java +++ b/src/main/java/ru/ulstu/user/model/UserResetPasswordDto.java @@ -14,6 +14,10 @@ public class UserResetPasswordDto { @Size(min = Constants.MIN_PASSWORD_LENGTH, max = 50) private String passwordConfirm; + @NotEmpty + @Size(min = Constants.RESET_KEY_LENGTH) + private String resetKey; + public String getPassword() { return password; } @@ -25,4 +29,8 @@ public class UserResetPasswordDto { public boolean isPasswordsValid() { return Objects.equals(password, passwordConfirm); } + + public String getResetKey() { + return resetKey; + } } diff --git a/src/main/java/ru/ulstu/user/service/MailService.java b/src/main/java/ru/ulstu/user/service/MailService.java index ec91739..864b749 100644 --- a/src/main/java/ru/ulstu/user/service/MailService.java +++ b/src/main/java/ru/ulstu/user/service/MailService.java @@ -106,8 +106,7 @@ public class MailService { sendEmailFromTemplate(user, "activationEmail", Constants.MAIL_ACTIVATE); } - @Async - public void sendPasswordResetMail(User user) { + public void sendPasswordResetMail(User user) throws MessagingException, MailException { sendEmailFromTemplate(user, "passwordResetEmail", Constants.MAIL_RESET); } @@ -118,6 +117,5 @@ public class MailService { @Async public void sendChangePasswordMail(User user) { sendEmailFromTemplate(user, "passwordChangeEmail", Constants.MAIL_CHANGE_PASSWORD); - } } diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index c889caa..8089a8e 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -236,7 +236,7 @@ public class UserService implements UserDetailsService { mailService.sendChangePasswordMail(user); } - public boolean requestUserPasswordReset(String email) { + public boolean requestUserPasswordReset(String email) { User user = userRepository.findOneByEmailIgnoreCase(email); if (user == null) { throw new UserNotFoundException(email); @@ -247,23 +247,30 @@ public class UserService implements UserDetailsService { user.setResetKey(UserUtils.generateResetKey()); user.setResetDate(new Date()); user = userRepository.save(user); - mailService.sendPasswordResetMail(user); + try { + mailService.sendPasswordResetMail(user); + } catch (MessagingException | MailException e) { + throw new UserSendingMailException(email); + } log.debug("Created Reset Password Request for User: {}", user.getLogin()); return true; } - public boolean completeUserPasswordReset(String key, UserResetPasswordDto userResetPasswordDto) { + public boolean completeUserPasswordReset(UserResetPasswordDto userResetPasswordDto) { if (!userResetPasswordDto.isPasswordsValid()) { - throw new UserPasswordsNotValidOrNotMatchException(""); + throw new UserPasswordsNotValidOrNotMatchException("Пароли не совпадают"); } - User user = userRepository.findOneByResetKey(key); + User user = userRepository.findOneByResetKey(userResetPasswordDto.getResetKey()); if (user == null) { - throw new UserResetKeyError(key); + throw new UserResetKeyError(userResetPasswordDto.getResetKey()); } user.setPassword(passwordEncoder.encode(userResetPasswordDto.getPassword())); user.setResetKey(null); user.setResetDate(null); user = userRepository.save(user); + + mailService.sendChangePasswordMail(user); + log.debug("Reset Password for User: {}", user.getLogin()); return true; } diff --git a/src/main/resources/mail_templates/passwordResetEmail.html b/src/main/resources/mail_templates/passwordResetEmail.html index a1034d4..99e4f77 100644 --- a/src/main/resources/mail_templates/passwordResetEmail.html +++ b/src/main/resources/mail_templates/passwordResetEmail.html @@ -1,23 +1,19 @@ - Password reset + Восстановление пароля

- Dear Ivan Ivanov + Дорогой Ivan Ivanov

- For your account a password reset was requested, please click on the URL below to + Ваш ключ для восстановления пароля

- Reset Link -

-

- Regards, + С уважением,
Balance Team.

diff --git a/src/main/resources/public/css/base.css b/src/main/resources/public/css/base.css new file mode 100644 index 0000000..0c69e7c --- /dev/null +++ b/src/main/resources/public/css/base.css @@ -0,0 +1,3 @@ +.loader { + padding-left:50% +} \ No newline at end of file diff --git a/src/main/resources/public/img/main/ajax-loader.gif b/src/main/resources/public/img/main/ajax-loader.gif new file mode 100644 index 0000000000000000000000000000000000000000..f2a1bc0c6f545e20e631a96e8e92f9822e75d046 GIT binary patch literal 673 zcmZ?wbhEHb6krfw_{6~Q|Nnmm28Kh24mmkF0U1e2Nli^nlO|14{3qpHl$uzQnxasi zS(2fUn3Y(Olb@KPmzkHA&!G5|g@FsGT=74*pKD04vtxj(k)8oFBTz^Oh=E26FfcG1 zbL_hF&)}42ws10s6^G;;cE1^EoUR)U5A70}d2pLv!jVIT7j&Z~EblI3x0K*v_sV|m z0W=b9G$XP(CLnYCdK49;TX=SFc-G}o=oA=|U?{1O;Nu!CwW3C5Yw7*Bi4yD$3fCnb zwK+>}QdQ9sf*QnxY>*kpE+b{_Q;sJloS71)&(@kO!}mqf@1v(v;*8Y=G9S3kY~Cw# zY=t&c z;3~JK4HxB^lY(MD+sYeQ=t%XSSW;x^1M?dTvN=W^yNcAcy`HCte31C;)5xP%b~qs> zDP&4(%TBqBNGHwnryK;BdMI$fEg xd0mc!C@j^ZpLxYv4HmnPfI0THYuv<%+6iSmMn&w3dPGDfL1|=LY008wP(boU~ literal 0 HcmV?d00001 diff --git a/src/main/resources/public/js/users.js b/src/main/resources/public/js/users.js index 76bd41d..a49bdc6 100644 --- a/src/main/resources/public/js/users.js +++ b/src/main/resources/public/js/users.js @@ -35,10 +35,7 @@ function changePassword() { function inviteUser() { email = document.getElementById("email").value; - re = /\S+@\S+\.\S+/; - - - if (!re.test(email)) { + if (!isEmailValid(email)) { showFeedbackMessage("Некорректный почтовый ящик", MessageTypesEnum.WARNING); return; } @@ -55,4 +52,77 @@ function inviteUser() { showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING) } }) +} + +function requestResetPassword() { + email = document.getElementById("emailReset").value + + if (!isEmailValid(email)) { + showFeedbackMessage("Некорректный почтовый ящик", MessageTypesEnum.WARNING); + return; + } + document.getElementById("dvloader").hidden = false; + + $.ajax({ + url:"/api/1.0/users/password-reset-request?email=" + email, + contentType: "application/json; charset=utf-8", + method: "POST", + success: function() { + showFeedbackMessage("Проверочный код был отправлен на указанный почтовый ящик", MessageTypesEnum.SUCCESS) + document.getElementById("passwordNew").hidden = false + document.getElementById("passwordConfirm").hidden = false + document.getElementById("btnReset").hidden = false + document.getElementById("resetKey").hidden = false + document.getElementById("emailReset").hidden = true + document.getElementById("btnSend").hidden = true + document.getElementById("dvloader").hidden = true; + + }, + error: function(errorData) { + showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING) + document.getElementById("dvloader").hidden = true; + + } + }) + +} + +function resetPassword() { + passwordNew = document.getElementById("passwordNew").value; + passwordConfirm = document.getElementById("passwordConfirm").value; + resetKey = document.getElementById("resetKey").value; + + if ([passwordNew, passwordConfirm, resetKey].includes("")) { + showFeedbackMessage("Заполните все поля", MessageTypesEnum.WARNING); + return; + } + + if (passwordNew != passwordConfirm) { + showFeedbackMessage("Пароли не совпадают", MessageTypesEnum.WARNING); + return; + } + + $.ajax({ + url:"/api/1.0/users/password-reset", + contentType: "application/json; charset=utf-8", + method: "POST", + data: JSON.stringify({ + "password": passwordNew, + "passwordConfirm": passwordConfirm, + "resetKey": resetKey, + }), + success: function() { + showFeedbackMessage("Пользователь был успешно приглашен", MessageTypesEnum.SUCCESS) + window.location.href = "/login" + }, + error: function(errorData) { + showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING) + } + }) +} + + +function isEmailValid(email) { + re = /\S+@\S+\.\S+/; + return re.test(email) } \ No newline at end of file diff --git a/src/main/resources/templates/resetRequest.html b/src/main/resources/templates/resetRequest.html index 2adab37..73bff76 100644 --- a/src/main/resources/templates/resetRequest.html +++ b/src/main/resources/templates/resetRequest.html @@ -1,9 +1,10 @@ + layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml"> + + -
-
-
-
- -
- - -
-
-
- - - +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+ + + + +
+
+
+ + \ No newline at end of file From e468646cd6c5b2b214b15ba25855de5c824dfb90 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Sun, 19 May 2019 00:47:49 +0400 Subject: [PATCH 02/13] 89 removed getCurrentUser --- src/main/java/ru/ulstu/core/controller/AdviceController.java | 5 ----- src/main/resources/public/js/users.js | 1 - 2 files changed, 6 deletions(-) diff --git a/src/main/java/ru/ulstu/core/controller/AdviceController.java b/src/main/java/ru/ulstu/core/controller/AdviceController.java index 37078b9..f89001a 100644 --- a/src/main/java/ru/ulstu/core/controller/AdviceController.java +++ b/src/main/java/ru/ulstu/core/controller/AdviceController.java @@ -34,11 +34,6 @@ public class AdviceController { public AdviceController(UserService userService) { this.userService = userService; } -// -// @ModelAttribute("currentUser") -// public String getCurrentUser() { -// return userService.getCurrentUser().getUserAbbreviate(); -// } @ModelAttribute("flashMessage") public String getFlashMessage() { diff --git a/src/main/resources/public/js/users.js b/src/main/resources/public/js/users.js index a49bdc6..1ea26e3 100644 --- a/src/main/resources/public/js/users.js +++ b/src/main/resources/public/js/users.js @@ -81,7 +81,6 @@ function requestResetPassword() { error: function(errorData) { showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING) document.getElementById("dvloader").hidden = true; - } }) From 284a3f51e9539c27db16825145815006c1d510ab Mon Sep 17 00:00:00 2001 From: ASH Date: Thu, 23 May 2019 12:07:34 +0400 Subject: [PATCH 03/13] #104 mod tests filter and create tasks --- .../java/ru/ulstu/students/model/TaskDto.java | 20 ++ .../students/service/TaskServiceTest.java | 181 ++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 src/test/java/ru/ulstu/students/service/TaskServiceTest.java diff --git a/src/main/java/ru/ulstu/students/model/TaskDto.java b/src/main/java/ru/ulstu/students/model/TaskDto.java index 8d52e01..1d0eac0 100644 --- a/src/main/java/ru/ulstu/students/model/TaskDto.java +++ b/src/main/java/ru/ulstu/students/model/TaskDto.java @@ -10,6 +10,7 @@ import ru.ulstu.tags.model.Tag; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; @@ -135,6 +136,25 @@ public class TaskDto { this.tags = tags; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TaskDto taskDto = (TaskDto) o; + return Objects.equals(id, taskDto.id) && + Objects.equals(title, taskDto.title) && + Objects.equals(description, taskDto.description) && + status == taskDto.status && + Objects.equals(deadlines, taskDto.deadlines) && + Objects.equals(tagIds, taskDto.tagIds) && + Objects.equals(tags, taskDto.tags); + } + + @Override + public int hashCode() { + return Objects.hash(id, title, description, status, deadlines, createDate, updateDate, tagIds, tags); + } + public String getTagsString() { return StringUtils.abbreviate(tags .stream() diff --git a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java new file mode 100644 index 0000000..e00570c --- /dev/null +++ b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java @@ -0,0 +1,181 @@ +package ru.ulstu.students.service; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.data.domain.Sort; +import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.students.model.Task; +import ru.ulstu.students.model.TaskDto; +import ru.ulstu.students.model.TaskFilterDto; +import ru.ulstu.students.repository.TaskRepository; +import ru.ulstu.tags.model.Tag; +import ru.ulstu.tags.service.TagService; +import ru.ulstu.timeline.service.EventService; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class TaskServiceTest { + + @Mock + TaskRepository taskRepository; + + @Mock + private TagService tagService; + + @Mock + DeadlineService deadlineService; + + @Mock + EventService eventService; + + @InjectMocks + TaskService taskService; + + private final static Sort SORT = new Sort(Sort.Direction.DESC, "createDate"); + private final static Integer ID = 1; + private final static Task.TaskStatus STATUS = Task.TaskStatus.IN_WORK; + private final static String TITLE = "title"; + private final static String DESCR = "descr"; + private final static String TAG = "tag"; + + private List tasks; + private List tags; + private Task task; + private TaskFilterDto filterDto; + private TaskDto taskDto; + private List tasksDto; + private Tag tag; + private Tag tagNull; + private Deadline deadline; + private List deadlines; + + + @Before + public void setUp() throws Exception { + + tasks = new ArrayList<>(); + task = new Task(); + + task.setId(ID); + task.setTitle(TITLE); + task.setDescription(DESCR); + + + tag = new Tag(); + tag.setId(ID); + tag.setTagName(TAG); + + deadlines = new ArrayList<>(); + deadline = new Deadline(new Date(), DESCR); + deadline.setId(ID); + deadlines.add(deadline); + + tags = new ArrayList<>(); + tags.add(tag); + + tasks.add(task); + taskDto = new TaskDto(task); + + } + + @Test + public void findAll() { + + when(taskRepository.findAll(SORT)).thenReturn(tasks); + assertEquals(Collections.singletonList(task), taskService.findAll()); + } + + @Test + public void filter() { + when(tagService.findById(ID)).thenReturn(tag); + when(taskRepository.filterNew(STATUS, tag)).thenReturn(tasks); + + TaskFilterDto taskFilterDto = new TaskFilterDto(); + taskFilterDto.setTag(ID); + taskFilterDto.setOrder("new"); + taskFilterDto.setStatus(STATUS); + + assertEquals(Collections.singletonList(taskDto), taskService.filter(taskFilterDto)); + } + + @Test + public void create() throws IOException { + when(tagService.saveOrCreate(new ArrayList<>())).thenReturn(tags); + when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines); + when(taskRepository.save(new Task())).thenReturn(task); + eventService.createFromTask(new Task()); + + taskDto.setTags(tags); + taskDto.setDeadlines(deadlines); + + Task newTask = new Task(); + task.setId(ID); + task.setTitle(TITLE); + task.setDescription(DESCR); + task.setTags(tags); + task.setDeadlines(deadlines); + + assertEquals(task.getId(), taskService.create(taskDto)); + } + + @Test + public void update() { + } + + @Test + public void delete() { + } + + @Test + public void save() { + } + + @Test + public void copyMainPart() { + } + + @Test + public void copyTaskWithNewDates() { + } + + @Test + public void copyTaskWithNewYear() { + } + + @Test + public void generateYearTasks() { + } + + @Test + public void checkRepeatingTags() { + } + + @Test + public void getTaskStatuses() { + } + + @Test + public void getTags() { + } + + @Test + public void findTasksByTag() { + } + + @Test + public void createPeriodTask() { + } +} \ No newline at end of file From ef521123dd157ea0381d2b6699be4ac9569e295e Mon Sep 17 00:00:00 2001 From: ASH Date: Thu, 23 May 2019 14:31:34 +0400 Subject: [PATCH 04/13] #104 mod tests check repeatings --- .../java/ru/ulstu/students/model/TaskDto.java | 8 +++- .../ulstu/students/service/TaskService.java | 10 ++-- .../students/service/TaskServiceTest.java | 46 +++++++++++-------- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/main/java/ru/ulstu/students/model/TaskDto.java b/src/main/java/ru/ulstu/students/model/TaskDto.java index 1d0eac0..2df691f 100644 --- a/src/main/java/ru/ulstu/students/model/TaskDto.java +++ b/src/main/java/ru/ulstu/students/model/TaskDto.java @@ -138,8 +138,12 @@ public class TaskDto { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } TaskDto taskDto = (TaskDto) o; return Objects.equals(id, taskDto.id) && Objects.equals(title, taskDto.title) && diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index 2be44cb..379314d 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -108,7 +108,7 @@ public class TaskService { } @Transactional - public void delete(Integer taskId) throws IOException { + public boolean delete(Integer taskId) throws IOException { if (taskRepository.exists(taskId)) { Task scheduleTask = taskRepository.findOne(taskId); Scheduler sch = schedulerRepository.findOneByTask(scheduleTask); @@ -116,7 +116,9 @@ public class TaskService { schedulerRepository.delete(sch.getId()); } taskRepository.delete(taskId); + return true; } + return false; } @@ -128,14 +130,14 @@ public class TaskService { } } - public void copyMainPart(Task newTask, Task task) { + private void copyMainPart(Task newTask, Task task) { newTask.setTitle(task.getTitle()); newTask.setTags(tagService.saveOrCreate(task.getTags())); newTask.setCreateDate(new Date()); newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS); } - public Task copyTaskWithNewDates(Task task) { + private Task copyTaskWithNewDates(Task task) { Task newTask = new Task(); copyMainPart(newTask, task); Calendar cal1 = DateUtils.getCalendar(newTask.getCreateDate()); @@ -157,7 +159,7 @@ public class TaskService { }).collect(Collectors.toList()); } - public Task copyTaskWithNewYear(Task task) { + private Task copyTaskWithNewYear(Task task) { Task newTask = new Task(); copyMainPart(newTask, task); newTask.setDeadlines(newYearDeadlines(task.getDeadlines())); diff --git a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java index e00570c..19eff12 100644 --- a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java +++ b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java @@ -7,11 +7,13 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.springframework.data.domain.Sort; +import ru.ulstu.core.util.DateUtils; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.students.model.Task; import ru.ulstu.students.model.TaskDto; import ru.ulstu.students.model.TaskFilterDto; +import ru.ulstu.students.repository.SchedulerRepository; import ru.ulstu.students.repository.TaskRepository; import ru.ulstu.tags.model.Tag; import ru.ulstu.tags.service.TagService; @@ -21,9 +23,12 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -32,6 +37,9 @@ public class TaskServiceTest { @Mock TaskRepository taskRepository; + @Mock + SchedulerRepository schedulerRepository; + @Mock private TagService tagService; @@ -50,6 +58,7 @@ public class TaskServiceTest { private final static String TITLE = "title"; private final static String DESCR = "descr"; private final static String TAG = "tag"; + private final static Date YEAR = DateUtils.clearTime(DateUtils.addYears(new Date(), 0)); private List tasks; private List tags; @@ -61,6 +70,7 @@ public class TaskServiceTest { private Tag tagNull; private Deadline deadline; private List deadlines; + private Set repeatingTags; @Before @@ -83,12 +93,17 @@ public class TaskServiceTest { deadline.setId(ID); deadlines.add(deadline); + task.setDeadlines(deadlines); + tags = new ArrayList<>(); tags.add(tag); tasks.add(task); taskDto = new TaskDto(task); + repeatingTags = new HashSet<>(); + repeatingTags.add(tag); + } @Test @@ -132,35 +147,26 @@ public class TaskServiceTest { } @Test - public void update() { - } + public void delete() throws IOException { + when(taskRepository.exists(ID)).thenReturn(true); + when(taskRepository.findOne(ID)).thenReturn(task); + when(schedulerRepository.findOneByTask(task)).thenReturn(null); - @Test - public void delete() { - } - - @Test - public void save() { - } - - @Test - public void copyMainPart() { - } - - @Test - public void copyTaskWithNewDates() { - } - - @Test - public void copyTaskWithNewYear() { + assertTrue(taskService.delete(ID)); } @Test public void generateYearTasks() { + when(taskService.checkRepeatingTags(false)).thenReturn(repeatingTags); + } @Test public void checkRepeatingTags() { + when(tagService.findById(ID)).thenReturn(tag); + when(taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)))).thenReturn(tasks); + + assertEquals(tag, taskService.checkRepeatingTags(false)); } @Test From 29cfadef02940976788796151f41132d557a5884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=9C?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=8F?= Date: Thu, 23 May 2019 15:02:55 +0400 Subject: [PATCH 05/13] #127 reference model, schema --- .../java/ru/ulstu/paper/model/Reference.java | 90 +++++++++++++++++++ .../db/changelog-20190523_000000-schema.xml | 34 +++++++ src/main/resources/db/changelog-master.xml | 1 + 3 files changed, 125 insertions(+) create mode 100644 src/main/java/ru/ulstu/paper/model/Reference.java create mode 100644 src/main/resources/db/changelog-20190523_000000-schema.xml diff --git a/src/main/java/ru/ulstu/paper/model/Reference.java b/src/main/java/ru/ulstu/paper/model/Reference.java new file mode 100644 index 0000000..1901f41 --- /dev/null +++ b/src/main/java/ru/ulstu/paper/model/Reference.java @@ -0,0 +1,90 @@ +package ru.ulstu.paper.model; + +import org.hibernate.validator.constraints.NotBlank; +import ru.ulstu.core.model.BaseEntity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; + +@Entity +public class Reference extends BaseEntity { + + @NotBlank + private String authors; + + @Column(name = "publication_title") + private String publicationTitle; + + @Column(name = "publication_year") + private Integer publicationYear; + + private String publisher; + + private String pages; + + @Column(name = "journal_or_collection_title") + private String journalOrCollectionTitle; + + @Enumerated(value = EnumType.STRING) + @Column(name = "reference_type") + private ReferenceDto.ReferenceType referenceType = ReferenceDto.ReferenceType.ARTICLE; + + public String getAuthors() { + return authors; + } + + public void setAuthors(String authors) { + this.authors = authors; + } + + public String getPublicationTitle() { + return publicationTitle; + } + + public void setPublicationTitle(String publicationTitle) { + this.publicationTitle = publicationTitle; + } + + public Integer getPublicationYear() { + return publicationYear; + } + + public void setPublicationYear(Integer publicationYear) { + this.publicationYear = publicationYear; + } + + public String getPublisher() { + return publisher; + } + + public void setPublisher(String publisher) { + this.publisher = publisher; + } + + public String getPages() { + return pages; + } + + public void setPages(String pages) { + this.pages = pages; + } + + public String getJournalOrCollectionTitle() { + return journalOrCollectionTitle; + } + + public void setJournalOrCollectionTitle(String journalOrCollectionTitle) { + this.journalOrCollectionTitle = journalOrCollectionTitle; + } + + public ReferenceDto.ReferenceType getReferenceType() { + return referenceType; + } + + public void setReferenceType(ReferenceDto.ReferenceType referenceType) { + this.referenceType = referenceType; + } + +} diff --git a/src/main/resources/db/changelog-20190523_000000-schema.xml b/src/main/resources/db/changelog-20190523_000000-schema.xml new file mode 100644 index 0000000..2bdc788 --- /dev/null +++ b/src/main/resources/db/changelog-20190523_000000-schema.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 18bd645..5011cc5 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -42,4 +42,5 @@ + \ No newline at end of file From 7c1b124c9470821b47c82642a7c6b945724efd04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=9C?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=8F?= Date: Thu, 23 May 2019 15:48:46 +0400 Subject: [PATCH 06/13] #127 references tab, crud --- .../paper/controller/PaperController.java | 20 ++++ src/main/java/ru/ulstu/paper/model/Paper.java | 13 +++ .../java/ru/ulstu/paper/model/PaperDto.java | 25 ++++- .../java/ru/ulstu/paper/model/Reference.java | 2 - .../ru/ulstu/paper/model/ReferenceDto.java | 39 +++++++- .../paper/repository/ReferenceRepository.java | 8 ++ .../ru/ulstu/paper/service/PaperService.java | 57 +++++++++++ .../db/changelog-20190523_000000-schema.xml | 13 +-- src/main/resources/public/css/paper.css | 20 ++++ .../resources/templates/papers/paper.html | 97 ++++++++++++++++++- 10 files changed, 279 insertions(+), 15 deletions(-) create mode 100644 src/main/java/ru/ulstu/paper/repository/ReferenceRepository.java diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index 41d5586..beae772 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -16,6 +16,7 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperListDto; +import ru.ulstu.paper.model.ReferenceDto; import ru.ulstu.paper.service.LatexService; import ru.ulstu.paper.service.PaperService; import ru.ulstu.user.model.User; @@ -105,6 +106,15 @@ public class PaperController { return "/papers/paper"; } + @PostMapping(value = "/paper", params = "addReference") + public String addReference(@Valid PaperDto paperDto, Errors errors) { + if (errors.hasErrors()) { + return "/papers/paper"; + } + paperDto.getReferences().add(new ReferenceDto()); + return "/papers/paper"; + } + @ModelAttribute("allStatuses") public List getPaperStatuses() { return paperService.getPaperStatuses(); @@ -129,6 +139,16 @@ public class PaperController { return years; } + @ModelAttribute("allFormatStandards") + public List getFormatStandards() { + return paperService.getFormatStandards(); + } + + @ModelAttribute("allReferenceTypes") + public List getReferenceTypes() { + return paperService.getReferenceTypes(); + } + @PostMapping("/generatePdf") public ResponseEntity getPdfFile(PaperDto paper) throws IOException, InterruptedException { HttpHeaders headers = new HttpHeaders(); diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index 15ee4b4..413c5db 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -123,6 +123,11 @@ public class Paper extends BaseEntity implements UserContainer { @ManyToMany(mappedBy = "papers") private List grants; + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "paper_id", unique = true) + @Fetch(FetchMode.SUBSELECT) + private List references = new ArrayList<>(); + public PaperStatus getStatus() { return status; } @@ -248,6 +253,14 @@ public class Paper extends BaseEntity implements UserContainer { return getAuthors(); } + public List getReferences() { + return references; + } + + public void setReferences(List references) { + this.references = references; + } + public Optional getNextDeadline() { return deadlines .stream() diff --git a/src/main/java/ru/ulstu/paper/model/PaperDto.java b/src/main/java/ru/ulstu/paper/model/PaperDto.java index 11d6dfc..8474a34 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperDto.java @@ -38,6 +38,8 @@ public class PaperDto { private Set authors; private Integer filterAuthorId; private String latexText; + private List references = new ArrayList<>(); + private ReferenceDto.FormatStandard formatStandard = ReferenceDto.FormatStandard.GOST; public PaperDto() { deadlines.add(new Deadline()); @@ -57,7 +59,9 @@ public class PaperDto { @JsonProperty("locked") Boolean locked, @JsonProperty("files") List files, @JsonProperty("authorIds") Set authorIds, - @JsonProperty("authors") Set authors) { + @JsonProperty("authors") Set authors, + @JsonProperty("references") List references, + @JsonProperty("formatStandard") ReferenceDto.FormatStandard formatStandard) { this.id = id; this.title = title; this.status = status; @@ -71,6 +75,8 @@ public class PaperDto { this.locked = locked; this.files = files; this.authors = authors; + this.references = references; + this.formatStandard = formatStandard; } public PaperDto(Paper paper) { @@ -88,6 +94,7 @@ public class PaperDto { this.files = convert(paper.getFiles(), FileDataDto::new); this.authorIds = convert(paper.getAuthors(), user -> user.getId()); this.authors = convert(paper.getAuthors(), UserDto::new); + this.references = convert(paper.getReferences(), ReferenceDto::new); } public Integer getId() { @@ -216,4 +223,20 @@ public class PaperDto { public void setFilterAuthorId(Integer filterAuthorId) { this.filterAuthorId = filterAuthorId; } + + public List getReferences() { + return references; + } + + public void setReferences(List references) { + this.references = references; + } + + public ReferenceDto.FormatStandard getFormatStandard() { + return formatStandard; + } + + public void setFormatStandard(ReferenceDto.FormatStandard formatStandard) { + this.formatStandard = formatStandard; + } } diff --git a/src/main/java/ru/ulstu/paper/model/Reference.java b/src/main/java/ru/ulstu/paper/model/Reference.java index 1901f41..289cdc1 100644 --- a/src/main/java/ru/ulstu/paper/model/Reference.java +++ b/src/main/java/ru/ulstu/paper/model/Reference.java @@ -1,6 +1,5 @@ package ru.ulstu.paper.model; -import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import javax.persistence.Column; @@ -11,7 +10,6 @@ import javax.persistence.Enumerated; @Entity public class Reference extends BaseEntity { - @NotBlank private String authors; @Column(name = "publication_title") diff --git a/src/main/java/ru/ulstu/paper/model/ReferenceDto.java b/src/main/java/ru/ulstu/paper/model/ReferenceDto.java index 8d71ae5..1705e08 100644 --- a/src/main/java/ru/ulstu/paper/model/ReferenceDto.java +++ b/src/main/java/ru/ulstu/paper/model/ReferenceDto.java @@ -34,6 +34,7 @@ public class ReferenceDto { } } + private Integer id; private String authors; private String publicationTitle; private Integer publicationYear; @@ -42,9 +43,11 @@ public class ReferenceDto { private String journalOrCollectionTitle; private ReferenceType referenceType; private FormatStandard formatStandard; + private boolean deleted; @JsonCreator public ReferenceDto( + @JsonProperty("id") Integer id, @JsonProperty("authors") String authors, @JsonProperty("publicationTitle") String publicationTitle, @JsonProperty("publicationYear") Integer publicationYear, @@ -52,7 +55,9 @@ public class ReferenceDto { @JsonProperty("pages") String pages, @JsonProperty("journalOrCollectionTitle") String journalOrCollectionTitle, @JsonProperty("referenceType") ReferenceType referenceType, - @JsonProperty("formatStandard") FormatStandard formatStandard) { + @JsonProperty("formatStandard") FormatStandard formatStandard, + @JsonProperty("isDeleted") boolean deleted) { + this.id = id; this.authors = authors; this.publicationTitle = publicationTitle; this.publicationYear = publicationYear; @@ -61,6 +66,22 @@ public class ReferenceDto { this.journalOrCollectionTitle = journalOrCollectionTitle; this.referenceType = referenceType; this.formatStandard = formatStandard; + this.deleted = deleted; + } + + public ReferenceDto(Reference reference) { + this.id = reference.getId(); + this.authors = reference.getAuthors(); + this.publicationTitle = reference.getPublicationTitle(); + this.publicationYear = reference.getPublicationYear(); + this.publisher = reference.getPublisher(); + this.pages = reference.getPages(); + this.journalOrCollectionTitle = reference.getJournalOrCollectionTitle(); + this.referenceType = reference.getReferenceType(); + } + + public ReferenceDto() { + referenceType = ReferenceType.ARTICLE; } public String getAuthors() { @@ -126,4 +147,20 @@ public class ReferenceDto { public void setFormatStandard(FormatStandard formatStandard) { this.formatStandard = formatStandard; } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public boolean getDeleted() { + return deleted; + } + + public void setDeleted(boolean deleted) { + this.deleted = deleted; + } } diff --git a/src/main/java/ru/ulstu/paper/repository/ReferenceRepository.java b/src/main/java/ru/ulstu/paper/repository/ReferenceRepository.java new file mode 100644 index 0000000..68e97d4 --- /dev/null +++ b/src/main/java/ru/ulstu/paper/repository/ReferenceRepository.java @@ -0,0 +1,8 @@ +package ru.ulstu.paper.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import ru.ulstu.paper.model.Reference; + +public interface ReferenceRepository extends JpaRepository { + void deleteById(Integer id); +} diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index db810f5..8658015 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -10,8 +10,10 @@ import ru.ulstu.file.service.FileService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperListDto; +import ru.ulstu.paper.model.Reference; import ru.ulstu.paper.model.ReferenceDto; import ru.ulstu.paper.repository.PaperRepository; +import ru.ulstu.paper.repository.ReferenceRepository; import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; @@ -39,6 +41,7 @@ import static ru.ulstu.paper.model.ReferenceDto.ReferenceType.ARTICLE; import static ru.ulstu.paper.model.ReferenceDto.ReferenceType.BOOK; @Service +@Transactional public class PaperService { private final static int MAX_DISPLAY_SIZE = 40; private final static String PAPER_FORMATTED_TEMPLATE = "%s %s"; @@ -49,14 +52,17 @@ public class PaperService { private final DeadlineService deadlineService; private final FileService fileService; private final EventService eventService; + private final ReferenceRepository referenceRepository; public PaperService(PaperRepository paperRepository, + ReferenceRepository referenceRepository, FileService fileService, PaperNotificationService paperNotificationService, UserService userService, DeadlineService deadlineService, EventService eventService) { this.paperRepository = paperRepository; + this.referenceRepository = referenceRepository; this.fileService = fileService; this.paperNotificationService = paperNotificationService; this.userService = userService; @@ -117,6 +123,7 @@ public class PaperService { paper.setTitle(paperDto.getTitle()); paper.setUpdateDate(new Date()); paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines())); + paper.setReferences(saveOrCreateReferences(paperDto.getReferences())); paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream() .filter(f -> !f.isDeleted()) .collect(toList()))); @@ -127,6 +134,43 @@ public class PaperService { return paper; } + public List saveOrCreateReferences(List references) { + return references + .stream() + .filter(reference -> !reference.getDeleted()) + .map(reference -> reference.getId() != null ? updateReference(reference) : createReference(reference)) + .collect(Collectors.toList()); + } + + @Transactional + public Reference updateReference(ReferenceDto referenceDto) { + Reference updateReference = referenceRepository.findOne(referenceDto.getId()); + updateReference.setAuthors(referenceDto.getAuthors()); + updateReference.setJournalOrCollectionTitle(referenceDto.getJournalOrCollectionTitle()); + updateReference.setPages(referenceDto.getPages()); + updateReference.setPublicationTitle(referenceDto.getPublicationTitle()); + updateReference.setPublicationYear(referenceDto.getPublicationYear()); + updateReference.setPublisher(referenceDto.getPublisher()); + updateReference.setReferenceType(referenceDto.getReferenceType()); + referenceRepository.save(updateReference); + return updateReference; + } + + @Transactional + public Reference createReference(ReferenceDto referenceDto) { + Reference newReference = new Reference(); + newReference.setAuthors(referenceDto.getAuthors()); + newReference.setJournalOrCollectionTitle(referenceDto.getJournalOrCollectionTitle()); + newReference.setPages(referenceDto.getPages()); + newReference.setPublicationTitle(referenceDto.getPublicationTitle()); + newReference.setPublicationYear(referenceDto.getPublicationYear()); + newReference.setPublisher(referenceDto.getPublisher()); + newReference.setReferenceType(referenceDto.getReferenceType()); + newReference = referenceRepository.save(newReference); + return newReference; + } + + @Transactional public Integer update(PaperDto paperDto) throws IOException { Paper paper = paperRepository.findOne(paperDto.getId()); @@ -139,6 +183,11 @@ public class PaperService { fileService.delete(file.getId()); } paperRepository.save(copyFromDto(paper, paperDto)); + for (ReferenceDto referenceDto : paperDto.getReferences().stream() + .filter(f -> f.getDeleted() && f.getId() != null) + .collect(toList())) { + referenceRepository.deleteById(referenceDto.getId()); + } eventService.updatePaperDeadlines(paper); paper.getAuthors().forEach(author -> { @@ -168,6 +217,14 @@ public class PaperService { return Arrays.asList(Paper.PaperType.values()); } + public List getFormatStandards() { + return Arrays.asList(ReferenceDto.FormatStandard.values()); + } + + public List getReferenceTypes() { + return Arrays.asList(ReferenceDto.ReferenceType.values()); + } + @Transactional public Paper create(String title, User user, Date deadlineDate) { Paper paper = new Paper(); diff --git a/src/main/resources/db/changelog-20190523_000000-schema.xml b/src/main/resources/db/changelog-20190523_000000-schema.xml index 2bdc788..aca880f 100644 --- a/src/main/resources/db/changelog-20190523_000000-schema.xml +++ b/src/main/resources/db/changelog-20190523_000000-schema.xml @@ -7,20 +7,13 @@ - - - - - - - - - + + + - diff --git a/src/main/resources/public/css/paper.css b/src/main/resources/public/css/paper.css index 824209f..1be8c1f 100644 --- a/src/main/resources/public/css/paper.css +++ b/src/main/resources/public/css/paper.css @@ -6,4 +6,24 @@ .nav-tabs { margin-bottom: 20px; +} + +#nav-references label, #nav-references select, #nav-references input { + display: inline-block; + vertical-align: middle; +} + +#nav-references .collapse-heading { + border: 1px solid #ddd; + border-radius: 4px; + padding: 5px 15px; + background-color: #efefef; +} + +#nav-references .collapse-heading a { + text-decoration: none; +} + +#nav-references a:hover { + text-decoration: none; } \ No newline at end of file diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index d408913..ef4217d 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -31,6 +31,9 @@ href="#nav-main" role="tab" aria-controls="nav-main" aria-selected="true">Статья Latex + References +
@@ -378,7 +474,6 @@ $('#pdfBtn').prop('disabled', false); } } -
From 82e454a50b8b209d0e0eb771e62ea3a864c0dbcc Mon Sep 17 00:00:00 2001 From: ASH Date: Thu, 23 May 2019 16:17:04 +0400 Subject: [PATCH 07/13] #104 mod tests generate task --- .../ulstu/students/service/TaskService.java | 4 ++- .../students/service/TaskServiceTest.java | 26 ++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index 379314d..d080d37 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -186,7 +186,7 @@ public class TaskService { } @Transactional - public void generateYearTasks() { + public List generateYearTasks() { Set tags = checkRepeatingTags(false); List tasks = new ArrayList<>(); tags.forEach(tag -> { @@ -202,7 +202,9 @@ public class TaskService { Task newTask = copyTaskWithNewYear(task); taskRepository.save(newTask); }); + return tasks; } + return null; } diff --git a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java index 19eff12..1ba04c4 100644 --- a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java +++ b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java @@ -21,6 +21,7 @@ import ru.ulstu.timeline.service.EventService; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.HashSet; @@ -157,16 +158,35 @@ public class TaskServiceTest { @Test public void generateYearTasks() { - when(taskService.checkRepeatingTags(false)).thenReturn(repeatingTags); + when(tagService.getTags()).thenReturn(tags); + tasks.get(0).setTags(tags); + when(taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)))).thenReturn(tasks); + tasks.get(0).setCreateDate(DateUtils.clearTime(DateUtils.addYears(new Date(), -1))); + when(taskRepository.findByTag(tag)).thenReturn(tasks); + Task newTask = new Task(); + newTask.setTitle(tasks.get(0).getTitle()); + newTask.setTags(tasks.get(0).getTags()); + newTask.setCreateDate(new Date()); + newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS); + + Deadline newDeadline = new Deadline(); + newDeadline.setDescription(deadline.getDescription()); + newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1)); + newTask.setDeadlines(Arrays.asList(newDeadline)); + + when(taskRepository.save(newTask)).thenReturn(task); + + assertEquals(Arrays.asList(task), taskService.generateYearTasks()); } @Test public void checkRepeatingTags() { - when(tagService.findById(ID)).thenReturn(tag); + when(tagService.getTags()).thenReturn(tags); + tasks.get(0).setTags(tags); when(taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)))).thenReturn(tasks); - assertEquals(tag, taskService.checkRepeatingTags(false)); + assertEquals(new HashSet(Arrays.asList(tag)), taskService.checkRepeatingTags(false)); } @Test From ab17b9f1521e498d7bea148935e48cfa675f1b5e Mon Sep 17 00:00:00 2001 From: ASH Date: Thu, 23 May 2019 16:45:09 +0400 Subject: [PATCH 08/13] #104 mod tests period task --- .../ulstu/students/service/TaskService.java | 3 +- .../students/service/TaskServiceTest.java | 47 +++++++++++-------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index d080d37..e89aedf 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -249,8 +249,9 @@ public class TaskService { } @Transactional - public void createPeriodTask(Scheduler scheduler) { + public Task createPeriodTask(Scheduler scheduler) { Task newTask = copyTaskWithNewDates(scheduler.getTask()); taskRepository.save(newTask); + return newTask; } } diff --git a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java index 1ba04c4..8edfc77 100644 --- a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java +++ b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java @@ -10,6 +10,7 @@ import org.springframework.data.domain.Sort; import ru.ulstu.core.util.DateUtils; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.students.model.Scheduler; import ru.ulstu.students.model.Task; import ru.ulstu.students.model.TaskDto; import ru.ulstu.students.model.TaskFilterDto; @@ -26,7 +27,6 @@ import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.List; -import java.util.Set; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -64,14 +64,12 @@ public class TaskServiceTest { private List tasks; private List tags; private Task task; - private TaskFilterDto filterDto; + private Task taskForSchedule; private TaskDto taskDto; - private List tasksDto; private Tag tag; - private Tag tagNull; private Deadline deadline; private List deadlines; - private Set repeatingTags; + private Scheduler scheduler; @Before @@ -102,8 +100,14 @@ public class TaskServiceTest { tasks.add(task); taskDto = new TaskDto(task); - repeatingTags = new HashSet<>(); - repeatingTags.add(tag); + taskForSchedule = new Task(); + taskForSchedule.setTitle(TITLE); + taskForSchedule.setDescription(DESCR); + + scheduler = new Scheduler(); + scheduler.setDate(new Date()); + scheduler.setTask(taskForSchedule); + } @@ -171,8 +175,10 @@ public class TaskServiceTest { newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS); Deadline newDeadline = new Deadline(); + newDeadline.setId(ID); newDeadline.setDescription(deadline.getDescription()); newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1)); + when(deadlineService.create(newDeadline)).thenReturn(newDeadline); newTask.setDeadlines(Arrays.asList(newDeadline)); when(taskRepository.save(newTask)).thenReturn(task); @@ -189,19 +195,22 @@ public class TaskServiceTest { assertEquals(new HashSet(Arrays.asList(tag)), taskService.checkRepeatingTags(false)); } - @Test - public void getTaskStatuses() { - } - - @Test - public void getTags() { - } - - @Test - public void findTasksByTag() { - } - @Test public void createPeriodTask() { + Task newTask = new Task(); + newTask.setTitle(scheduler.getTask().getTitle()); + newTask.setTags(scheduler.getTask().getTags()); + newTask.setCreateDate(new Date()); + + Deadline newDeadline = new Deadline(); + newDeadline.setId(ID); + newDeadline.setDescription(deadline.getDescription()); + newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1)); + when(deadlineService.create(newDeadline)).thenReturn(newDeadline); + newTask.setDeadlines(Arrays.asList(newDeadline)); + + when(taskRepository.save(newTask)).thenReturn(taskForSchedule); + + assertEquals(taskForSchedule, taskService.createPeriodTask(scheduler)); } } \ No newline at end of file From 512a805e8c4c4fa26cb58027ff2efc173e179c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=9C?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=8F?= Date: Thu, 23 May 2019 17:26:22 +0400 Subject: [PATCH 09/13] #127 references formatting --- .../paper/controller/PaperController.java | 5 +++ .../ru/ulstu/paper/service/PaperService.java | 11 +++++ src/main/resources/public/css/paper.css | 4 ++ src/main/resources/public/js/core.js | 1 + .../resources/templates/papers/paper.html | 45 +++++++++++++++++++ 5 files changed, 66 insertions(+) diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index beae772..e10135f 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -157,6 +157,11 @@ public class PaperController { return new ResponseEntity<>(latexService.generatePdfFromLatexFile(paper), headers, HttpStatus.OK); } + @PostMapping("/getFormattedReferences") + public ResponseEntity getFormattedReferences(PaperDto paperDto) { + return new ResponseEntity<>(paperService.getFormattedReferences(paperDto), new HttpHeaders(), HttpStatus.OK); + } + private void filterEmptyDeadlines(PaperDto paperDto) { paperDto.setDeadlines(paperDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 8658015..8a59486 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -344,6 +344,17 @@ public class PaperService { : getSpringerReference(referenceDto); } + public String getFormattedReferences(PaperDto paperDto) { + return String.join("\r\n", paperDto.getReferences() + .stream() + .filter(r -> !r.getDeleted()) + .map(r -> { + r.setFormatStandard(paperDto.getFormatStandard()); + return getFormattedReference(r); + }) + .collect(Collectors.toList())); + } + public String getGostReference(ReferenceDto referenceDto) { return MessageFormat.format(referenceDto.getReferenceType() == BOOK ? "{0} {1} - {2}{3}. - {4}с." : "{0} {1}{5} {2}{3}. С. {4}.", referenceDto.getAuthors(), diff --git a/src/main/resources/public/css/paper.css b/src/main/resources/public/css/paper.css index 1be8c1f..386c5af 100644 --- a/src/main/resources/public/css/paper.css +++ b/src/main/resources/public/css/paper.css @@ -26,4 +26,8 @@ #nav-references a:hover { text-decoration: none; +} + +#nav-references #formattedReferencesArea { + height: 150px; } \ No newline at end of file diff --git a/src/main/resources/public/js/core.js b/src/main/resources/public/js/core.js index 58e68f4..cc42258 100644 --- a/src/main/resources/public/js/core.js +++ b/src/main/resources/public/js/core.js @@ -4,6 +4,7 @@ var urlFileUpload = "/api/1.0/files/uploadTmpFile"; var urlFileDownload = "/api/1.0/files/download/"; var urlPdfGenerating = "/papers/generatePdf"; +var urlReferencesFormatting = "/papers/getFormattedReferences"; var urlFileDownloadTmp = "/api/1.0/files/download-tmp/"; /* exported MessageTypesEnum */ diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index ef4217d..e80fe85 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -260,7 +260,33 @@ class="btn btn-primary" value="Добавить источник"/> +
+
+ + + +
+ +
+ +
+ +
+ +
+
@@ -474,6 +500,25 @@ $('#pdfBtn').prop('disabled', false); } } + + function getFormattedReferences() { + + var formData = new FormData(document.forms.paperform); + var xhr = new XMLHttpRequest(); + xhr.open("POST", urlReferencesFormatting); + console.log(formData); + xhr.send(formData); + + xhr.onload = function () { + if (this.status == 200) { + console.debug(this.response); + $('#formattedReferencesArea').val(this.response); + + } else { + showFeedbackMessage("Ошибка при форматировании списка литературы", MessageTypesEnum.DANGER); + } + } + } From 24a1276005ecaac2d95bd0ca20ad5eddd353c778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=9C?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=8F?= Date: Fri, 24 May 2019 00:14:46 +0400 Subject: [PATCH 10/13] #127 autocomplete --- .../paper/controller/PaperController.java | 6 + .../ulstu/paper/model/AutoCompleteData.java | 42 ++++++ .../paper/repository/ReferenceRepository.java | 15 ++ .../ru/ulstu/paper/service/PaperService.java | 10 ++ src/main/resources/public/css/paper.css | 7 + .../resources/templates/papers/paper.html | 139 ++++++++++++------ 6 files changed, 172 insertions(+), 47 deletions(-) create mode 100644 src/main/java/ru/ulstu/paper/model/AutoCompleteData.java diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index e10135f..29da57d 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -13,6 +13,7 @@ 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.AutoCompleteData; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperListDto; @@ -162,6 +163,11 @@ public class PaperController { return new ResponseEntity<>(paperService.getFormattedReferences(paperDto), new HttpHeaders(), HttpStatus.OK); } + @ModelAttribute("autocompleteData") + public AutoCompleteData getAutocompleteData() { + return paperService.getAutoCompleteData(); + } + private void filterEmptyDeadlines(PaperDto paperDto) { paperDto.setDeadlines(paperDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/java/ru/ulstu/paper/model/AutoCompleteData.java b/src/main/java/ru/ulstu/paper/model/AutoCompleteData.java new file mode 100644 index 0000000..b70a780 --- /dev/null +++ b/src/main/java/ru/ulstu/paper/model/AutoCompleteData.java @@ -0,0 +1,42 @@ +package ru.ulstu.paper.model; + +import java.util.ArrayList; + +public class AutoCompleteData { + ArrayList authors = new ArrayList<>(); + ArrayList publicationTitles = new ArrayList<>(); + ArrayList publishers = new ArrayList<>(); + ArrayList journalOrCollectionTitles = new ArrayList<>(); + + public ArrayList getAuthors() { + return authors; + } + + public void setAuthors(ArrayList authors) { + this.authors = authors; + } + + public ArrayList getPublicationTitles() { + return publicationTitles; + } + + public void setPublicationTitles(ArrayList publicationTitles) { + this.publicationTitles = publicationTitles; + } + + public ArrayList getPublishers() { + return publishers; + } + + public void setPublishers(ArrayList publishers) { + this.publishers = publishers; + } + + public ArrayList getJournalOrCollectionTitles() { + return journalOrCollectionTitles; + } + + public void setJournalOrCollectionTitles(ArrayList journalOrCollectionTitles) { + this.journalOrCollectionTitles = journalOrCollectionTitles; + } +} diff --git a/src/main/java/ru/ulstu/paper/repository/ReferenceRepository.java b/src/main/java/ru/ulstu/paper/repository/ReferenceRepository.java index 68e97d4..1d4321b 100644 --- a/src/main/java/ru/ulstu/paper/repository/ReferenceRepository.java +++ b/src/main/java/ru/ulstu/paper/repository/ReferenceRepository.java @@ -1,8 +1,23 @@ package ru.ulstu.paper.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import ru.ulstu.paper.model.Reference; +import java.util.ArrayList; + public interface ReferenceRepository extends JpaRepository { void deleteById(Integer id); + + @Query("SELECT DISTINCT r.authors FROM Reference r") + ArrayList findDistinctAuthors(); + + @Query("SELECT DISTINCT r.publicationTitle FROM Reference r") + ArrayList findDistinctPublicationTitles(); + + @Query("SELECT DISTINCT r.publisher FROM Reference r") + ArrayList findDistinctPublishers(); + + @Query("SELECT DISTINCT r.journalOrCollectionTitle FROM Reference r where r.journalOrCollectionTitle <> ''") + ArrayList findDistinctJournalOrCollectionTitles(); } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 8a59486..f452c2f 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -7,6 +7,7 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.service.FileService; +import ru.ulstu.paper.model.AutoCompleteData; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperListDto; @@ -378,4 +379,13 @@ public class PaperService { public List findAllCompletedByType(Paper.PaperType type) { return paperRepository.findByTypeAndStatus(type, Paper.PaperStatus.COMPLETED); } + + public AutoCompleteData getAutoCompleteData() { + AutoCompleteData autoCompleteData = new AutoCompleteData(); + autoCompleteData.setAuthors(referenceRepository.findDistinctAuthors()); + autoCompleteData.setJournalOrCollectionTitles(referenceRepository.findDistinctJournalOrCollectionTitles()); + autoCompleteData.setPublicationTitles(referenceRepository.findDistinctPublicationTitles()); + autoCompleteData.setPublishers(referenceRepository.findDistinctPublishers()); + return autoCompleteData; + } } diff --git a/src/main/resources/public/css/paper.css b/src/main/resources/public/css/paper.css index 386c5af..b4b3f85 100644 --- a/src/main/resources/public/css/paper.css +++ b/src/main/resources/public/css/paper.css @@ -30,4 +30,11 @@ #nav-references #formattedReferencesArea { height: 150px; +} + +.ui-autocomplete { + max-height: 200px; + max-width: 400px; + overflow-y: scroll; + overflow-x: hidden; } \ No newline at end of file diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index e80fe85..2755aba 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -4,6 +4,10 @@ layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html"> + + + + @@ -74,54 +78,56 @@ th:field="*{comment}"> -
- - -
+
+ + +
-
- -
- -
- -
-
- -
-
- + +
+ +
+ +
+
+ +
+
+ - + aria-hidden="true"> + +
+
+

Incorrect title

-
-

Incorrect title

-
-
- + -
-
- - -

Incorrect title

-
+ +
+ + +

Incorrect title

+
@@ -215,14 +221,14 @@
@@ -235,7 +241,7 @@
@@ -248,7 +254,7 @@
@@ -519,6 +525,45 @@ } } } + + + From 01bcac2680f4b0e64e5fd69b03d3679d7c0bd759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=9C?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=8F?= Date: Fri, 24 May 2019 00:26:38 +0400 Subject: [PATCH 11/13] #127 allow nullable year --- src/main/java/ru/ulstu/paper/service/PaperService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index f452c2f..cfb1a0a 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -361,7 +361,7 @@ public class PaperService { referenceDto.getAuthors(), referenceDto.getPublicationTitle(), StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ", - referenceDto.getPublicationYear().toString(), + referenceDto.getPublicationYear() != null ? referenceDto.getPublicationYear().toString() : "", referenceDto.getPages(), StringUtils.isEmpty(referenceDto.getJournalOrCollectionTitle()) ? "." : " // " + referenceDto.getJournalOrCollectionTitle() + "."); } @@ -369,7 +369,7 @@ public class PaperService { public String getSpringerReference(ReferenceDto referenceDto) { return MessageFormat.format("{0} ({1}) {2}.{3} {4}pp {5}", referenceDto.getAuthors(), - referenceDto.getPublicationYear().toString(), + referenceDto.getPublicationYear() != null ? referenceDto.getPublicationYear().toString() : "", referenceDto.getPublicationTitle(), referenceDto.getReferenceType() == ARTICLE ? " " + referenceDto.getJournalOrCollectionTitle() + "," : "", StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ", From 8bb9e3a84469d2ff8529a463459f91497cf9600a Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Fri, 24 May 2019 01:52:50 +0400 Subject: [PATCH 12/13] #89 jquery --- src/main/resources/public/js/users.js | 38 +++++++++---------- .../resources/templates/resetRequest.html | 12 +++--- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/main/resources/public/js/users.js b/src/main/resources/public/js/users.js index 1ea26e3..e31d3ad 100644 --- a/src/main/resources/public/js/users.js +++ b/src/main/resources/public/js/users.js @@ -1,7 +1,7 @@ function changePassword() { - oldPassword = document.getElementById("oldPassword").value - password = document.getElementById("password").value - confirmPassword = document.getElementById("confirmPassword").value + oldPassword = $("#oldPassword").val() + password = $("#password").val() + confirmPassword = $("#confirmPassword").val() if ([oldPassword.length, password.length, confirmPassword.length].includes(0)) { showFeedbackMessage("Заполните все поля", MessageTypesEnum.WARNING); @@ -23,7 +23,7 @@ function changePassword() { }), method: "POST", success: function() { - document.getElementById("closeModalPassword").click(); + $("#closeModalPassword").click(); showFeedbackMessage("Пароль был обновлен", MessageTypesEnum.SUCCESS) }, @@ -34,7 +34,7 @@ function changePassword() { } function inviteUser() { - email = document.getElementById("email").value; + email = $("#email").val(); if (!isEmailValid(email)) { showFeedbackMessage("Некорректный почтовый ящик", MessageTypesEnum.WARNING); return; @@ -45,7 +45,7 @@ function inviteUser() { contentType: "application/json; charset=utf-8", method: "POST", success: function() { - document.getElementById("closeModalInvite").click(); + $("#closeModalInvite").click(); showFeedbackMessage("Пользователь был успешно приглашен", MessageTypesEnum.SUCCESS) }, error: function(errorData) { @@ -55,13 +55,13 @@ function inviteUser() { } function requestResetPassword() { - email = document.getElementById("emailReset").value + email = $("#emailReset").val() if (!isEmailValid(email)) { showFeedbackMessage("Некорректный почтовый ящик", MessageTypesEnum.WARNING); return; } - document.getElementById("dvloader").hidden = false; + $("#dvloader").show(); $.ajax({ url:"/api/1.0/users/password-reset-request?email=" + email, @@ -69,27 +69,27 @@ function requestResetPassword() { method: "POST", success: function() { showFeedbackMessage("Проверочный код был отправлен на указанный почтовый ящик", MessageTypesEnum.SUCCESS) - document.getElementById("passwordNew").hidden = false - document.getElementById("passwordConfirm").hidden = false - document.getElementById("btnReset").hidden = false - document.getElementById("resetKey").hidden = false - document.getElementById("emailReset").hidden = true - document.getElementById("btnSend").hidden = true - document.getElementById("dvloader").hidden = true; + $("#passwordNew").show() + $("#passwordConfirm").show() + $("#btnReset").show() + $("#resetKey").show() + $("#emailReset").hide() + $("#btnSend").hide() + $("#dvloader").hide() }, error: function(errorData) { showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING) - document.getElementById("dvloader").hidden = true; + $("#dvloader").hide() } }) } function resetPassword() { - passwordNew = document.getElementById("passwordNew").value; - passwordConfirm = document.getElementById("passwordConfirm").value; - resetKey = document.getElementById("resetKey").value; + passwordNew = $("#passwordNew").val(); + passwordConfirm = $("#passwordConfirm").val(); + resetKey = $("#resetKey").val(); if ([passwordNew, passwordConfirm, resetKey].includes("")) { showFeedbackMessage("Заполните все поля", MessageTypesEnum.WARNING); diff --git a/src/main/resources/templates/resetRequest.html b/src/main/resources/templates/resetRequest.html index 73bff76..4a2aeab 100644 --- a/src/main/resources/templates/resetRequest.html +++ b/src/main/resources/templates/resetRequest.html @@ -10,7 +10,7 @@
@@ -25,22 +25,22 @@
+ placeholder="Новый пароль" style="display:none"/>
+ placeholder="Подтвердите пароль" style="display:none"/>
+ placeholder="Код подтверждения" style="display:none"/>
- + -