Skip to content

Commit

Permalink
Merge pull request #940 from newswangerd/search-pagination-sneakiness
Browse files Browse the repository at this point in the history
Convert page URL parameters to integers on search page.
  • Loading branch information
newswangerd authored Jul 25, 2018
2 parents f0ce8ee + 6bc2db9 commit 52d53e0
Showing 1 changed file with 50 additions and 14 deletions.
64 changes: 50 additions & 14 deletions galaxyui/src/app/search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import { EmptyStateConfig } from 'patternfly-ng/empty-state/empty-state-conf
import { PaginationConfig } from 'patternfly-ng/pagination/pagination-config';
import { PaginationEvent } from 'patternfly-ng/pagination/pagination-event';

import { NotificationService } from 'patternfly-ng/notification/notification-service/notification.service';
import { NotificationType } from 'patternfly-ng/notification/notification-type';

import { ContentTypes } from '../enums/content-types.enum';
import { CloudPlatform } from '../resources/cloud-platforms/cloud-platform';
import { ContentSearchService } from '../resources/content-search/content-search.service';
Expand Down Expand Up @@ -93,7 +96,8 @@ export class SearchComponent implements OnInit, AfterViewInit {
private route: ActivatedRoute,
private router: Router,
private contentSearch: ContentSearchService,
private location: Location
private location: Location,
private notificationService: NotificationService,
) {}

ngOnInit() {
Expand Down Expand Up @@ -199,20 +203,41 @@ export class SearchComponent implements OnInit, AfterViewInit {
this.preparePlatforms(data.platforms);
this.prepareContentTypes(data.contentTypes);
this.prepareCloudPlatforms(data.cloudPlatforms);
if (!data.content.results.length && !Object.keys(params).length) {
// No vendors exists
const default_params = {vendor: false};
this.setSortConfig();
this.setAppliedFilters(default_params);
this.searchContent();

// If there is an error on the search API, the content search services
// returns nothing, so we have to check if results actually exist.
if (data.content.results) {
if (!data.content.results.length && !Object.keys(params).length) {
// No vendors exists
const default_params = {vendor: false};
this.setSortConfig();
this.setAppliedFilters(default_params);
this.searchContent();
} else {
this.setSortConfig(params['order_by']);
this.setPageSize(params);
this.setAppliedFilters(params);
this.prepareContent(data.content.results, data.content.count);
this.setQuery();
this.pageLoading = false;
}
} else {
this.notificationService.message(
NotificationType.WARNING,
'Error',
'Invalid search query',
false,
null,
null,
);

this.setSortConfig(params['order_by']);
this.setPageSize(params);
this.setAppliedFilters(params);
this.prepareContent(data.content.results, data.content.count);
this.setQuery();

this.pageLoading = false;
}

});
});
}
Expand Down Expand Up @@ -348,13 +373,24 @@ export class SearchComponent implements OnInit, AfterViewInit {

private setPageSize(params: any) {
if (params['page_size']) {
this.paginationConfig.pageSize = params['page_size'];
this.pageSize = params['page_size'];
this.pageNumber = 1;
let pageSize = Number(params['page_size']);

if (Number.isNaN(pageSize)) {
pageSize = 10;
}

this.paginationConfig.pageSize = pageSize;
this.pageSize = pageSize;
}
if (params['page']) {
this.paginationConfig.pageNumber = params['page'];
this.pageNumber = params['page'];
let pageNumber = Number(params['page']);

if (Number.isNaN(pageNumber)) {
pageNumber = 1;
}

this.paginationConfig.pageNumber = pageNumber;
this.pageNumber = pageNumber;
}
}

Expand Down

0 comments on commit 52d53e0

Please sign in to comment.