1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-01 15:23:05 +00:00

Merge pull request #2637 from haiwen/add-group

add-group
This commit is contained in:
Daniel Pan 2018-12-13 12:16:14 +08:00 committed by GitHub
commit 3571838b0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 137 additions and 3 deletions

View File

@ -0,0 +1,62 @@
import React from 'react';
import PropTypes from 'prop-types';
import { gettext } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api';
import { Modal, ModalHeader, ModalBody, ModalFooter, Input, Button } from 'reactstrap';
class CreateGroupDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
groupName: '',
};
}
handleGroupChange = (event) => {
let name = event.target.value.trim();
this.setState({
groupName: name
});
}
handleSubmitGroup = () => {
let name = this.state.groupName.trim();
if (name) {
let that = this;
seafileAPI.createGroup(name).then((res)=> {
that.props.listGroups();
});
}
this.setState({
groupName: '',
});
this.props.toggleAddGroupModal();
}
render() {
return(
<Modal isOpen={this.props.showAddGroupModal} toggle={this.props.toggleAddGroupModal}>
<ModalHeader toggle={this.toggle}>{gettext('New group')}</ModalHeader>
<ModalBody>
<label htmlFor="groupName">{gettext('Name')}</label>
<Input type="text" id="groupName" value={this.state.groupName} onChange={this.handleGroupChange}/>
</ModalBody>
<ModalFooter>
<Button color="primary" onClick={this.handleSubmitGroup}>{gettext('Submit')}</Button>
<Button color="secondary" onClick={this.props.toggleAddGroupModal}>{gettext('Cancel')}</Button>
</ModalFooter>
</Modal>
);
}
}
const CreateGroupDialogPropTypes = {
toggleAddGroupModal: PropTypes.func.isRequired,
listGroups: PropTypes.func.isRequired,
showAddGroupModal: PropTypes.bool.isRequired,
};
CreateGroupDialog.propTypes = CreateGroupDialogPropTypes;
export default CreateGroupDialog;

View File

@ -0,0 +1,43 @@
import React from 'react';
import PropTypes from 'prop-types';
import CommonToolbar from './common-toolbar';
import { Button } from 'reactstrap';
import { gettext } from '../../utils/constants';
const propTypes = {
searchPlaceholder: PropTypes.string,
onShowSidePanel: PropTypes.func.isRequired,
onSearchedClick: PropTypes.func.isRequired,
toggleAddGroupModal: PropTypes.func.isRequired,
};
class GroupsToolbar extends React.Component {
constructor(props) {
super(props);
}
render() {
let { onShowSidePanel, onSearchedClick } = this.props;
let placeHolder = this.props.searchPlaceholder || 'Search files in this library';
return (
<div className="main-panel-north">
<div className="cur-view-toolbar">
<div className="operation">
<Button color="btn btn-secondary operation-item" onClick={this.props.toggleAddGroupModal}>
<i className="fas fa-plus-square op-icon"></i>{gettext("New Group")}
</Button>
</div>
<span title="Side Nav Menu" onClick={onShowSidePanel}
className="sf2-icon-menu side-nav-toggle hidden-md-up d-md-none">
</span>
</div>
<CommonToolbar searchPlaceholder={placeHolder} onSearchedClick={onSearchedClick}/>
</div>
);
}
}
GroupsToolbar.propTypes = propTypes;
export default GroupsToolbar;

View File

@ -5,8 +5,9 @@ import { seafileAPI } from '../../utils/seafile-api';
import Loading from '../../components/loading';
import Group from '../../models/group';
import RepoInfo from '../../models/repoInfo';
import GeneralToolbar from '../../components/toolbar/general-toolbar';
import GroupsToolbar from '../../components/toolbar/groups-toolbar';
import SharedRepoListView from '../../components/shared-repo-list-view/shared-repo-list-view';
import CreateGroupDialog from '../../components/dialog/create-group-dialog';
import '../../css/groups.css';
@ -76,10 +77,11 @@ class GroupsView extends React.Component {
isLoading: true,
errorMsg: '',
groupList: [],
showAddGroupModal: false,
}
}
componentDidMount() {
listGroups = () => {
seafileAPI.listGroupsV2({'with_repos': 1}).then((res) => { // TODO: api name
// `{'with_repos': 1}`: list repos of every group
// res: {data: [...], status: 200, statusText: "OK", headers: {…}, config: {…}, …}
@ -114,10 +116,24 @@ class GroupsView extends React.Component {
});
}
toggleAddGroupModal = () => {
this.setState({
showAddGroupModal: !this.state.showAddGroupModal
});
}
componentDidMount() {
this.listGroups();
}
render() {
return (
<Fragment>
<GeneralToolbar onShowSidePanel={this.props.onShowSidePanel} onSearchedClick={this.props.onSearchedClick}/>
<GroupsToolbar
onShowSidePanel={this.props.onShowSidePanel}
onSearchedClick={this.props.onSearchedClick}
toggleAddGroupModal={this.toggleAddGroupModal}
/>
<div className="main-panel-center">
<div className="cur-view-container">
<div className="cur-view-path">
@ -135,11 +151,24 @@ class GroupsView extends React.Component {
</div>
</div>
</div>
{ this.state.showAddGroupModal &&
<CreateGroupDialog
toggleAddGroupModal={this.toggleAddGroupModal}
listGroups={this.listGroups}
showAddGroupModal={this.state.showAddGroupModal}
/>
}
</Fragment>
);
}
}
const GroupsViewPropTypes = {
onShowSidePanel: PropTypes.func.isRequired,
onSearchedClick: PropTypes.func.isRequired,
};
GroupsView.propTypes = GroupsViewPropTypes;
// Groups.propTypes = propTypes;
export default GroupsView;