2018-11-26 09:53:18 +00:00
|
|
|
import React, { Component } from 'react';
|
2018-12-26 08:07:22 +00:00
|
|
|
import { Link } from '@reach/router';
|
2018-11-19 03:53:44 +00:00
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
|
|
|
import { Utils } from '../../utils/utils';
|
|
|
|
import { gettext, siteRoot, loginUrl, isPro } from '../../utils/constants';
|
2018-12-26 08:07:22 +00:00
|
|
|
import PermissionEditor from '../../components/permission-editor';
|
2018-11-19 03:53:44 +00:00
|
|
|
|
|
|
|
class Content extends Component {
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {loading, errorMsg, items} = this.props.data;
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
return <span className="loading-icon loading-tip"></span>;
|
|
|
|
} else if (errorMsg) {
|
|
|
|
return <p className="error text-center">{errorMsg}</p>;
|
|
|
|
} else {
|
|
|
|
const emptyTip = (
|
|
|
|
<div className="empty-tip">
|
|
|
|
<h2>{gettext('You have not shared any folders')}</h2>
|
|
|
|
<p>{gettext("You can share a single folder with a registered user if you don't want to share a whole library.")}</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
const table = (
|
2018-12-26 08:07:22 +00:00
|
|
|
<table className="table-hover">
|
2018-11-19 03:53:44 +00:00
|
|
|
<thead>
|
|
|
|
<tr>
|
2018-12-26 08:07:22 +00:00
|
|
|
<th width="4%">{/*icon*/}</th>
|
|
|
|
<th width="34%">{gettext("Name")} <a className="table-sort-op by-name" href="#"><span className="sort-icon icon-caret-down hide"></span>{/* TODO: sort by name */}</a></th>
|
2018-11-19 03:53:44 +00:00
|
|
|
<th width="30%">{gettext("Share To")}</th>
|
2018-12-26 08:07:22 +00:00
|
|
|
<th width="24%">{gettext("Permission")}</th>
|
2018-11-19 03:53:44 +00:00
|
|
|
<th width="8%"></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<TableBody items={items} />
|
|
|
|
</table>
|
|
|
|
);
|
|
|
|
|
|
|
|
return items.length ? table : emptyTip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TableBody extends Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
items: this.props.items
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
document.addEventListener('click', this.clickDocument);
|
|
|
|
}
|
|
|
|
|
|
|
|
clickDocument(e) {
|
|
|
|
// TODO: click 'outside' to hide `<select>`
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
|
|
|
let listItems = this.state.items.map(function(item, index) {
|
|
|
|
return <Item key={index} data={item} />;
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<tbody>{listItems}</tbody>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Item extends Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
share_permission: this.props.data.share_permission,
|
|
|
|
showOpIcon: false,
|
|
|
|
showSelect: false,
|
|
|
|
unshared: false
|
|
|
|
};
|
|
|
|
|
2018-12-26 08:07:22 +00:00
|
|
|
this.permissions = ['rw', 'r'];
|
|
|
|
if (isPro) {
|
|
|
|
this.permissions = ['rw', 'r', 'cloud-edit', 'preview'];
|
|
|
|
}
|
2018-11-19 03:53:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-26 08:07:22 +00:00
|
|
|
onMouseEnter = () => {
|
|
|
|
this.setState({showOpIcon: true});
|
2018-11-19 03:53:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-26 08:07:22 +00:00
|
|
|
onMouseLeave = () => {
|
|
|
|
this.setState({showOpIcon: false});
|
2018-11-19 03:53:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-26 08:07:22 +00:00
|
|
|
unshare = (e) => {
|
2018-11-19 03:53:44 +00:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
const data = this.props.data;
|
|
|
|
const share_type = data.share_type;
|
|
|
|
|
|
|
|
let options = {
|
|
|
|
'p': data.path,
|
|
|
|
};
|
|
|
|
if (share_type == 'personal') {
|
|
|
|
options.share_type = 'user';
|
|
|
|
options.username = data.user_email;
|
|
|
|
} else if (share_type == 'group') {
|
|
|
|
options.share_type = 'group';
|
|
|
|
options.group_id = data.group_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
seafileAPI.unshareFolder(data.repo_id, options)
|
|
|
|
.then((res) => {
|
|
|
|
this.setState({
|
|
|
|
unshared: true
|
|
|
|
});
|
|
|
|
// TODO: show feedback msg
|
|
|
|
// gettext("Successfully deleted 1 item")
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
// TODO: show feedback msg
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-26 08:07:22 +00:00
|
|
|
showSelect = (e) => {
|
2018-11-19 03:53:44 +00:00
|
|
|
e.preventDefault();
|
|
|
|
this.setState({
|
|
|
|
showSelect: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-26 08:07:22 +00:00
|
|
|
changePerm = (permission) => {
|
2018-11-19 03:53:44 +00:00
|
|
|
const data = this.props.data;
|
|
|
|
const share_type = data.share_type;
|
2018-12-26 08:07:22 +00:00
|
|
|
const perm = permission;
|
2018-11-19 03:53:44 +00:00
|
|
|
const postData = {
|
|
|
|
'permission': perm
|
|
|
|
};
|
|
|
|
let options = {
|
|
|
|
'p': data.path,
|
|
|
|
};
|
|
|
|
if (share_type == 'personal') {
|
|
|
|
options.share_type = 'user';
|
|
|
|
options.username = data.user_email;
|
|
|
|
} else if (share_type == 'group') {
|
|
|
|
options.share_type = 'group';
|
|
|
|
options.group_id = data.group_id;
|
|
|
|
}
|
|
|
|
seafileAPI.updateFolderSharePerm(data.repo_id, postData, options).then((res) => {
|
|
|
|
this.setState({
|
|
|
|
share_permission: perm,
|
|
|
|
showSelect: false
|
|
|
|
});
|
|
|
|
// TODO: show feedback msg
|
|
|
|
// gettext("Successfully modified permission")
|
|
|
|
}).catch((error) => {
|
|
|
|
// TODO: show feedback msg
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
|
|
|
if (this.state.unshared) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const data = this.props.data;
|
|
|
|
const share_permission = this.state.share_permission;
|
|
|
|
|
|
|
|
let is_readonly = false;
|
|
|
|
if (share_permission == 'r' || share_permission == 'preview') {
|
|
|
|
is_readonly = true;
|
|
|
|
}
|
|
|
|
data.icon_url = Utils.getFolderIconUrl({
|
|
|
|
is_readonly: is_readonly,
|
|
|
|
size: Utils.isHiDPI() ? 48 : 24
|
|
|
|
});
|
|
|
|
data.icon_title = Utils.getFolderIconTitle({
|
|
|
|
'permission': share_permission
|
|
|
|
});
|
2018-12-26 08:07:22 +00:00
|
|
|
data.url = `${siteRoot}library/${data.repo_id}/${data.repo_name}${Utils.encodePath(data.path)}`;
|
2018-11-19 03:53:44 +00:00
|
|
|
|
|
|
|
let shareTo;
|
|
|
|
const shareType = data.share_type;
|
|
|
|
if (shareType == 'personal') {
|
|
|
|
shareTo = <td title={data.contact_email}>{data.user_name}</td>;
|
|
|
|
} else if (shareType == 'group') {
|
|
|
|
shareTo = <td>{data.group_name}</td>;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.cur_perm = share_permission;
|
2018-12-19 08:07:56 +00:00
|
|
|
data.cur_perm_text = Utils.sharePerms(data.cur_perm);
|
2018-11-19 03:53:44 +00:00
|
|
|
|
|
|
|
let iconVisibility = this.state.showOpIcon ? '' : ' invisible';
|
2018-12-26 08:07:22 +00:00
|
|
|
let unshareIconClassName = 'unshare op-icon sf2-icon-x3' + iconVisibility;
|
2018-11-19 03:53:44 +00:00
|
|
|
|
|
|
|
const item = (
|
2018-12-26 08:07:22 +00:00
|
|
|
<tr onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}>
|
2018-11-19 03:53:44 +00:00
|
|
|
<td><img src={data.icon_url} title={data.icon_title} alt={data.icon_title} width="24" /></td>
|
2018-12-26 08:07:22 +00:00
|
|
|
<td><Link to={data.url}>{data.folder_name}</Link></td>
|
2018-11-19 03:53:44 +00:00
|
|
|
{shareTo}
|
2018-12-26 08:07:22 +00:00
|
|
|
<td>
|
|
|
|
<PermissionEditor
|
|
|
|
isTextMode={true}
|
|
|
|
isEditIconShow={this.state.showOpIcon}
|
|
|
|
currentPermission={data.cur_perm}
|
|
|
|
permissions={this.permissions}
|
|
|
|
onPermissionChangedHandler={this.changePerm}
|
|
|
|
/>
|
|
|
|
</td>
|
2018-11-19 03:53:44 +00:00
|
|
|
<td><a href="#" className={unshareIconClassName} title={gettext('Unshare')} onClick={this.unshare}></a></td>
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ShareAdminFolders extends Component {
|
2018-12-26 08:07:22 +00:00
|
|
|
|
2018-11-19 03:53:44 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
loading: true,
|
|
|
|
errorMsg: '',
|
|
|
|
items: []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
seafileAPI.listSharedFolders().then((res) => {
|
|
|
|
// res: {data: Array(2), status: 200, statusText: "OK", headers: {…}, config: {…}, …}
|
|
|
|
this.setState({
|
|
|
|
loading: false,
|
|
|
|
items: res.data
|
|
|
|
});
|
|
|
|
}).catch((error) => {
|
|
|
|
if (error.response) {
|
|
|
|
if (error.response.status == 403) {
|
|
|
|
this.setState({
|
|
|
|
loading: false,
|
|
|
|
errorMsg: gettext("Permission denied")
|
|
|
|
});
|
|
|
|
location.href = `${loginUrl}?next=${encodeURIComponent(location.href)}`;
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
loading: false,
|
|
|
|
errorMsg: gettext("Error")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
loading: false,
|
|
|
|
errorMsg: gettext("Please check the network.")
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2018-11-26 09:53:18 +00:00
|
|
|
<div className="main-panel-center">
|
|
|
|
<div className="cur-view-container" id="share-admin-libs">
|
|
|
|
<div className="cur-view-path">
|
|
|
|
<h3 className="sf-heading">{gettext("Folders")}</h3>
|
|
|
|
</div>
|
|
|
|
<div className="cur-view-content">
|
|
|
|
<Content data={this.state} />
|
2018-11-26 06:00:32 +00:00
|
|
|
</div>
|
2018-11-19 03:53:44 +00:00
|
|
|
</div>
|
2018-11-26 09:53:18 +00:00
|
|
|
</div>
|
2018-11-19 03:53:44 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ShareAdminFolders;
|