/* * 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 ReactDOM = require('react-dom') const Clipboard = require('clipboard') const {Snackbar, Divider, FlatButton, TextField} = require('material-ui') import PydioContextConsumer from '../PydioContextConsumer' class ErrorStack extends React.Component{ constructor(props){ super(props); this.state = { copyMessage : false, copyError : false }; } componentDidMount(){ this._attachClipboard(); } componentDidUpdate(){ this._attachClipboard(); } componentWillUnmount(){ this._detachClipboard(); } _attachClipboard(){ this._detachClipboard(); if(this._button){ this._clip = new Clipboard(this._button, { text: (trigger) => { return this.props.fullMessage; } }); this._clip.on('success', ()=>{ this.setState({copyMessage:true}, this.clearCopyMessage); }); this._clip.on('error', ()=>{ this.setState({copyError: true}); }); } } _detachClipboard(){ if(this._clip){ this._clip.destroy(); } } clearCopyMessage(){ setTimeout(function(){ this.setState({copyMessage:false}); }.bind(this), 5000); } render(){ const {copyMessage, copyError} = this.state; const {errorStack, fullMessage, pydio} = this.props; return (
{pydio.MessageHash['622']}
{this._button = ReactDOM.findDOMNode(e)}} label={copyMessage ? pydio.MessageHash['624'] : pydio.MessageHash['623']}/>
{copyError && } {!copyError && errorStack.map((m)=>{ return
{m}
}) }
); } } class MessageBar extends React.Component{ constructor(props){ super(props); this.state = {open: false}; } componentDidMount(){ this.props.getPydio().UI.registerMessageBar(this); } componentWillUnmount(){ this.props.getPydio().UI.unregisterMessageBar(); } error(message, actionLabel, actionCallback) { this.setState({ open: true, errorStatus: true, message: message, actionLabel: actionLabel, actionCallback: actionCallback }); } info(message, actionLabel, actionCallback) { this.setState({ open: true, errorStatus: false, message: message, actionLabel: actionLabel, actionCallback: actionCallback }); } handleClose() { this.setState({open: false}); } render(){ let message = this.state.message || ''; const {errorStatus, actionLabel, actionCallback} = this.state; let mainStack = []; let errorStack = []; if(message.split('\n').length){ message.split('\n').forEach((m) => { if(errorStatus && m.length && ( m[0] === '#' || errorStack.length )){ errorStack.push(m); }else{ mainStack.push(m); } }); if(errorStack.length && ! mainStack.length) mainStack = errorStack[0]; }else{ mainStack.push(message); } message = ( {errorStatus && } {mainStack.map((m)=>{return
{m}
})} {errorStack.length > 0 && }
); return ( ); } } MessageBar = PydioContextConsumer(MessageBar); export {MessageBar as default}