Skip to content

Commit

Permalink
70-FE/license-page-missing-pagination-sorting (#166)
Browse files Browse the repository at this point in the history
* Fixed pagination and added a new search input field for better overview in the licenses.

* Fixed tests

* Fixed integration tests.

---------

Co-authored-by: MilanMajchrák <milan.majchak@dataquest.sk>
  • Loading branch information
milanmajchrak and MilanMajchrák committed Jun 19, 2024
1 parent e85a2b9 commit 7353b5d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/app/clarin-licenses/clarin-license-table-pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export const paginationID = 'cLicense';
// pageSize: 200; get all licenses
export const defaultPagination = Object.assign(new PaginationComponentOptions(), {
id: paginationID,
currentPage: 0,
pageSize: 200
currentPage: 1,
pageSize: 10
});

export const defaultSortConfiguration = new SortOptions('', SortDirection.DESC);
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<div class="container">
<div class="form-group input-group">
<input type="text"
name="query"
[(ngModel)]="searchingLicenseName"
class="form-control ng-pristine ng-valid ng-touched"
[placeholder]="'clarin-license.button.search.placeholder' | translate"/>
<span class="input-group-append" (click)="loadAllLicenses()">
<button type="submit" class="btn btn-primary search-button">
<i class="fas fa-search"></i>{{'clarin-license.button.search' | translate}}</button>
</span>
</div>
<!-- The table with pagination -->
<div *ngVar="(licensesRD$ | async)?.payload as cLicenses">
<div class="mb-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('ClarinLicenseTableComponent', () => {
findAll: mockLicenseRD$,
create: createdLicenseRD$,
put: createdLicenseRD$,
searchBy: mockLicenseRD$,
getLinkPath: observableOf('')
});
clarinLicenseLabelDataService = jasmine.createSpyObj('clarinLicenseLabelService', {
Expand Down Expand Up @@ -98,7 +99,7 @@ describe('ClarinLicenseTableComponent', () => {

it('should onInit should initialize clarin license table data', () => {
(component as ClarinLicenseTableComponent).ngOnInit();
expect((component as any).clarinLicenseService.findAll).toHaveBeenCalled();
expect((component as any).clarinLicenseService.searchBy).toHaveBeenCalled();
expect((component as ClarinLicenseTableComponent).licensesRD$).not.toBeNull();
});

Expand All @@ -108,7 +109,7 @@ describe('ClarinLicenseTableComponent', () => {
// notificate successful response
expect((component as any).notificationService.success).toHaveBeenCalled();
// load table data
expect((component as any).clarinLicenseService.findAll).toHaveBeenCalled();
expect((component as any).clarinLicenseService.searchBy).toHaveBeenCalled();
expect((component as ClarinLicenseTableComponent).licensesRD$).not.toBeNull();
});

Expand All @@ -127,7 +128,7 @@ describe('ClarinLicenseTableComponent', () => {
// notificate successful response
expect((component as any).notificationService.success).toHaveBeenCalled();
// load table data
expect((component as any).clarinLicenseService.findAll).toHaveBeenCalled();
expect((component as any).clarinLicenseService.searchBy).toHaveBeenCalled();
expect((component as ClarinLicenseTableComponent).licensesRD$).not.toBeNull();
});
}));
Expand All @@ -141,7 +142,7 @@ describe('ClarinLicenseTableComponent', () => {
// notificate successful response
expect((component as any).notificationService.success).toHaveBeenCalled();
// load table data
expect((component as any).clarinLicenseService.findAll).toHaveBeenCalled();
expect((component as any).clarinLicenseService.searchBy).toHaveBeenCalled();
expect((component as ClarinLicenseTableComponent).licensesRD$).not.toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ClarinLicenseLabelDataService } from '../../core/data/clarin/clarin-lic
import { ClarinLicenseLabelExtendedSerializer } from '../../core/shared/clarin/clarin-license-label-extended-serializer';
import { ClarinLicenseRequiredInfoSerializer } from '../../core/shared/clarin/clarin-license-required-info-serializer';
import { cloneDeep } from 'lodash';
import { RequestParam } from '../../core/cache/models/request-param.model';

/**
* Component for managing clarin licenses and defining clarin license labels.
Expand Down Expand Up @@ -61,6 +62,11 @@ export class ClarinLicenseTableComponent implements OnInit {
*/
isLoading = false;

/**
* License name typed into search input field, it is passed to the BE as searching value.
*/
searchingLicenseName = '';

ngOnInit(): void {
this.initializePaginationOptions();
this.loadAllLicenses();
Expand Down Expand Up @@ -311,10 +317,11 @@ export class ClarinLicenseTableComponent implements OnInit {

observableCombineLatest([currentPagination$, currentSort$]).pipe(
switchMap(([currentPagination, currentSort]) => {
return this.clarinLicenseService.findAll({
return this.clarinLicenseService.searchBy('byNameLike',{
currentPage: currentPagination.currentPage,
elementsPerPage: currentPagination.pageSize,
sort: {field: currentSort.field, direction: currentSort.direction}
sort: {field: currentSort.field, direction: currentSort.direction},
searchParams: [Object.assign(new RequestParam('name', this.searchingLicenseName))]
}, false
);
}),
Expand Down
4 changes: 4 additions & 0 deletions src/assets/i18n/en.json5
Original file line number Diff line number Diff line change
Expand Up @@ -3882,6 +3882,10 @@

"clarin-license.button.delete-license": "Delete License",

"clarin-license.button.search": "Search",

"clarin-license.button.search.placeholder": "Search by the license name ...",


"clarin-license.define-license-form.form-name": "Define new license",

Expand Down

0 comments on commit 7353b5d

Please sign in to comment.