Skip to content

Commit c37a2a1

Browse files
docs: extend example section (#912)
1 parent 614999c commit c37a2a1

File tree

109 files changed

+2464
-14
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+2464
-14
lines changed

README.md

-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44

55
# angular tree component
66

7-
## News
8-
9-
We are happy to announce, that starting today, [Circlon | group](https://circlon.de) is taking over this repository.
10-
We're going on this journey with the strong belief, that this component should not be missed by the community, and we are hoping on your continuous and significant support as always.
11-
On this new journey we will also receive technical guidance from [Adam](https://github.com/adamkleingit), who will help us to better understand the community, their needs and also to elevate this component to a completely new level of engineering.
12-
137
## Getting started
148

159
Install `angular-tree-component`:

projects/docs-app/src/app/app-routing.module.ts

+34-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ import { ApiComponent } from './fundamentals/api/api.component';
1212
import { StylingComponent } from './fundamentals/styling/styling.component';
1313
import { FocusComponent } from './fundamentals/focus/focus.component';
1414
import { IssuesComponent } from './fundamentals/issues/issues.component';
15+
import { ColumnsExampleComponent } from './examples/columns-example/columns-example.component';
16+
import { CrudExampleComponent } from './examples/crud-example/crud-example.component';
17+
import { LoadMoreExampleComponent } from './examples/load-more-example/load-more-example.component';
18+
import { AsyncGuideComponent } from './guides/async-guide/async-guide.component';
19+
import { FilterGuideComponent } from './guides/filter-guide/filter-guide.component';
20+
import { UpdateGuideComponent } from './guides/update-guide/update-guide.component';
21+
import { DragDropGuideComponent } from './guides/drag-drop-guide/drag-drop-guide.component';
22+
import { CheckboxesGuideComponent } from './guides/checkboxes-guide/checkboxes-guide.component';
23+
import { LargeTreeGuideComponent } from './guides/large-tree-guide/large-tree-guide.component';
24+
import { ReduxGuideComponent } from './guides/redux-guide/redux-guide.component';
25+
import { RtlGuideComponent } from './guides/rtl-guide/rtl-guide.component';
26+
import { CustomFieldsGuideComponent } from './guides/custom-fields-guide/custom-fields-guide.component';
27+
import { ExpandingGuideComponent } from './guides/expanding-guide/expanding-guide.component';
28+
import { AutoScrollGuideComponent } from './guides/auto-scroll-guide/auto-scroll-guide.component';
1529

1630
const routes: Routes = [
1731
{
@@ -22,7 +36,26 @@ const routes: Routes = [
2236
{
2337
path: 'examples',
2438
children: [
25-
{ path: 'basic', component: BasicUsageComponent }
39+
{ path: 'basic', component: BasicUsageComponent },
40+
{ path: 'columns', component: ColumnsExampleComponent },
41+
{ path: 'crud', component: CrudExampleComponent },
42+
{ path: 'loadmore', component: LoadMoreExampleComponent },
43+
]
44+
},
45+
{
46+
path: 'guides',
47+
children: [
48+
{ path: 'async', component: AsyncGuideComponent },
49+
{ path: 'filter', component: FilterGuideComponent },
50+
{ path: 'update', component: UpdateGuideComponent },
51+
{ path: 'dragdrop', component: DragDropGuideComponent },
52+
{ path: 'checkboxes', component: CheckboxesGuideComponent },
53+
{ path: 'largetree', component: LargeTreeGuideComponent },
54+
{ path: 'redux', component: ReduxGuideComponent },
55+
{ path: 'rtl', component: RtlGuideComponent },
56+
{ path: 'customfields', component: CustomFieldsGuideComponent },
57+
{ path: 'expanding', component: ExpandingGuideComponent },
58+
{ path: 'autoscroll', component: AutoScrollGuideComponent },
2659
]
2760
},
2861
{

projects/docs-app/src/app/app.component.ts

+30-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component } from '@angular/core';
22
import { MatIconRegistry } from '@angular/material/icon';
3-
import { DomSanitizer } from '@angular/platform-browser';
3+
import { DomSanitizer, Title } from '@angular/platform-browser';
44
import { NavigationNode } from './navigation/navigation.model';
55
import { NavigationEnd, Router } from '@angular/router';
66
import { filter } from 'rxjs/operators';
@@ -11,7 +11,7 @@ import { filter } from 'rxjs/operators';
1111
styleUrls: ['./app.component.scss']
1212
})
1313
export class AppComponent {
14-
title = 'docs-app';
14+
baseTitle = 'Angular Tree Component';
1515

1616
nav: NavigationNode[] = [
1717
{ title: 'Getting Started', children: null, link: [''] },
@@ -29,9 +29,27 @@ export class AppComponent {
2929
{ title: 'Common issues', url: 'fundamentals/issues', children: null, link: ['fundamentals', 'issues'] },
3030
]
3131
},
32+
{ title: 'Guides', children:
33+
[
34+
{ title: 'Async Data', url: 'guides/async', children: null, link: ['guides', 'async'] },
35+
{ title: 'Filtering', url: 'guides/filter', children: null, link: ['guides', 'filter'] },
36+
{ title: 'Updating the tree', url: 'guides/update', children: null, link: ['guides', 'update'] },
37+
{ title: 'Drag & Drop', url: 'guides/dragdrop', children: null, link: ['guides', 'dragdrop'] },
38+
{ title: 'Checkboxes', url: 'guides/checkboxes', children: null, link: ['guides', 'checkboxes'] },
39+
{ title: 'Large Trees & Virtual Scroll', url: 'guides/largetree', children: null, link: ['guides', 'largetree'] },
40+
{ title: 'Redux / Immutable Data', url: 'guides/redux', children: null, link: ['guides', 'redux'] },
41+
{ title: 'RTL', url: 'guides/rtl', children: null, link: ['guides', 'rtl'] },
42+
{ title: 'Custom Fields', url: 'guides/customfields', children: null, link: ['guides', 'customfields'] },
43+
{ title: 'Expanding nodes on init', url: 'guides/expanding', children: null, link: ['guides', 'expanding'] },
44+
{ title: 'Auto Scrolling', url: 'guides/autoscroll', children: null, link: ['guides', 'autoscroll'] },
45+
]
46+
},
3247
{ title: 'Examples', children:
3348
[
3449
{ title: 'Basic', url: 'examples/basic', children: null, link: ['examples', 'basic'] },
50+
{ title: 'Columns', url: 'examples/columns', children: null, link: ['examples', 'columns'] },
51+
{ title: 'CRUD', url: 'examples/crud', children: null, link: ['examples', 'crud'] },
52+
{ title: 'Load more', url: 'examples/loadmore', children: null, link: ['examples', 'loadmore'] },
3553
]
3654
},
3755
];
@@ -40,7 +58,8 @@ export class AppComponent {
4058
constructor(
4159
iconRegistry: MatIconRegistry,
4260
sanitizer: DomSanitizer,
43-
private router: Router
61+
private router: Router,
62+
private titleService: Title,
4463
) {
4564
iconRegistry.addSvgIcon(
4665
'github',
@@ -71,6 +90,14 @@ export class AppComponent {
7190
if (newCurrent.length >= 2 && newCurrent.find(n => n.title === this.nav[0].title) !== undefined) {
7291
newCurrent = newCurrent.filter(n => n.title !== this.nav[0].title);
7392
}
93+
94+
// set title on all but landing page
95+
if (newCurrent?.length && newCurrent[0].title !== 'Getting Started') {
96+
this.titleService.setTitle(`${this.baseTitle} - ${newCurrent[0].title}`);
97+
} else {
98+
this.titleService.setTitle(this.baseTitle);
99+
}
100+
74101
this.currentNodes = newCurrent;
75102
});
76103
}

projects/docs-app/src/app/app.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { TreeModule } from 'angular-tree-component';
1717
import { FundamentalsModule } from './fundamentals/fundamentals.module';
1818
import { LayoutModule } from './layout/layout.module';
1919
import { SharedModule } from './shared/shared.module';
20+
import { GuidesModule } from './guides/guides.module';
2021

2122
@NgModule({
2223
declarations: [AppComponent, GettingStartedComponent],
@@ -36,6 +37,7 @@ import { SharedModule } from './shared/shared.module';
3637
ExamplesModule,
3738
TreeModule,
3839
FundamentalsModule,
40+
GuidesModule,
3941
],
4042
providers: [],
4143
bootstrap: [AppComponent]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<tree-root [nodes]="nodes"></tree-root>

projects/docs-app/src/app/examples/basic-usage/basic-tree/basic-tree.component.scss

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { BasicTreeComponent } from './basic-tree.component';
4+
5+
describe('BasicTreeComponent', () => {
6+
let component: BasicTreeComponent;
7+
let fixture: ComponentFixture<BasicTreeComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
declarations: [ BasicTreeComponent ]
12+
})
13+
.compileComponents();
14+
});
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(BasicTreeComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-basic-tree',
5+
templateUrl: './basic-tree.component.html',
6+
styleUrls: ['./basic-tree.component.scss']
7+
})
8+
export class BasicTreeComponent {
9+
10+
nodes = [
11+
{
12+
name: 'root1',
13+
children: [
14+
{ name: 'child1' },
15+
{ name: 'child2' }
16+
]
17+
},
18+
{
19+
name: 'root2',
20+
children: [
21+
{ name: 'child2.1', children: [] },
22+
{ name: 'child2.2', children: [
23+
{name: 'grandchild2.2.1'}
24+
] }
25+
]
26+
},
27+
{ name: 'root3' },
28+
{ name: 'root4', children: [] },
29+
{ name: 'root5', children: null }
30+
];
31+
32+
}

projects/docs-app/src/app/examples/basic-usage/basic-usage.component.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ <h1>Basic usage</h1>
22

33
<h2>Working tree</h2>
44

5-
<tree-root [nodes]="nodes"></tree-root>
5+
<div class="demo-container">
6+
<app-basic-tree></app-basic-tree>
7+
</div>
68

79
<h2>How to implement</h2>
10+
11+
<p>See <a [routerLink]="['/', 'fundamentals', 'nodes']">Nodes Fundamentals</a></p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<h1>Tree with columns</h1>
2+
3+
<h2>Working tree</h2>
4+
5+
<div class="demo-container">
6+
<app-columns></app-columns>
7+
</div>
8+
9+
<h2>How to implement</h2>
10+
11+
<p>To create columns inside the tree we need to use the templating options of the tree and style them with css.</p>
12+
<p>
13+
The example component contains two parts. The header and the tree itself. The header is responsible for displaying the column header.
14+
This is needed to give the tree the grid style. If you just want the tree to have columns without any header you don't need to build a header.
15+
</p>
16+
17+
<h3>#treeNodeWrapperTemplate</h3>
18+
<p>
19+
To show the tree in columns it's not needed to use the full templating option. But at least the <code>treeNodeWrapperTemplate</code> is needed.
20+
See also the <a [routerLink]="['/', 'fundamentals', 'templates']">Template Fundamentals</a>.
21+
</p>
22+
23+
<h3>Column definition</h3>
24+
<p>
25+
The example uses a simple array <code>columns = ['city', 'zipCode']</code> to handle the columns.
26+
This array includes the property names that should be shown as columns and does not include the name, which is the first column.
27+
The name is handled differently as seen in the example. The columns array is just looped over and shown.
28+
In a more advanced example you could have the columns array as an input and also handle the name dynamically.
29+
</p>

projects/docs-app/src/app/examples/columns-example/columns-example.component.scss

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { ColumnsExampleComponent } from './columns-example.component';
4+
5+
describe('ColumnsExampleComponent', () => {
6+
let component: ColumnsExampleComponent;
7+
let fixture: ComponentFixture<ColumnsExampleComponent>;
8+
9+
beforeEach(async () => {
10+
await TestBed.configureTestingModule({
11+
declarations: [ ColumnsExampleComponent ]
12+
})
13+
.compileComponents();
14+
});
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(ColumnsExampleComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-columns-example',
5+
templateUrl: './columns-example.component.html',
6+
styleUrls: ['./columns-example.component.scss']
7+
})
8+
export class ColumnsExampleComponent implements OnInit {
9+
10+
constructor() { }
11+
12+
ngOnInit(): void {
13+
}
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<div class="base-tree-container">
2+
<div #treeHeader class="tree-header">
3+
<div class="tree-column tree-header-column"><span>Company name</span></div>
4+
<div
5+
*ngFor="let columnName of columns"
6+
class="tree-column tree-header-column">
7+
<span>{{ columnName }}</span>
8+
</div>
9+
</div>
10+
<div class="tree-wrapper">
11+
<tree-root
12+
#tree
13+
[options]="options"
14+
[nodes]="nodes">
15+
<!-- Node wrapper template to control wrapper classes and cursor behaviour -->
16+
<ng-template #treeNodeWrapperTemplate let-node let-index="index">
17+
<div class="tree-node-wrapper no-pointer">
18+
<tree-node-expander [node]="node"></tree-node-expander>
19+
<div class="node-content-wrapper pointer"
20+
[class.node-content-wrapper-active]="node.isActive"
21+
[class.node-content-wrapper-focused]="node.isFocused"
22+
(click)="node.mouseAction('click', $event)"
23+
(dblclick)="node.mouseAction('dblClick', $event)"
24+
(contextmenu)="node.mouseAction('contextMenu', $event)"
25+
(treeDrop)="node.onDrop($event)"
26+
[treeAllowDrop]="node.allowDrop"
27+
[treeDrag]="node"
28+
[treeDragEnabled]="node.allowDrag()">
29+
30+
<div class="tree-column-wrapper">
31+
<div class="tree-column" [title]="node.data.name">
32+
<span>{{ node.data.name }}</span>
33+
</div>
34+
<div
35+
*ngFor="let columnName of columns"
36+
class="tree-column"
37+
[title]="node.data[columnName]">
38+
<span>{{node.data[columnName]}}</span>
39+
</div>
40+
</div>
41+
</div>
42+
</div>
43+
</ng-template>
44+
</tree-root>
45+
</div>
46+
</div>

0 commit comments

Comments
 (0)