n % 2 == 0
+const EDIT_BAR_HEIGHT = getControlBarHeight(1) + DRAG_HANDLE_HEIGHT
+
+const isLeapPage = n => {
+ // pages 5,9,13,17,21,25,29... are leap pages
+ let x = 0
+ const startPage = 1
+ const getMultiple = factor => startPage + 4 * factor
+ let multiple = getMultiple(0)
+ let isLeapPage = false
+ while (multiple < n) {
+ multiple = getMultiple(x)
+ ++x
+ if (multiple === n) {
+ isLeapPage = true
+ break
+ }
+ }
+ return isLeapPage
+}
const addPageBreaks = ({ items, addDashboardItem }) => {
// add enough page breaks so that each item could
// be put on its own page. Due to the react-grid-layout
// unit system, we have to estimate roughly the size of each
- // page. At regular intervals adding an extra unit, like a leap year :P
+ // page. At regular intervals add a unit, like a leap year
let yPos = 0
const yPosList = []
- for (let i = 0; i < items.length; ++i) {
- if (i === 0) {
+ for (let pageNum = 1; pageNum <= items.length; ++pageNum) {
+ if (pageNum === 1) {
yPos += 35
- } else if (i === 4 || i === 10) {
+ } else if (isLeapPage(pageNum)) {
yPos += 40
- } else if (isEven(i)) {
- yPos += 39
} else {
- yPos += 40
+ yPos += 39
}
yPosList.push(yPos)
}
@@ -68,9 +94,9 @@ export class PrintLayoutDashboard extends Component {
// If any items are taller than one page, reduce it to one
// page (react-grid-layout units)
this.props.items.forEach(item => {
- if (item.h > 34) {
+ if (item.h > MAX_ITEM_GRID_HEIGHT) {
this.props.updateDashboardItem(
- Object.assign({}, item, { h: 34 })
+ Object.assign({}, item, { h: MAX_ITEM_GRID_HEIGHT })
)
}
})
@@ -93,14 +119,25 @@ export class PrintLayoutDashboard extends Component {
}
}
+ getWrapperStyle = () => {
+ return this.props.fromEdit
+ ? {
+ paddingTop: spacers.dp24,
+ height:
+ window.innerHeight - EDIT_BAR_HEIGHT - HEADERBAR_HEIGHT,
+ }
+ : {
+ height: window.innerHeight - PRINT_ACTIONS_BAR_HEIGHT,
+ }
+ }
+
render() {
- const style = this.props.fromEdit ? { marginTop: '100px' } : {}
return (
<>
{!this.props.fromEdit && (
)}
-
+
{!this.props.fromEdit &&
}
{
useEffect(() => {
@@ -21,11 +26,16 @@ export const ViewDashboard = props => {
}
}, [props.dashboardIsEditing, props.dashboardIsPrinting])
+ const height =
+ window.innerHeight -
+ HEADERBAR_HEIGHT -
+ getControlBarHeight(props.controlBarRows)
+
return (
<>
-
+
@@ -37,6 +47,7 @@ export const ViewDashboard = props => {
ViewDashboard.propTypes = {
clearEditDashboard: PropTypes.func,
clearPrintDashboard: PropTypes.func,
+ controlBarRows: PropTypes.number,
dashboardIsEditing: PropTypes.bool,
dashboardIsPrinting: PropTypes.bool,
}
@@ -45,6 +56,7 @@ const mapStateToProps = state => {
return {
dashboardIsEditing: sGetIsEditing(state),
dashboardIsPrinting: sGetIsPrinting(state),
+ controlBarRows: sGetControlBarUserRows(state),
}
}
diff --git a/src/components/Dashboard/__tests__/ViewDashboard.spec.js b/src/components/Dashboard/__tests__/ViewDashboard.spec.js
index f3dac4493..313b5066b 100644
--- a/src/components/Dashboard/__tests__/ViewDashboard.spec.js
+++ b/src/components/Dashboard/__tests__/ViewDashboard.spec.js
@@ -23,6 +23,7 @@ describe('ViewDashboard', () => {
clearPrintDashboard: jest.fn(),
dashboardIsEditing: false,
dashboardIsPrinting: false,
+ controlBarRows: 2,
}
})
diff --git a/src/components/Dashboard/__tests__/__snapshots__/EditDashboard.spec.js.snap b/src/components/Dashboard/__tests__/__snapshots__/EditDashboard.spec.js.snap
index 514654f9a..e58517503 100644
--- a/src/components/Dashboard/__tests__/__snapshots__/EditDashboard.spec.js.snap
+++ b/src/components/Dashboard/__tests__/__snapshots__/EditDashboard.spec.js.snap
@@ -3,11 +3,13 @@
exports[`EditDashboard renders message when enough access 1`] = `
-
-
@@ -34,9 +33,6 @@ exports[`EditDashboard renders message when not enough access 1`] = `
exports[`EditDashboard renders print preview 1`] = `
-
diff --git a/src/components/Dashboard/__tests__/__snapshots__/ViewDashboard.spec.js.snap b/src/components/Dashboard/__tests__/__snapshots__/ViewDashboard.spec.js.snap
index 2f9cd8ca2..60712f37e 100644
--- a/src/components/Dashboard/__tests__/__snapshots__/ViewDashboard.spec.js.snap
+++ b/src/components/Dashboard/__tests__/__snapshots__/ViewDashboard.spec.js.snap
@@ -6,6 +6,11 @@ exports[`ViewDashboard renders correctly default 1`] = `
{
container.addEventListener('scroll', this.shouldLoadHandler)
@@ -62,7 +62,7 @@ class ProgressiveLoadingContainer extends Component {
removeHandler() {
const containers = [
window, // this is probably unnecessary
- ...document.getElementsByClassName('app-shell-app'),
+ ...document.getElementsByClassName('dashboard-wrapper'),
]
containers.forEach(container => {
container.removeEventListener('scroll', this.shouldLoadHandler)
diff --git a/src/components/ItemGrid/gridUtil.js b/src/components/ItemGrid/gridUtil.js
index 060c4b6b6..953244b9b 100644
--- a/src/components/ItemGrid/gridUtil.js
+++ b/src/components/ItemGrid/gridUtil.js
@@ -1,6 +1,7 @@
import isFunction from 'd2-utilizr/lib/isFunction'
import { orObject } from '../../modules/util'
+import { MAX_ITEM_GRID_HEIGHT } from '../../modules/printUtils'
// Dimensions for the react-grid-layout
@@ -83,7 +84,7 @@ export const getPrintTitlePageItemShape = () => {
x: 0,
y: 0,
w: GRID_COLUMNS - 1,
- h: 30,
+ h: MAX_ITEM_GRID_HEIGHT,
static: true,
minH: 1,
}
diff --git a/src/components/TitleBar/TitleBar.js b/src/components/TitleBar/TitleBar.js
index b593b84e7..f8c256a43 100644
--- a/src/components/TitleBar/TitleBar.js
+++ b/src/components/TitleBar/TitleBar.js
@@ -26,7 +26,7 @@ const TitleBar = ({ edit }) => {
{edit ? (
diff --git a/src/modules/printUtils.js b/src/modules/printUtils.js
index 465df314e..788498f4d 100644
--- a/src/modules/printUtils.js
+++ b/src/modules/printUtils.js
@@ -7,6 +7,8 @@ import { itemTypeMap } from './itemTypes'
// const a4LandscapeHeightPx = 794
export const a4LandscapeWidthPx = 1102
+export const MAX_ITEM_GRID_HEIGHT = 33
+
export const getDomGridItemsSortedByYPos = elements => {
const types = Object.keys(itemTypeMap)
const elementsWithBoundingRect = orArray(elements).map(el => {