Skip to content
Open
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
3 changes: 3 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,8 @@
}
}
}
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. This should be a choice of the dev.

"cli": {
"analytics": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class DatePickerComponent extends FieldType<FormlyFieldConfig<IDateTimePi
this.defaultDate = this.processDate(this.props.defaultDate);
}
if (this.props.disabledDates) {
this.disabledDates = this.props.disabledDates.map((date: any) =>this.processDate(date));
this.disabledDates = this.props.disabledDates.map((date: string | Date) =>this.processDate(date));
}
if (this.props.minDate) {
this.minDate = this.processDate(this.props.minDate);
Expand All @@ -156,7 +156,7 @@ export class DatePickerComponent extends FieldType<FormlyFieldConfig<IDateTimePi
this.maxDate = this.processDate(this.props.maxDate);
}

this.subscription.add(this.value.subscribe((value: any) => {
this.subscription.add(this.value.subscribe((value: string | Date) => {
if (value) {
const convertedDate = this.outputDate(value);
if (convertedDate !== this.formControl.value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { CheckboxChangeEvent, CheckboxModule } from 'primeng/checkbox';
import { map, merge, Observable, Subscription, switchMap } from 'rxjs';
import { TranslateLabelService } from '../services/translate-label.service';

/* eslint-disable @typescript-eslint/no-explicit-any */

export interface IMultiCheckBoxProps extends FormlyFieldProps {
labelStyleClass?: string;
style: 'stacked' | 'inline';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import { FormlyFieldSelectProps, FormlySelectModule } from '@ngx-formly/core/sel
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { MultiSelectModule as PrimeNgMultiSelectModule } from 'primeng/multiselect';
import { map, merge, Observable, Subscription, switchMap, tap } from 'rxjs';
import { TranslateLabelService } from '../services/translate-label.service';
import { CONFIG } from '../../../../../utils/config';
import { TranslateLabelService } from '../services/translate-label.service';

/* eslint-disable @typescript-eslint/no-explicit-any */

export interface IMultiSelectProps extends FormlyFieldProps, FormlyFieldSelectProps {
appendTo?: any;
appendTo?: string;
class?: string;
display: string;
dropdownIcon?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import { inject, Injectable } from "@angular/core";
import { TranslateService } from "@ngx-translate/core";

/* eslint-disable @typescript-eslint/no-explicit-any */

@Injectable({
providedIn: 'root'
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import { TreeNode } from 'primeng/api';
import { TreeNodeSelectEvent } from 'primeng/tree';
import { TreeSelectModule } from 'primeng/treeselect';
import { map, merge, Observable, Subscription, switchMap, tap } from 'rxjs';
import { TranslateLabelService } from '../services/translate-label.service';
import { CONFIG } from '../../../../../utils/config';
import { TranslateLabelService } from '../services/translate-label.service';

/* eslint-disable @typescript-eslint/no-explicit-any */
// Doc https://primeng.org/treeselect

export interface ITreeSelectProps extends FormlyFieldProps {
Expand Down Expand Up @@ -103,7 +104,7 @@ export class TreeSelectComponent extends FieldType<FormlyFieldConfig<ITreeSelect
}
};

nodeSelected: any = undefined;
nodeSelected = undefined;

optionValues$: Observable<any[]>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { TestBed } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { TemplatesService } from './templates.service';
import { of } from 'rxjs';
import { RecordService } from '../../record.service';
import { TemplatesService } from './templates.service';

/* eslint-disable @typescript-eslint/no-explicit-any */
describe('TemplatesService', () => {
let service: TemplatesService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { Component, OnInit } from '@angular/core';
import { FieldArrayType, FormlyFieldConfig } from '@ngx-formly/core';

/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Component for displaying array fields in editor.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { AbstractControl, ValidatorFn } from '@angular/forms';
import { FieldType, FormlyFieldConfig } from '@ngx-formly/core';
import { FormlyFieldProps } from '@ngx-formly/primeng/form-field';

/* eslint-disable @typescript-eslint/no-explicit-any */
interface ExtraTextAreaProps extends FormlyFieldProps {
displayChars: boolean;
displayWords: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { TranslateService } from '@ngx-translate/core';
import { MenuItem } from 'primeng/api';
import { merge, Subscription } from 'rxjs';

/* eslint-disable @typescript-eslint/no-explicit-any */

@Component({
selector: 'ng-core-label-editor',
templateUrl: './label.component.html',
Expand Down
8 changes: 5 additions & 3 deletions projects/rero/ng-core/src/lib/record/record.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
import { getTestBed, TestBed } from '@angular/core/testing';
import { TranslateFakeLoader, TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { ApiService } from '../api/api.service';
import { Error } from '../error/error';
import { Record } from './record';
import { RecordService } from './record.service';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';

/* eslint-disable @typescript-eslint/no-explicit-any */

describe('RecordService', () => {
const url = 'https://localhost:5000/api/documents';
Expand Down Expand Up @@ -65,13 +67,13 @@ describe('RecordService', () => {
const expectedData: Record = {
aggregations: {},
hits: {
total: 2
total: { value: 2, relation: 'eq' }
},
links: {}
};

service.getRecords('documents', '', 1, 10, [{ key: 'author', values: ['John doe'] }]).subscribe((data: Record) => {
expect(service.totalHits(data.hits.total)).toBe(2);
expect(data.hits.total.value).toBe(2);
});

const req = httpMock.expectOne(request => request.method === 'GET' && request.url === url + '/');
Expand Down
40 changes: 8 additions & 32 deletions projects/rero/ng-core/src/lib/record/record.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular
import { inject, Injectable } from '@angular/core';
import { FormlyFieldConfig } from '@ngx-formly/core';
import { TranslateService } from '@ngx-translate/core';
import { Observable, Subject, of } from 'rxjs';
import { Observable, of, Subject } from 'rxjs';
import { catchError, debounceTime, map, tap } from 'rxjs/operators';
import { ApiService } from '../api/api.service';
import { Error } from '../error/error';
import { EsResult, InvenioRecord } from '../types';
import { resolveRefs } from './editor/utils';
import { Record } from './record';
import { RecordHandleErrorService } from './record.handle-error.service';
Expand Down Expand Up @@ -103,7 +104,7 @@ export class RecordService {
headers: any = null,
sort: string = null,
facets: string[] = []
): Observable<Record | Error> {
): Observable<EsResult | Error> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be described in the commit message.

// Build query string
let httpParams = new HttpParams().set('q', query);
httpParams = httpParams.append('page', '' + page);
Expand Down Expand Up @@ -168,10 +169,10 @@ export class RecordService {
type: string,
pid: string,
resolve = 0,
headers: any = {}
): Observable<any | Error> {
headers = {}
): Observable<InvenioRecord> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be described in the commit message.

return this.http
.get<Record>(
.get<InvenioRecord>(
`${this.apiService.getEndpointByType(
type,
true
Expand Down Expand Up @@ -254,7 +255,7 @@ export class RecordService {
query += ` NOT pid:${excludePid}`;
}
return this.getRecords(recordType, query, 1, 1).pipe(
map((res: Record) => this.totalHits(res.hits.total)),
map((res: EsResult) => res.hits.total.value),
map((total) => (total ? { alreadyTaken: value } : null)),
debounceTime(1000)
);
Expand Down Expand Up @@ -304,37 +305,12 @@ export class RecordService {
query += ` NOT pid:${excludePid}`;
}
return this.getRecords(recordType, query, 1, 1).pipe(
map((res: Record) => this.totalHits(res.hits.total)),
map((res: EsResult) => res.hits.total.value),
map((total) => (total ? { alreadyTaken: value } : null)),
debounceTime(500)
);
}

/**
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the ES6 compatibility should be mentioned in the commit message.

* Transform a total value string or object representation
* (ES compatibility v6 and v7)
* @param total - string or object
* @param relation - boolean
* @return integer, text or null
*/
totalHits(total: any, relation = false): any {
switch (typeof total) {
case 'object':
if (relation) {
return `${this.translateService.instant(
total.relation
)} ${total.value.toString()}`;
}
return Number(total.value);
case 'number':
return total;
case 'string':
return Number(total);
default:
return null;
}
}

/**
* Return the suggestions for query and field.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*/
import { Component, OnChanges, OnDestroy, OnInit, SimpleChanges, inject, input } from '@angular/core';
import { Subscription } from 'rxjs';
import { AggregationsFilter, RecordSearchService } from '../../record-search.service';
import { AggregationsFilter } from '../../../../types';
import { RecordSearchService } from '../../record-search.service';

@Component({
selector: 'ng-core-record-search-aggregation-buckets',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ActivatedRoute, convertToParamMap, Router } from '@angular/router';
import { TranslateFakeLoader, TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { ConfirmationService } from 'primeng/api';
import { ButtonModule } from 'primeng/button';
import { Observable, of } from 'rxjs';
import { DialogComponent } from '../../dialog/dialog.component';
import { DefaultPipe } from '../../pipe/default.pipe';
Expand All @@ -34,8 +36,6 @@ import { RecordSearchAggregationComponent } from './aggregation/aggregation.comp
import { RecordSearchComponent } from './record-search.component';
import { RecordSearchService } from './record-search.service';
import { RecordSearchResultComponent } from './result/record-search-result.component';
import { ConfirmationService } from 'primeng/api';
import { ButtonModule } from 'primeng/button';

const adminMode = (): Observable<ActionStatus> => {
return of({
Expand All @@ -48,7 +48,7 @@ const adminMode = (): Observable<ActionStatus> => {
describe('RecordSearchComponent', () => {
let component: RecordSearchComponent;
let fixture: ComponentFixture<RecordSearchComponent>;

const record = { created: '', id: '100', links: {}, metadata: {}, updated: '' };
const routerSpy = jasmine.createSpyObj('Router', ['navigate', 'parseUrl']);
routerSpy.parseUrl.and.returnValue({
root: {
Expand All @@ -74,10 +74,10 @@ describe('RecordSearchComponent', () => {
links: {}
};

const recordServiceSpy = jasmine.createSpyObj('RecordService', ['getRecords', 'delete', 'totalHits']);
const recordServiceSpy = jasmine.createSpyObj('RecordService', ['getRecords', 'delete']);
recordServiceSpy.getRecords.and.returnValue(of(emptyRecords));
recordServiceSpy.delete.and.returnValue(of({}));
recordServiceSpy.totalHits.and.returnValue(10);


const recordUiServiceSpy = jasmine.createSpyObj('RecordUiService', [
'getResourceConfig',
Expand Down Expand Up @@ -244,13 +244,13 @@ describe('RecordSearchComponent', () => {
component['currentType'] = 'documents';
component.detailUrl = '/custom/url/for/detail/:type/:pid';

component.resolveDetailUrl$({ id: 100 }).subscribe((result: any) => {
component.resolveDetailUrl$(record).subscribe((result: any) => {
expect(result.link).toBe('/custom/url/for/detail/documents/100');
});

component.detailUrl = null;

component.resolveDetailUrl$({ id: 100 }).subscribe((result: any) => {
component.resolveDetailUrl$(record).subscribe((result: any) => {
expect(result.link).toBe('detail/100');
});
}));
Expand Down
Loading
Loading