1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-29 04:01:24 +00:00
seahub/frontend/src/components/dialog/wiki-select-dialog.js

111 lines
3.4 KiB
JavaScript
Raw Normal View History

2018-12-07 16:01:23 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import { gettext } from '../../utils/constants';
2018-12-07 16:01:23 +00:00
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import { seafileAPI } from '../../utils/seafile-api';
import moment from 'moment';
import Repo from '../../models/repo';
import { Utils } from '../../utils/utils';
2018-12-07 16:01:23 +00:00
const propTypes = {
toggleCancel: PropTypes.func.isRequired,
addWiki: PropTypes.func.isRequired
2018-12-07 16:01:23 +00:00
};
2018-12-10 05:33:32 +00:00
class WikiSelectDialog extends React.Component {
2018-12-07 16:01:23 +00:00
constructor(props) {
super(props);
this.state = {
repos: [],
2018-12-11 05:44:09 +00:00
repoID: '',
};
2018-12-07 16:01:23 +00:00
}
componentDidMount() {
seafileAPI.listRepos().then(res => {
let repoList = res.data.repos
.filter(item => {
switch (item.type) {
case 'mine': // my libraries
return !item.encrypted;
case 'shared': // libraries shared with me
// 'is_admin': the library is shared with 'admin' permission
return !item.encrypted && item.is_admin;
case 'group':
default:
return !item.encrypted && !res.data.repos.some(repo => {
// just remove the duplicated libraries
return repo.type != item.type && repo.repo_id == item.repo_id;
});
}
})
.map(item => {
let repo = new Repo(item);
return repo;
});
repoList = Utils.sortRepos(repoList, 'name', 'asc');
this.setState({repos: repoList});
2018-12-11 05:44:09 +00:00
});
2018-12-07 16:01:23 +00:00
}
onChange = (repo) => {
this.setState({
repoID: repo.repo_id,
});
}
handleSubmit = () => {
let { repoID } = this.state;
this.props.addWiki(repoID);
2018-12-07 16:01:23 +00:00
this.props.toggleCancel();
}
toggle = () => {
this.props.toggleCancel();
}
render() {
return (
<Modal isOpen={true}>
2019-04-22 10:21:25 +00:00
<ModalHeader toggle={this.toggle}>{gettext('Publish a Library')}</ModalHeader>
2018-12-11 03:20:40 +00:00
<ModalBody className="dialog-list-container">
2018-12-07 16:01:23 +00:00
<table>
<thead>
<tr>
2019-04-22 10:21:25 +00:00
<th width='6%'>{/* select */}</th>
<th width='9%'>{/* icon */}</th>
<th width='55%'>{gettext('Name')}</th>
<th width='30%'>{gettext('Last Update')}</th>
2018-12-07 16:01:23 +00:00
</tr>
</thead>
<tbody>
{this.state.repos.map((repo, index) => {
return (
<tr key={index}>
2018-12-28 03:12:24 +00:00
<td className="text-center"><input type="radio" className="vam" name="repo" value={repo.repo_id} onChange={this.onChange.bind(this, repo)} /></td>
2019-07-26 03:39:46 +00:00
<td className="text-center"><img src={Utils.getLibIconUrl(repo, false)} width="24" title={Utils.getLibIconTitle(repo)} alt={Utils.getLibIconTitle(repo)} /></td>
<td>{repo.repo_name}</td>
2018-12-07 16:01:23 +00:00
<td>{moment(repo.last_modified).fromNow()}</td>
</tr>
);
})}
</tbody>
</table>
</ModalBody>
<ModalFooter>
2018-12-08 05:31:41 +00:00
<Button color="secondary" onClick={this.toggle}>{gettext('Cancel')}</Button>
2019-04-22 10:21:25 +00:00
{this.state.repoID ?
<Button color="primary" onClick={this.handleSubmit}>{gettext('Submit')}</Button>:
<Button color="primary" disabled>{gettext('Submit')}</Button>
}
2018-12-07 16:01:23 +00:00
</ModalFooter>
</Modal>
);
}
}
2018-12-10 05:33:32 +00:00
WikiSelectDialog.propTypes = propTypes;
2018-12-07 16:01:23 +00:00
2018-12-10 05:33:32 +00:00
export default WikiSelectDialog;