-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from MarshMapper/refactor-place-list
Refactor list of features into separate component. Add
- Loading branch information
Showing
8 changed files
with
174 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/app/components/feature-list/feature-list.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<div [ngClass]="getFeatureContainerClass()" id="featureTableContainer"> | ||
<div class="table-container"> | ||
<table mat-table [dataSource]="dataSource"> | ||
<ng-container matColumnDef="id"> | ||
<td mat-cell *matCellDef="let element"> {{element.id}} </td> | ||
</ng-container> | ||
<ng-container matColumnDef="name"> | ||
<td class="table-cell" mat-cell *matCellDef="let element"> {{element.name}} </td> | ||
</ng-container> | ||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr> | ||
</table> | ||
</div> | ||
<div class="paginator-container"> | ||
<mat-paginator #featurePaginator class="feature-paginator" showFirstLastButtons | ||
[pageSizeOptions]="[5, 10, 20, 50]" pageSize="50" aria-label="Select page"> | ||
</mat-paginator> | ||
</div> | ||
</div> |
22 changes: 22 additions & 0 deletions
22
src/app/components/feature-list/feature-list.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 64px header, 48px footer, 48px paginator | ||
.feature-table-container-horizontal { | ||
height: calc(100vh - 112px); | ||
display: grid; | ||
grid-template-rows: calc(100vh - 160px) 48px; | ||
} | ||
.feature-table-container-vertical { | ||
height: calc(40vh - 48px); | ||
display: grid; | ||
grid-template-rows: calc(40vh - 96px) 48px; | ||
} | ||
.table-container { | ||
overflow-y: auto; | ||
} | ||
.mat-mdc-row { | ||
height: 24px; | ||
font-size: 14px; | ||
line-height: 18px; | ||
} | ||
.paginator-container { | ||
overflow: hidden; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/app/components/feature-list/feature-list.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { FeatureListComponent } from './feature-list.component'; | ||
|
||
describe('FeatureListComponent', () => { | ||
let component: FeatureListComponent; | ||
let fixture: ComponentFixture<FeatureListComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [FeatureListComponent] | ||
}) | ||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(FeatureListComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { map, Observable, shareReplay } from 'rxjs'; | ||
import { AfterViewInit, Component, inject, Input, OnInit, ViewChild } from '@angular/core'; | ||
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout'; | ||
import { MatPaginator, MatPaginatorIntl, MatPaginatorModule } from '@angular/material/paginator'; | ||
import { MatTableDataSource, MatTableModule } from '@angular/material/table'; | ||
import { MatSortModule } from '@angular/material/sort'; | ||
import { when } from '@arcgis/core/core/reactiveUtils'; | ||
|
||
function getRangeLabel(page: number, pageSize: number, length: number): string { | ||
if (length === 0 || pageSize === 0) { | ||
return `0 of ${length}`; | ||
} | ||
length = Math.max(length, 0); | ||
const startIndex = page * pageSize; | ||
const endIndex = startIndex < length ? Math.min(startIndex + pageSize, length) : startIndex + pageSize; | ||
return `${startIndex + 1} – ${endIndex}`; | ||
} | ||
function CustomPaginator() { | ||
const customPaginatorIntl = new MatPaginatorIntl(); | ||
customPaginatorIntl.itemsPerPageLabel = 'Show:'; | ||
customPaginatorIntl.getRangeLabel = getRangeLabel; | ||
|
||
return customPaginatorIntl; | ||
} | ||
@Component({ | ||
selector: 'app-feature-list', | ||
standalone: true, | ||
imports: [CommonModule, MatPaginatorModule, MatTableModule, MatSortModule ], | ||
providers: [ | ||
{ provide: MatPaginatorIntl, useValue: CustomPaginator() } | ||
], | ||
templateUrl: './feature-list.component.html', | ||
styleUrl: './feature-list.component.scss' | ||
}) | ||
export class FeatureListComponent implements OnInit, AfterViewInit { | ||
public isSmallPortrait: boolean = false; | ||
private breakpointObserver = inject(BreakpointObserver); | ||
@ViewChild(MatPaginator) paginator!: MatPaginator; | ||
@Input() featureLayerView!: Observable<__esri.FeatureLayerView>; | ||
|
||
displayedColumns: string[] = ['name']; // Only 'name' column is displayed | ||
dataSource = new MatTableDataSource(); | ||
|
||
isSmallPortrait$ = this.breakpointObserver.observe([ | ||
Breakpoints.TabletPortrait, | ||
Breakpoints.HandsetPortrait]) | ||
.pipe( | ||
map(result => result.matches), | ||
shareReplay() | ||
); | ||
getFeatureContainerClass(): string { | ||
return this.isSmallPortrait ? 'feature-table-container-vertical' : 'feature-table-container-horizontal'; | ||
} | ||
ngOnInit(): void { | ||
this.isSmallPortrait$.subscribe((isSmallPortrait) => { | ||
this.isSmallPortrait = isSmallPortrait; | ||
}); | ||
// parent component will pass in the featureLayerView observable and emit a new value | ||
// each time the view changes | ||
this.featureLayerView.subscribe((layerView: __esri.FeatureLayerView) => { | ||
when( | ||
() => !layerView.updating, | ||
(val) => { | ||
// get all the features in view from the layerView | ||
layerView.queryFeatures().then((results) => { | ||
let features: any[] = []; | ||
// add to array with just the name for display and the id for selection / tracking | ||
results.features.forEach((feature) => { | ||
features.push({ id: feature.attributes.id, name: feature.attributes.name }); | ||
}); | ||
// sort the features by name, then update the data table | ||
features.sort((a, b) => a.name.localeCompare(b.name)); | ||
this.dataSource.data = features; | ||
}) | ||
}); | ||
}); | ||
} | ||
ngAfterViewInit(): void { | ||
this.dataSource.paginator = this.paginator; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters