2018-11-30 17:18:41 +08:00
|
|
|
import React, { Component, Fragment } from 'react';
|
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
2018-12-12 11:38:27 +08:00
|
|
|
import { gettext, loginUrl} from '../../utils/constants';
|
2018-12-03 16:21:09 +08:00
|
|
|
import CommonToolbar from '../../components/toolbar/common-toolbar';
|
|
|
|
import RepoViewToolbar from '../../components/toolbar/repo-view-toobar';
|
2018-12-12 15:34:54 +08:00
|
|
|
import LibDetail from '../../components/dirent-detail/lib-details';
|
2018-12-12 17:09:15 +08:00
|
|
|
import Content from './content';
|
2018-11-30 17:18:41 +08:00
|
|
|
|
|
|
|
class MyLibraries extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2018-12-12 15:34:54 +08:00
|
|
|
isShowDetails: false,
|
2018-11-30 17:18:41 +08:00
|
|
|
loading: true,
|
|
|
|
errorMsg: '',
|
2018-12-12 15:34:54 +08:00
|
|
|
items: [],
|
2018-11-30 17:18:41 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
seafileAPI.listRepos({type:'mine'}).then((res) => {
|
|
|
|
// res: {data: {...}, status: 200, statusText: "OK", headers: {…}, config: {…}, …}
|
|
|
|
this.setState({
|
|
|
|
loading: false,
|
|
|
|
items: res.data.repos
|
|
|
|
});
|
|
|
|
}).catch((error) => {
|
|
|
|
if (error.response) {
|
|
|
|
if (error.response.status == 403) {
|
|
|
|
this.setState({
|
|
|
|
loading: false,
|
|
|
|
errorMsg: gettext("Permission denied")
|
|
|
|
});
|
|
|
|
location.href = `${loginUrl}?next=${encodeURIComponent(location.href)}`;
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
loading: false,
|
|
|
|
errorMsg: gettext("Error")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
loading: false,
|
|
|
|
errorMsg: gettext("Please check the network.")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-07 10:36:59 +08:00
|
|
|
onCreateRepo = (repo) => {
|
|
|
|
seafileAPI.createMineRepo(repo).then((res) => {
|
2018-12-12 15:34:54 +08:00
|
|
|
let repo = res.data;
|
|
|
|
this.state.items.push(repo);
|
|
|
|
this.setState({items: this.state.items});
|
2018-12-07 10:36:59 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-12 15:34:54 +08:00
|
|
|
onTransferRepo = (repoID) => {
|
|
|
|
let items = this.state.items.filter(item => {
|
|
|
|
return item.repo_id !== repoID;
|
|
|
|
})
|
|
|
|
this.setState({items: items});
|
2018-12-07 02:46:47 +00:00
|
|
|
}
|
|
|
|
|
2018-12-12 15:34:54 +08:00
|
|
|
onRenameRepo = (repo, newName) => {
|
|
|
|
let items = this.state.items.map(item => {
|
|
|
|
if (item.repo_id === repo.repo_id) {
|
|
|
|
item.repo_name = newName;
|
2018-12-07 02:46:47 +00:00
|
|
|
}
|
2018-12-12 15:34:54 +08:00
|
|
|
return item;
|
|
|
|
});
|
|
|
|
this.setState({items: items});
|
|
|
|
}
|
|
|
|
|
|
|
|
onDeleteRepo = (repo) => {
|
2018-12-12 16:33:59 +08:00
|
|
|
let items = this.state.items.filter(item => {
|
2018-12-12 15:34:54 +08:00
|
|
|
return item.repo_id !== repo.repo_id;
|
|
|
|
});
|
|
|
|
this.setState({items: items});
|
|
|
|
}
|
|
|
|
|
|
|
|
onRepoDetails = (repo) => {
|
|
|
|
this.setState({
|
|
|
|
isShowDetails: true,
|
|
|
|
currentRepo: repo
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
closeDetails = () => {
|
|
|
|
this.setState({
|
|
|
|
isShowDetails: !this.state.isShowDetails
|
|
|
|
});
|
2018-12-07 02:46:47 +00:00
|
|
|
}
|
|
|
|
|
2018-11-30 17:18:41 +08:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Fragment>
|
2018-12-03 16:21:09 +08:00
|
|
|
<div className="main-panel-north">
|
2018-12-07 13:21:43 +08:00
|
|
|
<RepoViewToolbar onShowSidePanel={this.props.onShowSidePanel} onCreateRepo={this.onCreateRepo} libraryType={'mine'}/>
|
2018-12-03 16:21:09 +08:00
|
|
|
<CommonToolbar onSearchedClick={this.props.onSearchedClick} />
|
|
|
|
</div>
|
2018-12-12 15:34:54 +08:00
|
|
|
<div className="main-panel-center flex-row">
|
2018-11-30 17:18:41 +08:00
|
|
|
<div className="cur-view-container">
|
|
|
|
<div className="cur-view-path">
|
|
|
|
<h3 className="sf-heading">{gettext("My Libraries")}</h3>
|
|
|
|
</div>
|
|
|
|
<div className="cur-view-content">
|
2018-12-12 11:38:27 +08:00
|
|
|
<Content
|
2018-12-12 15:34:54 +08:00
|
|
|
loading={this.state.loading}
|
|
|
|
errorMsg={this.state.errorMsg}
|
|
|
|
items={this.state.items}
|
|
|
|
onDeleteRepo={this.onDeleteRepo}
|
|
|
|
onRenameRepo={this.onRenameRepo}
|
|
|
|
onTransferRepo={this.onTransferRepo}
|
|
|
|
onRepoDetails={this.onRepoDetails}
|
2018-12-12 11:38:27 +08:00
|
|
|
/>
|
2018-11-30 17:18:41 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-12-12 15:34:54 +08:00
|
|
|
{this.state.isShowDetails && (
|
|
|
|
<div className="cur-view-detail">
|
|
|
|
<LibDetail
|
|
|
|
currentRepo={this.state.currentRepo}
|
|
|
|
closeDetails={this.closeDetails}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2018-11-30 17:18:41 +08:00
|
|
|
</div>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MyLibraries;
|