Skip to content

Commit

Permalink
Switched to GET requests for Content Reports
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-François Morin committed Feb 23, 2024
1 parent 0497991 commit e2bf9d2
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class FilteredCollectionsComponent {

submit() {
this
.postFilteredCollections()
.getFilteredCollections()
.subscribe(
response => {
this.results.deserialize(response.payload);
Expand All @@ -49,10 +49,42 @@ export class FilteredCollectionsComponent {
);
}

postFilteredCollections(): Observable<RawRestResponse> {
getFilteredCollections(): Observable<RawRestResponse> {
let params = this.toQueryString();
if (params.length > 0) {
params = "?" + params;

Check failure on line 55 in src/app/admin/admin-reports/filtered-collections/filtered-collections.component.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

Strings must use singlequote

Check failure on line 55 in src/app/admin/admin-reports/filtered-collections/filtered-collections.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Strings must use singlequote
}
let scheme = environment.rest.ssl ? 'https' : 'http';
let urlRestApp = `${scheme}://${environment.rest.host}:${environment.rest.port}${environment.rest.nameSpace}`;
return this.restService.request(RestRequestMethod.GET, `${urlRestApp}/api/contentreport/filteredcollections${params}`);
}

private toQueryString() : string {

Check failure on line 62 in src/app/admin/admin-reports/filtered-collections/filtered-collections.component.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

Unexpected space before the ':'

Check failure on line 62 in src/app/admin/admin-reports/filtered-collections/filtered-collections.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Unexpected space before the ':'
let params = FiltersComponent.toQueryString(this.queryForm.value['filters']);

Check failure on line 63 in src/app/admin/admin-reports/filtered-collections/filtered-collections.component.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

["filters"] is better written in dot notation

Check failure on line 63 in src/app/admin/admin-reports/filtered-collections/filtered-collections.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

["filters"] is better written in dot notation
return params;
}

/*
downloadCsv() {
this
.postDownloadCsv()
.subscribe(
response => {
// TODO: Ne fonctionne pas, le restService de DSpace attend un document JSON.
const csv: any = response.payload;
const blob = new Blob([csv], { type: 'text/csv' });
const url = window.URL.createObjectURL(blob);
window.open(url);
}
);
}
postDownloadCsv(): Observable<RawRestResponse> {
let form = this.queryForm.value;
let scheme = environment.rest.ssl ? 'https' : 'http';
let urlRestApp = `${scheme}://${environment.rest.host}:${environment.rest.port}${environment.rest.nameSpace}`;
return this.restService.request(RestRequestMethod.POST, `${urlRestApp}/api/contentreport/filteredcollections`, form);
return this.restService.request(RestRequestMethod.POST, `${urlRestApp}/api/contentreport/filteredcollections/csv`, form);
}
*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export class FilteredItemsComponent {

resubmit() {
this.results$ = this
.postFilteredItems()
.getFilteredItems()
.pipe(
map(response => {
let offset = this.currentPage * this.pageSize();
Expand All @@ -290,12 +290,46 @@ export class FilteredItemsComponent {
);
}

postFilteredItems(): Observable<RawRestResponse> {
let form = this.queryForm.value;
getFilteredItems(): Observable<RawRestResponse> {
let params = this.toQueryString();
if (params.length > 0) {
params = "?" + params;

Check failure on line 296 in src/app/admin/admin-reports/filtered-items/filtered-items.component.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

Strings must use singlequote

Check failure on line 296 in src/app/admin/admin-reports/filtered-items/filtered-items.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Strings must use singlequote
}
let scheme = environment.rest.ssl ? 'https' : 'http';
let urlRestApp = `${scheme}://${environment.rest.host}:${environment.rest.port}${environment.rest.nameSpace}`;
let urlRequest = `${urlRestApp}/api/contentreport/filtereditems?page=${this.currentPage}&size=${this.pageSize()}`;
return this.restService.request(RestRequestMethod.POST, urlRequest, form);
return this.restService.request(RestRequestMethod.GET, `${urlRestApp}/api/contentreport/filtereditems${params}`);
}

private toQueryString() : string {

Check failure on line 303 in src/app/admin/admin-reports/filtered-items/filtered-items.component.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

Unexpected space before the ':'

Check failure on line 303 in src/app/admin/admin-reports/filtered-items/filtered-items.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

Unexpected space before the ':'
let params = `page=${this.currentPage}&size=${this.pageSize()}`;

let colls = this.queryForm.value['collections'];

Check failure on line 306 in src/app/admin/admin-reports/filtered-items/filtered-items.component.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

["collections"] is better written in dot notation

Check failure on line 306 in src/app/admin/admin-reports/filtered-items/filtered-items.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

["collections"] is better written in dot notation
for (const coll in colls) {

Check failure on line 307 in src/app/admin/admin-reports/filtered-items/filtered-items.component.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype

Check failure on line 307 in src/app/admin/admin-reports/filtered-items/filtered-items.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype
params += `&collections=${colls[coll]}`;
}

let preds = this.queryForm.value['queryPredicates'];

Check failure on line 311 in src/app/admin/admin-reports/filtered-items/filtered-items.component.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

["queryPredicates"] is better written in dot notation

Check failure on line 311 in src/app/admin/admin-reports/filtered-items/filtered-items.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

["queryPredicates"] is better written in dot notation
for (const pred in preds) {

Check failure on line 312 in src/app/admin/admin-reports/filtered-items/filtered-items.component.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype

Check failure on line 312 in src/app/admin/admin-reports/filtered-items/filtered-items.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype
const field = preds[pred].field;
const op = preds[pred].operator;
const value = preds[pred].value;
params += `&queryPredicates=${field}:${op}`;
if (value) {
params += `:${value}`;
}
}

let filters = FiltersComponent.toQueryString(this.queryForm.value['filters']);

Check failure on line 322 in src/app/admin/admin-reports/filtered-items/filtered-items.component.ts

View workflow job for this annotation

GitHub Actions / tests (16.x)

["filters"] is better written in dot notation

Check failure on line 322 in src/app/admin/admin-reports/filtered-items/filtered-items.component.ts

View workflow job for this annotation

GitHub Actions / tests (18.x)

["filters"] is better written in dot notation
if (filters.length > 0) {
params += `&${filters}`;
}

let addFlds = this.queryForm.value['additionalFields'];
for (const fld in addFlds) {
params += `&additionalFields=${addFlds[fld]}`;
}

return params;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,20 @@ export class FiltersComponent {
this.setAllFilters(false);
}

static toQueryString(filters: Object): string {
let params = '';
let first = true;
for (const key in filters) {
if (filters[key]) {
if (first) {
first = false;
} else {
params += '&';
}
params += `filters=${key}`;
}
}
return params;
}

}

0 comments on commit e2bf9d2

Please sign in to comment.