(docList);
+ }
}
- // _.reject() on item removal?
-
-
/**
* @returns a list of `ContentFittingDocumentView`s inside wrapper divs.
* The key of the wrapper div must be the same as the `i` value of the corresponding layout.
@@ -165,12 +217,13 @@ export class CollectionGridView extends CollectionSubView(GridSchema) {
for (let i = 0; i < childLayoutPairs.length; i++) {
const { layout } = childLayoutPairs[i];
- const dxf = () => this.lookupIndividualTransform(docList?.[i]);
- const width = () => this.width(docList?.[i]);
- const height = () => this.height(docList?.[i]);
+ const dxf = () => this.lookupIndividualTransform(docList[i]);
+ const width = () => this.width(docList[i]);
+ const height = () => this.height(docList[i]);
collector.push(
{this.getDisplayDoc(layout, dxf, width, height)}
@@ -187,10 +240,20 @@ export class CollectionGridView extends CollectionSubView(GridSchema) {
toLayoutList(docLayoutList: Doc[]): Layout[] {
const layouts: Layout[] = [];
- for (const layout of docLayoutList) {
- layouts.push(
- { i: layout.i as string, x: layout.x as number, y: layout.y as number, w: layout.w as number, h: layout.h as number }
- );
+
+ if (this.props.Document.flexGrid) {
+ for (const layout of docLayoutList) {
+ layouts.push(
+ { i: layout.i as string, x: layout.x as number, y: layout.y as number, w: layout.w as number, h: layout.h as number, static: !(this.props.Document.flexGrid as boolean) }
+ );
+ }
+ }
+ else {
+ for (let i = 0; i < docLayoutList.length; i++) {
+ layouts.push(
+ { i: docLayoutList[i].i as string, x: 2 * (i % Math.floor(this.props.Document.numCols as number / 2)), y: 2 * Math.floor(i / Math.floor(this.props.Document.numCols as number / 2)), w: 2, h: 2, static: true }
+ );
+ }
}
return layouts;
}
@@ -204,9 +267,9 @@ export class CollectionGridView extends CollectionSubView(GridSchema) {
if (this.childLayoutPairs.length > previousLength) {
console.log("adding doc");
const layoutDoc: Doc = new Doc();
- layoutDoc.i = layoutDoc[Id];
- layoutDoc.x = 2 * (previousLength % 5);
- layoutDoc.y = 2 * Math.floor(previousLength / 5);
+ layoutDoc.i = this.childLayoutPairs[this.childLayoutPairs.length - 1].layout[Id];
+ layoutDoc.x = 2 * (previousLength % Math.floor(this.props.Document.numCols as number / 2));
+ layoutDoc.y = 2 * Math.floor(previousLength / Math.floor(this.props.Document.numCols as number / 2));
layoutDoc.w = 2;
layoutDoc.h = 2;
@@ -218,11 +281,18 @@ export class CollectionGridView extends CollectionSubView(GridSchema) {
this.checkUpdate();
+ //console.log("here first?");
+
const docList: Doc[] = DocListCast(this.props.Document.gridLayouts);
+ //console.log("doclist length:::" + docList.length);
const contents: JSX.Element[] = this.contents;
const layout: Layout[] = this.toLayoutList(docList);
+ // for (const doc of docList) {
+ // console.log(doc.i);
+ // }
+
// if (layout.length === 0) {
// console.log("layouts not loaded");
// }
@@ -247,7 +317,8 @@ export class CollectionGridView extends CollectionSubView(GridSchema) {
layout={layout}
numCols={this.props.Document.numCols as number}
rowHeight={this.props.Document.rowHeight as number}
- setLayout={(layout: Layout[]) => this.setLayout(layout)}
+ setLayout={this.setLayout}
+ flex={this.props.Document.flexGrid as boolean}
/>
);
diff --git a/src/client/views/collections/collectionGrid/Grid.tsx b/src/client/views/collections/collectionGrid/Grid.tsx
index a5f5c724a..49179aaa8 100644
--- a/src/client/views/collections/collectionGrid/Grid.tsx
+++ b/src/client/views/collections/collectionGrid/Grid.tsx
@@ -7,7 +7,6 @@ import "../../../../../node_modules/react-resizable/css/styles.css";
import * as GridLayout from 'react-grid-layout';
import { Layout } from 'react-grid-layout';
-import { CollectionGridView } from './CollectionGridView';
export { Layout } from 'react-grid-layout';
@@ -18,6 +17,7 @@ interface GridProps {
numCols: number;
rowHeight: number;
setLayout: Function;
+ flex: boolean;
}
/**
@@ -26,13 +26,20 @@ interface GridProps {
@observer
export default class Grid extends React.Component {
+ constructor(props: Readonly) {
+ super(props);
+
+ this.onLayoutChange = this.onLayoutChange.bind(this);
+ }
/**
* If there has been a change in layout, calls a method in CollectionGridView to set the layouts on the Document.
* @param layout `Layout[]`
*/
onLayoutChange(layout: Layout[]) {
- console.log("setting in grid component" + layout[0].w);
+ console.log("setting in grid component" + layout[0]?.w);
+ // if (this.props.flex) {
this.props.setLayout(layout);
+ // }
}
render() {
@@ -46,7 +53,7 @@ export default class Grid extends React.Component {
compactType={null}
isDroppable={true}
margin={[10, 10]}
- onLayoutChange={layout => this.onLayoutChange(layout)}
+ onLayoutChange={this.onLayoutChange}
>
{this.props.nodeList}
--
cgit v1.2.3-70-g09d2