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-28 15:19:10 +08:00
|
|
|
import { Utils } from '../../utils/utils';
|
|
|
|
import Repo from '../../models/repo';
|
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-12-28 15:19:10 +08:00
|
|
|
sortBy: 'name', // 'name' or 'time'
|
|
|
|
sortOrder: 'asc' // 'asc' or 'desc'
|
2018-11-30 17:18:41 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2018-12-12 17:51:12 +08:00
|
|
|
seafileAPI.listRepos({type: 'mine'}).then((res) => {
|
2018-11-30 17:18:41 +08:00
|
|
|
// res: {data: {...}, status: 200, statusText: "OK", headers: {…}, config: {…}, …}
|
2018-12-28 15:19:10 +08:00
|
|
|
let repoList = res.data.repos.map((item) => {
|
|
|
|
return new Repo(item);
|
|
|
|
});
|
2018-11-30 17:18:41 +08:00
|
|
|
this.setState({
|
|
|
|
loading: false,
|
2018-12-28 15:19:10 +08:00
|
|
|
items: Utils.sortRepos(repoList, this.state.sortBy, this.state.sortOrder)
|
2018-11-30 17:18:41 +08:00
|
|
|
});
|
|
|
|
}).catch((error) => {
|
|
|
|
if (error.response) {
|
|
|
|
if (error.response.status == 403) {
|
|
|
|
this.setState({
|
|
|
|
loading: false,
|
2018-12-12 17:51:12 +08:00
|
|
|
errorMsg: gettext('Permission denied')
|
2018-11-30 17:18:41 +08:00
|
|
|
});
|
|
|
|
location.href = `${loginUrl}?next=${encodeURIComponent(location.href)}`;
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
loading: false,
|
2018-12-12 17:51:12 +08:00
|
|
|
errorMsg: gettext('Error')
|
2018-11-30 17:18:41 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
loading: false,
|
2018-12-12 17:51:12 +08:00
|
|
|
errorMsg: gettext('Please check the network.')
|
2018-11-30 17:18:41 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-07 10:36:59 +08:00
|
|
|
onCreateRepo = (repo) => {
|
2018-12-17 15:12:10 +08:00
|
|
|
let permission = repo.permission;
|
2018-12-07 10:36:59 +08:00
|
|
|
seafileAPI.createMineRepo(repo).then((res) => {
|
2018-12-17 15:12:10 +08:00
|
|
|
let repo = {
|
|
|
|
repo_id: res.data.repo_id,
|
|
|
|
repo_name: res.data.repo_name,
|
|
|
|
size: res.data.repo_size,
|
|
|
|
mtime: res.data.mtime,
|
|
|
|
owner_email: res.data.email,
|
|
|
|
encrypted: res.data.encrypted,
|
|
|
|
permission: permission,
|
|
|
|
};
|
2018-12-22 15:18:53 +08:00
|
|
|
this.state.items.unshift(repo);
|
2018-12-12 15:34:54 +08:00
|
|
|
this.setState({items: this.state.items});
|
2018-12-07 10:36:59 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-28 15:19:10 +08:00
|
|
|
sortItems = (sortBy, sortOrder) => {
|
|
|
|
this.setState({
|
|
|
|
sortBy: sortBy,
|
|
|
|
sortOrder: sortOrder,
|
|
|
|
items: Utils.sortRepos(this.state.items, sortBy, sortOrder)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-12 15:34:54 +08:00
|
|
|
onTransferRepo = (repoID) => {
|
|
|
|
let items = this.state.items.filter(item => {
|
|
|
|
return item.repo_id !== repoID;
|
2019-01-31 17:37:02 +08:00
|
|
|
});
|
2018-12-12 15:34:54 +08:00
|
|
|
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});
|
|
|
|
}
|
|
|
|
|
2019-01-17 17:05:08 +08:00
|
|
|
onItemClick = (repo) => {
|
|
|
|
if (this.state.isShowDetails) {
|
|
|
|
this.onRepoDetails(repo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-12 15:34:54 +08:00
|
|
|
onRepoDetails = (repo) => {
|
|
|
|
this.setState({
|
|
|
|
isShowDetails: true,
|
|
|
|
currentRepo: repo
|
2019-01-31 17:37:02 +08:00
|
|
|
});
|
2018-12-12 15:34:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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">
|
2018-12-12 17:51:12 +08:00
|
|
|
<h3 className="sf-heading">{gettext('My Libraries')}</h3>
|
2018-11-30 17:18:41 +08:00
|
|
|
</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}
|
2018-12-28 15:19:10 +08:00
|
|
|
sortBy={this.state.sortBy}
|
|
|
|
sortOrder={this.state.sortOrder}
|
|
|
|
sortItems={this.sortItems}
|
2018-12-12 15:34:54 +08:00
|
|
|
onDeleteRepo={this.onDeleteRepo}
|
|
|
|
onRenameRepo={this.onRenameRepo}
|
|
|
|
onTransferRepo={this.onTransferRepo}
|
|
|
|
onRepoDetails={this.onRepoDetails}
|
2019-01-17 17:05:08 +08:00
|
|
|
onItemClick={this.onItemClick}
|
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;
|