mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-05 08:53:14 +00:00
revert files tags (#3132)
This commit is contained in:
@@ -10,10 +10,8 @@ require('../../css/repo-tag.css');
|
|||||||
const TagItemPropTypes = {
|
const TagItemPropTypes = {
|
||||||
repoID: PropTypes.string.isRequired,
|
repoID: PropTypes.string.isRequired,
|
||||||
repoTag: PropTypes.object.isRequired,
|
repoTag: PropTypes.object.isRequired,
|
||||||
filePath: PropTypes.string,
|
filePath: PropTypes.string.isRequired,
|
||||||
filesPath: PropTypes.array,
|
fileTagList: PropTypes.array.isRequired,
|
||||||
fileTagList: PropTypes.array,
|
|
||||||
multiFileTagList: PropTypes.array,
|
|
||||||
onEditFileTag: PropTypes.func.isRequired,
|
onEditFileTag: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -22,8 +20,7 @@ class TagItem extends React.Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
showSelectedTag: false,
|
showSelectedTag: false
|
||||||
freeze: false,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,65 +38,25 @@ class TagItem extends React.Component {
|
|||||||
|
|
||||||
getRepoTagIdList = () => {
|
getRepoTagIdList = () => {
|
||||||
let repoTagIdList = [];
|
let repoTagIdList = [];
|
||||||
if (this.props.fileTagList.length > 0) {
|
|
||||||
let fileTagList = this.props.fileTagList;
|
let fileTagList = this.props.fileTagList;
|
||||||
fileTagList.map((fileTag) => {
|
fileTagList.map((fileTag) => {
|
||||||
repoTagIdList.push(fileTag.repo_tag_id);
|
repoTagIdList.push(fileTag.repo_tag_id);
|
||||||
});
|
});
|
||||||
return repoTagIdList;
|
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 = () => {
|
onEditFileTag = () => {
|
||||||
if (this.state.freeze) return;
|
let { repoID, repoTag, filePath } = this.props;
|
||||||
let { repoID, repoTag, filePath, filesPath, fileTagList } = this.props;
|
|
||||||
this.setState({ freeze: true });
|
|
||||||
if (filesPath.length === 1) {
|
|
||||||
let repoTagIdList = this.getRepoTagIdList();
|
let repoTagIdList = this.getRepoTagIdList();
|
||||||
if (repoTagIdList.indexOf(repoTag.id) === -1) {
|
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();
|
repoTagIdList = this.getRepoTagIdList();
|
||||||
this.props.onEditFileTag();
|
this.props.onEditFileTag();
|
||||||
this.setState({ freeze: false });
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let fileTag = null;
|
let fileTag = null;
|
||||||
|
let fileTagList = this.props.fileTagList;
|
||||||
for(let i = 0; i < fileTagList.length; i++) {
|
for(let i = 0; i < fileTagList.length; i++) {
|
||||||
if (fileTagList[i].repo_tag_id === repoTag.id) {
|
if (fileTagList[i].repo_tag_id === repoTag.id) {
|
||||||
fileTag = fileTagList[i];
|
fileTag = fileTagList[i];
|
||||||
@@ -109,36 +66,8 @@ class TagItem extends React.Component {
|
|||||||
seafileAPI.deleteFileTag(repoID, fileTag.id).then(() => {
|
seafileAPI.deleteFileTag(repoID, fileTag.id).then(() => {
|
||||||
repoTagIdList = this.getRepoTagIdList();
|
repoTagIdList = this.getRepoTagIdList();
|
||||||
this.props.onEditFileTag();
|
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() {
|
render() {
|
||||||
@@ -164,10 +93,8 @@ TagItem.propTypes = TagItemPropTypes;
|
|||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
repoID: PropTypes.string.isRequired,
|
repoID: PropTypes.string.isRequired,
|
||||||
filePath: PropTypes.string,
|
filePath: PropTypes.string.isRequired,
|
||||||
filesPath: PropTypes.array,
|
fileTagList: PropTypes.array.isRequired,
|
||||||
fileTagList: PropTypes.array,
|
|
||||||
multiFileTagList: PropTypes.array,
|
|
||||||
onFileTagChanged: PropTypes.func.isRequired,
|
onFileTagChanged: PropTypes.func.isRequired,
|
||||||
toggleCancel: PropTypes.func.isRequired,
|
toggleCancel: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
@@ -220,9 +147,7 @@ class EditFileTagDialog extends React.Component {
|
|||||||
repoTag={repoTag}
|
repoTag={repoTag}
|
||||||
repoID={this.props.repoID}
|
repoID={this.props.repoID}
|
||||||
filePath={this.props.filePath}
|
filePath={this.props.filePath}
|
||||||
filesPath={this.props.filesPath}
|
|
||||||
fileTagList={this.props.fileTagList}
|
fileTagList={this.props.fileTagList}
|
||||||
multiFileTagList={this.props.multiFileTagList}
|
|
||||||
onEditFileTag={this.onEditFileTag}
|
onEditFileTag={this.onEditFileTag}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@@ -38,14 +38,8 @@ class DirentMenu extends React.Component {
|
|||||||
menuList.splice(2, 1);
|
menuList.splice(2, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (length > 1) {
|
} else {
|
||||||
menuList = ['Tags'];
|
|
||||||
for (let i = 0; i < length; i++) {
|
|
||||||
if (dirents[i].type === 'dir') {
|
|
||||||
menuList = [];
|
menuList = [];
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
menuList: menuList,
|
menuList: menuList,
|
||||||
|
@@ -120,7 +120,7 @@ class MutipleDirOperationToolbar extends React.Component {
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'Tags':
|
case 'Tags':
|
||||||
this.listFilesTags(dirents);
|
this.listFileTags(dirent);
|
||||||
break;
|
break;
|
||||||
case 'Details':
|
case 'Details':
|
||||||
this.props.showDirentDetail();
|
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) => {
|
listFileTags = (dirent) => {
|
||||||
let filePath = this.getDirentPath(dirent);
|
let filePath = this.getDirentPath(dirent);
|
||||||
seafileAPI.listFileTags(this.props.repoID, filePath).then(res => {
|
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;
|
fileTagList[i].id = fileTagList[i].file_tag_id;
|
||||||
}
|
}
|
||||||
this.setState({
|
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 = () => {
|
onMenuFileTagChanged = () => {
|
||||||
this.listMultiFileTags(this.props.selectedDirentList);
|
|
||||||
this.listFileTags(this.props.selectedDirentList[0]);
|
this.listFileTags(this.props.selectedDirentList[0]);
|
||||||
let length = this.props.selectedDirentList.length;
|
let length = this.props.selectedDirentList.length;
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
@@ -312,14 +284,6 @@ class MutipleDirOperationToolbar extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
const { repoID } = this.props;
|
const { repoID } = this.props;
|
||||||
let direntPath = this.getDirentPath(this.props.selectedDirentList[0]);
|
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 (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<div className="d-flex">
|
<div className="d-flex">
|
||||||
@@ -386,12 +350,9 @@ class MutipleDirOperationToolbar extends React.Component {
|
|||||||
<EditFileTagDialog
|
<EditFileTagDialog
|
||||||
repoID={repoID}
|
repoID={repoID}
|
||||||
filePath={direntPath}
|
filePath={direntPath}
|
||||||
filesPath={direntsPath}
|
|
||||||
fileTagList={this.state.fileTagList}
|
fileTagList={this.state.fileTagList}
|
||||||
multiFileTagList={this.state.multiFileTagList}
|
|
||||||
toggleCancel={this.toggleCancel}
|
toggleCancel={this.toggleCancel}
|
||||||
onFileTagChanged={this.onMenuFileTagChanged}
|
onFileTagChanged={this.onMenuFileTagChanged}
|
||||||
selectedDirentList={this.props.selectedDirentList}
|
|
||||||
/>
|
/>
|
||||||
</ModalPortal>
|
</ModalPortal>
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user