import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import { NgIf, Icon, EventEmitter, EventReceiver } from './';
import ReactCSSTransitionGroup from 'react-addons-css-transition-group';
import './breadcrumb.scss';
export class BreadCrumb extends React.Component {
constructor(props){
super(props);
this.state = {
path: this._formatPath(props.path)
};
}
componentWillReceiveProps(props){
this.setState({path: this._formatPath(props.path)});
}
_formatPath(full_path){
let paths = full_path.split("/");
if(paths.slice(-1)[0] === ''){
paths.pop();
}
paths = paths.map((path, index) => {
let sub_path = paths.slice(0, index+1).join('/'),
label = path === '' ? (CONFIG.name || 'Filestash') : path;
if(index === paths.length - 1){
return {full: null, label: label};
}else{
return {
full: sub_path+'/',
label: label,
minify: function(){
if(index === 0){ return false; }
if(paths.length <= (document.body.clientWidth > 800 ? 5 : 4)){ return false; }
if(index > paths.length - (document.body.clientWidth > 1000? 4 : 3)) return false;
return true;
}()
};
}
});
return paths;
}
render(Element) {
if(new window.URL(location.href).searchParams.get("nav") === "false") return null;
const Path = Element? Element : PathElement;
return (
{
this.state.path.map((path, index) => {
return (
);
})
}
);
}
}
BreadCrumb.propTypes = {
path: PropTypes.string.isRequired,
needSaving: PropTypes.bool
}
const BreadCrumbContainer = (props) => {
return (
);
}
const Logout = (props) => {
const isRunningFromAnIframe = window.self !== window.top;
if(isRunningFromAnIframe) return null;
return (
);
}
const Saving = (props) => {
return (
*
);
}
const Separator = (props) => {
return (
);
}
@EventEmitter
export class PathElementWrapper extends React.Component {
constructor(props){
super(props);
}
limitSize(str, is_highlight = false){
if(is_highlight === true){
if(str.length > 30){
return str.substring(0,12).trim()+'...'+str.substring(str.length - 10, str.length).trim();
}
}else{
if(str.length > 27){
return str.substring(0,20).trim()+'...';
}
}
return str;
}
render(){
let className = "component_path-element-wrapper";
if(this.props.highlight) { className += " highlight"; }
let href = "/files" + (this.props.path.full || "")
href = href
.replace(/\%/g, "%2525") // Hack to get the Link Component to work
// See ExistingThing in 'thing-existing.js'
.replace(/#/g, "%23")
.replace(/\?/g, "%3F");
href = href || "/"
href += location.search;
return (
{this.limitSize(this.props.path.label)}
...
{this.limitSize(this.props.path.label, true)}
{this.limitSize(this.props.path.label)}
);
}
}
// just a hack to make it play nicely with react-dnd as it refuses to use our custom component if it's not wrap by something it knows ...
export class PathElement extends PathElementWrapper {
constructor(props){
super(props);
}
render(highlight = false){
let className = "component_path-element";
if(this.props.isLast){
className += " is-last";
}
return (
);
}
}