1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 23:20:51 +00:00

[share admin] rewrote it with react (#2538)

This commit is contained in:
llj
2018-11-19 11:53:44 +08:00
committed by Daniel Pan
parent 6b364b9a63
commit e2dc2d070a
11 changed files with 1225 additions and 16 deletions

View File

@@ -11,6 +11,10 @@ import FilesActivities from './pages/dashboard/files-activities';
import Starred from './pages/starred/starred';
import LinkedDevices from './pages/linked-devices/linked-devices';
import editUtilties from './utils/editor-utilties';
import ShareAdminLibraries from './pages/share-admin/libraries';
import ShareAdminFolders from './pages/share-admin/folders';
import ShareAdminShareLinks from './pages/share-admin/share-links';
import ShareAdminUploadLinks from './pages/share-admin/upload-links';
import 'seafile-ui';
import './assets/css/fa-solid.css';
@@ -88,6 +92,10 @@ class App extends Component {
</DraftsView>
<Starred path={siteRoot + 'starred'} />
<LinkedDevices path={siteRoot + 'linked-devices'} />
<ShareAdminLibraries path={siteRoot + 'share-admin-libs'} />
<ShareAdminFolders path={siteRoot + 'share-admin-folders'} />
<ShareAdminShareLinks path={siteRoot + 'share-admin-share-links'} />
<ShareAdminUploadLinks path={siteRoot + 'share-admin-upload-links'} />
</Router>
</MainPanel>
</div>

View File

@@ -95,22 +95,22 @@ class MainSideNav extends React.Component {
return (
<ul className={`${this.state.sharedExtended ? 'side-panel-slide' : 'side-panel-slide-up'}`} style={style} >
<li className={this.state.currentTab === 'share-admin-libs' ? 'tab-cur' : ''}>
<a href={siteRoot + '#share-admin-libs/'} className="ellipsis" title={gettext('Libraries')} onClick={() => this.tabItemClick('share-admin-libs')}>
<Link to={siteRoot + 'share-admin-libs/'} className="ellipsis" title={gettext('Libraries')} onClick={() => this.tabItemClick('share-admin-libs')}>
<span aria-hidden="true" className="sharp">#</span>
{gettext('Libraries')}
</a>
</Link>
</li>
<li className={this.state.currentTab === 'share-admin-folders' ? 'tab-cur' : ''}>
<a href={siteRoot + '#share-admin-folders/'} className="ellipsis" title={gettext('Folders')} onClick={() => this.tabItemClick('share-admin-folders')}>
<Link to={siteRoot + 'share-admin-folders/'} className="ellipsis" title={gettext('Folders')} onClick={() => this.tabItemClick('share-admin-folders')}>
<span aria-hidden="true" className="sharp">#</span>
{gettext('Folders')}
</a>
</Link>
</li>
<li className={this.state.currentTab === 'share-admin-share-links' ? 'tab-cur' : ''}>
<a href={siteRoot + '#share-admin-share-links/'} className="ellipsis" title={gettext('Links')} onClick={() => this.tabItemClick('share-admin-share-links')}>
<Link to={siteRoot + 'share-admin-share-links/'} className="ellipsis" title={gettext('Links')} onClick={() => this.tabItemClick('share-admin-share-links')}>
<span aria-hidden="true" className="sharp">#</span>
{gettext('Links')}
</a>
</Link>
</li>
</ul>
);

View File

@@ -0,0 +1,296 @@
import React, { Component } from 'react';
import { seafileAPI } from '../../utils/seafile-api';
import { Utils } from '../../utils/utils';
import { gettext, siteRoot, loginUrl, isPro } from '../../utils/constants';
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 = (
<table className="table table-hover table-vcenter">
<thead>
<tr>
<th width="7%">{/*icon*/}</th>
<th width="30%">{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>
<th width="30%">{gettext("Share To")}</th>
<th width="25%">{gettext("Permission")}</th>
<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
};
this.handleMouseOver = this.handleMouseOver.bind(this);
this.handleMouseOut = this.handleMouseOut.bind(this);
this.showSelect = this.showSelect.bind(this);
this.changePerm = this.changePerm.bind(this);
this.unshare = this.unshare.bind(this);
}
handleMouseOver() {
this.setState({
showOpIcon: true
});
}
handleMouseOut() {
this.setState({
showOpIcon: false
});
}
unshare(e) {
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
});
}
showSelect(e) {
e.preventDefault();
this.setState({
showSelect: true
});
}
changePerm(e) {
const data = this.props.data;
const share_type = data.share_type;
const perm = e.target.value;
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
});
data.url = `${siteRoot}#my-libs/lib/${data.repo_id}${Utils.encodePath(data.path)}`;
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;
data.cur_perm_text = Utils.sharePerms[data.cur_perm];
let iconVisibility = this.state.showOpIcon ? '' : ' invisible';
let editIconClassName = 'perm-edit-icon sf2-icon-edit op-icon' + iconVisibility;
let unshareIconClassName = 'unshare op-icon sf2-icon-delete' + iconVisibility;
let permOption = function(options) {
return <option value={options.perm}>{Utils.sharePerms[options.perm]}</option>;
};
const item = (
<tr onMouseOver={this.handleMouseOver} onMouseOut={this.handleMouseOut}>
<td><img src={data.icon_url} title={data.icon_title} alt={data.icon_title} width="24" /></td>
<td><a href={data.url}>{data.folder_name}</a></td>
{shareTo}
{
this.state.showSelect ? (
<td>
<select className="form-control" defaultValue={data.cur_perm} onChange={this.changePerm}>
{permOption({perm: 'rw'})}
{permOption({perm: 'r'})}
{isPro ? permOption({perm: 'cloud-edit'}) : ''}
{isPro ? permOption({perm: 'preview'}) : ''}
</select>
</td>
) : (
<td>
<span>{data.cur_perm_text}</span>
<a href="#" title={gettext('Edit')} className={editIconClassName} onClick={this.showSelect}></a>
</td>
)
}
<td><a href="#" className={unshareIconClassName} title={gettext('Unshare')} onClick={this.unshare}></a></td>
</tr>
);
return item;
}
}
class ShareAdminFolders extends Component {
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 (
<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} />
</div>
</div>
);
}
}
export default ShareAdminFolders;

