#45 差分表示以外完了
This commit is contained in:
@@ -52,11 +52,16 @@ class WikiPagesController < ApplicationController
|
|||||||
|
|
||||||
def changes
|
def changes
|
||||||
id = params[:id]
|
id = params[:id]
|
||||||
log = id.present? ? wiki.page("#{ id }.md").versions : wiki.repo.log('main', nil, max_count: 50)
|
log = id.present? ? wiki.page("#{ id }.md")&.versions : wiki.repo.log('main', nil, max_count: 50)
|
||||||
|
return render json: [] unless log
|
||||||
|
|
||||||
render json: log.map { |commit|
|
render json: log.map { |commit|
|
||||||
|
wiki_page = WikiPage.find(commit.message.split(' ')[1].to_i)
|
||||||
|
user = User.find(commit.author.name.to_i)
|
||||||
{ sha: commit.id,
|
{ sha: commit.id,
|
||||||
author: commit.author.name,
|
wiki_page: wiki_page && { id: wiki_page.id, title: wiki_page.title },
|
||||||
message: commit.message,
|
user: user && { id: user.id, name: user.name },
|
||||||
|
change_type: commit.message.split(' ')[0].downcase[0...(-1)],
|
||||||
timestamp: commit.authored_date } }
|
timestamp: commit.authored_date } }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -14,15 +14,14 @@ class WikiPage < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def set_body content, user:
|
def set_body content, user:
|
||||||
page = wiki.page("#{ id }.md")
|
commit_info = { name: user.id.to_s,
|
||||||
|
|
||||||
commit_info = { message: "Update #{ title }",
|
|
||||||
name: user.id.to_s,
|
|
||||||
email: 'dummy@example.com' }
|
email: 'dummy@example.com' }
|
||||||
|
page = wiki.page("#{ id }.md")
|
||||||
if page
|
if page
|
||||||
|
commit_info[:message] = "Updated #{ id }"
|
||||||
wiki.update_page(page, id.to_s, :markdown, content, commit_info)
|
wiki.update_page(page, id.to_s, :markdown, content, commit_info)
|
||||||
else
|
else
|
||||||
|
commit_info[:message] = "Created #{ id }"
|
||||||
wiki.write_page(id.to_s, :markdown, content, commit_info)
|
wiki.write_page(id.to_s, :markdown, content, commit_info)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,65 @@
|
|||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { Link, useLocation, useParams } from 'react-router-dom'
|
||||||
import MainArea from '@/components/layout/MainArea'
|
import MainArea from '@/components/layout/MainArea'
|
||||||
|
import axios from 'axios'
|
||||||
|
import { API_BASE_URL } from '@/config'
|
||||||
|
|
||||||
|
import type { WikiPageChange } from '@/types'
|
||||||
|
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
|
const [changes, setChanges] = useState<WikiPageChange[]> ([])
|
||||||
|
|
||||||
|
const location = useLocation ()
|
||||||
|
const query = new URLSearchParams (location.search)
|
||||||
|
const id = query.get ('id')
|
||||||
|
|
||||||
|
useEffect (() => {
|
||||||
|
void (axios.get (`${ API_BASE_URL }/wiki/changes`, id && { params: { id } })
|
||||||
|
.then (res => setChanges (res.data)))
|
||||||
|
}, [location.search])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MainArea>
|
<MainArea>
|
||||||
|
<table className="table-auto w-full border-collapse">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th className="p-2 text-left">タイトル</th>
|
||||||
|
<th className="p-2 text-left">変更</th>
|
||||||
|
<th className="p-2 text-left">日時</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{changes.map (change => (
|
||||||
|
<tr key={change.sha}>
|
||||||
|
<td>差分</td>
|
||||||
|
<td className="p-2">
|
||||||
|
<Link to={`/wiki/${ encodeURIComponent (change.wiki_page.title) }`}
|
||||||
|
className="text-blue-400 hover:underline">
|
||||||
|
{change.wiki_page.title}
|
||||||
|
</Link>
|
||||||
|
</td>
|
||||||
|
<td className="p-2">
|
||||||
|
{(() => {
|
||||||
|
switch (change.change_type)
|
||||||
|
{
|
||||||
|
case 'create': return '新規'
|
||||||
|
case 'update': return '更新'
|
||||||
|
case 'delete': return '削除'
|
||||||
|
}
|
||||||
|
}) ()}
|
||||||
|
</td>
|
||||||
|
<td className="p-2">
|
||||||
|
<Link to={`/users/${ change.user.id }`}
|
||||||
|
className="text-blue-400 hover:underline">
|
||||||
|
{change.user.name}
|
||||||
|
</Link>
|
||||||
|
<br />
|
||||||
|
{change.timestamp}
|
||||||
|
</td>
|
||||||
|
</tr>))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
</MainArea>)
|
</MainArea>)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,4 +22,16 @@ export type User = {
|
|||||||
inheritanceCode: string
|
inheritanceCode: string
|
||||||
role: UserRole }
|
role: UserRole }
|
||||||
|
|
||||||
|
export type WikiPage = {
|
||||||
|
id: number
|
||||||
|
title: string
|
||||||
|
updated_at?: string }
|
||||||
|
|
||||||
|
export type WikiPageChange = {
|
||||||
|
sha: string
|
||||||
|
wiki_page: WikiPage
|
||||||
|
user: User
|
||||||
|
change_type: string
|
||||||
|
timestamp: string }
|
||||||
|
|
||||||
export type UserRole = typeof USER_ROLES[number]
|
export type UserRole = typeof USER_ROLES[number]
|
||||||
|
|||||||
Reference in New Issue
Block a user