2018-12-10 13:33:32 +08:00
|
|
|
import React, { Component, Fragment } from 'react';
|
2019-04-22 18:21:25 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2019-04-17 10:34:43 +08:00
|
|
|
import { Button } from 'reactstrap';
|
2019-05-29 11:48:00 +08:00
|
|
|
import MediaQuery from 'react-responsive';
|
2018-12-08 00:01:23 +08:00
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
2019-12-05 15:45:16 +08:00
|
|
|
import { gettext } from '../../utils/constants';
|
|
|
|
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';
|
2018-12-26 16:27:15 +08:00
|
|
|
import CommonToolbar from '../../components/toolbar/common-toolbar';
|
2018-12-10 13:33:32 +08:00
|
|
|
import NewWikiDialog from '../../components/dialog/new-wiki-dialog';
|
|
|
|
import WikiSelectDialog from '../../components/dialog/wiki-select-dialog';
|
2018-12-11 08:42:30 +08:00
|
|
|
import WikiListView from '../../components/wiki-list-view/wiki-list-view';
|
2018-12-08 00:01:23 +08:00
|
|
|
|
2019-04-22 18:21:25 +08:00
|
|
|
const propTypes = {
|
|
|
|
onShowSidePanel: PropTypes.func.isRequired,
|
|
|
|
onSearchedClick: PropTypes.func.isRequired,
|
|
|
|
};
|
2018-12-08 00:01:23 +08:00
|
|
|
|
|
|
|
class Wikis extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
loading: true,
|
|
|
|
errorMsg: '',
|
|
|
|
wikis: [],
|
2018-12-11 13:44:09 +08:00
|
|
|
isShowAddWikiMenu: false,
|
2018-12-08 00:01:23 +08:00
|
|
|
isShowSelectDialog: false,
|
|
|
|
isShowCreateDialog: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.getWikis();
|
|
|
|
}
|
|
|
|
|
|
|
|
getWikis = () => {
|
|
|
|
seafileAPI.listWikis().then(res => {
|
|
|
|
this.setState({
|
|
|
|
loading: false,
|
2019-12-05 15:45:16 +08:00
|
|
|
wikis: res.data.data
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-11 13:22:52 +08:00
|
|
|
clickMenuToggle = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
this.onMenuToggle();
|
2018-12-08 00:01:23 +08:00
|
|
|
}
|
|
|
|
|
2018-12-11 13:22:52 +08:00
|
|
|
onMenuToggle = () => {
|
2018-12-11 13:44:09 +08:00
|
|
|
this.setState({isShowAddWikiMenu: !this.state.isShowAddWikiMenu});
|
2018-12-08 00:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onSelectToggle = () => {
|
2018-12-11 13:44:09 +08:00
|
|
|
this.setState({isShowSelectDialog: !this.state.isShowSelectDialog});
|
2018-12-08 00:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onCreateToggle = () => {
|
2018-12-11 13:44:09 +08:00
|
|
|
this.setState({isShowCreateDialog: !this.state.isShowCreateDialog});
|
2018-12-08 00:01:23 +08:00
|
|
|
}
|
|
|
|
|
2019-04-17 10:34:43 +08:00
|
|
|
addWiki = (repoID) => {
|
|
|
|
seafileAPI.addWiki(repoID).then((res) => {
|
2018-12-08 00:01:23 +08:00
|
|
|
this.state.wikis.push(res.data);
|
2018-12-11 13:44:09 +08:00
|
|
|
this.setState({wikis: this.state.wikis});
|
2018-12-08 00:01:23 +08:00
|
|
|
}).catch((error) => {
|
|
|
|
if(error.response) {
|
|
|
|
let errorMsg = error.response.data.error_msg;
|
2018-12-11 11:20:40 +08:00
|
|
|
toaster.danger(errorMsg);
|
2018-12-08 00:01:23 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-08 11:40:28 +08:00
|
|
|
renameWiki = (wiki, newName) => {
|
|
|
|
seafileAPI.renameWiki(wiki.slug, newName).then((res) => {
|
|
|
|
let wikis = this.state.wikis.map((item) => {
|
|
|
|
if (item.name === wiki.name) {
|
|
|
|
item = res.data;
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
});
|
2018-12-11 11:20:40 +08:00
|
|
|
this.setState({wikis: wikis});
|
2018-12-08 11:40:28 +08:00
|
|
|
}).catch((error) => {
|
|
|
|
if(error.response) {
|
|
|
|
let errorMsg = error.response.data.error_msg;
|
2018-12-11 11:20:40 +08:00
|
|
|
toaster.danger(errorMsg);
|
2018-12-08 11:40:28 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-08 00:01:23 +08:00
|
|
|
deleteWiki = (wiki) => {
|
|
|
|
seafileAPI.deleteWiki(wiki.slug).then(() => {
|
2018-12-11 11:20:40 +08:00
|
|
|
let wikis = this.state.wikis.filter(item => {
|
|
|
|
return item.name !== wiki.name;
|
2018-12-08 00:01:23 +08:00
|
|
|
});
|
2018-12-11 11:20:40 +08:00
|
|
|
this.setState({wikis: wikis});
|
2018-12-08 00:01:23 +08:00
|
|
|
}).catch((error) => {
|
|
|
|
if(error.response) {
|
|
|
|
let errorMsg = error.response.data.error_msg;
|
2018-12-11 11:20:40 +08:00
|
|
|
toaster.danger(errorMsg);
|
2018-12-08 00:01:23 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2018-12-10 13:33:32 +08:00
|
|
|
<Fragment>
|
2019-02-20 11:54:25 +08:00
|
|
|
<div className="main-panel-north border-left-show">
|
|
|
|
<div className="cur-view-toolbar">
|
2018-12-26 16:27:15 +08:00
|
|
|
<span className="sf2-icon-menu side-nav-toggle hidden-md-up d-md-none" title="Side Nav Menu" onClick={this.props.onShowSidePanel}></span>
|
|
|
|
<div className="operation">
|
2019-10-15 10:15:04 +08:00
|
|
|
<Fragment>
|
2019-05-29 11:48:00 +08:00
|
|
|
<MediaQuery query="(min-width: 768px)">
|
|
|
|
<Button className="btn btn-secondary operation-item" onClick={this.onSelectToggle}>{gettext('Publish a Library')}</Button>
|
|
|
|
</MediaQuery>
|
|
|
|
<MediaQuery query="(max-width: 767.8px)">
|
2019-07-22 20:26:08 +08:00
|
|
|
<span className="sf2-icon-plus mobile-toolbar-icon" title={gettext('Publish a Library')} onClick={this.onSelectToggle}></span>
|
2019-05-29 11:48:00 +08:00
|
|
|
</MediaQuery>
|
2019-10-15 10:15:04 +08:00
|
|
|
</Fragment>
|
2018-12-26 16:27:15 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<CommonToolbar onSearchedClick={this.props.onSearchedClick} />
|
|
|
|
</div>
|
|
|
|
<div className="main-panel-center">
|
|
|
|
<div className="cur-view-container" id="wikis">
|
|
|
|
<div className="cur-view-path">
|
|
|
|
<div className="path-container">
|
2019-07-19 23:50:22 +08:00
|
|
|
<h3 className="sf-heading m-0">{gettext('Published Libraries')}</h3>
|
2018-12-08 00:01:23 +08:00
|
|
|
</div>
|
2018-12-10 13:33:32 +08:00
|
|
|
</div>
|
|
|
|
<div className="cur-view-content">
|
|
|
|
{(this.state.loading || this.state.wikis.length !== 0) &&
|
2018-12-11 08:42:30 +08:00
|
|
|
<WikiListView
|
2018-12-10 13:33:32 +08:00
|
|
|
data={this.state}
|
|
|
|
renameWiki={this.renameWiki}
|
|
|
|
deleteWiki={this.deleteWiki}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
{(!this.state.loading && this.state.wikis.length === 0) &&
|
2019-06-10 17:30:10 +08:00
|
|
|
<EmptyTip>
|
2019-05-10 15:05:21 +08:00
|
|
|
<h2>{gettext('You do not have any public library')}</h2>
|
|
|
|
<p>{gettext('Public libraries are for publishing your contents in an organized way.')}</p>
|
2019-06-10 17:30:10 +08:00
|
|
|
</EmptyTip>
|
2018-12-10 13:33:32 +08:00
|
|
|
}
|
|
|
|
</div>
|
2018-12-08 00:01:23 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-12-11 13:44:09 +08:00
|
|
|
{this.state.isShowCreateDialog && (
|
2018-12-10 13:33:32 +08:00
|
|
|
<ModalPortal>
|
|
|
|
<NewWikiDialog
|
|
|
|
toggleCancel={this.onCreateToggle}
|
|
|
|
addWiki={this.addWiki}
|
|
|
|
/>
|
|
|
|
</ModalPortal>
|
2018-12-11 13:44:09 +08:00
|
|
|
)}
|
|
|
|
{this.state.isShowSelectDialog && (
|
2018-12-10 13:33:32 +08:00
|
|
|
<ModalPortal>
|
|
|
|
<WikiSelectDialog
|
|
|
|
toggleCancel={this.onSelectToggle}
|
|
|
|
addWiki={this.addWiki}
|
|
|
|
/>
|
|
|
|
</ModalPortal>
|
2018-12-11 13:44:09 +08:00
|
|
|
)}
|
2018-12-10 13:33:32 +08:00
|
|
|
</Fragment>
|
2018-12-08 00:01:23 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-22 18:21:25 +08:00
|
|
|
Wikis.propTypes = propTypes;
|
|
|
|
|
2018-12-08 00:01:23 +08:00
|
|
|
export default Wikis;
|