Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wiki history page #7061

Merged
merged 8 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ module.exports = function (webpackEnv) {
loader: 'svg-sprite-loader', options: {}
},
{ loader: 'svgo-loader', options: {
plugins:[
plugins: [
'removeTitle',
'removeStyleElement',
'cleanupIDs',
Expand Down
19 changes: 18 additions & 1 deletion frontend/src/pages/wiki2/main-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ class MainPanel extends Component {
return { ...props, docUuid: window.seafile.docUuid, currentPageConfig };
}

handleClickHistory = () => {
const { wikiId, permission } = window.wiki.config;
if (permission !== 'rw') return;

const { siteRoot } = window.app.config;
const { currentPageConfig } = this.state;
const historyUrl = `${siteRoot}wiki/file_revisions/${wikiId}/?page_id=${currentPageConfig.id}`;
window.location.href = historyUrl;
};

render() {
const { permission, pathExist, isDataLoading, config, onUpdatePage, isUpdateBySide } = this.props;
const { currentPageConfig = {} } = this.state;
Expand All @@ -83,7 +93,14 @@ class MainPanel extends Component {
<DocInfo initContext={true}/>
</div>
</div>
{username && wikiPermission !== 'public' && <Account />}
{username && wikiPermission !== 'public' && (
<div className='d-flex align-items-center'>
<div className='wiki2-file-history-button' onClick={this.handleClickHistory}>
<i className='sf3-font sf3-font-history'/>
</div>
<Account />
</div>
)}
</div>
<div className="main-panel-center">
<div className={`cur-view-content ${isViewingFile ? 'o-hidden' : ''}`}>
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/pages/wiki2/wiki.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ body {
font-size: 14px;
}

.wiki2-main-panel .wiki2-main-panel-north .wiki2-file-history-button {
width: 24px;
height: 24px;
margin-right: 16px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
border-radius: 3px;
color: #666666;
}

.wiki2-main-panel .wiki2-main-panel-north .wiki2-file-history-button:hover {
background-color: #EFEFEF;
}

.main-panel-center .cur-view-content {
padding: 0;
}
Expand Down
28 changes: 28 additions & 0 deletions seahub/templates/wiki/wiki_file_revisions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends "base_for_react.html" %}
{% load render_bundle from webpack_loader %}

{% block extra_style %}
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}sdoc-editor/sdoc-editor-font.css" />
{% render_bundle 'sdocFileHistory' 'css'%}
{% endblock %}

{% block extra_script %}
<script type="text/javascript">
window.app.config.lang = '{{LANGUAGE_CODE}}';
window.fileHistory = {
pageOptions: {
isWiki2: true,
wikiConfig: '{{ wiki_config|safe }}',
repoID: '{{ repo.id }}',
repoName: '{{ repo.name }}',
fileName: '{{ file_name }}',
filePath: '{{ filePath }}',
docUuid: '{{ file_uuid }}',
assetsUrl: '{{ assets_url }}',
seadocAccessToken: '{{ seadoc_access_token }}',
seadocServerUrl: '{{ seadoc_server_url }}',
}
}
</script>
{% render_bundle 'sdocFileHistory' 'js'%}
{% endblock %}
3 changes: 2 additions & 1 deletion seahub/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
from seahub.api2.endpoints.repo_auto_delete import RepoAutoDeleteView
from seahub.seadoc.views import sdoc_revision, sdoc_revisions, sdoc_to_docx
from seahub.ocm.settings import OCM_ENDPOINT
from seahub.wiki2.views import wiki_view, wiki_publish_view
from seahub.wiki2.views import wiki_view, wiki_publish_view, wiki_history_view
from seahub.api2.endpoints.wiki2 import Wikis2View, Wiki2View, Wiki2ConfigView, Wiki2PagesView, Wiki2PageView, \
Wiki2DuplicatePageView, WikiPageTrashView, Wiki2PublishView, Wiki2PublishConfigView, Wiki2PublishPageView, \
WikiSearch, WikiConvertView
Expand Down Expand Up @@ -743,6 +743,7 @@

re_path(r'^wikis/(?P<wiki_id>[^/]+)/$', wiki_view, name='wiki'),
re_path(r'^wiki/publish/(?P<publish_url>[-0-9a-zA-Z]+)/$', wiki_publish_view, name='wiki-publish'),
re_path(r'^wiki/file_revisions/(?P<wiki_id>[^/]+)/$', wiki_history_view, name='wiki-history'),

path('avatar/', include('seahub.avatar.urls')),
path('group/', include('seahub.group.urls')),
Expand Down
43 changes: 43 additions & 0 deletions seahub/wiki2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import logging
import posixpath
import json
from datetime import datetime

from constance import config
Expand All @@ -19,6 +20,7 @@

from seahub.utils.repo import get_repo_owner, is_repo_admin, is_repo_owner, is_group_repo_staff
from seahub.settings import SEADOC_SERVER_URL
from seahub.seadoc.utils import gen_seadoc_access_token

# Get an instance of a logger
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -145,3 +147,44 @@ def wiki_publish_view(request, publish_url):
"seadoc_server_url": SEADOC_SERVER_URL,
"permission": 'public'
})

def wiki_history_view(request, wiki_id):
""" view wiki history page. for wiki2
"""
# get wiki object or 404
wiki = Wiki.objects.get(wiki_id=wiki_id)
if not wiki:
raise Http404

username = request.user.username
repo_owner = get_repo_owner(request, wiki_id)
wiki.owner = repo_owner

page_id = request.GET.get('page_id')

if page_id:
wiki_config = get_wiki_config(wiki.repo_id, username)
pages = wiki_config.get('pages', [])
page_info = next(filter(lambda t: t['id'] == page_id, pages), {})

# perm check
if not check_wiki_permission(wiki, username):
return render_permission_error(request, 'Permission denied.')

repo_id = wiki.repo_id
repo = seafile_api.get_repo(repo_id)
file_uuid = page_info['docUuid']
file_name = page_info['name']
filePath = page_info['path']
wiki_config = json.dumps(page_info)

return render(request, "wiki/wiki_file_revisions.html", {
'repo': repo,
"wiki_config": wiki_config,
"file_uuid": file_uuid,
"file_name": file_name,
"filePath": filePath,
'assets_url': '/api/v2.1/seadoc/download-image/' + file_uuid,
"seadoc_access_token": gen_seadoc_access_token(file_uuid, file_name, username, permission='rw'),
"seadoc_server_url": SEADOC_SERVER_URL
})
Loading