From 435a3e62ba7d9cee741cfee6098e45d113b37d1c Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Sun, 7 Aug 2016 20:09:01 +0200 Subject: [PATCH] Remove calls to Page#last_version, replace with AJAX-lookup of version info. --- lib/gollum/app.rb | 11 +++++++++-- lib/gollum/public/gollum/javascript/gollum.js | 13 +++++++++++++ lib/gollum/templates/page.mustache | 6 ++---- lib/gollum/views/page.rb | 4 ---- test/test_app.rb | 17 +++-------------- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/lib/gollum/app.rb b/lib/gollum/app.rb index 9e060f8d..c3566ba5 100644 --- a/lib/gollum/app.rb +++ b/lib/gollum/app.rb @@ -5,6 +5,7 @@ require 'gollum-lib' require 'mustache/sinatra' require 'useragent' require 'stringex' +require 'json' require 'gollum' require 'gollum/views/layout' @@ -131,6 +132,14 @@ module Precious Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) 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 begin [200, {'Content-Type' => 'image/png'}, emoji(params['name'])] @@ -496,7 +505,6 @@ module Precious name = extract_name(fullpath) || wiki.index_page path = extract_path(fullpath) || '/' - if page = wiki.paged(name, path, exact = true) @page = page @name = name @@ -505,7 +513,6 @@ module Precious # Extensions and layout data @editable = true - @page_exists = !page.last_version.nil? @toc_content = wiki.universal_toc ? @page.toc_data : nil @mathjax = wiki.mathjax @h1_title = wiki.h1_title diff --git a/lib/gollum/public/gollum/javascript/gollum.js b/lib/gollum/public/gollum/javascript/gollum.js index 5fc447d3..c5b1460f 100755 --- a/lib/gollum/public/gollum/javascript/gollum.js +++ b/lib/gollum/public/gollum/javascript/gollum.js @@ -306,6 +306,19 @@ $(document).ready(function() { $.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 ' + data.author + ', ' + data.date); + } + }); + $("#last-edit").html(' Getting commit info...'); + }) + } + if( $('#wiki-wrapper.create').length ){ $("#gollum-editor-submit").click( function() { window.onbeforeunload = null; } ); $("#gollum-editor-body").one('change', function(){ diff --git a/lib/gollum/templates/page.mustache b/lib/gollum/templates/page.mustache index 80d1bf85..f23aec2a 100644 --- a/lib/gollum/templates/page.mustache +++ b/lib/gollum/templates/page.mustache @@ -40,12 +40,10 @@ Mousetrap.bind(['e'], function( e ) { class="action-edit-page">Edit {{/editable}} {{/allow_editing}} - {{#page_exists}}
  • History
  • Latest Changes
  • - {{/page_exists}}
    @@ -85,10 +83,10 @@ Mousetrap.bind(['e'], function( e ) {
    diff --git a/lib/gollum/views/page.rb b/lib/gollum/views/page.rb index e903f734..3e7c243c 100644 --- a/lib/gollum/views/page.rb +++ b/lib/gollum/views/page.rb @@ -41,10 +41,6 @@ module Precious @editable end - def page_exists - @page_exists - end - def allow_editing @allow_editing end diff --git a/test/test_app.rb b/test/test_app.rb index 32ba29ea..0eec3726 100644 --- a/test/test_app.rb +++ b/test/test_app.rb @@ -90,25 +90,14 @@ context "Frontend" do divs.each {|div| assert_match div, last_response.body} end - test "retain edit information" do + test "provide last edit information" do page1 = 'page1' user1 = 'user1' @wiki.write_page(page1, :markdown, '', { :name => user1, :email => user1 }); - get page1 - assert_match /Last edited by user1/, last_response.body - - page2 = 'page2' - user2 = 'user2' - @wiki.write_page(page2, :markdown, '', - { :name => user2, :email => user2 }); - - get page2 - assert_match /Last edited by user2/, last_response.body - - get page1 - assert_match /Last edited by user1/, last_response.body + get "/last-commit-info", :path => page1 + assert_match /\"author\":\"user1\"/, last_response.body end test "edits page" do