View File

@@ -0,0 +1,303 @@
import React, { Component } from 'react';
import { seafileAPI } from '../../utils/seafile-api';
import { Utils } from '../../utils/utils';
import { gettext, siteRoot, loginUrl, isPro } from '../../utils/constants';
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 libraries')}</h2>
<p>{gettext("You can share libraries with your friends and colleagues by clicking the share icon of your own libraries in your home page or creating a new library in groups you are in.")}</p>
</div>
);
const table = (
<table className="table table-hover table-vcenter">
<thead>
<tr>
<th width="7%">{/*icon*/}</th>
<th width="30%">{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>
<th width="30%">{gettext("Share To")}</th>
<th width="25%">{gettext("Permission")}</th>
<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,
is_admin: this.props.data.is_admin,
showOpIcon: false,
showSelect: false,
unshared: false
};
this.handleMouseOver = this.handleMouseOver.bind(this);
this.handleMouseOut = this.handleMouseOut.bind(this);
this.showSelect = this.showSelect.bind(this);
this.changePerm = this.changePerm.bind(this);
this.unshare = this.unshare.bind(this);
}
handleMouseOver() {
this.setState({
showOpIcon: true
});
}
handleMouseOut() {
this.setState({
showOpIcon: false
});
}
unshare(e) {
e.preventDefault();
const data = this.props.data;
const share_type = data.share_type;
let options = {
'share_type': share_type
};
if (share_type == 'personal') {
options.user = data.user_email;
} else if (share_type == 'group') {
options.group_id = data.group_id;
}
seafileAPI.unshareRepo(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
});
}
showSelect(e) {
e.preventDefault();
this.setState({
showSelect: true
});
}
changePerm(e) {
const data = this.props.data;
const share_type = data.share_type;
const perm = e.target.value;
let options = {
'share_type': share_type,
'permission': perm
};
if (share_type == 'personal') {
options.user = data.user_email;
} else if (share_type == 'group') {
options.group_id = data.group_id;
}
seafileAPI.updateRepoSharePerm(data.repo_id, options).then((res) => {
this.setState({
share_permission: perm == 'admin' ? 'rw' : perm,
is_admin: perm == 'admin',
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;
const is_admin = this.state.is_admin;
let is_readonly = false;
if (share_permission == 'r' || share_permission == 'preview') {
is_readonly = true;
}
data.icon_url = Utils.getLibIconUrl({
is_encrypted: data.encrypted,
is_readonly: is_readonly,
size: Utils.isHiDPI() ? 48 : 24
});
data.icon_title = Utils.getLibIconTitle({
'encrypted': data.encrypted,
'is_admin': is_admin,
'permission': share_permission
});
data.url = `${siteRoot}#my-libs/lib/${data.repo_id}/`;
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>;
} else if (shareType == 'public') {
shareTo = <td>{gettext('all members')}</td>;
}
data.cur_perm = share_permission;
// show 'admin' perm or not
data.show_admin = isPro && data.share_type != 'public';
if (data.show_admin && is_admin) {
data.cur_perm = 'admin';
}
data.cur_perm_text = Utils.sharePerms[data.cur_perm];
let iconVisibility = this.state.showOpIcon ? '' : ' invisible';
let editIconClassName = 'perm-edit-icon sf2-icon-edit op-icon' + iconVisibility;
let unshareIconClassName = 'unshare op-icon sf2-icon-delete' + iconVisibility;
let permOption = function(options) {
return <option value={options.perm}>{Utils.sharePerms[options.perm]}</option>;
};
const item = (
<tr onMouseOver={this.handleMouseOver} onMouseOut={this.handleMouseOut}>
<td><img src={data.icon_url} title={data.icon_title} alt={data.icon_title} width="24" /></td>
<td><a href={data.url}>{data.repo_name}</a></td>
{shareTo}
{
this.state.showSelect ? (
<td>
<select className="form-control" defaultValue={data.cur_perm} onChange={this.changePerm}>
{permOption({perm: 'rw'})}
{permOption({perm: 'r'})}
{data.show_admin ? permOption({perm: 'admin'}) : ''}
{isPro ? permOption({perm: 'cloud-edit'}) : ''}
{isPro ? permOption({perm: 'preview'}) : ''}
</select>
</td>
) : (
<td>
<span>{data.cur_perm_text}</span>
<a href="#" title={gettext('Edit')} className={editIconClassName} onClick={this.showSelect}></a>
</td>
)
}
<td><a href="#" className={unshareIconClassName} title={gettext('Unshare')} onClick={this.unshare}></a></td>
</tr>
);
return item;
}
}
class ShareAdminLibraries extends Component {
constructor(props) {
super(props);
this.state = {
loading: true,
errorMsg: '',
items: []
};
}
componentDidMount() {
seafileAPI.listSharedLibraries().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 (
<div className="cur-view-container" id="share-admin-libs">
<div className="cur-view-path">
<h3 className="sf-heading">{gettext("Libraries")}</h3>
</div>
<div className="cur-view-content">
<Content data={this.state} />
</div>
</div>
);
}
}
export default ShareAdminLibraries;

View File

@@ -0,0 +1,259 @@
import React, { Component } from 'react';
import { Link } from '@reach/router';
import moment from 'moment';
import { Modal, ModalHeader, ModalBody } from 'reactstrap';
import { seafileAPI } from '../../utils/seafile-api';
import { Utils } from '../../utils/utils';
import { gettext, siteRoot, loginUrl, isPro, canGenerateUploadLink } from '../../utils/constants';
class Content extends Component {
constructor(props) {
super(props);
this.state = {
modalOpen: false,
modalContent: ''
};
this.toggleModal = this.toggleModal.bind(this);
this.showModal = this.showModal.bind(this);
}
// required by `Modal`, and can only set the 'open' state
toggleModal() {
this.setState({
modalOpen: !this.state.modalOpen
});
}
showModal(options) {
this.toggleModal();
this.setState({
modalContent: options.content
});
}
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 don't have any share links")}</h2>
<p>{gettext("You can generate a share link for a folder or a file. Anyone who receives this link can view the folder or the file online.")}</p>
</div>
);
const table = (
<React.Fragment>
<table className="table table-hover table-vcenter">
<thead>
<tr>
<th width="10%">{/*icon*/}</th>
<th width="30%">{gettext("Name")}<a className="table-sort-op by-name" href="#"> <span className="sort-icon icon-caret-up"></span></a></th>{/* TODO:sort */}
<th width="24%">{gettext("Library")}</th>
<th width="12%">{gettext("Visits")}</th>
<th width="14%">{gettext("Expiration")}<a className="table-sort-op by-time" href="#"> <span className="sort-icon icon-caret-down hide" aria-hidden="true"></span></a></th>{/*TODO:sort*/}
<th width="10%">{/*Operations*/}</th>
</tr>
</thead>
<TableBody items={items} showModal={this.showModal} />
</table>
<Modal isOpen={this.state.modalOpen} toggle={this.toggleModal} centered={true}>
<ModalHeader toggle={this.toggleModal}>{gettext('Link')}</ModalHeader>
<ModalBody>
{this.state.modalContent}
</ModalBody>
</Modal>
</React.Fragment>
);
return items.length ? table : emptyTip;
}
}
}
class TableBody extends Component {
constructor(props) {
super(props);
this.state = {
//items: this.props.items
};
}
render() {
let listItems = this.props.items.map(function(item, index) {
return <Item key={index} data={item} showModal={this.props.showModal} />;
}, this);
return (
<tbody>{listItems}</tbody>
);
}
}
class Item extends Component {
constructor(props) {
super(props);
this.state = {
showOpIcon: false,
deleted: false
};
this.handleMouseOver = this.handleMouseOver.bind(this);
this.handleMouseOut = this.handleMouseOut.bind(this);
this.viewLink = this.viewLink.bind(this);
this.removeLink = this.removeLink.bind(this);
}
handleMouseOver() {
this.setState({
showOpIcon: true
});
}
handleMouseOut() {
this.setState({
showOpIcon: false
});
}
viewLink(e) {
e.preventDefault();
this.props.showModal({content: this.props.data.link});
}
removeLink(e) {
e.preventDefault();
const data = this.props.data;
seafileAPI.deleteShareLink(data.token)
.then((res) => {
this.setState({
deleted: true
});
// TODO: show feedback msg
// gettext("Successfully deleted 1 item")
})
.catch((error) => {
// TODO: show feedback msg
});
}
render() {
if (this.state.deleted) {
return null;
}
const data = this.props.data;
const icon_size = Utils.isHiDPI() ? 48 : 24;
if (data.is_dir) {
data.icon_url = Utils.getFolderIconUrl({
is_readonly: false,
size: icon_size
});
data.url = `${siteRoot}#my-libs/lib/${data.repo_id}${Utils.encodePath(data.path)}`;
} else {
data.icon_url = Utils.getFileIconUrl(data.obj_name, icon_size);
data.url = `${siteRoot}lib/${data.repo_id}/file${Utils.encodePath(data.path)}`;
}
let showDate = function(options) {
const date = moment(options.date).format('YYYY-MM-DD');
return options.is_expired ? <span className="error">{date}</span> : date;
}
let iconVisibility = this.state.showOpIcon ? '' : ' invisible';
let linkIconClassName = 'sf2-icon-link op-icon' + iconVisibility;
let deleteIconClassName = 'sf2-icon-delete op-icon' + iconVisibility;
const item = (
<tr onMouseOver={this.handleMouseOver} onMouseOut={this.handleMouseOut}>
<td><img src={data.icon_url} width="24" /></td>
<td><a href={data.url}>{data.obj_name}</a></td>
<td><a href={`${siteRoot}#my-libs/lib/${data.repo_id}/`}>{data.repo_name}</a></td>
<td>{data.view_cnt}</td>
<td>{data.expire_date ? showDate({date: data.expire_date, is_expired: data.is_expired}) : '--'}</td>
<td>
<a href="#" className={linkIconClassName} title={gettext('View')} onClick={this.viewLink}></a>
<a href="#" className={deleteIconClassName} title={gettext('Remove')} onClick={this.removeLink}></a>
</td>
</tr>
);
return item;
}
}
class ShareAdminShareLinks extends Component {
constructor(props) {
super(props);
this.state = {
loading: true,
errorMsg: '',
items: []
};
}
componentDidMount() {
seafileAPI.listShareLinks().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 (
<div className="cur-view-container">
<div className="cur-view-path">
<ul className="nav">
<li className="nav-item">
<Link to={`${siteRoot}share-admin-share-links/`} className="nav-link active">{gettext('Share Links')}</Link>
</li>
{ canGenerateUploadLink ?
<li className="nav-item"><Link to={`${siteRoot}share-admin-upload-links/`} className="nav-link">{gettext('Upload Links')}</Link></li>
: '' }
</ul>
</div>
<div className="cur-view-content">
<Content data={this.state} />
</div>
</div>
);
}
}
export default ShareAdminShareLinks;

View File

@@ -0,0 +1,246 @@
import React, { Component } from 'react';
import { Link } from '@reach/router';
import moment from 'moment';
import { Modal, ModalHeader, ModalBody } from 'reactstrap';
import { seafileAPI } from '../../utils/seafile-api';
import { Utils } from '../../utils/utils';
import { gettext, siteRoot, loginUrl, isPro, canGenerateShareLink } from '../../utils/constants';
class Content extends Component {
constructor(props) {
super(props);
this.state = {
modalOpen: false,
modalContent: ''
};
this.toggleModal = this.toggleModal.bind(this);
this.showModal = this.showModal.bind(this);
}
// required by `Modal`, and can only set the 'open' state
toggleModal() {
this.setState({
modalOpen: !this.state.modalOpen
});
}
showModal(options) {
this.toggleModal();
this.setState({
modalContent: options.content
});
}
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 don't have any upload links")}</h2>
<p>{gettext("You can generate an upload link from any folder. Anyone who receives this link can upload files to this folder.")}</p>
</div>
);
const table = (
<React.Fragment>
<table className="table table-hover table-vcenter">
<thead>
<tr>
<th width="10%">{/*icon*/}</th>
<th width="35%">{gettext("Name")}</th>
<th width="30%">{gettext("Library")}</th>
<th width="15%">{gettext("Visits")}</th>
<th width="10%">{/*Operations*/}</th>
</tr>
</thead>
<TableBody items={items} showModal={this.showModal} />
</table>
<Modal isOpen={this.state.modalOpen} toggle={this.toggleModal} centered={true}>
<ModalHeader toggle={this.toggleModal}>{gettext('Link')}</ModalHeader>
<ModalBody>
{this.state.modalContent}
</ModalBody>
</Modal>
</React.Fragment>
);
return items.length ? table : emptyTip;
}
}
}
class TableBody extends Component {
constructor(props) {
super(props);
this.state = {
//items: this.props.items
};
}
render() {
let listItems = this.props.items.map(function(item, index) {
return <Item key={index} data={item} showModal={this.props.showModal} />;
}, this);
return (
<tbody>{listItems}</tbody>
);
}
}
class Item extends Component {
constructor(props) {
super(props);
this.state = {
showOpIcon: false,
deleted: false
};
this.handleMouseOver = this.handleMouseOver.bind(this);
this.handleMouseOut = this.handleMouseOut.bind(this);
this.viewLink = this.viewLink.bind(this);
this.removeLink = this.removeLink.bind(this);
}
handleMouseOver() {
this.setState({
showOpIcon: true
});
}
handleMouseOut() {
this.setState({
showOpIcon: false
});
}
viewLink(e) {
e.preventDefault();
this.props.showModal({content: this.props.data.link});
}
removeLink(e) {
e.preventDefault();
const data = this.props.data;
seafileAPI.deleteUploadLink(data.token)
.then((res) => {
this.setState({
deleted: true
});
// TODO: show feedback msg
// gettext("Successfully deleted 1 item")
})
.catch((error) => {
// TODO: show feedback msg
});
}
render() {
if (this.state.deleted) {
return null;
}
const data = this.props.data;
const icon_size = Utils.isHiDPI() ? 48 : 24;
data.icon_url = Utils.getFolderIconUrl({
is_readonly: false,
size: icon_size
});
data.url = `${siteRoot}#my-libs/lib/${data.repo_id}${Utils.encodePath(data.path)}`;
let iconVisibility = this.state.showOpIcon ? '' : ' invisible';
let linkIconClassName = 'sf2-icon-link op-icon' + iconVisibility;
let deleteIconClassName = 'sf2-icon-delete op-icon' + iconVisibility;
const item = (
<tr onMouseOver={this.handleMouseOver} onMouseOut={this.handleMouseOut}>
<td><img src={data.icon_url} width="24" /></td>
<td><a href={data.url}>{data.obj_name}</a></td>
<td><a href={`${siteRoot}#my-libs/lib/${data.repo_id}/`}>{data.repo_name}</a></td>
<td>{data.view_cnt}</td>
<td>
<a href="#" className={linkIconClassName} title={gettext('View')} onClick={this.viewLink}></a>
<a href="#" className={deleteIconClassName} title={gettext('Remove')} onClick={this.removeLink}></a>
</td>
</tr>
);
return item;
}
}
class ShareAdminUploadLinks extends Component {
constructor(props) {
super(props);
this.state = {
loading: true,
errorMsg: '',
items: []
};
}
componentDidMount() {
seafileAPI.listUploadLinks().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 (
<div className="cur-view-container">
<div className="cur-view-path">
<ul className="nav">
{ canGenerateShareLink ?
<li className="nav-item"><Link to={`${siteRoot}share-admin-share-links/`} className="nav-link">{gettext('Share Links')}</Link></li>
: '' }
<li className="nav-item"><Link to={`${siteRoot}share-admin-upload-links/`} className="nav-link active">{gettext('Upload Links')}</Link></li>
</ul>
</div>
<div className="cur-view-content">
<Content data={this.state} />
</div>
</div>
);
}
}
export default ShareAdminUploadLinks;

