1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-27 15:54:39 +00:00
Files
seahub/frontend/src/pages/org-admin/org-departments-list.js

193 lines
6.2 KiB
JavaScript
Raw Normal View History

2019-05-05 18:29:06 +08:00
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import moment from 'moment';
2019-05-02 19:25:56 +08:00
import { Link } from '@reach/router';
import { Utils } from '../../utils/utils.js';
2019-05-06 16:15:11 +08:00
import { seafileAPI } from '../../utils/seafile-api';
import MainPanelTopbar from './main-panel-topbar';
import ModalPortal from '../../components/modal-portal';
import AddDepartDialog from '../../components/dialog/org-add-department-dialog';
import DeleteDepartDialog from '../../components/dialog/org-delete-department-dialog';
import SetGroupQuotaDialog from '../../components/dialog/org-set-group-quota-dialog';
2019-05-06 16:15:11 +08:00
import { siteRoot, gettext, orgID, lang } from '../../utils/constants';
import '../../css/org-department-item.css';
moment.locale(lang);
class OrgDepartmentsList extends React.Component {
constructor(props) {
super(props);
this.state = {
groups: null,
2019-05-15 15:58:52 +08:00
groupID: '',
groupName: '',
showDeleteDepartDialog: false,
showSetGroupQuotaDialog: false,
2019-05-05 15:18:54 +08:00
isShowAddDepartDialog: false,
};
}
2019-05-06 16:15:11 +08:00
componentDidMount() {
this.listDepartGroups();
}
2019-05-06 16:15:11 +08:00
listDepartGroups = () => {
seafileAPI.orgAdminListDepartGroups(orgID).then(res => {
this.setState({ groups: res.data.data });
});
}
showDeleteDepartDialog = (group) => {
this.setState({ showDeleteDepartDialog: true, groupID: group.id, groupName: group.name });
}
showSetGroupQuotaDialog = (groupID) => {
this.setState({ showSetGroupQuotaDialog: true, groupID: groupID });
}
2019-05-06 16:15:11 +08:00
toggleAddDepartDialog = () => {
this.setState({ isShowAddDepartDialog: !this.state.isShowAddDepartDialog});
}
toggleCancel = () => {
this.setState({
showDeleteDepartDialog: false,
showSetGroupQuotaDialog: false,
});
}
onDepartChanged = () => {
2019-05-06 16:15:11 +08:00
this.listDepartGroups();
}
render() {
const groups = this.state.groups;
2019-05-05 15:18:54 +08:00
const topbarChildren = (
2019-05-02 20:33:27 +08:00
<Fragment>
2019-05-06 16:15:11 +08:00
<button className='btn btn-secondary operation-item' title={gettext('New Department')} onClick={this.toggleAddDepartDialog}>{gettext('New Department')}
</button>
2019-05-05 15:18:54 +08:00
{this.state.isShowAddDepartDialog && (
<ModalPortal>
<AddDepartDialog
onDepartChanged={this.onDepartChanged}
groupID={this.state.groupID}
toggle={this.toggleAddDepartDialog}
/>
</ModalPortal>
)}
</Fragment>
);
return (
<Fragment>
2019-05-06 16:15:11 +08:00
<MainPanelTopbar children={topbarChildren}/>
2019-05-02 20:33:27 +08:00
<div className="main-panel-center flex-row h-100">
<div className="cur-view-container o-auto">
<div className="cur-view-path">
2019-05-05 18:29:06 +08:00
<div className="fleft">
2019-05-06 16:15:11 +08:00
<h3 className="sf-heading">{gettext('Departments')}</h3>
2019-05-05 18:29:06 +08:00
</div>
2019-05-02 20:33:27 +08:00
</div>
<div className="cur-view-content">
{groups && groups.length > 0 ?
<table>
<thead>
<tr>
<th width="40%">{gettext('Name')}</th>
<th width="25%">{gettext('Created At')}</th>
<th width="20%">{gettext('Quota')}</th>
<th width="15%"></th>
</tr>
</thead>
<tbody>
{groups.map((group, index) => {
return(
<React.Fragment key={group.id}>
<GroupItem
group={group}
showDeleteDepartDialog={this.showDeleteDepartDialog}
showSetGroupQuotaDialog={this.showSetGroupQuotaDialog}
/>
</React.Fragment>
);
})}
</tbody>
</table>
2019-05-06 16:15:11 +08:00
:
<p className="no-group">{gettext('No departments')}</p>
2019-05-02 20:33:27 +08:00
}
</div>
<React.Fragment>
{this.state.showDeleteDepartDialog && (
<ModalPortal>
<DeleteDepartDialog
toggle={this.toggleCancel}
groupID={this.state.groupID}
groupName={this.state.groupName}
onDepartChanged={this.onDepartChanged}
/>
</ModalPortal>
)}
{this.state.showSetGroupQuotaDialog && (
<ModalPortal>
<SetGroupQuotaDialog
toggle={this.toggleCancel}
groupID={this.state.groupID}
onDepartChanged={this.onDepartChanged}
/>
</ModalPortal>
)}
</React.Fragment>
</div>
</div>
2019-05-02 20:33:27 +08:00
</Fragment>
);
}
}
class GroupItem extends React.Component {
constructor(props) {
super(props);
this.state = {
highlight: false,
};
}
onMouseEnter = () => {
this.setState({ highlight: true });
}
onMouseLeave = () => {
this.setState({ highlight: false });
}
render() {
const group = this.props.group;
const highlight = this.state.highlight;
2019-05-02 19:25:56 +08:00
const newHref = siteRoot+ 'org/departmentadmin/groups/' + group.id + '/';
return (
<tr className={highlight ? 'tr-highlight' : ''} onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}>
2019-05-02 19:25:56 +08:00
<td><Link to={newHref}>{group.name}</Link></td>
<td>{moment(group.created_at).fromNow()}</td>
<td onClick={this.props.showSetGroupQuotaDialog.bind(this, group.id)}>
{Utils.bytesToSize(group.quota)}{' '}
<span title="Edit Quota" className={`fa fa-pencil-alt attr-action-icon ${highlight ? '' : 'vh'}`}></span>
</td>
<td className="cursor-pointer text-center" onClick={this.props.showDeleteDepartDialog.bind(this, group)}>
<span className={`sf2-icon-delete action-icon ${highlight ? '' : 'vh'}`} title="Delete"></span>
</td>
</tr>
);
}
}
const GroupItemPropTypes = {
group: PropTypes.object.isRequired,
showSetGroupQuotaDialog: PropTypes.func.isRequired,
showDeleteDepartDialog: PropTypes.func.isRequired,
};
GroupItem.propTypes = GroupItemPropTypes;
export default OrgDepartmentsList;