Adding edit views
This commit is contained in:
parent
4fb047f9e5
commit
e3a071a7f1
@ -6,6 +6,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -15,16 +16,16 @@ import java.util.Optional;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class Assessment extends BaseEntity {
|
public class Assessment extends BaseEntity {
|
||||||
@OneToMany(fetch = FetchType.EAGER)
|
@OneToMany(fetch = FetchType.EAGER)
|
||||||
private List<Question> questions;
|
private List<Question> questions = new ArrayList<>();
|
||||||
|
|
||||||
@OneToMany(fetch = FetchType.EAGER, mappedBy = "assessment", cascade = {CascadeType.ALL})
|
@OneToMany(fetch = FetchType.EAGER, mappedBy = "assessment", cascade = {CascadeType.ALL})
|
||||||
private List<Submission> submissions;
|
private List<Submission> submissions = new ArrayList<>();
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
private AppUser appUser;
|
private AppUser appUser;
|
||||||
|
|
||||||
@OneToMany(fetch = FetchType.EAGER, mappedBy = "assessment", cascade = {CascadeType.ALL})
|
@OneToMany(fetch = FetchType.EAGER, mappedBy = "assessment", cascade = {CascadeType.ALL})
|
||||||
private List<AssessmentEvent> assessmentEvents = List.of();
|
private List<AssessmentEvent> assessmentEvents = new ArrayList<>();
|
||||||
|
|
||||||
public Submission getCurrentSubmission() {
|
public Submission getCurrentSubmission() {
|
||||||
return submissions.getLast();
|
return submissions.getLast();
|
||||||
|
@ -12,5 +12,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class Question extends BaseEntity{
|
public class Question extends BaseEntity{
|
||||||
|
private String title;
|
||||||
|
private String description;
|
||||||
private String content;
|
private String content;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.primefactorsolutions.repositories;
|
||||||
|
|
||||||
|
import com.primefactorsolutions.model.Question;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public interface QuestionRepository extends JpaRepository<Question, UUID> {
|
||||||
|
}
|
@ -145,4 +145,8 @@ public class AssessmentService {
|
|||||||
submission.setResponse(currSubmission.getResponse());
|
submission.setResponse(currSubmission.getResponse());
|
||||||
Assessment saved = assessmentRepository.save(assessment);
|
Assessment saved = assessmentRepository.save(assessment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Assessment saveAssessment(final Assessment assessment) {
|
||||||
|
return assessmentRepository.save(assessment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.primefactorsolutions.service;
|
||||||
|
|
||||||
|
import com.primefactorsolutions.model.Question;
|
||||||
|
import com.primefactorsolutions.repositories.QuestionRepository;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Data
|
||||||
|
public class QuestionService {
|
||||||
|
private final QuestionRepository questionRepository;
|
||||||
|
|
||||||
|
public List<Question> getQuestions() {
|
||||||
|
return questionRepository.findAll();
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,15 @@
|
|||||||
package com.primefactorsolutions.views;
|
package com.primefactorsolutions.views;
|
||||||
|
|
||||||
|
import com.primefactorsolutions.model.AppUser;
|
||||||
import com.primefactorsolutions.model.Assessment;
|
import com.primefactorsolutions.model.Assessment;
|
||||||
|
import com.primefactorsolutions.model.Question;
|
||||||
import com.primefactorsolutions.service.AssessmentService;
|
import com.primefactorsolutions.service.AssessmentService;
|
||||||
|
import com.primefactorsolutions.service.QuestionService;
|
||||||
|
import com.primefactorsolutions.service.UserService;
|
||||||
import com.vaadin.flow.component.Component;
|
import com.vaadin.flow.component.Component;
|
||||||
import com.vaadin.flow.component.textfield.TextField;
|
import com.vaadin.flow.component.ItemLabelGenerator;
|
||||||
|
import com.vaadin.flow.component.combobox.ComboBox;
|
||||||
|
import com.vaadin.flow.component.dependency.Uses;
|
||||||
import com.vaadin.flow.router.BeforeEvent;
|
import com.vaadin.flow.router.BeforeEvent;
|
||||||
import com.vaadin.flow.router.HasUrlParameter;
|
import com.vaadin.flow.router.HasUrlParameter;
|
||||||
import com.vaadin.flow.router.PageTitle;
|
import com.vaadin.flow.router.PageTitle;
|
||||||
@ -11,6 +17,7 @@ import com.vaadin.flow.router.Route;
|
|||||||
import com.vaadin.flow.spring.annotation.SpringComponent;
|
import com.vaadin.flow.spring.annotation.SpringComponent;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.vaadin.firitin.fields.SubListSelector;
|
||||||
import org.vaadin.firitin.form.BeanValidationForm;
|
import org.vaadin.firitin.form.BeanValidationForm;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -20,32 +27,43 @@ import java.util.UUID;
|
|||||||
@Scope("prototype")
|
@Scope("prototype")
|
||||||
@PageTitle("Assessments")
|
@PageTitle("Assessments")
|
||||||
@Route(value = "/assessments", layout = MainLayout.class)
|
@Route(value = "/assessments", layout = MainLayout.class)
|
||||||
|
@Uses(ComboBox.class)
|
||||||
public class AssessmentView extends BeanValidationForm<Assessment> implements HasUrlParameter<String> {
|
public class AssessmentView extends BeanValidationForm<Assessment> implements HasUrlParameter<String> {
|
||||||
private final AssessmentService assessmentService;
|
private final AssessmentService assessmentService;
|
||||||
|
|
||||||
private final TextField appUserName = new TextField();
|
private ComboBox<AppUser> appUser = null;
|
||||||
|
private SubListSelector<Question> questions = null;
|
||||||
|
|
||||||
public AssessmentView(AssessmentService assessmentService) {
|
public AssessmentView(AssessmentService assessmentService, QuestionService questionService, UserService userService) {
|
||||||
super(Assessment.class);
|
super(Assessment.class);
|
||||||
setEntityWithEnabledSave(new Assessment());
|
|
||||||
this.assessmentService = assessmentService;
|
this.assessmentService = assessmentService;
|
||||||
|
|
||||||
setSavedHandler((SavedHandler<Assessment>) assessment -> {
|
appUser = new ComboBox<>("AppUser", userService.getUsers());
|
||||||
System.out.println(assessment);
|
appUser.setItemLabelGenerator((ItemLabelGenerator<AppUser>) AppUser::getEmail);
|
||||||
});
|
appUser.setReadOnly(false);
|
||||||
}
|
|
||||||
|
|
||||||
|
questions = new SubListSelector<>(Question.class);
|
||||||
|
questions.setItemLabelGenerator((ItemLabelGenerator<Question>) Question::getTitle);
|
||||||
|
questions.setReadOnly(false);
|
||||||
|
questions.setAvailableOptions(questionService.getQuestions());
|
||||||
|
|
||||||
|
setSavedHandler((SavedHandler<Assessment>) this.assessmentService::saveAssessment);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setParameter(final BeforeEvent beforeEvent, final String s) {
|
public void setParameter(final BeforeEvent beforeEvent, final String s) {
|
||||||
if (StringUtils.isNotBlank(s) && !"new".equals(s)) {
|
if (StringUtils.isNotBlank(s) && !"new".equals(s)) {
|
||||||
var assessment = assessmentService.getAssessment(UUID.fromString(s));
|
var assessment = assessmentService.getAssessment(UUID.fromString(s));
|
||||||
|
|
||||||
|
setEntityWithEnabledSave(assessment);
|
||||||
|
} else {
|
||||||
|
setEntityWithEnabledSave(new Assessment());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<Component> getFormComponents() {
|
protected List<Component> getFormComponents() {
|
||||||
return List.of(appUserName);
|
return List.of(appUser, questions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,9 @@ public class AssessmentsListView extends Main {
|
|||||||
|
|
||||||
public AssessmentsListView(final AssessmentService assessmentService) {
|
public AssessmentsListView(final AssessmentService assessmentService) {
|
||||||
final VGrid<Assessment> grid = new VGrid<>(Assessment.class);
|
final VGrid<Assessment> grid = new VGrid<>(Assessment.class);
|
||||||
grid.setDataProvider(new DataProvider<Assessment, Object>() {
|
grid.setColumns("id", "appUser.email");
|
||||||
|
|
||||||
|
grid.setDataProvider(new DataProvider<>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean isInMemory() {
|
public boolean isInMemory() {
|
||||||
return false;
|
return false;
|
||||||
@ -31,12 +33,16 @@ public class AssessmentsListView extends Main {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size(Query<Assessment, Object> query) {
|
public int size(Query<Assessment, Object> query) {
|
||||||
return 0;
|
return assessmentService.getAssessments().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Stream<Assessment> fetch(Query<Assessment, Object> query) {
|
public Stream<Assessment> fetch(Query<Assessment, Object> query) {
|
||||||
return null;
|
int limit = query.getLimit();
|
||||||
|
int pagerSize = query.getPageSize();
|
||||||
|
int page = query.getPage();
|
||||||
|
|
||||||
|
return assessmentService.getAssessments().stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,29 +23,30 @@ import java.util.UUID;
|
|||||||
public class UserView extends BeanValidationForm<AppUser> implements HasUrlParameter<String> {
|
public class UserView extends BeanValidationForm<AppUser> implements HasUrlParameter<String> {
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
private final TextField appUserName = new TextField();
|
private TextField email = null;
|
||||||
|
|
||||||
public UserView(UserService userService) {
|
public UserView(final UserService userService) {
|
||||||
super(AppUser.class);
|
super(AppUser.class);
|
||||||
setEntityWithEnabledSave(new AppUser("foo@bar.com", List.of()));
|
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
|
email = new TextField();
|
||||||
|
email.setLabel("Email");
|
||||||
|
|
||||||
setSavedHandler((SavedHandler<AppUser>) appUser -> {
|
setSavedHandler((SavedHandler<AppUser>) userService::createOrUpdate);
|
||||||
System.out.println(appUser);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setParameter(final BeforeEvent beforeEvent, final String s) {
|
public void setParameter(final BeforeEvent beforeEvent, final String s) {
|
||||||
if (StringUtils.isNotBlank(s) && !"new".equals(s)) {
|
if (StringUtils.isNotBlank(s) && !"new".equals(s)) {
|
||||||
var assessment = userService.getUser(UUID.fromString(s));
|
var user = userService.getUser(UUID.fromString(s));
|
||||||
|
setEntityWithEnabledSave(user);
|
||||||
|
} else {
|
||||||
|
setEntityWithEnabledSave(new AppUser());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<Component> getFormComponents() {
|
protected List<Component> getFormComponents() {
|
||||||
return List.of(appUserName);
|
return List.of(email);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.primefactorsolutions.views;
|
package com.primefactorsolutions.views;
|
||||||
|
|
||||||
import com.primefactorsolutions.model.AppUser;
|
import com.primefactorsolutions.model.AppUser;
|
||||||
|
import com.primefactorsolutions.service.UserService;
|
||||||
import com.vaadin.flow.component.html.Main;
|
import com.vaadin.flow.component.html.Main;
|
||||||
import com.vaadin.flow.data.provider.DataProvider;
|
import com.vaadin.flow.data.provider.DataProvider;
|
||||||
import com.vaadin.flow.data.provider.DataProviderListener;
|
import com.vaadin.flow.data.provider.DataProviderListener;
|
||||||
@ -20,11 +21,14 @@ import java.util.stream.Stream;
|
|||||||
@PageTitle("Users")
|
@PageTitle("Users")
|
||||||
@Route(value = "/users", layout = MainLayout.class)
|
@Route(value = "/users", layout = MainLayout.class)
|
||||||
public class UsersListView extends Main {
|
public class UsersListView extends Main {
|
||||||
|
final UserService userService;
|
||||||
|
|
||||||
public UsersListView() {
|
public UsersListView(final UserService userService) {
|
||||||
|
this.userService = userService;
|
||||||
final VGrid<AppUser> grid = new VGrid<>(AppUser.class);
|
final VGrid<AppUser> grid = new VGrid<>(AppUser.class);
|
||||||
|
grid.setColumns("id", "email");
|
||||||
|
|
||||||
grid.setDataProvider(new DataProvider<AppUser, Object>() {
|
grid.setDataProvider(new DataProvider<>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean isInMemory() {
|
public boolean isInMemory() {
|
||||||
return false;
|
return false;
|
||||||
@ -32,7 +36,7 @@ public class UsersListView extends Main {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size(Query<AppUser, Object> query) {
|
public int size(Query<AppUser, Object> query) {
|
||||||
return 1;
|
return userService.getUsers().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -40,7 +44,7 @@ public class UsersListView extends Main {
|
|||||||
int limit = query.getLimit();
|
int limit = query.getLimit();
|
||||||
int pagerSize = query.getPageSize();
|
int pagerSize = query.getPageSize();
|
||||||
int page = query.getPage();
|
int page = query.getPage();
|
||||||
return Stream.of(new AppUser("foo@bar.com", List.of()));
|
return userService.getUsers().stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,11 +6,11 @@ spring.mustache.check-template-location = false
|
|||||||
vaadin.launch-browser=true
|
vaadin.launch-browser=true
|
||||||
# To improve the performance during development.
|
# To improve the performance during development.
|
||||||
# For more information https://vaadin.com/docs/latest/integrations/spring/configuration#special-configuration-parameters
|
# For more information https://vaadin.com/docs/latest/integrations/spring/configuration#special-configuration-parameters
|
||||||
vaadin.allowed-packages = com.vaadin,org.vaadin,com.primefactorsolutions,com.hilerio.ace,com.flowingcode.vaadin
|
vaadin.allowed-packages = com.vaadin,org.vaadin,com.primefactorsolutions,com.hilerio.ace,com.flowingcode.vaadin,org.vaadin.firitin
|
||||||
|
|
||||||
|
|
||||||
#spring.datasource.url=jdbc:h2:mem:testdb
|
# spring.datasource.url=jdbc:h2:mem:testdb
|
||||||
#spring.datasource.url=jdbc:h2:file:./db
|
# spring.datasource.url=jdbc:h2:file:./db
|
||||||
spring.datasource.url=jdbc:h2:file:/var/opt/pfs/db
|
spring.datasource.url=jdbc:h2:file:/var/opt/pfs/db
|
||||||
spring.jpa.hibernate.ddl-auto=create-drop
|
spring.jpa.hibernate.ddl-auto=create-drop
|
||||||
spring.sql.init.mode=embedded
|
spring.sql.init.mode=embedded
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
insert into app_user (id, version, email) values ('23471ab3-f639-4d2b-9541-7227f4ea7ee6', 1, 'foo@bar.com');
|
insert into app_user (id, version, email) values ('23471ab3-f639-4d2b-9541-7227f4ea7ee6', 1, 'foo@bar.com');
|
||||||
|
|
||||||
insert into question (id, version, content) values ('a7e00ff8-da41-4624-b31c-1b13c3f2e3ae', 1, 'foo bar');
|
insert into question (id, version, content, title, description) values ('a7e00ff8-da41-4624-b31c-1b13c3f2e3ae', 1, 'foo bar', 'q1', 'lorem ipsum');
|
||||||
insert into question (id, version, content) values ('8a4b213c-ca81-4c38-b56d-d7028c2dde88', 1, 'foo buzz');
|
insert into question (id, version, content, title, description) values ('8a4b213c-ca81-4c38-b56d-d7028c2dde88', 1, 'foo buzz', 'q2', 'lorem ipsum');
|
||||||
|
|
||||||
insert into assessment(id, version, app_user_id) values ('46b153f4-23fd-462f-8430-fbe67b83caab', 1, '23471ab3-f639-4d2b-9541-7227f4ea7ee6');
|
insert into assessment(id, version, app_user_id) values ('46b153f4-23fd-462f-8430-fbe67b83caab', 1, '23471ab3-f639-4d2b-9541-7227f4ea7ee6');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user