mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-15 06:44:16 +00:00
Add the ability to create files and selected states
This commit is contained in:
@@ -28,6 +28,8 @@ const propTypes = {
|
|||||||
updateDirent: PropTypes.func.isRequired,
|
updateDirent: PropTypes.func.isRequired,
|
||||||
showShareBtn: PropTypes.bool.isRequired,
|
showShareBtn: PropTypes.bool.isRequired,
|
||||||
showDirentDetail: PropTypes.func.isRequired,
|
showDirentDetail: PropTypes.func.isRequired,
|
||||||
|
onAddFolder: PropTypes.func.isRequired,
|
||||||
|
onDirentClick: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
class DirGridView extends React.Component {
|
class DirGridView extends React.Component {
|
||||||
@@ -74,6 +76,8 @@ class DirGridView extends React.Component {
|
|||||||
onGridItemClick={this.props.onGridItemClick}
|
onGridItemClick={this.props.onGridItemClick}
|
||||||
isDirentDetailShow={this.props.isDirentDetailShow}
|
isDirentDetailShow={this.props.isDirentDetailShow}
|
||||||
onItemRename={this.props.onItemRename}
|
onItemRename={this.props.onItemRename}
|
||||||
|
onAddFolder={this.props.onAddFolder}
|
||||||
|
onDirentClick={this.props.onDirentClick}
|
||||||
/>
|
/>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
|
@@ -9,14 +9,49 @@ const propTypes = {
|
|||||||
dirent: PropTypes.object.isRequired,
|
dirent: PropTypes.object.isRequired,
|
||||||
onItemClick: PropTypes.func.isRequired,
|
onItemClick: PropTypes.func.isRequired,
|
||||||
showImagePopup: PropTypes.func.isRequired,
|
showImagePopup: PropTypes.func.isRequired,
|
||||||
handleContextClick: PropTypes.func.isRequired,
|
onGridItemContextmenu: PropTypes.func.isRequired,
|
||||||
|
onDirentClick: PropTypes.func.isRequired,
|
||||||
|
activeDirent: PropTypes.object,
|
||||||
|
onGridItemMouseDown: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
class DirentGridItem extends React.Component {
|
class DirentGridItem extends React.Component {
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
isGridSelect: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
this.setState({isGridSelect: false}, () => {
|
||||||
|
if (nextProps.activeDirent && nextProps.activeDirent.name === nextProps.dirent.name) {
|
||||||
|
this.setState({isGridSelect: true});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
onItemClick = (e) => {
|
onItemClick = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
const dirent = this.props.dirent;
|
||||||
|
if (this.props.dirent === this.props.activeDirent) {
|
||||||
|
this.setState({isGridSelect:false})
|
||||||
|
if (Utils.imageCheck(dirent.name)) {
|
||||||
|
this.props.showImagePopup(dirent);
|
||||||
|
} else {
|
||||||
|
this.props.onItemClick(dirent);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.setState({isGridSelect: true})
|
||||||
|
this.props.onDirentClick(this.props.dirent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onItemLinkClick = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
const dirent = this.props.dirent;
|
const dirent = this.props.dirent;
|
||||||
if (Utils.imageCheck(dirent.name)) {
|
if (Utils.imageCheck(dirent.name)) {
|
||||||
this.props.showImagePopup(dirent);
|
this.props.showImagePopup(dirent);
|
||||||
@@ -25,6 +60,10 @@ class DirentGridItem extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onGridItemMouseDown = (event) =>{
|
||||||
|
this.props.onGridItemMouseDown(event);
|
||||||
|
}
|
||||||
|
|
||||||
getFileUrl = (url) => {
|
getFileUrl = (url) => {
|
||||||
let fileUrlArr = url.split('/');
|
let fileUrlArr = url.split('/');
|
||||||
if (fileUrlArr.indexOf('48') !== -1) {
|
if (fileUrlArr.indexOf('48') !== -1) {
|
||||||
@@ -34,12 +73,9 @@ class DirentGridItem extends React.Component {
|
|||||||
return fileUrl;
|
return fileUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
onItemContextMenu = (event) => {
|
onGridItemContextmenu = (event) => {
|
||||||
this.handleContextClick(event);
|
let dirent = this.props.dirent;
|
||||||
}
|
this.props.onGridItemContextmenu(event, dirent);
|
||||||
|
|
||||||
handleContextClick = (event) => {
|
|
||||||
this.props.handleContextClick(event, this.props.dirent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -57,9 +93,9 @@ class DirentGridItem extends React.Component {
|
|||||||
|
|
||||||
return(
|
return(
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<li className="grid-item" onContextMenu={this.onItemContextMenu}>
|
<li className="grid-item" onContextMenu={this.onGridItemContextmenu} onMouseDown={this.onGridItemMouseDown}>
|
||||||
<div
|
<div
|
||||||
className="grid-file-img-link cursor-pointer"
|
className={`grid-file-img-link cursor-pointer ${this.state.isGridSelect ? "grid-selected-active" : ""}`}
|
||||||
onClick={this.onItemClick}
|
onClick={this.onItemClick}
|
||||||
>
|
>
|
||||||
{dirent.encoded_thumbnail_src ?
|
{dirent.encoded_thumbnail_src ?
|
||||||
@@ -68,8 +104,8 @@ class DirentGridItem extends React.Component {
|
|||||||
}
|
}
|
||||||
{dirent.is_locked && <img className="grid-file-locked-icon" src={mediaUrl + 'img/file-locked-32.png'} alt={gettext('locked')} title={dirent.lock_owner_name}/>}
|
{dirent.is_locked && <img className="grid-file-locked-icon" src={mediaUrl + 'img/file-locked-32.png'} alt={gettext('locked')} title={dirent.lock_owner_name}/>}
|
||||||
</div>
|
</div>
|
||||||
<div className="grid-file-name">
|
<div className={`grid-file-name ${this.state.isGridSelect ? "grid-link-selected-active" : ""}`}>
|
||||||
<a className="grid-file-name-link" href={dirent.type === 'dir' ? dirHref : fileHref} onClick={this.onItemClick}>{dirent.name}</a>
|
<a className="grid-file-name-link" href={dirent.type === 'dir' ? dirHref : fileHref} onClick={this.onItemLinkClick}>{dirent.name}</a>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
|
@@ -16,6 +16,8 @@ import CopyDirentDialog from '../dialog/copy-dirent-dialog';
|
|||||||
import ShareDialog from '../dialog/share-dialog';
|
import ShareDialog from '../dialog/share-dialog';
|
||||||
import ZipDownloadDialog from '../dialog/zip-download-dialog';
|
import ZipDownloadDialog from '../dialog/zip-download-dialog';
|
||||||
import Rename from '../../components/dialog/rename-grid-item-dialog';
|
import Rename from '../../components/dialog/rename-grid-item-dialog';
|
||||||
|
import CreateFile from '../dialog/create-file-dialog';
|
||||||
|
import CreateFolder from '../dialog/create-folder-dialog';
|
||||||
|
|
||||||
import '../../css/grid-view.css';
|
import '../../css/grid-view.css';
|
||||||
|
|
||||||
@@ -37,6 +39,8 @@ const propTypes = {
|
|||||||
updateDirent: PropTypes.func.isRequired,
|
updateDirent: PropTypes.func.isRequired,
|
||||||
isDirentDetailShow: PropTypes.bool.isRequired,
|
isDirentDetailShow: PropTypes.bool.isRequired,
|
||||||
onGridItemClick: PropTypes.func,
|
onGridItemClick: PropTypes.func,
|
||||||
|
onAddFolder: PropTypes.func.isRequired,
|
||||||
|
onDirentClick: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
class DirentGridView extends React.Component{
|
class DirentGridView extends React.Component{
|
||||||
@@ -46,20 +50,36 @@ class DirentGridView extends React.Component{
|
|||||||
isImagePopupOpen: false,
|
isImagePopupOpen: false,
|
||||||
imageItems: [],
|
imageItems: [],
|
||||||
imageIndex: 0,
|
imageIndex: 0,
|
||||||
isCreateFileDialogShow: false,
|
|
||||||
// onmenuClick
|
// onmenuClick
|
||||||
isShareDialogShow: false,
|
isShareDialogShow: false,
|
||||||
isMoveDialogShow: false,
|
isMoveDialogShow: false,
|
||||||
isCopyDialogShow: false,
|
isCopyDialogShow: false,
|
||||||
isZipDialogOpen: false,
|
isZipDialogOpen: false,
|
||||||
isRenameDialogShow: false,
|
isRenameDialogShow: false,
|
||||||
|
isCreateFolderDialogShow: false,
|
||||||
|
isCreateFileDialogShow: false,
|
||||||
|
|
||||||
isMutipleOperation: false,
|
isMutipleOperation: false,
|
||||||
dirent: '',
|
dirent: '',
|
||||||
|
isGridItemFreezed: false,
|
||||||
|
activeDirent: null,
|
||||||
|
|
||||||
}
|
}
|
||||||
this.isRepoOwner = props.currentRepoInfo.owner_email === username;
|
this.isRepoOwner = props.currentRepoInfo.owner_email === username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onCreateFileToggle = () => {
|
||||||
|
this.setState({
|
||||||
|
isCreateFileDialogShow: !this.state.isCreateFileDialogShow,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onDirentClick = (dirent) => {
|
||||||
|
this.setState({activeDirent: dirent});
|
||||||
|
this.props.onDirentClick(dirent);
|
||||||
|
this.props.onGridItemClick(dirent)
|
||||||
|
}
|
||||||
|
|
||||||
onMoveToggle = () => {
|
onMoveToggle = () => {
|
||||||
this.setState({isMoveDialogShow: !this.state.isMoveDialogShow});
|
this.setState({isMoveDialogShow: !this.state.isMoveDialogShow});
|
||||||
}
|
}
|
||||||
@@ -73,6 +93,11 @@ class DirentGridView extends React.Component{
|
|||||||
this.props.onAddFile(filePath, isDraft);
|
this.props.onAddFile(filePath, isDraft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onAddFolder = (dirPath) => {
|
||||||
|
this.setState({isCreateFolderDialogShow: false});
|
||||||
|
this.props.onAddFolder(dirPath);
|
||||||
|
}
|
||||||
|
|
||||||
onItemShare = (e) => {
|
onItemShare = (e) => {
|
||||||
e.nativeEvent.stopImmediatePropagation(); //for document event
|
e.nativeEvent.stopImmediatePropagation(); //for document event
|
||||||
this.setState({isShareDialogShow: !this.state.isShareDialogShow});
|
this.setState({isShareDialogShow: !this.state.isShareDialogShow});
|
||||||
@@ -126,6 +151,12 @@ class DirentGridView extends React.Component{
|
|||||||
case 'Details':
|
case 'Details':
|
||||||
this.onDetails(currentObject);
|
this.onDetails(currentObject);
|
||||||
break;
|
break;
|
||||||
|
case 'New Folder':
|
||||||
|
this.onCreateFolderToggle(currentObject);
|
||||||
|
break;
|
||||||
|
case 'New File':
|
||||||
|
this.onCreateFileToggle(currentObject);
|
||||||
|
break;
|
||||||
case 'Access Log':
|
case 'Access Log':
|
||||||
this.onAccessLog();
|
this.onAccessLog();
|
||||||
break;
|
break;
|
||||||
@@ -168,6 +199,12 @@ class DirentGridView extends React.Component{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onCreateFolderToggle = () => {
|
||||||
|
this.setState({
|
||||||
|
isCreateFolderDialogShow: !this.state.isCreateFolderDialogShow,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
onItemRenameToggle = () => {
|
onItemRenameToggle = () => {
|
||||||
this.setState({
|
this.setState({
|
||||||
isRenameDialogShow: !this.state.isRenameDialogShow,
|
isRenameDialogShow: !this.state.isRenameDialogShow,
|
||||||
@@ -299,13 +336,42 @@ class DirentGridView extends React.Component{
|
|||||||
return isDuplicated;
|
return isDuplicated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// common contextmenu handle
|
||||||
|
onMouseDown = (event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
if (event.button === 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onGridContainerMouseDown = (event) => {
|
||||||
|
this.onMouseDown(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
onGridItemMouseDown = (event) => {
|
||||||
|
this.onMouseDown(event);
|
||||||
|
}
|
||||||
|
|
||||||
gridContainerClick = () => {
|
gridContainerClick = () => {
|
||||||
if (!this.props.isDirentDetailShow) {
|
if (!this.props.isDirentDetailShow) {
|
||||||
this.props.onGridItemClick(null);
|
this.props.onGridItemClick(null);
|
||||||
}
|
}
|
||||||
|
this.onDirentClick(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleContextClick = (event, currentObject) => {
|
onGridContainContextMenu = (event) => {
|
||||||
|
let id = "dirent-grid-container-menu"
|
||||||
|
let menuList = [TextTranslation.NEW_FOLDER, TextTranslation.NEW_FILE];
|
||||||
|
this.handleContextClick(event, id, menuList);
|
||||||
|
}
|
||||||
|
|
||||||
|
onGridItemContextmenu = (event, dirent) => {
|
||||||
|
let id = 'grid-item-contextmenu';
|
||||||
|
let menuList = this.getDirentItemMenuList(dirent, true);
|
||||||
|
this.handleContextClick(event, id, menuList, dirent);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleContextClick = (event, id, menuList, currentObject = null) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
@@ -321,12 +387,10 @@ class DirentGridView extends React.Component{
|
|||||||
|
|
||||||
hideMenu();
|
hideMenu();
|
||||||
|
|
||||||
let menuList = this.getDirentItemMenuList(currentObject, true);
|
|
||||||
|
|
||||||
this.setState({dirent: currentObject});
|
this.setState({dirent: currentObject});
|
||||||
|
|
||||||
let showMenuConfig = {
|
let showMenuConfig = {
|
||||||
id: 'grid-item-contextmenu',
|
id: id,
|
||||||
position: { x, y },
|
position: { x, y },
|
||||||
target: event.target,
|
target: event.target,
|
||||||
currentObject: currentObject,
|
currentObject: currentObject,
|
||||||
@@ -415,7 +479,7 @@ class DirentGridView extends React.Component{
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
let {direntList, path} = this.props;
|
let {direntList, path} = this.props;
|
||||||
let dirent = this.state.dirent;
|
let dirent = this.state.dirent ? this.state.dirent : '';
|
||||||
let direntPath = Utils.joinPath(path, dirent.name);
|
let direntPath = Utils.joinPath(path, dirent.name);
|
||||||
|
|
||||||
if (this.props.isDirentListLoading) {
|
if (this.props.isDirentListLoading) {
|
||||||
@@ -424,7 +488,7 @@ class DirentGridView extends React.Component{
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<ul className="grid-view" onClick={this.gridContainerClick}>
|
<ul className="grid-view" onClick={this.gridContainerClick} onContextMenu={this.onGridContainContextMenu} onMouseDown={this.onGridContainerMouseDown}>
|
||||||
{
|
{
|
||||||
direntList.length !== 0 && direntList.map((dirent, index) => {
|
direntList.length !== 0 && direntList.map((dirent, index) => {
|
||||||
return (
|
return (
|
||||||
@@ -436,8 +500,11 @@ class DirentGridView extends React.Component{
|
|||||||
onItemClick={this.props.onItemClick}
|
onItemClick={this.props.onItemClick}
|
||||||
currentRepoInfo={this.props.currentRepoInfo}
|
currentRepoInfo={this.props.currentRepoInfo}
|
||||||
showImagePopup={this.showImagePopup}
|
showImagePopup={this.showImagePopup}
|
||||||
handleContextClick={this.handleContextClick}
|
onGridItemContextmenu={this.onGridItemContextmenu}
|
||||||
onItemMove={this.props.onItemMove}
|
onItemMove={this.props.onItemMove}
|
||||||
|
onGridItemMouseDown={this.onGridItemMouseDown}
|
||||||
|
onDirentClick={this.onDirentClick}
|
||||||
|
activeDirent={this.state.activeDirent}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -447,6 +514,30 @@ class DirentGridView extends React.Component{
|
|||||||
id={'grid-item-contextmenu'}
|
id={'grid-item-contextmenu'}
|
||||||
onMenuItemClick={this.onMenuItemClick}
|
onMenuItemClick={this.onMenuItemClick}
|
||||||
/>
|
/>
|
||||||
|
<ContextMenu
|
||||||
|
id={'dirent-grid-container-menu'}
|
||||||
|
onMenuItemClick={this.onMenuItemClick}
|
||||||
|
/>
|
||||||
|
{this.state.isCreateFolderDialogShow && (
|
||||||
|
<ModalPortal>
|
||||||
|
<CreateFolder
|
||||||
|
parentPath={this.props.path}
|
||||||
|
onAddFolder={this.onAddFolder}
|
||||||
|
checkDuplicatedName={this.checkDuplicatedName}
|
||||||
|
addFolderCancel={this.onCreateFolderToggle}
|
||||||
|
/>
|
||||||
|
</ModalPortal>
|
||||||
|
)}
|
||||||
|
{this.state.isCreateFileDialogShow && (
|
||||||
|
<ModalPortal>
|
||||||
|
<CreateFile
|
||||||
|
parentPath={this.props.path}
|
||||||
|
onAddFile={this.onAddFile}
|
||||||
|
checkDuplicatedName={this.checkDuplicatedName}
|
||||||
|
addFileCancel={this.onCreateFileToggle}
|
||||||
|
/>
|
||||||
|
</ModalPortal>
|
||||||
|
)}
|
||||||
{this.state.isMoveDialogShow &&
|
{this.state.isMoveDialogShow &&
|
||||||
<MoveDirentDialog
|
<MoveDirentDialog
|
||||||
path={this.props.path}
|
path={this.props.path}
|
||||||
|
@@ -72,3 +72,11 @@
|
|||||||
right: 10px;
|
right: 10px;
|
||||||
width: 16px;
|
width: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.grid-selected-active {
|
||||||
|
background-color: #f8f8f8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-selected-link-active a{
|
||||||
|
color: #eb8205;
|
||||||
|
}
|
@@ -233,6 +233,7 @@ class LibContentContainer extends React.Component {
|
|||||||
onGridItemClick={this.onGridItemClick}
|
onGridItemClick={this.onGridItemClick}
|
||||||
isDirentDetailShow={this.props.isDirentDetailShow}
|
isDirentDetailShow={this.props.isDirentDetailShow}
|
||||||
onItemRename={this.props.onItemRename}
|
onItemRename={this.props.onItemRename}
|
||||||
|
onDirentClick={this.onDirentClick}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{this.props.currentMode === 'column' && (
|
{this.props.currentMode === 'column' && (
|
||||||
|
Reference in New Issue
Block a user