Skip to content

Commit

Permalink
getDataList: support post requests
Browse files Browse the repository at this point in the history
  • Loading branch information
bouttier authored and jacquesfize committed Mar 8, 2024
1 parent c1f606f commit 6bc950c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
8 changes: 6 additions & 2 deletions frontend/src/app/GN2CommonModule/form/data-form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ export class DataFormService {
return httpParam.append('orderby', order_column);
}

getDataList(api: string, application: string, params = {}) {
getDataList(api: string, application: string, params = {}, data = undefined) {
let queryString: HttpParams = new HttpParams();
for (const key of Object.keys(params)) {
const param = params[key];
Expand All @@ -537,7 +537,11 @@ export class DataFormService {
? `${this.config.API_TAXHUB}/${api}`
: api;

return this._http.get<any>(url, { params: queryString });
if (data !== undefined) {
return this._http.post<any>(url, data, { params: queryString });
} else {
return this._http.get<any>(url, { params: queryString });
}
}

subscribeAndDownload(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export class DatalistComponent extends GenericFormComponent implements OnInit {

@Input() api: string; // api from 'GeoNature', 'TaxHub' or url to foreign app
@Input() application: string; // 'GeoNature', 'TaxHub' for api's; null for raw url
@Input() params: boolean; // parametres get pour la requete { orderby: truc } => api?orderby=truc
@Input() params: any = {}; // parametres get pour la requete { orderby: truc } => api?orderby=truc
@Input() data: any = undefined;

@Input() multiple: boolean;
@Input() required: boolean;
Expand Down Expand Up @@ -151,16 +152,18 @@ export class DatalistComponent extends GenericFormComponent implements OnInit {

getData() {
if (!this.values && this.api) {
this._dfs.getDataList(this.api, this.application, this.params).subscribe((data) => {
let values = data;
if (this.dataPath) {
const paths = this.dataPath.split('/');
for (const path of paths) {
values = values[path];
this._dfs
.getDataList(this.api, this.application, this.params, this.data)
.subscribe((data) => {
let values = data;
if (this.dataPath) {
const paths = this.dataPath.split('/');
for (const path of paths) {
values = values[path];
}
}
}
this.initValues(values);
});
this.initValues(values);
});
} else if (this.values) {
this.initValues(this.values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@
[label]="formDefComp['attribut_label']"
[required]="formDefComp['required']"
[params]="formDefComp['params']"
[data]="formDefComp['data']"
[definition]="formDefComp['definition']"
[filters]="formDefComp['filters']"
[default]="formDefComp['default']"
Expand Down

0 comments on commit 6bc950c

Please sign in to comment.