summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Kalderimis <alex.kalderimis@gmail.com>2019-09-10 18:29:04 +0100
committerAlex Kalderimis <alex.kalderimis@gmail.com>2019-09-12 12:08:39 +0100
commit8cc63517287b1efaad7dd75cea2b24515d15f695 (patch)
treec9c0782e9da7209bd18424516311e931b84609e6
parentbf4ea822ca443befbe40419049cd91e6fd611d52 (diff)
downloadgitlab-ce-sort-wiki-pages-by-date.tar.gz
Move shared wiki templates to own directoriessort-wiki-pages-by-date
This moves shared wiki templates to a distinct location, keeping templates solely concerned with wikis/pages/directories in their respective locations. This implements work requested by the maintainer review.
-rw-r--r--.haml-lint_todo.yml2
-rw-r--r--app/controllers/projects/wiki_directories_controller.rb29
-rw-r--r--app/controllers/projects/wiki_pages_controller.rb8
-rw-r--r--app/controllers/projects/wikis_controller.rb36
-rw-r--r--app/helpers/wiki_helper.rb72
-rw-r--r--app/models/project_wiki.rb7
-rw-r--r--app/models/wiki_directory.rb12
-rw-r--r--app/models/wiki_page.rb8
-rw-r--r--app/views/projects/wiki_directories/_pages_wiki_directory.html.haml (renamed from app/views/projects/wikis/_pages_wiki_directory.html.haml)0
-rw-r--r--app/views/projects/wiki_directories/_sidebar_wiki_directory.html.haml (renamed from app/views/projects/wikis/_sidebar_wiki_directory.html.haml)0
-rw-r--r--app/views/projects/wiki_directories/_wiki_directory.html.haml1
-rw-r--r--app/views/projects/wiki_directories/empty.html.haml34
-rw-r--r--app/views/projects/wiki_directories/show.html.haml (renamed from app/views/projects/wikis/show_dir.html.haml)0
-rw-r--r--app/views/projects/wiki_pages/_form.html.haml (renamed from app/views/projects/wikis/_form.html.haml)0
-rw-r--r--app/views/projects/wiki_pages/_page_title.html.haml4
-rw-r--r--app/views/projects/wiki_pages/_pages_wiki_page.html.haml (renamed from app/views/projects/wikis/_pages_wiki_page.html.haml)2
-rw-r--r--app/views/projects/wiki_pages/_sidebar_wiki_page.html.haml (renamed from app/views/projects/wikis/_sidebar_wiki_page.html.haml)0
-rw-r--r--app/views/projects/wiki_pages/_wiki_page.html.haml1
-rw-r--r--app/views/projects/wiki_pages/edit.html.haml (renamed from app/views/projects/wikis/edit.html.haml)5
-rw-r--r--app/views/projects/wiki_pages/history.html.haml (renamed from app/views/projects/wikis/history.html.haml)7
-rw-r--r--app/views/projects/wiki_pages/missing_page.html.haml (renamed from app/views/projects/wikis/empty.html.haml)0
-rw-r--r--app/views/projects/wiki_pages/show.html.haml34
-rw-r--r--app/views/projects/wikis/_wiki_directory.html.haml1
-rw-r--r--app/views/projects/wikis/_wiki_page.html.haml1
-rw-r--r--app/views/projects/wikis/pages.html.haml5
-rw-r--r--app/views/projects/wikis/show.html.haml37
-rw-r--r--app/views/shared/empty_states/_wikis.html.haml9
-rw-r--r--app/views/shared/wiki/_main_links.html.haml (renamed from app/views/projects/wikis/_main_links.html.haml)0
-rw-r--r--app/views/shared/wiki/_page_listing.html.haml (renamed from app/views/projects/wikis/_page_listing.html.haml)4
-rw-r--r--app/views/shared/wiki/_sidebar.html.haml (renamed from app/views/projects/wikis/_sidebar.html.haml)0
-rw-r--r--config/routes/wiki.rb2
-rw-r--r--locale/gitlab.pot21
-rw-r--r--qa/qa/page/project/wiki/edit.rb2
-rw-r--r--qa/qa/page/project/wiki/new.rb2
-rw-r--r--qa/qa/page/project/wiki/show.rb4
-rw-r--r--spec/controllers/projects/wiki_directories_controller_spec.rb28
-rw-r--r--spec/controllers/projects/wiki_pages_controller_spec.rb2
-rw-r--r--spec/controllers/projects/wikis_controller_spec.rb4
-rw-r--r--spec/features/projects/features_visibility_spec.rb102
-rw-r--r--spec/helpers/wiki_helper_spec.rb7
-rw-r--r--spec/models/wiki_directory_spec.rb2
-rw-r--r--spec/models/wiki_page_spec.rb2
42 files changed, 296 insertions, 201 deletions
diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml
index d29cb8aa0b0..54952719c34 100644
--- a/.haml-lint_todo.yml
+++ b/.haml-lint_todo.yml
@@ -341,8 +341,6 @@ linters:
- 'app/views/projects/triggers/_index.html.haml'
- 'app/views/projects/triggers/_trigger.html.haml'
- 'app/views/projects/triggers/edit.html.haml'
- - 'app/views/projects/wikis/_new.html.haml'
- - 'app/views/projects/wikis/_pages_wiki_page.html.haml'
- 'app/views/projects/wikis/edit.html.haml'
- 'app/views/projects/wikis/history.html.haml'
- 'app/views/repository_check_mailer/notify.html.haml'
diff --git a/app/controllers/projects/wiki_directories_controller.rb b/app/controllers/projects/wiki_directories_controller.rb
index 2934a652934..3416e51be4c 100644
--- a/app/controllers/projects/wiki_directories_controller.rb
+++ b/app/controllers/projects/wiki_directories_controller.rb
@@ -2,31 +2,30 @@
class Projects::WikiDirectoriesController < Projects::ApplicationController
include HasProjectWiki
+ include Gitlab::Utils::StrongMemoize
- before_action :load_dir, only: [:show_dir]
+ before_action :load_dir, only: [:show]
- # Share the templates from the wikis controller.
def self.local_prefixes
- [controller_path, 'projects/wikis']
+ [controller_path, 'shared/wiki']
end
- def show_dir
- @show_children = true # or false, it doesn't matter, since we only support one-level
- if @wiki_dir
- @wiki_pages = Kaminari
- .paginate_array(@wiki_dir.pages)
- .page(params[:page])
- @wiki_entries = @wiki_pages
- render 'show_dir'
- else
- render 'empty'
- end
+ def show
+ return render('empty') if @wiki_dir.empty?
+
+ @wiki_entries = @wiki_pages = Kaminari
+ .paginate_array(@wiki_dir.pages)
+ .page(params[:page])
+
+ render 'show'
end
private
def load_dir
- @wiki_dir ||= project_wiki.find_dir(*dir_params)
+ strong_memoize(:wiki_dir) do
+ project_wiki.find_dir(*dir_params) || WikiDirectory.new(params[:id])
+ end
end
def dir_params
diff --git a/app/controllers/projects/wiki_pages_controller.rb b/app/controllers/projects/wiki_pages_controller.rb
index 158e1c6a1bd..68716106c93 100644
--- a/app/controllers/projects/wiki_pages_controller.rb
+++ b/app/controllers/projects/wiki_pages_controller.rb
@@ -6,9 +6,8 @@ class Projects::WikiPagesController < Projects::ApplicationController
include PreviewMarkdown
include Gitlab::Utils::StrongMemoize
- # Share the templates from the wikis controller.
def self.local_prefixes
- [controller_path, 'projects/wikis']
+ [controller_path, 'shared/wiki']
end
before_action :authorize_create_wiki!, only: [:edit, :create, :update]
@@ -40,11 +39,10 @@ class Projects::WikiPagesController < Projects::ApplicationController
elsif should_create_missing_page?
create_missing_page
else
- render 'empty'
+ render 'missing_page'
end
end
- # Empty action
def edit
end
@@ -122,7 +120,7 @@ class Projects::WikiPagesController < Projects::ApplicationController
def should_create_missing_page?
view_param = @project_wiki.exists? ? 'create' : params[:view]
- can?(current_user, :create_wiki, @project) && view_param == 'create'
+ view_param == 'create' && can?(current_user, :create_wiki, @project)
end
def create_missing_page
diff --git a/app/controllers/projects/wikis_controller.rb b/app/controllers/projects/wikis_controller.rb
index 312661ac448..a64a25a0b5d 100644
--- a/app/controllers/projects/wikis_controller.rb
+++ b/app/controllers/projects/wikis_controller.rb
@@ -2,6 +2,11 @@
class Projects::WikisController < Projects::ApplicationController
include HasProjectWiki
+ include WikiHelper
+
+ def self.local_prefixes
+ [controller_path, 'shared/wiki']
+ end
def pages
@nesting = show_children_param
@@ -16,6 +21,8 @@ class Projects::WikisController < Projects::ApplicationController
else
WikiDirectory.group_by_directory(@wiki_pages)
end
+
+ render 'show'
end
def git_access
@@ -24,33 +31,12 @@ class Projects::WikisController < Projects::ApplicationController
private
def sort_params
- config = project_wiki.sort_params_config
- base_params = params.permit(:sort, :direction)
-
- ps = base_params
- .with_defaults(config[:defaults])
- .allow(config[:allowed])
- .to_hash
- .transform_keys(&:to_sym)
-
- raise ActionController::BadRequest, "illegal sort parameters: #{base_params}" unless ps.size == 2
-
- ps
+ process_params(sort_params_config)
end
- # One of ProjectWiki::NESTINGS
def show_children_param
- default_val = case params[:sort]
- when ProjectWiki::CREATED_AT_ORDER
- ProjectWiki::NESTING_FLAT
- else
- ProjectWiki::NESTING_CLOSED
- end
-
- params
- .with_defaults(show_children: default_val)
- .permit(:show_children)
- .allow(show_children: ProjectWiki::NESTINGS)
- .fetch(:show_children) { raise ActionController::BadRequest, 'illegal value for show_children' }
+ config = nesting_params_config(params[:sort])
+
+ process_params(config)
end
end
diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb
index 64cc09ddf9c..fae298459ca 100644
--- a/app/helpers/wiki_helper.rb
+++ b/app/helpers/wiki_helper.rb
@@ -51,17 +51,20 @@ module WikiHelper
WIKI_SORT_CSS_CLASSES = 'btn btn-default has-tooltip reverse-sort-btn qa-reverse-sort rspec-reverse-sort'
def wiki_sort_controls(sort_params = {}, &block)
- sort = sort_params[:sort] || ProjectWiki::TITLE_ORDER
- currently_desc = sort_params[:direction] == 'desc'
- reversed_direction = currently_desc ? 'asc' : 'desc'
- icon_class = currently_desc ? 'highest' : 'lowest'
+ current_sort = sort_params[:sort] || ProjectWiki::TITLE_ORDER
+ current_direction = (sort_params[:direction] || 'asc').inquiry
+
+ reversed_direction = current_direction.desc? ? 'asc' : 'desc'
+ icon_class = current_direction.desc? ? 'highest' : 'lowest'
+
+ sorting = sort_params.merge(sort: current_sort, direction: reversed_direction)
opts = {
type: 'button',
class: WIKI_SORT_CSS_CLASSES,
title: _('Sort direction')
}
- link_to(yield(sort_params.merge(sort: sort, direction: reversed_direction)), opts) do
+ link_to(yield(sorting), opts) do
sprite_icon("sort-#{icon_class}", size: 16)
end
end
@@ -75,7 +78,7 @@ module WikiHelper
end
# Render the sprite icon given the current show_children state
- def wiki_show_children_title(nesting)
+ def wiki_show_children_icon(nesting)
icon_name, icon_text =
case nesting
when ProjectWiki::NESTING_TREE
@@ -89,8 +92,11 @@ module WikiHelper
sprite_icon_with_text(icon_name, icon_text, size: 16)
end
- def wiki_pages_wiki_page_link(wiki_page, nesting, project)
- wiki_page_link = link_to wiki_page.title, project_wiki_path(project, wiki_page), class: 'wiki-page-title'
+ def wiki_page_link(wiki_page, nesting, project)
+ link = link_to(wiki_page.title,
+ project_wiki_path(project, wiki_page),
+ class: 'wiki-page-title')
+
case nesting
when ProjectWiki::NESTING_FLAT
tags = []
@@ -100,10 +106,56 @@ module WikiHelper
tags << content_tag(:span, '/', class: 'wiki-page-name-separator')
end
- tags << wiki_page_link
+ tags << link
tags.join.html_safe
else
- wiki_page_link
+ link
end
end
+
+ def sort_params_config
+ {
+ keys: [:sort, :direction],
+ defaults: {
+ sort: ProjectWiki::TITLE_ORDER, direction: ProjectWiki::DIRECTION_ASC
+ },
+ allowed: {
+ sort: ProjectWiki::SORT_ORDERS, direction: ProjectWiki::SORT_DIRECTIONS
+ }
+ }
+ end
+
+ def nesting_params_config(sort_key)
+ default_val = case sort_key
+ when ProjectWiki::CREATED_AT_ORDER
+ ProjectWiki::NESTING_FLAT
+ else
+ ProjectWiki::NESTING_CLOSED
+ end
+ {
+ keys: [:show_children],
+ defaults: { show_children: default_val },
+ allowed: { show_children: ProjectWiki::NESTINGS }
+ }
+ end
+
+ def process_params(config)
+ unprocessed = params.permit(*config[:keys])
+
+ processed = unprocessed
+ .with_defaults(config[:defaults])
+ .allow(config[:allowed])
+ .to_hash
+ .transform_keys(&:to_sym)
+
+ if processed.keys == config[:keys]
+ processed.size == 1 ? processed.values.first : processed
+ else
+ raise ActionController::BadRequest, "illegal parameters: #{unprocessed}"
+ end
+ end
+
+ def home_page?
+ params[:id] == 'home'
+ end
end
diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb
index f35bdf30a27..c12213018d7 100644
--- a/app/models/project_wiki.rb
+++ b/app/models/project_wiki.rb
@@ -121,13 +121,6 @@ class ProjectWiki
end
end
- def sort_params_config
- {
- defaults: { sort: TITLE_ORDER, direction: DIRECTION_ASC },
- allowed: { sort: SORT_ORDERS, direction: SORT_DIRECTIONS }
- }
- end
-
# Finds a page within the repository based on a tile
# or slug.
#
diff --git a/app/models/wiki_directory.rb b/app/models/wiki_directory.rb
index 76cf9387e4a..6c86c11e7fb 100644
--- a/app/models/wiki_directory.rb
+++ b/app/models/wiki_directory.rb
@@ -63,9 +63,13 @@ class WikiDirectory
@pages.size
end
- # Relative path to the partial to be used when rendering collections
- # of this object.
- def to_partial_path
- 'projects/wikis/wiki_directory'
+ def empty?
+ page_count.zero?
+ end
+
+ def to_partial_path(context = nil)
+ name = [context, 'wiki_directory'].compact.join('_')
+
+ "projects/wiki_directories/#{name}"
end
end
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb
index eb4aedd493c..f1fccc3aabe 100644
--- a/app/models/wiki_page.rb
+++ b/app/models/wiki_page.rb
@@ -241,10 +241,10 @@ class WikiPage
end
end
- # Relative path to the partial to be used when rendering collections
- # of this object.
- def to_partial_path
- 'projects/wikis/wiki_page'
+ def to_partial_path(context = nil)
+ name = [context, 'wiki_page'].compact.join('_')
+
+ "projects/wiki_pages/#{name}"
end
def id
diff --git a/app/views/projects/wikis/_pages_wiki_directory.html.haml b/app/views/projects/wiki_directories/_pages_wiki_directory.html.haml
index a9d2f38da88..a9d2f38da88 100644
--- a/app/views/projects/wikis/_pages_wiki_directory.html.haml
+++ b/app/views/projects/wiki_directories/_pages_wiki_directory.html.haml
diff --git a/app/views/projects/wikis/_sidebar_wiki_directory.html.haml b/app/views/projects/wiki_directories/_sidebar_wiki_directory.html.haml
index 2f62e9d4516..2f62e9d4516 100644
--- a/app/views/projects/wikis/_sidebar_wiki_directory.html.haml
+++ b/app/views/projects/wiki_directories/_sidebar_wiki_directory.html.haml
diff --git a/app/views/projects/wiki_directories/_wiki_directory.html.haml b/app/views/projects/wiki_directories/_wiki_directory.html.haml
new file mode 100644
index 00000000000..022c209c5bd
--- /dev/null
+++ b/app/views/projects/wiki_directories/_wiki_directory.html.haml
@@ -0,0 +1 @@
+= render wiki_directory.to_partial_path(context), wiki_dir: wiki_directory, context: context
diff --git a/app/views/projects/wiki_directories/empty.html.haml b/app/views/projects/wiki_directories/empty.html.haml
new file mode 100644
index 00000000000..cab1c3acb60
--- /dev/null
+++ b/app/views/projects/wiki_directories/empty.html.haml
@@ -0,0 +1,34 @@
+- layout_path = 'shared/empty_states/wikis_layout'
+- add_to_breadcrumbs _("Wiki"), project_wiki_path(@project, :home)
+- add_to_breadcrumbs s_("Wiki|Pages"), project_wikis_pages_path(@project)
+- breadcrumb_title s_(@wiki_dir.slug)
+- page_title @wiki_dir.slug
+
+- if can?(current_user, :create_wiki, @project)
+ - create_path = project_wiki_path(@project, params[:id], { view: 'create', params: { title: "#{params[:id]}/" } })
+ - create_link = link_to s_('WikiDirEmpty|Create a page in this directory'), create_path, class: 'btn btn-success qa-create-first-page-link', title: s_('WikiDirEmpty|Create a page')
+
+ = render layout: layout_path, locals: { image_path: 'illustrations/wiki_login_empty.svg' } do
+ %h4.text-left
+ = s_('WikiDirEmpty|This directory has no wiki pages')
+ %p.text-left
+ = s_("WikiDirEmpty|A wiki is where you can store all the details about your project. This can include why you've created it, its principles, how to use it, and so on.")
+ = create_link
+
+- elsif can?(current_user, :read_issue, @project)
+ - issues_link = link_to s_('WikiEmptyIssueMessage|issue tracker'), project_issues_path(@project)
+ - new_issue_link = link_to s_('WikiEmpty|Suggest wiki improvement'), new_project_issue_path(@project), class: 'btn btn-success', title: s_('WikiEmptyIssueMessage|Suggest wiki improvement')
+
+ = render layout: layout_path, locals: { image_path: 'illustrations/wiki_logout_empty.svg' } do
+ %h4
+ = s_('WikiDirEmpty|This directory has no wiki pages')
+ %p.text-left
+ = s_('WikiEmptyIssueMessage|You must be a project member in order to add wiki pages. If you have suggestions for how to improve the wiki for this project, consider opening an issue in the %{issues_link}.').html_safe % { issues_link: issues_link }
+ = new_issue_link
+
+- else
+ = render layout: layout_path, locals: { image_path: 'illustrations/wiki_logout_empty.svg' } do
+ %h4
+ = s_('WikiDirEmpty|This directory has no wiki pages')
+ %p
+ = s_('WikiEmpty|You must be a project member in order to add wiki pages.')
diff --git a/app/views/projects/wikis/show_dir.html.haml b/app/views/projects/wiki_directories/show.html.haml
index 4c7978d1216..4c7978d1216 100644
--- a/app/views/projects/wikis/show_dir.html.haml
+++ b/app/views/projects/wiki_directories/show.html.haml
diff --git a/app/views/projects/wikis/_form.html.haml b/app/views/projects/wiki_pages/_form.html.haml
index 8f5757d6d98..8f5757d6d98 100644
--- a/app/views/projects/wikis/_form.html.haml
+++ b/app/views/projects/wiki_pages/_form.html.haml
diff --git a/app/views/projects/wiki_pages/_page_title.html.haml b/app/views/projects/wiki_pages/_page_title.html.haml
new file mode 100644
index 00000000000..a3b077999e6
--- /dev/null
+++ b/app/views/projects/wiki_pages/_page_title.html.haml
@@ -0,0 +1,4 @@
+= link_to @page.human_title, project_wiki_path(@project, @page)
+%span.light
+ = _('&middot;').html_safe
+ = subtitle
diff --git a/app/views/projects/wikis/_pages_wiki_page.html.haml b/app/views/projects/wiki_pages/_pages_wiki_page.html.haml
index cf4f5d5a8c5..c177d03bee1 100644
--- a/app/views/projects/wikis/_pages_wiki_page.html.haml
+++ b/app/views/projects/wiki_pages/_pages_wiki_page.html.haml
@@ -1,6 +1,6 @@
%li
%span.text-secondary-500.svg-icon.svg-baseline= sprite_icon('book', size: 16)
- = wiki_pages_wiki_page_link(wiki_page, @nesting, @project)
+ = wiki_page_link(wiki_page, @nesting, @project)
.float-right
%span.badge.badge-pill.wiki-page-format= _(wiki_page.format)
- if wiki_page.last_version
diff --git a/app/views/projects/wikis/_sidebar_wiki_page.html.haml b/app/views/projects/wiki_pages/_sidebar_wiki_page.html.haml
index 205c3dd76bf..205c3dd76bf 100644
--- a/app/views/projects/wikis/_sidebar_wiki_page.html.haml
+++ b/app/views/projects/wiki_pages/_sidebar_wiki_page.html.haml
diff --git a/app/views/projects/wiki_pages/_wiki_page.html.haml b/app/views/projects/wiki_pages/_wiki_page.html.haml
new file mode 100644
index 00000000000..947e96fed6b
--- /dev/null
+++ b/app/views/projects/wiki_pages/_wiki_page.html.haml
@@ -0,0 +1 @@
+= render wiki_page.to_partial_path(context), wiki_page: wiki_page
diff --git a/app/views/projects/wikis/edit.html.haml b/app/views/projects/wiki_pages/edit.html.haml
index 1234fdcd660..4e5f6a077a4 100644
--- a/app/views/projects/wikis/edit.html.haml
+++ b/app/views/projects/wiki_pages/edit.html.haml
@@ -17,10 +17,7 @@
.nav-text
%h2.wiki-page-title
- if @page.persisted?
- = link_to @page.human_title, project_wiki_path(@project, @page)
- %span.light
- &middot;
- = s_("Wiki|Edit Page")
+ = render partial: 'page_title', locals: { subtitle: s_("Wiki|Edit Page") }
- else
= s_("Wiki|Create New Page")
diff --git a/app/views/projects/wikis/history.html.haml b/app/views/projects/wiki_pages/history.html.haml
index d3e0a91086b..d60a32750df 100644
--- a/app/views/projects/wikis/history.html.haml
+++ b/app/views/projects/wiki_pages/history.html.haml
@@ -7,10 +7,7 @@
.nav-text
%h2.wiki-page-title
- = link_to @page.human_title, project_wiki_path(@project, @page)
- %span.light
- &middot;
- = _("History")
+ = render partial: 'page_title', locals: { subtitle: _("History") }
.table-holder
%table.table
@@ -40,4 +37,4 @@
= version.format
= paginate @page_versions, theme: 'gitlab'
-= render 'sidebar'
+= render 'shared/wiki/sidebar'
diff --git a/app/views/projects/wikis/empty.html.haml b/app/views/projects/wiki_pages/missing_page.html.haml
index 62fa6e1907b..62fa6e1907b 100644
--- a/app/views/projects/wikis/empty.html.haml
+++ b/app/views/projects/wiki_pages/missing_page.html.haml
diff --git a/app/views/projects/wiki_pages/show.html.haml b/app/views/projects/wiki_pages/show.html.haml
new file mode 100644
index 00000000000..879ddfb03c8
--- /dev/null
+++ b/app/views/projects/wiki_pages/show.html.haml
@@ -0,0 +1,34 @@
+- @content_class = 'wiki-page' + (fluid_layout ? '' : ' limit-container-width')
+- breadcrumb_title @page.human_title
+- page_title @page.human_title, _("Wiki")
+- add_to_breadcrumbs _("Wiki"), project_wiki_path(@project, :home)
+- add_to_breadcrumbs s_("Wiki|Pages"), project_wikis_pages_path(@project)
+- if @page_dir.present?
+ - add_to_breadcrumbs _(@page_dir.slug), project_wiki_dir_path(@project, @page_dir)
+
+.wiki-page-header.top-area.has-sidebar-toggle.flex-column.flex-lg-row
+ %button.btn.btn-default.sidebar-toggle.js-sidebar-wiki-toggle{ role: "button", type: "button" }
+ = icon('angle-double-left')
+
+ .nav-text.flex-fill
+ %h2.wiki-page-title= @page.human_title
+ %span.wiki-last-edit-by
+ - if @page.last_version
+ = (_("Last edited by %{name}") % { name: "<strong>#{@page.last_version.author_name}</strong>" }).html_safe
+ #{time_ago_with_tooltip(@page.last_version.authored_date)}
+
+ .nav-controls.pb-md-3.pb-lg-0
+ = render 'main_links'
+
+- if @page.historical?
+ .warning_message
+ = s_("WikiHistoricalPage|This is an old version of this page.")
+ - most_recent_link = link_to s_("WikiHistoricalPage|most recent version"), project_wiki_path(@project, @page)
+ - history_link = link_to s_("WikiHistoricalPage|history"), project_wiki_history_path(@project, @page)
+ = (s_("WikiHistoricalPage|You can view the %{most_recent_link} or browse the %{history_link}.") % { most_recent_link: most_recent_link, history_link: history_link }).html_safe
+
+.prepend-top-default.append-bottom-default
+ .md.md-file.qa-wiki-page-content
+ = render_wiki_content(@page)
+
+= render 'sidebar'
diff --git a/app/views/projects/wikis/_wiki_directory.html.haml b/app/views/projects/wikis/_wiki_directory.html.haml
deleted file mode 100644
index 669cdf6e0dc..00000000000
--- a/app/views/projects/wikis/_wiki_directory.html.haml
+++ /dev/null
@@ -1 +0,0 @@
-= render "#{context}_wiki_directory", wiki_dir: wiki_directory, context: context
diff --git a/app/views/projects/wikis/_wiki_page.html.haml b/app/views/projects/wikis/_wiki_page.html.haml
deleted file mode 100644
index c84d06dad02..00000000000
--- a/app/views/projects/wikis/_wiki_page.html.haml
+++ /dev/null
@@ -1 +0,0 @@
-= render "#{context}_wiki_page", wiki_page: wiki_page
diff --git a/app/views/projects/wikis/pages.html.haml b/app/views/projects/wikis/pages.html.haml
deleted file mode 100644
index 9c732a933cf..00000000000
--- a/app/views/projects/wikis/pages.html.haml
+++ /dev/null
@@ -1,5 +0,0 @@
-- add_to_breadcrumbs "Wiki", project_wiki_path(@project, :home)
-- breadcrumb_title s_("Wiki|Pages")
-- page_title s_("Wiki|Contents"), _("Wiki")
-
-= render 'page_listing', { allow_change_nesting: ::Feature.enabled?(:wikis_allow_change_nesting), wiki_page_title: page_title, page_path: ->(opts) { project_wikis_pages_path(@project, opts) } }
diff --git a/app/views/projects/wikis/show.html.haml b/app/views/projects/wikis/show.html.haml
index dcd2ebd8b2e..9c732a933cf 100644
--- a/app/views/projects/wikis/show.html.haml
+++ b/app/views/projects/wikis/show.html.haml
@@ -1,34 +1,5 @@
-- @content_class = 'wiki-page' + (fluid_layout ? '' : ' limit-container-width')
-- breadcrumb_title @page.human_title
-- page_title @page.human_title, _("Wiki")
-- add_to_breadcrumbs _("Wiki"), project_wiki_path(@project, :home)
-- add_to_breadcrumbs s_("Wiki|Pages"), project_wikis_pages_path(@project)
-- if @page_dir.present?
- - add_to_breadcrumbs _(@page_dir.slug), project_wiki_dir_path(@project, @page_dir)
+- add_to_breadcrumbs "Wiki", project_wiki_path(@project, :home)
+- breadcrumb_title s_("Wiki|Pages")
+- page_title s_("Wiki|Contents"), _("Wiki")
-.wiki-page-header.top-area.has-sidebar-toggle.flex-column.flex-lg-row
- %button.btn.btn-default.sidebar-toggle.js-sidebar-wiki-toggle{ role: "button", type: "button" }
- = icon('angle-double-left')
-
- .nav-text.flex-fill
- %h2.wiki-page-title= @page.human_title
- %span.wiki-last-edit-by
- - if @page.last_version
- = (_("Last edited by %{name}") % { name: "<strong>#{@page.last_version.author_name}</strong>" }).html_safe
- #{time_ago_with_tooltip(@page.last_version.authored_date)}
-
- .nav-controls.pb-md-3.pb-lg-0
- = render 'main_links'
-
-- if @page.historical?
- .warning_message
- = s_("WikiHistoricalPage|This is an old version of this page.")
- - most_recent_link = link_to s_("WikiHistoricalPage|most recent version"), project_wiki_path(@project, @page)
- - history_link = link_to s_("WikiHistoricalPage|history"), project_wiki_history_path(@project, @page)
- = (s_("WikiHistoricalPage|You can view the %{most_recent_link} or browse the %{history_link}.") % { most_recent_link: most_recent_link, history_link: history_link }).html_safe
-
-.prepend-top-default.append-bottom-default
- .md.md-file{ data: { qa_selector: 'wiki_page_content' } }
- = render_wiki_content(@page)
-
-= render 'sidebar'
+= render 'page_listing', { allow_change_nesting: ::Feature.enabled?(:wikis_allow_change_nesting), wiki_page_title: page_title, page_path: ->(opts) { project_wikis_pages_path(@project, opts) } }
diff --git a/app/views/shared/empty_states/_wikis.html.haml b/app/views/shared/empty_states/_wikis.html.haml
index 73eedcc1dc9..e05230de457 100644
--- a/app/views/shared/empty_states/_wikis.html.haml
+++ b/app/views/shared/empty_states/_wikis.html.haml
@@ -1,8 +1,11 @@
- layout_path = 'shared/empty_states/wikis_layout'
+- wiki_is_empty = @project_wiki.empty?
+- empty_msg = wiki_is_empty ? s_('WikiEmpty|This project has no wiki pages') : s_('WikiEmpty|This page does not exist')
+- create_msg = wiki_is_empty ? s_('WikiEmpty|Create your first page') : s_('WikiEmpty|Create this page')
- if can?(current_user, :create_wiki, @project)
- create_path = project_wiki_path(@project, params[:id], { view: 'create' })
- - create_link = link_to s_('WikiEmpty|Create your first page'), create_path, class: 'btn btn-success qa-create-first-page-link', title: s_('WikiEmpty|Create your first page')
+ - create_link = link_to create_msg, create_path, class: 'btn btn-success qa-create-first-page-link', title: create_msg
= render layout: layout_path, locals: { image_path: 'illustrations/wiki_login_empty.svg' } do
%h4.text-left
@@ -17,7 +20,7 @@
= render layout: layout_path, locals: { image_path: 'illustrations/wiki_logout_empty.svg' } do
%h4
- = s_('WikiEmpty|This project has no wiki pages')
+ = empty_msg
%p.text-left
= s_('WikiEmptyIssueMessage|You must be a project member in order to add wiki pages. If you have suggestions for how to improve the wiki for this project, consider opening an issue in the %{issues_link}.').html_safe % { issues_link: issues_link }
= new_issue_link
@@ -25,6 +28,6 @@
- else
= render layout: layout_path, locals: { image_path: 'illustrations/wiki_logout_empty.svg' } do
%h4
- = s_('WikiEmpty|This project has no wiki pages')
+ = empty_msg
%p
= s_('WikiEmpty|You must be a project member in order to add wiki pages.')
diff --git a/app/views/projects/wikis/_main_links.html.haml b/app/views/shared/wiki/_main_links.html.haml
index 5e41bb6a9cd..5e41bb6a9cd 100644
--- a/app/views/projects/wikis/_main_links.html.haml
+++ b/app/views/shared/wiki/_main_links.html.haml
diff --git a/app/views/projects/wikis/_page_listing.html.haml b/app/views/shared/wiki/_page_listing.html.haml
index 868961138c9..80f3071a8b2 100644
--- a/app/views/projects/wikis/_page_listing.html.haml
+++ b/app/views/shared/wiki/_page_listing.html.haml
@@ -22,11 +22,11 @@
.dropdown.inline.wiki-nesting-dropdown
.btn-group{ role: 'group' }
%button.dropdown-toggle{ type: 'button', data: { toggle: 'dropdown', display: 'static' }, class: 'btn btn-default' }
- = wiki_show_children_title(@nesting)
+ = wiki_show_children_icon(@nesting)
= sprite_icon('chevron-down', size: 16)
%ul.dropdown-menu.dropdown-menu-right.dropdown-menu-selectable.dropdown-menu-sort
- ProjectWiki::NESTINGS.each do |choice|
- %li= link_to wiki_show_children_title(choice), page_path.call(current_sorting.merge(show_children: choice)), class: @nesting == choice ? 'is-active' : ''
+ %li= link_to wiki_show_children_icon(choice), page_path.call(current_sorting.merge(show_children: choice)), class: @nesting == choice ? 'is-active' : ''
.dropdown.inline.wiki-sort-dropdown
.btn-group{ role: 'group' }
diff --git a/app/views/projects/wikis/_sidebar.html.haml b/app/views/shared/wiki/_sidebar.html.haml
index 83d145444d8..83d145444d8 100644
--- a/app/views/projects/wikis/_sidebar.html.haml
+++ b/app/views/shared/wiki/_sidebar.html.haml
diff --git a/config/routes/wiki.rb b/config/routes/wiki.rb
index f5cc363b784..3e71c5eb924 100644
--- a/config/routes/wiki.rb
+++ b/config/routes/wiki.rb
@@ -25,6 +25,6 @@ scope(controller: :wikis) do
end
scope(path: '-/wiki_dirs/*id', as: :wiki_dir, format: false, controller: :wiki_directories) do
- get '/', action: :show_dir
+ get '/', action: :show
end
end
diff --git a/locale/gitlab.pot b/locale/gitlab.pot
index fdaf1c19353..dcc90af3e6b 100644
--- a/locale/gitlab.pot
+++ b/locale/gitlab.pot
@@ -297,6 +297,9 @@ msgstr ""
msgid "%{verb} %{time_spent_value} spent time."
msgstr ""
+msgid "&middot;"
+msgstr ""
+
msgid "'%{level}' is not a valid visibility level"
msgstr ""
@@ -13155,6 +13158,18 @@ msgstr ""
msgid "WikiClone|Start Gollum and edit locally"
msgstr ""
+msgid "WikiDirEmpty|A wiki is where you can store all the details about your project. This can include why you've created it, its principles, how to use it, and so on."
+msgstr ""
+
+msgid "WikiDirEmpty|Create a page"
+msgstr ""
+
+msgid "WikiDirEmpty|Create a page in this directory"
+msgstr ""
+
+msgid "WikiDirEmpty|This directory has no wiki pages"
+msgstr ""
+
msgid "WikiEditPageTip|Tip: You can move this page by adding the path to the beginning of the title."
msgstr ""
@@ -13173,6 +13188,9 @@ msgstr ""
msgid "WikiEmpty|A wiki is where you can store all the details about your project. This can include why you've created it, its principles, how to use it, and so on."
msgstr ""
+msgid "WikiEmpty|Create this page"
+msgstr ""
+
msgid "WikiEmpty|Create your first page"
msgstr ""
@@ -13182,6 +13200,9 @@ msgstr ""
msgid "WikiEmpty|The wiki lets you write documentation for your project"
msgstr ""
+msgid "WikiEmpty|This page does not exist"
+msgstr ""
+
msgid "WikiEmpty|This project has no wiki pages"
msgstr ""
diff --git a/qa/qa/page/project/wiki/edit.rb b/qa/qa/page/project/wiki/edit.rb
index f6edc28c41a..bdc1cda8950 100644
--- a/qa/qa/page/project/wiki/edit.rb
+++ b/qa/qa/page/project/wiki/edit.rb
@@ -5,7 +5,7 @@ module QA
module Project
module Wiki
class Edit < Page::Base
- view 'app/views/projects/wikis/_main_links.html.haml' do
+ view 'app/views/shared/wiki/_main_links.html.haml' do
element :new_page_link, 'New page' # rubocop:disable QA/ElementWithPattern
element :page_history_link, 'Page history' # rubocop:disable QA/ElementWithPattern
element :edit_page_link, 'Edit' # rubocop:disable QA/ElementWithPattern
diff --git a/qa/qa/page/project/wiki/new.rb b/qa/qa/page/project/wiki/new.rb
index 792eba4bab7..abad499d700 100644
--- a/qa/qa/page/project/wiki/new.rb
+++ b/qa/qa/page/project/wiki/new.rb
@@ -7,7 +7,7 @@ module QA
class New < Page::Base
include Component::LazyLoader
- view 'app/views/projects/wikis/_form.html.haml' do
+ view 'app/views/projects/wiki_pages/_form.html.haml' do
element :wiki_title_textbox
element :wiki_content_textarea
element :wiki_message_textbox
diff --git a/qa/qa/page/project/wiki/show.rb b/qa/qa/page/project/wiki/show.rb
index a9f6a48b8f4..c6b34ddc317 100644
--- a/qa/qa/page/project/wiki/show.rb
+++ b/qa/qa/page/project/wiki/show.rb
@@ -7,11 +7,11 @@ module QA
class Show < Page::Base
include Page::Component::LegacyClonePanel
- view 'app/views/projects/wikis/_page_listing.html.haml' do
+ view 'app/views/shared/wiki/_page_listing.html.haml' do
element :clone_repository_link, 'Clone repository' # rubocop:disable QA/ElementWithPattern
end
- view 'app/views/projects/wikis/show.html.haml' do
+ view 'app/views/projects/wiki_pages/show.html.haml' do
element :wiki_page_content
end
diff --git a/spec/controllers/projects/wiki_directories_controller_spec.rb b/spec/controllers/projects/wiki_directories_controller_spec.rb
index ede125efde5..78bd120d55e 100644
--- a/spec/controllers/projects/wiki_directories_controller_spec.rb
+++ b/spec/controllers/projects/wiki_directories_controller_spec.rb
@@ -3,7 +3,8 @@
require 'spec_helper'
describe Projects::WikiDirectoriesController do
- let(:project) { create(:project, :public, :repository) }
+ set(:project) { create(:project, :public, :repository) }
+
let(:user) { project.owner }
let(:project_wiki) { ProjectWiki.new(project, user) }
let(:wiki) { project_wiki.wiki }
@@ -19,15 +20,18 @@ describe Projects::WikiDirectoriesController do
destroy_page(wiki_title)
end
- describe 'GET #show_dir' do
- let(:show_dir_params) do
+ describe 'GET #show' do
+ let(:show_params) do
{
namespace_id: project.namespace,
project_id: project,
id: dir_slug
}
end
- subject { get :show_dir, params: show_dir_params }
+
+ before do
+ visit_page
+ end
context 'the directory does not exist' do
let(:dir_slug) { 'this-does-not-exist' }
@@ -38,24 +42,22 @@ describe Projects::WikiDirectoriesController do
context 'the directory does exist' do
let(:wiki_title) { 'some-dir/some-page' }
let(:dir_slug) { 'some-dir' }
- let(:visit_page) { subject }
+ let(:the_directory) { WikiDirectory.new('some-dir', [project_wiki.find_page(wiki_title)]) }
- it { is_expected.to render_template('show_dir') }
+ it { is_expected.to render_template('show') }
it 'sets the wiki_dir attribute' do
- visit_page
- expect(assigns(:wiki_dir)).to eq WikiDirectory.new('some-dir', [project_wiki.find_page(wiki_title)])
- end
-
- it 'sets show_children to true' do
- visit_page
- expect(assigns(:show_children)).to be true
+ expect(assigns(:wiki_dir)).to eq(the_directory)
end
end
end
private
+ def visit_page
+ get :show, params: show_params
+ end
+
def create_page(name, content)
wiki.write_page(name, :markdown, content, commit_details(name))
end
diff --git a/spec/controllers/projects/wiki_pages_controller_spec.rb b/spec/controllers/projects/wiki_pages_controller_spec.rb
index 568dc5e14ae..01a84fbbf20 100644
--- a/spec/controllers/projects/wiki_pages_controller_spec.rb
+++ b/spec/controllers/projects/wiki_pages_controller_spec.rb
@@ -143,7 +143,7 @@ describe Projects::WikiPagesController do
before do
forbid_controller_ability! :create_wiki
end
- it { is_expected.to render_template('empty') }
+ it { is_expected.to render_template('missing_page') }
end
end
diff --git a/spec/controllers/projects/wikis_controller_spec.rb b/spec/controllers/projects/wikis_controller_spec.rb
index df217f9d813..aa6c80394a2 100644
--- a/spec/controllers/projects/wikis_controller_spec.rb
+++ b/spec/controllers/projects/wikis_controller_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
describe Projects::WikisController do
set(:project) { create(:project, :public, :repository) }
set(:user) { project.owner }
+
let(:project_wiki) { ProjectWiki.new(project, user) }
let(:wiki) { project_wiki.wiki }
let(:wiki_title) { 'page title test' }
@@ -23,11 +24,11 @@ describe Projects::WikisController do
subject do
get :pages, params: { namespace_id: project.namespace, project_id: project, id: wiki_title }.merge(extra_params)
end
+
let(:extra_params) { {} }
it 'does not load the pages content' do
expect(controller).to receive(:load_wiki).and_return(project_wiki)
-
expect(project_wiki).to receive(:list_pages).twice.and_call_original
subject
@@ -64,6 +65,7 @@ describe Projects::WikisController do
let(:extra_params) { sort_params.merge(nesting_params) }
let(:sort_params) { { sort: sort_key } }
let(:nesting_params) { {} }
+
before do
subject
end
diff --git a/spec/features/projects/features_visibility_spec.rb b/spec/features/projects/features_visibility_spec.rb
index ca383da5f5c..aa23cb1bba2 100644
--- a/spec/features/projects/features_visibility_spec.rb
+++ b/spec/features/projects/features_visibility_spec.rb
@@ -3,8 +3,9 @@
require 'spec_helper'
describe 'Edit Project Settings' do
+ set(:project) { create(:project, :public, :repository) }
+
let(:member) { create(:user) }
- let!(:project) { create(:project, :public, :repository) }
let!(:issue) { create(:issue, project: project) }
let(:non_member) { create(:user) }
@@ -81,85 +82,88 @@ describe 'Edit Project Settings' do
end
describe 'project features visibility pages' do
- let(:pipeline) { create(:ci_empty_pipeline, project: project) }
- let(:job) { create(:ci_build, pipeline: pipeline) }
-
- let(:tools) do
- {
- builds: project_job_path(project, job),
- issues: project_issues_path(project),
- wiki: project_wiki_path(project, :home),
- snippets: project_snippets_path(project),
- merge_requests: project_merge_requests_path(project)
- }
+ set(:pipeline) { create(:ci_empty_pipeline, project: project) }
+ set(:job) { create(:ci_build, pipeline: pipeline) }
+
+ where(:method_name, :build_url) do
+ [
+ [:builds, -> { project_job_path(project, job) }],
+ [:issues, -> { project_issues_path(project) }],
+ [:wiki, -> { project_wiki_path(project, :home) }],
+ [:snippets, -> { project_snippets_path(project) }],
+ [:merge_requests, -> { project_merge_requests_path(project) }]
+ ]
end
- context 'normal user' do
- before do
- sign_in(member)
- end
+ with_them do
+ let(:url) { build_url.call }
+ let(:attr_name) { "#{method_name}_access_level" }
+
+ context 'normal user' do
+ before do
+ project.team.truncate
+ sign_in(member)
+ end
+
+ it 'renders 200 if tool is enabled' do
+ project.project_feature.update_attribute(attr_name, ProjectFeature::ENABLED)
- it 'renders 200 if tool is enabled' do
- tools.each do |method_name, url|
- project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::ENABLED)
visit url
+
expect(page.status_code).to eq(200)
end
- end
- it 'renders 404 if feature is disabled' do
- tools.each do |method_name, url|
- project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::DISABLED)
+ it 'renders 404 if feature is disabled' do
+ project.project_feature.update_attribute(attr_name, ProjectFeature::DISABLED)
+
visit url
+
expect(page.status_code).to eq(404)
end
- end
- it 'renders 404 if feature is enabled only for team members' do
- project.team.truncate
+ it 'renders 404 if feature is enabled only for team members' do
+ project.project_feature.update_attribute(attr_name, ProjectFeature::PRIVATE)
- tools.each do |method_name, url|
- project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::PRIVATE)
visit url
+
expect(page.status_code).to eq(404)
end
- end
- it 'renders 200 if user is member of group' do
- group = create(:group)
- project.group = group
- project.save
+ it 'renders 200 if user is member of group' do
+ group = create(:group)
+ project.group = group
+ project.save
- group.add_owner(member)
+ group.add_owner(member)
+
+ project.project_feature.update_attribute(attr_name, ProjectFeature::PRIVATE)
- tools.each do |method_name, url|
- project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::PRIVATE)
visit url
+
expect(page.status_code).to eq(200)
end
end
- end
- context 'admin user' do
- before do
- non_member.update_attribute(:admin, true)
- sign_in(non_member)
- end
+ context 'admin user' do
+ before do
+ non_member.update_attribute(:admin, true)
+ project.team.truncate
+ sign_in(non_member)
+ end
- it 'renders 404 if feature is disabled' do
- tools.each do |method_name, url|
+ it 'renders 404 if feature is disabled' do
project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::DISABLED)
+
visit url
+
expect(page.status_code).to eq(404)
end
- end
- it 'renders 200 if feature is enabled only for team members' do
- project.team.truncate
-
- tools.each do |method_name, url|
+ it 'renders 200 if feature is enabled only for team members' do
project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::PRIVATE)
+
visit url
+
expect(page.status_code).to eq(200)
end
end
diff --git a/spec/helpers/wiki_helper_spec.rb b/spec/helpers/wiki_helper_spec.rb
index 1d046cfa1d5..3e463da9671 100644
--- a/spec/helpers/wiki_helper_spec.rb
+++ b/spec/helpers/wiki_helper_spec.rb
@@ -22,7 +22,8 @@ describe WikiHelper do
describe '#wiki_sort_controls' do
let(:project) { create(:project) }
let(:classes) { described_class::WIKI_SORT_CSS_CLASSES }
- let(:wiki_link) do
+
+ subject(:wiki_link) do
helper.wiki_sort_controls(sort: sort, direction: direction) do |opts|
project_wikis_pages_path(project, opts)
end
@@ -64,10 +65,10 @@ describe WikiHelper do
end
end
- describe '#wiki_show_children_title' do
+ describe '#wiki_show_children_icon' do
ProjectWiki::NESTINGS.each do |nesting|
context "When the nesting parameter is `#{nesting}`" do
- let(:element) { helper.wiki_show_children_title(nesting) }
+ let(:element) { helper.wiki_show_children_icon(nesting) }
it 'produces something that contains an SVG' do
expect(element).to match(/svg/)
diff --git a/spec/models/wiki_directory_spec.rb b/spec/models/wiki_directory_spec.rb
index bd89f0fccca..1f9d673cd98 100644
--- a/spec/models/wiki_directory_spec.rb
+++ b/spec/models/wiki_directory_spec.rb
@@ -120,7 +120,7 @@ RSpec.describe WikiDirectory do
it 'returns the relative path to the partial to be used' do
directory = build(:wiki_directory)
- expect(directory.to_partial_path).to eq('projects/wikis/wiki_directory')
+ expect(directory.to_partial_path).to eq('projects/wiki_directories/wiki_directory')
end
end
diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb
index 35387a69fd7..8f3730f97ac 100644
--- a/spec/models/wiki_page_spec.rb
+++ b/spec/models/wiki_page_spec.rb
@@ -424,7 +424,7 @@ describe WikiPage do
it 'returns the relative path to the partial to be used' do
page = build(:wiki_page)
- expect(page.to_partial_path).to eq('projects/wikis/wiki_page')
+ expect(page.to_partial_path).to eq('projects/wiki_pages/wiki_page')
end
end