cache wiki page hierarchy

pull/6274/head
Wieland Lindenthal 7 years ago
parent 95d3803864
commit 7d72871a7b
  1. 11
      app/assets/javascripts/tree_menu.js
  2. 1
      app/assets/stylesheets/layout/_tree_menu.sass
  3. 10
      app/helpers/application_helper.rb
  4. 2
      app/models/wiki_page.rb
  5. 12
      app/views/wiki/_menu_pages_tree.html.erb
  6. 10
      db/migrate/20180518130559_add_timestamps_to_wiki.rb

@ -28,11 +28,20 @@
(function ($) {
"use strict";
$(function() {
// set selected page for menu tree if provided.
$('[data-selected-page].tree-menu--container').each(function(_i, tree){
var selectedPage = $(tree).data('selected-page');
if (selectedPage) {
$('[slug=' + selectedPage + ']', tree).toggleClass('-selected', true);
}
});
// set click handlers for expanding and collapsing tree nodes
$('.pages-hierarchy.-with-hierarchy .tree-menu--hierarchy-span').click(function (event) {
var target = $(event.target);
var targetList = target.closest('.-with-hierarchy');
console.log("click was triggered", targetList);
if (targetList.hasClass('-hierarchy-collapsed')) {
targetList.addClass('-hierarchy-expanded');
targetList.removeClass('-hierarchy-collapsed');

@ -56,7 +56,6 @@ div.wiki ul.pages-hierarchy,
.-with-hierarchy
padding-left: 18px
&.-hierarchy-collapsed > li
> .tree-menu--item > .tree-menu--hierarchy-span > .tree-menu--hierarchy-indicator > .tree-menu--hierarchy-indicator-icon
@include icon-common

@ -571,7 +571,7 @@ module ApplicationHelper
private
def render_hierarchy_item(page, is_parent, options = {})
content_tag(:span, class: hierarchy_item_classes(page)) do
content_tag(:span, class: 'tree-menu--item', slug: page.slug) do
hierarchy_span_content = nil
if is_parent
hierarchy_span_content = if is_parent
@ -596,14 +596,6 @@ module ApplicationHelper
end
end
def hierarchy_item_classes(page)
item_classes = 'tree-menu--item'
if @page.present? && @page.id == page.id
item_classes += ' -selected'
end
item_classes
end
def render_leaf_indicator
content_tag(:span, tabindex: 0, class: 'tree-menu--leaf-indicator') do
content_tag(:span,

@ -31,7 +31,7 @@ require 'diff'
require 'enumerator'
class WikiPage < ActiveRecord::Base
belongs_to :wiki
belongs_to :wiki, touch: true
has_one :project, through: :wiki
has_one :content, class_name: 'WikiContent', foreign_key: 'page_id', dependent: :destroy
acts_as_attachable delete_permission: :delete_wiki_pages_attachments

@ -1,6 +1,8 @@
<div class="menu-wiki-pages-tree">
<div class="main-menu--segment-header ellipsis"><%= t('label_table_of_contents') %></div>
<% pages = @project.wiki.pages.with_updated_on.order('title').includes(wiki: :project)
pages_by_parent_id = pages.group_by(&:parent_id) %>
<%= render_page_hierarchy(pages_by_parent_id, nil, timestamp: false) %>
<div class="menu-wiki-pages-tree tree-menu--container" data-selected-page="<%= @page.present? ? @page.slug : '' %>">
<% cache @project.wiki do %>
<div class="main-menu--segment-header ellipsis"><%= t('label_table_of_contents') %></div>
<% pages = @project.wiki.pages.order('title').includes(wiki: :project)
pages_by_parent_id = pages.group_by(&:parent_id) %>
<%= render_page_hierarchy(pages_by_parent_id, nil, timestamp: false) %>
<% end %>
</div>

@ -0,0 +1,10 @@
class AddTimestampsToWiki < ActiveRecord::Migration[5.1]
def change
add_timestamps :wikis, default: DateTime.now
change_column_default :wikis, :created_at, nil
change_column_default :wikis, :updated_at, nil
add_column :wiki_pages, :updated_at, :datetime, default: DateTime.now, null: false
change_column_default :wiki_pages, :updated_at, nil
end
end
Loading…
Cancel
Save