From 94137cb3a771ec6afd803f3cff97da86a14dd54f Mon Sep 17 00:00:00 2001
From: usodhi <61431818+usodhi@users.noreply.github.com>
Date: Fri, 26 Jun 2020 01:46:52 +0530
Subject: background colour + comments

---
 .../collectionGrid/CollectionGridView.tsx          | 41 +++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

(limited to 'src/client/views/collections/collectionGrid/CollectionGridView.tsx')

diff --git a/src/client/views/collections/collectionGrid/CollectionGridView.tsx b/src/client/views/collections/collectionGrid/CollectionGridView.tsx
index 2015ca930..72577e921 100644
--- a/src/client/views/collections/collectionGrid/CollectionGridView.tsx
+++ b/src/client/views/collections/collectionGrid/CollectionGridView.tsx
@@ -47,6 +47,9 @@ export class CollectionGridView extends CollectionSubView(GridSchema) {
     @computed get flexGrid() { return BoolCast(this.props.Document.gridFlex, true); } // is grid static/flexible i.e. whether nodes be moved around and resized
     @computed get compaction() { return StrCast(this.props.Document.gridStartCompaction, StrCast(this.props.Document.gridCompaction, "vertical")); } // is grid static/flexible i.e. whether nodes be moved around and resized
 
+    /**
+     * Sets up the listeners for the list of documents and the reset button.
+     */
     componentDidMount() {
         this._changeListenerDisposer = reaction(() => this.childLayoutPairs, (pairs) => {
             const newLayouts: Layout[] = [];
@@ -68,11 +71,18 @@ export class CollectionGridView extends CollectionSubView(GridSchema) {
         });
     }
 
+    /**
+     * Disposes the listeners.
+     */
     componentWillUnmount() {
         this._changeListenerDisposer?.();
         this._resetListenerDisposer?.();
     }
 
+    /**
+     * @returns the default location of the grid node (i.e. when the grid is static)
+     * @param index 
+     */
     unflexedPosition(index: number): Omit<Layout, "i"> {
         return {
             x: (index % Math.floor(this.numCols / this.defaultW)) * this.defaultW,
@@ -83,6 +93,9 @@ export class CollectionGridView extends CollectionSubView(GridSchema) {
         };
     }
 
+    /**
+     * Maps the x- and y- coordinates of the event to a grid cell.
+     */
     screenToCell(sx: number, sy: number) {
         const pt = this.props.ScreenToLocalTransform().transformPoint(sx, sy);
         const x = Math.floor(pt[0] / this.colWidthPlusGap);
@@ -90,10 +103,16 @@ export class CollectionGridView extends CollectionSubView(GridSchema) {
         return { x, y };
     }
 
+    /**
+     * Creates a layout object for a grid item
+     */
     makeLayoutItem = (doc: Doc, pos: { x: number, y: number }, Static: boolean = false, w: number = this.defaultW, h: number = this.defaultH) => {
         return ({ i: doc[Id], w, h, x: pos.x, y: pos.y, static: Static });
     }
 
+    /**
+     * Adds a layout to the list of layouts.
+     */
     addLayoutItem = (layouts: Layout[], layout: Layout) => {
         const f = layouts.findIndex(l => l.i === layout.i);
         f !== -1 && layouts.splice(f, 1);
@@ -215,6 +234,9 @@ export class CollectionGridView extends CollectionSubView(GridSchema) {
             this.savedLayoutList.map((layout, index) => Object.assign(layout, this.unflexedPosition(index)));
     }
 
+    /**
+     * Handles internal drop of Dash documents.
+     */
     @action
     onInternalDrop = (e: Event, de: DragManager.DropEvent) => {
         const savedLayouts = this.savedLayoutList;
@@ -227,6 +249,16 @@ export class CollectionGridView extends CollectionSubView(GridSchema) {
         return false;
     }
 
+    /**
+     * Handles external drop of images/PDFs etc from outside Dash.
+     */
+    @action
+    onExternalDrop = async (e: React.DragEvent): Promise<void> => {
+        const where = this.screenToCell(e.clientX, e.clientY);
+        super.onExternalDrop(e, { x: where.x, y: where.y });
+
+    }
+
     /**
      * Handles the change in the value of the rowHeight slider.
      */
@@ -234,6 +266,9 @@ export class CollectionGridView extends CollectionSubView(GridSchema) {
     onSliderChange = (event: React.ChangeEvent<HTMLInputElement>) => {
         this._rowHeight = event.currentTarget.valueAsNumber;
     }
+    /**
+     * Handles the user clicking on the slider.
+     */
     @action
     onSliderDown = (e: React.PointerEvent) => {
         this._rowHeight = this.rowHeight; // uses _rowHeight during dragging and sets doc's rowHeight when finished so that operation is undoable
@@ -253,6 +288,9 @@ export class CollectionGridView extends CollectionSubView(GridSchema) {
         ContextMenu.Instance.addItem({ description: "Display", subitems: displayOptionsMenu, icon: "tv" });
     }
 
+    /**
+     * Handles text document creation on double click.
+     */
     onPointerDown = (e: React.PointerEvent) => {
         if (this.props.active(true)) {
             setupMoveUpEvents(this, e, returnFalse, returnFalse,
@@ -276,8 +314,9 @@ export class CollectionGridView extends CollectionSubView(GridSchema) {
             <div className="collectionGridView-contents" ref={this.createDashEventsTarget}
                 style={{ pointerEvents: !this.props.active() && !SnappingManager.GetIsDragging() ? "none" : undefined }}
                 onContextMenu={this.onContextMenu}
-                onPointerDown={e => this.onPointerDown(e)} >
+                onPointerDown={e => this.onPointerDown(e)}>
                 <div className="collectionGridView-gridContainer" ref={this._containerRef}
+                    style={{ backgroundColor: StrCast(this.layoutDoc._backgroundColor, "white") }}
                     onWheel={e => e.stopPropagation()}
                     onScroll={action(e => {
                         if (!this.props.isSelected()) e.currentTarget.scrollTop = this._scroll;
-- 
cgit v1.2.3-70-g09d2

