Коммит 8cc63517 создал по автору Alex Kalderimis's avatar Alex Kalderimis
Просмотр файлов

Move shared wiki templates to own directories

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.
владелец bf4ea822
......@@ -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'
......
......@@ -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
......
......@@ -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 @@ def show
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 @@ def show_blob
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
......
......@@ -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 @@ def pages
else
WikiDirectory.group_by_directory(@wiki_pages)
end
render 'show'
end
def git_access
......@@ -24,33 +31,12 @@ def git_access
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
......@@ -51,17 +51,20 @@ def wiki_attachment_upload_url
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 @@ def wiki_sort_title(key)
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 @@ def wiki_show_children_title(nesting)
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 @@ def wiki_pages_wiki_page_link(wiki_page, nesting, project)
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
......@@ -121,13 +121,6 @@ def list_pages(limit: 0, sort: nil, direction: DIRECTION_ASC, load_content: fals
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.
#
......
......@@ -63,9 +63,13 @@ def page_count
@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
......@@ -241,10 +241,10 @@ def delete
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
......
= render wiki_directory.to_partial_path(context), wiki_dir: wiki_directory, context: context
- 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.')
= link_to @page.human_title, project_wiki_path(@project, @page)
%span.light
= _('&middot;').html_safe
= subtitle
%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
......
= render wiki_page.to_partial_path(context), wiki_page: wiki_page
......@@ -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")
......
......@@ -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'
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать