Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RemoteData } from '../../core/data/remote-data';
import { PaginatedList } from '../../core/data/paginated-list.model';
import { ClarinLicense } from '../../core/shared/clarin/clarin-license.model';
import { getFirstCompletedRemoteData, getFirstSucceededRemoteData } from '../../core/shared/operators';
import { switchMap } from 'rxjs/operators';
import { scan, switchMap } from 'rxjs/operators';
import { PaginationService } from '../../core/pagination/pagination.service';
import { ClarinLicenseDataService } from '../../core/data/clarin/clarin-license-data.service';
import { defaultPagination, defaultSortConfiguration } from '../clarin-license-table-pagination';
Expand Down Expand Up @@ -320,21 +320,28 @@ export class ClarinLicenseTableComponent implements OnInit {
*/
loadAllLicenses() {
this.selectedLicense = null;

this.licensesRD$ = new BehaviorSubject<RemoteData<PaginatedList<ClarinLicense>>>(null);
this.isLoading = true;

// load the current pagination and sorting options
const currentPagination$ = this.paginationService.getCurrentPagination(this.options.id, this.options);
const currentSort$ = this.paginationService.getCurrentSort(this.options.id, defaultSortConfiguration);

observableCombineLatest([currentPagination$, currentSort$]).pipe(
switchMap(([currentPagination, currentSort]) => {
return this.clarinLicenseService.searchBy('byNameLike',{
currentPage: currentPagination.currentPage,
const currentPagination$ = this.getCurrentPagination();
const currentSort$ = this.getCurrentSort();
const searchTerm$ = new BehaviorSubject<string>(this.searchingLicenseName);

observableCombineLatest([currentPagination$, currentSort$, searchTerm$]).pipe(
scan((prevState, [currentPagination, currentSort, searchTerm]) => {
// If search term has changed, reset to page 1; otherwise, keep current page
const currentPage = prevState.searchTerm !== searchTerm ? 1 : currentPagination.currentPage;
return { currentPage, currentPagination, currentSort, searchTerm };
}, { searchTerm: '', currentPage: 1, currentPagination: this.getCurrentPagination(),
currentSort: this.getCurrentSort() }),

switchMap(({ currentPage, currentPagination, currentSort, searchTerm }) => {
return this.clarinLicenseService.searchBy('byNameLike', {
currentPage: currentPage, // Properly reset page only when needed
elementsPerPage: currentPagination.pageSize,
sort: {field: currentSort.field, direction: currentSort.direction},
searchParams: [Object.assign(new RequestParam('name', this.searchingLicenseName))]
sort: { field: currentSort.field, direction: currentSort.direction },
searchParams: [new RequestParam('name', searchTerm)]
}, false
);
}),
Expand All @@ -361,7 +368,24 @@ export class ClarinLicenseTableComponent implements OnInit {
}
}

/**
* Initialize the pagination options. Set the default values.
*/
private initializePaginationOptions() {
this.options = defaultPagination;
}

/**
* Get the current pagination options.
*/
private getCurrentPagination() {
return this.paginationService.getCurrentPagination(this.options.id, this.options);
}

/**
* Get the current sorting options.
*/
private getCurrentSort() {
return this.paginationService.getCurrentSort(this.options.id, defaultSortConfiguration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h4 class="modal-title">{{'clarin-license.define-license-form.form-name' | trans
<label id="requiredInfo" for="requiredInfo">{{'clarin-license.define-license-form.required-info' | translate}}</label>
<div *ngFor="let ri of requiredInfoOptions">
<input type="checkbox" formArrayName="requiredInfo" [value]="ri"
[checked]="ri | dsCheckedLicense: requiredInfo"
[checked]="ri | dsCheckedRI: requiredInfo"
(change)="changeCheckboxValue($event,'requiredInfo', ri)"/>
{{ ri.value }}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ export class DefineLicenseFormComponent implements OnInit {
private loadArrayValuesToForm() {
// add passed extendedClarinLicenseLabels to the form because add them to the form in the init is a problem
const extendedClarinLicenseLabels = (this.clarinLicenseForm.controls.extendedClarinLicenseLabels).value as any[];
this.extendedClarinLicenseLabels.forEach(extendedClarinLicenseLabel => {
this.extendedClarinLicenseLabels?.forEach(extendedClarinLicenseLabel => {
extendedClarinLicenseLabels.push(extendedClarinLicenseLabel);
});

// add passed requiredInfo to the form because add them to the form in the init is a problem
const requiredInfoOptions = (this.clarinLicenseForm.controls.requiredInfo).value as any[];
this.requiredInfo.forEach(requiredInfo => {
this.requiredInfo?.forEach(requiredInfo => {
requiredInfoOptions.push(requiredInfo);
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/shared/clarin/clarin-license.resource-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export const CLARIN_LICENSE_FORM_REQUIRED_OPTIONS = [
}),
Object.assign(new ClarinLicenseRequiredInfo(), {
id: 9,
value: CLARIN_LICENSE_REQUIRED_INFO.INTENDED_USE,
name: 'INTENDED_USE'
value: CLARIN_LICENSE_REQUIRED_INFO.ACA_ORG_NAME_AND_SEAT,
name: 'ACA_ORG_NAME_AND_SEAT'
})
];

2 changes: 2 additions & 0 deletions src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ import { ClarinSafeHtmlPipe } from './utils/clarin-safehtml.pipe';
import { ReplacePipe } from './utils/replace.pipe';
import { ClarinDateService } from './clarin-date.service';
import { ItemIdentifierService } from './item-identifier.service';
import { ClarinLicenseRequiredInfoCheckedPipe } from './utils/clarin-license-required-info-checked.pipe';

const MODULES = [
CommonModule,
Expand Down Expand Up @@ -338,6 +339,7 @@ const PIPES = [
ShortNumberPipe,
ClarinExtendedLicensePipe,
ClarinLicenseCheckedPipe,
ClarinLicenseRequiredInfoCheckedPipe,
ClarinLicenseLabelRadioValuePipe,
ClarinLicenseRequiredInfoPipe,
CharToEndPipe,
Expand Down
11 changes: 5 additions & 6 deletions src/app/shared/utils/clarin-license-checked.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@ import { ClarinLicenseRequiredInfo } from '../../core/shared/clarin/clarin-licen

/**
* Pipe to mark checkbox or input to true/false based on the input form data.
* This Pipe is used for editing Clarin Licenses.
* This Pipe is used for editing Clarin License - extended license labels.
*/
@Pipe({
name: 'dsCheckedLicense'
})
export class ClarinLicenseCheckedPipe implements PipeTransform {

/**
* If the clarinLicenseLabels contains clarinLicenseLabel return true otherwise return false
* Compare Ids
* @param clarinLicenseProp to compare
* @param clarinLicenseProps all extended clarin license labels or non extended clarin license label in array
* If the clarin license contains extended clarinLicenseLabel return true otherwise return false
* @param clarinLicenseProp extended license label to compare
* @param clarinLicenseProps all extended or non-extended clarin license labels clarin license label in array
*/
transform(clarinLicenseProp: any | ClarinLicenseRequiredInfo, clarinLicenseProps: any[]): boolean {
let contains = false;
if (isEmpty(clarinLicenseProp) || isEmpty(clarinLicenseProps)) {
return contains;
}
clarinLicenseProps.forEach(cll => {
if (cll.name === clarinLicenseProp.name) {
if (cll.title === clarinLicenseProp.title) {
contains = true;
}
});
Expand Down
31 changes: 31 additions & 0 deletions src/app/shared/utils/clarin-license-required-info-checked.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Pipe, PipeTransform } from '@angular/core';
import { ClarinLicenseRequiredInfo } from '../../core/shared/clarin/clarin-license.resource-type';
import { isEmpty } from '../empty.util';

/**
* Pipe to mark checkbox or input to true/false based on the input form data.
* This Pipe is used for editing Clarin License - required info.
*/
@Pipe({
name: 'dsCheckedRI'
})
export class ClarinLicenseRequiredInfoCheckedPipe implements PipeTransform {

/**
* If the clarinLicense contains the required info return true otherwise return false
* @param clarinLicenseProp required info to compare
* @param clarinLicenseProps all required info which the clarin license contains
*/
transform(clarinLicenseProp: any | ClarinLicenseRequiredInfo, clarinLicenseProps: any[]): boolean {
let contains = false;
if (isEmpty(clarinLicenseProp) || isEmpty(clarinLicenseProps)) {
return contains;
}
clarinLicenseProps.forEach(cll => {
if (cll.name === clarinLicenseProp.name) {
contains = true;
}
});
return contains;
}
}