Browse Source

#188

feature/188
みてるぞ 1 week ago
parent
commit
23d6303b49
6 changed files with 32 additions and 36 deletions
  1. +1
    -1
      backend/app/controllers/wiki_pages_controller.rb
  2. +2
    -0
      backend/app/models/wiki_page.rb
  3. +1
    -1
      backend/app/models/wiki_revision.rb
  4. +1
    -1
      backend/app/services/wiki/commit.rb
  5. +5
    -15
      frontend/src/pages/wiki/WikiHistoryPage.tsx
  6. +22
    -18
      frontend/src/types.ts

+ 1
- 1
backend/app/controllers/wiki_pages_controller.rb View File

@@ -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
- 0
backend/app/models/wiki_page.rb 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
backend/app/models/wiki_revision.rb 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
backend/app/services/wiki/commit.rb 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
frontend/src/pages/wiki/WikiHistoryPage.tsx 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' && (
<Link to={`/wiki/${ change.wikiPage.id }/diff?from=${ change.pred }&to=${ change.sha }`}>
{change.pred != null && (
<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">
{(() => {
switch (change.changeType)
{
case 'create':
return '新規'
case 'update':
return '更新'
case 'delete':
return '削除'
}
}) ()}
{change.pred == null ? '新規' : '更新'}
</td> </td>
<td className="p-2"> <td className="p-2">
<Link to={`/users/${ change.user.id }`}> <Link to={`/users/${ change.user.id }`}>


+ 22
- 18
frontend/src/types.ts 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
title: string
body: string
sha: string
pred?: string
succ?: string
updatedAt?: string }
id: number
title: string
createdUserId: number
updatedUserId: number
createdAt: string
updatedAt: string
body: string
revisionId: number
pred: number | null
succ: number | null }


export type WikiPageChange = { export type WikiPageChange = {
sha: string
pred?: string
succ?: string
wikiPage: WikiPage
user: User
changeType: string
revisionId: number
pred: number | null
succ: null
wikiPage: Pick<WikiPage, 'id' | 'title'>
user: Pick<User, 'id' | 'name'>
kind: 'content' | 'redirect'
message: string | null
timestamp: string } timestamp: string }


export type WikiPageDiff = { export type WikiPageDiff = {
wikiPageId: number
title: string
olderSha: string
newerSha: string
diff: WikiPageDiffDiff[] }
wikiPageId: number
title: string
olderRevisionId: number | null
newerRevisionId: number | null
diff: WikiPageDiffDiff[] }


export type WikiPageDiffDiff = { export type WikiPageDiffDiff = {
type: 'context' | 'added' | 'removed' type: 'context' | 'added' | 'removed'


Loading…
Cancel
Save