2024-06-28 00:39:44 +00:00
|
|
|
import React from 'react';
|
2019-02-21 09:37:04 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2024-09-07 08:29:45 +00:00
|
|
|
import { Modal, ModalBody } from 'reactstrap';
|
2024-06-29 09:58:27 +00:00
|
|
|
import { SeafileMetadata } from '../../metadata';
|
2019-02-21 09:37:04 +00:00
|
|
|
import { Utils } from '../../utils/utils';
|
2024-07-26 09:15:52 +00:00
|
|
|
import { gettext, siteRoot, mediaUrl } from '../../utils/constants';
|
2023-12-26 06:35:44 +00:00
|
|
|
import SeafileMarkdownViewer from '../seafile-markdown-viewer';
|
2019-02-21 09:37:04 +00:00
|
|
|
|
2024-09-07 08:29:45 +00:00
|
|
|
import './dir-column-file.css';
|
|
|
|
|
2019-02-21 09:37:04 +00:00
|
|
|
const propTypes = {
|
|
|
|
path: PropTypes.string.isRequired,
|
|
|
|
repoID: PropTypes.string.isRequired,
|
|
|
|
hash: PropTypes.string,
|
|
|
|
isFileLoading: PropTypes.bool.isRequired,
|
|
|
|
isFileLoadedErr: PropTypes.bool.isRequired,
|
2019-04-19 07:50:27 +00:00
|
|
|
filePermission: PropTypes.string,
|
2019-02-21 09:37:04 +00:00
|
|
|
content: PropTypes.string,
|
2024-08-12 09:15:56 +00:00
|
|
|
viewId: PropTypes.string,
|
2019-02-21 09:37:04 +00:00
|
|
|
lastModified: PropTypes.string,
|
|
|
|
latestContributor: PropTypes.string,
|
|
|
|
onLinkClick: PropTypes.func.isRequired,
|
2024-07-05 09:41:34 +00:00
|
|
|
currentRepoInfo: PropTypes.object,
|
2024-09-07 08:29:45 +00:00
|
|
|
currentDirent: PropTypes.object,
|
|
|
|
onCloseMarkdownViewDialog: PropTypes.func
|
2019-02-21 09:37:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DirColumnFile extends React.Component {
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
if (this.props.hash) {
|
|
|
|
let hash = this.props.hash;
|
2024-07-18 03:58:42 +00:00
|
|
|
setTimeout(function () {
|
2019-02-21 09:37:04 +00:00
|
|
|
window.location.hash = hash;
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onEditClick = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
let { path, repoID } = this.props;
|
|
|
|
let url = siteRoot + 'lib/' + repoID + '/file' + Utils.encodePath(path) + '?mode=edit';
|
|
|
|
window.open(url);
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-02-21 09:37:04 +00:00
|
|
|
|
2019-02-27 09:34:39 +00:00
|
|
|
onOpenFile = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
let { path, repoID } = this.props;
|
|
|
|
let newUrl = siteRoot + 'lib/' + repoID + '/file' + Utils.encodePath(path);
|
|
|
|
window.open(newUrl, '_blank');
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2019-02-27 09:34:39 +00:00
|
|
|
|
2019-02-21 09:37:04 +00:00
|
|
|
render() {
|
2024-09-07 08:29:45 +00:00
|
|
|
const { currentDirent } = this.props;
|
2024-09-08 00:17:47 +00:00
|
|
|
const { name } = currentDirent || {};
|
2024-09-07 08:29:45 +00:00
|
|
|
|
2019-02-21 09:37:04 +00:00
|
|
|
if (this.props.isFileLoadedErr) {
|
|
|
|
return (
|
|
|
|
<div className="message err-tip">{gettext('File does not exist.')}</div>
|
|
|
|
);
|
|
|
|
}
|
2024-06-29 09:58:27 +00:00
|
|
|
|
|
|
|
if (this.props.content === '__sf-metadata') {
|
2024-08-12 09:15:56 +00:00
|
|
|
const { repoID, currentRepoInfo, viewId } = this.props;
|
2024-06-29 09:58:27 +00:00
|
|
|
|
2024-08-12 09:15:56 +00:00
|
|
|
return (<SeafileMetadata mediaUrl={mediaUrl} repoID={repoID} repoInfo={currentRepoInfo} viewID={viewId} />);
|
2024-06-29 09:58:27 +00:00
|
|
|
}
|
|
|
|
|
2019-02-21 09:37:04 +00:00
|
|
|
return (
|
2024-09-07 08:29:45 +00:00
|
|
|
<Modal
|
|
|
|
isOpen={true}
|
|
|
|
className='seafile-markdown-viewer-modal'
|
|
|
|
toggle={this.props.onCloseMarkdownViewDialog}
|
|
|
|
contentClassName='seafile-markdown-viewer-modal-content'
|
|
|
|
zIndex={1046}
|
2019-02-22 07:35:31 +00:00
|
|
|
>
|
2024-09-07 08:29:45 +00:00
|
|
|
<div className='seafile-markdown-viewer-modal-header'>
|
|
|
|
<div className='seafile-markdown-viewer-modal-header-left-name'>
|
|
|
|
<span ><img src={`${mediaUrl}img/file/256/md.png`} width='24' alt='' /></span>
|
|
|
|
<span>{name}</span>
|
|
|
|
</div>
|
|
|
|
<div className='seafile-markdown-viewer-modal-header-right-tool'>
|
|
|
|
{/* Hidden for now, operations may be added later */}
|
|
|
|
{/* <span className='sf3-font sf3-font-more'></span> */}
|
|
|
|
<span className='sf3-font sf3-font-open' onClick={this.onOpenFile}></span>
|
|
|
|
<span className='sf3-font sf3-font-x-01' onClick={this.props.onCloseMarkdownViewDialog}></span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<ModalBody className='seafile-markdown-viewer-modal-body'>
|
|
|
|
<SeafileMarkdownViewer
|
|
|
|
isTOCShow={false}
|
|
|
|
isFileLoading={this.props.isFileLoading}
|
|
|
|
markdownContent={this.props.content}
|
|
|
|
lastModified = {this.props.lastModified}
|
|
|
|
latestContributor={this.props.latestContributor}
|
|
|
|
onLinkClick={this.props.onLinkClick}
|
|
|
|
repoID={this.props.repoID}
|
|
|
|
path={this.props.path}
|
|
|
|
>
|
|
|
|
</SeafileMarkdownViewer>
|
|
|
|
</ModalBody>
|
|
|
|
</Modal>
|
2019-02-21 09:37:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DirColumnFile.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default DirColumnFile;
|