added edit links
This commit is contained in:
parent
4fbb6e8914
commit
ed9cc26831
@ -1,8 +1,6 @@
|
|||||||
package com.primefactorsolutions.model;
|
package com.primefactorsolutions.model;
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.*;
|
||||||
import jakarta.persistence.FetchType;
|
|
||||||
import jakarta.persistence.OneToMany;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
@ -16,6 +14,7 @@ import java.util.List;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class AppUser extends BaseEntity {
|
public class AppUser extends BaseEntity {
|
||||||
|
@Column(unique = true)
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@OneToMany(fetch = FetchType.EAGER, mappedBy = "appUser")
|
@OneToMany(fetch = FetchType.EAGER, mappedBy = "appUser")
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.primefactorsolutions.model;
|
package com.primefactorsolutions.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Lob;
|
import jakarta.persistence.Lob;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@ -13,6 +14,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class Question extends BaseEntity{
|
public class Question extends BaseEntity{
|
||||||
|
@Column(unique = true)
|
||||||
private String title;
|
private String title;
|
||||||
@Lob
|
@Lob
|
||||||
private String description;
|
private String description;
|
||||||
|
@ -21,7 +21,7 @@ public class QuestionService {
|
|||||||
return questionRepository.findAll();
|
return questionRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createOrUpdate(Question question) {
|
public Question createOrUpdate(Question question) {
|
||||||
questionRepository.save(question);
|
return questionRepository.save(question);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,13 +50,16 @@ public class AssessmentView extends BeanValidationForm<Assessment> implements Ha
|
|||||||
questions.setReadOnly(false);
|
questions.setReadOnly(false);
|
||||||
questions.setAvailableOptions(questionService.getQuestions());
|
questions.setAvailableOptions(questionService.getQuestions());
|
||||||
|
|
||||||
setSavedHandler((SavedHandler<Assessment>) this.assessmentService::saveAssessment);
|
setSavedHandler((SavedHandler<Assessment>) assessment -> {
|
||||||
|
final var saved = this.assessmentService.saveAssessment(assessment);
|
||||||
|
setEntityWithEnabledSave(saved);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@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));
|
final var assessment = assessmentService.getAssessment(UUID.fromString(s));
|
||||||
|
|
||||||
setEntityWithEnabledSave(assessment);
|
setEntityWithEnabledSave(assessment);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2,12 +2,15 @@ package com.primefactorsolutions.views;
|
|||||||
|
|
||||||
import com.primefactorsolutions.model.Assessment;
|
import com.primefactorsolutions.model.Assessment;
|
||||||
import com.primefactorsolutions.service.AssessmentService;
|
import com.primefactorsolutions.service.AssessmentService;
|
||||||
|
import com.vaadin.flow.component.ClickEvent;
|
||||||
import com.vaadin.flow.component.Component;
|
import com.vaadin.flow.component.Component;
|
||||||
import com.vaadin.flow.component.ComponentEventListener;
|
import com.vaadin.flow.component.ComponentEventListener;
|
||||||
import com.vaadin.flow.component.button.Button;
|
import com.vaadin.flow.component.button.Button;
|
||||||
import com.vaadin.flow.component.confirmdialog.ConfirmDialog;
|
import com.vaadin.flow.component.confirmdialog.ConfirmDialog;
|
||||||
|
import com.vaadin.flow.component.grid.Grid;
|
||||||
import com.vaadin.flow.component.html.Main;
|
import com.vaadin.flow.component.html.Main;
|
||||||
import com.vaadin.flow.component.notification.Notification;
|
import com.vaadin.flow.component.notification.Notification;
|
||||||
|
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||||
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;
|
||||||
import com.vaadin.flow.data.provider.Query;
|
import com.vaadin.flow.data.provider.Query;
|
||||||
@ -31,8 +34,21 @@ import java.util.stream.Stream;
|
|||||||
public class AssessmentsListView extends Main {
|
public class AssessmentsListView extends Main {
|
||||||
|
|
||||||
public AssessmentsListView(final AssessmentService assessmentService) {
|
public AssessmentsListView(final AssessmentService assessmentService) {
|
||||||
|
final HorizontalLayout hl = new HorizontalLayout();
|
||||||
|
final Button addAssessment = new Button("Add Assessment");
|
||||||
|
addAssessment.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||||
|
this.getUI().get().navigate(AssessmentView.class, "new");
|
||||||
|
});
|
||||||
|
hl.add(addAssessment);
|
||||||
|
|
||||||
final VGrid<Assessment> grid = new VGrid<>(Assessment.class);
|
final VGrid<Assessment> grid = new VGrid<>(Assessment.class);
|
||||||
grid.setColumns("id", "appUser.email");
|
grid.setColumns("id", "appUser.email");
|
||||||
|
final Grid.Column<Assessment> statusColumn = grid.addColumn((ValueProvider<Assessment, Object>) assessment ->
|
||||||
|
assessment.getAssessmentEvents().isEmpty()
|
||||||
|
? "N/A"
|
||||||
|
: assessment.getAssessmentEvents().getLast().getStatus().name());
|
||||||
|
statusColumn.setHeader("Status");
|
||||||
|
|
||||||
grid.addComponentColumn((ValueProvider<Assessment, Component>) assessment -> new Button("Copy Link", event ->
|
grid.addComponentColumn((ValueProvider<Assessment, Component>) assessment -> new Button("Copy Link", event ->
|
||||||
ClientsideClipboard.writeToClipboard(
|
ClientsideClipboard.writeToClipboard(
|
||||||
String.format("email: %s link: https://careers.primefactorsolutions.com/evaluation/%s",
|
String.format("email: %s link: https://careers.primefactorsolutions.com/evaluation/%s",
|
||||||
@ -91,8 +107,9 @@ public class AssessmentsListView extends Main {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
grid.setAllRowsVisible(true);
|
||||||
|
|
||||||
add(grid);
|
add(hl, grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -434,6 +434,10 @@ public class EvaluationView extends Main implements HasUrlParameter<String> {
|
|||||||
public void setParameter(BeforeEvent beforeEvent, String s) {
|
public void setParameter(BeforeEvent beforeEvent, String s) {
|
||||||
this.assessment = this.assessmentService.getAssessment(UUID.fromString(s));
|
this.assessment = this.assessmentService.getAssessment(UUID.fromString(s));
|
||||||
|
|
||||||
|
if (this.assessment == null) {
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
if (this.assessment.isCompleted()) {
|
if (this.assessment.isCompleted()) {
|
||||||
goToCompleted();
|
goToCompleted();
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,7 @@ import com.vaadin.flow.component.Component;
|
|||||||
import com.vaadin.flow.component.textfield.IntegerField;
|
import com.vaadin.flow.component.textfield.IntegerField;
|
||||||
import com.vaadin.flow.component.textfield.TextArea;
|
import com.vaadin.flow.component.textfield.TextArea;
|
||||||
import com.vaadin.flow.component.textfield.TextField;
|
import com.vaadin.flow.component.textfield.TextField;
|
||||||
import com.vaadin.flow.router.BeforeEvent;
|
import com.vaadin.flow.router.*;
|
||||||
import com.vaadin.flow.router.HasUrlParameter;
|
|
||||||
import com.vaadin.flow.router.PageTitle;
|
|
||||||
import com.vaadin.flow.router.Route;
|
|
||||||
import com.vaadin.flow.spring.annotation.SpringComponent;
|
import com.vaadin.flow.spring.annotation.SpringComponent;
|
||||||
import jakarta.annotation.security.PermitAll;
|
import jakarta.annotation.security.PermitAll;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -36,28 +33,35 @@ public class QuestionView extends BeanValidationForm<Question> implements HasUrl
|
|||||||
super(Question.class);
|
super(Question.class);
|
||||||
this.questionService = questionService;
|
this.questionService = questionService;
|
||||||
title = new TextField();
|
title = new TextField();
|
||||||
|
title.setWidthFull();
|
||||||
title.setLabel("Title");
|
title.setLabel("Title");
|
||||||
|
|
||||||
description = new TextArea();
|
description = new TextArea();
|
||||||
|
description.setWidthFull();
|
||||||
description.setLabel("Description");
|
description.setLabel("Description");
|
||||||
|
|
||||||
content = new TextArea();
|
|
||||||
content.setLabel("Content");
|
|
||||||
|
|
||||||
timeMinutes = new IntegerField();
|
timeMinutes = new IntegerField();
|
||||||
timeMinutes.setLabel("TimeMinutes");
|
timeMinutes.setLabel("TimeMinutes");
|
||||||
|
|
||||||
setSavedHandler((SavedHandler<Question>) questionService::createOrUpdate);
|
content = new TextArea();
|
||||||
}
|
content.setWidthFull();
|
||||||
|
content.setLabel("Content");
|
||||||
|
|
||||||
|
setSavedHandler((SavedHandler<Question>) question -> {
|
||||||
|
final Question saved = questionService.createOrUpdate(question);
|
||||||
|
setEntityWithEnabledSave(saved);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@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 user = questionService.getQuestion(UUID.fromString(s));
|
var user = questionService.getQuestion(UUID.fromString(s));
|
||||||
setEntityWithEnabledSave(user);
|
setEntityWithEnabledSave(user);
|
||||||
} else {
|
} else if ("new".equals(s)) {
|
||||||
setEntityWithEnabledSave(new Question());
|
setEntityWithEnabledSave(new Question());
|
||||||
|
} else {
|
||||||
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
package com.primefactorsolutions.views;
|
package com.primefactorsolutions.views;
|
||||||
|
|
||||||
import com.primefactorsolutions.model.AppUser;
|
|
||||||
import com.primefactorsolutions.model.Question;
|
import com.primefactorsolutions.model.Question;
|
||||||
import com.primefactorsolutions.service.QuestionService;
|
import com.primefactorsolutions.service.QuestionService;
|
||||||
import com.primefactorsolutions.service.UserService;
|
import com.vaadin.flow.component.ClickEvent;
|
||||||
|
import com.vaadin.flow.component.Component;
|
||||||
|
import com.vaadin.flow.component.ComponentEventListener;
|
||||||
|
import com.vaadin.flow.component.button.Button;
|
||||||
import com.vaadin.flow.component.html.Main;
|
import com.vaadin.flow.component.html.Main;
|
||||||
|
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||||
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;
|
||||||
import com.vaadin.flow.data.provider.Query;
|
import com.vaadin.flow.data.provider.Query;
|
||||||
|
import com.vaadin.flow.function.ValueProvider;
|
||||||
import com.vaadin.flow.router.PageTitle;
|
import com.vaadin.flow.router.PageTitle;
|
||||||
import com.vaadin.flow.router.Route;
|
import com.vaadin.flow.router.Route;
|
||||||
import com.vaadin.flow.shared.Registration;
|
import com.vaadin.flow.shared.Registration;
|
||||||
@ -28,9 +32,22 @@ public class QuestionsListView extends Main {
|
|||||||
|
|
||||||
public QuestionsListView(final QuestionService questionService) {
|
public QuestionsListView(final QuestionService questionService) {
|
||||||
this.questionService = questionService;
|
this.questionService = questionService;
|
||||||
|
|
||||||
|
final HorizontalLayout hl = new HorizontalLayout();
|
||||||
|
final Button addQuestion = new Button("Add Question");
|
||||||
|
addQuestion.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||||
|
this.getUI().get().navigate(QuestionView.class, "new");
|
||||||
|
});
|
||||||
|
hl.add(addQuestion);
|
||||||
|
|
||||||
final VGrid<Question> grid = new VGrid<>(Question.class);
|
final VGrid<Question> grid = new VGrid<>(Question.class);
|
||||||
grid.setColumns("id", "title");
|
grid.setColumns("id", "title");
|
||||||
|
grid.addComponentColumn((ValueProvider<Question, Component>) question -> {
|
||||||
|
final Button edit = new Button("Edit");
|
||||||
|
edit.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent ->
|
||||||
|
this.getUI().get().navigate(QuestionView.class, question.getId().toString()));
|
||||||
|
return edit;
|
||||||
|
});
|
||||||
grid.setDataProvider(new DataProvider<>() {
|
grid.setDataProvider(new DataProvider<>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean isInMemory() {
|
public boolean isInMemory() {
|
||||||
@ -65,7 +82,8 @@ public class QuestionsListView extends Main {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
grid.setAllRowsVisible(true);
|
||||||
|
|
||||||
add(grid);
|
add(hl, grid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package com.primefactorsolutions.views;
|
|||||||
import com.primefactorsolutions.model.AppUser;
|
import com.primefactorsolutions.model.AppUser;
|
||||||
import com.primefactorsolutions.service.UserService;
|
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.textfield.EmailField;
|
||||||
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;
|
||||||
@ -25,18 +25,21 @@ 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 TextField email = null;
|
private EmailField email = null;
|
||||||
|
|
||||||
public UserView(final UserService userService) {
|
public UserView(final UserService userService) {
|
||||||
super(AppUser.class);
|
super(AppUser.class);
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
email = new TextField();
|
email = new EmailField();
|
||||||
|
email.setWidthFull();
|
||||||
email.setLabel("Email");
|
email.setLabel("Email");
|
||||||
|
|
||||||
setSavedHandler((SavedHandler<AppUser>) userService::createOrUpdate);
|
setSavedHandler((SavedHandler<AppUser>) appUser -> {
|
||||||
|
final AppUser saved = userService.createOrUpdate(appUser);
|
||||||
|
setEntityWithEnabledSave(saved);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@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)) {
|
||||||
|
@ -2,10 +2,16 @@ package com.primefactorsolutions.views;
|
|||||||
|
|
||||||
import com.primefactorsolutions.model.AppUser;
|
import com.primefactorsolutions.model.AppUser;
|
||||||
import com.primefactorsolutions.service.UserService;
|
import com.primefactorsolutions.service.UserService;
|
||||||
|
import com.vaadin.flow.component.ClickEvent;
|
||||||
|
import com.vaadin.flow.component.Component;
|
||||||
|
import com.vaadin.flow.component.ComponentEventListener;
|
||||||
|
import com.vaadin.flow.component.button.Button;
|
||||||
import com.vaadin.flow.component.html.Main;
|
import com.vaadin.flow.component.html.Main;
|
||||||
|
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||||
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;
|
||||||
import com.vaadin.flow.data.provider.Query;
|
import com.vaadin.flow.data.provider.Query;
|
||||||
|
import com.vaadin.flow.function.ValueProvider;
|
||||||
import com.vaadin.flow.router.PageTitle;
|
import com.vaadin.flow.router.PageTitle;
|
||||||
import com.vaadin.flow.router.Route;
|
import com.vaadin.flow.router.Route;
|
||||||
import com.vaadin.flow.shared.Registration;
|
import com.vaadin.flow.shared.Registration;
|
||||||
@ -14,7 +20,6 @@ import jakarta.annotation.security.PermitAll;
|
|||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.vaadin.firitin.components.grid.VGrid;
|
import org.vaadin.firitin.components.grid.VGrid;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@SpringComponent
|
@SpringComponent
|
||||||
@ -27,8 +32,23 @@ public class UsersListView extends Main {
|
|||||||
|
|
||||||
public UsersListView(final UserService userService) {
|
public UsersListView(final UserService userService) {
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
|
|
||||||
|
final HorizontalLayout hl = new HorizontalLayout();
|
||||||
|
final Button addUser = new Button("Add User");
|
||||||
|
addUser.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||||
|
this.getUI().get().navigate(UserView.class, "new");
|
||||||
|
});
|
||||||
|
hl.add(addUser);
|
||||||
|
|
||||||
final VGrid<AppUser> grid = new VGrid<>(AppUser.class);
|
final VGrid<AppUser> grid = new VGrid<>(AppUser.class);
|
||||||
grid.setColumns("id", "email");
|
grid.setColumns("id", "email");
|
||||||
|
grid.setAllRowsVisible(true);
|
||||||
|
grid.addComponentColumn((ValueProvider<AppUser, Component>) appUser -> {
|
||||||
|
final Button edit = new Button("Edit");
|
||||||
|
edit.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent ->
|
||||||
|
this.getUI().get().navigate(UserView.class, appUser.getId().toString()));
|
||||||
|
return edit;
|
||||||
|
});
|
||||||
|
|
||||||
grid.setDataProvider(new DataProvider<>() {
|
grid.setDataProvider(new DataProvider<>() {
|
||||||
@Override
|
@Override
|
||||||
@ -65,6 +85,6 @@ public class UsersListView extends Main {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
add(grid);
|
add(hl, grid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user