このコミットが含まれているのは:
@@ -2,21 +2,129 @@ class WikiPagesController < ApplicationController
|
||||
rescue_from Wiki::Commit::Conflict, with: :render_wiki_conflict
|
||||
|
||||
def index
|
||||
# 互換性のための化石リソース
|
||||
# TODO: ヘルプおよびタグ・グループ追加後に,
|
||||
# TODO: タグ説明とヘルプ、タグ・グループから取得する作りに変更する.
|
||||
|
||||
title = params[:title].to_s.strip
|
||||
if title.blank?
|
||||
return render json: WikiPageRepr.base(
|
||||
WikiPage.joins(:tag_name).includes(tag_name: :tag))
|
||||
tag_descriptions = TagDescription.where(language_code: :ja).map do |td|
|
||||
{ id: td.id,
|
||||
tag_name_id: td.tag.tag_name(:ja).id,
|
||||
body: td.body,
|
||||
created_user_id: td.created_by_user_id,
|
||||
updated_user_id: td.updated_by_user_id,
|
||||
created_at: td.created_at,
|
||||
updated_at: td.updated_at,
|
||||
discarded_at: nil,
|
||||
version_no: td.version_no,
|
||||
title: td.tag.name(:ja),
|
||||
deprecated_at: td.tag.deprecated_at }
|
||||
end
|
||||
# TODO: ヘルプ移行したらここに追記
|
||||
# TODO: タグ・グループ追加したらここに追記
|
||||
|
||||
# TODO: ヘルプ、タグ・グループ移行したらそれらもタイトルから除外に含める.
|
||||
# てかこれ何順?
|
||||
wiki_pages =
|
||||
WikiPageRepr.base(WikiPage.joins(:tag_name).includes(tag_name: :tag))
|
||||
.reject { |wp| tag_descriptions.any? { |td| td.title == wp.title } }
|
||||
|
||||
json = tag_descriptions + wiki_pages
|
||||
|
||||
return render json:
|
||||
end
|
||||
|
||||
q = WikiPage.joins(:tag_name).includes(tag_name: :tag)
|
||||
q =
|
||||
TagDescription.joins(tag: :tag_names)
|
||||
.where(language_code: :ja)
|
||||
.where(tag: { tag_names: { language_code: :ja, primary_flg: true } })
|
||||
.where('tag_names.name LIKE ?', "%#{ ApplicationRecord.sanitize_sql_like(title) }%")
|
||||
tag_descriptions = q.limit(20).map do |td|
|
||||
{ id: td.id,
|
||||
tag_name_id: td.tag.tag_name(:ja).id,
|
||||
body: td.body,
|
||||
created_user_id: td.created_by_user_id,
|
||||
updated_user_id: td.updated_by_user_id,
|
||||
created_at: td.created_at,
|
||||
updated_at: td.updated_at,
|
||||
discarded_at: nil,
|
||||
version_no: td.version_no,
|
||||
title: td.tag.name(:ja),
|
||||
deprecated_at: td.tag.deprecated_at }
|
||||
end
|
||||
|
||||
q =
|
||||
WikiPage.joins(:tag_name).includes(tag_name: :tag)
|
||||
.where('tag_names.name LIKE ?', "%#{ WikiPage.sanitize_sql_like(title) }%")
|
||||
render json: WikiPageRepr.base(q.limit(20))
|
||||
# TODO: ヘルプ、タグ・グループ移行したらそれらもタイトルから除外に含める.
|
||||
wiki_pages =
|
||||
WikiPageRepr.base(q.limit(20))
|
||||
.reject { |wp| tag_descriptions.any? { |td| td.title == wp.title } }
|
||||
|
||||
json = (tag_descriptions + wiki_pages)[...20]
|
||||
|
||||
render json:
|
||||
end
|
||||
|
||||
def show
|
||||
tag_description = TagDescription.find_by(id: params[:id])
|
||||
|
||||
if tag_description
|
||||
rev =
|
||||
if params[:version].present?
|
||||
TagDescriptionVersion.find_by(id: params[:version])
|
||||
else
|
||||
TagDescriptionVersion.find_by(tag_id: tag_description.tag_id,
|
||||
language_code: :ja,
|
||||
version_no: tag_description.version_no)
|
||||
end
|
||||
|
||||
if rev
|
||||
body =
|
||||
if rev.version_no == tag_description.version_no
|
||||
tag_description.body
|
||||
else
|
||||
rev.body
|
||||
end
|
||||
revision_id = rev.id
|
||||
pred = TagDescriptionVersion.find_by(tag_id: tag_description.tag_id,
|
||||
language_code: :ja,
|
||||
version_no: tag_description.version_no - 1)&.id
|
||||
succ = TagDescriptionVersion.find_by(tag_id: tag_description.tag_id,
|
||||
language_code: :ja,
|
||||
version_no: tag_description.version_no + 1)&.id
|
||||
updated_at =
|
||||
if rev.version_no == tag_description.version_no
|
||||
tag_description.updated_at
|
||||
else
|
||||
rev.created_at
|
||||
end
|
||||
|
||||
json =
|
||||
{ id: tag_description.id,
|
||||
tag_name_id: tag_description.tag.tag_name(:ja).id,
|
||||
body:,
|
||||
created_user_id: tag_description.created_by_user_id,
|
||||
updated_user_id: tag_description.updated_by_user_id,
|
||||
created_at: tag_description.created_at,
|
||||
updated_at:,
|
||||
discarded_at: nil,
|
||||
version_no: tag_description.version_no,
|
||||
title: tag_description.tag.name(:ja),
|
||||
deprecated_at: tag_description.tag.deprecated_at,
|
||||
revision_id:,
|
||||
pred:,
|
||||
succ: }
|
||||
|
||||
return render json:
|
||||
end
|
||||
end
|
||||
|
||||
page = WikiPage.joins(:tag_name)
|
||||
.includes(tag_name: :tag)
|
||||
.find_by(id: params[:id])
|
||||
|
||||
render_wiki_page_or_404 page
|
||||
end
|
||||
|
||||
@@ -156,10 +264,6 @@ class WikiPagesController < ApplicationController
|
||||
head :ok
|
||||
end
|
||||
|
||||
def search
|
||||
index
|
||||
end
|
||||
|
||||
def changes
|
||||
id = params[:id].presence
|
||||
q = WikiRevision.joins(wiki_page: :tag_name)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
class TagDescription < ApplicationRecord
|
||||
belongs_to :tag
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
class TagDescriptionVersion < ApplicationRecord
|
||||
;
|
||||
end
|
||||
@@ -48,8 +48,11 @@ class WikiPage < ApplicationRecord
|
||||
page
|
||||
end
|
||||
|
||||
def pred_revision_id(revision_id) =
|
||||
wiki_revisions.where('id < ?', revision_id).order(id: :desc).limit(1).pick(:id)
|
||||
def succ_revision_id(revision_id) =
|
||||
wiki_revisions.where('id > ?', revision_id).order(id: :asc).limit(1).pick(:id)
|
||||
def pred_revision_id revision_id
|
||||
wiki_revisions.where('id < ?', revision_id).order(id: :desc).limit(1).pick(:id)
|
||||
end
|
||||
|
||||
def succ_revision_id revision_id
|
||||
wiki_revisions.where('id > ?', revision_id).order(id: :asc).limit(1).pick(:id)
|
||||
end
|
||||
end
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする