Skip to content

Update Print.jsx #429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions plugins/Print.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class Print extends React.Component {
/** The side of the application on which to display the sidebar. */
side: PropTypes.string,
theme: PropTypes.object
/** All layouts with this prefix will not be displayed in the print layoutlist */
hidePrintlayoutPrefix: PropTypes.string,
/** Alphabetical order for print layouts: asc or desc */
sortPrintlayouts: PropTypes.string
};
static defaultProps = {
defaultDpi: 300,
Expand All @@ -96,7 +100,8 @@ class Print extends React.Component {
printExternalLayers: true,
printMapHighlights: true,
scaleFactor: 1.9, // Experimentally determined...
side: 'right'
side: 'right',
sortPrintlayouts: 'desc'
};
state = {
center: null,
Expand Down Expand Up @@ -133,9 +138,19 @@ class Print extends React.Component {
componentDidUpdate(prevProps, prevState) {
if (prevProps.theme !== this.props.theme) {
if (this.props.theme && !isEmpty(this.props.theme.print)) {
const layouts = this.props.theme.print.filter(l => l.map).sort((a, b) => {
return a.name.split('/').pop().localeCompare(b.name.split('/').pop(), undefined, {numeric: true});
});
let layouts = null;
if (this.props.sortPrintlayouts == 'asc')
{
layouts = this.props.theme.print.filter(l => l.map && !l.name.startsWith(this.props.hidePrintlayoutPrefix)).sort((a, b) => {
return a.name.split('/').pop().localeCompare(b.name.split('/').pop(), undefined, {numeric: true});
});
}
else
{
layouts = this.props.theme.print.filter(l => l.map && !l.name.startsWith(this.props.hidePrintlayoutPrefix)).sort((a, b) => {
return b.name.split('/').pop().localeCompare(a.name.split('/').pop(), undefined, {numeric: true});
});
}
const layout = layouts.find(l => l.default) || layouts[0];
this.setState({layouts: layouts, layout: layout, atlasFeatures: []});
} else {
Expand Down Expand Up @@ -237,7 +252,7 @@ class Print extends React.Component {
<td>{LocaleUtils.tr("print.layout")}</td>
<td>
<select onChange={this.changeLayout} value={this.state.layout.name}>
{this.state.layouts.map(item => {
{this.state.layouts.filter(item => item.name.startsWith(this.props.hidePrintlayoutPrefix)).map(item => (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant (state.layouts is already filtered)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, there was still a line of original code... Thanks for correcting it.

return (
<option key={item.name} value={item.name}>{item.name.split('/').pop()}</option>
);
Expand Down
Loading