Commit a9b119d0 authored by Sean McGivern's avatar Sean McGivern

Merge branch '14995-custom_wiki_sidebar' into 'master'

Implement customized sidebar

Closes #14995

See merge request gitlab-org/gitlab-ce!17940
parents 05b25f5a b023a920
...@@ -116,7 +116,12 @@ class Projects::WikisController < Projects::ApplicationController ...@@ -116,7 +116,12 @@ class Projects::WikisController < Projects::ApplicationController
# Call #wiki to make sure the Wiki Repo is initialized # Call #wiki to make sure the Wiki Repo is initialized
@project_wiki.wiki @project_wiki.wiki
@sidebar_page = @project_wiki.find_sidebar(params[:version_id])
unless @sidebar_page # Fallback to default sidebar
@sidebar_wiki_entries = WikiPage.group_by_directory(@project_wiki.pages(limit: 15)) @sidebar_wiki_entries = WikiPage.group_by_directory(@project_wiki.pages(limit: 15))
end
rescue ProjectWiki::CouldNotCreateWikiError rescue ProjectWiki::CouldNotCreateWikiError
flash[:notice] = "Could not create Wiki Repository at this time. Please try again later." flash[:notice] = "Could not create Wiki Repository at this time. Please try again later."
redirect_to project_path(@project) redirect_to project_path(@project)
......
# frozen_string_literal: true
class ProjectWiki class ProjectWiki
include Gitlab::ShellAdapter include Gitlab::ShellAdapter
include Storage::LegacyProjectWiki include Storage::LegacyProjectWiki
...@@ -9,6 +11,7 @@ class ProjectWiki ...@@ -9,6 +11,7 @@ class ProjectWiki
}.freeze unless defined?(MARKUPS) }.freeze unless defined?(MARKUPS)
CouldNotCreateWikiError = Class.new(StandardError) CouldNotCreateWikiError = Class.new(StandardError)
SIDEBAR = '_sidebar'
# Returns a string describing what went wrong after # Returns a string describing what went wrong after
# an operation fails. # an operation fails.
...@@ -98,6 +101,10 @@ class ProjectWiki ...@@ -98,6 +101,10 @@ class ProjectWiki
end end
end end
def find_sidebar(version = nil)
find_page(SIDEBAR, version)
end
def find_file(name, version = nil) def find_file(name, version = nil)
wiki.file(name, version) wiki.file(name, version)
end end
......
...@@ -11,9 +11,11 @@ ...@@ -11,9 +11,11 @@
.blocks-container .blocks-container
.block.block-first .block.block-first
- if @sidebar_page
= render_wiki_content(@sidebar_page)
- else
%ul.wiki-pages %ul.wiki-pages
= render @sidebar_wiki_entries, context: 'sidebar' = render @sidebar_wiki_entries, context: 'sidebar'
.block .block
= link_to project_wikis_pages_path(@project), class: 'btn btn-block' do = link_to project_wikis_pages_path(@project), class: 'btn btn-block' do
= s_("Wiki|More Pages") = s_("Wiki|More Pages")
......
---
title: "Custom Wiki Sidebar Support Issue 14995"
merge_request:
author: Josh Sooter
type: added
...@@ -107,3 +107,10 @@ On the right sidebar, click on **Clone repository** and follow the on-screen ...@@ -107,3 +107,10 @@ On the right sidebar, click on **Clone repository** and follow the on-screen
instructions. instructions.
[permissions]: ../../permissions.md [permissions]: ../../permissions.md
## Customizing sidebar
By default, the wiki would render a sidebar which lists all the pages for the
wiki. You could as well provide a `_sidebar` page to replace this default
sidebar. When this customized sidebar page is provided, the default sidebar
would not be rendered, but the customized one.
...@@ -2,16 +2,22 @@ require "spec_helper" ...@@ -2,16 +2,22 @@ require "spec_helper"
describe "User creates wiki page" do describe "User creates wiki page" do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:wiki) { ProjectWiki.new(project, user) }
let(:project) { create(:project) }
before do before do
project.add_maintainer(user) project.add_maintainer(user)
sign_in(user) sign_in(user)
end
context "when wiki is empty" do
before do
visit(project_wikis_path(project)) visit(project_wikis_path(project))
click_link "Create your first page" click_link "Create your first page"
end end
context "when wiki is empty" do
context "in a user namespace" do context "in a user namespace" do
let(:project) { create(:project, :wiki_repo, namespace: user.namespace) } let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
...@@ -165,7 +171,9 @@ describe "User creates wiki page" do ...@@ -165,7 +171,9 @@ describe "User creates wiki page" do
context "when wiki is not empty", :js do context "when wiki is not empty", :js do
before do before do
create(:wiki_page, wiki: create(:project, :wiki_repo, namespace: user.namespace).wiki, attrs: { title: "home", content: "Home page" }) create(:wiki_page, wiki: wiki, attrs: { title: 'home', content: 'Home page' })
visit(project_wikis_path(project))
end end
context "in a user namespace" do context "in a user namespace" do
...@@ -290,4 +298,34 @@ describe "User creates wiki page" do ...@@ -290,4 +298,34 @@ describe "User creates wiki page" do
end end
end end
end end
describe 'sidebar feature' do
context 'when there are some existing pages' do
before do
create(:wiki_page, wiki: wiki, attrs: { title: 'home', content: 'home' })
create(:wiki_page, wiki: wiki, attrs: { title: 'another', content: 'another' })
end
it 'renders a default sidebar when there is no customized sidebar' do
visit(project_wikis_path(project))
expect(page).to have_content('Another')
expect(page).to have_content('More Pages')
end
context 'when there is a customized sidebar' do
before do
create(:wiki_page, wiki: wiki, attrs: { title: '_sidebar', content: 'My customized sidebar' })
end
it 'renders my customized sidebar instead of the default one' do
visit(project_wikis_path(project))
expect(page).to have_content('My customized sidebar')
expect(page).to have_content('More Pages')
expect(page).not_to have_content('Another')
end
end
end
end
end end
...@@ -189,6 +189,22 @@ describe ProjectWiki do ...@@ -189,6 +189,22 @@ describe ProjectWiki do
end end
end end
describe '#find_sidebar' do
before do
create_page(described_class::SIDEBAR, 'This is an awesome Sidebar')
end
after do
subject.pages.each { |page| destroy_page(page.page) }
end
it 'finds the page defined as _sidebar' do
page = subject.find_page('_sidebar')
expect(page.content).to eq('This is an awesome Sidebar')
end
end
describe '#find_file' do describe '#find_file' do
shared_examples 'finding a wiki file' do shared_examples 'finding a wiki file' do
let(:image) { File.open(Rails.root.join('spec', 'fixtures', 'big-image.png')) } let(:image) { File.open(Rails.root.join('spec', 'fixtures', 'big-image.png')) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment