mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-17 15:53:28 +00:00
Shared with all (#2672)
This commit is contained in:
@@ -50,6 +50,7 @@ class CreateRepoDialog extends React.Component {
|
||||
handleKeyPress = (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
this.handleSubmit();
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
|
155
frontend/src/components/dialog/share-repo-dialog.js
Normal file
155
frontend/src/components/dialog/share-repo-dialog.js
Normal file
@@ -0,0 +1,155 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import moment from 'moment';
|
||||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Input } from 'reactstrap';
|
||||
import { gettext, siteRoot } from '../../utils/constants';
|
||||
import { seafileAPI } from '../../utils/seafile-api';
|
||||
import Repo from '../../models/repo';
|
||||
import toaster from '../toast';
|
||||
|
||||
const shareRepoListItemProps = {
|
||||
repo: PropTypes.object.isRequired,
|
||||
onRepoSelect: PropTypes.func.isRequired,
|
||||
onPermissionChange: PropTypes.func.isRequired,
|
||||
}
|
||||
|
||||
class ShareRepoListItem extends React.Component {
|
||||
|
||||
onRepoSelect = (e) => {
|
||||
let isChecked = e.target.checked;
|
||||
this.props.onRepoSelect(this.props.repo, isChecked);
|
||||
}
|
||||
|
||||
onPermissionChange = (e) => {
|
||||
let permission = e.target.value;
|
||||
let repo = this.props.repo;
|
||||
this.props.onPermissionChange(repo, permission);
|
||||
}
|
||||
|
||||
render() {
|
||||
let repo = this.props.repo;
|
||||
return (
|
||||
<tr>
|
||||
<td className="select"><input type="checkbox" className="vam" name="repo" onChange={this.onRepoSelect} /></td>
|
||||
<td className="icon"><img src={siteRoot + 'media/img/lib/48/lib.png'} width="24" alt={gettext('icon')} /></td>
|
||||
<td className="name">{gettext(repo.repo_name)}</td>
|
||||
<td>{moment(repo.last_modified).fromNow()}</td>
|
||||
<td>
|
||||
<Input style={{height: '1.5rem', padding: 0}} type="select" name="select" onChange={this.onPermissionChange} value={repo.sharePermission}>
|
||||
<option value='rw'>{gettext('Read-Write')}</option>
|
||||
<option value='r'>{gettext('Read-Only')}</option>
|
||||
</Input>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ShareRepoListItem.propTypes = shareRepoListItemProps;
|
||||
|
||||
const propTypes = {
|
||||
onRepoSelectedHandler: PropTypes.func.isRequired,
|
||||
onShareRepoDialogClose: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
class ShareRepoDialog extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
repoList: [],
|
||||
currentRepo: null,
|
||||
permission: 'rw',
|
||||
selectedRepoList: [],
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
seafileAPI.listRepos({type: 'mine'}).then(res => {
|
||||
let repoList = res.data.repos.map(item => {
|
||||
let repo = new Repo(item);
|
||||
repo.sharePermission = 'rw';
|
||||
return repo;
|
||||
});
|
||||
this.setState({repoList: repoList});
|
||||
});
|
||||
}
|
||||
|
||||
onRepoSelect = (repo, isChecked) => {
|
||||
let selectedRepoList = [];
|
||||
if (isChecked) {
|
||||
this.state.selectedRepoList.push(repo);
|
||||
selectedRepoList = this.state.selectedRepoList;
|
||||
} else {
|
||||
selectedRepoList = this.state.selectedRepoList.filter(item => {
|
||||
return item.repo_id !== repo.repo_id;
|
||||
});
|
||||
}
|
||||
this.setState({selectedRepoList: selectedRepoList});
|
||||
}
|
||||
|
||||
onPermissionChange = (repo, permission) => {
|
||||
let repoList = this.state.repoList.map(item => {
|
||||
if (item.repo_id === repo.repo_id) {
|
||||
item.sharePermission = permission;
|
||||
}
|
||||
return item;
|
||||
});
|
||||
this.setState({repoList: repoList});
|
||||
}
|
||||
|
||||
handleSubmit = () => {
|
||||
if (this.state.selectedRepoList.length === 0) {
|
||||
toaster.danger(gettext('Place select a library to share.'));
|
||||
return;
|
||||
}
|
||||
|
||||
this.props.onRepoSelectedHandler(this.state.selectedRepoList);
|
||||
this.onCloseDialog();
|
||||
}
|
||||
|
||||
onCloseDialog = () => {
|
||||
this.props.onShareRepoDialogClose();
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Modal isOpen={true}>
|
||||
<ModalHeader toggle={this.toggle}>{gettext('Select libraries to share')}</ModalHeader>
|
||||
<ModalBody className="dialog-list-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th width='4%'>{/* select */}</th>
|
||||
<th width='6%'>{/* icon */}</th>
|
||||
<th width='35%'>{gettext('Name')}</th>
|
||||
<th width='25%'>{gettext('Last Update')}</th>
|
||||
<th width='30%'>{gettext('Permission')}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{this.state.repoList.map((repo, index) => {
|
||||
return (
|
||||
<ShareRepoListItem
|
||||
key={index}
|
||||
repo={repo}
|
||||
onRepoSelect={this.onRepoSelect}
|
||||
onPermissionChange={this.onPermissionChange}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button color="secondary" onClick={this.onCloseDialog}>{gettext('Close')}</Button>
|
||||
<Button color="primary" onClick={this.handleSubmit}>{gettext('Submit')}</Button>
|
||||
</ModalFooter>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ShareRepoDialog.propTypes = propTypes;
|
||||
|
||||
export default ShareRepoDialog;
|
@@ -191,7 +191,7 @@ class DirView extends React.Component {
|
||||
seafileAPI.moveDir(repoID, destRepo.repo_id, moveToDirentPath, this.state.path, dirName).then(() => {
|
||||
|
||||
let direntList = this.deleteItem(dirent);
|
||||
this.setState(direntList);
|
||||
this.setState({direntList: direntList});
|
||||
|
||||
let message = gettext('Successfully moved %(name)s.');
|
||||
message = message.replace('%(name)s', dirName);
|
||||
|
@@ -145,10 +145,10 @@ class MainSideNav extends React.Component {
|
||||
</li>
|
||||
{ canViewOrg &&
|
||||
<li className="nav-item" onClick={() => this.tabItemClick('org')}>
|
||||
<a href={ siteRoot + '#org/' } className={`nav-link ellipsis ${this.getActiveClass('org')}`} title={gettext('Shared with all')}>
|
||||
<Link to={ siteRoot + 'org/' } className={`nav-link ellipsis ${this.getActiveClass('org')}`} title={gettext('Shared with all')}>
|
||||
<span className="sf2-icon-organization" aria-hidden="true"></span>
|
||||
<span className="nav-text">{gettext('Shared with all')}</span>
|
||||
</a>
|
||||
</Link>
|
||||
</li>
|
||||
}
|
||||
<li className="nav-item flex-column" id="group-nav">
|
||||
|
@@ -4,12 +4,13 @@ import moment from 'moment';
|
||||
import { Dropdown, DropdownMenu, DropdownToggle, DropdownItem } from 'reactstrap';
|
||||
import { Link } from '@reach/router';
|
||||
import { Utils } from '../../utils/utils';
|
||||
import { gettext, siteRoot, isPro, username, folderPermEnabled } from '../../utils/constants';
|
||||
import { gettext, siteRoot, isPro, username, folderPermEnabled, isSystemStaff } from '../../utils/constants';
|
||||
import ModalPotal from '../../components/modal-portal';
|
||||
import ShareDialog from '../../components/dialog/share-dialog';
|
||||
|
||||
const propTypes = {
|
||||
currentGroup: PropTypes.object,
|
||||
libraryType: PropTypes.string,
|
||||
repo: PropTypes.object.isRequired,
|
||||
isItemFreezed: PropTypes.bool.isRequired,
|
||||
onFreezedItem: PropTypes.func.isRequired,
|
||||
@@ -152,7 +153,7 @@ class SharedRepoListItem extends React.Component {
|
||||
generatorOperations = () => {
|
||||
let { repo, currentGroup } = this.props;
|
||||
//todo this have a bug; use current api is not return admins param;
|
||||
let isStaff = currentGroup.admins && currentGroup.admins.indexOf(username) > -1; //for group repolist;
|
||||
let isStaff = currentGroup && currentGroup.admins && currentGroup.admins.indexOf(username) > -1; //for group repolist;
|
||||
let isRepoOwner = repo.owner_email === username;
|
||||
let isAdmin = repo.is_admin;
|
||||
let operations = [];
|
||||
@@ -189,10 +190,18 @@ class SharedRepoListItem extends React.Component {
|
||||
}
|
||||
|
||||
generatorMobileMenu = () => {
|
||||
let operations = this.generatorOperations();
|
||||
if (this.isDeparementOnwerGroupMember) {
|
||||
operations.unshift('unshare');
|
||||
operations.unshift('share');
|
||||
let operations = [];
|
||||
if (this.props.libraryType && this.props.libraryType === 'public') {
|
||||
let isRepoOwner = this.props.repo.owner_email === username;
|
||||
if (isSystemStaff || isRepoOwner) {
|
||||
operations.push('unshare');
|
||||
}
|
||||
} else {
|
||||
operations = this.generatorOperations();
|
||||
if (this.isDeparementOnwerGroupMember) {
|
||||
operations.unshift('unshare');
|
||||
operations.unshift('share');
|
||||
}
|
||||
}
|
||||
return (
|
||||
<Dropdown isOpen={this.state.isItemMenuShow} toggle={this.toggleOperationMenu}>
|
||||
@@ -219,9 +228,17 @@ class SharedRepoListItem extends React.Component {
|
||||
}
|
||||
|
||||
generatorPCMenu = () => {
|
||||
// scene one: (share, delete, itemToggle and other operations);
|
||||
// scene two: (share, unshare), (share), (unshare)
|
||||
let operations = this.generatorOperations();
|
||||
let operations = [];
|
||||
if (this.props.libraryType && this.props.libraryType === 'public') {
|
||||
let isRepoOwner = this.props.repo.owner_email === username;
|
||||
if (isSystemStaff || isRepoOwner) {
|
||||
operations.push('unshare');
|
||||
}
|
||||
} else {
|
||||
// scene one: (share, delete, itemToggle and other operations);
|
||||
// scene two: (share, unshare), (share), (unshare)
|
||||
operations = this.generatorOperations();
|
||||
}
|
||||
const shareOperation = <a href="#" className="sf2-icon-share sf2-x op-icon" title={gettext("Share")} onClick={this.onItemShare}></a>;
|
||||
const unshareOperation = <a href="#" className="sf2-icon-x3 sf2-x op-icon" title={gettext("Unshare")} onClick={this.onItemUnshare}></a>
|
||||
const deleteOperation = <a href="#" className="sf2-icon-delete sf2-x op-icon" title={gettext('Delete')} onClick={this.onItemDelete}></a>;
|
||||
|
@@ -4,9 +4,10 @@ import { gettext } from '../../utils/constants';
|
||||
import SharedRepoListItem from './shared-repo-list-item';
|
||||
|
||||
const propTypes = {
|
||||
libraryType: PropTypes.string,
|
||||
currentGroup: PropTypes.object,
|
||||
repoList: PropTypes.array.isRequired,
|
||||
isShowTableThread: PropTypes.bool,
|
||||
repoList: PropTypes.array.isRequired,
|
||||
onItemUnshare: PropTypes.func.isRequired,
|
||||
onItemDelete: PropTypes.func.isRequired,
|
||||
};
|
||||
@@ -34,6 +35,7 @@ class SharedRepoListView extends React.Component {
|
||||
<SharedRepoListItem
|
||||
key={repo.repo_id}
|
||||
repo={repo}
|
||||
libraryType={this.props.libraryType}
|
||||
currentGroup={this.props.currentGroup}
|
||||
isItemFreezed={this.state.isItemFreezed}
|
||||
onFreezedItem={this.onFreezedItem}
|
||||
|
Reference in New Issue
Block a user