Skip to content

Commit

Permalink
introduce an 'edit' field
Browse files Browse the repository at this point in the history
  • Loading branch information
ivy-rew committed Oct 24, 2023
1 parent b70d594 commit 608c601
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import ch.ivyteam.ivy.process.model.Process;
import ch.ivyteam.ivy.process.model.element.activity.Script;
import ch.ivyteam.ivy.process.model.element.event.start.dialog.html.HtmlDialogMethodStart;
import ch.ivyteam.ivy.scripting.dataclass.IDataClass;
import ch.ivyteam.ivy.scripting.dataclass.IDataClassField;
import ch.ivyteam.ivy.scripting.dataclass.IEntityClass;

@IvyTest
Expand All @@ -48,20 +50,9 @@ void createEntityDialog(@TempDir Path dir) throws IOException, CoreException {
String unit = "testing";
dialog = new DialogCreator().createDialog(customer, unit);

Process process = dialog.getProcess(null).getModel();
Script loader = process.search().type(Script.class).findOne();
assertThat(loader.getCode()).contains(customer.getName());
var delete = process.search().type(HtmlDialogMethodStart.class).findOne();
String removal = delete.getOutput().getCode();
assertThat(removal)
.contains("testing.remove(");

var view = read(dialog.getViewFile());
assertThat(view).contains("p:dataTable");
assertThat(view)
.as("visualizes properties of the entity")
.contains("firstname")
.doesNotContain("<!-- [entity.fields] -->");
assertData(dialog.getDataClass(null));
assertProcess(customer, dialog.getProcess(null).getModel());
assertView(read(dialog.getViewFile()));

} finally {
customer.getResource().delete(true, new NullProgressMonitor());
Expand All @@ -71,6 +62,28 @@ void createEntityDialog(@TempDir Path dir) throws IOException, CoreException {
}
}

private void assertData(IDataClass dataClass) {
assertThat(dataClass.getFields()).extracting(IDataClassField::getName)
.containsOnly("entries", "edit");
}

private void assertProcess(IEntityClass customer, Process process) {
Script loader = process.search().type(Script.class).findOne();
assertThat(loader.getCode()).contains(customer.getName());
var delete = process.search().type(HtmlDialogMethodStart.class).findOne();
String removal = delete.getOutput().getCode();
assertThat(removal)
.contains("testing.remove(");
}

private void assertView(String view) {
assertThat(view).contains("p:dataTable");
assertThat(view)
.as("visualizes properties of the entity")
.contains("firstname")
.doesNotContain("<!-- [entity.fields] -->");
}

private static String read(IFile viewFile) throws IOException, CoreException {
try(InputStream in = viewFile.getContents()) {
var bos = new java.io.ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ public IUserDialog createDialog(IEntityClass entity, String unit) {
var target = dialogStartFor(entity);

VariableDesc entries = new VariableDesc("entries", new QualifiedType(List.class.getName(), List.of(new QualifiedType(entity.getName()))));
VariableDesc edit = new VariableDesc("edit", new QualifiedType(entity.getName()));

prepareTemplate(project, "frame-10");
String dialogId = target.getId().getRawId();
var params = new DialogCreationParameters.Builder(project, dialogId)
.viewTechId(IvyConstants.VIEW_TECHONOLOGY_JSF)
.signature(target.getStartMethod())
.dataClassFields(List.of(entries))
.dataClassFields(List.of(entries, edit))
.toCreationParams();
var userDialog = local.createProjectUserDialog(params, null);

Expand Down Expand Up @@ -90,12 +91,12 @@ private void extendView(IFile viewFile, IEntityClass entity) {
private String renderFields(IEntityClass entity, String template) {
String fieldXhtml = entity.getFields().stream()
.filter(fld -> !fld.getName().equals("id"))
.map(this::htmlview)
.map(this::renderColumn)
.collect(Collectors.joining("\n"));
return template.replace("<!-- [entity.fields] -->", fieldXhtml);
}

private String htmlview(IEntityClassField field) {
private String renderColumn(IEntityClassField field) {
String fieldXhtml = """
<p:column headerText="%s">
<h:outputText value="#{entity.%s}"/>
Expand Down

0 comments on commit 608c601

Please sign in to comment.