1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-06 17:33:18 +00:00

tag-filter-file-show

This commit is contained in:
wangjianhui
2018-11-19 17:44:59 +08:00
committed by shanshuirenjia
parent 04d4f57b4e
commit 821cb29730
5 changed files with 121 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
import ListTagDialog from '../dialog/list-tag-dialog';
import CreateTagDialog from '../dialog/create-tag-dialog';
import UpdateTagDialog from '../dialog/update-tag-dialog';
import ListTaggedFilesDialog from '../dialog/list-taggedfiles-dialog';
const propTypes = {
repoID: PropTypes.string.isRequired,
@@ -22,6 +23,7 @@ class DirTool extends React.Component {
isListRepoTagShow: false,
isUpdateRepoTagShow: false,
isCreateRepoTagShow: false,
isListTaggedFileShow: false,
};
}
@@ -44,6 +46,14 @@ class DirTool extends React.Component {
});
}
onListTaggedFileToggle = (currentTag) => {
this.setState({
currentTag: currentTag,
isListRepoTagShow: !this.state.isListRepoTagShow,
isListTaggedFileShow: !this.state.isListTaggedFileShow,
});
}
isMarkdownFile(filePath) {
let name = Utils.getFileName(filePath);
return name.indexOf('.md') > -1 ? true : false;
@@ -70,6 +80,7 @@ class DirTool extends React.Component {
onListTagCancel={this.onListRepoTagToggle}
onCreateRepoTag={this.onCreateRepoTagToggle}
onUpdateRepoTag={this.onUpdateRepoTagToggle}
onListFileCancel={this.onListTaggedFileToggle}
/>
}
{
@@ -87,6 +98,13 @@ class DirTool extends React.Component {
toggleCancel={this.onUpdateRepoTagToggle}
/>
}
{
this.state.isListTaggedFileShow &&
<ListTaggedFilesDialog
repoTagId={this.state.currentTag.id}
toggleCancel={this.onListTaggedFileToggle}
/>
}
</Fragment>
);
} else if (!isFile && permission) {

View File

@@ -9,6 +9,7 @@ import '../../css/repo-tag.css';
const tagListItemPropTypes = {
item: PropTypes.object.isRequired,
onTagUpdate: PropTypes.func.isRequired,
onListFileCancel: PropTypes.func.isRequired,
};
class TagListItem extends React.Component {
@@ -17,11 +18,18 @@ class TagListItem extends React.Component {
this.props.onTagUpdate(this.props.item);
}
onListFileCancel = () => {
this.props.onListFileCancel(this.props.item)
}
render() {
let color = this.props.item.color;
return(
<li className="tag-list-item">
<span className={`tag-demo bg-${color}`}>{this.props.item.name}</span>
<span className={`tag-demo bg-${color}`}>
<td width='90%'>{this.props.item.name}</td>
<span onClick={this.onListFileCancel}>{this.props.item.fileCount}</span>
</span>
<i className="tag-edit fa fa-pencil" onClick={this.onTagUpdate}></i>
</li>
);
@@ -35,6 +43,7 @@ const listTagPropTypes = {
onListTagCancel: PropTypes.func.isRequired,
onCreateRepoTag: PropTypes.func.isRequired,
onUpdateRepoTag: PropTypes.func.isRequired,
onListFileCancel: PropTypes.func.isRequired,
};
class ListTagDialog extends React.Component {
@@ -79,7 +88,9 @@ class ListTagDialog extends React.Component {
<ul className="tag-list tag-list-container">
{this.state.repotagList.map((repoTag, index) => {
return (
<TagListItem key={index} item={repoTag} onTagUpdate={this.props.onUpdateRepoTag}/>
<TagListItem key={index} item={repoTag} onTagUpdate={this.props.onUpdateRepoTag}
onListFileCancel={this.props.onListFileCancel}
/>
);
})}
</ul>

View File

@@ -0,0 +1,87 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import { gettext, repoID } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api';
import moment from 'moment';
import { Utils } from '../../utils/utils';
const propTypes = {
repoTagId: PropTypes.number.isRequired,
toggleCancel: PropTypes.func.isRequired,
};
class ListTaggedFilesDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
taggedFileList: [],
};
}
componentDidMount() {
this.getTaggedFiles();
}
getTaggedFiles = () => {
let repoTagId = this.props.repoTagId;
seafileAPI.listTaggedFiles(repoID, repoTagId).then(res => {
let taggedFileList = [];
res.data.tagged_files !== undefined &&
res.data.tagged_files.forEach(file => {
let taggedFile = file;
taggedFileList.push(taggedFile)
});
this.setState({
taggedFileList: taggedFileList,
})
});
}
toggle = () => {
this.props.toggleCancel();
}
render() {
let taggedFileList = this.state.taggedFileList;
return (
<Modal isOpen={true} toggle={this.toggle}>
<ModalHeader toggle={this.toggle}>{gettext('Tagged Files')}</ModalHeader>
<ModalBody>
{
<table>
<thead>
<tr>
<th width='25%'>{gettext('Name')}</th>
<th width='25%'>{gettext('Size')}</th>
<th width='25%'>{gettext('Last Update')}</th>
<th width='25%'>{gettext('Parent Path')}</th>
</tr>
</thead>
<tbody>
{taggedFileList.map((taggedFile, index) => {
return (
<tr key={index}>
<td>{taggedFile.filename}</td>
<td>{Utils.bytesToSize(taggedFile.size)}</td>
<td>{moment.unix(taggedFile.mtime).fromNow()}</td>
<td>{taggedFile.parent_path}</td>
</tr>
);
})}
</tbody>
</table>
}
</ModalBody>
<ModalFooter>
<Button color="primary" onClick={this.toggle}>{gettext('Close')}</Button>
</ModalFooter>
</Modal>
);
}
}
ListTaggedFilesDialog.propTypes = propTypes;
export default ListTaggedFilesDialog;

View File

@@ -1,7 +1,7 @@
class RepoTag {
constructor(object) {
this.id = object.repo_tag_id;
this.repo_id = object.repo_id;
this.fileCount = object.files_count;
this.name = object.tag_name;
this.color = object.tag_color;
}

View File

@@ -48,6 +48,7 @@ def get_tagged_files(repo, repo_tag_id):
tagged_file["parent_path"] = parent_path
tagged_file["filename"] = filename
tagged_file["size"] = file_obj.size
tagged_file["mtime"] = file_obj.mtime
tagged_file["last_modified"] = timestamp_to_isoformat_timestr(file_obj.mtime)
tagged_file["modifier_email"] = file_obj.modifier
tagged_file["modifier_contact_email"] = email2contact_email(file_obj.modifier)