Add show modification only checkbox

This commit is contained in:
Johannes Zillmann 2017-02-03 13:14:42 +01:00
parent 12f6105d90
commit 9977814d34
2 changed files with 105 additions and 72 deletions

View File

@ -1,11 +1,13 @@
import React from 'react'; import React from 'react';
import ButtonToolbar from 'react-bootstrap/lib/ButtonToolbar' import ButtonToolbar from 'react-bootstrap/lib/ButtonToolbar'
import ButtonGroup from 'react-bootstrap/lib/ButtonGroup'
import Button from 'react-bootstrap/lib/Button' import Button from 'react-bootstrap/lib/Button'
import DropdownButton from 'react-bootstrap/lib/DropdownButton' import DropdownButton from 'react-bootstrap/lib/DropdownButton'
import Pagination from 'react-bootstrap/lib/Pagination' import Pagination from 'react-bootstrap/lib/Pagination'
import MenuItem from 'react-bootstrap/lib/MenuItem' import MenuItem from 'react-bootstrap/lib/MenuItem'
import Label from 'react-bootstrap/lib/Label' import Label from 'react-bootstrap/lib/Label'
import Checkbox from 'react-bootstrap/lib/Checkbox'
import ContentView from '../models/ContentView.jsx'; import ContentView from '../models/ContentView.jsx';
import PdfPageView from './PdfPageView.jsx'; import PdfPageView from './PdfPageView.jsx';
@ -23,7 +25,8 @@ export default class DebugView extends React.Component {
super(props); super(props);
this.state = { this.state = {
currentTransformation: 0, currentTransformation: 0,
pageNr: -1 pageNr: -1,
modificationsOnly: false
}; };
} }
@ -51,6 +54,12 @@ export default class DebugView extends React.Component {
}); });
} }
showModifications() {
this.setState({
modificationsOnly: !this.state.modificationsOnly
});
}
render() { render() {
const {currentTransformation, pageNr} = this.state; const {currentTransformation, pageNr} = this.state;
@ -72,9 +81,11 @@ export default class DebugView extends React.Component {
transformedPages = transformedPages.filter((elem, i) => pageNr == -1 || i == pageNr); transformedPages = transformedPages.filter((elem, i) => pageNr == -1 || i == pageNr);
var pageComponents; var pageComponents;
var showModificationCheckbox = false;
switch (contentView) { switch (contentView) {
case ContentView.PDF: case ContentView.PDF:
pageComponents = transformedPages.map(page => <PdfPageView key={ page.index } pdfPage={ page } />); pageComponents = transformedPages.map(page => <PdfPageView key={ page.index } pdfPage={ page } modificationsOnly={ this.state.modificationsOnly } />);
showModificationCheckbox = true;
break; break;
case ContentView.TEXT: case ContentView.TEXT:
//transformedPages.forEach(p => console.debug(p)); //transformedPages.forEach(p => console.debug(p));
@ -117,18 +128,30 @@ export default class DebugView extends React.Component {
<tr> <tr>
<td> <td>
<ButtonToolbar> <ButtonToolbar>
<Button className={ currentTransformation > 0 ? 'btn-round' : 'btn-round disabled' } onClick={ this.prevTransformation.bind(this) }> <ButtonGroup>
Previous <Button className={ currentTransformation > 0 ? 'btn-round' : 'btn-round disabled' } onClick={ this.prevTransformation.bind(this) }>
</Button> Previous
{ ' ' } </Button>
<Button className={ currentTransformation < transformations.length - 1 ? 'btn-round' : 'btn-round disabled' } onClick={ this.nextTransformation.bind(this) }> </ButtonGroup>
Next <ButtonGroup>
</Button> { ' ' }
<DropdownButton title={ currentTransformationName } id="dropdown-size-medium"> <Button className={ currentTransformation < transformations.length - 1 ? 'btn-round' : 'btn-round disabled' } onClick={ this.nextTransformation.bind(this) }>
{ transformations.map((transformation, i) => <MenuItem key={ i } eventKey={ i } onSelect={ this.selectTransformation.bind(this, i) }> Next
{ transformation.name } </Button>
</MenuItem>) } </ButtonGroup>
</DropdownButton> <ButtonGroup>
<DropdownButton title={ currentTransformationName } id="dropdown-size-medium">
{ transformations.map((transformation, i) => <MenuItem key={ i } eventKey={ i } onSelect={ this.selectTransformation.bind(this, i) }>
{ transformation.name }
</MenuItem>) }
</DropdownButton>
</ButtonGroup>
<ButtonGroup>
{ showModificationCheckbox &&
<Checkbox onClick={ this.showModifications.bind(this) }>
Show only modifications
</Checkbox> }
</ButtonGroup>
</ButtonToolbar> </ButtonToolbar>
</td> </td>
<td style={ { padding: '5px' } }> <td style={ { padding: '5px' } }>

View File

@ -6,69 +6,79 @@ export default class PdfPageView extends React.Component {
static propTypes = { static propTypes = {
pdfPage: React.PropTypes.object.isRequired, pdfPage: React.PropTypes.object.isRequired,
modificationsOnly: React.PropTypes.bool.isRequired,
}; };
render() { render() {
const header = "Page " + (this.props.pdfPage.index + 1); const header = "Page " + (this.props.pdfPage.index + 1);
var textItems = this.props.pdfPage.textItems;
var content = <div/>
if (this.props.modificationsOnly) {
textItems = textItems.filter(item => item.annotation);
}
if (!this.props.modificationsOnly || textItems.length > 0) {
content = <div>
<h2>{ header }</h2>
<Table responsive>
<thead>
<tr>
<th>
#
</th>
<th>
Text
</th>
<th>
X
</th>
<th>
Y
</th>
<th>
Width
</th>
<th>
Height
</th>
<th>
Annotation
</th>
</tr>
</thead>
<tbody>
{ textItems.map((textItem, i) => <tr key={ i } style={ textItem.annotation ? {
color: textItem.annotation.color
} : null }>
<td>
{ i }
</td>
<td>
{ textItem.text }
</td>
<td>
{ textItem.x }
</td>
<td>
{ textItem.y }
</td>
<td>
{ textItem.width }
</td>
<td>
{ textItem.height }
</td>
<td>
{ textItem.annotation ? textItem.annotation.category : '' }
</td>
</tr>
) }
</tbody>
</Table>
</div>
}
return ( return (
<div> content
<h2>{ header }</h2>
<Table responsive>
<thead>
<tr>
<th>
#
</th>
<th>
Text
</th>
<th>
X
</th>
<th>
Y
</th>
<th>
Width
</th>
<th>
Height
</th>
<th>
Annotation
</th>
</tr>
</thead>
<tbody>
{ this.props.pdfPage.textItems.map((textItem, i) => <tr key={ i } style={ textItem.annotation ? {
color: textItem.annotation.color
} : null }>
<td>
{ i }
</td>
<td>
{ textItem.text }
</td>
<td>
{ textItem.x }
</td>
<td>
{ textItem.y }
</td>
<td>
{ textItem.width }
</td>
<td>
{ textItem.height }
</td>
<td>
{ textItem.annotation ? textItem.annotation.category : '' }
</td>
</tr>
) }
</tbody>
</Table>
</div>
); );
} }
} }