View File

@@ -1,4 +1,4 @@
import { mediaUrl } from './constants';
import { mediaUrl, gettext } from './constants';
export const Utils = {
@@ -171,5 +171,89 @@ export const Utils = {
isSupportUploadFolder: function() {
return navigator.userAgent.indexOf('Firefox')!=-1 ||
navigator.userAgent.indexOf('Chrome') > -1;
},
getLibIconUrl: function(options) {
/*
* param: {is_encrypted, is_readonly, size}
*/
// icon name
var icon_name = 'lib.png';
if (options.is_encrypted) {
icon_name = 'lib-encrypted.png';
}
if (options.is_readonly) {
icon_name = 'lib-readonly.png';
}
// icon size
var icon_size = options.size || 256; // 'size' can be 24, 48, or undefined. (2017.7.31)
return mediaUrl + 'img/lib/' + icon_size + '/' + icon_name;
},
getFolderIconUrl: function(options) {
/*
* param: {is_readonly, size}
*/
const readonly = options.is_readonly;
const size = options.size;
return `${mediaUrl}img/folder${readonly ? '-read-only' : ''}${size > 24 ? '-192' : '-24'}.png`;
},
getLibIconTitle: function(options) {
/*
* param: {encrypted, is_admin, permission}
*/
var title;
if (options.encrypted) {
title = gettext("Encrypted library");
} else if (options.is_admin) { // shared with 'admin' permission
title = gettext("Admin access");
} else {
switch(options.permission) {
case 'rw':
title = gettext("Read-Write library");
break;
case 'r':
title = gettext("Read-Only library");
break;
case 'cloud-edit':
title = gettext("Preview-Edit-on-Cloud library");
break;
case 'preview':
title = gettext("Preview-on-Cloud library");
break;
}
}
return title;
},
getFolderIconTitle: function(options) {
var title;
switch(options.permission) {
case 'rw':
title = gettext("Read-Write folder");
break;
case 'r':
title = gettext("Read-Only folder");
break;
case 'cloud-edit':
title = gettext("Preview-Edit-on-Cloud folder");
break;
case 'preview':
title = gettext("Preview-on-Cloud folder");
break;
}
return title;
},
sharePerms: {
'rw': gettext("Read-Write"),
'r': gettext("Read-Only"),
'admin': gettext("Admin"),
'cloud-edit': gettext("Preview-Edit-on-Cloud"),
'preview': gettext("Preview-on-Cloud")
}
};

View File

@@ -50,7 +50,6 @@
-webkit-font-smoothing: antialiased;
}
.sf2-icon-delete:before { content:"\e006"; }
.sf2-icon-menu:before { content: "\e031"; }
.sf2-icon-more:before { content: "\e032"; }
.sf2-icon-x1:before { content:"\e01d"; }
@@ -72,6 +71,7 @@
.sf2-icon-trash:before { content:"\e016"; }
.sf2-icon-download:before { content:"\e008"; }
.sf2-icon-delete:before { content:"\e006"; }
.sf2-icon-link:before { content:"\e00e"; }
.sf2-icon-caret-down:before { content:"\e01a"; }
.sf2-icon-two-columns:before { content:"\e036"; }
.sf2-icon-confirm:before {content:"\e01e"}
@@ -1019,3 +1019,12 @@ a.op-icon:focus {
display: flex;
align-items: center;
}
.nav-link {
color: #8a948f;
padding: .3em .1em;
}
.nav-link.active {
color: #eb8205;
border-bottom: 2px solid #eb8205;
}

