/* * 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 {Component} = require('react'); const {List, ListItem, Paper, CardTitle, Divider, Subheader, TextField, Table, TableHeader, TableRow, TableBody, TableHeaderColumn, TableRowColumn} = require('material-ui') const PathUtils = require('pydio/util/path') class JSDocsPanel extends Component{ constructor(props, context){ super(props, context); this.state = {data : {}, selection: null, search: ''}; } componentDidMount(){ PydioApi.getClient().loadFile('plugins/gui.ajax/docgen.json', (transp) => { if(!transp.responseJSON || !transp.responseJSON['gui.ajax']){ this.setState({error: 'Docs are not loaded, you probably have to run \'grunt docgen\' command inside the gui.ajax plugin.'}); return; } let data = transp.responseJSON['gui.ajax']; Object.keys(transp.responseJSON).forEach((pluginId) => { if(pluginId === 'gui.ajax') return; const comps = transp.responseJSON[pluginId]; Object.keys(comps).forEach((compName) => { data[pluginId + '/' + compName] = comps[compName]; }); }); this.setState({data}); }); } onSearch(event, value){ this.setState({search: value}); } render(){ const {data, selection, search, error} = this.state; let items = []; let classPathes = {}; Object.keys(data).forEach((key) => { const parts = key.split('/'); const classPath = parts.shift(); let title = parts.pop().replace('.js', '').replace('.es6', ''); if(search && title.indexOf(search) === -1){ return; }else if(search && title.indexOf(search) > -1){ let parts = []; const startIndex = title.indexOf(search); const endIndex = startIndex + search.length; if(startIndex > 0) parts.push(title.substr(0, startIndex)); parts.push({title.substr(startIndex, search.length)}); if(endIndex < title.length - 1) parts.push(title.substr(endIndex)); title = {parts} } const secondary = parts.join('/'); if(!classPathes[classPath]){ classPathes[classPath] = classPath; items.push(); items.push({classPath}); } items.push( {this.setState({selection:key})}} /> ); }); return (
{error &&
{error}
} {items}
{selection && }
); } } class ClassPanel extends Component{ render(){ const {path, data} = this.props; const title = PathUtils.getBasename(path); const classPath = PathUtils.getDirname(path); const largeColumn = {width: '35%'}; let props = [], methods = []; if(data.props && path.indexOf('core/') !== 0){ Object.keys(data.props).forEach((pName) => { const pData = data.props[pName]; props.push( {pName} {pData.description} {pData.type && pData.type.raw && pData.type.raw.replace('React.PropTypes.', '').replace('.isRequired', '')} {(pData.required || (pData.type && pData.type.raw && pData.type.raw.indexOf('.isRequired') > -1) ) ? 'true': ''} ); }); } if(data.methods){ methods = data.methods.map((mData) => { let params = mData.params.map((p) => { return
{p.name + (p.type ? (' (' + p.type.name + ') ') : '') + (p.description? ': ' + p.description : '')}
; }); return( {mData.name} {mData.description} {params} {mData.returns && mData.returns.type ? mData.returns.type.name : ''} ); }); } const dStyle = {padding:'0 16px 16px'}; return (
{data.description}
{data.require &&
Usage: {data.require}
} {props.length > 0 &&
Name Description Type Required {props}
} {!props.length &&
No Props documented
} {methods.length > 0 &&
Name Description Parameters Return {methods}
} {!methods.length &&
No Methods documented
}
); } } export {JSDocsPanel as default}