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

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

Closes #113

See merge request romanov73/ng-tracker!71
environments/staging/deployments/39
Anton Romanov 5 years ago
commit 54c6fe815d

@ -5,6 +5,7 @@ import org.springframework.ui.ModelMap;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@ -78,6 +79,12 @@ public class ProjectController {
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) {
projectDto.setDeadlines(projectDto.getDeadlines().stream()
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))

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

@ -72,6 +72,15 @@ public class ProjectService {
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 {
project.setDescription(projectDto.getDescription());
project.setStatus(projectDto.getStatus() == null ? APPLICATION : projectDto.getStatus());

@ -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;
});
});
/*]]>*/

@ -40,7 +40,7 @@
</div>
</div>
<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-content">
<i class="fa fa-arrow-right fa-3x"></i>

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

@ -12,6 +12,10 @@
<span class="text-muted" th:text="${project.description}"/>
</a>
<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>
</body>

@ -4,7 +4,7 @@
<meta charset="UTF-8"/>
</head>
<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()}">
<div th:case="'APPLICATION'">
<i class="fa fa-circle fa-stack-2x text-draft"></i>

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

Loading…
Cancel
Save