Improved ESLint configuration, integrated spellcheck and error fixes (#8931)

* integrate cspell with eslint, improved configuration

* core: fix linting errors

* core: fix lint warnings

* content: lint fixes

* process service lint fixes

* lint: process services cloud

* lint: insights

* lint: extensions

* [ci:force] lint: cli fixes

* [ci:force] comment out dead code

* [ci:force] exclude dead code

* fix code and tests

* rollback some changes

* fix testing lib

* fix demo shell

* minor lint warning fixes

* minor lint fixes

* fix process services
This commit is contained in:
Denys Vuika
2023-09-26 13:46:53 +01:00
committed by GitHub
parent 8370a3de66
commit ef551a9c71
134 changed files with 2436 additions and 2269 deletions

View File

@@ -27,10 +27,7 @@ describe('AboutGithubLinkComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
CoreTestingModule
]
imports: [TranslateModule.forRoot(), CoreTestingModule]
});
fixture = TestBed.createComponent(AboutGithubLinkComponent);
component = fixture.componentInstance;
@@ -62,7 +59,7 @@ describe('AboutGithubLinkComponent', () => {
fixture.detectChanges();
await fixture.whenStable();
const githubUrl = fixture.nativeElement.querySelector('[data-automation-id="adf-github-url"]');
expect(githubUrl.innerText).toEqual(aboutGithubDetails.defualrUrl);
expect(githubUrl.innerText).toEqual(aboutGithubDetails.defaultUrl);
});
it('should display the github link', async () => {

View File

@@ -43,7 +43,7 @@ export const mockPlugins = [
export const aboutGithubDetails = {
url: 'https://github.com/componany/repository/commits/',
defualrUrl: 'https://github.com/Alfresco/alfresco-ng2-components/commits/',
defaultUrl: 'https://github.com/Alfresco/alfresco-ng2-components/commits/',
version: '0.0.7',
ecmHost: 'https://mock.ecmhost.com',
bpmHost: 'https://mock.bpmhost.com',
@@ -56,65 +56,65 @@ export const aboutAPSMockDetails = {
type: 'bpmSuite',
majorVersion: '1',
minorVersion: '10'
};
};
export const mockModules: any = {
edition: 'Enterprise',
version: {
major: '6',
minor: '2',
patch: '0',
hotfix: '0',
schema: 13001,
label: 'ra498a911-b5',
display: '6.2.0.0'
},
license: {
issuedAt: '2018-12-20T12:07:31.276+0000',
expiresAt: '2019-05-31T23:00:00.000+0000',
remainingDays: 100,
holder: 'CompanyQA',
mode: 'ENTERPRISE',
entitlements: {
isClusterEnabled: true,
isCryptodocEnabled: true
}
},
status: {
isReadOnly: false,
isAuditEnabled: true,
isQuickShareEnabled: true,
isThumbnailGenerationEnabled: true
},
modules: [
{
id: 'mock-id',
title: 'ABC Repo',
description: 'ABC Repository Extension',
version: '3.2.0',
installState: 'UNKNOWN',
versionMin: '6.1',
versionMax: '999'
},
{
id: 'aos-module-id',
title: 'AOFS Module',
description: 'Allows applications that can talk to a SharePoint server to talk to your Alfresco installation',
version: '1.3.0',
installDate: '2019-02-07T12:26:13.271+0000',
installState: 'INSTALLED',
versionMin: '6.0',
versionMax: '999'
},
{
id: 'mock-saml-repo',
title: 'SAML Repository Module',
description: 'The Repository piece of the Alfresco SAML Module',
version: '1.1.1',
installDate: '2019-02-07T12:26:12.565+0000',
installState: 'INSTALLED',
versionMin: '6.0',
versionMax: '6.99'
}
]
edition: 'Enterprise',
version: {
major: '6',
minor: '2',
patch: '0',
hotfix: '0',
schema: 13001,
label: 'ra498a911-b5',
display: '6.2.0.0'
},
license: {
issuedAt: '2018-12-20T12:07:31.276+0000',
expiresAt: '2019-05-31T23:00:00.000+0000',
remainingDays: 100,
holder: 'CompanyQA',
mode: 'ENTERPRISE',
entitlements: {
isClusterEnabled: true,
isCryptodocEnabled: true
}
},
status: {
isReadOnly: false,
isAuditEnabled: true,
isQuickShareEnabled: true,
isThumbnailGenerationEnabled: true
},
modules: [
{
id: 'mock-id',
title: 'ABC Repo',
description: 'ABC Repository Extension',
version: '3.2.0',
installState: 'UNKNOWN',
versionMin: '6.1',
versionMax: '999'
},
{
id: 'aos-module-id',
title: 'AOFS Module',
description: 'Allows applications that can talk to a SharePoint server to talk to your Alfresco installation',
version: '1.3.0',
installDate: '2019-02-07T12:26:13.271+0000',
installState: 'INSTALLED',
versionMin: '6.0',
versionMax: '999'
},
{
id: 'mock-saml-repo',
title: 'SAML Repository Module',
description: 'The Repository piece of the Alfresco SAML Module',
version: '1.1.1',
installDate: '2019-02-07T12:26:12.565+0000',
installState: 'INSTALLED',
versionMin: '6.0',
versionMax: '6.99'
}
]
};

View File

@@ -185,7 +185,7 @@ export class AppConfigService {
* @returns Notification when loading is complete
*/
load(): Promise<any> {
return new Promise(async (resolve) => {
return new Promise((resolve) => {
const configUrl = `app.config.json?v=${Date.now()}`;
if (this.status === Status.INIT) {
@@ -218,7 +218,7 @@ export class AppConfigService {
* @returns Discovery configuration
*/
loadWellKnown(hostIdp: string): Promise<OpenidConfiguration> {
return new Promise(async (resolve, reject) => {
return new Promise((resolve, reject) => {
this.http
.get<OpenidConfiguration>(`${hostIdp}/.well-known/openid-configuration`)
.subscribe({

View File

@@ -40,7 +40,7 @@ export class AuthBearerInterceptor implements HttpInterceptor {
this.authService = this.injector.get(AuthenticationService);
if (!this.authService || !this.authService.getBearerExcludedUrls()) {
if (!this.authService?.getBearerExcludedUrls()) {
return next.handle(req);
}

View File

@@ -97,10 +97,10 @@ describe('JwtHelperService', () => {
spyOn(jwtHelperService, 'decodeToken').and.returnValue(
{
resource_access: { fakeapp: { roles: ['role1'] } }
resource_access: { fakeApp: { roles: ['role1'] } }
});
const result = jwtHelperService.hasRealmRolesForClientRole('fakeapp', ['role1']);
const result = jwtHelperService.hasRealmRolesForClientRole('fakeApp', ['role1']);
expect(result).toBeTruthy();
});
@@ -109,10 +109,10 @@ describe('JwtHelperService', () => {
spyOn(jwtHelperService, 'decodeToken').and.returnValue(
{
resource_access: { fakeapp: { roles: ['role1'] } }
resource_access: { fakeApp: { roles: ['role1'] } }
});
const result = jwtHelperService.hasRealmRolesForClientRole('fakeapp', ['role1', 'role2']);
const result = jwtHelperService.hasRealmRolesForClientRole('fakeApp', ['role1', 'role2']);
expect(result).toBeTruthy();
});
@@ -120,9 +120,9 @@ describe('JwtHelperService', () => {
spyOn(jwtHelperService, 'getAccessToken').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue(
{
resource_access: { fakeapp: { roles: ['role3'] } }
resource_access: { fakeApp: { roles: ['role3'] } }
});
const result = jwtHelperService.hasRealmRolesForClientRole('fakeapp', ['role1', 'role2']);
const result = jwtHelperService.hasRealmRolesForClientRole('fakeApp', ['role1', 'role2']);
expect(result).toBeFalsy();
});
@@ -130,9 +130,9 @@ describe('JwtHelperService', () => {
spyOn(jwtHelperService, 'getAccessToken').and.returnValue('my-access_token');
spyOn(jwtHelperService, 'decodeToken').and.returnValue(
{
resource_access: { anotherfakeapp: { roles: ['role1'] } }
resource_access: { anotherFakeApp: { roles: ['role1'] } }
});
const result = jwtHelperService.hasRealmRolesForClientRole('fakeapp', ['role1', 'role2']);
const result = jwtHelperService.hasRealmRolesForClientRole('fakeApp', ['role1', 'role2']);
expect(result).toBeFalsy();
});
});

View File

@@ -46,10 +46,7 @@ describe('CardViewArrayItemComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
CoreTestingModule
]
imports: [TranslateModule.forRoot(), CoreTestingModule]
});
fixture = TestBed.createComponent(CardViewArrayItemComponent);
service = TestBed.inject(CardViewUpdateService);
@@ -87,8 +84,8 @@ describe('CardViewArrayItemComponent', () => {
});
it('should NOT call service on chip list container click', () => {
const chiplistContainer: HTMLElement = fixture.nativeElement.querySelector('[data-automation-id="card-arrayitem-chip-list-container"]');
chiplistContainer.dispatchEvent(new Event('click'));
const chipListContainer: HTMLElement = fixture.nativeElement.querySelector('[data-automation-id="card-arrayitem-chip-list-container"]');
chipListContainer.dispatchEvent(new Event('click'));
expect(serviceSpy).not.toHaveBeenCalled();
});
@@ -110,11 +107,11 @@ describe('CardViewArrayItemComponent', () => {
});
fixture.detectChanges();
const chiplistContainer = fixture.debugElement.query(By.css('[data-automation-id="card-arrayitem-chip-list-container"]'));
const chipListContainer = fixture.debugElement.query(By.css('[data-automation-id="card-arrayitem-chip-list-container"]'));
const chip1 = fixture.nativeElement.querySelector('[data-automation-id="card-arrayitem-chip-Zlatan"] span');
const chip2 = fixture.nativeElement.querySelector('[data-automation-id="card-arrayitem-chip-Lionel Messi"] span');
expect(chiplistContainer).not.toBeNull();
expect(chipListContainer).not.toBeNull();
expect(chip1.innerText).toEqual('Zlatan');
expect(chip2.innerText).toEqual('Lionel Messi');
});
@@ -126,13 +123,13 @@ describe('CardViewArrayItemComponent', () => {
});
fixture.detectChanges();
const chiplistContainer = fixture.debugElement.query(By.css('[data-automation-id="card-arrayitem-chip-list-container"]'));
const chipListContainer = fixture.debugElement.query(By.css('[data-automation-id="card-arrayitem-chip-list-container"]'));
const chip1 = fixture.nativeElement.querySelector('[data-automation-id="card-arrayitem-chip-Zlatan"] span');
const chip1Icon = fixture.nativeElement.querySelector('[data-automation-id="card-arrayitem-chip-Zlatan"] mat-icon');
const chip2 = fixture.nativeElement.querySelector('[data-automation-id="card-arrayitem-chip-Lionel Messi"] span');
const chip2Icon = fixture.nativeElement.querySelector('[data-automation-id="card-arrayitem-chip-Lionel Messi"] mat-icon');
expect(chiplistContainer).not.toBeNull();
expect(chipListContainer).not.toBeNull();
expect(chip1.innerText).toEqual('Zlatan');
expect(chip1Icon.innerText).toEqual('person');
expect(chip2.innerText).toEqual('Lionel Messi');
@@ -145,9 +142,9 @@ describe('CardViewArrayItemComponent', () => {
clickable: true
});
fixture.detectChanges();
const editicon = fixture.nativeElement.querySelector('[data-automation-id="card-array-item-clickable-icon-array"]');
expect(editicon).toBeDefined();
expect(editicon.innerText).toBe('edit');
const editIcon = fixture.nativeElement.querySelector('[data-automation-id="card-array-item-clickable-icon-array"]');
expect(editIcon).toBeDefined();
expect(editIcon.innerText).toBe('edit');
});
it('should not render defined icon if clickable set to false', () => {
@@ -156,18 +153,18 @@ describe('CardViewArrayItemComponent', () => {
clickable: false
});
fixture.detectChanges();
const editicon = fixture.nativeElement.querySelector('[data-automation-id="card-array-item-clickable-icon-array"]');
expect(editicon).toBeNull();
const editIcon = fixture.nativeElement.querySelector('[data-automation-id="card-array-item-clickable-icon-array"]');
expect(editIcon).toBeNull();
});
it('should render all values if noOfItemsToDisplay is not defined', () => {
fixture.detectChanges();
const chiplistContainer = fixture.debugElement.query(By.css('[data-automation-id="card-arrayitem-chip-list-container"]'));
const chipListContainer = fixture.debugElement.query(By.css('[data-automation-id="card-arrayitem-chip-list-container"]'));
const moreElement = fixture.debugElement.query(By.css('[data-automation-id="card-arrayitem-more-chip"]'));
const chip = fixture.nativeElement.querySelectorAll('mat-chip');
expect(chiplistContainer).not.toBeNull();
expect(chipListContainer).not.toBeNull();
expect(moreElement).toBeNull();
expect(chip.length).toBe(4);
});
@@ -179,10 +176,10 @@ describe('CardViewArrayItemComponent', () => {
});
fixture.detectChanges();
const chiplistContainer = fixture.debugElement.query(By.css('[data-automation-id="card-arrayitem-chip-list-container"]'));
const chipListContainer = fixture.debugElement.query(By.css('[data-automation-id="card-arrayitem-chip-list-container"]'));
const chip = fixture.debugElement.queryAll(By.css('mat-chip'));
expect(chiplistContainer).not.toBeNull();
expect(chipListContainer).not.toBeNull();
expect(chip.length).toBe(3);
expect(chip[2].nativeElement.innerText).toBe('2 CORE.CARDVIEW.MORE');
});

View File

@@ -41,7 +41,7 @@ describe('CardViewBoolItemComponent', () => {
component.property = new CardViewBoolItemModel({
label: 'Boolean label',
value: true,
key: 'boolkey',
key: 'boolKey',
default: false,
editable: false
});
@@ -207,7 +207,7 @@ describe('CardViewBoolItemComponent', () => {
const disposableUpdate = cardViewUpdateService.itemUpdated$.subscribe(
(updateNotification) => {
expect(updateNotification.target).toEqual(property);
expect(updateNotification.changed).toEqual({ boolkey: true });
expect(updateNotification.changed).toEqual({ boolKey: true });
disposableUpdate.unsubscribe();
done();
}

View File

@@ -118,6 +118,7 @@ export class CardViewItemDispatcherComponent implements OnChanges {
private proxy(methodName, ...args) {
if (this.componentReference.instance[methodName]) {
// eslint-disable-next-line prefer-spread
this.componentReference.instance[methodName].apply(this.componentReference.instance, args);
}
}

View File

@@ -45,7 +45,7 @@ describe('CardViewBaseItemModel', () => {
expect(itemModel.data).toBe(properties.data);
});
it('should persist the params\' properties as own properties', () => {
it('should persist the params properties as own properties', () => {
const allProperties = {
...properties,
default: 'default-value',

View File

@@ -40,6 +40,7 @@ export class HighlightTransformService {
let result = text;
if (search && text) {
// eslint-disable-next-line no-useless-escape
let pattern = search.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
pattern = pattern.split(' ').filter((t) => t.length > 0).join('|');

View File

@@ -24,12 +24,7 @@ interface TestSortableByCategoryItem extends SortableByCategoryItem {
describe('SortByCategoryMapperService', () => {
let mapper: SortByCategoryMapperService<TestSortableByCategoryItem>;
const DEFAULT_CATEGORIES = [
'',
'DefaultCategory1',
'DefaultCategory2',
'DefaultCategory3'
];
const DEFAULT_CATEGORIES = ['', 'DefaultCategory1', 'DefaultCategory2', 'DefaultCategory3'];
beforeEach(() => {
mapper = new SortByCategoryMapperService();
@@ -57,25 +52,29 @@ describe('SortByCategoryMapperService', () => {
});
it('should set all items under default category', () => {
const defaulValues: TestSortableByCategoryItem[] = [{
name: 'name-a',
id: 'id',
category: DEFAULT_CATEGORIES[1]
}, {
name: 'name-b',
id: 'id2',
category: DEFAULT_CATEGORIES[2]
}, {
name: 'name-c',
id: 'id3',
category: DEFAULT_CATEGORIES[0]
}];
const defaultValues: TestSortableByCategoryItem[] = [
{
name: 'name-a',
id: 'id',
category: DEFAULT_CATEGORIES[1]
},
{
name: 'name-b',
id: 'id2',
category: DEFAULT_CATEGORIES[2]
},
{
name: 'name-c',
id: 'id3',
category: DEFAULT_CATEGORIES[0]
}
];
const result = mapper.mapItems(defaulValues, DEFAULT_CATEGORIES);
const result = mapper.mapItems(defaultValues, DEFAULT_CATEGORIES);
expect(result.length).toBe(1);
expect(result[0].category).toBe('');
expect(result[0].items.length).toBe(defaulValues.length);
expect(result[0].items.length).toBe(defaultValues.length);
});
it('should work if no items are present', () => {
@@ -85,7 +84,7 @@ describe('SortByCategoryMapperService', () => {
});
it('should work if the default categories are empty', () => {
const result = mapper.mapItems([{id: 'id', name: 'name', category: ''}], []);
const result = mapper.mapItems([{ id: 'id', name: 'name', category: '' }], []);
expect(result.length).toBe(1);
expect(result[0].category).toBe('');

View File

@@ -21,7 +21,6 @@ import { Injectable } from '@angular/core';
providedIn: 'root'
})
export class StorageService {
private memoryStore: { [key: string]: any } = {};
private readonly useLocalStorage: boolean = false;
private _prefix: string = '';
@@ -48,7 +47,7 @@ export class StorageService {
if (this.useLocalStorage) {
return localStorage.getItem(this.prefix + key);
} else {
return this.memoryStore.hasOwnProperty(this.prefix + key) ? this.memoryStore[this.prefix + key] : null;
return Object.prototype.hasOwnProperty.call(this.memoryStore, this.prefix + key) ? this.memoryStore[this.prefix + key] : null;
}
}
@@ -96,9 +95,9 @@ export class StorageService {
*/
hasItem(key: string): boolean {
if (this.useLocalStorage) {
return localStorage.getItem(this.prefix + key) ? true : false;
return !!localStorage.getItem(this.prefix + key);
} else {
return this.memoryStore.hasOwnProperty(key);
return Object.prototype.hasOwnProperty.call(this.memoryStore, key);
}
}

View File

@@ -41,7 +41,7 @@ export class FileUtils {
files.push({
entry,
file,
relativeFolder: entry.fullPath.replace(/\/[^\/]*$/, '')
relativeFolder: entry.fullPath.replace(/\/[^/]*$/, '')
});
resolveFile();
});

View File

@@ -40,7 +40,7 @@ export class ObjectDataTableAdapter implements DataTableAdapter {
if (typeof rowToExamine === 'object') {
for (const key in rowToExamine) {
if (rowToExamine.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(rowToExamine, key)) {
schema.push({
type: 'text',
key,

View File

@@ -51,26 +51,24 @@ export class ResizableDirective implements OnInit, OnDestroy {
mousemove = new Subject<IResizeMouseEvent>();
private pointerDown: Observable<IResizeMouseEvent>;
private pointerMove: Observable<IResizeMouseEvent>;
private pointerUp: Observable<IResizeMouseEvent>;
private readonly pointerDown: Observable<IResizeMouseEvent>;
private readonly pointerMove: Observable<IResizeMouseEvent>;
private readonly pointerUp: Observable<IResizeMouseEvent>;
private startingRect: BoundingRectangle;
private currentRect: BoundingRectangle;
private unlistenMouseDown?: () => void;
private unlistenMouseMove?: () => void;
private unlistenMouseUp?: () => void;
private unsubscribeMouseDown?: () => void;
private unsubscribeMouseMove?: () => void;
private unsubscribeMouseUp?: () => void;
private destroy$ = new Subject<void>();
constructor(private readonly renderer: Renderer2, private readonly element: ElementRef<HTMLElement>, private readonly zone: NgZone) {
this.pointerDown = new Observable((observer: Observer<IResizeMouseEvent>) => {
zone.runOutsideAngular(() => {
this.unlistenMouseDown = renderer.listen('document', 'mousedown', (event: MouseEvent) => {
this.unsubscribeMouseDown = renderer.listen('document', 'mousedown', (event: MouseEvent) => {
observer.next(event);
});
});
@@ -78,7 +76,7 @@ export class ResizableDirective implements OnInit, OnDestroy {
this.pointerMove = new Observable((observer: Observer<IResizeMouseEvent>) => {
zone.runOutsideAngular(() => {
this.unlistenMouseMove = renderer.listen('document', 'mousemove', (event: MouseEvent) => {
this.unsubscribeMouseMove = renderer.listen('document', 'mousemove', (event: MouseEvent) => {
observer.next(event);
});
});
@@ -86,7 +84,7 @@ export class ResizableDirective implements OnInit, OnDestroy {
this.pointerUp = new Observable((observer: Observer<IResizeMouseEvent>) => {
zone.runOutsideAngular(() => {
this.unlistenMouseUp = renderer.listen('document', 'mouseup', (event: MouseEvent) => {
this.unsubscribeMouseUp = renderer.listen('document', 'mouseup', (event: MouseEvent) => {
observer.next(event);
});
});
@@ -101,7 +99,7 @@ export class ResizableDirective implements OnInit, OnDestroy {
const mouseDrag: Observable<IResizeMouseEvent | ICoordinateX> = mousedown$
.pipe(
mergeMap(({ clientX = 0 }) =>
merge(mousemove$.pipe(take(1)).pipe(map((coords) => [, coords])), mousemove$.pipe(pairwise()))
merge(mousemove$.pipe(take(1)).pipe(map((coords) => [undefined, coords])), mousemove$.pipe(pairwise()))
.pipe(
map(([previousCoords = {}, newCoords = {}]) => [
{ clientX: previousCoords.clientX - clientX },
@@ -170,9 +168,9 @@ export class ResizableDirective implements OnInit, OnDestroy {
this.mousedown.complete();
this.mousemove.complete();
this.mouseup.complete();
this.unlistenMouseDown?.();
this.unlistenMouseMove?.();
this.unlistenMouseUp?.();
this.unsubscribeMouseDown?.();
this.unsubscribeMouseMove?.();
this.unsubscribeMouseUp?.();
this.destroy$.next();
}

View File

@@ -30,7 +30,7 @@ import {
numberMinMaxForm,
textWidgetVisibility,
numberWidgetVisibilityForm,
radioWidgetVisibiltyForm,
radioWidgetVisibilityForm,
customWidgetForm,
formDateVisibility,
customWidgetFormWithVisibility,
@@ -86,7 +86,6 @@ const expectElementToBeValid = (fieldId: string, fixture: ComponentFixture<FormR
};
describe('Form Renderer Component', () => {
let formRendererComponent: FormRendererComponent<any>;
let fixture: ComponentFixture<FormRendererComponent<any>>;
let formService: FormService;
@@ -95,11 +94,7 @@ describe('Form Renderer Component', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
CoreTestingModule,
FormBaseModule
]
imports: [TranslateModule.forRoot(), CoreTestingModule, FormBaseModule]
});
fixture = TestBed.createComponent(FormRendererComponent);
formRendererComponent = fixture.componentInstance;
@@ -287,7 +282,6 @@ describe('Form Renderer Component', () => {
});
describe('Number widget', () => {
it('[C315169] - Should be able to complete a task with a form with number widgets', async () => {
formRendererComponent.formDefinition = formService.parseForm(formNumberWidgetVisibility.formRepresentation.formDefinition);
fixture.detectChanges();
@@ -364,8 +358,8 @@ describe('Form Renderer Component', () => {
await fixture.whenStable();
numberContainerElement = fixture.nativeElement.querySelector('#field-Number2-container');
expectElementToBeHidden(numberContainerElement);
const errorWidetText: HTMLDivElement = fixture.nativeElement.querySelector('#field-Number1-container error-widget .adf-error-text');
expect(errorWidetText.textContent).toBe(`FORM.FIELD.VALIDATOR.NOT_GREATER_THAN`);
const errorWidgetText: HTMLDivElement = fixture.nativeElement.querySelector('#field-Number1-container error-widget .adf-error-text');
expect(errorWidgetText.textContent).toBe(`FORM.FIELD.VALIDATOR.NOT_GREATER_THAN`);
expect(formRendererComponent.formDefinition.isValid).toBe(false, 'Form should not be valid without mandatory field');
});
@@ -397,12 +391,16 @@ describe('Form Renderer Component', () => {
await fixture.whenStable();
const formSizedElement = fixture.nativeElement.querySelector('#field-2bc275fb-e113-4d7d-885f-6e74a7332d40-container div.adf-grid-list');
expectElementToBeVisible(formSizedElement);
const sectionGridElement: HTMLElement[] = fixture.nativeElement.querySelectorAll('#field-2bc275fb-e113-4d7d-885f-6e74a7332d40-container div .adf-grid-list-item');
const sectionGridElement: HTMLElement[] = fixture.nativeElement.querySelectorAll(
'#field-2bc275fb-e113-4d7d-885f-6e74a7332d40-container div .adf-grid-list-item'
);
sectionGridElement.forEach((element) => {
expect(element.style['grid-area']).toBe('auto / auto / span 1 / span 1', 'Elemens is wrong sized for this section');
});
const fullWidthElement = fixture.nativeElement.querySelector('#field-d52ada4e-cbdc-4f0c-a480-5b85fa00e4f8-container div.adf-grid-list .adf-grid-list-item');
const fullWidthElement = fixture.nativeElement.querySelector(
'#field-d52ada4e-cbdc-4f0c-a480-5b85fa00e4f8-container div.adf-grid-list .adf-grid-list-item'
);
expect(fullWidthElement.style['grid-area']).toBe('auto / auto / span 1 / span 2');
});
@@ -410,13 +408,19 @@ describe('Form Renderer Component', () => {
formRendererComponent.formDefinition = formService.parseForm(colspanForm.formRepresentation.formDefinition, null, false, false);
fixture.detectChanges();
await fixture.whenStable();
const formSizedElement = fixture.nativeElement.querySelector('#field-2bc275fb-e113-4d7d-885f-6e74a7332d40-container section.adf-grid-list-column-view');
const formSizedElement = fixture.nativeElement.querySelector(
'#field-2bc275fb-e113-4d7d-885f-6e74a7332d40-container section.adf-grid-list-column-view'
);
expectElementToBeVisible(formSizedElement);
const sectionGridElement: HTMLElement[] = fixture.nativeElement.querySelectorAll('#field-2bc275fb-e113-4d7d-885f-6e74a7332d40-container section .adf-grid-list-single-column');
const sectionGridElement: HTMLElement[] = fixture.nativeElement.querySelectorAll(
'#field-2bc275fb-e113-4d7d-885f-6e74a7332d40-container section .adf-grid-list-single-column'
);
sectionGridElement.forEach((element) => {
expect(element.style['width']).toBe('50%', 'Elemens is wrong sized for this section');
});
const fullWidthElement = fixture.nativeElement.querySelector('#field-d52ada4e-cbdc-4f0c-a480-5b85fa00e4f8-container section.adf-grid-list-column-view .adf-grid-list-single-column');
const fullWidthElement = fixture.nativeElement.querySelector(
'#field-d52ada4e-cbdc-4f0c-a480-5b85fa00e4f8-container section.adf-grid-list-column-view .adf-grid-list-single-column'
);
expect(fullWidthElement.style['width']).toBe('100%');
});
@@ -587,11 +591,9 @@ describe('Form Renderer Component', () => {
expectInputElementValueIs(testTwoInput, 'aaa');
expectElementToBeHidden(numberFieldContainer);
});
});
describe('Text widget', () => {
it('[C309669] - Should be able to set visibility conditions for Text widget', async () => {
formRendererComponent.formDefinition = formService.parseForm(textWidgetVisibility.formRepresentation.formDefinition);
fixture.detectChanges();
@@ -630,13 +632,11 @@ describe('Form Renderer Component', () => {
expectElementToBeVisible(elementFourContainer);
expectElementToBeHidden(elementThreeContainer);
});
});
describe('Radio widget', () => {
it('[C310352] - Should be able to set visibility conditions for Radio Button widget', async () => {
formRendererComponent.formDefinition = formService.parseForm(radioWidgetVisibiltyForm.formRepresentation.formDefinition);
formRendererComponent.formDefinition = formService.parseForm(radioWidgetVisibilityForm.formRepresentation.formDefinition);
fixture.detectChanges();
await fixture.whenStable();
const textInputElement = fixture.nativeElement.querySelector('#Text0cee7g');
@@ -651,11 +651,9 @@ describe('Form Renderer Component', () => {
radioButtonContainer = fixture.nativeElement.querySelector('#field-Radiobuttons03rkbo-container');
expectElementToBeVisible(radioButtonContainer);
});
});
describe('Custom Widget', () => {
it('Should be able to correctly display a custom process cloud widget', async () => {
formRenderingService.register({ bananaforevah: () => TextWidgetComponent }, true);
formRendererComponent.formDefinition = formService.parseForm(customWidgetForm.formRepresentation.formDefinition);
@@ -681,7 +679,6 @@ describe('Form Renderer Component', () => {
customWidgetElementContainer = fixture.nativeElement.querySelector('#field-bananaforevah0k8gui-container');
expectElementToBeVisible(customWidgetElementContainer);
});
});
describe('Form rules', () => {

View File

@@ -84,7 +84,7 @@ export class FormRendererComponent<T> implements OnChanges, OnDestroy {
const maxColumnFieldsSize = this.getMaxColumnFieldSize(content);
for (let rowIndex = 0; rowIndex < maxColumnFieldsSize; rowIndex++) {
content?.columns.flatMap((currentColumn) => {
if (!!currentColumn?.fields[rowIndex]) {
if (currentColumn?.fields[rowIndex]) {
serialisedFormFields.push(currentColumn?.fields[rowIndex]);
} else {
const firstRowElementColSpan = currentColumn?.fields[0]?.colspan;

View File

@@ -38,13 +38,11 @@ import { FormModel } from './form.model';
declare let moment: any;
describe('FormFieldValidator', () => {
describe('RequiredFieldValidator', () => {
let validator: RequiredFieldValidator;
beforeEach(() => {
validator = new RequiredFieldValidator();
validator = new RequiredFieldValidator();
});
it('should require [required] setting', () => {
@@ -71,9 +69,7 @@ describe('FormFieldValidator', () => {
const field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.DROPDOWN,
value: '<empty>',
options: [
{id: 'empty', name: 'Choose option...'}
],
options: [{ id: 'empty', name: 'Choose option...' }],
hasEmptyValue: true,
required: true
});
@@ -241,10 +237,9 @@ describe('FormFieldValidator', () => {
expect(validator.validate(field)).toBeFalsy();
});
});
});
describe('NumberFieldValidator', () => {
let validator: NumberFieldValidator;
beforeEach(() => {
@@ -305,10 +300,9 @@ describe('FormFieldValidator', () => {
expect(validator.validate(field)).toBeFalsy();
expect(field.validationSummary).not.toBeNull();
});
});
});
describe('MinLengthFieldValidator', () => {
let validator: MinLengthFieldValidator;
beforeEach(() => {
@@ -357,10 +351,9 @@ describe('FormFieldValidator', () => {
expect(validator.validate(field)).toBeFalsy();
expect(field.validationSummary).not.toBeNull();
});
});
});
describe('MaxLengthFieldValidator', () => {
let validator: MaxLengthFieldValidator;
beforeEach(() => {
@@ -412,7 +405,6 @@ describe('FormFieldValidator', () => {
});
describe('MinValueFieldValidator', () => {
let validator: MinValueFieldValidator;
beforeEach(() => {
@@ -480,10 +472,9 @@ describe('FormFieldValidator', () => {
expect(validator.validate(field)).toBeFalsy();
expect(field.validationSummary).not.toBeNull();
});
});
});
describe('MaxValueFieldValidator', () => {
let validator: MaxValueFieldValidator;
beforeEach(() => {
@@ -551,10 +542,9 @@ describe('FormFieldValidator', () => {
expect(validator.validate(field)).toBeFalsy();
expect(field.validationSummary).not.toBeNull();
});
});
});
describe('RegExFieldValidator', () => {
let validator: RegExFieldValidator;
beforeEach(() => {
@@ -610,10 +600,9 @@ describe('FormFieldValidator', () => {
expect(validator.validate(field)).toBeFalsy();
});
});
});
describe('FixedValueFieldValidator', () => {
let validator: FixedValueFieldValidator;
beforeEach(() => {
@@ -647,7 +636,10 @@ describe('FormFieldValidator', () => {
const field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.TYPEAHEAD,
value: '1',
options: [{id: '1', name: 'Leanne Graham'}, {id: '2', name: 'Ervin Howell'}]
options: [
{ id: '1', name: 'Leanne Graham' },
{ id: '2', name: 'Ervin Howell' }
]
});
expect(validator.validate(field)).toBeTruthy();
@@ -657,15 +649,17 @@ describe('FormFieldValidator', () => {
const field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.TYPEAHEAD,
value: 'Lean',
options: [{id: '1', name: 'Leanne Graham'}, {id: '2', name: 'Ervin Howell'}]
options: [
{ id: '1', name: 'Leanne Graham' },
{ id: '2', name: 'Ervin Howell' }
]
});
expect(validator.validate(field)).toBeFalsy();
});
});
});
describe('MaxDateTimeFieldValidator', () => {
let validator: MaxDateTimeFieldValidator;
beforeEach(() => {
@@ -788,10 +782,9 @@ describe('FormFieldValidator', () => {
expect(validator.validate(field)).toBeFalsy();
expect(field.validationSummary).not.toBeNull();
});
});
});
describe('MinDateTimeFieldValidator', () => {
let validator: MinDateTimeFieldValidator;
beforeEach(() => {
@@ -914,10 +907,9 @@ describe('FormFieldValidator', () => {
expect(validator.validate(field)).toBeFalsy();
expect(field.validationSummary).not.toBeNull();
});
});
});
describe('MaxDateFieldValidator', () => {
let validator: MaxDateFieldValidator;
beforeEach(() => {
@@ -1007,10 +999,9 @@ describe('FormFieldValidator', () => {
expect(validator.validate(field)).toBeFalsy();
expect(field.validationSummary).not.toBeNull();
});
});
});
describe('MinDateFieldValidator', () => {
let validator: MinDateFieldValidator;
beforeEach(() => {
@@ -1100,10 +1091,9 @@ describe('FormFieldValidator', () => {
expect(validator.validate(field)).toBeFalsy();
expect(field.validationSummary).not.toBeNull();
});
});
});
describe('DateTimeFieldValidator', () => {
let validator: DateTimeFieldValidator;
beforeEach(() => {
@@ -1114,7 +1104,7 @@ describe('FormFieldValidator', () => {
const field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.DATETIME,
value: '2021-06-09 14:10',
dateDisplayFormay: 'YYYY-MM-DD HH:mm'
dateDisplayFormat: 'YYYY-MM-DD HH:mm'
});
expect(validator.validate(field)).toBeTruthy();

View File

@@ -272,11 +272,10 @@ export class FormFieldModel extends FormWidgetModel {
if (json.fields) {
for (const currentField in json.fields) {
if (json.fields.hasOwnProperty(currentField)) {
if (Object.prototype.hasOwnProperty.call(json.fields, currentField)) {
const col = new ContainerColumnModel();
const fields: FormFieldModel[] = (json.fields[currentField] || []).map((field) => new FormFieldModel(form, field));
col.fields = fields;
col.fields = (json.fields[currentField] || []).map((field) => new FormFieldModel(form, field));
col.rowspan = json.fields[currentField].length;
col.fields.forEach((colFields: any) => {
@@ -291,7 +290,7 @@ export class FormFieldModel extends FormWidgetModel {
}
parseValue(json: any): any {
let value = json.hasOwnProperty('value') && json.value !== undefined ? json.value : null;
let value = Object.prototype.hasOwnProperty.call(json, 'value') && json.value !== undefined ? json.value : null;
/*
This is needed due to Activiti issue related to reading dropdown values as value string
@@ -363,7 +362,7 @@ export class FormFieldModel extends FormWidgetModel {
}
switch (this.type) {
case FormFieldTypes.DROPDOWN:
case FormFieldTypes.DROPDOWN: {
if (!this.value) {
this.form.values[this.id] = null;
break;
@@ -390,13 +389,15 @@ export class FormFieldModel extends FormWidgetModel {
}
}
break;
case FormFieldTypes.RADIO_BUTTONS:
}
case FormFieldTypes.RADIO_BUTTONS: {
const radioButton: FormFieldOption[] = this.options.filter((opt) => opt.id === this.value);
if (radioButton.length > 0) {
this.form.values[this.id] = radioButton[0];
}
break;
case FormFieldTypes.UPLOAD:
}
case FormFieldTypes.UPLOAD: {
this.form.hasUpload = true;
if (this.value && this.value.length > 0) {
this.form.values[this.id] = Array.isArray(this.value) ? this.value.map((elem) => elem.id).join(',') : [this.value];
@@ -404,7 +405,8 @@ export class FormFieldModel extends FormWidgetModel {
this.form.values[this.id] = null;
}
break;
case FormFieldTypes.TYPEAHEAD:
}
case FormFieldTypes.TYPEAHEAD: {
const typeAheadEntry: FormFieldOption[] = this.options.filter((opt) => opt.id === this.value || opt.name === this.value);
if (typeAheadEntry.length > 0) {
this.form.values[this.id] = typeAheadEntry[0];
@@ -412,7 +414,8 @@ export class FormFieldModel extends FormWidgetModel {
this.form.values[this.id] = null;
}
break;
case FormFieldTypes.DATE:
}
case FormFieldTypes.DATE: {
if (typeof this.value === 'string' && this.value === 'today') {
this.value = moment(new Date()).format(this.dateDisplayFormat);
}
@@ -425,7 +428,8 @@ export class FormFieldModel extends FormWidgetModel {
this._value = this.value;
}
break;
case FormFieldTypes.DATETIME:
}
case FormFieldTypes.DATETIME: {
if (typeof this.value === 'string' && this.value === 'now') {
this.value = moment(new Date()).utc().format(this.dateDisplayFormat);
}
@@ -439,21 +443,27 @@ export class FormFieldModel extends FormWidgetModel {
this._value = this.value;
}
break;
case FormFieldTypes.NUMBER:
}
case FormFieldTypes.NUMBER: {
this.form.values[this.id] = this.enableFractions ? parseFloat(this.value) : parseInt(this.value, 10);
break;
case FormFieldTypes.AMOUNT:
}
case FormFieldTypes.AMOUNT: {
this.form.values[this.id] = this.enableFractions ? parseFloat(this.value) : parseInt(this.value, 10);
break;
case FormFieldTypes.BOOLEAN:
}
case FormFieldTypes.BOOLEAN: {
this.form.values[this.id] = this.value !== null && this.value !== undefined ? this.value : false;
break;
case FormFieldTypes.PEOPLE:
}
case FormFieldTypes.PEOPLE: {
this.form.values[this.id] = this.value ? this.value : null;
break;
case FormFieldTypes.FUNCTIONAL_GROUP:
}
case FormFieldTypes.FUNCTIONAL_GROUP: {
this.form.values[this.id] = this.value ? this.value : null;
break;
}
default:
if (!FormFieldTypes.isReadOnlyType(this.type) && !this.isInvalidFieldType(this.type)) {
this.form.values[this.id] = this.value;

View File

@@ -265,7 +265,7 @@ export class FormModel implements ProcessFormModel {
getDefaultFormVariableValue(identifier: string): any {
const variable = this.getFormVariable(identifier);
if (variable?.hasOwnProperty('value')) {
if (variable && Object.prototype.hasOwnProperty.call(variable, 'value')) {
return this.parseValue(variable.type, variable.value);
}
@@ -420,7 +420,7 @@ export class FormModel implements ProcessFormModel {
const visibilityRule: WidgetVisibilityModel = new WidgetVisibilityModel();
const field = this.getFieldById(fieldId);
if (!!field) {
if (field) {
visibilityRule.operator = visibility ? 'empty' : '!empty';
visibilityRule.leftType = WidgetTypeEnum.field;
field.visibilityCondition = visibilityRule;
@@ -430,28 +430,28 @@ export class FormModel implements ProcessFormModel {
changeFieldDisabled(fieldId: string, disabled: boolean): void {
const field = this.getFieldById(fieldId);
if (!!field) {
if (field) {
field.readOnly = this.readOnly || disabled;
}
}
changeFieldRequired(fieldId: string, required: boolean): void {
const field = this.getFieldById(fieldId);
if (!!field) {
if (field) {
field.required = required;
}
}
changeFieldValue(fieldId: string, value: any): void {
const field = this.getFieldById(fieldId);
if (!!field) {
if (field) {
field.value = value;
}
}
changeVariableValue(variableId: string, value: any): void {
const variable = this.getFormVariable(variableId);
if (!!variable) {
if (variable) {
variable.value = value;
}
}

View File

@@ -33,7 +33,7 @@ export function formRulesManagerFactory<T>(injector: Injector): FormRulesManager
}
export abstract class FormRulesManager<T> {
constructor(private formService: FormService) { }
constructor(private formService: FormService) {}
protected formModel: FormModel;
private onDestroy$ = new Subject<boolean>();
@@ -50,12 +50,13 @@ export abstract class FormRulesManager<T> {
if (!this.formModel.readOnly) {
const rules = this.getRules();
if (!!rules) {
if (rules) {
this.formService.formRulesEvent
.pipe(
filter(event => !!event?.form?.id && event.form.id === formModel?.id),
filter((event) => !!event?.form?.id && event.form.id === formModel?.id),
takeUntil(this.onDestroy$)
).subscribe(event => {
)
.subscribe((event) => {
this.handleRuleEvent(event, rules);
});
@@ -76,7 +77,6 @@ export abstract class FormRulesManager<T> {
}
export class ByPassFormRuleManager<T> extends FormRulesManager<T> {
protected getRules(): T {
return null;
}

View File

@@ -43,7 +43,7 @@ export class WidgetVisibilityModel {
return WidgetTypeEnum.field;
} else if (this.leftRestResponseId) {
return WidgetTypeEnum.variable;
} else if (!!this.json.leftType) {
} else if (this.json.leftType) {
return this.json.leftType;
}
return null;
@@ -68,7 +68,7 @@ export class WidgetVisibilityModel {
}
get rightType(): string {
if (!!this.json.rightType) {
if (this.json.rightType) {
return this.json.rightType;
} else if (this.json.rightValue) {
return WidgetTypeEnum.value;

View File

@@ -68,7 +68,7 @@ export class WidgetVisibilityService {
}
}
public isFieldVisible(form: FormModel, visibilityObj: WidgetVisibilityModel, accumulator: any[] = [], result: boolean = false): boolean {
public isFieldVisible(form: FormModel, visibilityObj: WidgetVisibilityModel, accumulator: any[] = [], result?: boolean): boolean {
const leftValue = this.getLeftValue(form, visibilityObj);
const rightValue = this.getRightValue(form, visibilityObj);
const actualResult = this.evaluateCondition(leftValue, rightValue, visibilityObj.operator);
@@ -88,7 +88,7 @@ export class WidgetVisibilityService {
}
private transformToLiteralExpression(currentExpression: any): string {
const currentTransformedValue = !!currentExpression.value ? 'true' : 'false';
const currentTransformedValue = currentExpression.value ? 'true' : 'false';
return currentTransformedValue.concat(this.transformToLiteralOperator(currentExpression.operator));
}
@@ -206,9 +206,9 @@ export class WidgetVisibilityService {
const containers = this.getFormTabContainers(form);
let isVisible: boolean = true;
containers.map((container: ContainerModel) => {
if (!!this.getCurrentFieldFromTabById(container, currentFormField.id)) {
if (this.getCurrentFieldFromTabById(container, currentFormField.id)) {
const currentTab = form.tabs.find((tab: TabModel) => tab.id === container.tab);
if (!!currentTab) {
if (currentTab) {
isVisible = currentTab.isVisible;
}
}
@@ -230,7 +230,7 @@ export class WidgetVisibilityService {
}
private getFormTabContainers(form: FormModel): ContainerModel[] {
if (!!form) {
if (form) {
return form.fields.filter((field) => field.type === 'container' && field.tab) as ContainerModel[];
}
return [];

View File

@@ -15,6 +15,8 @@
* limitations under the License.
*/
/* eslint-disable @cspell/spellchecker */
export const mockTabText = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam urna odio, sagittis vel nulla vel, condimentum egestas dolor.
Interdum et malesuada fames ac ante ipsum primis in faucibus. Mauris eu hendrerit lectus. Aliquam et ex imperdiet, sodales tellus finibus, malesuada eros.
Vestibulum aliquet eros sed diam euismod tincidunt.

View File

@@ -38,7 +38,7 @@ export class CookieServiceMock extends CookieService {
/** @override */
clear() {
Object.keys(this).forEach((key) => {
if (this.hasOwnProperty(key) && typeof this[key] !== 'function') {
if (Object.prototype.hasOwnProperty.call(this, key) && typeof this[key] !== 'function') {
this[key] = undefined;
}
});

View File

@@ -16,7 +16,6 @@
*/
export class DemoForm {
easyForm: any = {
formRepresentation: {
id: 1001,
@@ -1859,10 +1858,10 @@ export class DemoForm {
id: 'my1r7YmMOs',
type: 'paragraph',
data: {
text: `<font color="#000000">Is simply a redonly</font><mark class="cdx-marker">
text: `<font color="#000000">Is simply a readonly</font><mark class="cdx-marker">
<font color="#000000">dummy </font><b>text</b></mark><b></b><font color="#000000">
of the </font><i>printing and typesetting</i><font color="#000000"> industry.\n
</font><b><i>Lorem</i></b><font color="#000000"> Ipsum has been the industry\'s standard du</font><b>
</font><b><i>Lorem</i></b><font color="#000000"> Ipsum has been the industry's standard du</font><b>
<i>mmy text ever since the 1500s,\n when an unknown printer took a galley of type
and scrambled it to make a type specime</i></b><font color="#000000">n book. </font><font color="#ff1300">
It has survived not only five centuries</font><font color="#000000">,\n
@@ -1880,10 +1879,7 @@ export class DemoForm {
type: 'list',
data: {
style: 'unordered',
items: [
'Unordered list example',
'Unordered list example'
]
items: ['Unordered list example', 'Unordered list example']
}
},
{
@@ -1954,5 +1950,4 @@ export class DemoForm {
getFormCloudDefinition(): any {
return this.cloudFormDefinition;
}
}

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
export const formDefVisibilitiFieldDependsOnNextOne: any = {
export const formDefVisibilityFieldDependsOnNextOne: any = {
id: 19,
processDefinitionId: 'visibility:1:148',
processDefinitionName: 'visibility',

View File

@@ -173,13 +173,12 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
const urlFile = changes['urlFile'];
if (urlFile?.currentValue) {
const pdfOptions = {
const pdfOptions: any = {
...this.pdfjsDefaultOptions,
url: urlFile.currentValue,
withCredentials: this.appConfigService.get<boolean>('auth.withCredentials', undefined)
};
if (this.cacheType) {
// @ts-ignore
pdfOptions.httpHeaders = {
'Cache-Control': this.cacheType
};

View File

@@ -24,7 +24,6 @@ import { Injectable } from '@angular/core';
*/
@Injectable()
export class RenderingQueueServices {
renderingStates = {
INITIAL: 0,
RUNNING: 1,
@@ -149,22 +148,27 @@ export class RenderingQueueServices {
renderView(view: any) {
const state = view.renderingState;
switch (state) {
case this.renderingStates.FINISHED:
case this.renderingStates.FINISHED: {
return false;
case this.renderingStates.PAUSED:
}
case this.renderingStates.PAUSED: {
this.highestPriorityPage = view.renderingId;
view.resume();
break;
case this.renderingStates.RUNNING:
}
case this.renderingStates.RUNNING: {
this.highestPriorityPage = view.renderingId;
break;
case this.renderingStates.INITIAL:
}
case this.renderingStates.INITIAL: {
this.highestPriorityPage = view.renderingId;
const continueRendering = function() {
// eslint-disable-next-line space-before-function-paren
const continueRendering = function () {
this.renderHighestPriority();
}.bind(this);
view.draw().then(continueRendering, continueRendering);
break;
}
default:
break;
}

View File

@@ -22,7 +22,6 @@ import { AppExtensionService, ViewerExtensionRef } from '@alfresco/adf-extension
providedIn: 'root'
})
export class ViewUtilService {
// Extensions that are supported by the Viewer without conversion
private extensions = {
image: ['png', 'jpg', 'jpeg', 'gif', 'bpm', 'svg'],
@@ -50,11 +49,10 @@ export class ViewUtilService {
* Provides a list of file extensions supported by external plugins.
*/
get externalExtensions(): string[] {
return this.viewerExtensions.map(ext => ext.fileExtension);
return this.viewerExtensions.map((ext) => ext.fileExtension);
}
constructor(private extensionService: AppExtensionService) {
}
constructor(private extensionService: AppExtensionService) {}
/**
* get File name from url
@@ -64,9 +62,7 @@ export class ViewUtilService {
getFilenameFromUrl(url: string): string {
const anchor = url.indexOf('#');
const query = url.indexOf('?');
const end = Math.min(
anchor > 0 ? anchor : url.length,
query > 0 ? query : url.length);
const end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length);
return url.substring(url.lastIndexOf('/', end) + 1, end);
}
@@ -80,13 +76,13 @@ export class ViewUtilService {
*/
getFileExtension(fileName: string): string {
if (fileName) {
const match = fileName.match(/\.([^\./\?\#]+)($|\?|\#)/);
const match = fileName.match(/\.([^./?#]+)($|\?|#)/);
return match ? match[1] : null;
}
return null;
}
getViewerType(extension: string, mimeType: string): string {
getViewerType(extension: string, mimeType: string): string {
let viewerType = this.getViewerTypeByExtension(extension);
if (viewerType === 'unknown') {
@@ -143,7 +139,7 @@ export class ViewUtilService {
}
private isExternalViewer(): boolean {
return !!this.viewerExtensions.find(ext => ext.fileExtension === '*');
return !!this.viewerExtensions.find((ext) => ext.fileExtension === '*');
}
isCustomViewerExtension(extension: string): boolean {
@@ -156,5 +152,4 @@ export class ViewUtilService {
return false;
}
}