import React, { Component } from 'react'; import { seafileAPI } from '../../utils/seafile-api'; import { Utils } from '../../utils/utils'; import { gettext, siteRoot, loginUrl, username } from '../../utils/constants'; import Loading from '../../components/loading'; import GroupRepoItem from './group-repo-item'; import '../../css/groups.css'; class Header extends Component { render() { const {loading, errorMsg, data} = this.props.data; if (loading) { return ; } else if (errorMsg) { return

{errorMsg}

; } else { /* admins: ["lj@1.com"] avatar_url: "http://127.0.0.1:8000/media/avatars/groups/default.png" created_at: "2018-10-25T08:18:11+00:00" id: 2 name: "g1" owner: "lj@1.com" parent_group_id: 0 wiki_enabled: false */ const path = (
{gettext("Groups")} / {data.name} {data.parent_group_id == 0 ? null : }
); let showSettingsIcon = true; if (data.parent_group_id != 0 && data.admins.indexOf(username) == -1) { showSettingsIcon = false; } // TODO: click icon const toolbar = (
{showSettingsIcon ? : null}
); return ( {path} {toolbar} ); } } } class Content extends Component { render() { const {loading, errorMsg, items} = this.props.data.repos; if (loading) { return ; } else if (errorMsg) { return

{errorMsg}

; } else { if (!items) { return null; } const groupInfo = this.props.data.groupMetaInfo.data; let emptyTip; if (groupInfo.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 (groupInfo.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.')}

); } } const desktopThead = ( {gettext("Library Type")} {gettext("Name")}{/*TODO: sort*/} {gettext("Actions")} {gettext("Size")} {gettext("Last Update")}{/*TODO: sort*/} {gettext("Owner")} ); const mobileThead = ( {gettext("Library Type")} {gettext("Sort:")} {/* TODO: sort */} {gettext("name")} {gettext("last update")} {gettext("Actions")} ); const extraData = { groupId: groupInfo.id, isStaff: groupInfo.admins.indexOf(username) != -1, showRepoOwner: true }; const table = ( {window.innerWidth >= 768 ? desktopThead : mobileThead}
); return items.length ? table : emptyTip; } } } class TableBody extends Component { constructor(props) { super(props); this.state = { items: this.props.items }; } render() { let listItems = this.state.items.map(function(item, index) { return ; }, this); return ( {listItems} ); } } class Group extends Component { constructor(props) { super(props); this.state = { groupMetaInfo: { loading: true, errorMsg: '' }, repos: { loading: false, errorMsg: '' } }; } componentDidMount() { seafileAPI.getGroup(this.props.groupID).then((res) => { // res: {data: {...}, status: 200, statusText: "OK", headers: {…}, config: {…}, …} this.setState({ groupMetaInfo: { loading: false, data: res.data } }); this.listGroupRepos(); }).catch((error) => { if (error.response) { if (error.response.status == 403) { this.setState({ groupMetaInfo: { loading: false, errorMsg: gettext("Permission denied") } }); location.href = `${loginUrl}?next=${encodeURIComponent(location.href)}`; } else { this.setState({ groupMetaInfo: { loading: false, errorMsg: gettext("Error") } }); } } else { this.setState({ groupMetaInfo: { loading: false, errorMsg: gettext("Please check the network.") } }); } }); } listGroupRepos() { seafileAPI.listGroupRepos(this.props.groupID).then((res) => { // res: {data: [...], status: 200, statusText: "OK", headers: {…}, config: {…}, …} this.setState({ repos: { loading: false, items: res.data } }); }).catch((error) => { if (error.response) { if (error.response.status == 403) { this.setState({ repos: { loading: false, errorMsg: gettext("Permission denied") } }); location.href = `${loginUrl}?next=${encodeURIComponent(location.href)}`; } else { this.setState({ repos: { loading: false, errorMsg: gettext("Error") } }); } } else { this.setState({ repos: { loading: false, errorMsg: gettext("Please check the network.") } }); } }); } render() { return (
); } } export default Group;