/* * 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 . */ const React = require('react') const {IconButton, Paper, BottomNavigation, BottomNavigationItem, FontIcon, FlatButton, TextField} = require('material-ui') import Editor from '../editor/Editor' const PydioDataModel = require('pydio/model/data-model') const {muiThemeable} = require('material-ui/styles') let Dashboard = React.createClass({ mixins:[AdminComponents.MessagesConsumerMixin], propTypes:{ dataModel:React.PropTypes.instanceOf(PydioDataModel).isRequired, rootNode:React.PropTypes.instanceOf(AjxpNode).isRequired, currentNode:React.PropTypes.instanceOf(AjxpNode).isRequired, openEditor:React.PropTypes.func.isRequired }, getInitialState: function(){ // find roles node var siblings = this.props.rootNode.getParent().getChildren(); var roleNode; siblings.forEach(function(s){ if(s.getPath() == '/data/roles'){ roleNode = s; } }); if(!roleNode){ roleNode = new AjxpNode('/data/roles'); } return { searchResultData: false, currentNode:this.props.currentNode, dataModel:this.props.dataModel, roleNode:roleNode }; }, componentWillReceiveProps: function(newProps){ if(!this.state.searchResultData){ this.setState({ currentNode:newProps.currentNode, dataModel:newProps.dataModel }); } }, _extractMergedRole: function(node) { if (!node.getMetadata().get('merged_role') && node.getMetadata().get('json_merged_role')) { node.getMetadata().set('merged_role', JSON.parse(node.getMetadata().get('json_merged_role'))); node.getMetadata().delete('json_merged_role'); } return node.getMetadata().get('merged_role'); }, renderListUserAvatar:function(node){ if(node.getMetadata().get("shared_user")){ return
; } var role = this._extractMergedRole(node); if(role){ try{ var avatar = role.PARAMETERS.AJXP_REPO_SCOPE_ALL['core.conf'].avatar; }catch(e){} if(avatar){ var imgSrc = pydio.Parameters.get("ajxpServerAccess") + "&get_action=get_binary_param&user_id="+ PathUtils.getBasename(node.getPath()) +"&binary_id=" + avatar; return ; } } var iconClass = node.getMetadata().get("icon_class")? node.getMetadata().get("icon_class") : (node.isLeaf()?"icon-file-alt":"icon-folder-close"); return ; }, renderListEntryFirstLine:function(node){ if(node.getMetadata().get("shared_user")) { return node.getLabel() + " ["+this.context.getMessage('user.13')+"]"; }else if(node.getMetadata().get("isAdmin")== pydio.MessageHash['ajxp_conf.14']){ return ( {node.getLabel()} ); }else{ return node.getLabel(); } }, renderListEntrySecondLine:function(node){ if(node.isLeaf()){ if(node.getPath() == '/data/users'){ // This is the Root Group return this.context.getMessage('user.8'); } var strings = []; if(node.getMetadata().get("last_connection_readable")){ strings.push( this.context.getMessage('user.9') + ' ' + node.getMetadata().get("last_connection_readable")); } var role = this._extractMergedRole(node); if(role) { strings.push(this.context.getMessage('user.10').replace("%i", Object.keys(role.ACL).length)); } var roles = node.getMetadata().get('ajxp_roles'); if(roles && roles.split(',').length){ strings.push(this.context.getMessage('user.11').replace("%i", roles.split(',').length)); } return strings.join(" - "); }else{ return this.context.getMessage('user.12') + ': ' + node.getPath().replace('/data/users', ''); } }, renderListEntrySelector:function(node){ if(node.getPath() == '/data/users') return false; return node.isLeaf(); }, displaySearchResults:function(searchTerm, searchDataModel){ this.setState({ searchResultTerm:searchTerm, searchResultData: { term:searchTerm, toggleState:this.hideSearchResults }, currentNode:searchDataModel.getContextNode(), dataModel:searchDataModel }) }, hideSearchResults:function(){ this.setState({ searchResultData: false, currentNode:this.props.currentNode, dataModel:this.props.dataModel }); }, createUserAction: function(){ pydio.UI.openComponentInModal('AdminPeople','CreateUserForm', {dataModel: this.props.dataModel, openRoleEditor:this.openRoleEditor.bind(this)}); }, createGroupAction: function(){ pydio.UI.openComponentInModal('AdminPeople','CreateRoleOrGroupForm', {type:'group', openRoleEditor:this.openRoleEditor.bind(this)}); }, createRoleAction: function(){ pydio.UI.openComponentInModal('AdminPeople','CreateRoleOrGroupForm', {type:'role', roleNode:this.state.roleNode, openRoleEditor:this.openRoleEditor.bind(this)}); }, openUsersImporter: function(){ pydio.UI.openComponentInModal('EnterprisePeople','UsersImportDialog', {dataModel: this.props.dataModel}); }, toggleStateShowRoles: function(){ this.setState({showRolesActions:!this.state.showRolesActions}); }, openRoleEditor:function(node, initialSection = 'activity'){ if(this.refs.editor && this.refs.editor.isDirty()){ if(!window.confirm(this.props.pydio.MessageHash["role_editor.19"])) { return false; } } let editor = Editor; const editorNode = XMLUtils.XPathSelectSingleNode(this.props.pydio.getXmlRegistry(), '//client_configs/component_config[@component="AdminPeople.Dashboard"]/editor'); if(editorNode){ editor = editorNode.getAttribute('namespace') + '.' + editorNode.getAttribute('component'); } var editorData = { COMPONENT:editor, PROPS:{ ref:"editor", node:node, pydio: this.props.pydio, initialEditSection:initialSection, onRequestTabClose:this.closeRoleEditor } }; this.props.openRightPane(editorData); }, closeRoleEditor:function(){ if(this.refs.editor && this.refs.editor.isDirty()){ if(!window.confirm(this.props.pydio.MessageHash["role_editor.19"])) { return false; } } //this.setState({selectedNode:null, showCreator:null}); this.props.closeRightPane(); }, deleteAction: function(node){ const dm = new PydioDataModel(); dm.setSelectedNodes([node]); ResourcesManager.loadClassesAndApply(['AdminActions'], () => { AdminActions.Callbacks.deleteAction(null, [dm]); }) }, renderNodeActions: function(node){ const mime = node.getAjxpMime(); const iconStyle = { color: 'rgba(0,0,0,0.3)', fontSize: 20 }; let actions = []; if(mime === 'user_editable' || mime === 'group' || mime === 'role' || mime==='role_editable'){ actions.push( {this.openRoleEditor(node)}} onClick={(e)=>{e.stopPropagation()}} iconStyle={iconStyle} />); actions.push( {this.deleteAction(node)}} onClick={(e)=>{e.stopPropagation()}} iconStyle={iconStyle} />); }else if(mime === 'user'){ actions.push( {this.openRoleEditor(node)}} onClick={(e)=>{e.stopPropagation()}} iconStyle={iconStyle} />); } return (
{actions}
) }, toggleRoleSearch: function(){ if(this.state.showRolesSearch){ this.setState({showRolesSearch: false, searchRoleString: ''}); }else{ this.setState({showRolesSearch: true}); } }, filterRoleNodes: function(node){ return node.getLabel().toLowerCase().indexOf(this.state.searchRoleString.toLowerCase()) !== -1; }, render: function(){ const fontIconStyle = { style : { backgroundColor: this.props.muiTheme.palette.accent2Color, borderRadius: '50%', width: 36, height: 36, padding: 8, marginRight: 10 }, iconStyle : { color: 'white', fontSize: 20 } } const emptyToolbar =
; let importButton = ; if(!ResourcesManager.moduleIsAvailable('EnterprisePeople')){ let disabled = {style:{...fontIconStyle.style}, iconStyle:{...fontIconStyle.iconStyle}}; disabled.style.backgroundColor = 'rgba(0,0,0,0.23)'; importButton = ; } const leftPanelIndex = this.state.leftPanelIndex || 0; return (

{this.context.getMessage('2', 'ajxp_conf')}

{importButton}
} onTouchTap={() => {this.setState({leftPanelIndex: 0})}}/> } onTouchTap={() => {this.setState({leftPanelIndex: 1})}}/> {leftPanelIndex === 0 &&
} {leftPanelIndex === 1 &&
{this.state.showRolesSearch &&
this.setState({searchRoleString:v}) } />
}
}
); } }); Dashboard = muiThemeable()(Dashboard) export {Dashboard as default}