mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-13 22:01:06 +00:00
[share admin] libraries: added support for mobile (#3981)
* and 'bugfix & improvement'
This commit is contained in:
65
frontend/src/components/dialog/perm-select.js
Normal file
65
frontend/src/components/dialog/perm-select.js
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { Modal, ModalBody } from 'reactstrap';
|
||||||
|
import { Utils } from '../../utils/utils';
|
||||||
|
|
||||||
|
const propTypes = {
|
||||||
|
currentPerm: PropTypes.string.isRequired,
|
||||||
|
permissions: PropTypes.array.isRequired,
|
||||||
|
changePerm: PropTypes.func.isRequired,
|
||||||
|
toggleDialog: PropTypes.func.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
class PermSelect extends React.Component {
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
currentOption: this.props.currentPerm
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
switchOption = (e) => {
|
||||||
|
if (!e.target.checked) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentOption = e.target.value;
|
||||||
|
this.setState({
|
||||||
|
currentOption: currentOption
|
||||||
|
});
|
||||||
|
|
||||||
|
this.props.changePerm(currentOption);
|
||||||
|
this.props.toggleDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const options = this.props.permissions;
|
||||||
|
const { currentOption } = this.state;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal isOpen={true} toggle={this.props.toggleDialog}>
|
||||||
|
<ModalBody>
|
||||||
|
{options.map((item, index) => {
|
||||||
|
return (
|
||||||
|
<div className="d-flex" key={index}>
|
||||||
|
<input id={`option-${index}`} className="mt-1" type="radio" name="permission" value={item} checked={currentOption == item} onChange={this.switchOption} />
|
||||||
|
<label htmlFor={`option-${index}`} className="ml-2">
|
||||||
|
{Utils.sharePerms(item)}
|
||||||
|
<p className="text-secondary small m-0">
|
||||||
|
{Utils.sharePermsExplanation(item)}
|
||||||
|
</p>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ModalBody>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PermSelect.propTypes = propTypes;
|
||||||
|
|
||||||
|
export default PermSelect;
|
@@ -5,15 +5,6 @@
|
|||||||
.activity-details:hover {
|
.activity-details:hover {
|
||||||
color: #333;
|
color: #333;
|
||||||
}
|
}
|
||||||
.mobile-activity-op {
|
|
||||||
display: inline-block;
|
|
||||||
margin: 0 0 .2em .8em;
|
|
||||||
padding: 0 .5em;
|
|
||||||
background: #ffbd6f;
|
|
||||||
border-radius: 2px;
|
|
||||||
color: #fff;
|
|
||||||
font-size: 0.75rem;
|
|
||||||
}
|
|
||||||
.mobile-activity-time {
|
.mobile-activity-time {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin-bottom: .2em;
|
margin-bottom: .2em;
|
||||||
|
@@ -13,7 +13,7 @@ class SharedRepoInfo {
|
|||||||
this.is_admin = object.is_admin;
|
this.is_admin = object.is_admin;
|
||||||
this.user_name = object.user_name;
|
this.user_name = object.user_name;
|
||||||
this.user_email = object.user_email;
|
this.user_email = object.user_email;
|
||||||
this.contact_email = this.contact_email;
|
this.contact_email = object.contact_email;
|
||||||
} else if (this.share_type === 'group') {
|
} else if (this.share_type === 'group') {
|
||||||
this.is_admin = object.is_admin;
|
this.is_admin = object.is_admin;
|
||||||
this.group_id = object.group_id;
|
this.group_id = object.group_id;
|
||||||
|
@@ -269,7 +269,7 @@ class ActivityItem extends Component {
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href={userProfileURL}>{item.author_name}</a>
|
<a href={userProfileURL}>{item.author_name}</a>
|
||||||
<span className="mobile-activity-op">{op}</span>
|
<span className="item-meta-info-highlighted">{op}</span>
|
||||||
<br />{details}
|
<br />{details}
|
||||||
</td>
|
</td>
|
||||||
<td className="text-right align-top">
|
<td className="text-right align-top">
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Fragment, Component } from 'react';
|
||||||
import { Link } from '@reach/router';
|
import { Link } from '@reach/router';
|
||||||
|
import { Dropdown, DropdownToggle, DropdownItem } from 'reactstrap';
|
||||||
import { seafileAPI } from '../../utils/seafile-api';
|
import { seafileAPI } from '../../utils/seafile-api';
|
||||||
import { gettext, siteRoot, loginUrl, isPro } from '../../utils/constants';
|
import { gettext, siteRoot, loginUrl, isPro } from '../../utils/constants';
|
||||||
import { Utils } from '../../utils/utils';
|
import { Utils } from '../../utils/utils';
|
||||||
@@ -7,6 +8,7 @@ import toaster from '../../components/toast';
|
|||||||
import EmptyTip from '../../components/empty-tip';
|
import EmptyTip from '../../components/empty-tip';
|
||||||
import SharePermissionEditor from '../../components/select-editor/share-permission-editor';
|
import SharePermissionEditor from '../../components/select-editor/share-permission-editor';
|
||||||
import SharedRepoInfo from '../../models/shared-repo-info';
|
import SharedRepoInfo from '../../models/shared-repo-info';
|
||||||
|
import PermSelect from '../../components/dialog/perm-select';
|
||||||
|
|
||||||
class Content extends Component {
|
class Content extends Component {
|
||||||
|
|
||||||
@@ -36,9 +38,11 @@ class Content extends Component {
|
|||||||
const sortByName = sortBy == 'name';
|
const sortByName = sortBy == 'name';
|
||||||
const sortIcon = sortOrder == 'asc' ? <span className="fas fa-caret-up"></span> : <span className="fas fa-caret-down"></span>;
|
const sortIcon = sortOrder == 'asc' ? <span className="fas fa-caret-up"></span> : <span className="fas fa-caret-down"></span>;
|
||||||
|
|
||||||
|
const isDesktop = Utils.isDesktop();
|
||||||
const table = (
|
const table = (
|
||||||
<table className="table-hover">
|
<table className={`table-hover ${isDesktop ? '': 'table-thead-hidden'}`}>
|
||||||
<thead>
|
<thead>
|
||||||
|
{isDesktop ? (
|
||||||
<tr>
|
<tr>
|
||||||
<th width="4%">{/*icon*/}</th>
|
<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="34%"><a className="d-block table-sort-op" href="#" onClick={this.sortByName}>{gettext('Name')} {sortByName && sortIcon}</a></th>
|
||||||
@@ -46,10 +50,22 @@ class Content extends Component {
|
|||||||
<th width="24%">{gettext('Permission')}</th>
|
<th width="24%">{gettext('Permission')}</th>
|
||||||
<th width="8%"></th>
|
<th width="8%"></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
) : (
|
||||||
|
<tr>
|
||||||
|
<th width="12%"></th>
|
||||||
|
<th width="80%"></th>
|
||||||
|
<th width="8%"></th>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{items.map((item, index) => {
|
{items.map((item, index) => {
|
||||||
return (<Item key={index} item={item} unshareFolder={this.props.unshareFolder}/>);
|
return (<Item
|
||||||
|
key={index}
|
||||||
|
isDesktop={isDesktop}
|
||||||
|
item={item}
|
||||||
|
unshareItem={this.props.unshareItem}
|
||||||
|
/>);
|
||||||
})}
|
})}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -69,21 +85,40 @@ class Item extends Component {
|
|||||||
this.state = {
|
this.state = {
|
||||||
share_permission: item.share_permission,
|
share_permission: item.share_permission,
|
||||||
is_admin: item.is_admin,
|
is_admin: item.is_admin,
|
||||||
showOpIcon: false,
|
isOpIconShown: false,
|
||||||
|
isOpMenuOpen: false, // for mobile
|
||||||
|
isPermSelectDialogOpen: false, // for mobile
|
||||||
unshared: false
|
unshared: false
|
||||||
};
|
};
|
||||||
this.permissions = ['rw', 'r'];
|
let permissions = ['rw', 'r'];
|
||||||
if (isPro) {
|
this.permissions = permissions;
|
||||||
this.permissions = ['rw', 'r', 'cloud-edit', 'preview'];
|
this.showAdmin = isPro && (item.share_type !== 'public');
|
||||||
|
if (this.showAdmin) {
|
||||||
|
permissions.push('admin');
|
||||||
}
|
}
|
||||||
|
if (isPro) {
|
||||||
|
permissions.push('cloud-edit', 'preview');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleOpMenu = () => {
|
||||||
|
this.setState({
|
||||||
|
isOpMenuOpen: !this.state.isOpMenuOpen
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
togglePermSelectDialog = () => {
|
||||||
|
this.setState({
|
||||||
|
isPermSelectDialogOpen: !this.state.isPermSelectDialogOpen
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onMouseEnter = () => {
|
onMouseEnter = () => {
|
||||||
this.setState({showOpIcon: true});
|
this.setState({isOpIconShown: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
onMouseLeave = () => {
|
onMouseLeave = () => {
|
||||||
this.setState({showOpIcon: false});
|
this.setState({isOpIconShown: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
changePerm = (permission) => {
|
changePerm = (permission) => {
|
||||||
@@ -97,8 +132,6 @@ class Item extends Component {
|
|||||||
options.user = item.user_email;
|
options.user = item.user_email;
|
||||||
} else if (share_type == 'group') {
|
} else if (share_type == 'group') {
|
||||||
options.group_id = item.group_id;
|
options.group_id = item.group_id;
|
||||||
} else if (share_type === 'public') {
|
|
||||||
// nothing todo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
seafileAPI.updateRepoSharePerm(item.repo_id, options).then(() => {
|
seafileAPI.updateRepoSharePerm(item.repo_id, options).then(() => {
|
||||||
@@ -106,72 +139,102 @@ class Item extends Component {
|
|||||||
share_permission: permission == 'admin' ? 'rw' : permission,
|
share_permission: permission == 'admin' ? 'rw' : permission,
|
||||||
is_admin: permission == 'admin',
|
is_admin: permission == 'admin',
|
||||||
});
|
});
|
||||||
|
toaster.success(gettext('Successfully modified permission.'));
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
let errMessage = Utils.getErrorMsg(error);
|
let errMessage = Utils.getErrorMsg(error);
|
||||||
toaster.danger(errMessage);
|
toaster.danger(errMessage);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
unshare = () => {
|
unshare = (e) => {
|
||||||
this.props.unshareFolder(this.props.item);
|
e.preventDefault();
|
||||||
}
|
this.props.unshareItem(this.props.item);
|
||||||
|
|
||||||
getRepoParams = () => {
|
|
||||||
let item = this.props.item;
|
|
||||||
|
|
||||||
let iconUrl = Utils.getLibIconUrl(item);
|
|
||||||
let iconTitle = Utils.getLibIconTitle(item);
|
|
||||||
let repoUrl = `${siteRoot}library/${item.repo_id}/${item.repo_name}/`;
|
|
||||||
|
|
||||||
return { iconUrl, iconTitle, repoUrl };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
||||||
let { iconUrl, iconTitle, repoUrl } = this.getRepoParams();
|
|
||||||
let item = this.props.item;
|
let item = this.props.item;
|
||||||
let { share_permission, is_admin } = this.state;
|
let iconUrl = Utils.getLibIconUrl(item);
|
||||||
|
let iconTitle = Utils.getLibIconTitle(item);
|
||||||
|
let repoUrl = `${siteRoot}library/${item.repo_id}/${encodeURIComponent(item.repo_name)}/`;
|
||||||
|
|
||||||
|
let { share_permission, is_admin, isOpIconShown, isPermSelectDialogOpen } = this.state;
|
||||||
|
|
||||||
let shareTo;
|
let shareTo;
|
||||||
const shareType = item.share_type;
|
const shareType = item.share_type;
|
||||||
if (shareType == 'personal') {
|
if (shareType == 'personal') {
|
||||||
shareTo = <td title={item.contact_email}>{item.user_name}</td>;
|
shareTo = item.user_name;
|
||||||
} else if (shareType == 'group') {
|
} else if (shareType == 'group') {
|
||||||
shareTo = <td>{item.group_name}</td>;
|
shareTo = item.group_name;
|
||||||
} else if (shareType == 'public') {
|
} else if (shareType == 'public') {
|
||||||
shareTo = <td>{gettext('all members')}</td>;
|
shareTo = gettext('all members');
|
||||||
}
|
}
|
||||||
|
|
||||||
// show 'admin' perm or not
|
if (this.showAdmin && is_admin) {
|
||||||
let showAdmin = isPro && (item.share_type !== 'public');
|
|
||||||
if (showAdmin && is_admin) {
|
|
||||||
share_permission = 'admin';
|
share_permission = 'admin';
|
||||||
}
|
}
|
||||||
|
|
||||||
let iconVisibility = this.state.showOpIcon ? '' : ' invisible';
|
const desktopItem = (
|
||||||
let unshareIconClassName = 'unshare action-icon sf2-icon-x3' + iconVisibility;
|
|
||||||
|
|
||||||
if (showAdmin && this.permissions.indexOf('admin') === -1) {
|
|
||||||
this.permissions.splice(2, 0, 'admin'); // add a item after 'r' permission;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<tr onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}>
|
<tr onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}>
|
||||||
<td><img src={iconUrl} title={iconTitle} alt={iconTitle} width="24" /></td>
|
<td><img src={iconUrl} title={iconTitle} alt={iconTitle} width="24" /></td>
|
||||||
<td><Link to={repoUrl}>{item.repo_name}</Link></td>
|
<td><Link to={repoUrl}>{item.repo_name}</Link></td>
|
||||||
{shareTo}
|
<td>
|
||||||
|
{item.share_type == 'personal' ? <span title={item.contact_email}>{shareTo}</span> : shareTo}
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<SharePermissionEditor
|
<SharePermissionEditor
|
||||||
isTextMode={true}
|
isTextMode={true}
|
||||||
isEditIconShow={this.state.showOpIcon}
|
isEditIconShow={this.state.isOpIconShown}
|
||||||
currentPermission={share_permission}
|
currentPermission={share_permission}
|
||||||
permissions={this.permissions}
|
permissions={this.permissions}
|
||||||
onPermissionChanged={this.changePerm}
|
onPermissionChanged={this.changePerm}
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
<td><a href="#" className={unshareIconClassName} title={gettext('Unshare')} onClick={this.unshare}></a></td>
|
<td><a href="#" className={`action-icon sf2-icon-x3 ${isOpIconShown ? '': 'invisible'}`} title={gettext('Unshare')} onClick={this.unshare}></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const mobileItem = (
|
||||||
|
<Fragment>
|
||||||
|
<tr>
|
||||||
|
<td><img src={iconUrl} title={iconTitle} alt={iconTitle} width="24" /></td>
|
||||||
|
<td>
|
||||||
|
<Link to={repoUrl}>{item.repo_name}</Link>
|
||||||
|
<span className="item-meta-info-highlighted">{Utils.sharePerms(share_permission)}</span>
|
||||||
|
<br />
|
||||||
|
<span className="item-meta-info">{`${gettext('Share To:')} ${shareTo}`}</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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +284,7 @@ class ShareAdminLibraries extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
unshareFolder = (item) => {
|
unshareItem = (item) => {
|
||||||
const share_type = item.share_type;
|
const share_type = item.share_type;
|
||||||
let options = {
|
let options = {
|
||||||
'share_type': share_type
|
'share_type': share_type
|
||||||
@@ -282,7 +345,7 @@ class ShareAdminLibraries extends Component {
|
|||||||
sortBy={this.state.sortBy}
|
sortBy={this.state.sortBy}
|
||||||
sortOrder={this.state.sortOrder}
|
sortOrder={this.state.sortOrder}
|
||||||
sortItems={this.sortItems}
|
sortItems={this.sortItems}
|
||||||
unshareFolder={this.unshareFolder}
|
unshareItem={this.unshareItem}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -33,6 +33,10 @@ export const Utils = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isDesktop: function() {
|
||||||
|
return window.innerWidth >= 768;
|
||||||
|
},
|
||||||
|
|
||||||
FILEEXT_ICON_MAP: {
|
FILEEXT_ICON_MAP: {
|
||||||
|
|
||||||
// text file
|
// text file
|
||||||
|
@@ -1134,6 +1134,16 @@ a.table-sort-op:focus {
|
|||||||
color: #666;
|
color: #666;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.item-meta-info-highlighted {
|
||||||
|
display: inline-block;
|
||||||
|
margin: 0 0 .2em .8em;
|
||||||
|
padding: 0 .5em;
|
||||||
|
background: #ffbd6f;
|
||||||
|
border-radius: 2px;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
.mobile-operation-menu-bg-layer {
|
.mobile-operation-menu-bg-layer {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
left: 0;
|
left: 0;
|
||||||
|
Reference in New Issue
Block a user