2019-08-15 20:59:10 +08:00
|
|
|
import React, { Fragment, Component } from 'react';
|
2018-12-26 16:07:22 +08:00
|
|
|
import { Link } from '@reach/router';
|
2019-08-15 20:59:10 +08:00
|
|
|
import { Dropdown, DropdownToggle, DropdownItem } from 'reactstrap';
|
2018-11-19 11:53:44 +08:00
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
|
|
|
import { Utils } from '../../utils/utils';
|
2019-12-05 15:45:16 +08:00
|
|
|
import { gettext, siteRoot, isPro } from '../../utils/constants';
|
2019-08-15 20:59:10 +08:00
|
|
|
import Loading from '../../components/loading';
|
2019-06-10 17:30:10 +08:00
|
|
|
import EmptyTip from '../../components/empty-tip';
|
2019-08-15 20:59:10 +08:00
|
|
|
import toaster from '../../components/toast';
|
2019-01-11 12:41:30 +08:00
|
|
|
import SharePermissionEditor from '../../components/select-editor/share-permission-editor';
|
2018-12-27 10:24:34 +08:00
|
|
|
import SharedFolderInfo from '../../models/shared-folder-info';
|
2019-08-15 20:59:10 +08:00
|
|
|
import PermSelect from '../../components/dialog/perm-select';
|
2018-11-19 11:53:44 +08:00
|
|
|
|
|
|
|
class Content extends Component {
|
|
|
|
|
2019-01-02 16:17:39 +08:00
|
|
|
sortByName = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
const sortBy = 'name';
|
|
|
|
const sortOrder = this.props.sortOrder == 'asc' ? 'desc' : 'asc';
|
|
|
|
this.props.sortItems(sortBy, sortOrder);
|
|
|
|
}
|
|
|
|
|
2018-11-19 11:53:44 +08:00
|
|
|
render() {
|
2019-01-02 16:17:39 +08:00
|
|
|
const { loading, errorMsg, items, sortBy, sortOrder } = this.props;
|
2018-11-19 11:53:44 +08:00
|
|
|
|
|
|
|
if (loading) {
|
2019-08-15 20:59:10 +08:00
|
|
|
return <Loading />;
|
2018-11-19 11:53:44 +08:00
|
|
|
} else if (errorMsg) {
|
|
|
|
return <p className="error text-center">{errorMsg}</p>;
|
|
|
|
} else {
|
|
|
|
const emptyTip = (
|
2019-06-10 17:30:10 +08:00
|
|
|
<EmptyTip>
|
2018-11-19 11:53:44 +08:00
|
|
|
<h2>{gettext('You have not shared any folders')}</h2>
|
2019-01-31 17:37:02 +08:00
|
|
|
<p>{gettext('You can share a single folder with a registered user if you don\'t want to share a whole library.')}</p>
|
2019-06-10 17:30:10 +08:00
|
|
|
</EmptyTip>
|
2018-11-19 11:53:44 +08:00
|
|
|
);
|
|
|
|
|
2019-01-02 16:17:39 +08:00
|
|
|
// sort
|
|
|
|
const sortByName = sortBy == 'name';
|
|
|
|
const sortIcon = sortOrder == 'asc' ? <span className="fas fa-caret-up"></span> : <span className="fas fa-caret-down"></span>;
|
|
|
|
|
2019-08-15 20:59:10 +08:00
|
|
|
const isDesktop = Utils.isDesktop();
|
2018-11-19 11:53:44 +08:00
|
|
|
const table = (
|
2019-08-15 20:59:10 +08:00
|
|
|
<table className={`table-hover ${isDesktop ? '': 'table-thead-hidden'}`}>
|
2018-11-19 11:53:44 +08:00
|
|
|
<thead>
|
2019-08-15 20:59:10 +08:00
|
|
|
{isDesktop ? (
|
|
|
|
<tr>
|
|
|
|
<th width="4%">{/*icon*/}</th>
|
|
|
|
<th width="34%"><a className="d-block table-sort-op" href="#" onClick={this.sortByName}>{gettext('Name')} {sortByName && sortIcon}</a></th>
|
|
|
|
<th width="30%">{gettext('Share To')}</th>
|
|
|
|
<th width="24%">{gettext('Permission')}</th>
|
|
|
|
<th width="8%"></th>
|
|
|
|
</tr>
|
|
|
|
) : (
|
|
|
|
<tr>
|
|
|
|
<th width="12%"></th>
|
|
|
|
<th width="80%"></th>
|
|
|
|
<th width="8%"></th>
|
|
|
|
</tr>
|
|
|
|
)}
|
2018-11-19 11:53:44 +08:00
|
|
|
</thead>
|
2018-12-27 10:24:34 +08:00
|
|
|
<tbody>
|
|
|
|
{items.map((item, index) => {
|
2019-08-15 20:59:10 +08:00
|
|
|
return (<Item key={index} isDesktop={isDesktop} item={item} />);
|
2018-12-27 10:24:34 +08:00
|
|
|
})}
|
|
|
|
</tbody>
|
2018-11-19 11:53:44 +08:00
|
|
|
</table>
|
|
|
|
);
|
|
|
|
|
|
|
|
return items.length ? table : emptyTip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Item extends Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2018-12-27 10:24:34 +08:00
|
|
|
share_permission: this.props.item.share_permission,
|
2019-08-15 20:59:10 +08:00
|
|
|
isOpIconShown: false,
|
|
|
|
isOpMenuOpen: false, // for mobile
|
|
|
|
isPermSelectDialogOpen: false, // for mobile
|
2018-11-19 11:53:44 +08:00
|
|
|
unshared: false
|
|
|
|
};
|
|
|
|
|
2018-12-26 16:07:22 +08:00
|
|
|
this.permissions = ['rw', 'r'];
|
|
|
|
if (isPro) {
|
2019-08-15 20:59:10 +08:00
|
|
|
this.permissions.push('cloud-edit', 'preview');
|
2018-12-26 16:07:22 +08:00
|
|
|
}
|
2018-11-19 11:53:44 +08:00
|
|
|
}
|
|
|
|
|
2019-08-15 20:59:10 +08:00
|
|
|
toggleOpMenu = () => {
|
|
|
|
this.setState({
|
|
|
|
isOpMenuOpen: !this.state.isOpMenuOpen
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
togglePermSelectDialog = () => {
|
|
|
|
this.setState({
|
|
|
|
isPermSelectDialogOpen: !this.state.isPermSelectDialogOpen
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-26 16:07:22 +08:00
|
|
|
onMouseEnter = () => {
|
2019-08-15 20:59:10 +08:00
|
|
|
this.setState({isOpIconShown: true});
|
2018-11-19 11:53:44 +08:00
|
|
|
}
|
|
|
|
|
2018-12-26 16:07:22 +08:00
|
|
|
onMouseLeave = () => {
|
2019-08-15 20:59:10 +08:00
|
|
|
this.setState({isOpIconShown: false});
|
2018-11-19 11:53:44 +08:00
|
|
|
}
|
|
|
|
|
2018-12-26 16:07:22 +08:00
|
|
|
unshare = (e) => {
|
2018-11-19 11:53:44 +08:00
|
|
|
e.preventDefault();
|
2019-08-15 20:59:10 +08:00
|
|
|
|
2018-12-27 10:24:34 +08:00
|
|
|
const item = this.props.item;
|
2019-08-15 20:59:10 +08:00
|
|
|
let options = {
|
|
|
|
'p': item.path
|
|
|
|
};
|
|
|
|
if (item.share_type == 'personal') {
|
|
|
|
Object.assign(options, {
|
|
|
|
'share_type': 'user',
|
|
|
|
'username': item.user_email
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Object.assign(options, {
|
|
|
|
'share_type': item.share_type, // 'group'
|
|
|
|
'group_id': item.group_id
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
seafileAPI.unshareFolder(item.repo_id, options).then((res) => {
|
|
|
|
this.setState({
|
|
|
|
unshared: true
|
|
|
|
});
|
|
|
|
let message = gettext('Successfully unshared {name}').replace('{name}', item.folder_name);
|
|
|
|
toaster.success(message);
|
|
|
|
}).catch(error => {
|
|
|
|
let errMessage = Utils.getErrorMsg(error);
|
|
|
|
toaster(errMessage);
|
|
|
|
});
|
2018-11-19 11:53:44 +08:00
|
|
|
}
|
|
|
|
|
2018-12-26 16:07:22 +08:00
|
|
|
changePerm = (permission) => {
|
2019-08-15 20:59:10 +08:00
|
|
|
const item = this.props.item;
|
2018-11-19 11:53:44 +08:00
|
|
|
const postData = {
|
2019-08-15 20:59:10 +08:00
|
|
|
'permission': permission
|
2018-11-19 11:53:44 +08:00
|
|
|
};
|
|
|
|
let options = {
|
2019-08-15 20:59:10 +08:00
|
|
|
'p': item.path
|
2018-11-19 11:53:44 +08:00
|
|
|
};
|
2019-08-15 20:59:10 +08:00
|
|
|
if (item.share_type == 'personal') {
|
|
|
|
Object.assign(options, {
|
|
|
|
'share_type': 'user',
|
|
|
|
'username': item.user_email
|
|
|
|
});
|
2018-12-27 10:24:34 +08:00
|
|
|
} else {
|
2019-08-15 20:59:10 +08:00
|
|
|
Object.assign(options, {
|
|
|
|
'share_type': item.share_type, // 'group'
|
|
|
|
'group_id': item.group_id
|
|
|
|
});
|
2018-11-19 11:53:44 +08:00
|
|
|
}
|
2018-12-27 10:24:34 +08:00
|
|
|
|
|
|
|
seafileAPI.updateFolderSharePerm(item.repo_id, postData, options).then((res) => {
|
2019-08-15 20:59:10 +08:00
|
|
|
this.setState({share_permission: permission});
|
|
|
|
toaster.success(gettext('Successfully modified permission.'));
|
2018-11-19 11:53:44 +08:00
|
|
|
}).catch((error) => {
|
2019-07-16 10:01:09 +08:00
|
|
|
let errMessage = Utils.getErrorMsg(error);
|
|
|
|
toaster.danger(errMessage);
|
2018-11-19 11:53:44 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-15 20:59:10 +08:00
|
|
|
render() {
|
|
|
|
if (this.state.unshared) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const item = this.props.item;
|
|
|
|
let { share_permission, isOpIconShown, isPermSelectDialogOpen } = this.state;
|
|
|
|
|
2018-11-19 11:53:44 +08:00
|
|
|
let is_readonly = false;
|
|
|
|
if (share_permission == 'r' || share_permission == 'preview') {
|
|
|
|
is_readonly = true;
|
|
|
|
}
|
2019-01-29 15:22:02 +08:00
|
|
|
let iconUrl = Utils.getFolderIconUrl(is_readonly);
|
2018-12-27 10:24:34 +08:00
|
|
|
let iconTitle = Utils.getFolderIconTitle({
|
2018-11-19 11:53:44 +08:00
|
|
|
'permission': share_permission
|
|
|
|
});
|
2019-08-15 20:59:10 +08:00
|
|
|
let folderUrl = `${siteRoot}library/${item.repo_id}/${encodeURIComponent(item.repo_name)}${Utils.encodePath(item.path)}`;
|
2018-11-19 11:53:44 +08:00
|
|
|
|
2019-08-15 20:59:10 +08:00
|
|
|
const desktopItem = (
|
2018-12-26 16:07:22 +08:00
|
|
|
<tr onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}>
|
2019-01-11 15:37:02 +08:00
|
|
|
<td><img src={iconUrl} title={iconTitle} alt={iconTitle} width="24" /></td>
|
2018-12-27 10:24:34 +08:00
|
|
|
<td><Link to={folderUrl}>{item.folder_name}</Link></td>
|
2019-08-15 20:59:10 +08:00
|
|
|
<td>
|
|
|
|
{item.share_type == 'personal' ?
|
|
|
|
<span title={item.contact_email}>{item.user_name}</span> : item.group_name}
|
|
|
|
</td>
|
2018-12-26 16:07:22 +08:00
|
|
|
<td>
|
2019-01-11 12:41:30 +08:00
|
|
|
<SharePermissionEditor
|
2018-12-26 16:07:22 +08:00
|
|
|
isTextMode={true}
|
2019-08-15 20:59:10 +08:00
|
|
|
isEditIconShow={isOpIconShown}
|
|
|
|
currentPermission={share_permission}
|
2018-12-26 16:07:22 +08:00
|
|
|
permissions={this.permissions}
|
2019-01-14 13:33:36 +08:00
|
|
|
onPermissionChanged={this.changePerm}
|
2018-12-26 16:07:22 +08:00
|
|
|
/>
|
|
|
|
</td>
|
2019-08-15 20:59:10 +08:00
|
|
|
<td><a href="#" className={`action-icon sf2-icon-x3 ${isOpIconShown ? '': 'invisible'}`} title={gettext('Unshare')} onClick={this.unshare}></a></td>
|
2018-11-19 11:53:44 +08:00
|
|
|
</tr>
|
|
|
|
);
|
2019-08-15 20:59:10 +08:00
|
|
|
|
|
|
|
const mobileItem = (
|
|
|
|
<Fragment>
|
|
|
|
<tr>
|
|
|
|
<td><img src={iconUrl} title={iconTitle} alt={iconTitle} width="24" /></td>
|
|
|
|
<td>
|
|
|
|
<Link to={folderUrl}>{item.folder_name}</Link>
|
|
|
|
<span className="item-meta-info-highlighted">{Utils.sharePerms(share_permission)}</span>
|
|
|
|
<br />
|
|
|
|
<span className="item-meta-info">{`${gettext('Share To:')} ${item.share_type == 'personal' ? item.user_name : item.group_name}`}</span>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<Dropdown isOpen={this.state.isOpMenuOpen} toggle={this.toggleOpMenu}>
|
|
|
|
<DropdownToggle
|
|
|
|
tag="i"
|
|
|
|
className="sf-dropdown-toggle fa fa-ellipsis-v ml-0"
|
|
|
|
title={gettext('More Operations')}
|
|
|
|
data-toggle="dropdown"
|
|
|
|
aria-expanded={this.state.isOpMenuOpen}
|
|
|
|
/>
|
|
|
|
<div className={this.state.isOpMenuOpen ? '' : 'd-none'} onClick={this.toggleOpMenu}>
|
|
|
|
<div className="mobile-operation-menu-bg-layer"></div>
|
|
|
|
<div className="mobile-operation-menu">
|
|
|
|
<DropdownItem className="mobile-menu-item" onClick={this.togglePermSelectDialog}>{gettext('Permission')}</DropdownItem>
|
|
|
|
<DropdownItem className="mobile-menu-item" onClick={this.unshare}>{gettext('Unshare')}</DropdownItem>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Dropdown>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
{isPermSelectDialogOpen &&
|
|
|
|
<PermSelect
|
|
|
|
currentPerm={share_permission}
|
|
|
|
permissions={this.permissions}
|
|
|
|
changePerm={this.changePerm}
|
|
|
|
toggleDialog={this.togglePermSelectDialog}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
|
|
|
|
return this.props.isDesktop ? desktopItem : mobileItem;
|
2018-11-19 11:53:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ShareAdminFolders extends Component {
|
2018-12-26 16:07:22 +08:00
|
|
|
|
2018-11-19 11:53:44 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
loading: true,
|
|
|
|
errorMsg: '',
|
2019-01-02 16:17:39 +08:00
|
|
|
items: [],
|
|
|
|
sortBy: 'name',
|
|
|
|
sortOrder: 'asc' // 'asc' or 'desc'
|
2018-11-19 11:53:44 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:17:39 +08:00
|
|
|
_sortItems = (items, sortBy, sortOrder) => {
|
|
|
|
let comparator;
|
|
|
|
|
|
|
|
switch (`${sortBy}-${sortOrder}`) {
|
|
|
|
case 'name-asc':
|
|
|
|
comparator = function(a, b) {
|
|
|
|
var result = Utils.compareTwoWord(a.folder_name, b.folder_name);
|
|
|
|
return result;
|
2019-01-02 17:49:30 +08:00
|
|
|
};
|
2019-01-02 16:17:39 +08:00
|
|
|
break;
|
|
|
|
case 'name-desc':
|
|
|
|
comparator = function(a, b) {
|
|
|
|
var result = Utils.compareTwoWord(a.folder_name, b.folder_name);
|
|
|
|
return -result;
|
2019-01-02 17:49:30 +08:00
|
|
|
};
|
2019-01-02 16:17:39 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
items.sort(comparator);
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
sortItems = (sortBy, sortOrder) => {
|
|
|
|
this.setState({
|
|
|
|
sortBy: sortBy,
|
|
|
|
sortOrder: sortOrder,
|
|
|
|
items: this._sortItems(this.state.items, sortBy, sortOrder)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-19 11:53:44 +08:00
|
|
|
componentDidMount() {
|
|
|
|
seafileAPI.listSharedFolders().then((res) => {
|
2018-12-27 10:24:34 +08:00
|
|
|
let items = res.data.map(item => {
|
|
|
|
return new SharedFolderInfo(item);
|
|
|
|
});
|
2018-11-19 11:53:44 +08:00
|
|
|
this.setState({
|
|
|
|
loading: false,
|
2019-01-02 16:17:39 +08:00
|
|
|
items: this._sortItems(items, this.state.sortBy, this.state.sortOrder)
|
2018-11-19 11:53:44 +08:00
|
|
|
});
|
|
|
|
}).catch((error) => {
|
2019-12-05 15:45:16 +08:00
|
|
|
this.setState({
|
|
|
|
loading: false,
|
|
|
|
errorMsg: Utils.getErrorMsg(error, true) // true: show login tip if 403
|
|
|
|
});
|
2018-11-19 11:53:44 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2018-11-26 17:53:18 +08:00
|
|
|
<div className="main-panel-center">
|
|
|
|
<div className="cur-view-container" id="share-admin-libs">
|
|
|
|
<div className="cur-view-path">
|
2019-01-31 17:37:02 +08:00
|
|
|
<h3 className="sf-heading">{gettext('Folders')}</h3>
|
2018-11-26 17:53:18 +08:00
|
|
|
</div>
|
|
|
|
<div className="cur-view-content">
|
2018-12-27 10:24:34 +08:00
|
|
|
<Content
|
|
|
|
errorMsg={this.state.errorMsg}
|
|
|
|
loading={this.state.loading}
|
|
|
|
items={this.state.items}
|
2019-01-02 16:17:39 +08:00
|
|
|
sortBy={this.state.sortBy}
|
|
|
|
sortOrder={this.state.sortOrder}
|
|
|
|
sortItems={this.sortItems}
|
2018-12-27 10:24:34 +08:00
|
|
|
/>
|
2018-11-26 14:00:32 +08:00
|
|
|
</div>
|
2018-11-19 11:53:44 +08:00
|
|
|
</div>
|
2018-11-26 17:53:18 +08:00
|
|
|
</div>
|
2018-11-19 11:53:44 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ShareAdminFolders;
|