Skip to content

Commit

Permalink
fixed revisions and diffing
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed May 12, 2017
1 parent ec5f0d8 commit df2104e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ public String get(@PathVariable String postid, HttpServletRequest req, Model mod
}
Pager itemcount = utils.getPager("page", req);
List<Revision> revisionslist = showPost.getRevisions(itemcount);
// we need the first revision on the next page for diffing
List<Revision> nextPage = showPost.getRevisions(new Pager(itemcount.getPage() + 1, itemcount.getLimit()));
utils.fetchProfiles(revisionslist);
model.addAttribute("path", "revisions.vm");
model.addAttribute("title", utils.getLang(req).get("revisions.title"));
model.addAttribute("showPost", showPost);
model.addAttribute("itemcount", itemcount);
model.addAttribute("revisionslist", revisionslist);
model.addAttribute("lastOnPage", nextPage.isEmpty() ? null : nextPage.get(0));
return "base";
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/erudika/scoold/core/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ public void restoreRevisionAndUpdate(String revisionid) {
setBody(rev.getBody());
setTags(rev.getTags());
setRevisionid(rev.getId());
//update post
update();
//update post without creating a new revision
client().update(this);
}
}

Expand Down
36 changes: 22 additions & 14 deletions src/main/resources/static/scripts/scoold.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ $(function () {
} else {
contentDiv.append(trimmed).find(".dropdown-button").dropdown();
}
$(document).trigger("event:page");
}
}
});
Expand Down Expand Up @@ -722,21 +723,28 @@ $(function () {
}
}

$(".newrev").html(function(index, html) {
var newText = html;
var dis = $(this);
var oldText = dis.next(".oldrev").html();
var ds = newText;

if (newText && oldText) {
// var dd = diff_linesToHtml(oldText, newText);
// var d = dmp.diff_main(dd[0], dd[1], false);
function diffInit(elem) {
$(elem).html(function(index, html) {
var dis = $(this);
var undiffed = dis.data("undiffedHTML");
var newText = undiffed || html;
var oldText = dis.next(".oldrev").html();
var ds = newText;
if (!undiffed) {
dis.data("undiffedHTML", html);
}
if (newText && oldText) {
var d = dmp.diff_main(oldText, newText);
dmp.diff_cleanupSemantic(d);
ds = diffToHtml(d, oldText, newText);
}
return ds;
});
}

var d = dmp.diff_main(oldText, newText);
dmp.diff_cleanupSemantic(d);
ds = diffToHtml(d, oldText, newText);
}
diffInit(".newrev");

return ds;
$(document).on("event:page", function() {
diffInit(".newrev");
});
});
9 changes: 7 additions & 2 deletions src/main/resources/templates/macro.vm
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
<div class="card">
<div class="row valign-wrapper">
<div class="col s4">
<img src="#profilepic($showFriend)" alt="$showFriend.name" class="responsive-img pts pls">
<img src="#profilepic($showFriend)" alt="$showFriend.name" class="responsive-img pts pls" width="100%">
</div>
<div class="col s8">
<div class="right mrm">
Expand All @@ -193,6 +193,12 @@
#if($showFriend.badges && $showFriend.badgesMap)
$showFriend.badgesMap.size() <i class="fa fa-star yellow-text text-darken-3"></i>
#end
#if ($showFriend.groups == "admins")
<i class="fa fa-asterisk orange-text mhs tooltipped" data-delay="0" data-tooltip="$!lang.get('admin')"></i>
#end
#if ($showFriend.groups == "mods")
<i class="fa fa-dot-circle-o orange-text mhs tooltipped" data-delay="0" data-tooltip="$!lang.get('mod')"></i>
#end
<div class="grey-text r prl tooltipped" data-position="top" data-tooltip="$!{lang.get('profile.about.lastseen')}">
<i class="fa fa-clock-o"></i> #formatdate($!{showFriend.lastseen} "")
</div>
Expand Down Expand Up @@ -329,7 +335,6 @@
#macro(answerspage $answers $parentpost)
#foreach($answer in $answers)
#postbox($answer $parentpost)
<hr>
#end
#end
####################################
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/profile.vm
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<div class="mvm center-align">
#getreportlink($showUser "$profilelink/$!showUser.creatorid" "chip")
#if ($isAdmin)
#if ($isMod)#set($hidemakemod = "hide")#else#set($unhidemakemod = "hide")#end
#if ($showUser.groups == "mods")#set($hidemakemod = "hide")#else#set($unhidemakemod = "hide")#end
<a href="$profilelink/$showUser.creatorid/?makemod=false" class="chip make-mod-btn $!{unhidemakemod}">
<i class="fa fa-chevron-down"></i> Unmake mod
</a>
Expand Down
23 changes: 9 additions & 14 deletions src/main/resources/templates/revisions.vm
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
#if ($showpost.revisionid == $showrev.id)
<i class="fa fa-check-circle green-text fa-3x tooltipped" data-tooltip="$!lang.get('revisions.current')"></i>
#elseif ($canrestore || $isMod)
<a href="$!actionlink/$showrev.parentid/restore/$!showrev.id" class="post-refresh-ask btn waves-effect waves-light" title="Restore">
<i class="fa fa-undo"></i> $!lang.get("restore")
</a>
<form method="post" action="$!actionlink/$showrev.parentid/restore/$!showrev.id">
#sectoken(false)
<button type="submit" class="btn waves-effect waves-light" title="Restore">
<i class="fa fa-undo"></i> $!lang.get("restore")
</button>
</form>
#end
</div>
</div>
Expand All @@ -42,13 +45,9 @@
<hr>
#end
#if ($showrev.body)
#set($revHtml = $utils.markdownToHtml($showrev.body))
#set($showRevBody = $utils.stripHtml($revHtml) )
<div class="newrev mtl">$!showRevBody</div>
<div class="newrev mtl">$!showrev.body</div>
#if ($showorigrev.body)
#set($origHtml = $utils.markdownToHtml($showorigrev.body))
#set($showOrigBody = $utils.stripHtml($origHtml) )
<span class="hide oldrev">$!showOrigBody</span>
<span class="hide oldrev">$!showorigrev.body</span>
#end
#end
#if ($showrev.tags)
Expand All @@ -72,15 +71,11 @@
#if ($revisions.size() == 1)
#revisionbox($lastrev $lastrev $canrestore $showpost)
#else
#if ($revisions.size() > $MAX_ITEMS_PER_PAGE)
#set($lastrev = $revisions.remove($lastIndex))
#end

#foreach($revision in $revisions)
#if ($velocityCount < $revisions.size())
#set($prevrev = $revisions.get($velocityCount))
#else
#set($prevrev = $lastrev)
#set($prevrev = $lastOnPage)
#end
#revisionbox($revision $prevrev $canrestore $showpost)
#end
Expand Down

0 comments on commit df2104e

Please sign in to comment.