77 lines
1.9 KiB
Java
77 lines
1.9 KiB
Java
package ru.ulstu.paper.controller;
|
|
|
|
import ru.ulstu.core.util.FacesUtil;
|
|
import ru.ulstu.paper.model.Paper;
|
|
import ru.ulstu.paper.service.PaperService;
|
|
import ru.ulstu.user.service.UserService;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.faces.view.ViewScoped;
|
|
import javax.inject.Inject;
|
|
import javax.inject.Named;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
@Named
|
|
@ViewScoped
|
|
public class PaperDashboardView {
|
|
@Inject
|
|
private PaperService paperService;
|
|
|
|
@Inject
|
|
private UserService userService;
|
|
|
|
private List<Paper> papers;
|
|
|
|
private List<Paper> selectedPapers = new ArrayList<>();
|
|
|
|
private String newPaperTitle;
|
|
|
|
@PostConstruct
|
|
public void init() {
|
|
papers = paperService.findAllActiveByCurrentUser();
|
|
}
|
|
|
|
public List<Paper> getPapers() {
|
|
return papers;
|
|
}
|
|
|
|
public void create() {
|
|
paperService.createByTitle(newPaperTitle);
|
|
FacesUtil.showInfoMessage("Статья создана", newPaperTitle);
|
|
newPaperTitle = "";
|
|
papers = paperService.findAllActiveByCurrentUser();
|
|
}
|
|
|
|
public void deleteSelected() {
|
|
paperService.delete(selectedPapers);
|
|
papers = paperService.findAllActiveByCurrentUser();
|
|
FacesUtil.showInfoMessage("Было удалено статей: " + selectedPapers.size(), "");
|
|
}
|
|
|
|
public List<Paper.PaperStatus> getPaperStatuses() {
|
|
return Arrays.asList(Paper.PaperStatus.values());
|
|
}
|
|
|
|
public String getNewPaperTitle() {
|
|
return newPaperTitle;
|
|
}
|
|
|
|
public void setNewPaperTitle(String newPaperTitle) {
|
|
this.newPaperTitle = newPaperTitle;
|
|
}
|
|
|
|
public List<Paper> getSelectedPapers() {
|
|
return selectedPapers;
|
|
}
|
|
|
|
public void setSelectedPapers(List<Paper> selectedPapers) {
|
|
this.selectedPapers = selectedPapers;
|
|
}
|
|
|
|
public String getCurrentUser() {
|
|
return userService.getCurrentUser().getUserAbbreviate();
|
|
}
|
|
}
|