1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-04 16:31:13 +00:00

revert files tags (#3132)

This commit is contained in:
Michael An
2019-03-19 10:38:05 +08:00
committed by Daniel Pan
parent 413f82b484
commit 2fdbf9e196
3 changed files with 34 additions and 154 deletions

View File

@@ -10,10 +10,8 @@ require('../../css/repo-tag.css');
const TagItemPropTypes = {
repoID: PropTypes.string.isRequired,
repoTag: PropTypes.object.isRequired,
filePath: PropTypes.string,
filesPath: PropTypes.array,
fileTagList: PropTypes.array,
multiFileTagList: PropTypes.array,
filePath: PropTypes.string.isRequired,
fileTagList: PropTypes.array.isRequired,
onEditFileTag: PropTypes.func.isRequired,
};
@@ -22,8 +20,7 @@ class TagItem extends React.Component {
constructor(props) {
super(props);
this.state = {
showSelectedTag: false,
freeze: false,
showSelectedTag: false
};
}
@@ -41,65 +38,25 @@ class TagItem extends React.Component {
getRepoTagIdList = () => {
let repoTagIdList = [];
if (this.props.fileTagList.length > 0) {
let fileTagList = this.props.fileTagList;
fileTagList.map((fileTag) => {
repoTagIdList.push(fileTag.repo_tag_id);
});
return repoTagIdList;
} else {
const tagList = this.props.multiFileTagList;
const length = tagList.length;
let tagArray = [];
for (let i = 0; i< length; i++) {
for (let j = 0; j < tagList[i].length; j++) {
tagArray.push(tagList[i][j].repo_tag_id);
}
}
repoTagIdList = this.getCommonTag(tagArray, length);
return repoTagIdList;
}
}
getCommonTag = (filesTags, filesNumber) => {
let hash = {};
let tagNumber = 1;
let commonTags = [];
for (let i = 0, len = filesTags.length; i < len; i++) {
let filesTag = filesTags[i];
if (!hash[filesTag]) {
hash[filesTag] = 1;
} else{
hash[filesTag]++;
}
if (hash[filesTag] == tagNumber) {
if (tagNumber === filesNumber) {
commonTags.push(filesTag);
}
} else if (hash[filesTag] > tagNumber) {
tagNumber = hash[filesTag];
if (tagNumber === filesNumber) {
commonTags.push(filesTag);
}
}
}
return commonTags;
}
onEditFileTag = () => {
if (this.state.freeze) return;
let { repoID, repoTag, filePath, filesPath, fileTagList } = this.props;
this.setState({ freeze: true });
if (filesPath.length === 1) {
let { repoID, repoTag, filePath } = this.props;
let repoTagIdList = this.getRepoTagIdList();
if (repoTagIdList.indexOf(repoTag.id) === -1) {
seafileAPI.addFileTag(repoID, filePath, repoTag.id).then(() => {
let id = repoTag.id;
seafileAPI.addFileTag(repoID, filePath, id).then(() => {
repoTagIdList = this.getRepoTagIdList();
this.props.onEditFileTag();
this.setState({ freeze: false });
});
} else {
let fileTag = null;
let fileTagList = this.props.fileTagList;
for(let i = 0; i < fileTagList.length; i++) {
if (fileTagList[i].repo_tag_id === repoTag.id) {
fileTag = fileTagList[i];
@@ -109,36 +66,8 @@ class TagItem extends React.Component {
seafileAPI.deleteFileTag(repoID, fileTag.id).then(() => {
repoTagIdList = this.getRepoTagIdList();
this.props.onEditFileTag();
this.setState({ freeze: false });
});
}
} else {
this.onEditFilesTag();
}
}
onEditFilesTag = () => {
let { repoID, repoTag, filesPath, multiFileTagList } = this.props;
let repoTagIdList = this.getRepoTagIdList();
if (repoTagIdList.indexOf(repoTag.id) === -1) {
for (let i = 0, length = filesPath.length; i < length; i++) {
seafileAPI.addFileTag(repoID, filesPath[i], repoTag.id).then(() => {
this.props.onEditFileTag();
this.setState({ freeze: false });
});
}
} else {
for (let i = 0, len = multiFileTagList.length; i < len; i++) {
for (let j = 0, length = multiFileTagList[i].length; j < length; j++) {
if (multiFileTagList[i][j].repo_tag_id === repoTag.id) {
seafileAPI.deleteFileTag(repoID, multiFileTagList[i][j].file_tag_id).then(() => {
this.props.onEditFileTag();
this.setState({ freeze: false });
});
}
}
}
}
}
render() {
@@ -164,10 +93,8 @@ TagItem.propTypes = TagItemPropTypes;
const propTypes = {
repoID: PropTypes.string.isRequired,
filePath: PropTypes.string,
filesPath: PropTypes.array,
fileTagList: PropTypes.array,
multiFileTagList: PropTypes.array,
filePath: PropTypes.string.isRequired,
fileTagList: PropTypes.array.isRequired,
onFileTagChanged: PropTypes.func.isRequired,
toggleCancel: PropTypes.func.isRequired,
};
@@ -220,9 +147,7 @@ class EditFileTagDialog extends React.Component {
repoTag={repoTag}
repoID={this.props.repoID}
filePath={this.props.filePath}
filesPath={this.props.filesPath}
fileTagList={this.props.fileTagList}
multiFileTagList={this.props.multiFileTagList}
onEditFileTag={this.onEditFileTag}
/>
);

View File

@@ -38,14 +38,8 @@ class DirentMenu extends React.Component {
menuList.splice(2, 1);
}
}
} else if (length > 1) {
menuList = ['Tags'];
for (let i = 0; i < length; i++) {
if (dirents[i].type === 'dir') {
} else {
menuList = [];
break;
}
}
}
this.setState({
menuList: menuList,

View File

@@ -120,7 +120,7 @@ class MutipleDirOperationToolbar extends React.Component {
});
break;
case 'Tags':
this.listFilesTags(dirents);
this.listFileTags(dirent);
break;
case 'Details':
this.props.showDirentDetail();
@@ -239,18 +239,6 @@ class MutipleDirOperationToolbar extends React.Component {
});
}
listFilesTags = (dirents) => {
if (dirents.length === 1) {
this.listFileTags(dirents[0]);
} else if (dirents.length > 1) {
this.listMultiFileTags(dirents);
}
this.setState({
showLibContentViewDialogs: true,
showEditFileTagDialog: true,
});
}
listFileTags = (dirent) => {
let filePath = this.getDirentPath(dirent);
seafileAPI.listFileTags(this.props.repoID, filePath).then(res => {
@@ -259,30 +247,14 @@ class MutipleDirOperationToolbar extends React.Component {
fileTagList[i].id = fileTagList[i].file_tag_id;
}
this.setState({
fileTagList: fileTagList
fileTagList: fileTagList,
showLibContentViewDialogs: true,
showEditFileTagDialog: true,
});
});
}
listMultiFileTags = (dirents) => {
let multiFileTagList = [];
let len = dirents.length;
for (let j = 0; j < len; j++) {
seafileAPI.listFileTags(this.props.repoID, this.getDirentPath(dirents[j])).then(res => {
let fileTagList = res.data.file_tags;
for (let i = 0, length = fileTagList.length; i < length; i++) {
fileTagList[i].id = fileTagList[i].file_tag_id;
}
multiFileTagList.push(fileTagList);
});
this.setState({
multiFileTagList: multiFileTagList
});
}
}
onMenuFileTagChanged = () => {
this.listMultiFileTags(this.props.selectedDirentList);
this.listFileTags(this.props.selectedDirentList[0]);
let length = this.props.selectedDirentList.length;
for (let i = 0; i < length; i++) {
@@ -312,14 +284,6 @@ class MutipleDirOperationToolbar extends React.Component {
render() {
const { repoID } = this.props;
let direntPath = this.getDirentPath(this.props.selectedDirentList[0]);
let direntsPath = [];
if (this.state.showLibContentViewDialogs && this.props.selectedDirentList.length > 0) {
for (let i = 0; i < this.props.selectedDirentList.length; i++) {
let newDirentPath = this.getDirentPath(this.props.selectedDirentList[i]);
direntsPath.push(newDirentPath);
}
}
return (
<Fragment>
<div className="d-flex">
@@ -386,12 +350,9 @@ class MutipleDirOperationToolbar extends React.Component {
<EditFileTagDialog
repoID={repoID}
filePath={direntPath}
filesPath={direntsPath}
fileTagList={this.state.fileTagList}
multiFileTagList={this.state.multiFileTagList}
toggleCancel={this.toggleCancel}
onFileTagChanged={this.onMenuFileTagChanged}
selectedDirentList={this.props.selectedDirentList}
/>
</ModalPortal>
}