Merge branch '98-project-tasks' into 'dev'

Resolve "Задачи проекта"

Closes #98

See merge request romanov73/ng-tracker!74
environments/staging/deployments/75
Anton Romanov 5 years ago
commit 330ffc4df1

@ -4,11 +4,15 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.format.annotation.DateTimeFormat;
import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.user.model.User;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@Entity
@ -20,6 +24,11 @@ public class Deadline extends BaseEntity {
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date date;
@OneToMany(targetEntity = User.class, fetch = FetchType.EAGER)
private List<User> executors;
private Boolean done;
public Deadline() {
}
@ -28,13 +37,24 @@ public class Deadline extends BaseEntity {
this.description = description;
}
public Deadline(Date deadlineDate, String description, List<User> executors, Boolean done) {
this.date = deadlineDate;
this.description = description;
this.executors = executors;
this.done = done;
}
@JsonCreator
public Deadline(@JsonProperty("id") Integer id,
@JsonProperty("description") String description,
@JsonProperty("date") Date date) {
@JsonProperty("date") Date date,
@JsonProperty("executors") List<User> executors,
@JsonProperty("done") Boolean done) {
this.setId(id);
this.description = description;
this.date = date;
this.executors = executors;
this.done = done;
}
public String getDescription() {
@ -53,6 +73,22 @@ public class Deadline extends BaseEntity {
this.date = date;
}
public List<User> getExecutors() {
return executors;
}
public void setExecutors(List<User> executors) {
this.executors = executors;
}
public Boolean getDone() {
return done;
}
public void setDone(Boolean done) {
this.done = done;
}
@Override
public boolean equals(Object o) {
if (this == o) {
@ -72,11 +108,13 @@ public class Deadline extends BaseEntity {
}
return getId().equals(deadline.getId()) &&
description.equals(deadline.description) &&
date.equals(deadline.date);
date.equals(deadline.date) &&
executors.equals(deadline.executors) &&
done.equals(deadline.done);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), description, date);
return Objects.hash(super.hashCode(), description, date, executors, done);
}
}

@ -30,6 +30,8 @@ public class DeadlineService {
Deadline updateDeadline = deadlineRepository.findOne(deadline.getId());
updateDeadline.setDate(deadline.getDate());
updateDeadline.setDescription(deadline.getDescription());
updateDeadline.setExecutors(deadline.getExecutors());
updateDeadline.setDone(deadline.getDone());
deadlineRepository.save(updateDeadline);
return updateDeadline;
}
@ -39,6 +41,8 @@ public class DeadlineService {
Deadline newDeadline = new Deadline();
newDeadline.setDate(deadline.getDate());
newDeadline.setDescription(deadline.getDescription());
newDeadline.setExecutors(deadline.getExecutors());
newDeadline.setDone(deadline.getDone());
newDeadline = deadlineRepository.save(newDeadline);
return newDeadline;
}

@ -13,6 +13,7 @@ import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.project.model.Project;
import ru.ulstu.project.model.ProjectDto;
import ru.ulstu.project.service.ProjectService;
import ru.ulstu.user.model.User;
import springfox.documentation.annotations.ApiIgnore;
import javax.validation.Valid;
@ -79,12 +80,24 @@ public class ProjectController {
return "/projects/project";
}
@PostMapping(value = "/project", params = "removeDeadline")
public String removeDeadline(ProjectDto projectDto,
@RequestParam(value = "removeDeadline") Integer deadlineId) {
projectService.removeDeadline(projectDto, deadlineId);
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");
}
@ModelAttribute("allExecutors")
public List<User> getAllExecutors(ProjectDto projectDto) {
return projectService.getProjectExecutors(projectDto);
}
private void filterEmptyDeadlines(ProjectDto projectDto) {
projectDto.setDeadlines(projectDto.getDeadlines().stream()
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))

