Remove calls to Page#last_version, replace with AJAX-lookup of version info.

This commit is contained in:
Dawa Ometto
2016-08-07 20:09:01 +02:00
parent 6316f97c06
commit 435a3e62ba
5 changed files with 27 additions and 24 deletions
+9 -2
View File
@@ -5,6 +5,7 @@ require 'gollum-lib'
require 'mustache/sinatra' require 'mustache/sinatra'
require 'useragent' require 'useragent'
require 'stringex' require 'stringex'
require 'json'
require 'gollum' require 'gollum'
require 'gollum/views/layout' require 'gollum/views/layout'
@@ -131,6 +132,14 @@ module Precious
Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
end end
get '/last-commit-info' do
content_type :json
if page = wiki_page(params[:path]).page
version = page.last_version
{:author => version.author.name, :date => version.authored_date}.to_json
end
end
get '/emoji/:name' do get '/emoji/:name' do
begin begin
[200, {'Content-Type' => 'image/png'}, emoji(params['name'])] [200, {'Content-Type' => 'image/png'}, emoji(params['name'])]
@@ -496,7 +505,6 @@ module Precious
name = extract_name(fullpath) || wiki.index_page name = extract_name(fullpath) || wiki.index_page
path = extract_path(fullpath) || '/' path = extract_path(fullpath) || '/'
if page = wiki.paged(name, path, exact = true) if page = wiki.paged(name, path, exact = true)
@page = page @page = page
@name = name @name = name
@@ -505,7 +513,6 @@ module Precious
# Extensions and layout data # Extensions and layout data
@editable = true @editable = true
@page_exists = !page.last_version.nil?
@toc_content = wiki.universal_toc ? @page.toc_data : nil @toc_content = wiki.universal_toc ? @page.toc_data : nil
@mathjax = wiki.mathjax @mathjax = wiki.mathjax
@h1_title = wiki.h1_title @h1_title = wiki.h1_title
@@ -306,6 +306,19 @@ $(document).ready(function() {
$.GollumEditor(); $.GollumEditor();
} }
if( $("#last-edit").length ) {
$("#page-info-toggle").click ( function () {
$.ajax({
url: '/last-commit-info',
data: {path: $("#page-info-toggle").data('pagepath')},
success: function ( data ) {
$("#last-edit").html('Last edited by <b>' + data.author + '</b>, ' + data.date);
}
});
$("#last-edit").html('<i class="fa fa-spinner fa-spin"></i> Getting commit info...');
})
}
if( $('#wiki-wrapper.create').length ){ if( $('#wiki-wrapper.create').length ){
$("#gollum-editor-submit").click( function() { window.onbeforeunload = null; } ); $("#gollum-editor-submit").click( function() { window.onbeforeunload = null; } );
$("#gollum-editor-body").one('change', function(){ $("#gollum-editor-body").one('change', function(){
+2 -4
View File
@@ -40,12 +40,10 @@ Mousetrap.bind(['e'], function( e ) {
class="action-edit-page">Edit</a></li> class="action-edit-page">Edit</a></li>
{{/editable}} {{/editable}}
{{/allow_editing}} {{/allow_editing}}
{{#page_exists}}
<li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}" <li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}"
class="action-page-history">History</a></li> class="action-page-history">History</a></li>
<li class="minibutton"><a href="{{base_url}}/latest_changes" <li class="minibutton"><a href="{{base_url}}/latest_changes"
class="action-page-history">Latest Changes</a></li> class="action-page-history">Latest Changes</a></li>
{{/page_exists}}
</ul> </ul>
</div> </div>
<div id="wiki-content"> <div id="wiki-content">
@@ -85,10 +83,10 @@ Mousetrap.bind(['e'], function( e ) {
</div> </div>
<div id="footer"> <div id="footer">
<p id="last-edit">Last edited by <b>{{author}}</b>, {{date}}</p> <p id="last-edit"><a id="page-info-toggle" data-pagepath="{{escaped_url_path}}">When was this page last modified?</a></p>
{{#allow_editing}} {{#allow_editing}}
<p> <p>
<a id="delete-link" href="{{base_url}}/{{escaped_url_path}}" data-confirm="Are you sure you want to delete this page?"><span>Delete this Page</span></a> <a id="delete-link" href="{{escaped_url_path}}" data-confirm="Are you sure you want to delete this page?"><span>Delete this Page</span></a>
</p> </p>
{{/allow_editing}} {{/allow_editing}}
</div> </div>
-4
View File
@@ -41,10 +41,6 @@ module Precious
@editable @editable
end end
def page_exists
@page_exists
end
def allow_editing def allow_editing
@allow_editing @allow_editing
end end
+3 -14
View File
@@ -90,25 +90,14 @@ context "Frontend" do
divs.each {|div| assert_match div, last_response.body} divs.each {|div| assert_match div, last_response.body}
end end
test "retain edit information" do test "provide last edit information" do
page1 = 'page1' page1 = 'page1'
user1 = 'user1' user1 = 'user1'
@wiki.write_page(page1, :markdown, '', @wiki.write_page(page1, :markdown, '',
{ :name => user1, :email => user1 }); { :name => user1, :email => user1 });
get page1 get "/last-commit-info", :path => page1
assert_match /Last edited by <b>user1/, last_response.body assert_match /\"author\":\"user1\"/, last_response.body
page2 = 'page2'
user2 = 'user2'
@wiki.write_page(page2, :markdown, '',
{ :name => user2, :email => user2 });
get page2
assert_match /Last edited by <b>user2/, last_response.body
get page1
assert_match /Last edited by <b>user1/, last_response.body
end end
test "edits page" do test "edits page" do