Skip to content

Commit

Permalink
Revision-Diffs nebeneinander + Metadaten
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernd Ritter committed May 24, 2024
1 parent 39e14ff commit debcbbc
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 14 deletions.
10 changes: 10 additions & 0 deletions src/main/java/de/holarse/backend/view/ArticleView.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ArticleView {
private String content;
private LocalDateTime created;
private LocalDateTime updated;
private String changelog;

// Calculated Values
private transient String url;
Expand Down Expand Up @@ -56,6 +57,7 @@ public static ArticleView of(final ArticleRevision ar, final NodeSlug slug) {
av.setCreated(ar.getCreated().toLocalDateTime());
av.setUpdated(ar.getUpdated().toLocalDateTime());
av.setRevision(ar.getRevision());
av.setChangelog(ar.getChangelog());

if (StringUtils.isNotBlank(ar.getTitle2())) { av.getAlternativeTitles().add(ar.getTitle2()); }
if (StringUtils.isNotBlank(ar.getTitle3())) { av.getAlternativeTitles().add(ar.getTitle3()); }
Expand Down Expand Up @@ -213,6 +215,14 @@ public void setUrl(String url) {
this.url = url;
}

public String getChangelog() {
return changelog;
}

public void setChangelog(String changelog) {
this.changelog = changelog;
}

public List<ScreenshotView> getScreenshots() {
return screenshotViews;
}
Expand Down
33 changes: 25 additions & 8 deletions src/main/java/de/holarse/web/controller/RevisionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,35 @@ public ModelAndView diff(@PathVariable final Integer nodeId, @PathVariable final
final ArticleView view2 = articleService.buildArticleView(article, articleRevision2);

final DiffRowGenerator diffGenerator = DiffRowGenerator.create().showInlineDiffs(true).mergeOriginalRevised(true).inlineDiffByWord(true).oldTag(f -> "~").newTag(f -> "**").build();
final List<DiffRow> diffRows = diffGenerator.generateDiffRows(Arrays.asList(view1.getContent().split("\n")), Arrays.asList(view2.getContent().split("\n")));

final StringBuilder buffer = new StringBuilder(4096);
for (final DiffRow diffRow : diffRows) {
buffer.append(diffRow.getOldLine()).append("\n");
buffer.append(diffRow.getNewLine()).append("\n");
}

final StringBuilder contentLeft = new StringBuilder();
contentLeft.append(view1.getTitle1()).append("\n");
contentLeft.append(view1.getTitle2()).append("\n");
contentLeft.append(view1.getTitle3()).append("\n");
contentLeft.append(view1.getTitle4()).append("\n");
contentLeft.append(view1.getTitle5()).append("\n");
contentLeft.append(view1.getTitle6()).append("\n");
contentLeft.append(view1.getTitle7()).append("\n");
contentLeft.append(view1.getContent());

final StringBuilder contentRight = new StringBuilder();
contentRight.append(view1.getTitle1()).append("\n");
contentRight.append(view1.getTitle2()).append("\n");
contentRight.append(view1.getTitle3()).append("\n");
contentRight.append(view1.getTitle4()).append("\n");
contentRight.append(view1.getTitle5()).append("\n");
contentRight.append(view1.getTitle6()).append("\n");
contentRight.append(view1.getTitle7()).append("\n");
contentRight.append(view1.getContent());

final List<DiffRow> diffRows = diffGenerator.generateDiffRows(
Arrays.asList(contentLeft.toString().split("\n")),
Arrays.asList(contentRight.toString().split("\n")));

mv.addObject("nodeid", article.getNodeId());
mv.addObject("view1", view1);
mv.addObject("view2", view2);
mv.addObject("diff", buffer.toString());
mv.addObject("diffRows", diffRows);

return mv;
}
Expand Down
34 changes: 30 additions & 4 deletions src/main/webapp/WEB-INF/templates/sites/revisions/diff.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
<section class="g-pt-50 g-pb-90">
<div class="container">
Diff zwischen Revision <div data-th-text="${view1.revision}"></div> und <div data-th-text="${view2.revision}"></div>
<div class="row">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Revisionen</th>
<th><div data-th-text="${view1.revision}">Revision 1</div></th>
<th><div data-th-text="${view2.revision}">Revision 2</div></th>
</tr>
<tr>
<th>Aktualisierung</th>
<th><span data-th-text="${view1.updated}"></span></th>
<th><span data-th-text="${view2.updated}"></span></th>
</tr>
<tr>
<th>Changelog:</th>
<th data-th-text="${view1.changelog}"></th>
<th data-th-text="${view2.changelog}"></th>
</tr>
</thead>
<tbody>
<tr data-th-each="diffRow : ${diffRows}">
<td data-th-text="${diffRow.getTag()}"></td>
<td data-th-text="${diffRow.getOldLine()}"></td>
<td data-th-text="${diffRow.getNewLine()}"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>

<div data-th-text="${diff}"></div>

</section>
3 changes: 1 addition & 2 deletions src/main/webapp/WEB-INF/templates/sites/revisions/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ <h3 class="h4 g-mb-15">
</tr>
</tbody>
</table>

</div>
</div>
</div>
</section>

0 comments on commit debcbbc

Please sign in to comment.