@ -2,29 +2,36 @@ package ru.ulstu.project.model;
import org.hibernate.validator.constraints.NotBlank;
import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.core.model.UserContainer;
import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.file.model.FileData;
import ru.ulstu.grant.model.Grant;
import ru.ulstu.user.model.User;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Entity
public class Project extends BaseEntity {
public class Project extends BaseEntity implements UserContainer {
public enum ProjectStatus {
APPLICATION("Заявка"),
ON_COMPETITION("Отправлен на конкурс"),
SUCCESSFUL_PASSAGE("Успешное прохождение"),
TECHNICAL_TASK("Техническое задание"),
OPEN("Открыт"),
IN_WORK("В работе"),
COMPLETED("Завершен"),
CERTIFICATE_ISSUED("Оформление свидетельства"),
CLOSED("Закрыт"),
FAILED("Провалены сроки");
private String statusName;
@ -42,7 +49,7 @@ public class Project extends BaseEntity {
private String title;
@Enumerated(value = EnumType.STRING)
private ProjectStatus status = ProjectStatus.APPLICATION;
private ProjectStatus status = ProjectStatus.TECHNICAL_TASK;
@NotNull
private String description;
@ -62,6 +69,9 @@ public class Project extends BaseEntity {
@JoinColumn(name = "file_id")
private FileData application;
@ManyToMany(fetch = FetchType.LAZY)
private List<User> executors = new ArrayList<>();
public String getTitle() {
return title;
}
@ -117,4 +127,18 @@ public class Project extends BaseEntity {
public void setApplication(FileData application) {
this.application = application;
}
public List<User> getExecutors() {
return executors;
}
public void setExecutors(List<User> executors) {
this.executors = executors;
}
@Override
public Set<User> getUsers() {
Set<User> users = new HashSet<User>(getExecutors());
return users;
}
}

@ -3,11 +3,19 @@ package ru.ulstu.project.model;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.NotEmpty;
import org.thymeleaf.util.StringUtils;
import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.user.model.User;
import ru.ulstu.user.model.UserDto;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import static ru.ulstu.core.util.StreamApiUtils.convert;
public class ProjectDto {
private Integer id;
@ -20,6 +28,11 @@ public class ProjectDto {
private GrantDto grant;
private String repository;
private String applicationFileName;
private List<Integer> removedDeadlineIds = new ArrayList<>();
private Set<Integer> executorIds;
private List<UserDto> executors;
private final static int MAX_EXECUTORS_LENGTH = 40;
public ProjectDto() {
}
@ -35,7 +48,9 @@ public class ProjectDto {
@JsonProperty("description") String description,
@JsonProperty("grant") GrantDto grant,
@JsonProperty("repository") String repository,
@JsonProperty("deadlines") List<Deadline> deadlines) {
@JsonProperty("deadlines") List<Deadline> deadlines,
@JsonProperty("executorIds") Set<Integer> executorIds,
@JsonProperty("executors") List<UserDto> executors) {
this.id = id;
this.title = title;
this.status = status;
@ -44,10 +59,13 @@ public class ProjectDto {
this.repository = repository;
this.deadlines = deadlines;
this.applicationFileName = null;
this.executorIds = executorIds;
this.executors = executors;
}
public ProjectDto(Project project) {
Set<User> users = new HashSet<User>(project.getExecutors());
this.id = project.getId();
this.title = project.getTitle();
this.status = project.getStatus();
@ -56,6 +74,8 @@ public class ProjectDto {
this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant());
this.repository = project.getRepository();
this.deadlines = project.getDeadlines();
this.executorIds = convert(users, user -> user.getId());
this.executors = convert(project.getExecutors(), UserDto::new);
}
public Integer getId() {
@ -121,4 +141,35 @@ public class ProjectDto {
public void setApplicationFileName(String applicationFileName) {
this.applicationFileName = applicationFileName;
}
public List<Integer> getRemovedDeadlineIds() {
return removedDeadlineIds;
}
public void setRemovedDeadlineIds(List<Integer> removedDeadlineIds) {
this.removedDeadlineIds = removedDeadlineIds;
}
public Set<Integer> getExecutorIds() {
return executorIds;
}
public void setExecutorIds(Set<Integer> executorIds) {
this.executorIds = executorIds;
}
public List<UserDto> getExecutors() {
return executors;
}
public void setExecutors(List<UserDto> executors) {
this.executors = executors;
}
public String getExecutorsString() {
return StringUtils.abbreviate(executors
.stream()
.map(executor -> executor.getLastName())
.collect(Collectors.joining(", ")), MAX_EXECUTORS_LENGTH);
}
}

@ -9,6 +9,8 @@ import ru.ulstu.grant.repository.GrantRepository;
import ru.ulstu.project.model.Project;
import ru.ulstu.project.model.ProjectDto;
import ru.ulstu.project.repository.ProjectRepository;
import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService;
import java.io.IOException;
import java.util.Arrays;
@ -16,7 +18,7 @@ import java.util.List;
import static org.springframework.util.ObjectUtils.isEmpty;
import static ru.ulstu.core.util.StreamApiUtils.convert;
import static ru.ulstu.project.model.Project.ProjectStatus.APPLICATION;
import static ru.ulstu.project.model.Project.ProjectStatus.TECHNICAL_TASK;
@Service
public class ProjectService {
@ -26,15 +28,18 @@ public class ProjectService {
private final DeadlineService deadlineService;
private final GrantRepository grantRepository;
private final FileService fileService;
private final UserService userService;
public ProjectService(ProjectRepository projectRepository,
DeadlineService deadlineService,
GrantRepository grantRepository,
FileService fileService) {
FileService fileService,
UserService userService) {
this.projectRepository = projectRepository;
this.deadlineService = deadlineService;
this.grantRepository = grantRepository;
this.fileService = fileService;
this.userService = userService;
}
public List<Project> findAll() {
@ -83,7 +88,7 @@ public class ProjectService {
private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException {
project.setDescription(projectDto.getDescription());
project.setStatus(projectDto.getStatus() == null ? APPLICATION : projectDto.getStatus());
project.setStatus(projectDto.getStatus() == null ? TECHNICAL_TASK : projectDto.getStatus());
project.setTitle(projectDto.getTitle());
if (projectDto.getGrant() != null && projectDto.getGrant().getId() != null) {
project.setGrant(grantRepository.findOne(projectDto.getGrant().getId()));
@ -104,8 +109,20 @@ public class ProjectService {
}
}
public void removeDeadline(ProjectDto projectDto, Integer deadlineId) {
if (deadlineId != null) {
projectDto.getRemovedDeadlineIds().add(deadlineId);
}
projectDto.getDeadlines().remove((int) deadlineId);
}
public Project findById(Integer id) {
return projectRepository.findOne(id);
}
public List<User> getProjectExecutors(ProjectDto projectDto) {
List<User> users = userService.findAll();
return users;
}
}

@ -0,0 +1,13 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet author="anton" id="20190506_000000-1">
<addColumn tableName="deadline">
<column name="executor" type="varchar(255)"/>
</addColumn>
<addColumn tableName="deadline">
<column name="done" type="boolean"/>
</addColumn>
</changeSet>
</databaseChangeLog>

@ -0,0 +1,17 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet author="anton" id="20190506_000000-2">
<createTable tableName="project_executors">
<column name="project_id" type="integer"/>
<column name="executors_id" type="integer"/>
</createTable>
<addForeignKeyConstraint baseTableName="project_executors" baseColumnNames="project_id"
constraintName="fk_project_project_executors" referencedTableName="project"
referencedColumnNames="id"/>
<addForeignKeyConstraint baseTableName="project_executors" baseColumnNames="executors_id"
constraintName="fk_user_project_executors" referencedTableName="users"
referencedColumnNames="id"/>
</changeSet>
</databaseChangeLog>

@ -0,0 +1,14 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet author="anton" id="20190517_000001-1">
<modifyDataType tableName="deadline"
columnName="executor"
newDataType="integer"
schemaName="public"/>
<addForeignKeyConstraint baseTableName="deadline" baseColumnNames="executor"
constraintName="fk_deadline_executor" referencedTableName="users"
referencedColumnNames="id"/>
</changeSet>
</databaseChangeLog>

@ -0,0 +1,11 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet author="anton" id="20190528_000000-1">
<renameColumn tableName="deadline"
columnDataType="integer"
newColumnName="executors"
oldColumnName="executor"/>
</changeSet>
</databaseChangeLog>

@ -0,0 +1,17 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
<changeSet author="anton" id="20190528_000000-3">
<createTable tableName="deadline_executors">
<column name="deadline_id" type="integer"/>
<column name="executors_id" type="integer"/>
</createTable>
<addForeignKeyConstraint baseTableName="deadline_executors" baseColumnNames="deadline_id"
constraintName="fk_deadline_deadline_executors" referencedTableName="deadline"
referencedColumnNames="id"/>
<addForeignKeyConstraint baseTableName="deadline_executors" baseColumnNames="executors_id"
constraintName="fk_user_deadline_executors" referencedTableName="users"
referencedColumnNames="id"/>
</changeSet>
</databaseChangeLog>

@ -39,9 +39,14 @@
<include file="db/changelog-20190430_000000-schema.xml"/>
<include file="db/changelog-20190505_000000-schema.xml"/>
<include file="db/changelog-20190505_000001-schema.xml"/>
<include file="db/changelog-20190506_000000-schema.xml"/>
<include file="db/changelog-20190506_000001-schema.xml"/>
<include file="db/changelog-20190507_000000-schema.xml"/>
<include file="db/changelog-20190507_000001-schema.xml"/>
<include file="db/changelog-20190511_000000-schema.xml"/>
<include file="db/changelog-20190517_000001-schema.xml"/>
<include file="db/changelog-20190520_000000-schema.xml"/>
<include file="db/changelog-20190523_000000-schema.xml"/>
<include file="db/changelog-20190528_000000-schema.xml"/>
<include file="db/changelog-20190528_000002-schema.xml"/>
</databaseChangeLog>

@ -0,0 +1,5 @@
.div-deadline-done {
width: 60%;
height: 100%;
float: right;
}

@ -6,19 +6,19 @@
<body>
<span th:fragment="projectStatus (projectStatus)" class="fa-stack fa-1x">
<th:block th:switch="${projectStatus.name()}">
<div th:case="'APPLICATION'">
<div th:case="'TECHNICAL_TASK'">
<i class="fa fa-circle fa-stack-2x text-draft"></i>
</div>
<div th:case="'ON_COMPETITION'">
<div th:case="'OPEN'">
<i class="fa fa-circle fa-stack-2x text-review"></i>
</div>
<div th:case="'SUCCESSFUL_PASSAGE'">
<div th:case="'IN_WORK'">
<i class="fa fa-circle fa-stack-2x text-accepted"></i>
</div>
<div th:case="'IN_WORK'">
<div th:case="'CERTIFICATE_ISSUED'">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
</div>
<div th:case="'COMPLETED'">
<div th:case="'CLOSED'">
<i class="fa fa-circle fa-stack-2x text-success"></i>
</div>
<div th:case="'FAILED'">

@ -3,7 +3,7 @@
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
<head>
<link rel="stylesheet" href="../css/project.css"/>
</head>
<body>
@ -71,7 +71,8 @@
<div class="form-group">
<label>Дедлайны показателей:</label>
<div class="row" th:each="deadline, rowStat : *{deadlines}">
<div class="row" th:each="deadline, rowStat : *{deadlines}"
style="margin-bottom: 15px;">
<input type="hidden" th:field="*{deadlines[__${rowStat.index}__].id}"/>
<div class="col-6 div-deadline-date">
<input type="date" class="form-control form-deadline-date" name="deadline"
@ -89,6 +90,20 @@
aria-hidden="true"><i class="fa fa-times"/></span>
</a>
</div>
<div class="col-12" style="margin-bottom: 15px;"></div>
<div class="col-10 div-deadline-executor">
<select class="selectpicker form-control" multiple="true" data-live-search="true"
title="-- Выберите исполнителя --" id="executors"
th:field="*{deadlines[__${rowStat.index}__].executors}" data-size="5">
<option th:each="executors : ${allExecutors}" th:value="${executors.id}"
th:text="${executors.lastName}"> Участник
</option>
</select>
</div>
<div class="col-2">
<input class="form-control div-deadline-done" type="checkbox"
th:field="*{deadlines[__${rowStat.index}__].done}"/>
</div>
</div>
<p th:if="${#fields.hasErrors('deadlines')}" th:errors="*{deadlines}"
class="alert alert-danger">Incorrect title</p>

Loading…
Cancel
Save