This commit is contained in:
2025-12-29 07:02:02 +09:00
parent 2832d0a6ca
commit 23d6303b49
6 changed files with 32 additions and 36 deletions
@@ -72,7 +72,7 @@ class WikiPagesController < ApplicationController
return head :unprocessable_entity if title.blank? || body.blank? return head :unprocessable_entity if title.blank? || body.blank?
page = WikiPage.new(title:) page = WikiPage.new(title:, created_user: current_user, updated_user: current_user)
if page.save if page.save
message = params[:message].presence message = params[:message].presence
+2
View File
@@ -3,6 +3,8 @@ require 'set'
class WikiPage < ApplicationRecord class WikiPage < ApplicationRecord
has_many :wiki_revisions, dependent: :destroy has_many :wiki_revisions, dependent: :destroy
belongs_to :created_user, class_name: 'User'
belongs_to :updated_user, class_name: 'User'
has_many :redirected_from_revisions, has_many :redirected_from_revisions,
class_name: 'WikiRevision', class_name: 'WikiRevision',
+1 -1
View File
@@ -7,7 +7,7 @@ class WikiRevision < ApplicationRecord
has_many :wiki_revision_lines, dependent: :delete_all has_many :wiki_revision_lines, dependent: :delete_all
has_many :wiki_lines, through: :wiki_revision_lines has_many :wiki_lines, through: :wiki_revision_lines
enum kind: { content: 0, redirect: 1 } enum :kind, { content: 0, redirect: 1 }
validates :kind, presence: true validates :kind, presence: true
validates :lines_count, numericality: { only_integer: true, greater_than_or_equal_to: 0 } validates :lines_count, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
+1 -1
View File
@@ -112,7 +112,7 @@ module Wiki
end end
if missing_rows.any? if missing_rows.any?
WikiLine.upsert_all(missing_rows, unique_by: :index_wiki_lines_on_sha256) WikiLine.upsert_all(missing_rows)
id_by_sha = WikiLine.where(sha256: line_shas).pluck(:sha256, :id).to_h id_by_sha = WikiLine.where(sha256: line_shas).pluck(:sha256, :id).to_h
end end
+5 -15
View File
@@ -41,30 +41,20 @@ export default () => {
</thead> </thead>
<tbody> <tbody>
{changes.map (change => ( {changes.map (change => (
<tr key={change.sha}> <tr key={change.revisionId}>
<td> <td>
{change.changeType === 'update' && ( {change.pred != null && (
<Link to={`/wiki/${ change.wikiPage.id }/diff?from=${ change.pred }&to=${ change.sha }`}> <Link to={`/wiki/${ change.wikiPage.id }/diff?from=${ change.pred }&to=${ change.revisionId }`}>
</Link>)} </Link>)}
</td> </td>
<td className="p-2"> <td className="p-2">
<Link to={`/wiki/${ encodeURIComponent (change.wikiPage.title) }?version=${ change.sha }`}> <Link to={`/wiki/${ encodeURIComponent (change.wikiPage.title) }?version=${ change.revisionId }`}>
{change.wikiPage.title} {change.wikiPage.title}
</Link> </Link>
</td> </td>
<td className="p-2"> <td className="p-2">
{(() => { {change.pred == null ? '新規' : '更新'}
switch (change.changeType)
{
case 'create':
return '新規'
case 'update':
return '更新'
case 'delete':
return '削除'
}
}) ()}
</td> </td>
<td className="p-2"> <td className="p-2">
<Link to={`/users/${ change.user.id }`}> <Link to={`/users/${ change.user.id }`}>
+22 -18
View File
@@ -59,29 +59,33 @@ export type User = {
export type ViewFlagBehavior = typeof ViewFlagBehavior[keyof typeof ViewFlagBehavior] export type ViewFlagBehavior = typeof ViewFlagBehavior[keyof typeof ViewFlagBehavior]
export type WikiPage = { export type WikiPage = {
id: number id: number
title: string title: string
body: string createdUserId: number
sha: string updatedUserId: number
pred?: string createdAt: string
succ?: string updatedAt: string
updatedAt?: string } body: string
revisionId: number
pred: number | null
succ: number | null }
export type WikiPageChange = { export type WikiPageChange = {
sha: string revisionId: number
pred?: string pred: number | null
succ?: string succ: null
wikiPage: WikiPage wikiPage: Pick<WikiPage, 'id' | 'title'>
user: User user: Pick<User, 'id' | 'name'>
changeType: string kind: 'content' | 'redirect'
message: string | null
timestamp: string } timestamp: string }
export type WikiPageDiff = { export type WikiPageDiff = {
wikiPageId: number wikiPageId: number
title: string title: string
olderSha: string olderRevisionId: number | null
newerSha: string newerRevisionId: number | null
diff: WikiPageDiffDiff[] } diff: WikiPageDiffDiff[] }
export type WikiPageDiffDiff = { export type WikiPageDiffDiff = {
type: 'context' | 'added' | 'removed' type: 'context' | 'added' | 'removed'