Merge branch '113-delete-project' into 'dev'

Resolve "Реализовать удаление проекта"

Closes #113

See merge request romanov73/ng-tracker!71
This commit is contained in:
Anton Romanov 2019-04-24 09:34:12 +00:00
commit 54c6fe815d
9 changed files with 66 additions and 14 deletions

View File

@ -5,6 +5,7 @@ import org.springframework.ui.ModelMap;
import org.springframework.validation.Errors; 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.ModelAttribute;
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.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@ -78,6 +79,12 @@ public class ProjectController {
return "/projects/project"; return "/projects/project";
} }
@GetMapping("/delete/{project-id}")
public String delete(@PathVariable("project-id") Integer projectId) throws IOException {
projectService.delete(projectId);
return String.format("redirect:%s", "/projects/projects");
}
private void filterEmptyDeadlines(ProjectDto projectDto) { private void filterEmptyDeadlines(ProjectDto projectDto) {
projectDto.setDeadlines(projectDto.getDeadlines().stream() projectDto.setDeadlines(projectDto.getDeadlines().stream()
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))

View File

@ -15,7 +15,6 @@ public class ProjectDto {
@NotEmpty @NotEmpty
private String title; private String title;
private Project.ProjectStatus status; private Project.ProjectStatus status;
private String statusName;
private String description; private String description;
private List<Deadline> deadlines = new ArrayList<>(); private List<Deadline> deadlines = new ArrayList<>();
private GrantDto grant; private GrantDto grant;
@ -40,7 +39,6 @@ public class ProjectDto {
this.id = id; this.id = id;
this.title = title; this.title = title;
this.status = status; this.status = status;
this.statusName = status.getStatusName();
this.description = description; this.description = description;
this.grant = grant; this.grant = grant;
this.repository = repository; this.repository = repository;
@ -53,7 +51,6 @@ public class ProjectDto {
this.id = project.getId(); this.id = project.getId();
this.title = project.getTitle(); this.title = project.getTitle();
this.status = project.getStatus(); this.status = project.getStatus();
this.statusName = project.getStatus().getStatusName();
this.description = project.getDescription(); this.description = project.getDescription();
this.applicationFileName = project.getApplication() == null ? null : project.getApplication().getName(); this.applicationFileName = project.getApplication() == null ? null : project.getApplication().getName();
this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant()); this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant());
@ -85,14 +82,6 @@ public class ProjectDto {
this.status = status; this.status = status;
} }
public String getStatusName() {
return statusName;
}
public void setStatusName(String statusName) {
this.statusName = statusName;
}
public String getDescription() { public String getDescription() {
return description; return description;
} }

View File

@ -72,6 +72,15 @@ public class ProjectService {
return project; return project;
} }
@Transactional
public void delete(Integer projectId) throws IOException {
Project project = projectRepository.findOne(projectId);
if (project.getApplication() != null) {
fileService.deleteFile(project.getApplication());
}
projectRepository.delete(project);
}
private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException { private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException {
project.setDescription(projectDto.getDescription()); project.setDescription(projectDto.getDescription());
project.setStatus(projectDto.getStatus() == null ? APPLICATION : projectDto.getStatus()); project.setStatus(projectDto.getStatus() == null ? APPLICATION : projectDto.getStatus());

View File

@ -0,0 +1,42 @@
/*<![CDATA[*/
$(document).ready(function () {
$(".project-row").mouseenter(function (event) {
var projectRow = $(event.target).closest(".project-row");
$(projectRow).css("background-color", "#f8f9fa");
$(projectRow).find(".remove-paper").removeClass("d-none");
});
$(".project-row").mouseleave(function (event) {
var projectRow = $(event.target).closest(".project-row");
$(projectRow).css("background-color", "white");
$(projectRow).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>'+
' <button class="btn primary" data-dismiss="modal" aria-hidden="true">Нет</button>'+
' </div>\n' +
' </div>\n' +
' </div>\n' +
' </div>');
}
$('#dataConfirmModal').find('#myModalLabel').text($(this).attr('data-confirm'));
$('#dataConfirmOK').attr('href', href);
$('#dataConfirmModal').modal({show:true});
return false;
});
});
/*]]>*/

View File

@ -40,7 +40,7 @@
</div> </div>
</div> </div>
<div class="col-md-4 col-sm-6 portfolio-item"> <div class="col-md-4 col-sm-6 portfolio-item">
<a class="portfolio-link" href="./projects/projects"> <a class="portfolio-link" href="./projects/dashboard">
<div class="portfolio-hover"> <div class="portfolio-hover">
<div class="portfolio-hover-content"> <div class="portfolio-hover-content">
<i class="fa fa-arrow-right fa-3x"></i> <i class="fa fa-arrow-right fa-3x"></i>

View File

@ -11,7 +11,6 @@
</div> </div>
<div class="col col-10 text-right"> <div class="col col-10 text-right">
<h7 class="service-heading" th:text="${project.title}"> title</h7> <h7 class="service-heading" th:text="${project.title}"> title</h7>
<p class="text-muted" th:text="${project.statusName}"> status</p>
</div> </div>
</div> </div>
</div> </div>

View File

@ -12,6 +12,10 @@
<span class="text-muted" th:text="${project.description}"/> <span class="text-muted" th:text="${project.description}"/>
</a> </a>
<input class="id-class" type="hidden" th:value="${project.id}"/> <input class="id-class" type="hidden" th:value="${project.id}"/>
<a class="remove-paper pull-right d-none" th:href="@{'/projects/delete/'+${project.id}}"
data-confirm="Удалить проект?">
<i class="fa fa-trash" aria-hidden="true"></i>
</a>
</div> </div>
</div> </div>
</body> </body>

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
</head> </head>
<body> <body>
<span th:fragment="paperStatus (paperStatus)" class="fa-stack fa-1x"> <span th:fragment="projectStatus (projectStatus)" class="fa-stack fa-1x">
<th:block th:switch="${projectStatus.name()}"> <th:block th:switch="${projectStatus.name()}">
<div th:case="'APPLICATION'"> <div th:case="'APPLICATION'">
<i class="fa fa-circle fa-stack-2x text-draft"></i> <i class="fa fa-circle fa-stack-2x text-draft"></i>

View File

@ -27,7 +27,9 @@
</div> </div>
</div> </div>
</section> </section>
<div id="modalDelete"/>
</form> </form>
<script src="/js/projects.js"></script>
</div> </div>
</body> </body>
</html> </html>