Commit c342e156 authored by ndurand's avatar ndurand
Browse files

correction typage des fonctions

parent e1315135
......@@ -19,7 +19,7 @@ export class DynamicTemplateComponent implements OnInit {
constructor(protected dataService: DataService) { }
ngOnInit() {
ngOnInit(): void {
if (this.type) {
this.htmlContent = '';
this.dataService.loadHtmlContent(this.type)
......
......@@ -48,7 +48,7 @@ export class EditDataComponent implements OnInit {
}
/** */
ngOnInit() {
ngOnInit(): void {
this.gid = this.activatedRoute.snapshot.paramMap.get('gid');
if ( this.gid ) {
......@@ -73,7 +73,7 @@ export class EditDataComponent implements OnInit {
}
/** */
saveData() {
saveData(): void {
this.dataService.postData([this.feature]);
}
......
......@@ -20,7 +20,7 @@ export class MainComponent implements OnInit {
constructor(private activatedRoute: ActivatedRoute, private dataService: DataService, private tableViewData: TableViewDataService, ) { }
ngOnInit() {
ngOnInit(): void {
/** uuid */
if (this.activatedRoute.snapshot.paramMap.get('uuid')) {
this.uuid = this.activatedRoute.snapshot.paramMap.get('uuid');
......
......@@ -3,10 +3,10 @@
<!-- Template pagination -->
<ng-template #paginationTpl>
<div class="d-flex justify-content-between p-2">
<ngb-pagination [collectionSize]="total$ | async" [(page)]="state.page" [maxSize]="10" [pageSize]="state.pageSize" [rotate]="true" [boundaryLinks]="true" >
<ngb-pagination [collectionSize]="total$ | async" [(page)]="tableViewData.page" [maxSize]="10" [pageSize]="tableViewData.pageSize" [rotate]="true" [boundaryLinks]="true" >
</ngb-pagination>
<select class="custom-select" style="width: auto" name="pageSize" [(ngModel)]="state.pageSize" >
<select class="custom-select" style="width: auto" name="pageSize" [(ngModel)]="tableViewData.pageSize" >
<option *ngFor="let choiceValue of pageSizeChoice" [ngValue]="choiceValue">{{choiceValue}}</option>
</select>
</div>
......@@ -14,8 +14,8 @@
<!-- Recherche-->
<div class="form-group form-inline">
Recherche : <input class="form-control ml-2" type="text" name="searchTerm" [(ngModel)]="state.searchTerm"/>
<span class="ml-3" *ngIf="tableViewDataService.getLoading$() | async">Loading...</span>
Recherche : <input class="form-control ml-2" type="text" name="searchTerm" [(ngModel)]="tableViewData.searchTerm"/>
<span class="ml-3" *ngIf="tableViewData.getLoading$() | async">Loading...</span>
</div>
<a routerLink="edit" class="btn btn-primary" routerLinkActive="active"><i class="fas fa-edit"></i> Editer</a>
......@@ -32,7 +32,7 @@
</thead>
<tbody>
<tr *ngFor="let feature of features$ | async ; index as i">
<td *ngFor="let structure of structures$ | async; index as j" scope="row">
<td *ngFor="let structure of structures$ | async; index as j">
{{feature.properties[structure.column_name]}}
</td>
<td class="table-button-action">
......
......@@ -5,7 +5,7 @@ import { ActivatedRoute } from '@angular/router';
import { SortableHeaderDirective, SortEvent } from 'src/app/directives/sortable-header.directive';
import { Observable } from 'rxjs';
import { DecimalPipe } from '@angular/common';
import { TableViewDataService, State } from 'src/app/services/table-view-data.service';
import { TableViewDataService } from 'src/app/services/table-view-data.service';
import { EnvService } from 'src/app/services/env.service';
import { Structure } from 'src/app/models/structure';
......@@ -28,27 +28,24 @@ export class TableViewComponent implements OnInit {
public features$: Observable<Feature[]>;
public total$: Observable<number>;
public state: State;
/** Pour le tri */
@ViewChildren(SortableHeaderDirective) headers: QueryList<SortableHeaderDirective>;
/** */
constructor(
public tableViewDataService: TableViewDataService,
public tableViewData: TableViewDataService,
) {
this.features$ = this.tableViewDataService.getFeatures$();
this.structures$ = this.tableViewDataService.getStructures$();
this.total$ = this.tableViewDataService.getTotal$();
this.state = this.tableViewDataService.getState();
this.features$ = this.tableViewData.getFeatures$();
this.structures$ = this.tableViewData.getStructures$();
this.total$ = this.tableViewData.getTotal$();
}
/** */
ngOnInit() {
this.tableViewDataService.searchFromUrlParam();
ngOnInit(): void {
this.tableViewData.searchFromUrlParam();
}
onSort({column, direction}: SortEvent) {
onSort({column, direction}: SortEvent): void {
// resetting other headers
this.headers.forEach(header => {
if (header.appSortable !== column) {
......@@ -56,7 +53,7 @@ export class TableViewComponent implements OnInit {
}
});
this.tableViewDataService.setSortColumn(column);
this.tableViewDataService.setSortDirection(direction);
this.tableViewData.sortColumn = column;
this.tableViewData.sortDirection = direction;
}
}
......@@ -20,7 +20,7 @@ export class SortableHeaderDirective {
@Input() direction: SortDirection = '';
@Output() sort = new EventEmitter<SortEvent>();
rotate() {
rotate(): void {
this.direction = rotate[this.direction];
this.sort.emit({column: this.appSortable, direction: this.direction});
}
......
......@@ -9,12 +9,12 @@ import { SortDirection, SortEvent } from 'src/app/directives/sortable-header.dir
import { EnvService } from './env.service';
import { Structure } from '../models/structure';
export interface SearchResult {
interface SearchResult {
features: Feature[];
total: number;
}
export interface State {
interface State {
page: number;
pageSize: number;
searchTerm: string;
......@@ -64,34 +64,34 @@ export class TableViewDataService {
this.search$.next();
}
/** Getter */
getState() {return this.state; }
getStructures$(): Observable<Structure[]> {return this.structures$.asObservable(); }
getEnumerations$(): Observable<{}> {return this.enumerations$.asObservable(); }
getFeatures$(): Observable<Feature[]> { return this.features$.asObservable(); }
getTotal$(): Observable<number> { return this.total$.asObservable(); }
getLoading$(): Observable<boolean> { return this.loading$.asObservable(); }
getStructures$() {return this.structures$.asObservable(); }
getEnumerations$() {return this.enumerations$.asObservable(); }
getFeatures$() { return this.features$.asObservable(); }
getTotal$() { return this.total$.asObservable(); }
getLoading$() { return this.loading$.asObservable(); }
getPage() { return this.state.page; }
getPageSize() { return this.state.pageSize; }
getSearchTerm() { return this.state.searchTerm; }
getEnumerations() { return this.enumerations; }
getStructures() { return this.structures; }
getEnumerations(): {} { return this.enumerations; }
getStructures(): Structure[] { return this.structures; }
/** Setter */
setPage(page: number) { this._set({page}); }
setPageSize(pageSize: number) { this._set({pageSize}); }
setSearchTerm(searchTerm: string) { this._set({searchTerm}); }
setSortColumn(sortColumn: string) { this._set({sortColumn}); }
setSortDirection(sortDirection: SortDirection) { this._set({sortDirection}); }
get page(): number { return this.state.page; }
set page(page: number) { this._set({page}); }
setStructures(structures: Array<Structure>) { this.structures = structures; this.structures$.next(this.structures ); }
setEnumerations(enumerations: {}) {this.enumerations = enumerations; this.enumerations$.next(this.enumerations); }
get pageSize(): number { return this.state.pageSize; }
set pageSize(pageSize: number) { this._set({pageSize}); }
get searchTerm(): string { return this.state.searchTerm; }
set searchTerm(searchTerm: string) { this._set({searchTerm}); }
set sortColumn(sortColumn: string) { this._set({sortColumn}); }
set sortDirection(sortDirection: SortDirection) { this._set({sortDirection}); }
setStructures(structures: Array<Structure>): void { this.structures = structures; this.structures$.next(this.structures ); }
setEnumerations(enumerations: {}): void {this.enumerations = enumerations; this.enumerations$.next(this.enumerations); }
/** Fonctions */
private compare(v1, v2) {
private compare(v1, v2): number {
return v1 < v2 ? -1 : v1 > v2 ? 1 : 0;
}
......@@ -108,7 +108,7 @@ export class TableViewDataService {
}
/** */
private matches(feature: Feature, term: string, pipe: PipeTransform, searchField: string) {
private matches(feature: Feature, term: string, pipe: PipeTransform, searchField: string): boolean {
let retour = false;
const properties = feature.properties;
......@@ -124,12 +124,7 @@ export class TableViewDataService {
}
/** */
public getFeatureByIndex(index: number) {
return this.features[index];
}
/** */
public searchFromUrlParam() {
public searchFromUrlParam(): void {
const locationUrl = new URL(window.location.href);
let searchTerm = locationUrl.searchParams.get(this.envService.fitlerOnAllColumn);
......@@ -148,13 +143,13 @@ export class TableViewDataService {
}
/** */
public initFeatures(features: Array<Feature>) {
public initFeatures(features: Array<Feature>): void {
this.features = features;
this.search$.next();
}
/** */
private _set(patch: Partial<State>) {
private _set(patch: Partial<State>): void {
Object.assign(this.state, patch);
this.search$.next();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment