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 11:38:27 +08:00
|
|
|
import Content from '../../components/mylib-repo-list-view/content';
|
2018-11-30 17:18:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MyLibraries extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
loading: true,
|
|
|
|
errorMsg: '',
|
|
|
|
items: []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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-07 10:42:47 +08:00
|
|
|
//todo update repoList
|
2018-12-07 10:36:59 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-07 02:46:47 +00:00
|
|
|
toggleTransferSubmit = (repoID) => {
|
|
|
|
this.setState({
|
|
|
|
items: this.state.items.filter(item => item.repo_id !== repoID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
renameRepo = (repoID, newName) => {
|
|
|
|
let array = this.state.items;
|
2018-12-10 06:29:30 +00:00
|
|
|
for (var i=0; i < array.length; i++) {
|
|
|
|
if (array[i].repo_id === repoID) {
|
2018-12-07 02:46:47 +00:00
|
|
|
array[i].repo_name=newName;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-12-12 11:38:27 +08:00
|
|
|
this.setState({items: array});
|
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-11-30 17:18:41 +08:00
|
|
|
<div className="main-panel-center">
|
|
|
|
<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
|
|
|
|
data={this.state}
|
|
|
|
toggleTransferSubmit={this.toggleTransferSubmit}
|
|
|
|
renameRepo={this.renameRepo}
|
|
|
|
/>
|
2018-11-30 17:18:41 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MyLibraries;
|