This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
class PostVersionsController < ApplicationController
|
||||||
|
def index
|
||||||
|
post_id = params[:post].presence
|
||||||
|
tag_id = params[:tag].presence
|
||||||
|
page = (params[:page].presence || 1).to_i
|
||||||
|
limit = (params[:limit].presence || 20).to_i
|
||||||
|
|
||||||
|
page = 1 if page < 1
|
||||||
|
limit = 1 if limit < 1
|
||||||
|
|
||||||
|
offset = (page - 1) * limit
|
||||||
|
|
||||||
|
tag_name = nil
|
||||||
|
if tag_id
|
||||||
|
tag_name = TagName.joins(:tag).find_by(tag: { id: tag_id })
|
||||||
|
return render json: [] unless tag_name
|
||||||
|
end
|
||||||
|
|
||||||
|
q = PostVersion
|
||||||
|
q = q.where(post_id:) if post_id
|
||||||
|
q = q.where("CONCAT(' ', tags, ' ') LIKE ?", "% #{ tag_name } %") if tag_name
|
||||||
|
|
||||||
|
versions = q.order(created_at: :desc, id: :desc)
|
||||||
|
.limit(limit)
|
||||||
|
.offset(offset)
|
||||||
|
|
||||||
|
render json: { versions:, count: q.count }
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -204,7 +204,7 @@ class PostsController < ApplicationController
|
|||||||
pts = pts.where(post_id: id) if id.present?
|
pts = pts.where(post_id: id) if id.present?
|
||||||
pts = pts.where(tag_id:) if tag_id.present?
|
pts = pts.where(tag_id:) if tag_id.present?
|
||||||
pts = pts.includes(:post, :created_user, :deleted_user,
|
pts = pts.includes(:post, :created_user, :deleted_user,
|
||||||
tag: { tag_name: :wiki_page })
|
tag: [:materials, { tag_name: :wiki_page }])
|
||||||
|
|
||||||
events = []
|
events = []
|
||||||
pts.each do |pt|
|
pts.each do |pt|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ Rails.application.routes.draw do
|
|||||||
collection do
|
collection do
|
||||||
get :random
|
get :random
|
||||||
get :changes
|
get :changes
|
||||||
|
get :versions, to: 'post_versions#index'
|
||||||
end
|
end
|
||||||
|
|
||||||
member do
|
member do
|
||||||
|
|||||||
@@ -90,7 +90,9 @@ export default (({ tag, nestLevel, pathKey, parentTagId, suppressClickRef, sp }:
|
|||||||
className={cn ('rounded select-none', over && 'ring-2 ring-offset-2')}
|
className={cn ('rounded select-none', over && 'ring-2 ring-offset-2')}
|
||||||
{...attributes}
|
{...attributes}
|
||||||
{...listeners}>
|
{...listeners}>
|
||||||
<motion.div layoutId={`tag-${ sp ? 'sp-' : '' }${ tag.id }`}>
|
<motion.div
|
||||||
|
transition={{ layout: { duration: .2, ease: 'easeOut' } }}
|
||||||
|
layoutId={`tag-${ sp ? 'sp-' : '' }${ tag.id }`}>
|
||||||
<TagLink tag={tag} nestLevel={nestLevel}/>
|
<TagLink tag={tag} nestLevel={nestLevel}/>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
</div>)
|
</div>)
|
||||||
|
|||||||
@@ -313,7 +313,9 @@ export default (({ post, sp }: Props) => {
|
|||||||
{CATEGORIES.map ((cat: Category) => ((tags[cat] ?? []).length > 0 || dragging) && (
|
{CATEGORIES.map ((cat: Category) => ((tags[cat] ?? []).length > 0 || dragging) && (
|
||||||
<div className="my-3" key={cat}>
|
<div className="my-3" key={cat}>
|
||||||
<SubsectionTitle>
|
<SubsectionTitle>
|
||||||
<motion.div layoutId={`tag-${ sp ? 'sp-' : '' }${ cat }`}>
|
<motion.div
|
||||||
|
layoutId={`tag-${ sp ? 'sp-' : '' }${ cat }`}
|
||||||
|
transition={{ layout: { duration: .2, ease: 'easeOut' } }}>
|
||||||
{CATEGORY_NAMES[cat]}
|
{CATEGORY_NAMES[cat]}
|
||||||
</motion.div>
|
</motion.div>
|
||||||
</SubsectionTitle>
|
</SubsectionTitle>
|
||||||
@@ -325,7 +327,9 @@ export default (({ post, sp }: Props) => {
|
|||||||
</ul>
|
</ul>
|
||||||
</div>))}
|
</div>))}
|
||||||
{post && (
|
{post && (
|
||||||
<motion.div layoutId={`post-info-${ sp }`}>
|
<motion.div
|
||||||
|
layoutId={`post-info-${ sp }`}
|
||||||
|
transition={{ layout: { duration: .2, ease: 'easeOut' } }}>
|
||||||
<SectionTitle>情報</SectionTitle>
|
<SectionTitle>情報</SectionTitle>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Id.: {post.id}</li>
|
<li>Id.: {post.id}</li>
|
||||||
|
|||||||
@@ -136,6 +136,21 @@ export type PostTagChange = {
|
|||||||
changeType: 'add' | 'remove'
|
changeType: 'add' | 'remove'
|
||||||
timestamp: string }
|
timestamp: string }
|
||||||
|
|
||||||
|
export type PostVersion = {
|
||||||
|
postId: number
|
||||||
|
versionNo: number
|
||||||
|
eventType: 'create' | 'update' | 'discard' | 'restore'
|
||||||
|
title: string
|
||||||
|
url: string
|
||||||
|
thumbnail: string
|
||||||
|
thumbnailBase: string
|
||||||
|
tags: Tag[]
|
||||||
|
parent: Post | null
|
||||||
|
originalCreatedFrom: string | null
|
||||||
|
originalCreatedBefore: string | null
|
||||||
|
createdAt: string
|
||||||
|
createdByUser: { id: number; name: string | null } | null }
|
||||||
|
|
||||||
export type SubMenuComponentItem = {
|
export type SubMenuComponentItem = {
|
||||||
component: ReactNode
|
component: ReactNode
|
||||||
visible: boolean }
|
visible: boolean }
|
||||||
|
|||||||
Reference in New Issue
Block a user