Skip to content

Commit 33cdcf7

Browse files
committed
more angular wrapper code
1 parent 35b27f4 commit 33cdcf7

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

demo/angular/src/app/app.component.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
22
import { GridStack, GridStackOptions, GridStackWidget } from 'gridstack';
3-
import { GridstackComponent, NgGridStackWidget, elementCB, nodesCB } from './gridstack.component';
3+
import { GridstackComponent, NgGridStackWidget, elementCB, gsCreateNgComponents, nodesCB } from './gridstack.component';
4+
import { AngularSimpleComponent } from './simple';
5+
import { AngularNgForTestComponent } from './ngFor';
6+
import { AngularNgForCmdTestComponent } from './ngFor_cmd';
47

58
// unique ids sets for each item for correct ngFor updating
69
let ids = 1;
@@ -11,12 +14,15 @@ let ids = 1;
1114
})
1215
export class AppComponent implements OnInit {
1316

17+
@ViewChild(AngularSimpleComponent) case0Comp?: AngularSimpleComponent;
18+
@ViewChild(AngularNgForTestComponent) case1Comp?: AngularNgForTestComponent;
19+
@ViewChild(AngularNgForCmdTestComponent) case2Comp?: AngularNgForCmdTestComponent;
1420
@ViewChild(GridstackComponent) gridComp?: GridstackComponent;
1521
@ViewChild('origTextArea', {static: true}) origTextEl?: ElementRef<HTMLTextAreaElement>;
1622
@ViewChild('textArea', {static: true}) textEl?: ElementRef<HTMLTextAreaElement>;
1723

1824
// which sample to show
19-
public show = 6; // nested
25+
public show = 6;
2026

2127
/** sample grid options and items to load... */
2228
public items: GridStackWidget[] = [
@@ -74,15 +80,37 @@ export class AppComponent implements OnInit {
7480
// setTimeout(() => {
7581
// if (!this.gridComp) return;
7682
// this.saveGrid();
77-
// this.clearGrid();
78-
// // this.loadGrid();
83+
// // this.clearGrid();
84+
// this.delete();
85+
// this.delete();
86+
// this.loadGrid();
87+
// this.delete();
88+
// this.delete();
7989
// }, 500)
8090
}
8191

8292
public onShow(val: number) {
8393
this.show = val;
84-
const data = val === 6 ? this.nestedGridOptions : this.gridOptionsFull;
85-
if (this.origTextEl) this.origTextEl.nativeElement.value = JSON.stringify(data, null, ' ');
94+
95+
// set globally our method to create the right widget type
96+
if (val < 3) GridStack.addRemoveCB = undefined;
97+
else GridStack.addRemoveCB = gsCreateNgComponents;
98+
99+
// let the switch take affect then load the starting values (since we sometimes save())
100+
setTimeout(() => {
101+
let data;
102+
switch(val) {
103+
case 0: data = this.case0Comp?.items; break;
104+
case 1: data = this.case1Comp?.items; break;
105+
case 2: data = this.case2Comp?.items; break;
106+
case 3: data = this.gridComp?.grid?.save(true, true); break;
107+
case 4: data = this.items; break;
108+
case 5: data = this.gridOptionsFull; break;
109+
case 6: data = this.nestedGridOptions; break;
110+
}
111+
if (this.origTextEl) this.origTextEl.nativeElement.value = JSON.stringify(data, null, ' ');
112+
});
113+
if (this.textEl) this.textEl.nativeElement.value = '';
86114

87115
// if (val === 6 && !this.gridComp) {
88116
// const cont: HTMLElement | null = document.querySelector('.grid-container');

0 commit comments

Comments
 (0)