View File

@@ -60,19 +60,19 @@
<ul class="hide">
{% if user.permissions.can_add_repo %}
<li>
<a href="{{ SITE_ROOT }}#share-admin-libs/"><span aria-hidden="true" class="sharp">#</span>{% trans "Libraries" %}</a>
<a href="{{ SITE_ROOT }}share-admin-libs/"><span aria-hidden="true" class="sharp">#</span>{% trans "Libraries" %}</a>
</li>
<li>
<a href="{{ SITE_ROOT }}#share-admin-folders/"><span aria-hidden="true" class="sharp">#</span>{% trans "Folders" %}</a>
<a href="{{ SITE_ROOT }}share-admin-folders/"><span aria-hidden="true" class="sharp">#</span>{% trans "Folders" %}</a>
</li>
{% endif %}
{% if user.permissions.can_generate_share_link %}
<li>
<a href="{{ SITE_ROOT }}#share-admin-share-links/"><span aria-hidden="true" class="sharp">#</span>{% trans "Links" %}</a>
<a href="{{ SITE_ROOT }}share-admin-share-links/"><span aria-hidden="true" class="sharp">#</span>{% trans "Links" %}</a>
</li>
{% elif user.permissions.can_generate_upload_link %}
<li>
<a href="{{ SITE_ROOT }}#share-admin-upload-links/"><span aria-hidden="true" class="sharp">#</span>{% trans "Links" %}</a>
<a href="{{ SITE_ROOT }}share-admin-upload-links/"><span aria-hidden="true" class="sharp">#</span>{% trans "Links" %}</a>
</li>
{% endif %}
</ul>

