2018-12-21 07:40:59 +00:00
|
|
|
import React, { Component } from 'react';
|
2018-09-21 06:16:15 +00:00
|
|
|
import ReactDOM from 'react-dom';
|
2018-12-13 12:42:51 +00:00
|
|
|
import { Router, navigate } from '@reach/router';
|
2019-01-24 02:02:18 +00:00
|
|
|
import { siteRoot, canAddRepo } from './utils/constants';
|
2018-12-13 12:42:51 +00:00
|
|
|
import { Utils } from './utils/utils';
|
2018-09-21 06:16:15 +00:00
|
|
|
import SidePanel from './components/side-panel';
|
|
|
|
import MainPanel from './components/main-panel';
|
|
|
|
import DraftsView from './pages/drafts/drafts-view';
|
2018-10-15 07:51:29 +00:00
|
|
|
import DraftContent from './pages/drafts/draft-content';
|
|
|
|
import ReviewContent from './pages/drafts/review-content';
|
2018-09-21 06:16:15 +00:00
|
|
|
import FilesActivities from './pages/dashboard/files-activities';
|
2018-10-08 07:33:40 +00:00
|
|
|
import Starred from './pages/starred/starred';
|
2018-11-10 09:14:07 +00:00
|
|
|
import LinkedDevices from './pages/linked-devices/linked-devices';
|
2018-11-01 09:52:59 +00:00
|
|
|
import editUtilties from './utils/editor-utilties';
|
2018-11-19 03:53:44 +00:00
|
|
|
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';
|
2018-11-22 08:49:48 +00:00
|
|
|
import SharedLibraries from './pages/shared-libs/shared-libs';
|
2018-11-30 09:18:41 +00:00
|
|
|
import MyLibraries from './pages/my-libs/my-libs';
|
2018-12-08 10:29:13 +00:00
|
|
|
import MyLibDeleted from './pages/my-libs/my-libs-deleted';
|
2018-12-21 07:40:59 +00:00
|
|
|
import PublicSharedView from './pages/shared-with-all/public-shared-view';
|
2018-11-30 09:18:41 +00:00
|
|
|
import DirView from './components/dir-view/dir-view';
|
2018-12-10 10:33:50 +00:00
|
|
|
import Group from './pages/groups/group-view';
|
|
|
|
import Groups from './pages/groups/groups-view';
|
2018-12-07 16:01:23 +00:00
|
|
|
import Wikis from './pages/wikis/wikis';
|
2018-11-26 09:53:18 +00:00
|
|
|
import MainContentWrapper from './components/main-content-wrapper';
|
2018-09-21 06:16:15 +00:00
|
|
|
|
|
|
|
import './assets/css/fa-solid.css';
|
|
|
|
import './assets/css/fa-regular.css';
|
|
|
|
import './assets/css/fontawesome.css';
|
|
|
|
import './css/layout.css';
|
|
|
|
import './css/toolbar.css';
|
|
|
|
import './css/search.css';
|
|
|
|
|
2018-11-26 09:53:18 +00:00
|
|
|
const FilesActivitiesWrapper = MainContentWrapper(FilesActivities);
|
|
|
|
const DraftsViewWrapper = MainContentWrapper(DraftsView);
|
|
|
|
const StarredWrapper = MainContentWrapper(Starred);
|
|
|
|
const LinkedDevicesWrapper = MainContentWrapper(LinkedDevices);
|
|
|
|
const SharedLibrariesWrapper = MainContentWrapper(SharedLibraries);
|
|
|
|
const ShareAdminLibrariesWrapper = MainContentWrapper(ShareAdminLibraries);
|
|
|
|
const ShareAdminFoldersWrapper = MainContentWrapper(ShareAdminFolders);
|
|
|
|
const ShareAdminShareLinksWrapper = MainContentWrapper(ShareAdminShareLinks);
|
|
|
|
const ShareAdminUploadLinksWrapper = MainContentWrapper(ShareAdminUploadLinks);
|
|
|
|
|
2018-09-21 06:16:15 +00:00
|
|
|
class App extends Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
isOpen: false,
|
2018-09-25 01:13:06 +00:00
|
|
|
isSidePanelClosed: false,
|
2018-11-01 09:52:59 +00:00
|
|
|
draftCounts: 0,
|
2018-11-08 02:36:41 +00:00
|
|
|
draftList:[],
|
|
|
|
isLoadingDraft: true,
|
2018-12-10 10:19:29 +00:00
|
|
|
currentTab: '/',
|
2018-12-13 06:40:09 +00:00
|
|
|
pathPrefix: [],
|
2018-09-21 06:16:15 +00:00
|
|
|
};
|
2018-12-13 06:40:09 +00:00
|
|
|
this.dirViewPanels = ['my-libs', 'shared-libs', 'org']; // and group
|
2018-09-21 06:16:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 09:52:59 +00:00
|
|
|
componentDidMount() {
|
2018-11-22 09:00:23 +00:00
|
|
|
// e.g. from http://127.0.0.1:8000/drafts/reviews/
|
|
|
|
// get reviews
|
|
|
|
// TODO: need refactor later
|
|
|
|
let href = window.location.href.split('/');
|
2018-11-08 02:36:41 +00:00
|
|
|
this.getDrafts();
|
2018-11-30 09:18:41 +00:00
|
|
|
this.setState({currentTab: href[href.length - 2]});
|
2018-11-01 09:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getDrafts = () => {
|
|
|
|
editUtilties.listDrafts().then(res => {
|
|
|
|
this.setState({
|
|
|
|
draftCounts: res.data.draft_counts,
|
2018-11-08 02:36:41 +00:00
|
|
|
draftList: res.data.data,
|
|
|
|
isLoadingDraft: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
updateDraftsList = (draft_id) => {
|
|
|
|
this.setState({
|
|
|
|
draftCounts: this.state.draftCounts - 1,
|
|
|
|
draftList: this.state.draftList.filter(draft => draft.id != draft_id),
|
|
|
|
});
|
2018-11-01 09:52:59 +00:00
|
|
|
}
|
|
|
|
|
2018-09-25 01:13:06 +00:00
|
|
|
onCloseSidePanel = () => {
|
|
|
|
this.setState({
|
|
|
|
isSidePanelClosed: !this.state.isSidePanelClosed
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onShowSidePanel = () => {
|
|
|
|
this.setState({
|
|
|
|
isSidePanelClosed: !this.state.isSidePanelClosed
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-13 12:42:51 +00:00
|
|
|
onSearchedClick = (selectedItem) => {
|
|
|
|
if (selectedItem.is_dir === true) {
|
|
|
|
this.setState({currentTab: '', pathPrefix: []});
|
|
|
|
let url = siteRoot + 'library/' + selectedItem.repo_id + '/' + selectedItem.repo_name + selectedItem.path;
|
|
|
|
navigate(url, {repalce: true});
|
|
|
|
} else {
|
2018-12-14 13:52:54 +00:00
|
|
|
let url = siteRoot + 'lib/' + selectedItem.repo_id + '/file' + Utils.encodePath(selectedItem.path);
|
2018-12-13 12:42:51 +00:00
|
|
|
let newWindow = window.open('about:blank');
|
|
|
|
newWindow.location.href = url;
|
|
|
|
}
|
2018-11-26 06:00:32 +00:00
|
|
|
}
|
|
|
|
|
2018-12-19 02:44:23 +00:00
|
|
|
onGroupChanged = (groupID) => {
|
|
|
|
setTimeout(function(){
|
2018-12-20 10:22:07 +00:00
|
|
|
let url;
|
2018-12-19 02:44:23 +00:00
|
|
|
if (groupID) {
|
2018-12-20 10:22:07 +00:00
|
|
|
url = siteRoot + 'group/' + groupID + '/';
|
2018-12-19 02:44:23 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-12-20 10:22:07 +00:00
|
|
|
url = siteRoot + 'groups/';
|
2018-12-19 02:44:23 +00:00
|
|
|
}
|
|
|
|
window.location = url.toString();
|
|
|
|
}, 1);
|
|
|
|
}
|
|
|
|
|
2018-12-11 09:52:19 +00:00
|
|
|
tabItemClick = (tabName, groupID) => {
|
2018-12-13 06:40:09 +00:00
|
|
|
let pathPrefix = [];
|
|
|
|
if (groupID || this.dirViewPanels.indexOf(tabName) > -1) {
|
|
|
|
pathPrefix = this.generatorPrefix(tabName, groupID);
|
|
|
|
}
|
2018-12-11 09:52:19 +00:00
|
|
|
this.setState({
|
|
|
|
currentTab: tabName,
|
|
|
|
pathPrefix: pathPrefix
|
|
|
|
});
|
2018-11-22 09:00:23 +00:00
|
|
|
}
|
2018-11-01 09:52:59 +00:00
|
|
|
|
2018-12-13 06:40:09 +00:00
|
|
|
generatorPrefix = (tabName, groupID) => {
|
|
|
|
let pathPrefix = [];
|
|
|
|
if (groupID) {
|
|
|
|
let navTab1 = {
|
|
|
|
url: siteRoot + 'groups/',
|
|
|
|
showName: 'Groups',
|
|
|
|
name: 'groups',
|
|
|
|
id: null,
|
2019-01-31 09:37:02 +00:00
|
|
|
};
|
2018-12-13 06:40:09 +00:00
|
|
|
let navTab2 = {
|
|
|
|
url: siteRoot + 'group/' + groupID + '/',
|
|
|
|
showName: tabName,
|
|
|
|
name: tabName,
|
|
|
|
id: groupID,
|
|
|
|
};
|
|
|
|
pathPrefix.push(navTab1);
|
|
|
|
pathPrefix.push(navTab2);
|
|
|
|
} else {
|
|
|
|
let navTab = {
|
|
|
|
url: siteRoot + tabName + '/',
|
2018-12-13 08:35:11 +00:00
|
|
|
showName: this.getTabShowName(tabName),
|
2018-12-13 06:40:09 +00:00
|
|
|
name: tabName,
|
|
|
|
id: null,
|
|
|
|
};
|
|
|
|
pathPrefix.push(navTab);
|
|
|
|
}
|
|
|
|
return pathPrefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
getTabShowName = (tabName) => {
|
|
|
|
if (tabName === 'my-libs') {
|
|
|
|
return 'Libraries';
|
2018-12-11 09:52:19 +00:00
|
|
|
}
|
2018-12-13 06:40:09 +00:00
|
|
|
if (tabName === 'shared-libs') {
|
|
|
|
return 'Shared with me';
|
2018-12-11 09:52:19 +00:00
|
|
|
}
|
2018-12-13 06:40:09 +00:00
|
|
|
if (tabName === 'org') {
|
|
|
|
return 'Shared with all';
|
2018-12-11 09:52:19 +00:00
|
|
|
}
|
2018-11-30 09:18:41 +00:00
|
|
|
}
|
|
|
|
|
2018-11-22 09:00:23 +00:00
|
|
|
render() {
|
|
|
|
let { currentTab } = this.state;
|
2019-01-24 02:02:18 +00:00
|
|
|
|
|
|
|
const home = canAddRepo ?
|
|
|
|
<MyLibraries path={ siteRoot } onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} /> :
|
|
|
|
<SharedLibrariesWrapper path={ siteRoot } onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} />;
|
|
|
|
|
2018-09-21 06:16:15 +00:00
|
|
|
return (
|
|
|
|
<div id="main">
|
2018-11-22 09:00:23 +00:00
|
|
|
<SidePanel isSidePanelClosed={this.state.isSidePanelClosed} onCloseSidePanel={this.onCloseSidePanel} currentTab={currentTab} tabItemClick={this.tabItemClick} draftCounts={this.state.draftCounts} />
|
2018-11-26 06:00:32 +00:00
|
|
|
<MainPanel>
|
2018-09-21 06:16:15 +00:00
|
|
|
<Router>
|
2019-01-24 02:02:18 +00:00
|
|
|
{home}
|
2018-11-26 09:53:18 +00:00
|
|
|
<FilesActivitiesWrapper path={siteRoot + 'dashboard'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} />
|
|
|
|
<DraftsViewWrapper path={siteRoot + 'drafts'}
|
2018-11-26 06:00:32 +00:00
|
|
|
currentTab={currentTab}
|
|
|
|
tabItemClick={this.tabItemClick}
|
|
|
|
onShowSidePanel={this.onShowSidePanel}
|
|
|
|
onSearchedClick={this.onSearchedClick}
|
|
|
|
>
|
|
|
|
<DraftContent
|
|
|
|
path='/'
|
|
|
|
getDrafts={this.getDrafts}
|
2018-11-08 02:36:41 +00:00
|
|
|
isLoadingDraft={this.state.isLoadingDraft}
|
|
|
|
draftList={this.state.draftList}
|
|
|
|
updateDraftsList={this.updateDraftsList}
|
|
|
|
/>
|
2018-10-15 07:51:29 +00:00
|
|
|
<ReviewContent path='reviews' />
|
2018-11-26 09:53:18 +00:00
|
|
|
</DraftsViewWrapper>
|
|
|
|
<StarredWrapper path={siteRoot + 'starred'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} />
|
|
|
|
<LinkedDevicesWrapper path={siteRoot + 'linked-devices'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} />
|
|
|
|
<ShareAdminLibrariesWrapper path={siteRoot + 'share-admin-libs'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} />
|
|
|
|
<ShareAdminFoldersWrapper path={siteRoot + 'share-admin-folders'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} />
|
|
|
|
<ShareAdminShareLinksWrapper path={siteRoot + 'share-admin-share-links'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} />
|
|
|
|
<ShareAdminUploadLinksWrapper path={siteRoot + 'share-admin-upload-links'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} />
|
|
|
|
<SharedLibrariesWrapper path={siteRoot + 'shared-libs'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} />
|
2018-11-30 09:18:41 +00:00
|
|
|
<MyLibraries path={siteRoot + 'my-libs'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} />
|
2018-12-08 10:29:13 +00:00
|
|
|
<MyLibDeleted path={siteRoot + 'my-libs/deleted/'} onSearchedClick={this.onSearchedClick} />
|
2018-12-13 06:40:09 +00:00
|
|
|
<DirView path={siteRoot + 'library/:repoID/*'} pathPrefix={this.state.pathPrefix} onMenuClick={this.onShowSidePanel} onTabNavClick={this.tabItemClick}/>
|
2018-12-07 02:36:59 +00:00
|
|
|
<Groups path={siteRoot + 'groups'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick}/>
|
2018-12-19 02:44:23 +00:00
|
|
|
<Group
|
|
|
|
path={siteRoot + 'group/:groupID'}
|
|
|
|
onShowSidePanel={this.onShowSidePanel}
|
|
|
|
onSearchedClick={this.onSearchedClick}
|
|
|
|
onTabNavClick={this.tabItemClick}
|
|
|
|
onGroupChanged={this.onGroupChanged}
|
2019-01-31 09:37:02 +00:00
|
|
|
/>
|
2018-12-26 08:27:15 +00:00
|
|
|
<Wikis path={siteRoot + 'wikis'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick}/>
|
2018-12-21 07:40:59 +00:00
|
|
|
<PublicSharedView path={siteRoot + 'org/'} onShowSidePanel={this.onShowSidePanel} onSearchedClick={this.onSearchedClick} onTabNavClick={this.tabItemClick}/>
|
2018-09-21 06:16:15 +00:00
|
|
|
</Router>
|
|
|
|
</MainPanel>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactDOM.render(
|
|
|
|
<App />,
|
|
|
|
document.getElementById('wrapper')
|
|
|
|
);
|