import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import Loading from '../../components/loading'; import { gettext, username, loginUrl } from '../../utils/constants'; import { seafileAPI } from '../../utils/seafile-api'; import Group from '../../models/group'; import RepoInfo from '../../models/repoInfo'; import CommonToolbar from '../../components/toolbar/common-toolbar'; import RepoViewToolbar from '../../components/toolbar/repo-view-toobar'; import CurGroupPath from '../../components/cur-group-path/'; import RepoListView from '../../components/repo-list-view/repo-list-view'; const propTypes = { }; class GroupView extends React.Component { constructor(props) { super(props); this.state = { isLoading: true, errMessage: '', currentGroup: null, repoList: [], } } componentDidMount() { let groupID = this.props.groupID; this.loadGroup(groupID); } componentWillReceiveProps(nextProps) { if (nextProps.groupID !== this.props.groupID) { this.loadGroup(nextProps.groupID); } } loadGroup = (groupID) => { seafileAPI.getGroup(groupID).then((res) => { let currentGroup = new Group(res.data); this.setState({currentGroup: currentGroup}); this.loadRepos(groupID); }).catch((error) => { if (error.response) { if (error.response.status == 403) { this.setState({ isLoading: false, errorMsg: gettext("Permission denied") }); location.href = `${loginUrl}?next=${encodeURIComponent(location.href)}`; } else { this.setState({ isLoading: false, errorMsg: gettext("Error") }); } } else { this.setState({ isLoading: false, errorMsg: gettext("Please check the network.") }); } }); } loadRepos = (groupID) => { this.setState({isLoading: true}); seafileAPI.listGroupRepos(groupID).then((res) => { let repoList = res.data.map(item => { let repoInfo = new RepoInfo(item); return repoInfo; }); this.setState({ isLoading: false, repoList: repoList }); }).catch((error) => { if (error.response) { if (error.response.status == 403) { this.setState({ isLoading: false, errorMsg: gettext("Permission denied") }); location.href = `${loginUrl}?next=${encodeURIComponent(location.href)}`; } else { this.setState({ isLoading: false, errorMsg: gettext("Error") }); } } else { this.setState({ isLoading: false, errorMsg: gettext("Please check the network.") }); } }); } onCreateRepo = (repo) => { let groupId = this.props.groupID; seafileAPI.createGroupRepo(groupId, repo).then(() => { //todo update group list }); } getEmptyTip = () => { let currentGroup = this.state.currentGroup; let emptyTip = null; if (currentGroup) { if (currentGroup.parent_group_id === 0) { emptyTip = (

{gettext('No library is shared to this group')}

{gettext('You can share libraries by clicking the "New Library" button above or the "Share" icon on your libraries list.')}

{gettext('Libraries shared as writable can be downloaded and synced by other group members. Read only libraries can only be downloaded, updates by others will not be uploaded.')}

); } else { if (currentGroup.admins.indexOf(username) == -1) { emptyTip = (

{gettext('No libraries')}

); } else { emptyTip = (

{gettext('No libraries')}

{gettext('You can create libraries by clicking the "New Library" button above.')}

); } } } return emptyTip; } render() { let emptyTip = this.getEmptyTip(); return (
{this.state.currentGroup && }
{this.state.isLoading && } {(!this.state.isLoading && this.state.errMessage) && this.state.errMessage} {(!this.state.isLoading && this.state.repoList.length === 0) && emptyTip} {(!this.state.isLoading && this.state.repoList.length > 0) && }
); } } GroupView.propTypes = propTypes; export default GroupView;