1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-07 01:41:39 +00:00

[add]related-files and file-tags (#2829)

This commit is contained in:
Michael An
2019-01-16 11:49:00 +08:00
committed by Daniel Pan
parent 9a53cccd2f
commit 0af388d974
5 changed files with 176 additions and 23 deletions

View File

@@ -32,7 +32,6 @@
"react-select": "^2.1.1", "react-select": "^2.1.1",
"reactstrap": "^6.4.0", "reactstrap": "^6.4.0",
"seafile-js": "^0.2.57", "seafile-js": "^0.2.57",
"seafile-ui": "^0.1.10",
"socket.io-client": "^2.2.0", "socket.io-client": "^2.2.0",
"sw-precache-webpack-plugin": "0.11.4", "sw-precache-webpack-plugin": "0.11.4",
"unified": "^7.0.0", "unified": "^7.0.0",

View File

@@ -4,6 +4,7 @@ import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import { gettext } from '../../utils/constants'; import { gettext } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api'; import { seafileAPI } from '../../utils/seafile-api';
import RepoTag from '../../models/repo-tag'; import RepoTag from '../../models/repo-tag';
require('../../css/repo-tag.css');
const TagItemPropTypes = { const TagItemPropTypes = {
repoTag: PropTypes.object.isRequired, repoTag: PropTypes.object.isRequired,

View File

@@ -7,7 +7,6 @@ import i18n from './i18n';
import './assets/css/fa-solid.css'; import './assets/css/fa-solid.css';
import './assets/css/fa-regular.css'; import './assets/css/fa-regular.css';
import './assets/css/fontawesome.css'; import './assets/css/fontawesome.css';
import 'seafile-ui';
import './index.css'; import './index.css';
let lang = window.app.pageOptions.lang; let lang = window.app.pageOptions.lang;

View File

@@ -4,6 +4,12 @@ import 'whatwg-fetch';
import { SeafileAPI } from 'seafile-js'; import { SeafileAPI } from 'seafile-js';
import { Utils } from './utils/utils'; import { Utils } from './utils/utils';
import cookie from 'react-cookies'; import cookie from 'react-cookies';
import ModalPortal from './components/modal-portal';
import { Modal } from 'reactstrap';
import EditFileTagDialog from './components/dialog/edit-filetag-dialog';
import ListRelatedFileDialog from './components/dialog/list-related-file-dialog';
import AddRelatedFileDialog from './components/dialog/add-related-file-dialog';
import Dirent from './models/dirent';
let repoID = window.app.pageOptions.repoID; let repoID = window.app.pageOptions.repoID;
let repoName = window.app.pageOptions.repoName; let repoName = window.app.pageOptions.repoName;
let filePath = window.app.pageOptions.filePath; let filePath = window.app.pageOptions.filePath;
@@ -262,6 +268,14 @@ class EditorUtilities {
fileMetaData() { fileMetaData() {
return seafileAPI.fileMetaData(repoID, filePath); return seafileAPI.fileMetaData(repoID, filePath);
} }
listFileTags = () => {
return seafileAPI.listFileTags(repoID, filePath);
}
listRepoTags = () => {
return seafileAPI.listRepoTags(repoID);
}
} }
const editorUtilities = new EditorUtilities(); const editorUtilities = new EditorUtilities();
@@ -286,9 +300,58 @@ class MarkdownEditor extends React.Component {
}, },
collabServer: seafileCollabServer ? seafileCollabServer : null, collabServer: seafileCollabServer ? seafileCollabServer : null,
relatedFiles: [], relatedFiles: [],
fileTagList: [],
dirent: {},
showRelatedFileDialog: false,
showEditFileTagDialog: false,
showAddRelatedFileDialog: false,
showMarkdownEditorDialog: false,
}; };
} }
toggleCancel = () => {
this.setState({
showRelatedFileDialog: false,
showEditFileTagDialog: false,
showAddRelatedFileDialog: false,
showMarkdownEditorDialog: false,
});
}
closeAddRelatedFileDialog = () => {
this.setState({
showAddRelatedFileDialog: false,
showRelatedFileDialog: true,
});
}
addRelatedFileToggle = () => {
this.setState({
showRelatedFileDialog: false,
showAddRelatedFileDialog: true,
});
}
openDialogs = (option) => {
switch(option)
{
case 'related_files':
this.setState({
showRelatedFileDialog: true,
showMarkdownEditorDialog: true,
});
break;
case 'tags':
this.setState({
showEditFileTagDialog: true,
showMarkdownEditorDialog: true,
});
break;
default:
return;
}
}
componentDidMount() { componentDidMount() {
seafileAPI.getFileInfo(repoID, filePath).then((res) => { seafileAPI.getFileInfo(repoID, filePath).then((res) => {
@@ -317,14 +380,60 @@ class MarkdownEditor extends React.Component {
}); });
}); });
}); });
this.listRelatedFiles();
this.listFileTags();
this.listDirent();
}
listRelatedFiles = () => {
seafileAPI.listRelatedFiles(repoID, filePath).then(res => { seafileAPI.listRelatedFiles(repoID, filePath).then(res => {
this.setState({ this.setState({
relatedFiles: res.data.related_files relatedFiles: res.data.related_files
}) });
}); });
} }
listFileTags = () => {
seafileAPI.listFileTags(repoID, filePath).then(res => {
let fileTagList = res.data.file_tags;
for (let i = 0, length = fileTagList.length; i < length; i++) {
fileTagList[i].id = fileTagList[i].file_tag_id;
}
this.setState({
fileTagList: fileTagList
});
});
}
listDirent = () => {
seafileAPI.listDir(repoID, dirPath).then(res => {
let direntList = [];
res.data.forEach(item => {
if (this.props.isShowFile === true) {
let dirent = new Dirent(item);
direntList.push(dirent);
} else {
if (item.type === 'dir') {
let dirent = new Dirent(item);
direntList.push(dirent);
}
}
});
direntList = Utils.sortDirents(direntList, 'name', 'asc');
this.setState({
dirent: direntList[0]
});
});
}
onRelatedFileChange = () => {
this.listRelatedFiles();
}
onFileTagChanged = () => {
this.listFileTags();
}
render() { render() {
if (this.state.loading) { if (this.state.loading) {
return ( return (
@@ -334,24 +443,65 @@ class MarkdownEditor extends React.Component {
); );
} else if (this.state.mode === 'editor') { } else if (this.state.mode === 'editor') {
return ( return (
<SeafileEditor <React.Fragment>
fileInfo={this.state.fileInfo} <SeafileEditor
markdownContent={this.state.markdownContent} fileInfo={this.state.fileInfo}
editorUtilities={editorUtilities} markdownContent={this.state.markdownContent}
userInfo={this.state.collabServer ? userInfo : null} editorUtilities={editorUtilities}
collabServer={this.state.collabServer} userInfo={this.state.collabServer ? userInfo : null}
showFileHistory={true} collabServer={this.state.collabServer}
mode={mode} showFileHistory={true}
draftID={draftID} mode={mode}
reviewID={reviewID} draftID={draftID}
reviewStatus={reviewStatus} reviewID={reviewID}
isDraft={isDraft} reviewStatus={reviewStatus}
hasDraft={hasDraft} isDraft={isDraft}
shareLinkExpireDaysMin={shareLinkExpireDaysMin} hasDraft={hasDraft}
shareLinkExpireDaysMax={shareLinkExpireDaysMax} shareLinkExpireDaysMin={shareLinkExpireDaysMin}
relatedFiles={this.state.relatedFiles} shareLinkExpireDaysMax={shareLinkExpireDaysMax}
siteRoot={siteRoot} relatedFiles={this.state.relatedFiles}
/> siteRoot={siteRoot}
openDialogs={this.openDialogs}
fileTagList={this.state.fileTagList}
/>
{this.state.showMarkdownEditorDialog && (
<ModalPortal>
<Modal isOpen={true}>
{
this.state.showRelatedFileDialog &&
<ListRelatedFileDialog
repoID={repoID}
filePath={filePath}
relatedFiles={this.state.relatedFiles}
toggleCancel={this.toggleCancel}
addRelatedFileToggle={this.addRelatedFileToggle}
onRelatedFileChange={this.onRelatedFileChange}
/>
}
{
this.state.showEditFileTagDialog &&
<EditFileTagDialog
repoID={repoID}
filePath={filePath}
fileTagList={this.state.fileTagList}
toggleCancel={this.toggleCancel}
onFileTagChanged={this.onFileTagChanged}
/>
}
{
this.state.showAddRelatedFileDialog &&
<AddRelatedFileDialog
repoID={repoID}
filePath={filePath}
toggleCancel={this.closeAddRelatedFileDialog}
dirent={this.state.dirent}
onRelatedFileChange={this.onRelatedFileChange}
/>
}
</Modal>
</ModalPortal>
)}
</React.Fragment>
); );
} }
} }

View File

@@ -1,15 +1,18 @@
{% load render_bundle from webpack_loader %} {% load render_bundle from webpack_loader %}
{% load static seahub_tags %} {% load static seahub_tags i18n %}
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="{{ LANGUAGE_CODE }}">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<title>{{ filename }}</title> <title>{{ filename }}</title>
<link rel="shortcut icon" href="{{ MEDIA_URL }}{{ favicon_path }}" /> <link rel="shortcut icon" href="{{ MEDIA_URL }}{{ favicon_path }}" />
<link rel="stylesheet" type="text/css" href="{% static "css/seafile-ui.css" %}" />
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/seahub_react.css?t=1398068110" />
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>
<div id="modal-wrapper"></div>
<script type="text/javascript"> <script type="text/javascript">
window.app = { window.app = {
config: { config: {
@@ -43,6 +46,7 @@
} }
} }
</script> </script>
<script src="{{ STATIC_URL }}scripts/i18n/{{ LANGUAGE_CODE }}/djangojs.js"></script>
{% render_bundle 'markdownEditor' %} {% render_bundle 'markdownEditor' %}
</body> </body>
</html> </html>