2018-12-08 10:29:13 +00:00
|
|
|
import React, { Component, Fragment } from 'react';
|
|
|
|
import { Link } from '@reach/router';
|
2018-12-12 17:09:15 +08:00
|
|
|
import moment from 'moment';
|
2018-12-08 10:29:13 +00:00
|
|
|
import { gettext, siteRoot, lang } from '../../utils/constants';
|
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
2018-12-10 04:05:54 +00:00
|
|
|
import toaster from '../../components/toast';
|
2018-12-08 10:29:13 +00:00
|
|
|
import CommonToolbar from '../../components/toolbar/common-toolbar';
|
2018-12-12 17:09:15 +08:00
|
|
|
import Loading from '../../components/loading';
|
2019-04-08 18:04:56 +08:00
|
|
|
import { Utils } from '../../utils/utils';
|
2018-12-12 17:09:15 +08:00
|
|
|
|
2018-12-08 10:29:13 +00:00
|
|
|
moment.locale(lang);
|
|
|
|
|
|
|
|
class MyLibsDeleted extends Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
deletedRepoList: [],
|
2018-12-12 17:09:15 +08:00
|
|
|
isLoading: true,
|
2018-12-08 10:29:13 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
seafileAPI.listDeletedRepo().then(res => {
|
|
|
|
this.setState({
|
2018-12-12 17:09:15 +08:00
|
|
|
deletedRepoList: res.data,
|
|
|
|
isLoading: false,
|
2018-12-08 10:29:13 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshDeletedRepoList = (repoID) => {
|
2018-12-12 17:09:15 +08:00
|
|
|
let deletedRepoList = this.state.deletedRepoList.filter(item => {
|
|
|
|
return item.repo_id !== repoID;
|
|
|
|
});
|
|
|
|
this.setState({deletedRepoList: deletedRepoList});
|
2018-12-08 10:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-12-12 17:09:15 +08:00
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<div className="main-panel-north">
|
|
|
|
<CommonToolbar onSearchedClick={this.props.onSearchedClick} />
|
|
|
|
</div>
|
|
|
|
<div className="main-panel-center">
|
|
|
|
<div className="cur-view-container">
|
|
|
|
<div className="cur-view-path">
|
|
|
|
<div className="path-container">
|
|
|
|
<Link to={ siteRoot + 'my-libs/' }>{gettext("My Libraries")}</Link>
|
|
|
|
<span className="path-split">/</span>
|
|
|
|
<span>{gettext('Deleted Libraries')}</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="cur-view-content">
|
|
|
|
{this.state.isLoading && <Loading />}
|
|
|
|
{(!this.state.isLoading && this.state.deletedRepoList.length === 0) &&
|
2019-01-31 17:37:02 +08:00
|
|
|
<div className="message empty-tip">
|
|
|
|
<h2>{gettext('No deleted libraries.')}</h2>
|
|
|
|
</div>
|
2018-12-12 17:09:15 +08:00
|
|
|
}
|
|
|
|
{this.state.deletedRepoList.length !== 0 &&
|
|
|
|
<div>
|
|
|
|
<p className="tip">{gettext('Tip: libraries deleted 30 days ago will be cleaned automatically.')}</p>
|
|
|
|
<DeletedRepoTable
|
|
|
|
deletedRepoList={this.state.deletedRepoList}
|
|
|
|
refreshDeletedRepoList={this.refreshDeletedRepoList}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Fragment>
|
2018-12-08 10:29:13 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class DeletedRepoTable extends Component {
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let deletedRepos = this.props.deletedRepoList;
|
|
|
|
return (
|
|
|
|
<table>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th style={{width: '4%'}}>{/*img*/}</th>
|
|
|
|
<th style={{width: '52%'}}>{gettext('Name')}</th>
|
|
|
|
<th style={{width: '30%'}}>{gettext('Deleted Time')}</th>
|
|
|
|
<th style={{width: '14%'}}></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{ deletedRepos && deletedRepos.map((item) => {
|
|
|
|
return (
|
|
|
|
<DeletedRepoItem
|
|
|
|
key={item.repo_id}
|
|
|
|
repo={item}
|
|
|
|
refreshDeletedRepoList={this.props.refreshDeletedRepoList}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class DeletedRepoItem extends Component {
|
2018-12-10 05:42:13 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
hideRestoreMenu: true,
|
2018-12-12 15:50:05 +08:00
|
|
|
highlight: false,
|
2018-12-10 05:42:13 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onMouseEnter = () => {
|
|
|
|
if (!this.props.isItemFreezed) {
|
|
|
|
this.setState({
|
|
|
|
hideRestoreMenu: false,
|
2018-12-12 15:50:05 +08:00
|
|
|
highlight: true,
|
2018-12-10 05:42:13 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onMouseLeave = () => {
|
|
|
|
if (!this.props.isItemFreezed) {
|
|
|
|
this.setState({
|
|
|
|
hideRestoreMenu: true,
|
2018-12-12 15:50:05 +08:00
|
|
|
highlight: false,
|
2018-12-10 05:42:13 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2018-12-08 10:29:13 +00:00
|
|
|
|
|
|
|
restoreDeletedRepo = () => {
|
|
|
|
let repoID = this.props.repo.repo_id;
|
2018-12-10 04:05:54 +00:00
|
|
|
let repoName = this.props.repo.repo_name;
|
2018-12-08 10:29:13 +00:00
|
|
|
seafileAPI.restoreDeletedRepo(repoID).then(res => {
|
2018-12-20 15:37:14 +08:00
|
|
|
let message = gettext('Successfully restored the library.') + ' ' + repoName;
|
2018-12-10 04:05:54 +00:00
|
|
|
toaster.success(message);
|
2018-12-08 10:29:13 +00:00
|
|
|
this.props.refreshDeletedRepoList(repoID);
|
2018-12-10 04:05:54 +00:00
|
|
|
}).catch(res => {
|
|
|
|
let message = gettext('Failed. Please check the network.')
|
|
|
|
toaster.danger(message);
|
2018-12-08 10:29:13 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let localTime = moment.utc(this.props.repo.del_time).toDate();
|
|
|
|
localTime = moment(localTime).fromNow();
|
2019-04-08 18:04:56 +08:00
|
|
|
let iconUrl = Utils.getLibIconUrl(this.props.repo);
|
2018-12-08 10:29:13 +00:00
|
|
|
|
|
|
|
return (
|
2018-12-12 15:50:05 +08:00
|
|
|
<tr className={this.state.highlight ? 'tr-highlight' : ''} onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}>
|
2019-04-08 18:04:56 +08:00
|
|
|
<td className="text-center"><img src={iconUrl} alt='' width="24" /></td>
|
2018-12-08 10:29:13 +00:00
|
|
|
<td className="name">{this.props.repo.repo_name}</td>
|
|
|
|
<td className="update">{localTime}</td>
|
2018-12-12 15:50:05 +08:00
|
|
|
<td>
|
2019-04-08 18:04:56 +08:00
|
|
|
<span onClick={this.restoreDeletedRepo} title={gettext('Restore')}
|
|
|
|
className={`sf2-icon-reply action-icon ${this.state.highlight ? '' : 'vh'}`}></span>
|
2018-12-12 15:50:05 +08:00
|
|
|
</td>
|
2018-12-08 10:29:13 +00:00
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MyLibsDeleted;
|