1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-12 12:22:13 +00:00
seahub/frontend/src/components/dir-view-mode/dir-column-file.js

104 lines
3.4 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import { Modal, ModalBody } from 'reactstrap';
import { SeafileMetadata } from '../../metadata';
import { Utils } from '../../utils/utils';
import { gettext, siteRoot, mediaUrl } from '../../utils/constants';
import SeafileMarkdownViewer from '../seafile-markdown-viewer';
import './dir-column-file.css';
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,
content: PropTypes.string,
viewId: PropTypes.string,
lastModified: PropTypes.string,
latestContributor: PropTypes.string,
onLinkClick: PropTypes.func.isRequired,
currentRepoInfo: PropTypes.object,
currentDirent: PropTypes.object,
onCloseMarkdownViewDialog: PropTypes.func
};
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 () {
window.location.hash = hash;
}, 500);
}
}
2019-02-27 09:34:39 +00:00
onOpenFile = (e) => {
e.preventDefault();
let { path, repoID, currentDirent } = this.props;
let { name } = currentDirent || {};
let newUrl = siteRoot + 'lib/' + repoID + '/file' + Utils.encodePath(path) + '/' + name;
2019-02-27 09:34:39 +00:00
window.open(newUrl, '_blank');
};
2019-02-27 09:34:39 +00:00
render() {
const { currentDirent } = this.props;
const { name } = currentDirent || {};
if (this.props.isFileLoadedErr) {
return (
<div className="message err-tip">{gettext('File does not exist.')}</div>
);
}
if (this.props.content === '__sf-metadata') {
const { repoID, currentRepoInfo, viewId } = this.props;
return (<SeafileMetadata mediaUrl={mediaUrl} repoID={repoID} repoInfo={currentRepoInfo} viewID={viewId} />);
}
return (
<Modal
isOpen={true}
className='seafile-markdown-viewer-modal'
toggle={this.props.onCloseMarkdownViewDialog}
contentClassName='seafile-markdown-viewer-modal-content'
zIndex={1046}
>
<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>
);
}
}
DirColumnFile.propTypes = propTypes;
export default DirColumnFile;