Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend - tab 9 : hierarchy error displays #88

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions frontend/app/services/hierarchy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class HierarchyService {
public items: ItemModel[];
public rb_name: string;
public isLoading: boolean = false;
public warning: string = '';

constructor(
private _dataService: ZhDataService,
Expand All @@ -40,32 +41,31 @@ export class HierarchyService {
// get current zone humides
getHierarchy(zhId, rb_name) {
this.isLoading = true;
this.warning = '';
this.rb_name = rb_name;
this._dataService.getHierZh(zhId).subscribe(
(data: HierarchyModel) => {
this.items = this.setItems(data);
},
(error) => {
this.isLoading = false;
this.items = [];
if (error.status === 404) {
this._toastr.warning("La ZH n'est présente dans aucun bassin versant", '', {
closeButton: true,
});
} else if (error.status === 400) {
this._toastr.warning(
this._error['errors'].filter((i) => error.error['message'] === i.api)[0].front,
'',
{
closeButton: true,
}
);
this._dataService
.getHierZh(zhId, {
'not-to-handle': '1',
})
.subscribe(
(data: HierarchyModel) => {
this.items = this.setItems(data);
},
(error) => {
this.isLoading = false;
this.items = [];
if (error.status === 404) {
this.warning = "La ZH n'est présente dans aucun bassin versant";
} else if (error.status === 400) {
this.warning = this._error['errors'].filter(
(i) => error.error['message'] === i.api
)[0].front;
}
},
() => {
this.isLoading = false;
}
},
() => {
this.isLoading = false;
}
);
);
}

// set list of hierarchy items
Expand Down
10 changes: 5 additions & 5 deletions frontend/app/services/zh-data.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { BehaviorSubject } from 'rxjs';
import { map } from 'rxjs/operators';
import { ConfigService } from '@geonature/services/config.service';
Expand Down Expand Up @@ -115,10 +115,10 @@ export class ZhDataService {
return this._api.get(`${this.config.API_ENDPOINT}/zones_humides/${zhId}/taxa`);
}

getHierZh(zhId: string) {
return this._api.get<HierarchyModel>(
`${this.config.API_ENDPOINT}/zones_humides/${zhId}/hierarchy`
);
getHierZh(zhId: string, headers?: HttpHeaders | { [header: string]: string | string[] }) {
return this._api.get(`${this.config.API_ENDPOINT}/zones_humides/${zhId}/hierarchy`, {
headers,
});
}

getPdf(zhId: number) {
Expand Down
7 changes: 7 additions & 0 deletions frontend/app/zh-details/hierarchy/hierarchy.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<h4 class="tabsSubtitle">Bassin versant : {{ data?.river_basin_name }}</h4>
<div
*ngIf="hierarchy.warning"
class="alert alert-warning mat-alert"
>
{{ hierarchy.warning }}
</div>
<zh-table
*ngIf="hierarchy.items?.length"
[tableCols]="hierarchy.hierTableCols"
[data]="hierarchy.items"
[bold_row_values]="hierarchy.bold_row_values"
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/zh-details/zh-details.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
[title]="'9. Hiérarchisation'"
[expanded]="expanded"
>
<zh-details-hierarchy [data]="zhDetails.hierarchy"></zh-details-hierarchy>
<zh-details-hierarchy [data]="hierarchy"></zh-details-hierarchy>
</collapse>
</mat-accordion>
</div>
Expand Down
20 changes: 19 additions & 1 deletion frontend/app/zh-details/zh-details.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { ZhDataService } from '../services/zh-data.service';
import { ErrorTranslatorService } from '../services/error-translator.service';
import { Rights } from '../models/rights';
import { ToastrService } from 'ngx-toastr';
import { GeoJSON } from 'leaflet';
import { Subscription } from 'rxjs';
import * as L from 'leaflet';

import { DetailsModel } from './models/zh-details.model';
import { HierarchyService } from '../services/hierarchy.service';

@Component({
selector: 'zh-details',
Expand All @@ -24,10 +25,13 @@ export class ZhDetailsComponent implements OnInit, AfterViewInit {
public rights: Rights;
public expanded: boolean = false;
public onError: boolean = false;
private $_currentZhSub: Subscription;
public currentZh: any;

constructor(
private _mapService: MapService,
private _zhService: ZhDataService,
public hierarchy: HierarchyService,
private _route: ActivatedRoute,
private _toastr: ToastrService,
private _error: ErrorTranslatorService
Expand All @@ -37,6 +41,16 @@ export class ZhDetailsComponent implements OnInit, AfterViewInit {
this.id_zh = this._route.snapshot.params['id'];
this.getRights(this.id_zh);
this.getData();
this.getCurrentZh();
}

getCurrentZh() {
this._zhService.getZhById(this.id_zh).subscribe((zh: any) => {
if (zh) {
this.currentZh = zh;
this.hierarchy.getHierarchy(zh.id, zh.properties.bassin_versant);
}
});
}

getRights(idZh: number) {
Expand Down Expand Up @@ -107,4 +121,8 @@ export class ZhDetailsComponent implements OnInit, AfterViewInit {
onWrapAll() {
this.expanded = !this.expanded;
}

ngOnDestroy() {
if (this.$_currentZhSub) this.$_currentZhSub.unsubscribe();
}
}
8 changes: 7 additions & 1 deletion frontend/app/zh-forms/tabs/tab9/zh-form-tab9.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ <h2 class="tabsTitle">Hiérarchisation</h2>

<div *ngIf="!hierarchy.isLoading">
<h4 class="tabsSubtitle">Bassin versant : {{ hierarchy.rb_name }}</h4>

<div
*ngIf="hierarchy.warning"
class="alert alert-warning mat-alert"
>
{{ hierarchy.warning }}
</div>
<zh-table
*ngIf="hierarchy.items?.length"
[tableCols]="hierarchy.hierTableCols"
[data]="hierarchy.items"
[bold_row_values]="hierarchy.bold_row_values"
Expand Down
Loading