2019-04-01 13:38:25 +08:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import moment from 'moment';
|
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
2019-04-30 10:28:32 +08:00
|
|
|
import { serviceURL, gettext, orgID, lang } from '../../utils/constants';
|
2019-04-01 13:38:25 +08:00
|
|
|
import { Utils } from '../../utils/utils.js';
|
|
|
|
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';
|
|
|
|
import '../../css/org-department-item.css';
|
|
|
|
|
|
|
|
moment.locale(lang);
|
|
|
|
|
|
|
|
class OrgDepartmentsList extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
groups: null,
|
|
|
|
groupID: -1,
|
|
|
|
groupName: '',
|
|
|
|
showDeleteDepartDialog: false,
|
|
|
|
showSetGroupQuotaDialog: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
listDepartGroups = () => {
|
|
|
|
if (this.props.groupID) {
|
|
|
|
seafileAPI.orgAdminListGroupInfo(orgID, this.props.groupID, true).then(res => {
|
2019-04-30 10:28:32 +08:00
|
|
|
this.setState({ groups: res.data.groups });
|
2019-04-01 13:38:25 +08:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
seafileAPI.orgAdminListDepartGroups(orgID).then(res => {
|
2019-04-30 10:28:32 +08:00
|
|
|
this.setState({ groups: res.data.data });
|
2019-04-01 13:38:25 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
showDeleteDepartDialog = (group) => {
|
|
|
|
this.setState({ showDeleteDepartDialog: true, groupID: group.id, groupName: group.name });
|
|
|
|
}
|
|
|
|
|
|
|
|
showSetGroupQuotaDialog = (groupID) => {
|
|
|
|
this.setState({ showSetGroupQuotaDialog: true, groupID: groupID });
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleCancel = () => {
|
|
|
|
this.setState({
|
|
|
|
showDeleteDepartDialog: false,
|
|
|
|
showSetGroupQuotaDialog: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onDepartChanged = () => {
|
|
|
|
this.listDepartGroups();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
this.listDepartGroups();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const groups = this.state.groups;
|
|
|
|
let isSub = this.props.groupID ? true : false;
|
|
|
|
let header = isSub ? gettext('Sub-departments') : gettext('Departments');
|
2019-04-03 18:15:19 +08:00
|
|
|
let noGroup = isSub ? gettext('No sub-departments') : gettext('No departments');
|
2019-04-01 13:38:25 +08:00
|
|
|
return (
|
|
|
|
<div className="main-panel-center flex-row h-100">
|
|
|
|
<div className="cur-view-container o-auto">
|
|
|
|
<div className="cur-view-path">
|
|
|
|
<div className="fleft"><h3 className="sf-heading">{header}</h3></div>
|
|
|
|
</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>
|
|
|
|
:
|
|
|
|
<p className="no-group">{noGroup}</p>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
<React.Fragment>
|
2019-04-29 22:20:56 +08:00
|
|
|
{this.props.isShowAddDepartDialog && (
|
2019-04-01 13:38:25 +08:00
|
|
|
<ModalPortal>
|
|
|
|
<AddDepartDialog
|
|
|
|
onDepartChanged={this.onDepartChanged}
|
|
|
|
parentGroupID={this.props.groupID}
|
|
|
|
groupID={this.state.groupID}
|
2019-04-29 22:20:56 +08:00
|
|
|
toggle={this.props.toggleAddDepartDialog}
|
2019-04-01 13:38:25 +08:00
|
|
|
/>
|
|
|
|
</ModalPortal>
|
|
|
|
)}
|
|
|
|
{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-04-30 10:28:32 +08:00
|
|
|
const OrgDepartmentsListPropTypes = {
|
|
|
|
isShowAddDepartDialog: PropTypes.bool.isRequired,
|
|
|
|
toggleAddDepartDialog: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
OrgDepartmentsList.propTypes = OrgDepartmentsListPropTypes;
|
|
|
|
|
|
|
|
|
2019-04-01 13:38:25 +08:00
|
|
|
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;
|
|
|
|
const newHref = serviceURL + '/org/departmentadmin/groups/' + group.id + '/';
|
|
|
|
return (
|
|
|
|
<tr className={highlight ? 'tr-highlight' : ''} onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}>
|
|
|
|
<td><a href={newHref} onClick={this.changeOrgGroup}>{group.name}</a></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;
|