1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-09 19:01:42 +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, repoID: PropTypes.string.isRequired,
currentTag: PropTypes.object.isRequired, currentTag: PropTypes.object.isRequired,
toggleCancel: PropTypes.func.isRequired, toggleCancel: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired onClose: PropTypes.func.isRequired,
updateUsedRepoTags: PropTypes.func.isRequired,
}; };
class ListTaggedFilesDialog extends React.Component { 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() { componentDidMount() {
this.getTaggedFiles(); this.getTaggedFiles();
} }
@@ -50,23 +60,21 @@ class ListTaggedFilesDialog extends React.Component {
<table> <table>
<thead> <thead>
<tr> <tr>
<th width='50%' className="ellipsis">{gettext('Name')}</th> <th width='45%' className="ellipsis">{gettext('Name')}</th>
<th width='25%'>{gettext('Size')}</th> <th width='27%'>{gettext('Size')}</th>
<th width='25%'>{gettext('Last Update')}</th> <th width='18%'>{gettext('Last Update')}</th>
<th width='10%'></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{taggedFileList.map((taggedFile, index) => { {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 ( return (
<tr key={index}> <TaggedFile
<td className="name"> key={index}
<a href={href} target='_blank'>{taggedFile.filename}</a> repoID={this.props.repoID}
</td> taggedFile={taggedFile}
<td>{Utils.bytesToSize(taggedFile.size)}</td> onDeleteTaggedFile={this.onDeleteTaggedFile}
<td>{moment.unix(taggedFile.mtime).fromNow()}</td> />
</tr>
); );
})} })}
</tbody> </tbody>
@@ -83,3 +91,54 @@ class ListTaggedFilesDialog extends React.Component {
ListTaggedFilesDialog.propTypes = propTypes; ListTaggedFilesDialog.propTypes = propTypes;
export default ListTaggedFilesDialog; 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, readmeMarkdown: PropTypes.object,
draftCounts: PropTypes.number, draftCounts: PropTypes.number,
reviewCounts: PropTypes.number, reviewCounts: PropTypes.number,
updateUsedRepoTags: PropTypes.func.isRequired,
}; };
class DirPanel extends React.Component { class DirPanel extends React.Component {
@@ -211,6 +212,7 @@ class DirPanel extends React.Component {
readmeMarkdown={this.props.readmeMarkdown} readmeMarkdown={this.props.readmeMarkdown}
draftCounts={this.props.draftCounts} draftCounts={this.props.draftCounts}
reviewCounts={this.props.reviewCounts} reviewCounts={this.props.reviewCounts}
updateUsedRepoTags={this.props.updateUsedRepoTags}
/> />
)} )}
<DirentListView <DirentListView

View File

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

View File

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

View File

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

View File

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

View File

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