1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-08 18:30:53 +00:00

chuck away useless filetag (#2943)

This commit is contained in:
王健辉
2019-02-14 16:48:46 +08:00
committed by Daniel Pan
parent 61470d7f01
commit 53153d83c5
7 changed files with 111 additions and 57 deletions

View File

@@ -10,7 +10,8 @@ const propTypes = {
repoID: PropTypes.string.isRequired,
currentTag: PropTypes.object.isRequired,
toggleCancel: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired
onClose: PropTypes.func.isRequired,
updateUsedRepoTags: PropTypes.func.isRequired,
};
class ListTaggedFilesDialog extends React.Component {
@@ -22,6 +23,15 @@ class ListTaggedFilesDialog extends React.Component {
};
}
onDeleteTaggedFile = (taggedFile) => {
let repoID = this.props.repoID;
let fileTagID = taggedFile.file_tag_id;
seafileAPI.deleteFileTag(repoID, fileTagID).then(res => {
this.getTaggedFiles();
this.props.updateUsedRepoTags();
});
}
componentDidMount() {
this.getTaggedFiles();
}
@@ -50,23 +60,21 @@ class ListTaggedFilesDialog extends React.Component {
<table>
<thead>
<tr>
<th width='50%' className="ellipsis">{gettext('Name')}</th>
<th width='25%'>{gettext('Size')}</th>
<th width='25%'>{gettext('Last Update')}</th>
<th width='45%' className="ellipsis">{gettext('Name')}</th>
<th width='27%'>{gettext('Size')}</th>
<th width='18%'>{gettext('Last Update')}</th>
<th width='10%'></th>
</tr>
</thead>
<tbody>
{taggedFileList.map((taggedFile, index) => {
let path = Utils.joinPath(taggedFile.parent_path, taggedFile.filename);
let href = siteRoot + 'lib/' + this.props.repoID + '/file' + Utils.encodePath(path);
return (
<tr key={index}>
<td className="name">
<a href={href} target='_blank'>{taggedFile.filename}</a>
</td>
<td>{Utils.bytesToSize(taggedFile.size)}</td>
<td>{moment.unix(taggedFile.mtime).fromNow()}</td>
</tr>
<TaggedFile
key={index}
repoID={this.props.repoID}
taggedFile={taggedFile}
onDeleteTaggedFile={this.onDeleteTaggedFile}
/>
);
})}
</tbody>
@@ -83,3 +91,54 @@ class ListTaggedFilesDialog extends React.Component {
ListTaggedFilesDialog.propTypes = propTypes;
export default ListTaggedFilesDialog;
const TaggedFilePropTypes = {
repoID: PropTypes.string.isRequired,
taggedFile: PropTypes.object,
onDeleteTaggedFile: PropTypes.func.isRequired,
};
class TaggedFile extends React.Component {
constructor(props) {
super(props);
this.state = ({
active: false,
});
}
onMouseEnter = () => {
this.setState({
active: true
});
}
onMouseLeave = () => {
this.setState({
active: false
});
}
render() {
const taggedFile = this.props.taggedFile;
let className = this.state.active ? 'action-icon sf2-icon-x3' : 'action-icon vh sf2-icon-x3';
let path = taggedFile.parent_path ? Utils.joinPath(taggedFile.parent_path, taggedFile.filename) : '';
let href = siteRoot + 'lib/' + this.props.repoID + '/file' + Utils.encodePath(path);
return ( taggedFile.file_deleted ?
<tr onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}>
<td colSpan='3' className="name">{taggedFile.filename}{' '}
<span style={{color:"red"}}>{gettext('deleted')}</span>
</td>
<td><i className={className} onClick={this.props.onDeleteTaggedFile.bind(this, taggedFile)}></i></td>
</tr>
:
<tr>
<td className="name"><a href={href} target='_blank'>{taggedFile.filename}</a></td>
<td>{Utils.bytesToSize(taggedFile.size)}</td>
<td colSpan='2'>{moment.unix(taggedFile.mtime).fromNow()}</td>
</tr>
);
}
}
TaggedFile.propTypes = TaggedFilePropTypes;

View File

@@ -60,6 +60,7 @@ const propTypes = {
readmeMarkdown: PropTypes.object,
draftCounts: PropTypes.number,
reviewCounts: PropTypes.number,
updateUsedRepoTags: PropTypes.func.isRequired,
};
class DirPanel extends React.Component {
@@ -211,6 +212,7 @@ class DirPanel extends React.Component {
readmeMarkdown={this.props.readmeMarkdown}
draftCounts={this.props.draftCounts}
reviewCounts={this.props.reviewCounts}
updateUsedRepoTags={this.props.updateUsedRepoTags}
/>
)}
<DirentListView

View File

@@ -75,16 +75,7 @@ class DirView extends React.Component {
reviewCounts: res.data.review_counts,
});
});
seafileAPI.listRepoTags(repoID).then(res => {
let usedRepoTags = [];
res.data.repo_tags.forEach(item => {
let usedRepoTag = new RepoTag(item);
if (usedRepoTag.fileCount > 0) {
usedRepoTags.push(usedRepoTag);
}
});
this.setState({usedRepoTags: usedRepoTags});
});
this.updateUsedRepoTags();
seafileAPI.getRepoInfo(repoID).then(res => {
let repoInfo = new RepoInfo(res.data);
this.setState({
@@ -178,8 +169,17 @@ class DirView extends React.Component {
});
}
updateUsedRepoTags = (newUsedRepoTags) => {
this.setState({usedRepoTags: newUsedRepoTags});
updateUsedRepoTags = () => {
seafileAPI.listRepoTags(this.props.repoID).then(res => {
let usedRepoTags = [];
res.data.repo_tags.forEach(item => {
let usedRepoTag = new RepoTag(item);
if (usedRepoTag.fileCount > 0) {
usedRepoTags.push(usedRepoTag);
}
});
this.setState({usedRepoTags: usedRepoTags});
});
}
updateReadmeMarkdown = (direntList) => {
@@ -487,16 +487,7 @@ class DirView extends React.Component {
this.updateDirent(dirent, 'file_tags', fileTags);
});
seafileAPI.listRepoTags(repoID).then(res => {
let usedRepoTags = [];
res.data.repo_tags.forEach(item => {
let usedRepoTag = new RepoTag(item);
if (usedRepoTag.fileCount > 0) {
usedRepoTags.push(usedRepoTag);
}
});
this.updateUsedRepoTags(usedRepoTags);
});
this.updateUsedRepoTags();
}
onMenuClick = () => {
@@ -754,6 +745,7 @@ class DirView extends React.Component {
readmeMarkdown={this.state.readmeMarkdown}
draftCounts={this.state.draftCounts}
reviewCounts={this.state.reviewCounts}
updateUsedRepoTags={this.updateUsedRepoTags}
/>
);
}

View File

@@ -17,6 +17,7 @@ const propTypes = {
readmeMarkdown: PropTypes.object,
draftCounts: PropTypes.number,
reviewCounts: PropTypes.number,
updateUsedRepoTags: PropTypes.func.isRequired,
};
class RepoInfoBar extends React.Component {
@@ -123,6 +124,7 @@ class RepoInfoBar extends React.Component {
currentTag={this.state.currentTag}
onClose={this.onCloseDialog}
toggleCancel={this.onListTaggedFiles}
updateUsedRepoTags={this.props.updateUsedRepoTags}
/>
</ModalPortal>
)}

View File

@@ -71,6 +71,7 @@ const propTypes = {
readmeMarkdown: PropTypes.object,
draftCounts: PropTypes.number,
reviewCounts: PropTypes.number,
updateUsedRepoTags: PropTypes.func.isRequired,
};
class MainPanel extends Component {
@@ -261,6 +262,7 @@ class MainPanel extends Component {
readmeMarkdown={this.props.readmeMarkdown}
draftCounts={this.props.draftCounts}
reviewCounts={this.props.reviewCounts}
updateUsedRepoTags={this.props.updateUsedRepoTags}
/>
)}
<DirentListView

View File

@@ -149,16 +149,7 @@ class Wiki extends Component {
collabServer.watchRepo(repoID, this.onRepoUpdateEvent);
// list used FileTags
seafileAPI.listRepoTags(repoID).then(res => {
let usedRepoTags = [];
res.data.repo_tags.forEach(item => {
let usedRepoTag = new RepoTag(item);
if (usedRepoTag.fileCount > 0) {
usedRepoTags.push(usedRepoTag);
}
});
this.setState({usedRepoTags: usedRepoTags});
});
this.updateUsedRepoTags();
// list draft counts and revierw counts
seafileAPI.getRepoDraftReviewCounts(repoID).then(res => {
@@ -325,8 +316,17 @@ class Wiki extends Component {
}
}
updateUsedRepoTags = (newUsedRepoTags) => {
this.setState({usedRepoTags: newUsedRepoTags});
updateUsedRepoTags = () => {
seafileAPI.listRepoTags(repoID).then(res => {
let usedRepoTags = [];
res.data.repo_tags.forEach(item => {
let usedRepoTag = new RepoTag(item);
if (usedRepoTag.fileCount > 0) {
usedRepoTags.push(usedRepoTag);
}
});
this.setState({usedRepoTags: usedRepoTags});
});
}
updateDirent = (dirent, paramKey, paramValue) => {
@@ -671,16 +671,7 @@ class Wiki extends Component {
this.updateDirent(dirent, 'file_tags', fileTags);
});
seafileAPI.listRepoTags(repoID).then(res => {
let usedRepoTags = [];
res.data.repo_tags.forEach(item => {
let usedRepoTag = new RepoTag(item);
if (usedRepoTag.fileCount > 0) {
usedRepoTags.push(usedRepoTag);
}
});
this.updateUsedRepoTags(usedRepoTags);
});
this.updateUsedRepoTags();
}
onFileUploadSuccess = (direntObject) => {
@@ -1128,6 +1119,7 @@ class Wiki extends Component {
readmeMarkdown={this.state.readmeMarkdown}
draftCounts={this.state.draftCounts}
reviewCounts={this.state.reviewCounts}
updateUsedRepoTags={this.updateUsedRepoTags}
/>
</div>
);

View File

@@ -39,6 +39,7 @@ def get_tagged_files(repo, repo_tag_id):
tagged_files = defaultdict(list)
for tagged_file_obj in tagged_file_objs:
file_tag_id = tagged_file_obj.pk
parent_path = tagged_file_obj.file_uuid.parent_path
filename = tagged_file_obj.file_uuid.filename
file_path = posixpath.join(parent_path, filename)
@@ -48,6 +49,10 @@ def get_tagged_files(repo, repo_tag_id):
if not file_obj:
exception = "Can't find tagged file. Repo_id: %s, Path: %s." % (repo.id, file_path)
logger.warning(exception)
tagged_file["file_deleted"] = True
tagged_file["file_tag_id"] = file_tag_id
tagged_file["filename"] = filename
tagged_files["tagged_files"].append(tagged_file)
continue
tagged_file["parent_path"] = parent_path