1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-07 12:09:08 +00:00
seahub/frontend/src/components/main-side-nav.js

296 lines
13 KiB
JavaScript
Raw Normal View History

import React from 'react';
2018-10-16 10:19:51 +00:00
import PropTypes from 'prop-types';
import { Link } from '@reach/router';
import { Badge } from 'reactstrap';
2019-10-21 09:12:05 +00:00
import { gettext, siteRoot, canPublishRepo, canAddRepo, canGenerateShareLink, canGenerateUploadLink, canInvitePeople, dtableWebServer } from '../utils/constants';
import { seafileAPI } from '../utils/seafile-api';
import { Utils } from '../utils/utils';
import toaster from './toast';
import Group from '../models/group';
import { canViewOrg, isDocs, isPro, customNavItems } from '../utils/constants';
2018-11-19 10:28:31 +00:00
2018-10-16 10:19:51 +00:00
const propTypes = {
currentTab: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
2018-11-22 09:00:23 +00:00
tabItemClick: PropTypes.func.isRequired,
draftCounts: PropTypes.number,
2018-10-16 10:19:51 +00:00
};
class MainSideNav extends React.Component {
constructor(props) {
super(props);
this.state = {
groupsExtended: false,
sharedExtended: false,
closeSideBar:false,
groupItems: [],
};
this.listHeight = 24; //for caculate tabheight
this.groupsHeight = 0;
this.adminHeight = 0;
}
grpsExtend = () => {
this.setState({
groupsExtended: !this.state.groupsExtended,
2018-10-16 10:19:51 +00:00
});
this.loadGroups();
}
shExtend = () => {
this.setState({
sharedExtended: !this.state.sharedExtended,
2018-10-16 10:19:51 +00:00
});
}
loadGroups = () => {
let _this = this;
2019-01-08 05:55:00 +00:00
seafileAPI.listGroups().then(res =>{
2018-12-17 09:06:59 +00:00
let groupList = res.data.map(item => {
let group = new Group(item);
return group;
});
2018-12-17 09:06:59 +00:00
this.groupsHeight = (groupList.length + 1) * _this.listHeight;
_this.setState({
2019-08-28 04:16:56 +00:00
groupItems: groupList.sort((a, b) => {
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1;
})
2018-10-16 10:19:51 +00:00
});
}).catch(error => {
let errMessage = Utils.getErrorMsg(error);
toaster.danger(errMessage);
2018-10-16 10:19:51 +00:00
});
}
tabItemClick = (e, param, id) => {
2019-10-21 08:44:49 +00:00
if (window.uploader &&
window.uploader.isUploadProgressDialogShow &&
window.uploader.totalProgress !== 100) {
if (!window.confirm(gettext('A file is being uploaded. Are you sure you want to leave this page?'))) {
e.preventDefault();
return false;
}
window.uploader.isUploadProgressDialogShow = false;
}
2018-12-11 09:52:19 +00:00
this.props.tabItemClick(param, id);
}
onDTableClick = () => {
2019-10-21 09:12:05 +00:00
let url = dtableWebServer;
window.open(url);
}
2019-10-21 08:44:49 +00:00
getActiveClass = (tab) => {
return this.props.currentTab === tab ? 'active' : '';
}
renderSharedGroups() {
let style = {height: 0};
if (this.state.groupsExtended) {
style = {height: this.groupsHeight};
}
return (
<ul className={`nav sub-nav nav-pills flex-column grp-list ${this.state.groupsExtended ? 'side-panel-slide' : 'side-panel-slide-up'}`} style={style}>
2019-10-21 08:44:49 +00:00
<li className="nav-item">
<Link to={siteRoot + 'groups/'} className={`nav-link ellipsis ${this.getActiveClass('groups')}`} onClick={(e) => this.tabItemClick(e, 'groups')}>
2018-10-16 10:19:51 +00:00
<span className="sharp" aria-hidden="true">#</span>
2018-12-06 06:39:21 +00:00
<span className="nav-text">{gettext('All Groups')}</span>
</Link>
</li>
{this.state.groupItems.map(item => {
return (
2019-10-21 08:44:49 +00:00
<li key={item.id} className="nav-item">
<Link to={siteRoot + 'group/' + item.id + '/'} className={`nav-link ellipsis ${this.getActiveClass(item.name)}`} onClick={(e) => this.tabItemClick(e, item.name, item.id)}>
<span className="sharp" aria-hidden="true">#</span>
2018-12-06 06:39:21 +00:00
<span className="nav-text">{item.name}</span>
</Link>
</li>
2018-10-16 10:19:51 +00:00
);
})}
</ul>
2018-10-16 10:19:51 +00:00
);
}
renderSharedAdmin() {
let height = 0;
if (this.state.sharedExtended) {
if (!this.adminHeight) {
this.adminHeight = 3 * this.listHeight;
}
height = this.adminHeight;
}
let style = {height: height};
let linksNavItem = null;
if (canGenerateShareLink) {
linksNavItem = (
<li className="nav-item">
<Link to={siteRoot + 'share-admin-share-links/'} className={`nav-link ellipsis ${this.getActiveClass('share-admin-share-links')}`} title={gettext('Links')} onClick={(e) => this.tabItemClick(e, 'share-admin-share-links')}>
<span aria-hidden="true" className="sharp">#</span>
<span className="nav-text">{gettext('Links')}</span>
</Link>
</li>
);
} else if (canGenerateUploadLink) {
linksNavItem = (
<li className="nav-item">
<Link to={siteRoot + 'share-admin-upload-links/'} className={`nav-link ellipsis ${this.getActiveClass('share-admin-upload-links')}`} title={gettext('Links')} onClick={(e) => this.tabItemClick(e, 'share-admin-upload-links')}>
<span aria-hidden="true" className="sharp">#</span>
<span className="nav-text">{gettext('Links')}</span>
</Link>
</li>
);
}
return (
<ul className={`nav sub-nav nav-pills flex-column ${this.state.sharedExtended ? 'side-panel-slide' : 'side-panel-slide-up'}`} style={style} >
{canAddRepo && (
<li className="nav-item">
<Link to={siteRoot + 'share-admin-libs/'} className={`nav-link ellipsis ${this.getActiveClass('share-admin-libs')}`} title={gettext('Libraries')} onClick={(e) => this.tabItemClick(e, 'share-admin-libs')}>
<span aria-hidden="true" className="sharp">#</span>
<span className="nav-text">{gettext('Libraries')}</span>
</Link>
</li>
)}
<li className="nav-item">
<Link to={siteRoot + 'share-admin-folders/'} className={`nav-link ellipsis ${this.getActiveClass('share-admin-folders')}`} title={gettext('Folders')} onClick={(e) => this.tabItemClick(e, 'share-admin-folders')}>
<span aria-hidden="true" className="sharp">#</span>
2018-12-06 06:39:21 +00:00
<span className="nav-text">{gettext('Folders')}</span>
</Link>
</li>
{linksNavItem}
</ul>
2018-10-16 10:19:51 +00:00
);
}
renderCustomNavItems() {
return (
customNavItems.map((item, idx) => {
return (
<li key={idx} className="nav-item">
<a href={item.link} className="nav-link ellipsis" title={item.desc}>
<span className={item.icon} aria-hidden="true"></span>
<span className="nav-text">{item.desc}</span>
</a>
</li>
);
})
);
}
render() {
2019-10-21 08:44:49 +00:00
let showActivity = isDocs || isPro;
return (
<div className="side-nav">
<div className="side-nav-con">
2018-12-21 08:16:45 +00:00
<h3 className="sf-heading">{gettext('Files')}</h3>
<ul className="nav nav-pills flex-column nav-container">
{canAddRepo && (
<li className="nav-item">
<Link to={ siteRoot + 'my-libs/' } className={`nav-link ellipsis ${this.getActiveClass('my-libs') || this.getActiveClass('deleted') }`} title={gettext('My Libraries')} onClick={(e) => this.tabItemClick(e, 'my-libs')}>
<span className="sf2-icon-user" aria-hidden="true"></span>
<span className="nav-text">{gettext('My Libraries')}</span>
</Link>
</li>
)}
<li className="nav-item">
<Link to={siteRoot + 'shared-libs/'} className={`nav-link ellipsis ${this.getActiveClass('shared-libs')}`} title={gettext('Shared with me')} onClick={(e) => this.tabItemClick(e, 'shared-libs')}>
<span className="sf2-icon-share" aria-hidden="true"></span>
2018-12-06 06:39:21 +00:00
<span className="nav-text">{gettext('Shared with me')}</span>
</Link>
</li>
2018-11-19 10:28:31 +00:00
{ canViewOrg &&
<li className="nav-item" onClick={(e) => this.tabItemClick(e, 'org')}>
2018-12-21 07:40:59 +00:00
<Link to={ siteRoot + 'org/' } className={`nav-link ellipsis ${this.getActiveClass('org')}`} title={gettext('Shared with all')}>
2018-11-19 10:28:31 +00:00
<span className="sf2-icon-organization" aria-hidden="true"></span>
2018-12-06 06:39:21 +00:00
<span className="nav-text">{gettext('Shared with all')}</span>
2018-12-21 07:40:59 +00:00
</Link>
2018-11-19 10:28:31 +00:00
</li>
}
<li className="nav-item flex-column" id="group-nav">
<a className="nav-link ellipsis" title={gettext('Shared with groups')} onClick={this.grpsExtend}>
<span className={`toggle-icon float-right fas ${this.state.groupsExtended ?'fa-caret-down':'fa-caret-left'}`} aria-hidden="true"></span>
<span className="sf2-icon-group" aria-hidden="true"></span>
2018-12-06 06:39:21 +00:00
<span className="nav-text">{gettext('Shared with groups')}</span>
</a>
{this.renderSharedGroups()}
</li>
</ul>
2019-05-31 03:24:53 +00:00
2018-12-21 08:16:45 +00:00
<h3 className="sf-heading">{gettext('Tools')}</h3>
<ul className="nav nav-pills flex-column nav-container">
<li className="nav-item">
<Link className={`nav-link ellipsis ${this.getActiveClass('starred')}`} to={siteRoot + 'starred/'} title={gettext('Favorites')} onClick={(e) => this.tabItemClick(e, 'starred')}>
<span className="sf2-icon-star" aria-hidden="true"></span>
2018-12-06 06:39:21 +00:00
<span className="nav-text">{gettext('Favorites')}</span>
2018-10-15 07:51:29 +00:00
</Link>
</li>
2019-04-17 02:32:32 +00:00
{showActivity &&
<li className="nav-item">
<Link className={`nav-link ellipsis ${this.getActiveClass('dashboard')}`} to={siteRoot + 'dashboard/'} title={gettext('Activities')} onClick={(e) => this.tabItemClick(e, 'dashboard')}>
<span className="sf2-icon-clock" aria-hidden="true"></span>
<span className="nav-text">{gettext('Activities')}</span>
</Link>
</li>
}
{canPublishRepo &&
2018-12-10 05:33:32 +00:00
<li className="nav-item">
<Link className={`nav-link ellipsis ${this.getActiveClass('published')}`} to={siteRoot + 'published/'} title={gettext('Published Libraries')} onClick={(e) => this.tabItemClick(e, 'published')}>
<span className="sf2-icon-wiki-view" aria-hidden="true"></span>
<span className="nav-text">{gettext('Published Libraries')}</span>
</Link>
</li>
2018-12-10 05:33:32 +00:00
}
{isDocs &&
<li className="nav-item" onClick={(e) => this.tabItemClick(e, 'drafts')}>
<Link className={`nav-link ellipsis ${this.getActiveClass('drafts')}`} to={siteRoot + 'drafts/'} title={gettext('Drafts')}>
<span className="sf2-icon-edit" aria-hidden="true"></span>
<span className="draft-info nav-text">
2019-10-21 08:44:49 +00:00
{gettext('Drafts')}
{this.props.draftCounts === 0 ? '' : <Badge color="info" pill>{this.props.draftCounts}</Badge>}
</span>
</Link>
</li>
}
2019-02-18 09:48:35 +00:00
<li className="nav-item">
<Link className={`nav-link ellipsis ${this.getActiveClass('linked-devices')}`} to={siteRoot + 'linked-devices/'} title={gettext('Linked Devices')} onClick={(e) => this.tabItemClick(e, 'linked-devices')}>
2019-02-18 09:48:35 +00:00
<span className="sf2-icon-monitor" aria-hidden="true"></span>
<span className="nav-text">{gettext('Linked Devices')}</span>
</Link>
</li>
2019-04-12 05:28:15 +00:00
{canInvitePeople &&
2019-06-04 09:59:54 +00:00
<li className="nav-item">
<Link className={`nav-link ellipsis ${this.getActiveClass('invitations')}`} to={siteRoot + 'invitations/'} title={gettext('Invite People')} onClick={(e) => this.tabItemClick(e, 'invitations')}>
2019-04-12 05:28:15 +00:00
<span className="sf2-icon-invite" aria-hidden="true"></span>
<span className="nav-text">{gettext('Invite People')}</span>
</Link>
</li>
}
<li className="nav-item flex-column" id="share-admin-nav">
<a className="nav-link ellipsis" title={gettext('Share Admin')} onClick={this.shExtend}>
<span className={`toggle-icon float-right fas ${this.state.sharedExtended ? 'fa-caret-down':'fa-caret-left'}`} aria-hidden="true"></span>
2018-12-06 06:39:21 +00:00
<span className="sf2-icon-wrench" aria-hidden="true"></span>
<span className="nav-text">{gettext('Share Admin')}</span>
</a>
{this.renderSharedAdmin()}
</li>
{customNavItems && this.renderCustomNavItems()}
</ul>
</div>
<div className="side-nav-link" onClick={this.onDTableClick}>
<span className="link-icon icon-left sf3-font sf3-font-dtable-logo" aria-hidden="true"></span>
<span className="link-text">Database</span>
<span className="link-icon icon-right sf3-font sf3-font-arrow"></span>
</div>
</div>
2018-10-16 10:19:51 +00:00
);
}
}
2018-10-16 10:19:51 +00:00
MainSideNav.propTypes = propTypes;
export default MainSideNav;