/* * Copyright 2007-2017 Charles du Jeu - Abstrium SAS * This file is part of Pydio. * * Pydio is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Pydio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Pydio. If not, see . * * The latest code can be found at . */ import React from 'react' import Pydio from 'pydio' const {withVerticalScroll} = Pydio.requireLib('hoc') import WorkspaceEntry from './WorkspaceEntry' import XMLUtils from 'pydio/util/xml' class WorkspacesList extends React.Component{ constructor(props, context){ super(props, context); this.state = this.stateFromPydio(props.pydio); this._reloadObserver = () => { this.setState(this.stateFromPydio(this.props.pydio)); }; } stateFromPydio(pydio){ return { workspaces : pydio.user ? pydio.user.getRepositoriesList() : [], showTreeForWorkspace: pydio.user ? pydio.user.activeRepository : false }; } componentDidMount(){ this.props.pydio.observe('repository_list_refreshed', this._reloadObserver); } componentWillUnmount(){ this.props.pydio.stopObserving('repository_list_refreshed', this._reloadObserver); } createRepositoryEnabled(){ const reg = this.props.pydio.Registry.getXML(); return XMLUtils.XPathSelectSingleNode(reg, 'actions/action[@name="user_create_repository"]') !== null; } render(){ let entries = [], sharedEntries = [], inboxEntry, createAction; const {workspaces,showTreeForWorkspace} = this.state; const {pydio, className, style, filterByType} = this.props; workspaces.forEach(function(object, key){ if (object.getId().indexOf('ajxp_') === 0) return; if (object.hasContentFilter()) return; if (object.getAccessStatus() === 'declined') return; const entry = ( ); if (object.getAccessType() == "inbox") { inboxEntry = entry; } else if(object.getOwner()) { sharedEntries.push(entry); } else { entries.push(entry); } }.bind(this)); if(inboxEntry){ sharedEntries.unshift(inboxEntry); } const messages = pydio.MessageHash; if(this.createRepositoryEnabled()){ const createClick = function(){ pydio.Controller.fireAction('user_create_repository'); }.bind(this); createAction = (
+ {messages[417]} {messages[418]}
); } let sections = []; if(entries.length){ sections.push({ k:'entries', title:
{messages[468]}
, content:
{entries}
}); } if(sharedEntries.length){ sections.push({ k:'shared', title:
{messages[469]}
, content:
{sharedEntries}
}); } if(createAction){ sections.push({ k:'create', title:
, content: createAction }); } let classNames = ['user-workspaces-list']; if(className) classNames.push(className); if(filterByType){ let ret; sections.map(function(s){ if(filterByType && filterByType === s.k){ ret =
{s.title}{s.content}
} }); return ret; } let elements = []; sections.map(function(s) { elements.push(s.title); elements.push(s.content); }); return (
{elements}
); } } WorkspacesList.PropTypes = { pydio : React.PropTypes.instanceOf(Pydio), workspaces : React.PropTypes.instanceOf(Map), showTreeForWorkspace : React.PropTypes.string, onHoverLink : React.PropTypes.func, onOutLink : React.PropTypes.func, className : React.PropTypes.string, style : React.PropTypes.object, sectionTitleStyle : React.PropTypes.object, filterByType : React.PropTypes.oneOf(['shared', 'entries', 'create']) }; WorkspacesList = withVerticalScroll(WorkspacesList); export {WorkspacesList as default}