2018-12-10 13:33:32 +08:00
|
|
|
import React, { Component, Fragment } from 'react';
|
2024-07-15 17:23:23 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2024-06-17 10:19:27 +08:00
|
|
|
import { Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap';
|
2023-07-14 12:55:30 +08:00
|
|
|
import { gettext, canPublishRepo } from '../../utils/constants';
|
2019-12-05 15:45:16 +08:00
|
|
|
import { Utils } from '../../utils/utils';
|
2018-12-11 11:20:40 +08:00
|
|
|
import toaster from '../../components/toast';
|
2018-12-11 08:42:30 +08:00
|
|
|
import ModalPortal from '../../components/modal-portal';
|
2019-06-10 17:30:10 +08:00
|
|
|
import EmptyTip from '../../components/empty-tip';
|
2024-05-15 11:57:30 +08:00
|
|
|
import AddWikiDialog from '../../components/dialog/add-wiki-dialog';
|
|
|
|
import wikiAPI from '../../utils/wiki-api';
|
2024-05-29 20:28:46 +08:00
|
|
|
import WikiCardView from '../../components/wiki-card-view/wiki-card-view';
|
2024-07-25 17:28:55 +08:00
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
2024-11-07 11:38:36 +08:00
|
|
|
import { userAPI } from '../../utils/user-api';
|
|
|
|
import WikiConvertStatusDialog from '../../components/dialog/wiki-convert-status-dialog';
|
2024-07-25 17:28:55 +08:00
|
|
|
|
2018-12-08 00:01:23 +08:00
|
|
|
|
2024-07-15 17:23:23 +08:00
|
|
|
const propTypes = {
|
|
|
|
sidePanelRate: PropTypes.number,
|
|
|
|
isSidePanelFolded: PropTypes.bool,
|
|
|
|
};
|
|
|
|
|
2018-12-08 00:01:23 +08:00
|
|
|
class Wikis extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
loading: true,
|
|
|
|
errorMsg: '',
|
2024-09-20 16:04:35 +08:00
|
|
|
currentDeptID: '',
|
2018-12-08 00:01:23 +08:00
|
|
|
wikis: [],
|
2024-07-25 17:28:55 +08:00
|
|
|
groupWikis: [],
|
2018-12-11 13:44:09 +08:00
|
|
|
isShowAddWikiMenu: false,
|
2024-05-15 11:57:30 +08:00
|
|
|
isShowAddDialog: false,
|
2024-06-17 10:19:27 +08:00
|
|
|
isDropdownMenuShown: false,
|
2024-11-07 11:38:36 +08:00
|
|
|
isShowConvertStatusDialog: false,
|
2018-12-08 00:01:23 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.getWikis();
|
|
|
|
}
|
|
|
|
|
|
|
|
getWikis = () => {
|
2024-05-15 11:57:30 +08:00
|
|
|
let wikis = [];
|
2024-07-25 17:28:55 +08:00
|
|
|
let groupWikis = [];
|
2024-05-15 11:57:30 +08:00
|
|
|
wikiAPI.listWikis().then(res => {
|
|
|
|
wikis = wikis.concat(res.data.data);
|
|
|
|
wikis.map(wiki => {
|
|
|
|
return wiki['version'] = 'v1';
|
|
|
|
});
|
|
|
|
wikiAPI.listWikis2().then(res => {
|
2024-05-27 17:19:58 +08:00
|
|
|
let wikis2 = res.data.wikis;
|
2024-07-25 17:28:55 +08:00
|
|
|
groupWikis = res.data.group_wikis;
|
|
|
|
groupWikis.forEach(group => {
|
|
|
|
group.wiki_info.forEach(wiki => {
|
|
|
|
wiki.version = 'v2';
|
|
|
|
wiki.admins = group.group_admins;
|
|
|
|
});
|
|
|
|
});
|
2024-05-15 11:57:30 +08:00
|
|
|
wikis2.map(wiki => {
|
|
|
|
return wiki['version'] = 'v2';
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
loading: false,
|
2024-07-25 17:28:55 +08:00
|
|
|
wikis: wikis.concat(wikis2),
|
|
|
|
groupWikis: groupWikis
|
2024-05-15 11:57:30 +08:00
|
|
|
});
|
|
|
|
}).catch((error) => {
|
|
|
|
this.setState({
|
|
|
|
loading: false,
|
|
|
|
errorMsg: Utils.getErrorMsg(error, true) // true: show login tip if 403
|
|
|
|
});
|
|
|
|
});
|
2018-12-08 00:01:23 +08:00
|
|
|
}).catch((error) => {
|
2019-12-05 15:45:16 +08:00
|
|
|
this.setState({
|
|
|
|
loading: false,
|
|
|
|
errorMsg: Utils.getErrorMsg(error, true) // true: show login tip if 403
|
|
|
|
});
|
2018-12-08 00:01:23 +08:00
|
|
|
});
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2018-12-08 00:01:23 +08:00
|
|
|
|
2018-12-11 13:22:52 +08:00
|
|
|
clickMenuToggle = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
this.onMenuToggle();
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2018-12-08 00:01:23 +08:00
|
|
|
|
2018-12-11 13:22:52 +08:00
|
|
|
onMenuToggle = () => {
|
2024-06-17 10:19:27 +08:00
|
|
|
this.setState({ isShowAddWikiMenu: !this.state.isShowAddWikiMenu });
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2018-12-08 00:01:23 +08:00
|
|
|
|
2024-09-20 16:04:35 +08:00
|
|
|
toggelAddWikiDialog = (currentDeptID) => {
|
2024-06-17 10:19:27 +08:00
|
|
|
if (this.state.isShowAddDialog) {
|
|
|
|
this.setState({
|
|
|
|
isShowAddDialog: false,
|
2024-09-20 16:04:35 +08:00
|
|
|
currentDeptID: '',
|
2024-06-17 10:19:27 +08:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
isShowAddDialog: true,
|
2024-09-20 16:04:35 +08:00
|
|
|
currentDeptID
|
2024-06-17 10:19:27 +08:00
|
|
|
});
|
|
|
|
}
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2018-12-08 00:01:23 +08:00
|
|
|
|
2024-06-17 10:19:27 +08:00
|
|
|
addWiki = (wikiName, currentDeptID) => {
|
|
|
|
wikiAPI.addWiki2(wikiName, currentDeptID).then((res) => {
|
2024-05-15 11:57:30 +08:00
|
|
|
let wikis = this.state.wikis.slice(0);
|
2024-07-25 17:28:55 +08:00
|
|
|
let groupWikis = this.state.groupWikis;
|
2024-05-15 11:57:30 +08:00
|
|
|
let new_wiki = res.data;
|
|
|
|
new_wiki['version'] = 'v2';
|
2024-09-29 17:54:16 +08:00
|
|
|
new_wiki['admins'] = new_wiki.group_admins;
|
2024-07-25 17:28:55 +08:00
|
|
|
if (currentDeptID) {
|
|
|
|
groupWikis.filter(group => {
|
|
|
|
if (group.group_id === currentDeptID) {
|
|
|
|
group.wiki_info.push(new_wiki);
|
|
|
|
}
|
|
|
|
return group;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
wikis.push(new_wiki);
|
|
|
|
}
|
2024-06-17 10:19:27 +08:00
|
|
|
this.setState({
|
|
|
|
wikis,
|
2024-07-25 17:28:55 +08:00
|
|
|
currentDeptID: '',
|
2024-09-20 16:04:35 +08:00
|
|
|
groupWikis,
|
2024-06-17 10:19:27 +08:00
|
|
|
});
|
2018-12-08 00:01:23 +08:00
|
|
|
}).catch((error) => {
|
2024-05-15 11:57:30 +08:00
|
|
|
if (error.response) {
|
|
|
|
let errMessage = Utils.getErrorMsg(error);
|
|
|
|
toaster.danger(errMessage);
|
2018-12-08 00:01:23 +08:00
|
|
|
}
|
|
|
|
});
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2018-12-08 00:01:23 +08:00
|
|
|
|
2024-05-15 11:57:30 +08:00
|
|
|
deleteWiki = (wiki) => {
|
|
|
|
if (wiki.version === 'v1') {
|
|
|
|
wikiAPI.deleteWiki(wiki.id).then(() => {
|
|
|
|
let wikis = this.state.wikis.filter(item => {
|
2024-07-23 14:40:52 +08:00
|
|
|
return item.id !== wiki.id;
|
2024-05-15 11:57:30 +08:00
|
|
|
});
|
2024-07-25 17:28:55 +08:00
|
|
|
let groupWikis = this.state.groupWikis.filter(group => {
|
|
|
|
group.wiki_info = group.wiki_info.filter(item => item.name !== wiki.name);
|
|
|
|
return group;
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
wikis: wikis,
|
|
|
|
groupWikis: groupWikis,
|
|
|
|
});
|
2024-05-15 11:57:30 +08:00
|
|
|
}).catch((error) => {
|
2024-05-31 10:59:59 +08:00
|
|
|
if (error.response) {
|
2024-05-15 11:57:30 +08:00
|
|
|
let errorMsg = error.response.data.error_msg;
|
|
|
|
toaster.danger(errorMsg);
|
2018-12-08 11:40:28 +08:00
|
|
|
}
|
|
|
|
});
|
2024-05-15 11:57:30 +08:00
|
|
|
} else {
|
|
|
|
wikiAPI.deleteWiki2(wiki.id).then(() => {
|
|
|
|
let wikis = this.state.wikis.filter(item => {
|
2024-07-23 14:40:52 +08:00
|
|
|
return item.id !== wiki.id;
|
2024-05-15 11:57:30 +08:00
|
|
|
});
|
2024-07-25 17:28:55 +08:00
|
|
|
let groupWikis = this.state.groupWikis.filter(group => {
|
|
|
|
group.wiki_info = group.wiki_info.filter(item => item.name !== wiki.name);
|
|
|
|
return group;
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
wikis: wikis,
|
|
|
|
groupWikis: groupWikis,
|
|
|
|
});
|
2024-05-15 11:57:30 +08:00
|
|
|
}).catch((error) => {
|
2024-05-31 10:59:59 +08:00
|
|
|
if (error.response) {
|
|
|
|
let errorMsg = error.response.data.error_msg;
|
|
|
|
toaster.danger(errorMsg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-07-25 17:28:55 +08:00
|
|
|
leaveSharedWiki = (wiki) => {
|
|
|
|
if (!wiki.owner.includes('@seafile_group')) {
|
|
|
|
let options = {
|
|
|
|
'share_type': 'personal',
|
|
|
|
'from': wiki.owner
|
|
|
|
};
|
|
|
|
seafileAPI.leaveShareRepo(wiki.repo_id, options).then(res => {
|
|
|
|
let wikis = this.state.wikis.filter(item => {
|
|
|
|
return item.name !== wiki.name;
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
wikis: wikis,
|
|
|
|
});
|
|
|
|
}).catch((error) => {
|
|
|
|
let errorMsg = Utils.getErrorMsg(error, true);
|
|
|
|
toaster.danger(errorMsg);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
seafileAPI.leaveShareGroupOwnedRepo(wiki.repo_id).then(res => {
|
|
|
|
let wikis = this.state.wikis.filter(item => {
|
|
|
|
return item.name !== wiki.name;
|
|
|
|
});
|
|
|
|
this.setState({
|
|
|
|
wikis: wikis,
|
|
|
|
});
|
|
|
|
}).catch((error) => {
|
|
|
|
let errorMsg = Utils.getErrorMsg(error, true);
|
|
|
|
toaster.danger(errorMsg);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
unshareGroupWiki = (wiki, groupId) => {
|
|
|
|
seafileAPI.unshareRepoToGroup(wiki.repo_id, groupId).then(() => {
|
|
|
|
let groupWikis = this.state.groupWikis.map(group => {
|
|
|
|
if (group.group_id === groupId) {
|
|
|
|
return {
|
|
|
|
...group,
|
|
|
|
wiki_info: group.wiki_info.filter(item => item.name !== wiki.name)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return group;
|
|
|
|
});
|
|
|
|
this.setState({ groupWikis: groupWikis });
|
|
|
|
}).catch(error => {
|
|
|
|
let errMessage = Utils.getErrorMsg(error);
|
|
|
|
toaster.danger(errMessage);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2024-05-31 10:59:59 +08:00
|
|
|
renameWiki = (wiki, newName) => {
|
|
|
|
if (wiki.version === 'v1') {
|
|
|
|
wikiAPI.renameWiki(wiki.id, newName).then(() => {
|
|
|
|
let wikis = this.state.wikis.map(item => {
|
|
|
|
if (item.id === wiki.id && item.version === 'v1') {
|
|
|
|
item.name = newName;
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
});
|
2024-07-18 11:58:42 +08:00
|
|
|
this.setState({ wikis: wikis });
|
2024-05-31 10:59:59 +08:00
|
|
|
}).catch((error) => {
|
|
|
|
if (error.response) {
|
|
|
|
let errorMsg = error.response.data.error_msg;
|
|
|
|
toaster.danger(errorMsg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
wikiAPI.renameWiki2(wiki.id, newName).then(() => {
|
2024-07-25 17:28:55 +08:00
|
|
|
this.getWikis();
|
2024-05-31 10:59:59 +08:00
|
|
|
}).catch((error) => {
|
|
|
|
if (error.response) {
|
2024-05-15 11:57:30 +08:00
|
|
|
let errorMsg = error.response.data.error_msg;
|
|
|
|
toaster.danger(errorMsg);
|
|
|
|
}
|
2018-12-08 00:01:23 +08:00
|
|
|
});
|
2024-05-15 11:57:30 +08:00
|
|
|
}
|
2023-09-13 08:40:50 +08:00
|
|
|
};
|
2018-12-08 00:01:23 +08:00
|
|
|
|
2024-11-05 18:03:53 +08:00
|
|
|
convertWiki = (wiki, wikiName, departmentID) => {
|
2024-11-07 11:38:36 +08:00
|
|
|
let task_id = '';
|
|
|
|
this.setState({
|
|
|
|
isShowConvertStatusDialog: true,
|
|
|
|
});
|
2024-11-05 18:03:53 +08:00
|
|
|
wikiAPI.convertWiki(wiki.id, wikiName, departmentID).then((res) => {
|
2024-11-07 11:38:36 +08:00
|
|
|
task_id = res.data.task_id;
|
|
|
|
return userAPI.queryIOStatus(task_id);
|
|
|
|
}).then(res => {
|
|
|
|
if (res.data.is_finished === true) {
|
|
|
|
this.setState({
|
|
|
|
isShowConvertStatusDialog: false,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.queryConvertStatus(task_id);
|
|
|
|
}
|
2024-11-05 18:03:53 +08:00
|
|
|
}).catch((error) => {
|
2024-11-07 11:38:36 +08:00
|
|
|
this.setState({
|
|
|
|
isShowConvertStatusDialog: false
|
|
|
|
});
|
2024-11-05 18:03:53 +08:00
|
|
|
if (error.response) {
|
|
|
|
let errorMsg = error.response.data.error_msg;
|
|
|
|
toaster.danger(errorMsg);
|
|
|
|
}
|
|
|
|
});
|
2024-11-07 11:38:36 +08:00
|
|
|
this.getWikis();
|
|
|
|
};
|
|
|
|
|
|
|
|
onConvertStatusToggle = () => {
|
|
|
|
this.setState({
|
|
|
|
isShowConvertDialog: !this.state.isShowConvertStatusDialog,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
queryConvertStatus = (task_id) => {
|
|
|
|
userAPI.queryIOStatus(task_id).then(res => {
|
|
|
|
if (res.data.is_finished === true) {
|
|
|
|
this.setState({
|
|
|
|
isShowConvertStatusDialog: false
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.queryConvertStatus(task_id);
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
}).catch(err => {
|
|
|
|
this.setState({
|
|
|
|
isShowConvertStatusDialog: false
|
|
|
|
});
|
|
|
|
if (err.response) {
|
|
|
|
let errorMsg = err.response.data.error_msg;
|
|
|
|
toaster.danger(errorMsg);
|
|
|
|
}
|
|
|
|
});
|
2024-11-05 18:03:53 +08:00
|
|
|
};
|
|
|
|
|
2024-06-17 10:19:27 +08:00
|
|
|
toggleDropdownMenu = (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
this.setState({
|
|
|
|
isDropdownMenuShown: !this.state.isDropdownMenuShown
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-12-08 00:01:23 +08:00
|
|
|
render() {
|
|
|
|
return (
|
2018-12-10 13:33:32 +08:00
|
|
|
<Fragment>
|
2024-11-07 11:38:36 +08:00
|
|
|
{this.state.isShowConvertStatusDialog &&
|
|
|
|
<WikiConvertStatusDialog
|
|
|
|
toggle={this.onConvertStatusToggle}
|
|
|
|
/>
|
|
|
|
}
|
2024-05-15 11:57:30 +08:00
|
|
|
{this.state.isShowAddDialog &&
|
|
|
|
<ModalPortal>
|
2024-06-17 10:19:27 +08:00
|
|
|
<AddWikiDialog
|
|
|
|
toggleCancel={this.toggelAddWikiDialog}
|
|
|
|
addWiki={this.addWiki}
|
2024-09-20 16:04:35 +08:00
|
|
|
currentDeptID={this.state.currentDeptID}
|
2024-06-17 10:19:27 +08:00
|
|
|
/>
|
2024-05-15 11:57:30 +08:00
|
|
|
</ModalPortal>
|
|
|
|
}
|
2018-12-26 16:27:15 +08:00
|
|
|
<div className="main-panel-center">
|
|
|
|
<div className="cur-view-container" id="wikis">
|
|
|
|
<div className="cur-view-path">
|
|
|
|
<div className="path-container">
|
2024-05-06 17:09:47 +08:00
|
|
|
<h3 className="sf-heading m-0">{gettext('Wikis')}</h3>
|
2024-06-17 10:19:27 +08:00
|
|
|
{canPublishRepo &&
|
|
|
|
<Dropdown
|
|
|
|
direction="down"
|
|
|
|
className="add-wiki-dropdown"
|
|
|
|
isOpen={this.state.isDropdownMenuShown}
|
|
|
|
toggle={this.toggleDropdownMenu}
|
|
|
|
onMouseMove={(e) => {e.stopPropagation();}}
|
|
|
|
>
|
|
|
|
<DropdownToggle tag="i" className="px-1">
|
2024-06-21 12:07:58 +08:00
|
|
|
<span className="sf3-font sf3-font-down" aria-hidden="true"></span>
|
2024-06-17 10:19:27 +08:00
|
|
|
</DropdownToggle>
|
2024-08-22 09:47:58 +08:00
|
|
|
<DropdownMenu positionFixed={true}>
|
2024-06-17 10:19:27 +08:00
|
|
|
<DropdownItem onClick={() => {this.toggelAddWikiDialog();}}>{gettext('Add Wiki')}</DropdownItem>
|
|
|
|
</DropdownMenu>
|
|
|
|
</Dropdown>
|
|
|
|
}
|
2018-12-08 00:01:23 +08:00
|
|
|
</div>
|
2018-12-10 13:33:32 +08:00
|
|
|
</div>
|
2024-07-25 17:28:55 +08:00
|
|
|
{(this.state.loading || this.state.wikis.length !== 0 || this.state.groupWikis.length !== 0) &&
|
2024-05-29 20:28:46 +08:00
|
|
|
<div className="cur-view-content pb-4">
|
|
|
|
<WikiCardView
|
2018-12-10 13:33:32 +08:00
|
|
|
data={this.state}
|
|
|
|
deleteWiki={this.deleteWiki}
|
2024-07-25 17:28:55 +08:00
|
|
|
leaveSharedWiki={this.leaveSharedWiki}
|
|
|
|
unshareGroupWiki={this.unshareGroupWiki}
|
2024-05-31 10:59:59 +08:00
|
|
|
renameWiki={this.renameWiki}
|
2024-11-05 18:03:53 +08:00
|
|
|
convertWiki={this.convertWiki}
|
2024-06-17 10:19:27 +08:00
|
|
|
toggelAddWikiDialog={this.toggelAddWikiDialog}
|
2024-07-15 17:23:23 +08:00
|
|
|
sidePanelRate={this.props.sidePanelRate}
|
|
|
|
isSidePanelFolded={this.props.isSidePanelFolded}
|
2018-12-10 13:33:32 +08:00
|
|
|
/>
|
2024-05-29 20:28:46 +08:00
|
|
|
</div>
|
|
|
|
}
|
2024-07-25 17:28:55 +08:00
|
|
|
{(!this.state.loading && this.state.wikis.length === 0 && this.state.groupWikis.length === 0) &&
|
2024-05-29 20:28:46 +08:00
|
|
|
<div className="cur-view-content">
|
2024-10-12 13:48:47 +08:00
|
|
|
<EmptyTip
|
|
|
|
title={gettext('No Wikis')}
|
|
|
|
text={
|
|
|
|
<>
|
|
|
|
<p>{gettext('You do not have any Wikis yet.')}</p>
|
|
|
|
<p>{gettext('You can add a Wiki by clicking the "Add Wiki" item in the menu.')}</p>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
/>
|
2024-05-29 20:28:46 +08:00
|
|
|
</div>
|
|
|
|
}
|
2018-12-08 00:01:23 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-12-10 13:33:32 +08:00
|
|
|
</Fragment>
|
2018-12-08 00:01:23 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-15 17:23:23 +08:00
|
|
|
Wikis.propTypes = propTypes;
|
|
|
|
|
2018-12-08 00:01:23 +08:00
|
|
|
export default Wikis;
|