View File

@@ -1595,19 +1595,19 @@
<% } %>
<% if (can_add_repo) { %>
<li class="<% if (cur_tab == 'share-admin-repos') { %>tab-cur<% } %>">
<a href="{{ SITE_ROOT }}#share-admin-libs/"><span aria-hidden="true" class="sharp">#</span>{% trans "Libraries" %}</a>
<a href="{{ SITE_ROOT }}share-admin-libs/"><span aria-hidden="true" class="sharp">#</span>{% trans "Libraries" %}</a>
</li>
<li class="<% if (cur_tab == 'share-admin-folders') { %>tab-cur<% } %>">
<a href="{{ SITE_ROOT }}#share-admin-folders/"><span aria-hidden="true" class="sharp">#</span>{% trans "Folders" %}</a>
<a href="{{ SITE_ROOT }}share-admin-folders/"><span aria-hidden="true" class="sharp">#</span>{% trans "Folders" %}</a>
</li>
<% } %>
<% if (can_generate_share_link) { %>
<li class="<% if (cur_tab == 'share-admin-links') { %>tab-cur<% } %>">
<a href="{{ SITE_ROOT }}#share-admin-share-links/"><span aria-hidden="true" class="sharp">#</span>{% trans "Links" %}</a>
<a href="{{ SITE_ROOT }}share-admin-share-links/"><span aria-hidden="true" class="sharp">#</span>{% trans "Links" %}</a>
</li>
<% } else if (can_generate_upload_link) { %>
<li class="<% if (cur_tab == 'share-admin-links') { %>tab-cur<% } %>">
<a href="{{ SITE_ROOT }}#share-admin-upload-links/"><span aria-hidden="true" class="sharp">#</span>{% trans "Links" %}</a>
<a href="{{ SITE_ROOT }}share-admin-upload-links/"><span aria-hidden="true" class="sharp">#</span>{% trans "Links" %}</a>
</li>
<% } %>
</ul>

View File

@@ -194,6 +194,10 @@ urlpatterns = [
url(r'^dashboard/$', react_fake_view, name="dashboard"),
url(r'^starred/$', react_fake_view, name="starred"),
url(r'^linked-devices/$', react_fake_view, name="linked_devices"),
url(r'^share-admin-libs/$', react_fake_view, name="share_admin_libs"),
url(r'^share-admin-folders/$', react_fake_view, name="share_admin_folders"),
url(r'^share-admin-share-links/$', react_fake_view, name="share_admin_share_links"),
url(r'^share-admin-upload-links/$', react_fake_view, name="share_admin_upload_links"),
### Ajax ###
url(r'^ajax/repo/(?P<repo_id>[-0-9a-f]{36})/dirents/$', get_dirents, name="get_dirents"),