[ACS-5991] ESLint fixes and code quality improvements (#8893)

* prefer-optional-chain: core

* prefer-optional-chain: content, fix typings

* prefer-optional-chain: process, fix typings

* prefer-optional-chain: process-cloud, fix typings, fix ts configs and eslint

* [ci: force] sonar errors fixes, insights lib

* [ci:force] fix security issues

* [ci:force] fix metadata e2e bug, js assignment bugs

* [ci:force] fix lint issue

* [ci:force] fix tests
This commit is contained in:
Denys Vuika 2023-09-18 09:42:16 +01:00 committed by GitHub
parent 99f591ed67
commit a1dd270c5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
203 changed files with 4155 additions and 4960 deletions

View File

@ -1,193 +1,170 @@
path = require('path');
module.exports = {
root: true,
ignorePatterns: [
'projects/**/*',
'**/node_modules/**/*',
'lib/cli/node_modules/**/*',
'**/node_modules',
'**/docker',
'**/assets',
'**/scripts',
'**/docs'
],
overrides: [
{
files: [
'*.ts'
],
parserOptions: {
project: [
path.join(__dirname, 'tsconfig.json'),
path.join(__dirname, 'e2e/tsconfig.e2e.json')
],
createDefaultProgram: true
},
extends: [
'plugin:@angular-eslint/ng-cli-compat',
'plugin:@angular-eslint/ng-cli-compat--formatting-add-on',
'plugin:@angular-eslint/template/process-inline-templates'
],
plugins: [
'eslint-plugin-unicorn',
'eslint-plugin-rxjs',
'ban',
'license-header'
],
rules: {
'ban/ban': [
'error',
{ name: 'eval', message: 'Calls to eval is not allowed.' },
{ name: 'fdescribe', message: 'Calls to fdescribe is not allowed' },
{ name: 'fit', message: 'Calls to fit is not allowed' },
{ name: 'xit', message: 'Calls to xit is not allowed' },
{ name: 'xdescribe', message: 'Calls to xdescribe is not allowed' },
{ name: ['test', 'only'], message: 'Calls to test.only is not allowed' },
{ name: ['describe', 'only'], message: 'Calls to describe.only is not allowed' }
],
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: [
'adf',
'app'
root: true,
ignorePatterns: [
'projects/**/*',
'**/node_modules/**/*',
'lib/cli/node_modules/**/*',
'**/node_modules',
'**/docker',
'**/assets',
'**/scripts',
'**/docs'
],
overrides: [
{
files: ['*.ts'],
parserOptions: {
project: [path.join(__dirname, 'tsconfig.json'), path.join(__dirname, 'e2e/tsconfig.e2e.json')],
createDefaultProgram: true
},
extends: [
'plugin:@angular-eslint/ng-cli-compat',
'plugin:@angular-eslint/ng-cli-compat--formatting-add-on',
'plugin:@angular-eslint/template/process-inline-templates'
],
style: 'kebab-case'
}
],
'@angular-eslint/directive-selector': [
'error',
{
type: [
'element',
'attribute'
],
prefix: [
'adf',
'app'
],
style: 'kebab-case'
}
],
'@angular-eslint/no-host-metadata-property': 'off',
'@angular-eslint/no-input-prefix': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/dot-notation': 'off',
'@typescript-eslint/explicit-member-accessibility': [
'off',
{
accessibility: 'explicit'
}
],
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/naming-convention': [
'error',
{
selector: [
'classProperty',
'objectLiteralProperty',
'typeProperty',
'classMethod',
'objectLiteralMethod',
'typeMethod',
'accessor',
'enumMember'
],
format: null,
modifiers: ['requiresQuotes']
}
],
'@typescript-eslint/member-ordering': 'off',
'prefer-arrow/prefer-arrow-functions': 'off',
plugins: ['eslint-plugin-unicorn', 'eslint-plugin-rxjs', 'ban', 'license-header'],
rules: {
'ban/ban': [
'error',
{ name: 'eval', message: 'Calls to eval is not allowed.' },
{ name: 'fdescribe', message: 'Calls to fdescribe is not allowed' },
{ name: 'fit', message: 'Calls to fit is not allowed' },
{ name: 'xit', message: 'Calls to xit is not allowed' },
{ name: 'xdescribe', message: 'Calls to xdescribe is not allowed' },
{ name: ['test', 'only'], message: 'Calls to test.only is not allowed' },
{ name: ['describe', 'only'], message: 'Calls to describe.only is not allowed' }
],
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: ['adf', 'app'],
style: 'kebab-case'
}
],
'@angular-eslint/directive-selector': [
'error',
{
type: ['element', 'attribute'],
prefix: ['adf', 'app'],
style: 'kebab-case'
}
],
'@angular-eslint/no-host-metadata-property': 'off',
'@angular-eslint/no-input-prefix': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/dot-notation': 'off',
'@typescript-eslint/explicit-member-accessibility': [
'off',
{
accessibility: 'explicit'
}
],
'@typescript-eslint/prefer-optional-chain': 'warn',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/naming-convention': [
'error',
{
selector: [
'classProperty',
'objectLiteralProperty',
'typeProperty',
'classMethod',
'objectLiteralMethod',
'typeMethod',
'accessor',
'enumMember'
],
format: null,
modifiers: ['requiresQuotes']
}
],
'@typescript-eslint/member-ordering': 'off',
'prefer-arrow/prefer-arrow-functions': 'off',
'brace-style': [
'error',
'1tbs'
],
'comma-dangle': 'error',
'default-case': 'error',
'import/order': 'off',
'max-len': [
'error',
{
code: 240
}
],
'no-bitwise': 'off',
'no-console': [
'error',
{
allow: [
'warn',
'dir',
'timeLog',
'assert',
'clear',
'count',
'countReset',
'group',
'groupEnd',
'table',
'dirxml',
'error',
'groupCollapsed',
'Console',
'profile',
'profileEnd',
'timeStamp',
'context'
]
}
],
'no-duplicate-imports': 'error',
'no-multiple-empty-lines': 'error',
'no-redeclare': 'error',
'no-return-await': 'error',
'rxjs/no-create': 'error',
'rxjs/no-subject-unsubscribe': 'error',
'rxjs/no-subject-value': 'error',
'rxjs/no-unsafe-takeuntil': 'error',
'unicorn/filename-case': 'error',
'@typescript-eslint/no-unused-expressions': [
'error',
{
allowShortCircuit: true,
allowTernary: true
}
],
'license-header/header': ['error',
[
'/*!',
' * @license',
' * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.',
' *',
' * Licensed under the Apache License, Version 2.0 (the \"License\");',
' * you may not use this file except in compliance with the License.',
' * You may obtain a copy of the License at',
' *',
' * http://www.apache.org/licenses/LICENSE-2.0',
' *',
' * Unless required by applicable law or agreed to in writing, software',
' * distributed under the License is distributed on an \"AS IS\" BASIS,',
' * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.',
' * See the License for the specific language governing permissions and',
' * limitations under the License.',
' */'
]
]
}
},
{
files: [
'*.html'
],
extends: [
'plugin:@angular-eslint/template/recommended'
],
rules: {}
}
]
}
'brace-style': 'off',
'@typescript-eslint/brace-style': 'error',
'comma-dangle': 'error',
'default-case': 'error',
'import/order': 'off',
'max-len': [
'error',
{
code: 240
}
],
'no-bitwise': 'off',
'no-console': [
'error',
{
allow: [
'warn',
'dir',
'timeLog',
'assert',
'clear',
'count',
'countReset',
'group',
'groupEnd',
'table',
'dirxml',
'error',
'groupCollapsed',
'Console',
'profile',
'profileEnd',
'timeStamp',
'context'
]
}
],
'no-duplicate-imports': 'error',
'no-multiple-empty-lines': 'error',
'no-redeclare': 'error',
'no-return-await': 'error',
'rxjs/no-create': 'error',
'rxjs/no-subject-unsubscribe': 'error',
'rxjs/no-subject-value': 'error',
'rxjs/no-unsafe-takeuntil': 'error',
'unicorn/filename-case': 'error',
'@typescript-eslint/no-unused-expressions': [
'error',
{
allowShortCircuit: true,
allowTernary: true
}
],
'license-header/header': [
'error',
[
'/*!',
' * @license',
' * Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.',
' *',
' * Licensed under the Apache License, Version 2.0 (the "License");',
' * you may not use this file except in compliance with the License.',
' * You may obtain a copy of the License at',
' *',
' * http://www.apache.org/licenses/LICENSE-2.0',
' *',
' * Unless required by applicable law or agreed to in writing, software',
' * distributed under the License is distributed on an "AS IS" BASIS,',
' * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.',
' * See the License for the specific language governing permissions and',
' * limitations under the License.',
' */'
]
]
}
},
{
files: ['*.html'],
extends: ['plugin:@angular-eslint/template/recommended'],
rules: {}
}
]
};

View File

@ -1,95 +1,73 @@
path = require('path');
module.exports = {
extends: '../.eslintrc.js',
ignorePatterns: [
'!**/*'
],
overrides: [
{
files: [
'*.ts'
],
parserOptions: {
project: [
path.join(__dirname, 'tsconfig.app.json'),
path.join(__dirname, 'src/tsconfig.spec.json'),
path.join(__dirname, 'e2e/tsconfig.e2e.json')
],
createDefaultProgram: true
},
plugins: [
'eslint-plugin-unicorn',
'eslint-plugin-rxjs'
],
rules: {
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: [
'adf',
'app'
],
style: 'kebab-case'
}
],
'@angular-eslint/directive-selector': [
'error',
{
type: [
'element',
'attribute'
],
prefix: [
'adf',
'app'
],
style: 'kebab-case'
}
],
'@angular-eslint/no-host-metadata-property': 'off',
'@angular-eslint/no-input-prefix': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/dot-notation': 'off',
'@typescript-eslint/explicit-member-accessibility': [
'off',
{
accessibility: 'explicit'
}
],
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-var-requires': 'error',
'brace-style': [
'error',
'1tbs'
],
'comma-dangle': 'error',
'default-case': 'error',
'import/order': 'off',
'max-len': [
'error',
{
code: 240
}
],
'no-bitwise': 'off',
'no-duplicate-imports': 'error',
'no-multiple-empty-lines': 'error',
'no-redeclare': 'error',
'no-return-await': 'error',
'rxjs/no-create': 'error',
'rxjs/no-subject-unsubscribe': 'error',
'rxjs/no-subject-value': 'error',
'rxjs/no-unsafe-takeuntil': 'error',
'unicorn/filename-case': 'error'
}
},
{
files: [
'*.html'
],
rules: {}
}
]
}
extends: '../.eslintrc.js',
ignorePatterns: ['!**/*'],
overrides: [
{
files: ['*.ts'],
parserOptions: {
project: [
path.join(__dirname, 'tsconfig.app.json'),
path.join(__dirname, 'src/tsconfig.spec.json'),
path.join(__dirname, 'e2e/tsconfig.e2e.json')
],
createDefaultProgram: true
},
plugins: ['eslint-plugin-unicorn', 'eslint-plugin-rxjs'],
rules: {
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: ['adf', 'app'],
style: 'kebab-case'
}
],
'@angular-eslint/directive-selector': [
'error',
{
type: ['element', 'attribute'],
prefix: ['adf', 'app'],
style: 'kebab-case'
}
],
'@angular-eslint/no-host-metadata-property': 'off',
'@angular-eslint/no-input-prefix': 'error',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/dot-notation': 'off',
'@typescript-eslint/explicit-member-accessibility': [
'off',
{
accessibility: 'explicit'
}
],
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-var-requires': 'error',
'comma-dangle': 'error',
'default-case': 'error',
'import/order': 'off',
'max-len': [
'error',
{
code: 240
}
],
'no-bitwise': 'off',
'no-duplicate-imports': 'error',
'no-multiple-empty-lines': 'error',
'no-redeclare': 'error',
'no-return-await': 'error',
'rxjs/no-create': 'error',
'rxjs/no-subject-unsubscribe': 'error',
'rxjs/no-subject-value': 'error',
'rxjs/no-unsafe-takeuntil': 'error',
'unicorn/filename-case': 'error'
}
},
{
files: ['*.html'],
rules: {}
}
]
};

View File

@ -15,7 +15,6 @@
* limitations under the License.
*/
/* eslint-disable brace-style */
import { test as base } from '@playwright/test';
import { BaseStories } from '../../page-object';
import { ComponentTitles } from '../../models/component-titles.model';
@ -29,9 +28,15 @@ interface Pages {
}
export const test = base.extend<Pages>({
processServicesCloud: async ({ page }, use) => { await use(new BaseStories(page, ComponentTitles.processServicesCloud)); },
peopleComponent: async ({ page }, use) => { await use(new PeopleComponent(page)); },
groupComponent: async ({ page }, use) => { await use(new GroupComponent(page)); }
processServicesCloud: async ({ page }, use) => {
await use(new BaseStories(page, ComponentTitles.processServicesCloud));
},
peopleComponent: async ({ page }, use) => {
await use(new PeopleComponent(page));
},
groupComponent: async ({ page }, use) => {
await use(new GroupComponent(page));
}
});
export { expect } from '@playwright/test';

View File

@ -19,7 +19,6 @@ import { $, by, element, Key, protractor, ElementFinder } from 'protractor';
import { BrowserActions, BrowserVisibility, DropdownPage, TestElement, Logger } from '@alfresco/adf-testing';
export class MetadataViewPage {
title = $(`div[info-drawer-title]`);
expandedAspect = $(`mat-expansion-panel-header[aria-expanded='true']`);
aspectTitle = `mat-panel-title`;
@ -48,8 +47,10 @@ export class MetadataViewPage {
saveMetadataButton = $(`[data-automation-id='save-metadata']`);
resetMetadataButton = $(`[data-automation-id='reset-metadata']`);
private getMetadataGroupLocator = async (groupName: string): Promise<ElementFinder> => $(`mat-expansion-panel[data-automation-id="adf-metadata-group-${groupName}"]`);
private getExpandedMetadataGroupLocator = async (groupName: string): Promise<ElementFinder> => $(`mat-expansion-panel[data-automation-id="adf-metadata-group-${groupName}"] > mat-expansion-panel-header`);
private getMetadataGroupLocator = async (groupName: string): Promise<ElementFinder> =>
$(`mat-expansion-panel[data-automation-id="adf-metadata-group-${groupName}"]`);
private getExpandedMetadataGroupLocator = async (groupName: string): Promise<ElementFinder> =>
$(`mat-expansion-panel[data-automation-id="adf-metadata-group-${groupName}"] > mat-expansion-panel-header`);
async getTitle(): Promise<string> {
return BrowserActions.getText(this.title);
@ -132,7 +133,9 @@ export class MetadataViewPage {
}
async clickOnPropertiesTab(): Promise<void> {
const propertiesTab = element(by.cssContainingText(`.adf-info-drawer-layout-content div.mat-tab-labels div .mat-tab-label-content`, `Properties`));
const propertiesTab = element(
by.cssContainingText(`.adf-info-drawer-layout-content div.mat-tab-labels div .mat-tab-label-content`, `Properties`)
);
await BrowserActions.click(propertiesTab);
}
@ -208,7 +211,9 @@ export class MetadataViewPage {
}
async getMetadataGroupTitle(groupName: string): Promise<string> {
const group = $('mat-expansion-panel[data-automation-id="adf-metadata-group-' + groupName + '"] > mat-expansion-panel-header > span > mat-panel-title');
const group = $(
'mat-expansion-panel[data-automation-id="adf-metadata-group-' + groupName + '"] > mat-expansion-panel-header > span > mat-panel-title'
);
return BrowserActions.getText(group);
}
@ -225,7 +230,7 @@ export class MetadataViewPage {
return false;
}
await type.waitVisible();
const isPresent = type.isPresent();
const isPresent = await type.isPresent();
if (isPresent) {
return true;
}
@ -269,7 +274,7 @@ export class MetadataViewPage {
} catch (error) {
Logger.log(`re trying content type options attempt :: ${attempt}`);
await BrowserActions.closeMenuAndDialogs();
return this.changeContentType(option, attempt + 1, maxAttempt);
return this.changeContentType(option, attempt + 1, maxAttempt);
}
}

View File

@ -16,43 +16,41 @@
*/
var FormDefinitionFieldModel = function (details) {
this.fieldType;
this.id;
this.name;
this.value;
this.type;
this.required;
this.readOnly;
this.overrideId;
this.colspan;
this.placeholder;
this.minLength;
this.maxLength;
this.minValue;
this.maxValue;
this.regexPattern;
this.optionType;
this.hasEmptyValue;
this.options;
this.restUrl;
this.restResponsePath;
this.restIdProperty;
this.setRestLabelProperty;
this.tab;
this.className;
this.dateDisplayFormat;
this.fieldType = undefined;
this.id = undefined;
this.name = undefined;
this.value = undefined;
this.type = undefined;
this.required = undefined;
this.readOnly = undefined;
this.overrideId = undefined;
this.colspan = undefined;
this.placeholder = undefined;
this.minLength = undefined;
this.maxLength = undefined;
this.minValue = undefined;
this.maxValue = undefined;
this.regexPattern = undefined;
this.optionType = undefined;
this.hasEmptyValue = undefined;
this.options = undefined;
this.restUrl = undefined;
this.restResponsePath = undefined;
this.restIdProperty = undefined;
this.setRestLabelProperty = undefined;
this.tab = undefined;
this.className = undefined;
this.dateDisplayFormat = undefined;
this.layout = {};
this.sizeX;
this.sizeY;
this.row;
this.col;
this.columnDefinitions;
this.visibilityCondition;
this.numberOfColumns;
this.sizeX = undefined;
this.sizeY = undefined;
this.row = undefined;
this.col = undefined;
this.columnDefinitions = undefined;
this.visibilityCondition = undefined;
this.numberOfColumns = undefined;
this.fields = {};
Object.assign(this, details);
};
module.exports = FormDefinitionFieldModel;

View File

@ -16,14 +16,13 @@
*/
var FormModel = function (details) {
this.id;
this.name;
this.description;
this.modelId;
this.appDefinitionId;
this.appDeploymentId;
this.tenantId;
this.id = undefined;
this.name = undefined;
this.description = undefined;
this.modelId = undefined;
this.appDefinitionId = undefined;
this.appDeploymentId = undefined;
this.tenantId = undefined;
this.getName = function () {
return this.name;

View File

@ -23,9 +23,8 @@
*/
var Task = function (details) {
this.processInstanceId;
this.sort;
this.processInstanceId = undefined;
this.sort = undefined;
Object.assign(this, details);
};

View File

@ -16,11 +16,10 @@
*/
var TaskAssigneeModel = function (details) {
this.id;
this.firstName;
this.lastName;
this.email;
this.id = undefined;
this.firstName = undefined;
this.lastName = undefined;
this.email = undefined;
this.getFirstName = function () {
return this.firstName;
@ -38,12 +37,11 @@ var TaskAssigneeModel = function (details) {
return this.email;
};
this.getEntireName = function() {
return this.firstName + " " + this.getLastName();
this.getEntireName = function () {
return this.firstName + ' ' + this.getLastName();
};
Object.assign(this, details);
};
module.exports = TaskAssigneeModel;

View File

@ -18,19 +18,18 @@
var TaskAssigneeModel = require('./TaskAssigneeModel');
var TaskModel = function (details) {
this.id;
this.name;
this.description;
this.category;
this.created;
this.dueDate;
this.priority;
this.parentTaskName;
this.parentTaskId;
this.formKey;
this.duration;
this.endDate;
this.id = undefined;
this.name = undefined;
this.description = undefined;
this.category = undefined;
this.created = undefined;
this.dueDate = undefined;
this.priority = undefined;
this.parentTaskName = undefined;
this.parentTaskId = undefined;
this.formKey = undefined;
this.duration = undefined;
this.endDate = undefined;
this.assignee = {};
this.getName = function () {

View File

@ -62,10 +62,6 @@
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-require-imports": "off",
"@typescript-eslint/no-var-requires": "error",
"brace-style": [
"error",
"1tbs"
],
"comma-dangle": "error",
"default-case": "error",
"import/order": "off",

View File

@ -18,33 +18,24 @@
import { Injectable } from '@angular/core';
import { Observable, from, throwError } from 'rxjs';
import { AlfrescoApiService, LogService } from '@alfresco/adf-core';
import {
AuditApi,
AuditAppPaging,
AuditAppEntry,
AuditApp,
AuditBodyUpdate,
AuditEntryPaging,
AuditEntryEntry
} from '@alfresco/js-api';
import { AuditApi, AuditAppPaging, AuditAppEntry, AuditApp, AuditBodyUpdate, AuditEntryPaging, AuditEntryEntry } from '@alfresco/js-api';
import { catchError } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class AuditService {
private _auditApi: AuditApi;
get auditApi(): AuditApi {
this._auditApi = this._auditApi ?? new AuditApi(this.apiService.getInstance());
return this._auditApi;
}
constructor(private apiService: AlfrescoApiService, private logService: LogService) {
}
constructor(private apiService: AlfrescoApiService, private logService: LogService) {}
/**
* Gets a list of audit applications.
*
* @param opts Options.
* @returns a list of the audit applications.
*/
@ -53,14 +44,12 @@ export class AuditService {
skipCount: 0
};
const queryOptions = Object.assign({}, defaultOptions, opts);
return from(this.auditApi.listAuditApps(queryOptions))
.pipe(
catchError((err: any) => this.handleError(err))
);
return from(this.auditApi.listAuditApps(queryOptions)).pipe(catchError((err: any) => this.handleError(err)));
}
/**
* Get audit application info.
*
* @param auditApplicationId The identifier of an audit application.
* @param opts Options.
* @returns status of an audit application.
@ -70,14 +59,12 @@ export class AuditService {
auditApplicationId
};
const queryOptions = Object.assign({}, defaultOptions, opts);
return from(this.auditApi.getAuditApp(queryOptions))
.pipe(
catchError((err: any) => this.handleError(err))
);
return from(this.auditApi.getAuditApp(queryOptions)).pipe(catchError((err: any) => this.handleError(err)));
}
/**
* Update audit application info.
*
* @param auditApplicationId The identifier of an audit application.
* @param auditAppBodyUpdate The audit application to update.
* @param opts Options.
@ -86,14 +73,14 @@ export class AuditService {
updateAuditApp(auditApplicationId: string, auditAppBodyUpdate: boolean, opts?: any): Observable<AuditApp | any> {
const defaultOptions = {};
const queryOptions = Object.assign({}, defaultOptions, opts);
return from(this.auditApi.updateAuditApp(auditApplicationId, new AuditBodyUpdate({ isEnabled: auditAppBodyUpdate }), queryOptions))
.pipe(
catchError((err: any) => this.handleError(err))
);
return from(this.auditApi.updateAuditApp(auditApplicationId, new AuditBodyUpdate({ isEnabled: auditAppBodyUpdate }), queryOptions)).pipe(
catchError((err: any) => this.handleError(err))
);
}
/**
* List audit entries for an audit application.
*
* @param auditApplicationId The identifier of an audit application.
* @param opts Options.
* @returns a list of audit entries.
@ -104,14 +91,14 @@ export class AuditService {
maxItems: 100
};
const queryOptions = Object.assign({}, defaultOptions, opts);
return from(this.auditApi.listAuditEntriesForAuditApp(auditApplicationId, queryOptions))
.pipe(
catchError((err: any) => this.handleError(err))
);
return from(this.auditApi.listAuditEntriesForAuditApp(auditApplicationId, queryOptions)).pipe(
catchError((err: any) => this.handleError(err))
);
}
/**
* Get audit entry.
*
* @param auditApplicationId The identifier of an audit application.
* @param auditEntryId The identifier of an audit entry.
* @param opts Options.
@ -120,14 +107,14 @@ export class AuditService {
getAuditEntry(auditApplicationId: string, auditEntryId: string, opts?: any): Observable<AuditEntryEntry> {
const defaultOptions = {};
const queryOptions = Object.assign({}, defaultOptions, opts);
return from(this.auditApi.getAuditEntry(auditApplicationId, auditEntryId, queryOptions))
.pipe(
catchError((err: any) => this.handleError(err))
);
return from(this.auditApi.getAuditEntry(auditApplicationId, auditEntryId, queryOptions)).pipe(
catchError((err: any) => this.handleError(err))
);
}
/**
* List audit entries for a node.
*
* @param nodeId The identifier of a node.
* @param opts Options.
* @returns
@ -137,36 +124,29 @@ export class AuditService {
nodeId
};
const queryOptions = Object.assign({}, defaultOptions, opts);
return from(this.auditApi.listAuditEntriesForNode(queryOptions))
.pipe(
catchError((err: any) => this.handleError(err))
);
return from(this.auditApi.listAuditEntriesForNode(queryOptions)).pipe(catchError((err: any) => this.handleError(err)));
}
/**
* Permanently delete audit entries for an audit application.
*
* @param auditApplicationId The identifier of an audit application.
* @param where Audit entries to permanently delete for an audit application, given an inclusive time period or range of ids.
* @returns
*/
deleteAuditEntries(auditApplicationId: string, where: string): Observable<any> {
return from(this.auditApi.deleteAuditEntriesForAuditApp(auditApplicationId, where))
.pipe(
catchError((err: any) => this.handleError(err))
);
return from(this.auditApi.deleteAuditEntriesForAuditApp(auditApplicationId, where)).pipe(catchError((err: any) => this.handleError(err)));
}
/**
* Permanently delete an audit entry.
*
* @param auditApplicationId The identifier of an audit application.
* @param auditEntryId The identifier of an audit entry.
* @returns
*/
deleteAuditEntry(auditApplicationId: string, auditEntryId: string): Observable<any> {
return from(this.auditApi.deleteAuditEntry(auditApplicationId, auditEntryId))
.pipe(
catchError((err: any) => this.handleError(err))
);
return from(this.auditApi.deleteAuditEntry(auditApplicationId, auditEntryId)).pipe(catchError((err: any) => this.handleError(err)));
}
private handleError(error: any): any {

View File

@ -129,7 +129,7 @@ export class BreadcrumbComponent implements OnInit, OnChanges, OnDestroy {
}
parseRoute(node: Node): PathElement[] {
if (node && node.path) {
if (node?.path) {
const route = (node.path.elements || []).slice();
route.push({

View File

@ -43,27 +43,27 @@ export class EcmUserModel {
capabilities?: Capabilities;
constructor(obj?: any) {
this.id = obj && obj.id || null;
this.firstName = obj && obj.firstName;
this.lastName = obj && obj.lastName;
this.description = obj && obj.description || null;
this.avatarId = obj && obj.avatarId || null;
this.email = obj && obj.email || null;
this.skypeId = obj && obj.skypeId;
this.googleId = obj && obj.googleId;
this.instantMessageId = obj && obj.instantMessageId;
this.jobTitle = obj && obj.jobTitle || null;
this.location = obj && obj.location || null;
this.company = obj && obj.company;
this.mobile = obj && obj.mobile;
this.telephone = obj && obj.telephone;
this.statusUpdatedAt = obj && obj.statusUpdatedAt;
this.userStatus = obj && obj.userStatus;
this.enabled = obj && obj.enabled;
this.emailNotificationsEnabled = obj && obj.emailNotificationsEnabled;
this.aspectNames = obj && obj.aspectNames;
this.properties = obj && obj.properties;
this.capabilities = obj && obj.capabilities;
this.id = obj?.id || null;
this.firstName = obj?.firstName;
this.lastName = obj?.lastName;
this.description = obj?.description || null;
this.avatarId = obj?.avatarId || null;
this.email = obj?.email || null;
this.skypeId = obj?.skypeId;
this.googleId = obj?.googleId;
this.instantMessageId = obj?.instantMessageId;
this.jobTitle = obj?.jobTitle || null;
this.location = obj?.location || null;
this.company = obj?.company;
this.mobile = obj?.mobile;
this.telephone = obj?.telephone;
this.statusUpdatedAt = obj?.statusUpdatedAt;
this.userStatus = obj?.userStatus;
this.enabled = obj?.enabled;
this.emailNotificationsEnabled = obj?.emailNotificationsEnabled;
this.aspectNames = obj?.aspectNames;
this.properties = obj?.properties;
this.capabilities = obj?.capabilities;
}
isAdmin(): boolean {

View File

@ -89,7 +89,7 @@ export class ContentService {
(currentPermission) => currentPermission.authorityId === userId
);
if (permissions.length) {
if (permission && permission.startsWith('!')) {
if (permission?.startsWith('!')) {
hasPermissions = !permissions.find((currentPermission) => currentPermission.name === permission.replace('!', ''));
} else {
hasPermissions = !!permissions.find((currentPermission) => currentPermission.name === permission);
@ -99,7 +99,7 @@ export class ContentService {
hasPermissions = true;
} else if (permission === PermissionsEnum.NOT_CONSUMER) {
hasPermissions = false;
} else if (permission && permission.startsWith('!')) {
} else if (permission?.startsWith('!')) {
hasPermissions = true;
}
}
@ -117,8 +117,8 @@ export class ContentService {
hasAllowableOperations(node: Node, allowableOperation: AllowableOperationsEnum | string): boolean {
let hasAllowableOperations = false;
if (node && node.allowableOperations) {
if (allowableOperation && allowableOperation.startsWith('!')) {
if (node?.allowableOperations) {
if (allowableOperation?.startsWith('!')) {
hasAllowableOperations = !node.allowableOperations.find(
(currentOperation) => currentOperation === allowableOperation.replace('!', '')
);
@ -126,7 +126,7 @@ export class ContentService {
hasAllowableOperations = !!node.allowableOperations.find((currentOperation) => currentOperation === allowableOperation);
}
} else {
if (allowableOperation && allowableOperation.startsWith('!')) {
if (allowableOperation?.startsWith('!')) {
hasAllowableOperations = true;
}
}

View File

@ -221,7 +221,7 @@ export class NodesApiService {
private cleanMetadataFromSemicolon(nodeEntry: NodeEntry): NodeMetadata {
const metadata = {};
if (nodeEntry && nodeEntry.entry.properties) {
if (nodeEntry?.entry.properties) {
for (const key in nodeEntry.entry.properties) {
if (key) {
if (key.indexOf(':') !== -1) {

View File

@ -135,7 +135,7 @@ export class SitesService {
*/
getSiteNameFromNodePath(node: Node): string {
let siteName = '';
if (node.path && node.path.elements) {
if (node.path?.elements) {
const foundNode = node.path.elements.find((pathNode) => pathNode.nodeType === 'st:site' && pathNode.name !== 'Sites');
siteName = foundNode ? foundNode.name : '';
}

View File

@ -18,12 +18,7 @@
import { EventEmitter, Injectable } from '@angular/core';
import { Minimatch } from 'minimatch';
import { Subject } from 'rxjs';
import {
FileUploadCompleteEvent,
FileUploadDeleteEvent,
FileUploadErrorEvent,
FileUploadEvent
} from '../events/file.event';
import { FileUploadCompleteEvent, FileUploadDeleteEvent, FileUploadErrorEvent, FileUploadEvent } from '../events/file.event';
import { FileModel, FileUploadProgress, FileUploadStatus } from '../models/file.model';
import { AppConfigService, AlfrescoApiService } from '@alfresco/adf-core';
import { filter } from 'rxjs/operators';
@ -81,12 +76,11 @@ export class UploadService {
constructor(
protected apiService: AlfrescoApiService,
private appConfigService: AppConfigService,
private discoveryApiService: DiscoveryApiService) {
this.discoveryApiService.ecmProductInfo$.pipe(filter(info => !!info))
.subscribe(({status}) => {
this.isThumbnailGenerationEnabled = status.isThumbnailGenerationEnabled;
});
private discoveryApiService: DiscoveryApiService
) {
this.discoveryApiService.ecmProductInfo$.pipe(filter((info) => !!info)).subscribe(({ status }) => {
this.isThumbnailGenerationEnabled = status.isThumbnailGenerationEnabled;
});
}
clearCache() {
@ -108,8 +102,17 @@ export class UploadService {
* @returns True if files in the queue are still uploading, false otherwise
*/
isUploading(): boolean {
const finishedFileStates = [FileUploadStatus.Complete, FileUploadStatus.Cancelled, FileUploadStatus.Aborted, FileUploadStatus.Error, FileUploadStatus.Deleted];
return this.queue.reduce((stillUploading: boolean, currentFile: FileModel) => stillUploading || finishedFileStates.indexOf(currentFile.status) === -1, false);
const finishedFileStates = [
FileUploadStatus.Complete,
FileUploadStatus.Cancelled,
FileUploadStatus.Aborted,
FileUploadStatus.Error,
FileUploadStatus.Deleted
];
return this.queue.reduce(
(stillUploading: boolean, currentFile: FileModel) => stillUploading || finishedFileStates.indexOf(currentFile.status) === -1,
false
);
}
/**
@ -128,9 +131,7 @@ export class UploadService {
* @returns Array of files that were not blocked from upload by the ignore list
*/
addToQueue(...files: FileModel[]): FileModel[] {
const allowedFiles = files.filter((currentFile) =>
this.filterElement(currentFile)
);
const allowedFiles = files.filter((currentFile) => this.filterElement(currentFile));
this.queue = this.queue.concat(allowedFiles);
this.queueChanged.next(this.queue);
return allowedFiles;
@ -217,7 +218,7 @@ export class UploadService {
opts.renditions = 'doclib';
}
if (file.options && file.options.versioningEnabled !== undefined) {
if (file.options?.versioningEnabled !== undefined) {
opts.versioningEnabled = file.options.versioningEnabled;
}
@ -240,13 +241,7 @@ export class UploadService {
const nodeBody: NodeBodyCreate = { ...file.options, name: file.name, nodeType: file.options.nodeType };
delete nodeBody['versioningEnabled'];
return this.uploadApi.uploadFile(
file.file,
file.options.path,
file.options.parentId,
nodeBody,
opts
);
return this.uploadApi.uploadFile(file.file, file.options.path, file.options.parentId, nodeBody, opts);
}
}
@ -259,7 +254,7 @@ export class UploadService {
}
const files = this.queue
.filter(toUpload => !cached.includes(toUpload.name) && toUpload.status === FileUploadStatus.Pending)
.filter((toUpload) => !cached.includes(toUpload.name) && toUpload.status === FileUploadStatus.Pending)
.slice(0, threadsCount);
return files;
@ -274,13 +269,13 @@ export class UploadService {
.on('abort', () => {
this.onUploadAborted(file);
if (successEmitter) {
successEmitter.emit({value: 'File aborted'});
successEmitter.emit({ value: 'File aborted' });
}
})
.on('error', (err) => {
this.onUploadError(file, err);
if (errorEmitter) {
errorEmitter.emit({value: 'Error file uploaded'});
errorEmitter.emit({ value: 'Error file uploaded' });
}
})
.on('success', (data) => {
@ -292,17 +287,16 @@ export class UploadService {
this.deleteAbortedNodeVersion(data.entry.id, data.entry.properties['cm:versionLabel']);
}
if (successEmitter) {
successEmitter.emit({value: 'File deleted'});
successEmitter.emit({ value: 'File deleted' });
}
} else {
this.onUploadComplete(file, data);
if (successEmitter) {
successEmitter.emit({value: data});
successEmitter.emit({ value: data });
}
}
})
.catch(() => {
});
.catch(() => {});
return promise;
}
@ -316,10 +310,7 @@ export class UploadService {
}
}
private onUploadProgress(
file: FileModel,
progress: FileUploadProgress
): void {
private onUploadProgress(file: FileModel, progress: FileUploadProgress): void {
if (file) {
file.progress = progress;
file.status = FileUploadStatus.Progress;
@ -330,9 +321,9 @@ export class UploadService {
}
}
private onUploadError(file: FileModel, error: any): void {
private onUploadError(file: FileModel, error: { status?: number }): void {
if (file) {
file.errorCode = (error || {}).status;
file.errorCode = error?.status;
file.status = FileUploadStatus.Error;
this.totalError++;
@ -341,11 +332,7 @@ export class UploadService {
delete this.cache[file.name];
}
const event = new FileUploadErrorEvent(
file,
error,
this.totalError
);
const event = new FileUploadErrorEvent(file, error, this.totalError);
this.fileUpload.next(event);
this.fileUploadError.next(event);
}
@ -361,12 +348,7 @@ export class UploadService {
delete this.cache[file.name];
}
const event = new FileUploadCompleteEvent(
file,
this.totalComplete,
data,
this.totalAborted
);
const event = new FileUploadCompleteEvent(file, this.totalComplete, data, this.totalAborted);
this.fileUpload.next(event);
this.fileUploadComplete.next(event);
}
@ -415,20 +397,15 @@ export class UploadService {
}
private deleteAbortedNode(nodeId: string) {
this.nodesApi.deleteNode(nodeId, {permanent: true})
.then(() => (this.abortedFile = undefined));
this.nodesApi.deleteNode(nodeId, { permanent: true }).then(() => (this.abortedFile = undefined));
}
private deleteAbortedNodeVersion(nodeId: string, versionId: string) {
this.versionsApi.deleteVersion(nodeId, versionId)
.then(() => (this.abortedFile = undefined));
this.versionsApi.deleteVersion(nodeId, versionId).then(() => (this.abortedFile = undefined));
}
private isSaveToAbortFile(file: FileModel): boolean {
return (
file.size > MIN_CANCELLABLE_FILE_SIZE &&
file.progress.percent < MAX_CANCELLABLE_FILE_PERCENTAGE
);
return file.size > MIN_CANCELLABLE_FILE_SIZE && file.progress.percent < MAX_CANCELLABLE_FILE_PERCENTAGE;
}
private filterElement(file: FileModel) {
@ -454,12 +431,12 @@ export class UploadService {
const fileRelativePath = currentFile.webkitRelativePath ? currentFile.webkitRelativePath : file.options.path;
if (currentFile && fileRelativePath) {
isAllowed =
this.excludedFoldersList.filter((folderToExclude) => fileRelativePath
.split('/')
.some((pathElement) => {
this.excludedFoldersList.filter((folderToExclude) =>
fileRelativePath.split('/').some((pathElement) => {
const minimatch = new Minimatch(folderToExclude, this.folderMatchingOptions);
return minimatch.match(pathElement);
})).length === 0;
})
).length === 0;
}
return isAllowed;
}

View File

@ -31,7 +31,6 @@ import { AllowableOperationsEnum } from '../../../common/models/allowable-operat
host: { class: 'adf-content-metadata-card' }
})
export class ContentMetadataCardComponent implements OnChanges {
/** (required) The node entity to fetch metadata about */
@Input()
node: Node;
@ -101,12 +100,16 @@ export class ContentMetadataCardComponent implements OnChanges {
editAspectSupported = false;
constructor(private contentService: ContentService, private nodeAspectService: NodeAspectService, private versionCompatibilityService: VersionCompatibilityService) {
constructor(
private contentService: ContentService,
private nodeAspectService: NodeAspectService,
private versionCompatibilityService: VersionCompatibilityService
) {
this.editAspectSupported = this.versionCompatibilityService.isVersionSupported('7');
}
ngOnChanges(changes: SimpleChanges): void {
if (changes.displayAspect && changes.displayAspect.currentValue) {
if (changes.displayAspect?.currentValue) {
this.expanded = true;
}
}

View File

@ -407,7 +407,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy {
private isExcludedSiteContent(row: ShareDataRow): boolean {
const entry = row.node.entry;
if (this._excludeSiteContent && this._excludeSiteContent.length && entry && entry.properties && entry.properties['st:componentId']) {
if (this._excludeSiteContent?.length && entry && entry.properties?.['st:componentId']) {
const excludedItem = this._excludeSiteContent.find((id: string) => entry.properties['st:componentId'] === id);
return !!excludedItem;
}
@ -489,7 +489,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy {
if (this.customResourcesService.hasCorrespondingNodeIds(this.siteId)) {
this.customResourcesService.getCorrespondingNodeIds(this.siteId).subscribe((nodeIds) => {
if (nodeIds && nodeIds.length) {
if (nodeIds?.length) {
nodeIds
.filter((id) => id !== this.siteId)
.forEach((extraId) => {

View File

@ -15,14 +15,7 @@
* limitations under the License.
*/
import {
Component,
Inject,
OnInit,
ViewEncapsulation,
ViewChild,
OnDestroy
} from '@angular/core';
import { Component, Inject, OnInit, ViewEncapsulation, ViewChild, OnDestroy } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog';
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
import { UntypedFormGroup, UntypedFormControl, AbstractControl } from '@angular/forms';
@ -43,11 +36,10 @@ type DatePickerType = 'date' | 'time' | 'month' | 'datetime';
selector: 'adf-share-dialog',
templateUrl: './content-node-share.dialog.html',
styleUrls: ['./content-node-share.dialog.scss'],
host: {class: 'adf-share-dialog'},
host: { class: 'adf-share-dialog' },
encapsulation: ViewEncapsulation.None
})
export class ShareDialogComponent implements OnInit, OnDestroy {
minDate = add(new Date(), { days: 1 });
sharedId: string;
fileName: string;
@ -57,16 +49,16 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
isLinkWithExpiryDate = false;
form: UntypedFormGroup = new UntypedFormGroup({
sharedUrl: new UntypedFormControl(''),
time: new UntypedFormControl({value: '', disabled: true})
time: new UntypedFormControl({ value: '', disabled: true })
});
type: DatePickerType = 'date';
maxDebounceTime = 500;
isExpiryDateToggleChecked: boolean;
@ViewChild('slideToggleExpirationDate', {static: true})
@ViewChild('slideToggleExpirationDate', { static: true })
slideToggleExpirationDate;
@ViewChild('datePickerInput', {static: true})
@ViewChild('datePickerInput', { static: true })
datePickerInput;
private onDestroy$ = new Subject<boolean>();
@ -78,17 +70,16 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
private contentService: ContentService,
private renditionService: RenditionService,
@Inject(MAT_DIALOG_DATA) public data: ContentNodeShareSettings
) {
}
) {}
ngOnInit() {
if (this.data.node && this.data.node.entry) {
if (this.data.node?.entry) {
this.fileName = this.data.node.entry.name;
this.baseShareUrl = this.data.baseShareUrl;
const properties = this.data.node.entry.properties;
if (!properties || !properties['qshare:sharedId']) {
if (!properties?.['qshare:sharedId']) {
this.createSharedLinks(this.data.node.entry.id);
} else {
this.sharedId = properties['qshare:sharedId'];
@ -100,12 +91,7 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
}
}
this.time.valueChanges
.pipe(
debounceTime(this.maxDebounceTime),
takeUntil(this.onDestroy$)
)
.subscribe(value => this.onTimeChanged(value));
this.time.valueChanges.pipe(debounceTime(this.maxDebounceTime), takeUntil(this.onDestroy$)).subscribe((value) => this.onTimeChanged(value));
}
onTimeChanged(date: Date) {
@ -130,9 +116,9 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
}
get canUpdate() {
const {entry} = this.data.node;
const { entry } = this.data.node;
if (entry && entry.allowableOperations) {
if (entry?.allowableOperations) {
return this.contentService.hasAllowableOperations(entry, 'update');
}
@ -214,28 +200,25 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
deleteSharedLink(sharedId: string, dialogOpenFlag?: boolean) {
this.isDisabled = true;
this.sharedLinksApiService
.deleteSharedLink(sharedId)
.subscribe((response: any) => {
if (response instanceof Error) {
this.isDisabled = false;
this.isFileShared = true;
this.handleError(response);
} else {
if (this.data.node.entry.properties) {
this.data.node.entry.properties['qshare:sharedId'] = null;
this.data.node.entry.properties['qshare:expiryDate'] = null;
}
if (dialogOpenFlag) {
this.createSharedLinks(this.data.node.entry.id);
this.isExpiryDateToggleChecked = false;
this.isLinkWithExpiryDate = false;
} else {
this.dialogRef.close(false);
}
}
this.sharedLinksApiService.deleteSharedLink(sharedId).subscribe((response: any) => {
if (response instanceof Error) {
this.isDisabled = false;
this.isFileShared = true;
this.handleError(response);
} else {
if (this.data.node.entry.properties) {
this.data.node.entry.properties['qshare:sharedId'] = null;
this.data.node.entry.properties['qshare:expiryDate'] = null;
}
);
if (dialogOpenFlag) {
this.createSharedLinks(this.data.node.entry.id);
this.isExpiryDateToggleChecked = false;
this.isLinkWithExpiryDate = false;
} else {
this.dialogRef.close(false);
}
}
});
}
private handleError(error: Error) {
@ -244,8 +227,7 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
try {
statusCode = JSON.parse(error.message).error.statusCode;
} catch {
}
} catch {}
if (statusCode === 403) {
message = 'SHARE.UNSHARE_PERMISSION_ERROR';
@ -258,17 +240,20 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
}
private updateForm(): Date {
const {entry} = this.data.node;
const { entry } = this.data.node;
let expiryDate = null;
if (entry && entry.properties) {
if (entry?.properties) {
expiryDate = entry.properties['qshare:expiryDate'];
}
this.form.setValue({
sharedUrl: `${this.baseShareUrl}${this.sharedId}`,
time: expiryDate ? new Date(expiryDate) : null
}, { emitEvent: false });
this.form.setValue(
{
sharedUrl: `${this.baseShareUrl}${this.sharedId}`,
time: expiryDate ? new Date(expiryDate) : null
},
{ emitEvent: false }
);
return expiryDate;
}
@ -279,25 +264,25 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
if (this.type === 'date') {
expiryDate = format(endOfDay(new Date(date)), `yyyy-MM-dd'T'HH:mm:ss.SSSxx`);
} else {
expiryDate = format((new Date(date)), `yyyy-MM-dd'T'HH:mm:ss.SSSxx`);
expiryDate = format(new Date(date), `yyyy-MM-dd'T'HH:mm:ss.SSSxx`);
}
} else {
expiryDate = null;
}
if (this.sharedId && expiryDate) {
this.isDisabled = true;
this.isDisabled = true;
this.sharedLinksApiService.deleteSharedLink(this.sharedId).subscribe((response: any) => {
if (response instanceof Error) {
this.isDisabled = false;
this.isFileShared = true;
this.handleError(response);
} else {
this.sharedLinkWithExpirySettings(expiryDate as Date);
this.isLinkWithExpiryDate = true;
this.updateEntryExpiryDate(date);
}
this.sharedLinksApiService.deleteSharedLink(this.sharedId).subscribe((response: any) => {
if (response instanceof Error) {
this.isDisabled = false;
this.isFileShared = true;
this.handleError(response);
} else {
this.sharedLinkWithExpirySettings(expiryDate as Date);
this.isLinkWithExpiryDate = true;
this.updateEntryExpiryDate(date);
}
});
}
}
@ -311,12 +296,10 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
}
private updateEntryExpiryDate(date: Date) {
const {properties} = this.data.node.entry;
const { properties } = this.data.node.entry;
if (properties) {
properties['qshare:expiryDate'] = date
? new Date(date)
: null;
properties['qshare:expiryDate'] = date ? new Date(date) : null;
}
}
}

View File

@ -29,12 +29,11 @@ import { takeUntil } from 'rxjs/operators';
exportAs: 'adfShare'
})
export class NodeSharedDirective implements OnChanges, OnDestroy {
isFile: boolean = false;
isShared: boolean = false;
/** Node to share. */
// eslint-disable-next-line @angular-eslint/no-input-rename
// eslint-disable-next-line @angular-eslint/no-input-rename
@Input('adf-share')
node: NodeEntry;
@ -50,11 +49,7 @@ export class NodeSharedDirective implements OnChanges, OnDestroy {
return this._nodesApi;
}
constructor(
private dialog: MatDialog,
private zone: NgZone,
private alfrescoApiService: AlfrescoApiService) {
}
constructor(private dialog: MatDialog, private zone: NgZone, private alfrescoApiService: AlfrescoApiService) {}
ngOnDestroy() {
this.onDestroy$.next(true);
@ -62,7 +57,7 @@ export class NodeSharedDirective implements OnChanges, OnDestroy {
}
shareNode(nodeEntry: NodeEntry) {
if (nodeEntry && nodeEntry.entry && nodeEntry.entry.isFile) {
if (nodeEntry?.entry?.isFile) {
// shared and favorite
const nodeId = nodeEntry.entry['nodeId'] || nodeEntry.entry['guid'];
@ -96,14 +91,12 @@ export class NodeSharedDirective implements OnChanges, OnDestroy {
}
ngOnChanges() {
this.zone.onStable
.pipe(takeUntil(this.onDestroy$))
.subscribe(() => {
if (this.node && this.node.entry) {
this.isFile = this.node.entry.isFile;
this.isShared = this.node.entry.properties ? this.node.entry.properties['qshare:sharedId'] : false;
}
});
this.zone.onStable.pipe(takeUntil(this.onDestroy$)).subscribe(() => {
if (this.node?.entry) {
this.isFile = this.node.entry.isFile;
this.isShared = this.node.entry.properties ? this.node.entry.properties['qshare:sharedId'] : false;
}
});
}
@HostListener('click')

View File

@ -46,7 +46,7 @@ export class DownloadZipDialogComponent implements OnInit {
) {}
ngOnInit() {
if (this.data && this.data.nodeIds && this.data.nodeIds.length > 0) {
if (this.data?.nodeIds?.length > 0) {
if (!this.cancelled) {
this.downloadZip(this.data.nodeIds);
} else {
@ -64,7 +64,7 @@ export class DownloadZipDialogComponent implements OnInit {
downloadZip(nodeIds: string[]) {
if (nodeIds && nodeIds.length > 0) {
this.downloadZipService.createDownload({ nodeIds }).subscribe((data: DownloadEntry) => {
if (data && data.entry && data.entry.id) {
if (data?.entry?.id) {
const url = this.contentService.getContentUrl(data.entry.id, true);
this.nodeService.getNode(data.entry.id).subscribe((downloadNode) => {

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Directive, HostListener, Input, OnChanges, Output, EventEmitter } from '@angular/core';
import { Directive, HostListener, Input, OnChanges, Output, EventEmitter, SimpleChanges } from '@angular/core';
import { FavoriteBodyCreate, FavoritesApi } from '@alfresco/js-api';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { LibraryEntity } from '../interfaces/library-entity.interface';
@ -59,7 +59,7 @@ export class LibraryFavoriteDirective implements OnChanges {
constructor(private alfrescoApiService: AlfrescoApiService) {}
ngOnChanges(changes) {
ngOnChanges(changes: SimpleChanges) {
if (!changes.library.currentValue) {
this.targetLibrary = null;
return;
@ -70,7 +70,7 @@ export class LibraryFavoriteDirective implements OnChanges {
}
isFavorite(): boolean {
return this.targetLibrary && this.targetLibrary.isFavorite;
return this.targetLibrary?.isFavorite;
}
private async markFavoriteLibrary(library: LibraryEntity) {

View File

@ -16,17 +16,11 @@
*/
import { Directive, EventEmitter, HostListener, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import {
SiteEntry,
SiteMembershipRequestBodyCreate,
SiteMemberEntry,
SiteMembershipRequestEntry,
SitesApi
} from '@alfresco/js-api';
import { SiteEntry, SiteMembershipRequestBodyCreate, SiteMembershipRequestEntry, SitesApi } from '@alfresco/js-api';
import { BehaviorSubject, from, Observable } from 'rxjs';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { LibraryMembershipToggleEvent } from '../interfaces/library-membership-toggle-event.interface';
import { LibraryMembershipErrorEvent} from '../interfaces/library-membership-error-event.interface';
import { LibraryMembershipErrorEvent } from '../interfaces/library-membership-error-event.interface';
import { VersionCompatibilityService } from '../version-compatibility/version-compatibility.service';
import { SitesService } from '../common/services/sites.service';
@ -39,7 +33,7 @@ export class LibraryMembershipDirective implements OnChanges {
isJoinRequested: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
_sitesApi: SitesApi;
private _sitesApi: SitesApi;
get sitesApi(): SitesApi {
this._sitesApi = this._sitesApi ?? new SitesApi(this.alfrescoApiService.getInstance());
return this._sitesApi;
@ -69,11 +63,10 @@ export class LibraryMembershipDirective implements OnChanges {
private alfrescoApiService: AlfrescoApiService,
private sitesService: SitesService,
private versionCompatibilityService: VersionCompatibilityService
) {
}
) {}
ngOnChanges(changes: SimpleChanges) {
if (!changes.selection.currentValue || !changes.selection.currentValue.entry) {
if (!changes.selection.currentValue?.entry) {
this.targetSite = null;
return;
@ -115,7 +108,7 @@ export class LibraryMembershipDirective implements OnChanges {
this.targetSite.joinRequested = true;
this.isJoinRequested.next(true);
if (createdMembership.entry && createdMembership.entry.site && createdMembership.entry.site.role) {
if (createdMembership.entry?.site?.role) {
const info = {
shouldReload: true,
i18nKey: 'ADF_LIBRARY_MEMBERSHIP_MESSAGES.INFO.JOINED'
@ -154,8 +147,8 @@ export class LibraryMembershipDirective implements OnChanges {
if (this.isAdmin) {
this.joinLibrary().subscribe(
(createdMembership: SiteMemberEntry) => {
if (createdMembership.entry && createdMembership.entry.role) {
(createdMembership) => {
if (createdMembership.entry?.role) {
const info = {
shouldReload: true,
i18nKey: 'ADF_LIBRARY_MEMBERSHIP_MESSAGES.INFO.JOINED'
@ -223,7 +216,7 @@ export class LibraryMembershipDirective implements OnChanges {
});
}
private cancelJoinRequest() {
private cancelJoinRequest(): Observable<void> {
return from(this.sitesApi.deleteSiteMembershipRequestForPerson('-me-', this.targetSite.id));
}

View File

@ -78,10 +78,7 @@ export class NodeDeleteDirective implements OnChanges {
this.process(this.selection);
}
constructor(private alfrescoApiService: AlfrescoApiService,
private translation: TranslationService,
private elementRef: ElementRef) {
}
constructor(private alfrescoApiService: AlfrescoApiService, private translation: TranslationService, private elementRef: ElementRef) {}
ngOnChanges() {
if (!this.selection || (this.selection && this.selection.length === 0)) {
@ -98,23 +95,21 @@ export class NodeDeleteDirective implements OnChanges {
}
private process(selection: NodeEntry[] | DeletedNodeEntry[]) {
if (selection && selection.length) {
if (selection?.length) {
const batch = this.getDeleteNodesBatch(selection);
forkJoin(...batch)
.subscribe((data: ProcessedNodeData[]) => {
const processedItems: ProcessStatus = this.processStatus(data);
const message = this.getMessage(processedItems);
forkJoin(...batch).subscribe((data: ProcessedNodeData[]) => {
const processedItems: ProcessStatus = this.processStatus(data);
const message = this.getMessage(processedItems);
if (message) {
this.delete.emit(message);
}
});
if (message) {
this.delete.emit(message);
}
});
}
}
private getDeleteNodesBatch(selection: any): Observable<ProcessedNodeData>[] {
private getDeleteNodesBatch(selection: NodeEntry[] | DeletedNodeEntry[]): Observable<ProcessedNodeData>[] {
return selection.map((node) => this.deleteNode(node));
}
@ -135,10 +130,12 @@ export class NodeDeleteDirective implements OnChanges {
entry: node.entry,
status: 1
})),
catchError(() => of({
entry: node.entry,
status: 0
}))
catchError(() =>
of({
entry: node.entry,
status: 0
})
)
);
}
@ -147,10 +144,10 @@ export class NodeDeleteDirective implements OnChanges {
success: [],
failed: [],
get someFailed() {
return !!(this.failed.length);
return !!this.failed.length;
},
get someSucceeded() {
return !!(this.success.length);
return !!this.success.length;
},
get oneFailed() {
return this.failed.length === 1;
@ -166,18 +163,15 @@ export class NodeDeleteDirective implements OnChanges {
}
};
return data.reduce(
(acc, next) => {
if (next.status === 1) {
acc.success.push(next);
} else {
acc.failed.push(next);
}
return data.reduce((acc, next) => {
if (next.status === 1) {
acc.success.push(next);
} else {
acc.failed.push(next);
}
return acc;
},
deleteStatus
);
return acc;
}, deleteStatus);
}
private getMessage(status: ProcessStatus): string | null {
@ -198,37 +192,25 @@ export class NodeDeleteDirective implements OnChanges {
}
if (status.someFailed && status.someSucceeded && !status.oneSucceeded) {
return this.translation.instant(
'CORE.DELETE_NODE.PARTIAL_PLURAL',
{
success: status.success.length,
failed: status.failed.length
}
);
return this.translation.instant('CORE.DELETE_NODE.PARTIAL_PLURAL', {
success: status.success.length,
failed: status.failed.length
});
}
if (status.someFailed && status.oneSucceeded) {
return this.translation.instant(
'CORE.DELETE_NODE.PARTIAL_SINGULAR',
{
success: status.success.length,
failed: status.failed.length
}
);
return this.translation.instant('CORE.DELETE_NODE.PARTIAL_SINGULAR', {
success: status.success.length,
failed: status.failed.length
});
}
if (status.oneFailed && !status.someSucceeded) {
return this.translation.instant(
'CORE.DELETE_NODE.ERROR_SINGULAR',
{ name: status.failed[0].entry.name }
);
return this.translation.instant('CORE.DELETE_NODE.ERROR_SINGULAR', { name: status.failed[0].entry.name });
}
if (status.oneSucceeded && !status.someFailed) {
return this.translation.instant(
'CORE.DELETE_NODE.SINGULAR',
{ name: status.success[0].entry.name }
);
return this.translation.instant('CORE.DELETE_NODE.SINGULAR', { name: status.success[0].entry.name });
}
return null;

View File

@ -29,7 +29,6 @@ import { ContentApi, NodeEntry, VersionEntry } from '@alfresco/js-api';
selector: '[adfNodeDownload]'
})
export class NodeDownloadDirective {
_contentApi: ContentApi;
get contentApi(): ContentApi {
this._contentApi = this._contentApi ?? new ContentApi(this.apiService.getInstance());
@ -49,11 +48,7 @@ export class NodeDownloadDirective {
this.downloadNodes(this.nodes);
}
constructor(
private apiService: AlfrescoApiService,
private downloadService: DownloadService,
private dialog: MatDialog) {
}
constructor(private apiService: AlfrescoApiService, private downloadService: DownloadService, private dialog: MatDialog) {}
/**
* Downloads multiple selected nodes.
@ -62,7 +57,6 @@ export class NodeDownloadDirective {
* @param selection Multiple selected nodes to download
*/
downloadNodes(selection: NodeEntry | Array<NodeEntry>) {
if (!this.isSelectionValid(selection)) {
return;
}
@ -84,7 +78,7 @@ export class NodeDownloadDirective {
* @param node Node to download
*/
downloadNode(node: NodeEntry) {
if (node && node.entry) {
if (node?.entry) {
const entry = node.entry;
if (entry.isFile) {
@ -107,12 +101,12 @@ export class NodeDownloadDirective {
}
private downloadFile(node: NodeEntry) {
if (node && node.entry) {
if (node?.entry) {
// nodeId for Shared node
const id = (node.entry as any).nodeId || node.entry.id;
let url;
let fileName;
let url: string;
let fileName: string;
if (this.version) {
url = this.contentApi.getVersionContentUrl(id, this.version.entry.id, true);
fileName = this.version.entry.name;
@ -128,7 +122,7 @@ export class NodeDownloadDirective {
private downloadZip(selection: Array<NodeEntry>) {
if (selection && selection.length > 0) {
// nodeId for Shared node
const nodeIds = selection.map((node: any) => (node.entry.nodeId || node.entry.id));
const nodeIds = selection.map((node: any) => node.entry.nodeId || node.entry.id);
this.dialog.open(DownloadZipDialogComponent, {
width: '600px',

View File

@ -130,7 +130,7 @@ export class NodeFavoriteDirective implements OnChanges {
const node: Node | SharedLink = selected.entry;
// ACS 6.x with 'isFavorite' include
if (node && node.hasOwnProperty('isFavorite')) {
if (node?.hasOwnProperty('isFavorite')) {
return of(selected);
}

View File

@ -19,8 +19,20 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {
AfterContentInit, Component, ContentChild, ElementRef, EventEmitter, HostListener, Input,
OnChanges, OnDestroy, OnInit, Output, SimpleChanges, ViewChild, ViewEncapsulation
AfterContentInit,
Component,
ContentChild,
ElementRef,
EventEmitter,
HostListener,
Input,
OnChanges,
OnDestroy,
OnInit,
Output,
SimpleChanges,
ViewChild,
ViewEncapsulation
} from '@angular/core';
import { ContentService } from '../../common/services/content.service';
@ -75,15 +87,17 @@ const BYTES_TO_MB_CONVERSION_VALUE = 1048576;
selector: 'adf-document-list',
templateUrl: './document-list.component.html',
styleUrls: ['./document-list.component.scss'],
providers:[{
provide: ADF_DOCUMENT_PARENT_COMPONENT,
useExisting: DocumentListComponent
}, DataTableService],
providers: [
{
provide: ADF_DOCUMENT_PARENT_COMPONENT,
useExisting: DocumentListComponent
},
DataTableService
],
encapsulation: ViewEncapsulation.None,
host: { class: 'adf-document-list' }
})
export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, AfterContentInit, PaginatedComponent, NavigableComponentInterface {
static SINGLE_CLICK_NAVIGATION: string = 'click';
static DOUBLE_CLICK_NAVIGATION: string = 'dblclick';
@ -94,10 +108,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
totalItems: 0
});
DEFAULT_SORTING: DataSorting[] = [
new DataSorting('name', 'asc'),
new DataSorting('isFolder', 'desc')
];
DEFAULT_SORTING: DataSorting[] = [new DataSorting('name', 'asc'), new DataSorting('isFolder', 'desc')];
@ContentChild(DataColumnListComponent)
columnList: DataColumnListComponent;
@ -362,34 +373,33 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
return this._nodesApi;
}
constructor(private documentListService: DocumentListService,
private elementRef: ElementRef,
private appConfig: AppConfigService,
private userPreferencesService: UserPreferencesService,
private contentService: ContentService,
private thumbnailService: ThumbnailService,
private alfrescoApiService: AlfrescoApiService,
private nodeService: NodesApiService,
private dataTableService: DataTableService,
private lockService: LockService,
private dialog: MatDialog) {
this.nodeService.nodeUpdated
.pipe(takeUntil(this.onDestroy$))
.subscribe((node) => {
this.dataTableService.rowUpdate.next({id: node.id, obj: {entry: node}});
});
constructor(
private documentListService: DocumentListService,
private elementRef: ElementRef,
private appConfig: AppConfigService,
private userPreferencesService: UserPreferencesService,
private contentService: ContentService,
private thumbnailService: ThumbnailService,
private alfrescoApiService: AlfrescoApiService,
private nodeService: NodesApiService,
private dataTableService: DataTableService,
private lockService: LockService,
private dialog: MatDialog
) {
this.nodeService.nodeUpdated.pipe(takeUntil(this.onDestroy$)).subscribe((node) => {
this.dataTableService.rowUpdate.next({ id: node.id, obj: { entry: node } });
});
this.userPreferencesService
.select(UserPreferenceValues.PaginationSize)
.pipe(takeUntil(this.onDestroy$))
.subscribe(pagSize => {
.subscribe((pagSize) => {
this.maxItems = this._pagination.maxItems = pagSize;
});
}
getContextActions(node: NodeEntry) {
if (node && node.entry) {
if (node?.entry) {
const actions = this.getNodeActions(node);
if (actions && actions.length > 0) {
return actions.map((currentAction: ContentActionModel) => ({
@ -403,7 +413,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
}
private get hasCustomLayout(): boolean {
return this.columnList && this.columnList.columns && this.columnList.columns.length > 0;
return this.columnList?.columns?.length > 0;
}
private getDefaultSorting(): DataSorting {
@ -433,8 +443,14 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
ngOnInit() {
this.rowMenuCache = {};
this.loadLayoutPresets();
this.data = new ShareDataTableAdapter(this.thumbnailService, this.contentService, null, this.getDefaultSorting(),
this.sortingMode, this.allowDropFiles);
this.data = new ShareDataTableAdapter(
this.thumbnailService,
this.contentService,
null,
this.getDefaultSorting(),
this.sortingMode,
this.allowDropFiles
);
this.data.thumbnails = this.thumbnails;
this.data.permissionsStyle = this.permissionsStyle;
@ -446,9 +462,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
this.data.setImageResolver(this.imageResolver);
}
this.contextActionHandler
.pipe(takeUntil(this.onDestroy$))
.subscribe(val => this.contextActionCallback(val));
this.contextActionHandler.pipe(takeUntil(this.onDestroy$)).subscribe((val) => this.contextActionCallback(val));
this.enforceSingleClickNavigationForMobile();
if (this.filterValue && Object.keys(this.filterValue).length > 0) {
@ -458,9 +472,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
ngAfterContentInit() {
if (this.columnList) {
this.columnList.columns.changes
.pipe(takeUntil(this.onDestroy$))
.subscribe(() => this.setTableSchema());
this.columnList.columns.changes.pipe(takeUntil(this.onDestroy$)).subscribe(() => this.setTableSchema());
}
this.setTableSchema();
}
@ -517,7 +529,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
}
if (this.data) {
if (changes.node && changes.node.currentValue) {
if (changes.node?.currentValue) {
const merge = this._pagination ? this._pagination.merge : false;
this.data.loadPage(changes.node.currentValue, merge, null);
this.preserveExistingSelection();
@ -555,7 +567,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
}
getNodeActions(node: NodeEntry | any): ContentActionModel[] {
if (node && node.entry) {
if (node?.entry) {
let target = null;
if (node.entry.isFile) {
@ -575,9 +587,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
const actionsByTarget = this.actions
.filter((entry) => {
const isVisible = (typeof entry.visible === 'function')
? entry.visible(node)
: entry.visible;
const isVisible = typeof entry.visible === 'function' ? entry.visible(node) : entry.visible;
return isVisible && entry.target.toLowerCase() === target;
})
@ -613,10 +623,10 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
return action.disabled(node);
}
if ((action.permission &&
action.disableWithNoPermission &&
!this.contentService.hasAllowableOperations(node.entry, action.permission)) ||
this.lockService.isLocked(node.entry)) {
if (
(action.permission && action.disableWithNoPermission && !this.contentService.hasAllowableOperations(node.entry, action.permission)) ||
this.lockService.isLocked(node.entry)
) {
return true;
} else {
return action.disabled;
@ -654,8 +664,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
}
private isLinkFolder(node: Node) {
return node.nodeType === 'app:folderlink' && node.properties &&
node.properties['cm:destination'];
return node.nodeType === 'app:folderlink' && node.properties && node.properties['cm:destination'];
}
private updateCustomSourceData(nodeId: string): void {
@ -669,13 +678,11 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
* @param action Action to be executed against the context.
*/
executeContentAction(node: NodeEntry, action: ContentActionModel) {
if (node && node.entry && action) {
const handlerSub = (typeof action.handler === 'function') ? action.handler(node, this, action.permission) : of(true);
if (node?.entry && action) {
const handlerSub = typeof action.handler === 'function' ? action.handler(node, this, action.permission) : of(true);
if (typeof action.execute === 'function' && handlerSub) {
handlerSub
.pipe(takeUntil(this.onDestroy$))
.subscribe(() => action.execute(node));
handlerSub.pipe(takeUntil(this.onDestroy$)).subscribe(() => action.execute(node));
}
}
}
@ -710,16 +717,18 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
this.updateCustomSourceData(this.currentFolderId);
}
this.documentListService.loadFolderByNodeId(this.currentFolderId, this._pagination, this.includeFields, this.where, this.orderBy)
.subscribe((documentNode: DocumentLoaderNode) => {
this.documentListService.loadFolderByNodeId(this.currentFolderId, this._pagination, this.includeFields, this.where, this.orderBy).subscribe(
(documentNode: DocumentLoaderNode) => {
if (documentNode.currentNode) {
this.folderNode = documentNode.currentNode.entry;
this.$folderNode.next(documentNode.currentNode.entry);
}
this.onPageLoaded(documentNode.children);
}, (err) => {
},
(err) => {
this.handleError(err);
});
}
);
}
resetSelection() {
@ -751,10 +760,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
}
private buildOrderByArray(currentKey: string, currentDirection: string): string[] {
return [
`${this.additionalSorting.key} ${this.additionalSorting.direction}`,
`${currentKey} ${currentDirection}`
];
return [`${this.additionalSorting.key} ${this.additionalSorting.direction}`, `${currentKey} ${currentDirection}`];
}
/**
@ -801,7 +807,6 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
this.executeActionClick(nodeEntry);
}
}
}
onNodeDblClick(nodeEntry: NodeEntry) {
@ -825,7 +830,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
}
executeActionClick(nodeEntry: NodeEntry) {
if (nodeEntry && nodeEntry.entry) {
if (nodeEntry?.entry) {
if (nodeEntry.entry.isFile) {
this.onPreviewFile(nodeEntry);
}
@ -839,10 +844,9 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
include: this.includeFields
};
this.nodesApi.getNode(nodeEntry.entry['guid'], options)
.then((node: NodeEntry) => {
this.navigateTo(node.entry);
});
this.nodesApi.getNode(nodeEntry.entry['guid'], options).then((node: NodeEntry) => {
this.navigateTo(node.entry);
});
}
}
}
@ -911,7 +915,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
canNavigateFolder(node: Node): boolean {
let canNavigateFolder: boolean = false;
if (node && node.isFolder) {
if (node?.isFolder) {
canNavigateFolder = true;
}
@ -960,8 +964,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
if (JSON.parse(err.message).error.statusCode === 403) {
this.noPermission = true;
}
} catch (error) {
}
} catch (error) {}
}
this.setLoadingState(false);
this.error.emit(err);
@ -976,7 +979,11 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
}
getSelectionBasedOnSelectionMode(): DataRow[] {
return this.hasPreselectedRows() ? (this.isSingleSelectionMode() ? [this.preselectedRows[0]] : this.data.getSelectedRows()) : this.data.getSelectedRows();
return this.hasPreselectedRows()
? this.isSingleSelectionMode()
? [this.preselectedRows[0]]
: this.data.getSelectedRows()
: this.data.getSelectedRows();
}
onPreselectNodes() {

View File

@ -63,7 +63,7 @@ export class FilterHeaderComponent implements OnInit, OnChanges, OnDestroy {
}
ngOnChanges(changes: SimpleChanges) {
if (changes['currentFolderId'] && changes['currentFolderId'].currentValue) {
if (changes['currentFolderId']?.currentValue) {
this.resetFilterHeader();
this.configureSearchParent(changes['currentFolderId'].currentValue);
}

View File

@ -15,15 +15,7 @@
* limitations under the License.
*/
import {
Component,
ChangeDetectionStrategy,
ViewEncapsulation,
OnInit,
Input,
ElementRef,
OnDestroy
} from '@angular/core';
import { Component, ChangeDetectionStrategy, ViewEncapsulation, OnInit, Input, ElementRef, OnDestroy } from '@angular/core';
import { NodeEntry, Site } from '@alfresco/js-api';
import { ShareDataRow } from '../../data/share-data-row.model';
import { NodesApiService } from '../../../common/services/nodes-api.service';
@ -36,13 +28,17 @@ import { takeUntil } from 'rxjs/operators';
template: `
<span
role="link"
[attr.aria-label]="'NAME_COLUMN_LINK.ACCESSIBILITY.ARIA_LABEL' | translate:{
name: displayText$ | async
}"
[attr.aria-label]="
'NAME_COLUMN_LINK.ACCESSIBILITY.ARIA_LABEL'
| translate
: {
name: displayText$ | async
}
"
class="adf-datatable-cell-value"
title="{{ displayTooltip$ | async }}"
(click)="onClick()">
(click)="onClick()"
>
{{ displayText$ | async }}
</span>
`,
@ -62,36 +58,29 @@ export class LibraryNameColumnComponent implements OnInit, OnDestroy {
private onDestroy$ = new Subject<boolean>();
constructor(
private element: ElementRef,
private nodesApiService: NodesApiService
) {}
constructor(private element: ElementRef, private nodesApiService: NodesApiService) {}
ngOnInit() {
this.updateValue();
this.nodesApiService.nodeUpdated
.pipe(takeUntil(this.onDestroy$))
.subscribe(node => {
const row: ShareDataRow = this.context.row;
if (row) {
const { entry } = row.node;
this.nodesApiService.nodeUpdated.pipe(takeUntil(this.onDestroy$)).subscribe((node) => {
const row: ShareDataRow = this.context.row;
if (row) {
const { entry } = row.node;
if (entry === node) {
row.node = { entry };
this.updateValue();
}
if (entry === node) {
row.node = { entry };
this.updateValue();
}
});
}
});
}
protected updateValue() {
this.node = this.context.row.node;
const rows: Array<ShareDataRow> = this.context.data.rows || [];
if (this.node && this.node.entry) {
this.displayText$.next(
this.makeLibraryTitle(this.node.entry as any, rows)
);
if (this.node?.entry) {
this.displayText$.next(this.makeLibraryTitle(this.node.entry as any, rows));
this.displayTooltip$.next(this.makeLibraryTooltip(this.node.entry));
}
}

View File

@ -15,14 +15,7 @@
* limitations under the License.
*/
import {
Component,
OnInit,
Input,
ChangeDetectionStrategy,
ViewEncapsulation,
OnDestroy
} from '@angular/core';
import { Component, OnInit, Input, ChangeDetectionStrategy, ViewEncapsulation, OnDestroy } from '@angular/core';
import { BehaviorSubject, Subject } from 'rxjs';
import { SiteEntry, Site } from '@alfresco/js-api';
import { ShareDataRow } from '../../data/share-data-row.model';
@ -32,8 +25,8 @@ import { NodesApiService } from '../../../common/services/nodes-api.service';
@Component({
selector: 'adf-library-role-column',
template: `
<span class="adf-datatable-cell-value" title="{{ (displayText$ | async) | translate }}">
{{ (displayText$ | async) | translate }}
<span class="adf-datatable-cell-value" title="{{ displayText$ | async | translate }}">
{{ displayText$ | async | translate }}
</span>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
@ -53,24 +46,22 @@ export class LibraryRoleColumnComponent implements OnInit, OnDestroy {
ngOnInit() {
this.updateValue();
this.nodesApiService.nodeUpdated
.pipe(takeUntil(this.onDestroy$))
.subscribe(node => {
const row: ShareDataRow = this.context.row;
if (row) {
const { entry } = row.node;
this.nodesApiService.nodeUpdated.pipe(takeUntil(this.onDestroy$)).subscribe((node) => {
const row: ShareDataRow = this.context.row;
if (row) {
const { entry } = row.node;
if (entry === node) {
row.node = { entry };
this.updateValue();
}
if (entry === node) {
row.node = { entry };
this.updateValue();
}
});
}
});
}
protected updateValue() {
const node: SiteEntry = this.context.row.node;
if (node && node.entry) {
if (node?.entry) {
const role: string = node.entry.role;
switch (role) {
case Site.RoleEnum.SiteManager:

View File

@ -25,8 +25,8 @@ import { takeUntil } from 'rxjs/operators';
@Component({
selector: 'adf-library-status-column',
template: `
<span class="adf-datatable-cell-value" title="{{ (displayText$ | async) | translate }}">
{{ (displayText$ | async) | translate }}
<span class="adf-datatable-cell-value" title="{{ displayText$ | async | translate }}">
{{ displayText$ | async | translate }}
</span>
`,
host: { class: 'adf-library-status-column adf-datatable-content-cell' }
@ -44,24 +44,22 @@ export class LibraryStatusColumnComponent implements OnInit, OnDestroy {
ngOnInit() {
this.updateValue();
this.nodesApiService.nodeUpdated
.pipe(takeUntil(this.onDestroy$))
.subscribe(node => {
const row: ShareDataRow = this.context.row;
if (row) {
const { entry } = row.node;
this.nodesApiService.nodeUpdated.pipe(takeUntil(this.onDestroy$)).subscribe((node) => {
const row: ShareDataRow = this.context.row;
if (row) {
const { entry } = row.node;
if (entry === node) {
row.node = { entry };
this.updateValue();
}
if (entry === node) {
row.node = { entry };
this.updateValue();
}
});
}
});
}
protected updateValue() {
const node: SiteEntry = this.context.row.node;
if (node && node.entry) {
if (node?.entry) {
const visibility: string = node.entry.visibility;
switch (visibility) {

View File

@ -15,15 +15,7 @@
* limitations under the License.
*/
import {
Component,
Input,
OnInit,
ChangeDetectionStrategy,
ViewEncapsulation,
ElementRef,
OnDestroy
} from '@angular/core';
import { Component, Input, OnInit, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, OnDestroy } from '@angular/core';
import { NodeEntry } from '@alfresco/js-api';
import { BehaviorSubject, Subject } from 'rxjs';
import { NodesApiService } from '../../../common/services/nodes-api.service';
@ -35,13 +27,17 @@ import { takeUntil } from 'rxjs/operators';
template: `
<span
role="link"
[attr.aria-label]="'NAME_COLUMN_LINK.ACCESSIBILITY.ARIA_LABEL' | translate:{
name: displayText$ | async
}"
[attr.aria-label]="
'NAME_COLUMN_LINK.ACCESSIBILITY.ARIA_LABEL'
| translate
: {
name: displayText$ | async
}
"
class="adf-datatable-cell-value"
title="{{ node | adfNodeNameTooltip }}"
(click)="onClick()">
(click)="onClick()"
>
{{ displayText$ | async }}
</span>
`,
@ -66,25 +62,23 @@ export class NameColumnComponent implements OnInit, OnDestroy {
ngOnInit() {
this.updateValue();
this.nodesApiService.nodeUpdated
.pipe(takeUntil(this.onDestroy$))
.subscribe(node => {
const row: ShareDataRow = this.context.row;
if (row) {
const { entry } = row.node;
this.nodesApiService.nodeUpdated.pipe(takeUntil(this.onDestroy$)).subscribe((node) => {
const row: ShareDataRow = this.context.row;
if (row) {
const { entry } = row.node;
if (entry === node) {
row.node = { entry };
this.updateValue();
}
if (entry === node) {
row.node = { entry };
this.updateValue();
}
});
}
});
}
protected updateValue() {
this.node = this.context.row.node;
if (this.node && this.node.entry) {
if (this.node?.entry) {
const displayText = this.context.row.getValue(this.key);
this.displayText$.next(displayText || this.node.entry.id);
}

View File

@ -15,71 +15,62 @@
* limitations under the License.
*/
import {
Component,
ChangeDetectionStrategy,
ViewEncapsulation,
OnInit,
Input
} from '@angular/core';
import { Component, ChangeDetectionStrategy, ViewEncapsulation, OnInit, Input } from '@angular/core';
import { NodeEntry } from '@alfresco/js-api';
import { ShareDataRow } from '../../data/share-data-row.model';
@Component({
selector: 'adf-trashcan-name-column',
template: `
<ng-container *ngIf="!isLibrary">
<span class="adf-datatable-cell-value" title="{{ node | adfNodeNameTooltip }}">{{ displayText }}</span>
</ng-container>
<ng-container *ngIf="isLibrary">
<span class="adf-datatable-cell-value" title="{{ displayTooltip }}">{{ displayText }}</span>
</ng-container>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: { class: 'adf-datatable-content-cell adf-trashcan-name-column' }
selector: 'adf-trashcan-name-column',
template: `
<ng-container *ngIf="!isLibrary">
<span class="adf-datatable-cell-value" title="{{ node | adfNodeNameTooltip }}">{{ displayText }}</span>
</ng-container>
<ng-container *ngIf="isLibrary">
<span class="adf-datatable-cell-value" title="{{ displayTooltip }}">{{ displayText }}</span>
</ng-container>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: { class: 'adf-datatable-content-cell adf-trashcan-name-column' }
})
export class TrashcanNameColumnComponent implements OnInit {
@Input()
context: any;
@Input()
context: any;
isLibrary = false;
displayText: string;
displayTooltip: string;
node: NodeEntry;
isLibrary = false;
displayText: string;
displayTooltip: string;
node: NodeEntry;
ngOnInit() {
this.node = this.context.row.node;
const rows: Array<ShareDataRow> = this.context.data.rows || [];
ngOnInit() {
this.node = this.context.row.node;
const rows: Array<ShareDataRow> = this.context.data.rows || [];
if (this.node && this.node.entry) {
this.isLibrary = this.node.entry.nodeType === 'st:site';
if (this.node?.entry) {
this.isLibrary = this.node.entry.nodeType === 'st:site';
if (this.isLibrary) {
const { properties } = this.node.entry;
if (this.isLibrary) {
const { properties } = this.node.entry;
this.displayText = this.makeLibraryTitle(this.node.entry, rows);
this.displayTooltip =
properties['cm:description'] || properties['cm:title'];
} else {
this.displayText = this.node.entry.name || this.node.entry.id;
}
}
}
makeLibraryTitle(library: any, rows: Array<ShareDataRow>): string {
const entries = rows.map((r: ShareDataRow) => r.node.entry);
const { id } = library;
const title = library.properties['cm:title'];
let isDuplicate = false;
if (entries) {
isDuplicate = entries.some((entry: any) => entry.id !== id && entry.properties['cm:title'] === title);
this.displayText = this.makeLibraryTitle(this.node.entry, rows);
this.displayTooltip = properties['cm:description'] || properties['cm:title'];
} else {
this.displayText = this.node.entry.name || this.node.entry.id;
}
}
}
return isDuplicate
? `${library.properties['cm:title']} (${library.name})`
: `${library.properties['cm:title']}`;
}
makeLibraryTitle(library: any, rows: Array<ShareDataRow>): string {
const entries = rows.map((r: ShareDataRow) => r.node.entry);
const { id } = library;
const title = library.properties['cm:title'];
let isDuplicate = false;
if (entries) {
isDuplicate = entries.some((entry: any) => entry.id !== id && entry.properties['cm:title'] === title);
}
return isDuplicate ? `${library.properties['cm:title']} (${library.name})` : `${library.properties['cm:title']}`;
}
}

View File

@ -95,11 +95,11 @@ export class ShareDataRow implements DataRow {
}
isFile(nodeEntry: NodeEntry): boolean {
return nodeEntry.entry && nodeEntry.entry.isFile;
return nodeEntry.entry?.isFile;
}
isFolder(nodeEntry: NodeEntry): boolean {
return nodeEntry.entry && nodeEntry.entry.isFolder;
return nodeEntry.entry?.isFolder;
}
cacheValue(key: string, value: any): any {

View File

@ -87,7 +87,7 @@ export class DocumentListService implements DocumentListLoader {
*/
getFolder(folder: string, opts?: any, includeFields: string[] = []): Observable<NodePaging> {
let rootNodeId = ROOT_ID;
if (opts && opts.rootFolderId) {
if (opts?.rootFolderId) {
rootNodeId = opts.rootFolderId;
}

View File

@ -51,7 +51,7 @@ export class SearchPermissionConfigurationService implements SearchConfiguration
private getQuery(searchTerm: string) {
let query: string;
if (this.queryProvider && this.queryProvider.query) {
if (this.queryProvider?.query) {
query = this.queryProvider.query.replace(new RegExp(/\${([^}]+)}/g), searchTerm);
} else {
query = `(email:*${searchTerm}* OR firstName:*${searchTerm}* OR lastName:*${searchTerm}* OR displayName:*${searchTerm}* OR authorityName:*${searchTerm}* OR authorityDisplayName:*${searchTerm}*) AND ANAME:(\"0/APP.DEFAULT\")`;

View File

@ -22,7 +22,6 @@ import { NodeEntry } from '@alfresco/js-api';
name: 'adfNodeNameTooltip'
})
export class NodeNameTooltipPipe implements PipeTransform {
transform(node: NodeEntry): string {
if (node) {
return this.getNodeTooltip(node);
@ -46,18 +45,17 @@ export class NodeNameTooltipPipe implements PipeTransform {
}
private getNodeTooltip(node: NodeEntry): string {
if (!node || !node.entry) {
if (!node?.entry) {
return null;
}
const { entry: { properties, name } } = node;
const lines = [ name ];
const {
entry: { properties, name }
} = node;
const lines = [name];
if (properties) {
const {
'cm:title': title,
'cm:description': description
} = properties;
const { 'cm:title': title, 'cm:description': description } = properties;
if (title && description) {
lines[0] = title;

View File

@ -16,8 +16,19 @@
*/
import { AuthenticationService, ThumbnailService, SearchTextInputComponent } from '@alfresco/adf-core';
import { Component, EventEmitter, Input, OnDestroy, Output,
QueryList, ViewEncapsulation, ViewChild, ViewChildren, TemplateRef, ContentChild } from '@angular/core';
import {
Component,
EventEmitter,
Input,
OnDestroy,
Output,
QueryList,
ViewEncapsulation,
ViewChild,
ViewChildren,
TemplateRef,
ContentChild
} from '@angular/core';
import { NodeEntry } from '@alfresco/js-api';
import { Subject } from 'rxjs';
import { SearchComponent } from './search.component';
@ -32,7 +43,6 @@ import { EmptySearchResultComponent } from './empty-search-result.component';
host: { class: 'adf-search-control' }
})
export class SearchControlComponent implements OnDestroy {
/** Toggles highlighting of the search term in the results. */
@Input()
highlight: boolean = false;
@ -90,15 +100,12 @@ export class SearchControlComponent implements OnDestroy {
emptySearchTemplate: EmptySearchResultComponent;
focusSubject = new Subject<FocusEvent>();
noSearchResultTemplate: TemplateRef <any> = null;
noSearchResultTemplate: TemplateRef<any> = null;
searchTerm: string = '';
private onDestroy$ = new Subject<boolean>();
constructor(
public authService: AuthenticationService,
private thumbnailService: ThumbnailService
) {}
constructor(public authService: AuthenticationService, private thumbnailService: ThumbnailService) {}
isNoSearchTemplatePresent(): boolean {
return !!this.emptySearchTemplate;
@ -126,7 +133,7 @@ export class SearchControlComponent implements OnDestroy {
getMimeType(node: NodeEntry): string {
let mimeType: string;
if (node.entry.content && node.entry.content.mimeType) {
if (node.entry.content?.mimeType) {
mimeType = node.entry.content.mimeType;
}
if (node.entry.isFolder) {
@ -154,7 +161,7 @@ export class SearchControlComponent implements OnDestroy {
}
onSelectFirstResult() {
if ( this.listResultElement && this.listResultElement.length > 0) {
if (this.listResultElement && this.listResultElement.length > 0) {
const firstElement = this.listResultElement.first as MatListItem;
// eslint-disable-next-line no-underscore-dangle
firstElement._getHostElement().focus();
@ -184,7 +191,7 @@ export class SearchControlComponent implements OnDestroy {
}
private isListElement(event: any): boolean {
return event.relatedTarget && event.relatedTarget.children[0] && event.relatedTarget.children[0].className === 'mat-list-item-content';
return event.relatedTarget?.children[0] && event.relatedTarget.children[0].className === 'mat-list-item-content';
}
private getNextElementSibling(node: Element): Element {

View File

@ -18,12 +18,7 @@
import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms';
import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE } from '@angular/material/core';
import {
MOMENT_DATE_FORMATS,
MomentDateAdapter,
UserPreferencesService,
UserPreferenceValues
} from '@alfresco/adf-core';
import { MOMENT_DATE_FORMATS, MomentDateAdapter, UserPreferencesService, UserPreferenceValues } from '@alfresco/adf-core';
import { SearchWidget } from '../../models/search-widget.interface';
import { SearchWidgetSettings } from '../../models/search-widget-settings.interface';
@ -54,7 +49,6 @@ const DEFAULT_FORMAT_DATE: string = 'DD/MM/YYYY';
host: { class: 'adf-search-date-range' }
})
export class SearchDateRangeComponent implements SearchWidget, OnInit, OnDestroy {
from: UntypedFormControl;
to: UntypedFormControl;
@ -74,23 +68,28 @@ export class SearchDateRangeComponent implements SearchWidget, OnInit, OnDestroy
private onDestroy$ = new Subject<boolean>();
constructor(private dateAdapter: DateAdapter<Moment>,
private userPreferencesService: UserPreferencesService) {
}
constructor(private dateAdapter: DateAdapter<Moment>, private userPreferencesService: UserPreferencesService) {}
getFromValidationMessage(): string {
return this.from.hasError('invalidOnChange') || this.hasParseError(this.from) ? 'SEARCH.FILTER.VALIDATION.INVALID-DATE' :
this.from.hasError('matDatepickerMax') ? 'SEARCH.FILTER.VALIDATION.BEYOND-MAX-DATE' :
this.from.hasError('required') ? 'SEARCH.FILTER.VALIDATION.REQUIRED-VALUE' :
'';
return this.from.hasError('invalidOnChange') || this.hasParseError(this.from)
? 'SEARCH.FILTER.VALIDATION.INVALID-DATE'
: this.from.hasError('matDatepickerMax')
? 'SEARCH.FILTER.VALIDATION.BEYOND-MAX-DATE'
: this.from.hasError('required')
? 'SEARCH.FILTER.VALIDATION.REQUIRED-VALUE'
: '';
}
getToValidationMessage(): string {
return this.to.hasError('invalidOnChange') || this.hasParseError(this.to) ? 'SEARCH.FILTER.VALIDATION.INVALID-DATE' :
this.to.hasError('matDatepickerMin') ? 'SEARCH.FILTER.VALIDATION.NO-DAYS' :
this.to.hasError('matDatepickerMax') ? 'SEARCH.FILTER.VALIDATION.BEYOND-MAX-DATE' :
this.to.hasError('required') ? 'SEARCH.FILTER.VALIDATION.REQUIRED-VALUE' :
'';
return this.to.hasError('invalidOnChange') || this.hasParseError(this.to)
? 'SEARCH.FILTER.VALIDATION.INVALID-DATE'
: this.to.hasError('matDatepickerMin')
? 'SEARCH.FILTER.VALIDATION.NO-DAYS'
: this.to.hasError('matDatepickerMax')
? 'SEARCH.FILTER.VALIDATION.BEYOND-MAX-DATE'
: this.to.hasError('required')
? 'SEARCH.FILTER.VALIDATION.REQUIRED-VALUE'
: '';
}
ngOnInit() {
@ -102,13 +101,11 @@ export class SearchDateRangeComponent implements SearchWidget, OnInit, OnDestroy
this.userPreferencesService
.select(UserPreferenceValues.Locale)
.pipe(takeUntil(this.onDestroy$))
.subscribe(locale => this.setLocale(locale));
.subscribe((locale) => this.setLocale(locale));
const validators = Validators.compose([
Validators.required
]);
const validators = Validators.compose([Validators.required]);
if (this.settings && this.settings.maxDate) {
if (this.settings?.maxDate) {
if (this.settings.maxDate === 'today') {
this.maxDate = this.dateAdapter.today().endOf('day');
} else {
@ -174,7 +171,12 @@ export class SearchDateRangeComponent implements SearchWidget, OnInit, OnDestroy
if (this.form.invalid || this.form.pristine) {
this.displayValue$.next('');
} else {
this.displayValue$.next(`${this.dateAdapter.format(this.form.value.from, this.datePickerFormat)} - ${this.dateAdapter.format(this.form.value.to, this.datePickerFormat)}`);
this.displayValue$.next(
`${this.dateAdapter.format(this.form.value.from, this.datePickerFormat)} - ${this.dateAdapter.format(
this.form.value.to,
this.datePickerFormat
)}`
);
}
}
@ -219,10 +221,9 @@ export class SearchDateRangeComponent implements SearchWidget, OnInit, OnDestroy
}
onChangedHandler(event: any, formControl: UntypedFormControl) {
const inputValue = event.value;
const formatDate = this.dateAdapter.parse(inputValue, this.datePickerFormat);
if (formatDate && formatDate.isValid()) {
if (formatDate?.isValid()) {
formControl.setValue(formatDate);
} else if (formatDate) {
formControl.setErrors({
@ -247,6 +248,6 @@ export class SearchDateRangeComponent implements SearchWidget, OnInit, OnDestroy
}
setFromMaxDate() {
this.fromMaxDate = (!this.to.value || this.maxDate && (moment(this.maxDate).isBefore(this.to.value))) ? this.maxDate : moment(this.to.value);
this.fromMaxDate = !this.to.value || (this.maxDate && moment(this.maxDate).isBefore(this.to.value)) ? this.maxDate : moment(this.to.value);
}
}

View File

@ -42,14 +42,11 @@ const DEFAULT_DATETIME_FORMAT: string = 'DD/MM/YYYY HH:mm';
selector: 'adf-search-datetime-range',
templateUrl: './search-datetime-range.component.html',
styleUrls: ['./search-datetime-range.component.scss'],
providers: [
{ provide: MAT_DATETIME_FORMATS, useValue: MAT_MOMENT_DATETIME_FORMATS }
],
providers: [{ provide: MAT_DATETIME_FORMATS, useValue: MAT_MOMENT_DATETIME_FORMATS }],
encapsulation: ViewEncapsulation.None,
host: { class: 'adf-search-date-range' }
})
export class SearchDatetimeRangeComponent implements SearchWidget, OnInit, OnDestroy {
from: UntypedFormControl;
to: UntypedFormControl;
@ -69,23 +66,28 @@ export class SearchDatetimeRangeComponent implements SearchWidget, OnInit, OnDes
private onDestroy$ = new Subject<boolean>();
constructor(private dateAdapter: DatetimeAdapter<Moment>,
private userPreferencesService: UserPreferencesService) {
}
constructor(private dateAdapter: DatetimeAdapter<Moment>, private userPreferencesService: UserPreferencesService) {}
getFromValidationMessage(): string {
return this.from.hasError('invalidOnChange') || this.hasParseError(this.from) ? 'SEARCH.FILTER.VALIDATION.INVALID-DATETIME' :
this.from.hasError('matDatepickerMax') ? 'SEARCH.FILTER.VALIDATION.BEYOND-MAX-DATETIME' :
this.from.hasError('required') ? 'SEARCH.FILTER.VALIDATION.REQUIRED-VALUE' :
'';
return this.from.hasError('invalidOnChange') || this.hasParseError(this.from)
? 'SEARCH.FILTER.VALIDATION.INVALID-DATETIME'
: this.from.hasError('matDatepickerMax')
? 'SEARCH.FILTER.VALIDATION.BEYOND-MAX-DATETIME'
: this.from.hasError('required')
? 'SEARCH.FILTER.VALIDATION.REQUIRED-VALUE'
: '';
}
getToValidationMessage(): string {
return this.to.hasError('invalidOnChange') || this.hasParseError(this.to) ? 'SEARCH.FILTER.VALIDATION.INVALID-DATETIME' :
this.to.hasError('matDatepickerMin') ? 'SEARCH.FILTER.VALIDATION.NO-DAYS' :
this.to.hasError('matDatepickerMax') ? 'SEARCH.FILTER.VALIDATION.BEYOND-MAX-DATETIME' :
this.to.hasError('required') ? 'SEARCH.FILTER.VALIDATION.REQUIRED-VALUE' :
'';
return this.to.hasError('invalidOnChange') || this.hasParseError(this.to)
? 'SEARCH.FILTER.VALIDATION.INVALID-DATETIME'
: this.to.hasError('matDatepickerMin')
? 'SEARCH.FILTER.VALIDATION.NO-DAYS'
: this.to.hasError('matDatepickerMax')
? 'SEARCH.FILTER.VALIDATION.BEYOND-MAX-DATETIME'
: this.to.hasError('required')
? 'SEARCH.FILTER.VALIDATION.REQUIRED-VALUE'
: '';
}
ngOnInit() {
@ -94,13 +96,11 @@ export class SearchDatetimeRangeComponent implements SearchWidget, OnInit, OnDes
this.userPreferencesService
.select(UserPreferenceValues.Locale)
.pipe(takeUntil(this.onDestroy$))
.subscribe(locale => this.setLocale(locale));
.subscribe((locale) => this.setLocale(locale));
const validators = Validators.compose([
Validators.required
]);
const validators = Validators.compose([Validators.required]);
if (this.settings && this.settings.maxDatetime) {
if (this.settings?.maxDatetime) {
this.maxDatetime = moment(this.settings.maxDatetime);
}
@ -161,7 +161,12 @@ export class SearchDatetimeRangeComponent implements SearchWidget, OnInit, OnDes
if (this.form.invalid || this.form.pristine) {
this.displayValue$.next('');
} else {
this.displayValue$.next(`${this.dateAdapter.format(this.form.value.from, this.datetimePickerFormat)} - ${this.dateAdapter.format(this.form.value.to, this.datetimePickerFormat)}`);
this.displayValue$.next(
`${this.dateAdapter.format(this.form.value.from, this.datetimePickerFormat)} - ${this.dateAdapter.format(
this.form.value.to,
this.datetimePickerFormat
)}`
);
}
}
@ -207,10 +212,9 @@ export class SearchDatetimeRangeComponent implements SearchWidget, OnInit, OnDes
}
onChangedHandler(event: any, formControl: UntypedFormControl) {
const inputValue = event.value;
const formatDate = this.dateAdapter.parse(inputValue, this.datetimePickerFormat);
if (formatDate && formatDate.isValid()) {
if (formatDate?.isValid()) {
formControl.setValue(formatDate);
} else if (formatDate) {
formControl.setErrors({
@ -235,6 +239,7 @@ export class SearchDatetimeRangeComponent implements SearchWidget, OnInit, OnDes
}
setFromMaxDatetime() {
this.fromMaxDatetime = (!this.to.value || this.maxDatetime && (moment(this.maxDatetime).isBefore(this.to.value))) ? this.maxDatetime : moment(this.to.value);
this.fromMaxDatetime =
!this.to.value || (this.maxDatetime && moment(this.maxDatetime).isBefore(this.to.value)) ? this.maxDatetime : moment(this.to.value);
}
}

View File

@ -33,19 +33,19 @@ import { Subject } from 'rxjs';
encapsulation: ViewEncapsulation.None
})
export class SearchFacetFieldComponent implements FacetWidget {
@Input()
field!: FacetField;
displayValue$: Subject<string> = new Subject<string>();
constructor(@Inject(SEARCH_QUERY_SERVICE_TOKEN) public queryBuilder: SearchQueryBuilderService,
private searchFacetFiltersService: SearchFacetFiltersService,
private translationService: TranslationService) {
}
constructor(
@Inject(SEARCH_QUERY_SERVICE_TOKEN) public queryBuilder: SearchQueryBuilderService,
private searchFacetFiltersService: SearchFacetFiltersService,
private translationService: TranslationService
) {}
get canUpdateOnChange() {
return this.field.settings?.allowUpdateOnChange ?? true;
return this.field.settings?.allowUpdateOnChange ?? true;
}
onToggleBucket(event: MatCheckboxChange, field: FacetField, bucket: FacetFieldBucket) {
@ -83,14 +83,14 @@ export class SearchFacetFieldComponent implements FacetWidget {
}
canResetSelectedBuckets(field: FacetField): boolean {
if (field && field.buckets) {
if (field?.buckets) {
return field.buckets.items.some((bucket) => bucket.checked);
}
return false;
}
resetSelectedBuckets(field: FacetField) {
if (field && field.buckets) {
if (field?.buckets) {
for (const bucket of field.buckets.items) {
bucket.checked = false;
this.queryBuilder.removeUserFacetBucket(field.field, bucket);
@ -110,7 +110,8 @@ export class SearchFacetFieldComponent implements FacetWidget {
if (!this.field.buckets?.items) {
this.displayValue$.next('');
} else {
const displayValue = this.field.buckets?.items?.filter((item) => item.checked)
const displayValue = this.field.buckets?.items
?.filter((item) => item.checked)
.map((item) => this.translationService.instant(item.display || item.label))
.join(', ');
this.displayValue$.next(displayValue);

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Component, Inject, Input, ViewEncapsulation } from '@angular/core';
import { Component, Inject, Input, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { SearchFacetFiltersService } from '../../services/search-facet-filters.service';
import { SEARCH_QUERY_SERVICE_TOKEN } from '../../search-query-service.token';
import { SearchQueryBuilderService } from '../../services/search-query-builder.service';
@ -28,7 +28,7 @@ import { takeUntil } from 'rxjs/operators';
styleUrls: ['./search-filter-chips.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class SearchFilterChipsComponent {
export class SearchFilterChipsComponent implements OnInit, OnDestroy {
private onDestroy$ = new Subject<void>();
/** Toggles whether to show or not the context facet filters. */
@ -40,12 +40,14 @@ export class SearchFilterChipsComponent {
constructor(
@Inject(SEARCH_QUERY_SERVICE_TOKEN)
public queryBuilder: SearchQueryBuilderService,
public facetFiltersService: SearchFacetFiltersService) {}
public facetFiltersService: SearchFacetFiltersService
) {}
ngOnInit() {
this.queryBuilder.executed.asObservable()
.pipe(takeUntil(this.onDestroy$))
.subscribe(() => this.facetChipTabbedId = 'search-fact-chip-tabbed-' + this.facetFiltersService.tabbedFacet?.fields.join('-'));
this.queryBuilder.executed
.asObservable()
.pipe(takeUntil(this.onDestroy$))
.subscribe(() => (this.facetChipTabbedId = 'search-fact-chip-tabbed-' + this.facetFiltersService.tabbedFacet?.fields.join('-')));
}
ngOnDestroy() {

View File

@ -15,18 +15,7 @@
* limitations under the License.
*/
import {
Component,
Input,
Output,
OnInit,
EventEmitter,
ViewEncapsulation,
ViewChild,
Inject,
OnDestroy,
ElementRef
} from '@angular/core';
import { Component, Input, Output, OnInit, EventEmitter, ViewEncapsulation, ViewChild, Inject, OnDestroy, ElementRef } from '@angular/core';
import { ConfigurableFocusTrapFactory, ConfigurableFocusTrap } from '@angular/cdk/a11y';
import { DataColumn, TranslationService } from '@alfresco/adf-core';
import { SearchWidgetContainerComponent } from '../search-widget-container/search-widget-container.component';
@ -44,7 +33,6 @@ import { FilterSearch } from '../../models/filter-search.interface';
encapsulation: ViewEncapsulation.None
})
export class SearchFilterContainerComponent implements OnInit, OnDestroy {
/** The column the filter will be applied on. */
@Input()
col: DataColumn;
@ -69,14 +57,15 @@ export class SearchFilterContainerComponent implements OnInit, OnDestroy {
private onDestroy$ = new Subject<boolean>();
constructor(@Inject(SEARCH_QUERY_SERVICE_TOKEN) private searchFilterQueryBuilder: SearchHeaderQueryBuilderService,
private translationService: TranslationService,
private focusTrapFactory: ConfigurableFocusTrapFactory) {
}
constructor(
@Inject(SEARCH_QUERY_SERVICE_TOKEN) private searchFilterQueryBuilder: SearchHeaderQueryBuilderService,
private translationService: TranslationService,
private focusTrapFactory: ConfigurableFocusTrapFactory
) {}
ngOnInit() {
this.category = this.searchFilterQueryBuilder.getCategoryForColumn(this.col.key);
this.initialValue = this.value && this.value[this.col.key] ? this.value[this.col.key] : undefined;
this.initialValue = this.value?.[this.col.key] ? this.value[this.col.key] : undefined;
}
ngOnDestroy() {

View File

@ -30,7 +30,6 @@ import { SearchFacetFiltersService } from '../../services/search-facet-filters.s
host: { class: 'adf-search-filter' }
})
export class SearchFilterComponent {
/** Toggles whether to show or not the context facet filters. */
@Input()
showContextFacets: boolean = true;
@ -41,16 +40,18 @@ export class SearchFilterComponent {
};
displayResetButton: boolean;
constructor(@Inject(SEARCH_QUERY_SERVICE_TOKEN) public queryBuilder: SearchQueryBuilderService,
public facetFiltersService: SearchFacetFiltersService) {
if (queryBuilder.config && queryBuilder.config.facetQueries) {
constructor(
@Inject(SEARCH_QUERY_SERVICE_TOKEN) public queryBuilder: SearchQueryBuilderService,
public facetFiltersService: SearchFacetFiltersService
) {
if (queryBuilder.config?.facetQueries) {
this.facetQueriesLabel = queryBuilder.config.facetQueries.label || 'Facet Queries';
this.facetExpanded['query'] = queryBuilder.config.facetQueries.expanded;
}
if (queryBuilder.config && queryBuilder.config.facetFields) {
if (queryBuilder.config?.facetFields) {
this.facetExpanded['field'] = queryBuilder.config.facetFields.expanded;
}
if (queryBuilder.config && queryBuilder.config.facetIntervals) {
if (queryBuilder.config?.facetIntervals) {
this.facetExpanded['interval'] = queryBuilder.config.facetIntervals.expanded;
}
this.displayResetButton = this.queryBuilder.config && !!this.queryBuilder.config.resetButton;

View File

@ -38,7 +38,6 @@ import { Observable } from 'rxjs';
template: '<div #content></div>'
})
export class SearchWidgetContainerComponent implements OnInit, OnDestroy, OnChanges {
@ViewChild('content', { read: ViewContainerRef, static: true })
content: ViewContainerRef;
@ -62,8 +61,8 @@ export class SearchWidgetContainerComponent implements OnInit, OnDestroy, OnChan
constructor(
private searchFilterService: SearchFilterService,
@Inject(SEARCH_QUERY_SERVICE_TOKEN) private queryBuilder: BaseQueryBuilderService,
private componentFactoryResolver: ComponentFactoryResolver) {
}
private componentFactoryResolver: ComponentFactoryResolver
) {}
ngOnInit() {
const componentType = this.searchFilterService.widgets[this.selector];
@ -85,9 +84,9 @@ export class SearchWidgetContainerComponent implements OnInit, OnDestroy, OnChan
}
private setupWidget(ref: ComponentRef<any>) {
if (ref && ref.instance) {
if (ref?.instance) {
ref.instance.id = this.id;
ref.instance.settings = {...this.settings};
ref.instance.settings = { ...this.settings };
ref.instance.context = this.queryBuilder;
if (this.value) {
ref.instance.isActive = true;
@ -128,7 +127,7 @@ export class SearchWidgetContainerComponent implements OnInit, OnDestroy, OnChan
}
resetInnerWidget() {
if (this.componentRef && this.componentRef.instance) {
if (this.componentRef?.instance) {
this.componentRef.instance.reset();
}
}

View File

@ -28,7 +28,8 @@ import {
TemplateRef,
ViewChild,
ViewEncapsulation,
OnDestroy
OnDestroy,
SimpleChanges
} from '@angular/core';
import { NodePaging, ResultSetPaging } from '@alfresco/js-api';
import { Subject } from 'rxjs';
@ -45,7 +46,6 @@ import { SearchComponentInterface } from '@alfresco/adf-core';
host: { class: 'adf-search' }
})
export class SearchComponent implements SearchComponentInterface, AfterContentInit, OnChanges, OnDestroy {
@ViewChild('panel', { static: true })
panel: ElementRef;
@ -74,8 +74,8 @@ export class SearchComponent implements SearchComponentInterface, AfterContentIn
// eslint-disable-next-line @angular-eslint/no-input-rename
@Input('class')
set classList(classList: string) {
if (classList && classList.length) {
classList.split(' ').forEach((className) => this._classList[className.trim()] = true);
if (classList?.length) {
classList.split(' ').forEach((className) => (this._classList[className.trim()] = true));
this._elementRef.nativeElement.className = '';
}
}
@ -104,31 +104,23 @@ export class SearchComponent implements SearchComponentInterface, AfterContentIn
_classList: { [key: string]: boolean } = {};
private onDestroy$ = new Subject<boolean>();
constructor(private searchService: SearchService,
private _elementRef: ElementRef) {
this.keyPressedStream
.pipe(
debounceTime(200),
takeUntil(this.onDestroy$)
)
.subscribe(searchedWord => {
this.loadSearchResults(searchedWord);
});
constructor(private searchService: SearchService, private _elementRef: ElementRef) {
this.keyPressedStream.pipe(debounceTime(200), takeUntil(this.onDestroy$)).subscribe((searchedWord) => {
this.loadSearchResults(searchedWord);
});
searchService.dataLoaded
.pipe(takeUntil(this.onDestroy$))
.subscribe(
nodePaging => this.onSearchDataLoaded(nodePaging),
error => this.onSearchDataError(error)
);
searchService.dataLoaded.pipe(takeUntil(this.onDestroy$)).subscribe(
(nodePaging) => this.onSearchDataLoaded(nodePaging),
(error) => this.onSearchDataError(error)
);
}
ngAfterContentInit() {
this.setVisibility();
}
ngOnChanges(changes) {
if (changes.searchTerm && changes.searchTerm.currentValue) {
ngOnChanges(changes: SimpleChanges) {
if (changes.searchTerm?.currentValue) {
this.loadSearchResults(changes.searchTerm.currentValue);
}
}
@ -174,8 +166,8 @@ export class SearchComponent implements SearchComponentInterface, AfterContentIn
}
}
onSearchDataError(error) {
if (error && error.status !== 400) {
onSearchDataError(error: { status: number }) {
if (error?.status !== 400) {
this.results = null;
this.error.emit(error);
}

View File

@ -19,10 +19,8 @@ import { ErrorStateMatcher } from '@angular/material/core';
import { UntypedFormControl, FormGroupDirective, NgForm } from '@angular/forms';
export class LiveErrorStateMatcher implements ErrorStateMatcher {
isErrorState(control: UntypedFormControl | null, form: FormGroupDirective | NgForm | null): boolean {
const isSubmitted = form && form.submitted;
return !!(control && control.invalid && (control.dirty || control.touched || (!control.pristine && isSubmitted)));
const isSubmitted = form?.submitted;
return !!(control?.invalid && (control.dirty || control.touched || (!control.pristine && isSubmitted)));
}
}

View File

@ -90,7 +90,7 @@ export abstract class BaseQueryBuilderService {
// TODO: to be supported in future iterations
ranges: { [id: string]: SearchRange } = {};
constructor(protected appConfig: AppConfigService, protected alfrescoApiService: AlfrescoApiService) {
protected constructor(protected appConfig: AppConfigService, protected alfrescoApiService: AlfrescoApiService) {
this.resetToDefaults();
}
@ -374,7 +374,7 @@ export abstract class BaseQueryBuilderService {
* @returns The primary sorting definition
*/
getPrimarySorting(): SearchSortingDefinition {
if (this.sorting && this.sorting.length > 0) {
if (this.sorting?.length > 0) {
return this.sorting[0];
}
return null;
@ -386,10 +386,7 @@ export abstract class BaseQueryBuilderService {
* @returns Pre-configured sorting options
*/
getSortingOptions(): SearchSortingDefinition[] {
if (this.config && this.config.sorting) {
return this.config.sorting.options || [];
}
return [];
return this.config?.sorting?.options || [];
}
/**
@ -398,7 +395,7 @@ export abstract class BaseQueryBuilderService {
* @param query Target query
* @returns Query group
*/
getQueryGroup(query) {
getQueryGroup(query: FacetQuery): string {
return query.group || this.config.facetQueries.label || 'Facet Queries';
}
@ -408,10 +405,7 @@ export abstract class BaseQueryBuilderService {
* @returns True if defined, false otherwise
*/
get hasFacetQueries(): boolean {
if (this.config && this.config.facetQueries && this.config.facetQueries.queries && this.config.facetQueries.queries.length > 0) {
return true;
}
return false;
return this.config?.facetQueries?.queries?.length > 0;
}
/**
@ -420,11 +414,11 @@ export abstract class BaseQueryBuilderService {
* @returns True if defined, false otherwise
*/
get hasFacetIntervals(): boolean {
return this.config && this.config.facetIntervals && this.config.facetIntervals.intervals && this.config.facetIntervals.intervals.length > 0;
return this.config?.facetIntervals?.intervals?.length > 0;
}
get hasFacetHighlight(): boolean {
return !!(this.config && this.config.highlight);
return !!this.config?.highlight;
}
protected get sort(): RequestSortDefinitionInner[] {
@ -515,9 +509,9 @@ export abstract class BaseQueryBuilderService {
}
protected get facetFields(): RequestFacetFields {
const facetFields = this.config.facetFields && this.config.facetFields.fields;
const facetFields = this.config.facetFields?.fields;
if (facetFields && facetFields.length > 0) {
if (facetFields?.length > 0) {
return {
facets: facetFields.map(
(facet) =>

View File

@ -40,7 +40,6 @@ const DEFAULT_PAGE_SIZE: number = 5;
providedIn: 'root'
})
export class SearchFacetFiltersService implements OnDestroy {
/** All facet field items to be displayed in the component. These are updated according to the response.
* When a new search is performed, the already existing items are updated with the new bucket count values and
* the newly received items are added to the responseFacets.
@ -55,32 +54,27 @@ export class SearchFacetFiltersService implements OnDestroy {
private readonly facetQueriesPageSize = DEFAULT_PAGE_SIZE;
private readonly onDestroy$ = new Subject<boolean>();
constructor(@Inject(SEARCH_QUERY_SERVICE_TOKEN) public queryBuilder: SearchQueryBuilderService,
private searchService: SearchService,
private translationService: TranslationService,
private categoryService: CategoryService
constructor(
@Inject(SEARCH_QUERY_SERVICE_TOKEN) public queryBuilder: SearchQueryBuilderService,
private searchService: SearchService,
private translationService: TranslationService,
private categoryService: CategoryService
) {
if (queryBuilder.config && queryBuilder.config.facetQueries) {
if (queryBuilder.config?.facetQueries) {
this.facetQueriesPageSize = queryBuilder.config.facetQueries.pageSize || DEFAULT_PAGE_SIZE;
}
this.queryBuilder.configUpdated
.pipe(takeUntil(this.onDestroy$))
.subscribe(() => {
this.selectedBuckets = [];
this.responseFacets = null;
});
this.queryBuilder.configUpdated.pipe(takeUntil(this.onDestroy$)).subscribe(() => {
this.selectedBuckets = [];
this.responseFacets = null;
});
this.queryBuilder.updated
.pipe(takeUntil(this.onDestroy$))
.subscribe((query) => this.queryBuilder.execute(query));
this.queryBuilder.updated.pipe(takeUntil(this.onDestroy$)).subscribe((query) => this.queryBuilder.execute(query));
this.queryBuilder.executed
.pipe(takeUntil(this.onDestroy$))
.subscribe((resultSetPaging: ResultSetPaging) => {
this.onDataLoaded(resultSetPaging);
this.searchService.dataLoaded.next(resultSetPaging);
});
this.queryBuilder.executed.pipe(takeUntil(this.onDestroy$)).subscribe((resultSetPaging: ResultSetPaging) => {
this.onDataLoaded(resultSetPaging);
this.searchService.dataLoaded.next(resultSetPaging);
});
}
onDataLoaded(data: any) {
@ -104,17 +98,20 @@ export class SearchFacetFiltersService implements OnDestroy {
private parseFacetItems(context: ResultSetContext, configFacetFields: FacetField[], itemType: string) {
configFacetFields.forEach((facetField) => {
const responseField = this.findFacet(context, itemType, facetField.label);
const responseBuckets = this.getResponseBuckets(responseField, facetField)
.filter(this.getFilterByMinCount(facetField.mincount));
this.sortFacetBuckets(responseBuckets, facetField.settings?.bucketSortBy, facetField.settings?.bucketSortDirection ?? FacetBucketSortDirection.ASCENDING);
const responseBuckets = this.getResponseBuckets(responseField, facetField).filter(this.getFilterByMinCount(facetField.mincount));
this.sortFacetBuckets(
responseBuckets,
facetField.settings?.bucketSortBy,
facetField.settings?.bucketSortDirection ?? FacetBucketSortDirection.ASCENDING
);
const alreadyExistingField = this.findResponseFacet(itemType, facetField.label);
if (facetField.field === 'cm:categories'){
if (facetField.field === 'cm:categories') {
this.loadCategoryNames(responseBuckets);
}
if (alreadyExistingField) {
const alreadyExistingBuckets = alreadyExistingField.buckets && alreadyExistingField.buckets.items || [];
const alreadyExistingBuckets = alreadyExistingField.buckets?.items || [];
this.updateExistingBuckets(responseField, responseBuckets, alreadyExistingField, alreadyExistingBuckets);
} else if (responseField) {
@ -166,18 +163,18 @@ export class SearchFacetFiltersService implements OnDestroy {
}
private parseFacetFields(context: ResultSetContext) {
const configFacetFields = this.queryBuilder.config.facetFields && this.queryBuilder.config.facetFields.fields || [];
const configFacetFields = this.queryBuilder.config.facetFields?.fields || [];
this.parseFacetItems(context, configFacetFields, 'field');
}
private parseFacetIntervals(context: ResultSetContext) {
const configFacetIntervals = this.queryBuilder.config.facetIntervals && this.queryBuilder.config.facetIntervals.intervals || [];
const configFacetIntervals = this.queryBuilder.config.facetIntervals?.intervals || [];
this.parseFacetItems(context, configFacetIntervals, 'interval');
}
private parseFacetQueries(context: ResultSetContext) {
const facetQuerySetting = this.queryBuilder.config.facetQueries?.settings || {};
const configFacetQueries = this.queryBuilder.config.facetQueries && this.queryBuilder.config.facetQueries.queries || [];
const configFacetQueries = this.queryBuilder.config.facetQueries?.queries || [];
const configGroups = configFacetQueries.reduce((acc, query) => {
const group = this.queryBuilder.getQueryGroup(query);
if (acc[group]) {
@ -188,18 +185,21 @@ export class SearchFacetFiltersService implements OnDestroy {
return acc;
}, []);
const mincount = this.queryBuilder.config.facetQueries && this.queryBuilder.config.facetQueries.mincount;
const mincountFilter = this.getFilterByMinCount(mincount);
const minCount = this.queryBuilder.config.facetQueries?.mincount;
const minCountFilter = this.getFilterByMinCount(minCount);
Object.keys(configGroups).forEach((group) => {
const responseField = this.findFacet(context, 'query', group);
const responseBuckets = this.getResponseQueryBuckets(responseField, configGroups[group])
.filter(mincountFilter);
this.sortFacetBuckets(responseBuckets, facetQuerySetting?.bucketSortBy, facetQuerySetting.bucketSortDirection ?? FacetBucketSortDirection.ASCENDING);
const responseBuckets = this.getResponseQueryBuckets(responseField, configGroups[group]).filter(minCountFilter);
this.sortFacetBuckets(
responseBuckets,
facetQuerySetting?.bucketSortBy,
facetQuerySetting.bucketSortDirection ?? FacetBucketSortDirection.ASCENDING
);
const alreadyExistingField = this.findResponseFacet('query', group);
if (alreadyExistingField) {
const alreadyExistingBuckets = alreadyExistingField.buckets && alreadyExistingField.buckets.items || [];
const alreadyExistingBuckets = alreadyExistingField.buckets?.items || [];
this.updateExistingBuckets(responseField, responseBuckets, alreadyExistingField, alreadyExistingBuckets);
} else if (responseField) {
@ -229,8 +229,7 @@ export class SearchFacetFiltersService implements OnDestroy {
}
private getResponseBuckets(responseField: GenericFacetResponse, configField: FacetField): FacetFieldBucket[] {
return ((responseField && responseField.buckets) || []).map((respBucket) => {
return (responseField?.buckets || []).map((respBucket) => {
respBucket['count'] = this.getCountValue(respBucket);
respBucket.filterQuery = respBucket.filterQuery || this.getCorrespondingFilterQuery(configField, respBucket.label);
return {
@ -244,8 +243,7 @@ export class SearchFacetFiltersService implements OnDestroy {
private getResponseQueryBuckets(responseField: GenericFacetResponse, configGroup: any): FacetFieldBucket[] {
return (configGroup || []).map((query) => {
const respBucket = ((responseField && responseField.buckets) || [])
.find((bucket) => bucket.label === query.label) || {};
const respBucket = (responseField?.buckets || []).find((bucket) => bucket.label === query.label) || {};
respBucket['count'] = this.getCountValue(respBucket);
return {
@ -261,7 +259,9 @@ export class SearchFacetFiltersService implements OnDestroy {
switch (sortBy) {
case FacetBucketSortBy.LABEL:
buckets.sort((bucket1, bucket2) =>
sortDirection === FacetBucketSortDirection.ASCENDING ? bucket1.label.localeCompare(bucket2.label) : bucket2.label.localeCompare(bucket1.label)
sortDirection === FacetBucketSortDirection.ASCENDING
? bucket1.label.localeCompare(bucket2.label)
: bucket2.label.localeCompare(bucket1.label)
);
break;
case FacetBucketSortBy.COUNT:
@ -282,28 +282,26 @@ export class SearchFacetFiltersService implements OnDestroy {
return bucket.count === null ? '' : `(${bucket.count})`;
}
private getFilterByMinCount(mincountInput: number) {
return (bucket) => {
let mincount = mincountInput;
if (mincount === undefined) {
mincount = 1;
private getFilterByMinCount =
(minCountInput: number) =>
(bucket: FacetFieldBucket): boolean => {
let minCount = minCountInput;
if (minCount === undefined) {
minCount = 1;
}
return bucket.count >= mincount;
return bucket.count >= minCount;
};
}
private getCorrespondingFilterQuery(configFacetItem: FacetField, bucketLabel: string): string {
let filterQuery = null;
if (configFacetItem.field && bucketLabel) {
if (configFacetItem.sets) {
const configSet = configFacetItem.sets.find((set) => bucketLabel === set.label);
if (configSet) {
filterQuery = this.buildIntervalQuery(configFacetItem.field, configSet);
}
} else {
filterQuery = `${configFacetItem.field}:"${bucketLabel}"`;
}
@ -315,8 +313,8 @@ export class SearchFacetFiltersService implements OnDestroy {
private buildIntervalQuery(fieldName: string, interval: any): string {
const start = interval.start;
const end = interval.end;
const startLimit = (interval.startInclusive === undefined || interval.startInclusive === true) ? '[' : '<';
const endLimit = (interval.endInclusive === undefined || interval.endInclusive === true) ? ']' : '>';
const startLimit = interval.startInclusive === undefined || interval.startInclusive === true ? '[' : '<';
const endLimit = interval.endInclusive === undefined || interval.endInclusive === true ? ']' : '>';
return `${fieldName}:${startLimit}"${start}" TO "${end}"${endLimit}`;
}
@ -329,22 +327,27 @@ export class SearchFacetFiltersService implements OnDestroy {
return (this.responseFacets || []).find((response) => response.type === itemType && response.label === fieldLabel);
}
private updateExistingBuckets(responseField, responseBuckets, alreadyExistingField, alreadyExistingBuckets) {
private updateExistingBuckets(
responseField: GenericFacetResponse,
responseBuckets: FacetFieldBucket[],
alreadyExistingField: FacetField,
alreadyExistingBuckets: FacetFieldBucket[]
) {
const bucketsToDelete = [];
alreadyExistingBuckets
.map((bucket) => {
const responseBucket = ((responseField && responseField.buckets) || []).find((respBucket) => respBucket.label === bucket.label);
alreadyExistingBuckets.forEach((bucket) => {
const responseBucket = (responseField?.buckets || []).find((respBucket) => respBucket.label === bucket.label);
if (!responseBucket) {
bucketsToDelete.push(bucket);
}
bucket.count = this.getCountValue(responseBucket);
return bucket;
});
if (!responseBucket) {
bucketsToDelete.push(bucket);
}
bucket.count = this.getCountValue(responseBucket);
return bucket;
});
const hasSelection = this.selectedBuckets
.find((selBuckets) => alreadyExistingField.label === selBuckets.field.label && alreadyExistingField.type === selBuckets.field.type);
const hasSelection = !!this.selectedBuckets.find(
(selBuckets) => alreadyExistingField.label === selBuckets.field.label && alreadyExistingField.type === selBuckets.field.type
);
if (!hasSelection && bucketsToDelete.length) {
bucketsToDelete.forEach((bucket) => {
@ -361,8 +364,9 @@ export class SearchFacetFiltersService implements OnDestroy {
});
}
private getBucketFilterFunction(bucketList) {
return (bucket: FacetFieldBucket): boolean => {
private getBucketFilterFunction =
(bucketList: SearchFilterList<FacetFieldBucket>) =>
(bucket: FacetFieldBucket): boolean => {
if (bucket && bucketList.filterText) {
const pattern = (bucketList.filterText || '').toLowerCase();
const label = (this.translationService.instant(bucket.display) || this.translationService.instant(bucket.label)).toLowerCase();
@ -370,21 +374,19 @@ export class SearchFacetFiltersService implements OnDestroy {
}
return true;
};
}
private loadCategoryNames(bucketList: FacetFieldBucket[]) {
bucketList.forEach((item) => {
const categoryId = item.label.split('/').pop();
this.categoryService.getCategory(categoryId, {include: ['path']})
.pipe(catchError(error => throwError(error)))
.subscribe(
category => {
const nextAfterGeneralPathPartIndex = 3;
const pathSeparator = '/';
const path = category.entry.path.split(pathSeparator).slice(nextAfterGeneralPathPartIndex).join('/');
item.display = path ? `${path}/${category.entry.name}` : category.entry.name;
}
);
this.categoryService
.getCategory(categoryId, { include: ['path'] })
.pipe(catchError((error) => throwError(error)))
.subscribe((category) => {
const nextAfterGeneralPathPartIndex = 3;
const pathSeparator = '/';
const path = category.entry.path.split(pathSeparator).slice(nextAfterGeneralPathPartIndex).join('/');
item.display = path ? `${path}/${category.entry.name}` : category.entry.name;
});
});
}
@ -401,14 +403,15 @@ export class SearchFacetFiltersService implements OnDestroy {
updateSelectedBuckets() {
if (this.responseFacets) {
this.selectedBuckets = [];
let facetFields = this.tabbedFacet === null ? [] : Object.keys(this.tabbedFacet?.fields).map(field => this.tabbedFacet.facets[field]);
let facetFields = this.tabbedFacet === null ? [] : Object.keys(this.tabbedFacet?.fields).map((field) => this.tabbedFacet.facets[field]);
facetFields = [...facetFields, ...this.responseFacets];
for (const facetField of facetFields) {
if (facetField?.buckets) {
this.selectedBuckets.push(
...this.queryBuilder.getUserFacetBuckets(facetField.field)
...this.queryBuilder
.getUserFacetBuckets(facetField.field)
.filter((bucket) => bucket.checked)
.map((bucket) => ({field: facetField, bucket}))
.map((bucket) => ({ field: facetField, bucket }))
);
}
}

View File

@ -19,8 +19,8 @@ import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } fro
import { LogService, InfiniteSelectScrollDirective, AuthenticationService } from '@alfresco/adf-core';
import { SitePaging, SiteEntry, Site } from '@alfresco/js-api';
import { MatSelectChange } from '@angular/material/select';
import {LiveAnnouncer} from '@angular/cdk/a11y';
import {TranslateService} from '@ngx-translate/core';
import { LiveAnnouncer } from '@angular/cdk/a11y';
import { TranslateService } from '@ngx-translate/core';
import { SitesService } from '../common/services/sites.service';
/* eslint-disable no-shadow */
@ -39,7 +39,6 @@ export enum Relations {
host: { class: 'adf-sites-dropdown' }
})
export class DropdownSitesComponent implements OnInit {
/** Hide the "My Files" option. */
@Input()
hideMyFiles: boolean = false;
@ -81,12 +80,13 @@ export class DropdownSitesComponent implements OnInit {
selected: SiteEntry = null;
MY_FILES_VALUE = '-my-';
constructor(private authService: AuthenticationService,
private sitesService: SitesService,
private logService: LogService,
private liveAnnouncer: LiveAnnouncer,
private translateService: TranslateService) {
}
constructor(
private authService: AuthenticationService,
private sitesService: SitesService,
private logService: LogService,
private liveAnnouncer: LiveAnnouncer,
private translateService: TranslateService
) {}
ngOnInit() {
if (!this.siteList) {
@ -102,10 +102,12 @@ export class DropdownSitesComponent implements OnInit {
}
selectedSite(event: MatSelectChange) {
this.liveAnnouncer.announce(this.translateService.instant('ADF_DROPDOWN.SELECTION_ARIA_LABEL', {
placeholder: this.translateService.instant(this.placeholder),
selectedOption: this.translateService.instant(event.value.entry.title)
}));
this.liveAnnouncer.announce(
this.translateService.instant('ADF_DROPDOWN.SELECTION_ARIA_LABEL', {
placeholder: this.translateService.instant(this.placeholder),
selectedOption: this.translateService.instant(event.value.entry.title)
})
);
this.change.emit(event.value);
}
@ -121,8 +123,8 @@ export class DropdownSitesComponent implements OnInit {
extendedOptions.relations = [this.relations];
}
this.sitesService.getSites(extendedOptions).subscribe((sitePaging: SitePaging) => {
this.sitesService.getSites(extendedOptions).subscribe(
(sitePaging: SitePaging) => {
if (!this.siteList) {
this.siteList = this.relations === Relations.Members ? this.filteredResultsByMember(sitePaging) : sitePaging;
@ -137,7 +139,6 @@ export class DropdownSitesComponent implements OnInit {
this.value = this.MY_FILES_VALUE;
}
}
} else {
const siteList: SitePaging = this.relations === Relations.Members ? this.filteredResultsByMember(sitePaging) : sitePaging;
@ -155,7 +156,8 @@ export class DropdownSitesComponent implements OnInit {
},
(error) => {
this.logService.error(error);
});
}
);
}
showLoading(): boolean {
@ -167,7 +169,7 @@ export class DropdownSitesComponent implements OnInit {
}
private siteListHasMoreItems(): boolean {
return this.siteList && this.siteList.list.pagination && this.siteList.list.pagination.hasMoreItems;
return this.siteList?.list.pagination?.hasMoreItems;
}
private filteredResultsByMember(sites: SitePaging): SitePaging {
@ -177,7 +179,9 @@ export class DropdownSitesComponent implements OnInit {
}
private isCurrentUserMember(site: SiteEntry, loggedUserName: string): boolean {
return site.entry.visibility === 'PUBLIC' ||
!!site.relations.members.list.entries.find((member) => member.entry.id.toLowerCase() === loggedUserName.toLowerCase());
return (
site.entry.visibility === 'PUBLIC' ||
!!site.relations.members.list.entries.find((member) => member.entry.id.toLowerCase() === loggedUserName.toLowerCase())
);
}
}

View File

@ -27,9 +27,7 @@ import { NodeEntry } from '@alfresco/js-api';
templateUrl: './tree-view.component.html',
styleUrls: ['./tree-view.component.scss']
})
export class TreeViewComponent implements OnChanges {
/** Identifier of the node to display. */
@Input()
nodeId: string;
@ -51,8 +49,7 @@ export class TreeViewComponent implements OnChanges {
}
ngOnChanges(changes: SimpleChanges) {
if (changes['nodeId'] && changes['nodeId'].currentValue &&
changes['nodeId'].currentValue !== changes['nodeId'].previousValue) {
if (changes['nodeId']?.currentValue && changes['nodeId'].currentValue !== changes['nodeId'].previousValue) {
this.loadTreeNode();
} else {
this.dataSource.data = [];
@ -70,12 +67,11 @@ export class TreeViewComponent implements OnChanges {
hasChild = (_: number, nodeData: TreeBaseNode) => nodeData.expandable;
private loadTreeNode() {
this.treeViewService.getTreeNodes(this.nodeId)
.subscribe(
(treeNode: TreeBaseNode[]) => {
this.dataSource.data = treeNode;
},
(error) => this.error.emit(error)
);
this.treeViewService.getTreeNodes(this.nodeId).subscribe(
(treeNode: TreeBaseNode[]) => {
this.dataSource.data = treeNode;
},
(error) => this.error.emit(error)
);
}
}

View File

@ -23,7 +23,7 @@ import { TreeNode } from '../models/tree-node.interface';
import { TreeResponse } from '../models/tree-response.interface';
@Injectable({ providedIn: 'root' })
export abstract class TreeService<T extends TreeNode> extends DataSource<T> {
export abstract class TreeService<T extends TreeNode> extends DataSource<T> {
public readonly treeControl: FlatTreeControl<T>;
public treeNodesSource = new BehaviorSubject<T[]>([]);
@ -38,7 +38,10 @@ export abstract class TreeService<T extends TreeNode> extends DataSource<T> {
constructor() {
super();
this.treeControl = new FlatTreeControl<T>(node => node.level, node => node.hasChildren);
this.treeControl = new FlatTreeControl<T>(
(node) => node.level,
(node) => node.hasChildren
);
this.treeNodes = [];
}
@ -66,7 +69,7 @@ export abstract class TreeService<T extends TreeNode> extends DataSource<T> {
* @param nodeToCollapse Node to be collapsed
*/
public collapseNode(nodeToCollapse: T): void {
if (nodeToCollapse != null && nodeToCollapse.hasChildren) {
if (nodeToCollapse?.hasChildren) {
this.treeControl.collapse(nodeToCollapse);
const children: T[] = this.treeNodes.filter((node: T) => nodeToCollapse.id === node.parentId);
children.forEach((child: T) => {
@ -142,9 +145,7 @@ export abstract class TreeService<T extends TreeNode> extends DataSource<T> {
const index: number = this.treeNodes.indexOf(nodeToCollapse);
this.treeNodes.splice(index, 1);
if (nodeToCollapse.hasChildren) {
this.treeNodes
.filter((node: T) => nodeToCollapse.id === node.parentId)
.forEach((child: T) => this.collapseInnerNode(child));
this.treeNodes.filter((node: T) => nodeToCollapse.id === node.parentId).forEach((child: T) => this.collapseInnerNode(child));
}
}
}

View File

@ -36,9 +36,11 @@ export class FileUploadingListRowComponent {
}
showCancelledStatus(): boolean {
return this.file.status === FileUploadStatus.Cancelled ||
return (
this.file.status === FileUploadStatus.Cancelled ||
this.file.status === FileUploadStatus.Aborted ||
this.file.status === FileUploadStatus.Deleted;
this.file.status === FileUploadStatus.Deleted
);
}
get versionNumber(): string {
@ -46,29 +48,19 @@ export class FileUploadingListRowComponent {
}
get mimeType(): string {
if (this.file && this.file.file && this.file.file.type) {
return this.file.file.type;
}
return 'default';
return this.file?.file?.type || 'default';
}
isUploadVersion(): boolean {
return (
!!this.file.data &&
this.file.options &&
this.file.options.newVersion &&
this.file.data.entry.properties &&
this.file.data.entry.properties['cm:versionLabel']
);
return !!this.file.data && this.file.options?.newVersion && this.file.data.entry.properties?.['cm:versionLabel'];
}
canCancelUpload(): boolean {
return this.file && this.file.status === FileUploadStatus.Pending;
return this.file?.status === FileUploadStatus.Pending;
}
isUploadError(): boolean {
return this.file && this.file.status === FileUploadStatus.Error;
return this.file?.status === FileUploadStatus.Error;
}
isUploading(): boolean {
@ -76,10 +68,10 @@ export class FileUploadingListRowComponent {
}
isUploadComplete(): boolean {
return this.file.status === FileUploadStatus.Complete && !this.isUploadVersion();
return this.file?.status === FileUploadStatus.Complete && !this.isUploadVersion();
}
isUploadVersionComplete(): boolean {
return this.file && (this.file.status === FileUploadStatus.Complete && this.isUploadVersion());
return this.file?.status === FileUploadStatus.Complete && this.isUploadVersion();
}
}

View File

@ -16,10 +16,7 @@
*/
import { EXTENDIBLE_COMPONENT, FileUtils, LogService } from '@alfresco/adf-core';
import {
Component, EventEmitter, forwardRef, Input,
OnChanges, OnInit, Output, SimpleChanges, ViewEncapsulation, inject
} from '@angular/core';
import { Component, EventEmitter, forwardRef, Input, OnChanges, OnInit, Output, SimpleChanges, ViewEncapsulation, inject } from '@angular/core';
import { NodesApiService } from '../../common/services/nodes-api.service';
import { ContentService } from '../../common/services/content.service';
import { AllowableOperationsEnum } from '../../common/models/allowable-operations.enum';
@ -33,9 +30,7 @@ import { NodeAllowableOperationSubject } from '../../interfaces/node-allowable-o
selector: 'adf-upload-button',
templateUrl: './upload-button.component.html',
styleUrls: ['./upload-button.component.scss'],
viewProviders: [
{ provide: EXTENDIBLE_COMPONENT, useExisting: forwardRef(() => UploadButtonComponent) }
],
viewProviders: [{ provide: EXTENDIBLE_COMPONENT, useExisting: forwardRef(() => UploadButtonComponent) }],
encapsulation: ViewEncapsulation.None
})
export class UploadButtonComponent extends UploadBase implements OnInit, OnChanges, NodeAllowableOperationSubject {
@ -78,7 +73,7 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
ngOnChanges(changes: SimpleChanges) {
const rootFolderId = changes['rootFolderId'];
if (rootFolderId && rootFolderId.currentValue) {
if (rootFolderId?.currentValue) {
this.checkPermission();
}
}
@ -88,7 +83,7 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
}
onFilesAdded($event: any): void {
const files: File[] = FileUtils.toFileArray($event.currentTarget.files);
const files = FileUtils.toFileArray($event.currentTarget.files);
if (this.hasAllowableOperations) {
this.uploadFiles(files);
@ -101,7 +96,7 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
onClickUploadButton(): void {
if (this.file) {
const files: File[] = [this.file];
const files = [this.file];
if (this.hasAllowableOperations) {
this.uploadFiles(files);
@ -113,7 +108,7 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
onDirectoryAdded($event: any): void {
if (this.hasAllowableOperations) {
const files: File[] = FileUtils.toFileArray($event.currentTarget.files);
const files = FileUtils.toFileArray($event.currentTarget.files);
this.uploadFiles(files);
} else {
this.permissionEvent.emit(new PermissionModel({ type: 'content', action: 'upload', permission: 'create' }));
@ -132,10 +127,10 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
this.nodesApiService.getNode(this.rootFolderId, opts).subscribe(
(res) => this.permissionValue.next(this.nodeHasPermission(res, AllowableOperationsEnum.CREATE)),
(error: { error: Error }) => {
if (error && error.error) {
if (error?.error) {
this.error.emit({ error: error.error.message } as any);
} else {
this.error.emit({ error: 'FILE_UPLOAD.BUTTON.PERMISSION_CHECK_ERROR'} as any);
this.error.emit({ error: 'FILE_UPLOAD.BUTTON.PERMISSION_CHECK_ERROR' } as any);
}
}
);

View File

@ -22,15 +22,14 @@ import { UploadBase } from './base-upload/upload-base';
import { AllowableOperationsEnum } from '../../common/models/allowable-operations.enum';
import { ContentService } from '../../common/services/content.service';
import { FileModel } from '../../common/models/file.model';
import { Node } from '@alfresco/js-api';
@Component({
selector: 'adf-upload-drag-area',
templateUrl: './upload-drag-area.component.html',
styleUrls: ['./upload-drag-area.component.scss'],
host: { class: 'adf-upload-drag-area' },
viewProviders: [
{provide: EXTENDIBLE_COMPONENT, useExisting: forwardRef(() => UploadDragAreaComponent)}
],
viewProviders: [{ provide: EXTENDIBLE_COMPONENT, useExisting: forwardRef(() => UploadDragAreaComponent) }],
encapsulation: ViewEncapsulation.None
})
export class UploadDragAreaComponent extends UploadBase implements NodeAllowableOperationSubject {
@ -70,9 +69,12 @@ export class UploadDragAreaComponent extends UploadBase implements NodeAllowable
const messageTranslate = this.translationService.instant('FILE_UPLOAD.MESSAGES.PROGRESS');
const actionTranslate = this.translationService.instant('FILE_UPLOAD.ACTION.UNDO');
this.notificationService.openSnackMessageAction(messageTranslate, actionTranslate).onAction().subscribe(() => {
this.uploadService.cancelUpload(...latestFilesAdded);
});
this.notificationService
.openSnackMessageAction(messageTranslate, actionTranslate)
.onAction()
.subscribe(() => {
this.uploadService.cancelUpload(...latestFilesAdded);
});
}
/** Returns true or false considering the component options and node permissions */
@ -88,27 +90,29 @@ export class UploadDragAreaComponent extends UploadBase implements NodeAllowable
onUploadFiles(event: CustomEvent) {
event.stopPropagation();
event.preventDefault();
const isAllowed: boolean = this.isTargetNodeFolder(event) ?
this.contentService.hasAllowableOperations(event.detail.data.obj.entry, AllowableOperationsEnum.CREATE)
: this.contentService.hasAllowableOperations(event.detail.data.obj.entry, AllowableOperationsEnum.UPDATE);
const node: Node = event.detail.data.obj.entry;
const files: FileInfo[] = event.detail?.files || [];
const isAllowed: boolean = this.isTargetNodeFolder(node)
? this.contentService.hasAllowableOperations(node, AllowableOperationsEnum.CREATE)
: this.contentService.hasAllowableOperations(node, AllowableOperationsEnum.UPDATE);
if (isAllowed) {
if (!this.isTargetNodeFolder(event) && event.detail.files.length === 1) {
if (!this.isTargetNodeFolder(node) && files.length === 1) {
this.updateFileVersion.emit(event);
} else {
const fileInfo: FileInfo[] = event.detail.files;
if (this.isTargetNodeFolder(event)) {
const destinationFolderName = event.detail.data.obj.entry.name;
fileInfo.map((file) => file.relativeFolder = destinationFolderName ? destinationFolderName.concat(file.relativeFolder) : file.relativeFolder);
if (this.isTargetNodeFolder(node)) {
files.forEach((file) => (file.relativeFolder = node.name ? node.name.concat(file.relativeFolder) : file.relativeFolder));
}
if (fileInfo && fileInfo.length > 0) {
this.uploadFilesInfo(fileInfo);
if (files?.length > 0) {
this.uploadFilesInfo(files);
}
}
}
}
private isTargetNodeFolder(event: CustomEvent): boolean {
return event.detail.data.obj && event.detail.data.obj.entry.isFolder;
private isTargetNodeFolder(node: Node): boolean {
return !!node?.isFolder;
}
}

View File

@ -42,17 +42,7 @@ import {
ViewUtilService
} from '@alfresco/adf-core';
import { Subject } from 'rxjs';
import {
ContentApi,
Node,
NodeEntry,
NodesApi,
RenditionEntry,
SharedlinksApi,
Version,
VersionEntry,
VersionsApi
} from '@alfresco/js-api';
import { ContentApi, Node, NodeEntry, NodesApi, RenditionEntry, SharedlinksApi, Version, VersionEntry, VersionsApi } from '@alfresco/js-api';
import { RenditionService } from '../../common/services/rendition.service';
import { MatDialog } from '@angular/material/dialog';
import { filter, takeUntil } from 'rxjs/operators';
@ -66,12 +56,11 @@ import { NodeActionsService } from '../../document-list';
selector: 'adf-alfresco-viewer',
templateUrl: './alfresco-viewer.component.html',
styleUrls: ['./alfresco-viewer.component.scss'],
host: {class: 'adf-alfresco-viewer'},
host: { class: 'adf-alfresco-viewer' },
encapsulation: ViewEncapsulation.None,
providers: [ViewUtilService]
})
export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
@ViewChild('adfViewer')
adfViewer: ViewerComponent<{ node: Node }>;
@ -204,8 +193,8 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
tracks: Track[] = [];
readOnly: boolean = true;
sidebarRightTemplateContext: { node: Node } = {node: null};
sidebarLeftTemplateContext: { node: Node } = {node: null};
sidebarRightTemplateContext: { node: Node } = { node: null };
sidebarLeftTemplateContext: { node: Node } = { node: null };
_sharedLinksApi: SharedlinksApi;
get sharedLinksApi(): SharedlinksApi {
@ -231,27 +220,33 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
return this._contentApi;
}
constructor(private apiService: AlfrescoApiService,
private nodesApiService: NodesApiService,
private renditionService: RenditionService,
private viewUtilService: ViewUtilService,
private logService: LogService,
private contentService: ContentService,
private uploadService: UploadService,
public dialog: MatDialog,
private cdr: ChangeDetectorRef,
private nodeActionsService: NodeActionsService) {
constructor(
private apiService: AlfrescoApiService,
private nodesApiService: NodesApiService,
private renditionService: RenditionService,
private viewUtilService: ViewUtilService,
private logService: LogService,
private contentService: ContentService,
private uploadService: UploadService,
public dialog: MatDialog,
private cdr: ChangeDetectorRef,
private nodeActionsService: NodeActionsService
) {
renditionService.maxRetries = this.maxRetries;
}
ngOnInit() {
this.nodesApiService.nodeUpdated.pipe(
filter((node) => node && node.id === this.nodeId &&
(node.name !== this.fileName ||
this.getNodeVersionProperty(this.nodeEntry.entry) !== this.getNodeVersionProperty(node))),
takeUntil(this.onDestroy$)
).subscribe((node) => this.onNodeUpdated(node));
this.nodesApiService.nodeUpdated
.pipe(
filter(
(node) =>
node &&
node.id === this.nodeId &&
(node.name !== this.fileName || this.getNodeVersionProperty(this.nodeEntry.entry) !== this.getNodeVersionProperty(node))
),
takeUntil(this.onDestroy$)
)
.subscribe((node) => this.onNodeUpdated(node));
}
private async onNodeUpdated(node: Node) {
@ -282,7 +277,7 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
private async setupNode() {
try {
this.nodeEntry = await this.nodesApi.getNode(this.nodeId, {include: ['allowableOperations']});
this.nodeEntry = await this.nodesApi.getNode(this.nodeId, { include: ['allowableOperations'] });
if (this.versionId) {
this.versionEntry = await this.versionsApi.getVersion(this.nodeId, this.versionId);
await this.setUpNodeFile(this.nodeEntry.entry, this.versionEntry.entry);
@ -297,24 +292,24 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
}
private async setUpNodeFile(nodeData: Node, versionData?: Version): Promise<void> {
this.readOnly = !this.contentService.hasAllowableOperations(nodeData, 'update');
let mimeType;
let urlFileContent;
let mimeType: string;
let urlFileContent: string;
if (versionData && versionData.content) {
if (versionData?.content) {
mimeType = versionData.content.mimeType;
} else if (nodeData.content) {
mimeType = nodeData.content.mimeType;
}
const currentFileVersion = this.nodeEntry?.entry?.properties && this.nodeEntry.entry.properties['cm:versionLabel'] ?
encodeURI(this.nodeEntry?.entry?.properties['cm:versionLabel']) : encodeURI('1.0');
const currentFileVersion = this.nodeEntry?.entry?.properties?.['cm:versionLabel']
? encodeURI(this.nodeEntry?.entry?.properties['cm:versionLabel'])
: encodeURI('1.0');
urlFileContent = versionData ? this.contentApi.getVersionContentUrl(this.nodeId, versionData.id) :
this.contentApi.getContentUrl(this.nodeId);
urlFileContent = this.cacheBusterNumber ? urlFileContent + '&' + currentFileVersion + '&' + this.cacheBusterNumber :
urlFileContent + '&' + currentFileVersion;
urlFileContent = versionData ? this.contentApi.getVersionContentUrl(this.nodeId, versionData.id) : this.contentApi.getContentUrl(this.nodeId);
urlFileContent = this.cacheBusterNumber
? urlFileContent + '&' + currentFileVersion + '&' + this.cacheBusterNumber
: urlFileContent + '&' + currentFileVersion;
const fileExtension = this.viewUtilService.getFileExtension(versionData ? versionData.name : nodeData.name);
this.fileName = versionData ? versionData.name : nodeData.name;
@ -349,10 +344,7 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
const viewerType = this.viewUtilService.getViewerType(fileExtension, mimeType);
if (viewerType === 'unknown') {
({
url: urlFileContent,
mimeType
} = await this.getSharedLinkRendition(this.sharedLinkId));
({ url: urlFileContent, mimeType } = await this.getSharedLinkRendition(this.sharedLinkId));
}
this.mimeType = mimeType;
this.urlFileContent = urlFileContent;
@ -363,7 +355,7 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
const rendition: RenditionEntry = await this.sharedLinksApi.getSharedLinkRendition(sharedId, 'pdf');
if (rendition.entry.status.toString() === 'CREATED') {
const urlFileContent = this.contentApi.getSharedLinkRenditionUrl(sharedId, 'pdf');
return {url: urlFileContent, mimeType: 'application/pdf'};
return { url: urlFileContent, mimeType: 'application/pdf' };
}
} catch (error) {
this.logService.error(error);
@ -371,8 +363,7 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
const rendition: RenditionEntry = await this.sharedLinksApi.getSharedLinkRendition(sharedId, 'imgpreview');
if (rendition.entry.status.toString() === 'CREATED') {
const urlFileContent = this.contentApi.getSharedLinkRenditionUrl(sharedId, 'imgpreview');
return {url: urlFileContent, mimeType: 'image/png'};
return { url: urlFileContent, mimeType: 'image/png' };
}
} catch (renditionError) {
this.logService.error(renditionError);
@ -404,7 +395,7 @@ export class AlfrescoViewerComponent implements OnChanges, OnInit, OnDestroy {
onSubmitFile(newImageBlob: Blob) {
if (this?.nodeEntry?.entry?.id && !this.readOnly) {
const newImageFile: File = new File([newImageBlob], this?.nodeEntry?.entry?.name, {type: this?.nodeEntry?.entry?.content?.mimeType});
const newImageFile: File = new File([newImageBlob], this?.nodeEntry?.entry?.name, { type: this?.nodeEntry?.entry?.content?.mimeType });
const newFile = new FileModel(
newImageFile,
{

View File

@ -2,6 +2,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"declarationMap": true,
"paths": {
"@alfresco/adf-extensions": ["../../../dist/libs/extensions"],

View File

@ -63,10 +63,6 @@
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-require-imports": "off",
"@typescript-eslint/no-var-requires": "error",
"brace-style": [
"error",
"1tbs"
],
"comma-dangle": "error",
"default-case": "error",
"import/order": "off",

View File

@ -15,14 +15,7 @@
* limitations under the License.
*/
import {
Router,
CanActivate,
ActivatedRouteSnapshot,
RouterStateSnapshot,
CanActivateChild,
UrlTree
} from '@angular/router';
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanActivateChild, UrlTree } from '@angular/router';
import { AuthenticationService } from '../services/authentication.service';
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
import { OauthConfigModel } from '../models/oauth-config.model';
@ -39,10 +32,7 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
private storageService = inject(StorageService);
protected get withCredentials(): boolean {
return this.appConfigService.get<boolean>(
'auth.withCredentials',
false
);
return this.appConfigService.get<boolean>('auth.withCredentials', false);
}
abstract checkLogin(
@ -54,7 +44,6 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
if (this.authenticationService.isLoggedIn() && this.authenticationService.isOauth() && this.isLoginFragmentPresent()) {
return this.redirectSSOSuccessURL();
}
@ -116,23 +105,11 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
}
protected getLoginRoute(): string {
return (
this.appConfigService &&
this.appConfigService.get<string>(
AppConfigValues.LOGIN_ROUTE,
'login'
)
);
return this.appConfigService.get<string>(AppConfigValues.LOGIN_ROUTE, 'login');
}
protected getProvider(): string {
return (
this.appConfigService &&
this.appConfigService.get<string>(
AppConfigValues.PROVIDERS,
'ALL'
)
);
return this.appConfigService.get<string>(AppConfigValues.PROVIDERS, 'ALL');
}
protected isOAuthWithoutSilentLogin(): boolean {
@ -141,8 +118,7 @@ export abstract class AuthGuardBase implements CanActivate, CanActivateChild {
}
protected isSilentLogin(): boolean {
const oauth = this.appConfigService.oauth2;;
const oauth = this.appConfigService.oauth2;
return this.authenticationService.isOauth() && oauth && oauth.silentLogin;
}
}

View File

@ -42,7 +42,6 @@ const templateTypes = {
encapsulation: ViewEncapsulation.None
})
export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemModel> implements OnChanges, OnDestroy {
@Input()
editable: boolean = false;
@ -69,21 +68,19 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
private onDestroy$ = new Subject<boolean>();
constructor(private clipboardService: ClipboardService,
private translateService: TranslationService,
private cd: ChangeDetectorRef) {
constructor(private clipboardService: ClipboardService, private translateService: TranslationService, private cd: ChangeDetectorRef) {
super();
}
ngOnChanges(changes: SimpleChanges): void {
if (changes.property && changes.property.firstChange) {
if (changes.property?.firstChange) {
this.textInput.valueChanges
.pipe(
filter(textInputValue => textInputValue !== this.editedValue && textInputValue !== null),
filter((textInputValue) => textInputValue !== this.editedValue && textInputValue !== null),
debounceTime(50),
takeUntil(this.onDestroy$)
)
.subscribe(textInputValue => {
.subscribe((textInputValue) => {
this.editedValue = textInputValue;
this.update();
});
@ -143,8 +140,7 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
prepareValueForUpload(property: CardViewTextItemModel, value: string | string[]): string | string[] {
if (property.multivalued && typeof value === 'string') {
const listOfValues = value.split(this.multiValueSeparator.trim()).map((item) => item.trim());
return listOfValues;
return value.split(this.multiValueSeparator.trim()).map((item) => item.trim());
}
return value;
}
@ -196,7 +192,7 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
undoText(event: KeyboardEvent) {
if ((event.ctrlKey || event.metaKey) && event.code === 'KeyZ' && this.textInput.value) {
this.textInput.setValue('');
this.textInput.setValue('');
}
}
@ -226,7 +222,7 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
}
get hasErrors(): boolean {
return (!!this.errors?.length) ?? false;
return !!this.errors?.length;
}
get isChipViewEnabled(): boolean {

View File

@ -34,7 +34,7 @@ export abstract class CardViewBaseItemModel {
constructor(cardViewItemProperties: CardViewItemProperties) {
this.label = cardViewItemProperties.label || '';
this.value = cardViewItemProperties.value && cardViewItemProperties.value.displayName || cardViewItemProperties.value;
this.value = cardViewItemProperties.value?.displayName || cardViewItemProperties.value;
this.key = cardViewItemProperties.key;
this.default = cardViewItemProperties.default;
this.editable = !!cardViewItemProperties.editable;
@ -63,9 +63,7 @@ export abstract class CardViewBaseItemModel {
return true;
}
return this.validators
.map((validator) => validator.isValid(newValue))
.reduce((isValidUntilNow, isValid) => isValidUntilNow && isValid, true);
return this.validators.map((validator) => validator.isValid(newValue)).reduce((isValidUntilNow, isValid) => isValidUntilNow && isValid, true);
}
getValidationErrors(value): CardViewItemValidator[] {

View File

@ -19,7 +19,10 @@ import { Type } from '@angular/core';
const getType = (type: any): any => () => type;
export interface DynamicComponentModel { type: string }
export interface DynamicComponentModel {
type: string;
}
export type DynamicComponentResolveFunction = (model: DynamicComponentModel) => Type<any>;
export class DynamicComponentResolver {
static fromType(type: Type<any>): DynamicComponentResolveFunction {

View File

@ -21,7 +21,6 @@ import moment, { isMoment, Moment } from 'moment';
@Injectable()
export class MomentDateAdapter extends DateAdapter<Moment> {
private localeData: any = moment.localeData();
overrideDisplayFormat: string;
@ -50,7 +49,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
return this.localeData.monthsShort();
case 'narrow':
return this.localeData.monthsShort().map((month) => month[0]);
default :
default:
return [];
}
}
@ -72,7 +71,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
return this.localeData.weekdaysShort();
case 'narrow':
return this.localeData.weekdaysShort();
default :
default:
return [];
}
}
@ -134,7 +133,7 @@ export class MomentDateAdapter extends DateAdapter<Moment> {
date = this.clone(date);
displayFormat = this.overrideDisplayFormat ? this.overrideDisplayFormat : displayFormat;
if (date && date.format) {
if (date?.format) {
return date.utc().local().format(displayFormat);
} else {
return '';

View File

@ -15,10 +15,7 @@
* limitations under the License.
*/
import {
Component, ViewEncapsulation, HostListener, AfterViewInit,
Optional, Inject, QueryList, ViewChildren
} from '@angular/core';
import { Component, ViewEncapsulation, HostListener, AfterViewInit, Optional, Inject, QueryList, ViewChildren } from '@angular/core';
import { trigger } from '@angular/animations';
import { DOWN_ARROW, UP_ARROW } from '@angular/cdk/keycodes';
import { FocusKeyManager } from '@angular/cdk/a11y';
@ -33,13 +30,15 @@ import { CONTEXT_MENU_DATA } from './context-menu.tokens';
<div mat-menu class="mat-menu-panel" @panelAnimation>
<div id="adf-context-menu-content" class="mat-menu-content">
<ng-container *ngFor="let link of links">
<button *ngIf="link.model?.visible"
[attr.data-automation-id]="'context-'+((link.title || link.model?.title) | translate)"
mat-menu-item
[disabled]="link.model?.disabled"
(click)="onMenuItemClick($event, link)">
<button
*ngIf="link.model?.visible"
[attr.data-automation-id]="'context-' + (link.title || link.model?.title | translate)"
mat-menu-item
[disabled]="link.model?.disabled"
(click)="onMenuItemClick($event, link)"
>
<mat-icon *ngIf="link.model?.icon">{{ link.model.icon }}</mat-icon>
<span>{{ (link.title || link.model?.title) | translate }}</span>
<span>{{ link.title || link.model?.title | translate }}</span>
</button>
</ng-container>
</div>
@ -50,9 +49,7 @@ import { CONTEXT_MENU_DATA } from './context-menu.tokens';
class: 'adf-context-menu'
},
encapsulation: ViewEncapsulation.None,
animations: [
trigger('panelAnimation', contextMenuAnimation)
]
animations: [trigger('panelAnimation', contextMenuAnimation)]
})
export class ContextMenuListComponent implements AfterViewInit {
private keyManager: FocusKeyManager<MatMenuItem>;
@ -84,7 +81,7 @@ export class ContextMenuListComponent implements AfterViewInit {
}
onMenuItemClick(event: Event, menuItem: any) {
if (menuItem && menuItem.model && menuItem.model.disabled) {
if (menuItem?.model?.disabled) {
event.preventDefault();
event.stopImmediatePropagation();
return;

View File

@ -15,14 +15,7 @@
* limitations under the License.
*/
import {
ChangeDetectionStrategy,
Component,
Input,
OnInit,
ViewEncapsulation,
OnDestroy, Optional
} from '@angular/core';
import { ChangeDetectionStrategy, Component, Input, OnInit, ViewEncapsulation, OnDestroy, Optional } from '@angular/core';
import { DataColumn } from '../../data/data-column.model';
import { DataRow } from '../../data/data-row.model';
import { DataTableAdapter } from '../../data/datatable-adapter';
@ -35,23 +28,22 @@ import { DataTableService } from '../../services/datatable.service';
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<ng-container>
<span *ngIf="copyContent; else defaultCell"
adf-clipboard="CLIPBOARD.CLICK_TO_COPY"
[clipboard-notification]="'CLIPBOARD.SUCCESS_COPY'"
[attr.aria-label]="value$ | async"
[title]="tooltip"
class="adf-datatable-cell-value"
>{{ value$ | async }}</span>
</ng-container>
<ng-template #defaultCell>
<span
*ngIf="copyContent; else defaultCell"
adf-clipboard="CLIPBOARD.CLICK_TO_COPY"
[clipboard-notification]="'CLIPBOARD.SUCCESS_COPY'"
[attr.aria-label]="value$ | async"
[title]="tooltip"
class="adf-datatable-cell-value"
>{{ value$ | async }}</span>
>{{ value$ | async }}</span
>
</ng-container>
<ng-template #defaultCell>
<span [title]="tooltip" class="adf-datatable-cell-value">{{ value$ | async }}</span>
</ng-template>
`,
encapsulation: ViewEncapsulation.None,
host: {class: 'adf-datatable-content-cell'}
host: { class: 'adf-datatable-content-cell' }
})
export class DataTableCellComponent implements OnInit, OnDestroy {
/** Data table adapter instance. */
@ -82,31 +74,30 @@ export class DataTableCellComponent implements OnInit, OnDestroy {
protected onDestroy$ = new Subject<boolean>();
constructor(@Optional() protected dataTableService: DataTableService) {
}
constructor(@Optional() protected dataTableService: DataTableService) {}
ngOnInit() {
this.updateValue();
if(this.dataTableService) {
this.dataTableService.rowUpdate
.pipe(takeUntil(this.onDestroy$))
.subscribe(data => {
if (data && data.id) {
if (this.row.id === data.id) {
if (this.row.obj && data.obj) {
this.row.obj = data.obj;
this.row['cache'][this.column.key] = this.column.key.split('.').reduce((source, key) => source ? source[key] : '', data.obj);
if (this.dataTableService) {
this.dataTableService.rowUpdate.pipe(takeUntil(this.onDestroy$)).subscribe((data) => {
if (data?.id) {
if (this.row.id === data.id) {
if (this.row.obj && data.obj) {
this.row.obj = data.obj;
this.row['cache'][this.column.key] = this.column.key
.split('.')
.reduce((source, key) => (source ? source[key] : ''), data.obj);
this.updateValue();
}
this.updateValue();
}
}
});
}
});
}
}
protected updateValue() {
if (this.column && this.column.key && this.row && this.data) {
if (this.column?.key && this.row && this.data) {
const value = this.data.getValue(this.row, this.column, this.resolverFn);
this.value$.next(value);

View File

@ -269,16 +269,12 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
this.keyManager.onKeydown(event);
}
constructor(private elementRef: ElementRef,
differs: IterableDiffers,
private matIconRegistry: MatIconRegistry,
private sanitizer: DomSanitizer) {
constructor(private elementRef: ElementRef, differs: IterableDiffers, private matIconRegistry: MatIconRegistry, private sanitizer: DomSanitizer) {
if (differs) {
this.differ = differs.find([]).create(null);
}
this.click$ = new Observable<DataRowEvent>((observer) => this.clickObserver = observer)
.pipe(share());
this.click$ = new Observable<DataRowEvent>((observer) => (this.clickObserver = observer)).pipe(share());
}
ngOnInit(): void {
@ -298,14 +294,12 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
}
ngAfterViewInit() {
this.keyManager = new FocusKeyManager(this.rowsList)
.withWrap()
.skipPredicate(item => item.disabled);
this.keyManager = new FocusKeyManager(this.rowsList).withWrap().skipPredicate((item) => item.disabled);
}
ngOnChanges(changes: SimpleChanges) {
this.initAndSubscribeClickStream();
if(this.selectedRowId) {
if (this.selectedRowId) {
this.setRowAsContextSource();
}
@ -358,8 +352,8 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
onDropHeaderColumn(event: CdkDragDrop<unknown>): void {
const allColumns = this.data.getColumns();
const shownColumns = allColumns.filter(column => !column.isHidden);
const hiddenColumns = allColumns.filter(column => column.isHidden);
const shownColumns = allColumns.filter((column) => !column.isHidden);
const hiddenColumns = allColumns.filter((column) => column.isHidden);
moveItemInArray(shownColumns, event.previousIndex, event.currentIndex);
const allColumnsWithNewOrder = [...shownColumns, ...hiddenColumns];
@ -378,14 +372,14 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
}
isPropertyChanged(property: SimpleChange): boolean {
return !!(property && property.currentValue);
return !!property?.currentValue;
}
convertToRowsData(rows: any []): ObjectDataRow[] {
convertToRowsData(rows: any[]): ObjectDataRow[] {
return rows.map((row) => new ObjectDataRow(row, row.isSelected));
}
convertToColumnsData(columns: any []): ObjectDataColumn[] {
convertToColumnsData(columns: any[]): ObjectDataColumn[] {
return columns.map((column) => new ObjectDataColumn(column));
}
@ -398,16 +392,11 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
private initAndSubscribeClickStream() {
this.unsubscribeClickStream();
const singleClickStream = this.click$
.pipe(
buffer(
this.click$.pipe(
debounceTime(250)
)
),
map((list) => list),
filter((x) => x.length === 1)
);
const singleClickStream = this.click$.pipe(
buffer(this.click$.pipe(debounceTime(250))),
map((list) => list),
filter((x) => x.length === 1)
);
this.singleClickStreamSub = singleClickStream.subscribe((dataRowEvents: DataRowEvent[]) => {
const event: DataRowEvent = dataRowEvents[0];
@ -423,16 +412,11 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
}
});
const multiClickStream = this.click$
.pipe(
buffer(
this.click$.pipe(
debounceTime(250)
)
),
map((list) => list),
filter((x) => x.length >= 2)
);
const multiClickStream = this.click$.pipe(
buffer(this.click$.pipe(debounceTime(250))),
map((list) => list),
filter((x) => x.length >= 2)
);
this.multiClickStreamSub = multiClickStream.subscribe((dataRowEvents: DataRowEvent[]) => {
const event: DataRowEvent = dataRowEvents[0];
@ -489,10 +473,7 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
}
private getRuntimeColumns(): any[] {
return [
...(this.columns || []),
...this.getSchemaFromHtml()
];
return [...(this.columns || []), ...this.getSchemaFromHtml()];
}
private setTableSchema() {
@ -511,7 +492,7 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
public getSchemaFromHtml(): any {
let schema = [];
if (this.columnList && this.columnList.columns && this.columnList.columns.length > 0) {
if (this.columnList?.columns?.length > 0) {
schema = this.columnList.columns.map((c) => c as DataColumn);
}
return schema;
@ -577,7 +558,7 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
if (this.data) {
const rows = this.data.getRows();
if (rows && rows.length > 0) {
rows.forEach((r) => r.isSelected = false);
rows.forEach((r) => (r.isSelected = false));
}
this.selection = [];
}
@ -722,7 +703,7 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
isIconValue(row: DataRow, col: DataColumn): boolean {
if (row && col) {
const value = row.getValue(col.key);
return value && value.startsWith('material-icons://');
return value?.startsWith('material-icons://');
}
return false;
}
@ -809,13 +790,13 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
markRowAsContextMenuSource(selectedRow: DataRow): void {
this.selectedRowId = selectedRow.id ? selectedRow.id : '';
this.data.getRows().forEach((row) => row.isContextMenuSource = false);
this.data.getRows().forEach((row) => (row.isContextMenuSource = false));
selectedRow.isContextMenuSource = true;
}
private setRowAsContextSource(): void {
const selectedRow = this.data.getRows().find((row) => this.selectedRowId === row.id);
if(selectedRow) {
if (selectedRow) {
selectedRow.isContextMenuSource = true;
}
}
@ -845,7 +826,7 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
}
findSelectionById(id: string): number {
return this.selection.findIndex(selection => selection?.id === id);
return this.selection.findIndex((selection) => selection?.id === id);
}
getCellTooltip(row: DataRow, col: DataColumn): string {
@ -923,7 +904,7 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
if (this.display === 'gallery') {
for (let i = 0; i < maxGalleryRows; i++) {
this.fakeRows.push('');
this.fakeRows.push('');
}
} else {
this.fakeRows = [];
@ -931,7 +912,7 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
}
getNameColumnValue() {
return this.data.getColumns().find( (el: any) => el.key.includes('name'));
return this.data.getColumns().find((el: any) => el.key.includes('name'));
}
getAutomationValue(row: DataRow): any {
@ -944,35 +925,27 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
return 'ADF-DATATABLE.ACCESSIBILITY.SORT_NONE';
}
return this.isColumnSorted(column, 'asc') ?
'ADF-DATATABLE.ACCESSIBILITY.SORT_ASCENDING' :
'ADF-DATATABLE.ACCESSIBILITY.SORT_DESCENDING';
return this.isColumnSorted(column, 'asc') ? 'ADF-DATATABLE.ACCESSIBILITY.SORT_ASCENDING' : 'ADF-DATATABLE.ACCESSIBILITY.SORT_DESCENDING';
}
getSortLiveAnnouncement(column: DataColumn): string {
if (!this.isColumnSortActive(column)) {
return 'ADF-DATATABLE.ACCESSIBILITY.SORT_DEFAULT' ;
return 'ADF-DATATABLE.ACCESSIBILITY.SORT_DEFAULT';
}
return this.isColumnSorted(column, 'asc') ?
'ADF-DATATABLE.ACCESSIBILITY.SORT_ASCENDING_BY' :
'ADF-DATATABLE.ACCESSIBILITY.SORT_DESCENDING_BY';
return this.isColumnSorted(column, 'asc')
? 'ADF-DATATABLE.ACCESSIBILITY.SORT_ASCENDING_BY'
: 'ADF-DATATABLE.ACCESSIBILITY.SORT_DESCENDING_BY';
}
private registerDragHandleIcon(): void {
const iconUrl = this.sanitizer.bypassSecurityTrustResourceUrl(
'./assets/images/drag_indicator_24px.svg'
);
const iconUrl = this.sanitizer.bypassSecurityTrustResourceUrl('./assets/images/drag_indicator_24px.svg');
this.matIconRegistry.addSvgIconInNamespace(
'adf',
'drag_indicator',
iconUrl
);
this.matIconRegistry.addSvgIconInNamespace('adf', 'drag_indicator', iconUrl);
}
onResizing({ rectangle: { width } }: ResizeEvent, colIndex: number): void {
const timeoutId = setTimeout(() => {
const allColumns = this.data.getColumns().filter(column => !column.isHidden);
const allColumns = this.data.getColumns().filter((column) => !column.isHidden);
allColumns[colIndex].width = width;
this.data.setColumns(allColumns);
@ -1003,11 +976,9 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
headerContainerColumns.forEach((column: HTMLElement, index: number): void => {
if (allColumns[index]) {
if (index === 0) {
allColumns[index].width =
column.clientWidth - parseInt(window.getComputedStyle(column).paddingLeft, 10);
} else if ( index === headerContainerColumns.length - 1) {
allColumns[index].width =
column.clientWidth - parseInt(window.getComputedStyle(column).paddingRight, 10);
allColumns[index].width = column.clientWidth - parseInt(window.getComputedStyle(column).paddingLeft, 10);
} else if (index === headerContainerColumns.length - 1) {
allColumns[index].width = column.clientWidth - parseInt(window.getComputedStyle(column).paddingRight, 10);
} else {
allColumns[index].width = column.clientWidth;
}

View File

@ -38,29 +38,23 @@ import { DataTableService } from '../../services/datatable.service';
host: { class: 'adf-datatable-content-cell' }
})
export class JsonCellComponent extends DataTableCellComponent implements OnInit {
/** Editable JSON. */
@Input()
editable: boolean = false;
constructor(
private dialog: MatDialog,
@Optional() dataTableService: DataTableService
) {
constructor(private dialog: MatDialog, @Optional() dataTableService: DataTableService) {
super(dataTableService);
}
ngOnInit() {
if (this.column && this.column.key && this.row && this.data) {
if (this.column?.key && this.row && this.data) {
this.value$.next(this.data.getValue(this.row, this.column, this.resolverFn));
}
}
view() {
const rawValue: string | any = this.data.getValue(this.row, this.column, this.resolverFn);
const value = typeof rawValue === 'object'
? JSON.stringify(rawValue || {}, null, 2)
: rawValue;
const value = typeof rawValue === 'object' ? JSON.stringify(rawValue || {}, null, 2) : rawValue;
const settings: EditJsonDialogSettings = {
title: this.column.title,
@ -68,16 +62,19 @@ export class JsonCellComponent extends DataTableCellComponent implements OnInit
value
};
this.dialog.open(EditJsonDialogComponent, {
data: settings,
minWidth: '50%',
minHeight: '50%'
}).afterClosed().subscribe((/*result: string*/) => {
if (typeof rawValue === 'object') {
// todo: update cell value as object
} else {
// todo: update cell value as string
}
});
this.dialog
.open(EditJsonDialogComponent, {
data: settings,
minWidth: '50%',
minHeight: '50%'
})
.afterClosed()
.subscribe((/*result: string*/) => {
if (typeof rawValue === 'object') {
// todo: update cell value as object
} else {
// todo: update cell value as string
}
});
}
}

View File

@ -15,13 +15,7 @@
* limitations under the License.
*/
import {
ChangeDetectionStrategy,
Component,
Input,
OnInit, Optional,
ViewEncapsulation
} from '@angular/core';
import { ChangeDetectionStrategy, Component, Input, OnInit, Optional, ViewEncapsulation } from '@angular/core';
import { DataTableCellComponent } from '../datatable-cell/datatable-cell.component';
import { DataTableService } from '../../services/datatable.service';
@ -48,14 +42,10 @@ export class LocationCellComponent extends DataTableCellComponent implements OnI
/** @override */
ngOnInit() {
if (this.column && this.column.key && this.row && this.data) {
const path: any = this.data.getValue(
this.row,
this.column,
this.resolverFn
);
if (this.column?.key && this.row && this.data) {
const path: any = this.data.getValue(this.row, this.column, this.resolverFn);
if (path && path.name && path.elements) {
if (path?.name && path.elements) {
this.value$.next(path.name.split('/').pop());
if (!this.tooltip) {

View File

@ -25,7 +25,6 @@ import { ObjectDataColumn } from './object-datacolumn.model';
@Directive()
// eslint-disable-next-line @angular-eslint/directive-class-suffix
export abstract class DataTableSchema<T = unknown> {
@ContentChild(DataColumnListComponent)
columnList: DataColumnListComponent;
@ -39,16 +38,14 @@ export abstract class DataTableSchema<T = unknown> {
protected columnsOrderedByKey: string = 'id';
protected columnsVisibility: { [columnId: string]: boolean } | undefined;
protected columnsWidths: { [columnId: string]: number} | undefined;
protected columnsWidths: { [columnId: string]: number } | undefined;
private layoutPresets = {};
private columnsSchemaSubject$ = new ReplaySubject<boolean>();
isColumnSchemaCreated$ = this.columnsSchemaSubject$.asObservable();
constructor(private appConfigService: AppConfigService,
protected presetKey: string,
protected presetsModel: any) { }
constructor(private appConfigService: AppConfigService, protected presetKey: string, protected presetsModel: any) {}
public createDatatableSchema(): void {
this.loadLayoutPresets();
@ -81,10 +78,7 @@ export abstract class DataTableSchema<T = unknown> {
const configSchemaColumns = this.getSchemaFromConfig(this.presetColumn);
const htmlSchemaColumns = this.getSchemaFromHtml(this.columnList);
let customSchemaColumns = [
...configSchemaColumns,
...htmlSchemaColumns
];
let customSchemaColumns = [...configSchemaColumns, ...htmlSchemaColumns];
if (customSchemaColumns.length === 0) {
customSchemaColumns = this.getDefaultLayoutPreset();
@ -95,18 +89,18 @@ export abstract class DataTableSchema<T = unknown> {
public getSchemaFromHtml(columnList: DataColumnListComponent): DataColumn[] {
let schema = [];
if (columnList && columnList.columns && columnList.columns.length > 0) {
if (columnList?.columns?.length > 0) {
schema = columnList.columns.map((c) => c as DataColumn);
}
return schema;
}
public getSchemaFromConfig(presetColumn: string): DataColumn[] {
return presetColumn ? (this.layoutPresets[presetColumn]).map((col) => new ObjectDataColumn(col)) : [];
public getSchemaFromConfig(presetColumn: string): DataColumn[] {
return presetColumn ? this.layoutPresets[presetColumn].map((col) => new ObjectDataColumn(col)) : [];
}
private getDefaultLayoutPreset(): DataColumn[] {
return (this.layoutPresets['default']).map((col) => new ObjectDataColumn(col));
return this.layoutPresets['default'].map((col) => new ObjectDataColumn(col));
}
public setPresetKey(presetKey: string) {
@ -117,12 +111,12 @@ export abstract class DataTableSchema<T = unknown> {
this.presetsModel = presetsModel;
}
private sortColumnsByKey(columns: any[]): any[] {
private sortColumnsByKey(columns: any[]): any[] {
const defaultColumns = [...columns];
const columnsWithProperOrder = [];
(this.columnsOrder ?? []).forEach(columnKey => {
const originalColumnIndex = defaultColumns.findIndex(defaultColumn => defaultColumn[this.columnsOrderedByKey] === columnKey);
(this.columnsOrder ?? []).forEach((columnKey) => {
const originalColumnIndex = defaultColumns.findIndex((defaultColumn) => defaultColumn[this.columnsOrderedByKey] === columnKey);
if (originalColumnIndex > -1) {
columnsWithProperOrder.push(defaultColumns[originalColumnIndex]);
@ -135,12 +129,10 @@ export abstract class DataTableSchema<T = unknown> {
private setHiddenColumns(columns: DataColumn[]): DataColumn[] {
if (this.columnsVisibility) {
return columns.map(column => {
return columns.map((column) => {
const isColumnVisible = this.columnsVisibility[column.id];
return isColumnVisible === undefined ?
column :
{ ...column, isHidden: !isColumnVisible };
return isColumnVisible === undefined ? column : { ...column, isHidden: !isColumnVisible };
});
}
@ -148,10 +140,10 @@ export abstract class DataTableSchema<T = unknown> {
}
private setColumnsWidth(columns: DataColumn[]): DataColumn[] {
if(this.columnsWidths) {
return columns.map(column => {
if (this.columnsWidths) {
return columns.map((column) => {
const columnWidth = this.columnsWidths[column.id];
return columnWidth === undefined ? column : {...column, width:columnWidth};
return columnWidth === undefined ? column : { ...column, width: columnWidth };
});
}
return columns;

View File

@ -25,7 +25,6 @@ import { Subject } from 'rxjs';
// Simple implementation of the DataTableAdapter interface.
export class ObjectDataTableAdapter implements DataTableAdapter {
private _sorting: DataSorting;
private _rows: DataRow[];
private _columns: DataColumn[];
@ -36,12 +35,12 @@ export class ObjectDataTableAdapter implements DataTableAdapter {
static generateSchema(data: any[]) {
const schema = [];
if (data && data.length) {
const rowToExaminate = data[0];
if (data?.length) {
const rowToExamine = data[0];
if (typeof rowToExaminate === 'object') {
for (const key in rowToExaminate) {
if (rowToExaminate.hasOwnProperty(key)) {
if (typeof rowToExamine === 'object') {
for (const key in rowToExamine) {
if (rowToExamine.hasOwnProperty(key)) {
schema.push({
type: 'text',
key,
@ -51,7 +50,6 @@ export class ObjectDataTableAdapter implements DataTableAdapter {
}
}
}
}
return schema;
}
@ -99,7 +97,7 @@ export class ObjectDataTableAdapter implements DataTableAdapter {
this._columns = columns || [];
}
getValue(row: DataRow, col: DataColumn, resolver?: (_row: DataRow, _col: DataColumn) => any ): any {
getValue(row: DataRow, col: DataColumn, resolver?: (_row: DataRow, _col: DataColumn) => any): any {
if (!row) {
throw new Error('Row not found');
}
@ -111,14 +109,7 @@ export class ObjectDataTableAdapter implements DataTableAdapter {
return resolver(row, col);
}
const value = row.getValue(col.key);
if (col.type === 'icon') {
const icon = row.getValue(col.key);
return icon;
}
return value;
return row.getValue(col.key);
}
getSorting(): DataSorting {
@ -128,7 +119,7 @@ export class ObjectDataTableAdapter implements DataTableAdapter {
setSorting(sorting: DataSorting): void {
this._sorting = sorting;
if (sorting && sorting.key) {
if (sorting?.key) {
this._rows.sort((a: DataRow, b: DataRow) => {
let left = a.getValue(sorting.key);
let right = b.getValue(sorting.key);
@ -137,20 +128,18 @@ export class ObjectDataTableAdapter implements DataTableAdapter {
return sorting.direction === 'asc' ? left - right : right - left;
} else {
if (left) {
left = (left instanceof Date) ? left.valueOf().toString() : left.toString();
left = left instanceof Date ? left.valueOf().toString() : left.toString();
} else {
left = '';
}
if (right) {
right = (right instanceof Date) ? right.valueOf().toString() : right.toString();
right = right instanceof Date ? right.valueOf().toString() : right.toString();
} else {
right = '';
}
return sorting.direction === 'asc'
? left.localeCompare(right)
: right.localeCompare(left);
return sorting.direction === 'asc' ? left.localeCompare(right) : right.localeCompare(left);
}
});
}

View File

@ -21,223 +21,185 @@ import { map, take, share, filter, pairwise, mergeMap, takeUntil } from 'rxjs/op
import { OnInit, Output, NgZone, OnDestroy, Directive, Renderer2, ElementRef, EventEmitter, Input } from '@angular/core';
@Directive({
selector: '[adf-resizable]',
exportAs: 'adf-resizable'
selector: '[adf-resizable]',
exportAs: 'adf-resizable'
})
export class ResizableDirective implements OnInit, OnDestroy {
/**
* Emitted when the mouse is pressed and a resize event is about to begin.
*/
@Output() resizeStart = new EventEmitter<ResizeEvent>();
/**
* Emitted when the mouse is pressed and a resize event is about to begin.
*/
@Output() resizeStart = new EventEmitter<ResizeEvent>();
/**
* Emitted when the mouse is dragged after a resize event has started.
*/
@Output() resizing = new EventEmitter<ResizeEvent>();
/**
* Emitted when the mouse is dragged after a resize event has started.
*/
@Output() resizing = new EventEmitter<ResizeEvent>();
/**
* Emitted when the mouse is released after a resize event.
*/
@Output() resizeEnd = new EventEmitter<ResizeEvent>();
/**
* Emitted when the mouse is released after a resize event.
*/
@Output() resizeEnd = new EventEmitter<ResizeEvent>();
/**
* This is to cover sum of the left and right padding between resize handler and its parent.
*/
@Input() coverPadding = 0;
/**
* This is to cover sum of the left and right padding between resize handler and its parent.
*/
@Input() coverPadding = 0;
mouseup = new Subject<IResizeMouseEvent>();
mouseup = new Subject<IResizeMouseEvent>();
mousedown = new Subject<IResizeMouseEvent>();
mousedown = new Subject<IResizeMouseEvent>();
mousemove = new Subject<IResizeMouseEvent>();
mousemove = new Subject<IResizeMouseEvent>();
private pointerDown: Observable<IResizeMouseEvent>;
private pointerDown: Observable<IResizeMouseEvent>;
private pointerMove: Observable<IResizeMouseEvent>;
private pointerMove: Observable<IResizeMouseEvent>;
private pointerUp: Observable<IResizeMouseEvent>;
private pointerUp: Observable<IResizeMouseEvent>;
private startingRect: BoundingRectangle;
private startingRect: BoundingRectangle;
private currentRect: BoundingRectangle;
private currentRect: BoundingRectangle;
private unlistenMouseDown: () => void;
private unlistenMouseDown?: () => void;
private unlistenMouseMove?: () => void;
private unlistenMouseUp?: () => void;
private unlistenMouseMove: () => void;
private destroy$ = new Subject<void>();
private unlistenMouseUp: () => 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) => {
observer.next(event);
}
);
});
}
).pipe(share());
this.pointerMove = new Observable(
(observer: Observer<IResizeMouseEvent>) => {
zone.runOutsideAngular(() => {
this.unlistenMouseMove = renderer.listen(
'document',
'mousemove',
(event: MouseEvent) => {
observer.next(event);
}
);
});
}
).pipe(share());
this.pointerUp = new Observable(
(observer: Observer<IResizeMouseEvent>) => {
zone.runOutsideAngular(() => {
this.unlistenMouseUp = renderer.listen(
'document',
'mouseup',
(event: MouseEvent) => {
observer.next(event);
}
);
});
}
).pipe(share());
}
ngOnInit(): void {
const mousedown$: Observable<IResizeMouseEvent> = merge(this.pointerDown, this.mousedown);
const mousemove$: Observable<IResizeMouseEvent> = merge(this.pointerMove, this.mousemove);
const mouseup$: Observable<IResizeMouseEvent> = merge(this.pointerUp, this.mouseup);
const mousedrag: Observable<IResizeMouseEvent | ICoordinateX> = mousedown$
.pipe(
mergeMap(({ clientX = 0 }) => merge(
mousemove$.pipe(take(1)).pipe(map((coords) => [, coords])),
mousemove$.pipe(pairwise())
)
.pipe(
map(([previousCoords = {}, newCoords = {}]) =>
[
{ clientX: previousCoords.clientX - clientX },
{ clientX: newCoords.clientX - clientX }
]
)
)
.pipe(
filter(([previousCoords = {}, newCoords = {}]) =>
Math.ceil(previousCoords.clientX) !== Math.ceil(newCoords.clientX))
)
.pipe(
map(([, newCoords]) =>
({
clientX: Math.round(newCoords.clientX)
}))
)
.pipe(takeUntil(merge(mouseup$, mousedown$)))
)
)
.pipe(filter(() => !!this.currentRect));
mousedrag
.pipe(
map(({ clientX }) => this.getNewBoundingRectangle(this.startingRect, clientX + this.coverPadding))
)
.subscribe((rectangle: BoundingRectangle) => {
if (this.resizing.observers.length > 0) {
this.zone.run(() => {
this.resizing.emit({ rectangle });
});
}
this.currentRect = rectangle;
});
mousedown$
.pipe(
map(({ resize = false }) => resize),
filter((resize) => resize),
takeUntil(this.destroy$)
)
.subscribe(() => {
const startingRect: BoundingRectangle = this.getElementRect(this.element);
this.startingRect = startingRect;
this.currentRect = startingRect;
this.renderer.setStyle(document.body, 'cursor', 'col-resize');
if (this.resizeStart.observers.length > 0) {
this.zone.run(() => {
this.resizeStart.emit({
rectangle: this.getNewBoundingRectangle(this.startingRect, 0)
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) => {
observer.next(event);
});
});
});
}
});
}).pipe(share());
mouseup$.pipe(takeUntil(this.destroy$)).subscribe(() => {
if (this.currentRect) {
this.renderer.setStyle(document.body, 'cursor', '');
if (this.resizeEnd.observers.length > 0) {
this.zone.run(() => {
this.resizeEnd.emit({ rectangle: this.currentRect });
});
}
this.startingRect = null;
this.currentRect = null;
}
});
}
this.pointerMove = new Observable((observer: Observer<IResizeMouseEvent>) => {
zone.runOutsideAngular(() => {
this.unlistenMouseMove = renderer.listen('document', 'mousemove', (event: MouseEvent) => {
observer.next(event);
});
});
}).pipe(share());
ngOnDestroy(): void {
this.mousedown.complete();
this.mousemove.complete();
this.mouseup.complete();
this.unlistenMouseDown && this.unlistenMouseDown();
this.unlistenMouseMove && this.unlistenMouseMove();
this.unlistenMouseUp && this.unlistenMouseUp();
this.destroy$.next();
}
this.pointerUp = new Observable((observer: Observer<IResizeMouseEvent>) => {
zone.runOutsideAngular(() => {
this.unlistenMouseUp = renderer.listen('document', 'mouseup', (event: MouseEvent) => {
observer.next(event);
});
});
}).pipe(share());
}
private getNewBoundingRectangle({ top, bottom, left, right }: BoundingRectangle, clientX: number): BoundingRectangle {
const updatedRight = Math.round(right + clientX);
ngOnInit(): void {
const mousedown$ = merge(this.pointerDown, this.mousedown);
const mousemove$ = merge(this.pointerMove, this.mousemove);
const mouseup$ = merge(this.pointerUp, this.mouseup);
return {
top,
left,
bottom,
right: updatedRight,
width: updatedRight - left
};
}
const mouseDrag: Observable<IResizeMouseEvent | ICoordinateX> = mousedown$
.pipe(
mergeMap(({ clientX = 0 }) =>
merge(mousemove$.pipe(take(1)).pipe(map((coords) => [, coords])), mousemove$.pipe(pairwise()))
.pipe(
map(([previousCoords = {}, newCoords = {}]) => [
{ clientX: previousCoords.clientX - clientX },
{ clientX: newCoords.clientX - clientX }
])
)
.pipe(filter(([previousCoords = {}, newCoords = {}]) => Math.ceil(previousCoords.clientX) !== Math.ceil(newCoords.clientX)))
.pipe(
map(([, newCoords]) => ({
clientX: Math.round(newCoords.clientX)
}))
)
.pipe(takeUntil(merge(mouseup$, mousedown$)))
)
)
.pipe(filter(() => !!this.currentRect));
private getElementRect({ nativeElement }: ElementRef): BoundingRectangle {
mouseDrag
.pipe(map(({ clientX }) => this.getNewBoundingRectangle(this.startingRect, clientX + this.coverPadding)))
.subscribe((rectangle: BoundingRectangle) => {
if (this.resizing.observers.length > 0) {
this.zone.run(() => {
this.resizing.emit({ rectangle });
});
}
this.currentRect = rectangle;
});
const { height = 0, width = 0, top = 0, bottom = 0, right = 0, left = 0 }: BoundingRectangle = nativeElement.getBoundingClientRect();
mousedown$
.pipe(
map(({ resize = false }) => resize),
filter((resize) => resize),
takeUntil(this.destroy$)
)
.subscribe(() => {
const startingRect: BoundingRectangle = this.getElementRect(this.element);
return {
top,
left,
right,
width,
height,
bottom,
scrollTop: nativeElement.scrollTop,
scrollLeft: nativeElement.scrollLeft
};
}
this.startingRect = startingRect;
this.currentRect = startingRect;
this.renderer.setStyle(document.body, 'cursor', 'col-resize');
if (this.resizeStart.observers.length > 0) {
this.zone.run(() => {
this.resizeStart.emit({
rectangle: this.getNewBoundingRectangle(this.startingRect, 0)
});
});
}
});
mouseup$.pipe(takeUntil(this.destroy$)).subscribe(() => {
if (this.currentRect) {
this.renderer.setStyle(document.body, 'cursor', '');
if (this.resizeEnd.observers.length > 0) {
this.zone.run(() => {
this.resizeEnd.emit({ rectangle: this.currentRect });
});
}
this.startingRect = null;
this.currentRect = null;
}
});
}
ngOnDestroy(): void {
this.mousedown.complete();
this.mousemove.complete();
this.mouseup.complete();
this.unlistenMouseDown?.();
this.unlistenMouseMove?.();
this.unlistenMouseUp?.();
this.destroy$.next();
}
private getNewBoundingRectangle({ top, bottom, left, right }: BoundingRectangle, clientX: number): BoundingRectangle {
const updatedRight = Math.round(right + clientX);
return {
top,
left,
bottom,
right: updatedRight,
width: updatedRight - left
};
}
private getElementRect({ nativeElement }: ElementRef): BoundingRectangle {
const { height = 0, width = 0, top = 0, bottom = 0, right = 0, left = 0 }: BoundingRectangle = nativeElement.getBoundingClientRect();
return {
top,
left,
right,
width,
height,
bottom,
scrollTop: nativeElement.scrollTop,
scrollLeft: nativeElement.scrollLeft
};
}
}

View File

@ -20,80 +20,62 @@ import { ResizableDirective } from './resizable.directive';
import { Input, OnInit, Directive, Renderer2, ElementRef, OnDestroy, NgZone } from '@angular/core';
@Directive({
selector: '[adf-resize-handle]'
selector: '[adf-resize-handle]'
})
export class ResizeHandleDirective implements OnInit, OnDestroy {
/**
* Reference to ResizableDirective
*/
@Input() resizableContainer: ResizableDirective;
/**
* Reference to ResizableDirective
*/
@Input() resizableContainer: ResizableDirective;
private unlistenMouseDown: () => void;
private unlistenMouseDown?: () => void;
private unlistenMouseMove?: () => void;
private unlistenMouseUp?: () => void;
private unlistenMouseMove: () => void;
private destroy$ = new Subject<void>();
private unlistenMouseUp: () => void;
constructor(private readonly renderer: Renderer2, private readonly element: ElementRef, private readonly zone: NgZone) {}
private destroy$ = new Subject<void>();
constructor(
private readonly renderer: Renderer2,
private readonly element: ElementRef,
private readonly zone: NgZone
) { }
ngOnInit(): void {
this.zone.runOutsideAngular(() => {
this.unlistenMouseDown = this.renderer.listen(
this.element.nativeElement,
'mousedown',
(mouseDownEvent: MouseEvent) => {
this.onMousedown(mouseDownEvent);
}
);
});
}
ngOnDestroy(): void {
this.unlistenMouseDown && this.unlistenMouseDown();
this.unlistenMouseMove && this.unlistenMouseMove();
this.unlistenMouseUp && this.unlistenMouseUp();
this.destroy$.next();
}
private onMousedown(event: MouseEvent): void {
if (event.cancelable) {
event.preventDefault();
ngOnInit(): void {
this.zone.runOutsideAngular(() => {
this.unlistenMouseDown = this.renderer.listen(this.element.nativeElement, 'mousedown', (mouseDownEvent: MouseEvent) => {
this.onMousedown(mouseDownEvent);
});
});
}
if (!this.unlistenMouseMove) {
this.unlistenMouseMove = this.renderer.listen(
this.element.nativeElement,
'mousemove',
(mouseMoveEvent: MouseEvent) => {
this.onMousemove(mouseMoveEvent);
}
);
ngOnDestroy(): void {
this.unlistenMouseDown?.();
this.unlistenMouseMove?.();
this.unlistenMouseUp?.();
this.destroy$.next();
}
this.unlistenMouseUp = this.renderer.listen(
'document',
'mouseup',
(mouseUpEvent: MouseEvent) => {
this.onMouseup(mouseUpEvent);
}
);
private onMousedown(event: MouseEvent): void {
if (event.cancelable) {
event.preventDefault();
}
this.resizableContainer.mousedown.next({ ...event, resize: true });
}
if (!this.unlistenMouseMove) {
this.unlistenMouseMove = this.renderer.listen(this.element.nativeElement, 'mousemove', (mouseMoveEvent: MouseEvent) => {
this.onMousemove(mouseMoveEvent);
});
}
private onMouseup(event: MouseEvent): void {
this.unlistenMouseMove && this.unlistenMouseMove();
this.unlistenMouseUp();
this.resizableContainer.mouseup.next(event);
}
this.unlistenMouseUp = this.renderer.listen('document', 'mouseup', (mouseUpEvent: MouseEvent) => {
this.onMouseup(mouseUpEvent);
});
private onMousemove(event: MouseEvent): void {
this.resizableContainer.mousemove.next(event);
}
this.resizableContainer.mousedown.next({ ...event, resize: true });
}
private onMouseup(event: MouseEvent): void {
this.unlistenMouseMove?.();
this.unlistenMouseUp();
this.resizableContainer.mouseup.next(event);
}
private onMousemove(event: MouseEvent): void {
this.resizableContainer.mousemove.next(event);
}
}

View File

@ -24,7 +24,6 @@ import { FileInfo, FileUtils } from '../common/utils/file-utils';
selector: '[adf-upload]'
})
export class UploadDirective implements OnInit, OnDestroy {
/** Enables/disables uploading. */
@Input('adf-upload')
enabled: boolean = true;
@ -135,7 +134,6 @@ export class UploadDirective implements OnInit, OnDestroy {
onDrop(event: Event) {
if (this.isDropMode()) {
event.stopPropagation();
event.preventDefault();
@ -147,7 +145,6 @@ export class UploadDirective implements OnInit, OnDestroy {
this.getFilesDropped(dataTransfer).then((files) => {
this.onUploadFiles(files);
});
}
}
return false;
@ -181,10 +178,10 @@ export class UploadDirective implements OnInit, OnDestroy {
}
getDataTransfer(event: Event | any): DataTransfer {
if (event && event.dataTransfer) {
if (event?.dataTransfer) {
return event.dataTransfer;
}
if (event && event.originalEvent && event.originalEvent.dataTransfer) {
if (event?.originalEvent?.dataTransfer) {
return event.originalEvent.dataTransfer;
}
return null;
@ -207,34 +204,38 @@ export class UploadDirective implements OnInit, OnDestroy {
const item = items[i].webkitGetAsEntry();
if (item) {
if (item.isFile) {
iterations.push(Promise.resolve({
entry: item,
file: items[i].getAsFile(),
relativeFolder: '/'
}));
iterations.push(
Promise.resolve({
entry: item,
file: items[i].getAsFile(),
relativeFolder: '/'
})
);
} else if (item.isDirectory) {
iterations.push(new Promise((resolveFolder) => {
FileUtils.flatten(item).then((files) => resolveFolder(files));
}));
iterations.push(
new Promise((resolveFolder) => {
FileUtils.flatten(item).then((files) => resolveFolder(files));
})
);
}
}
} else {
iterations.push(Promise.resolve({
entry: null,
file: items[i].getAsFile(),
relativeFolder: '/'
}));
iterations.push(
Promise.resolve({
entry: null,
file: items[i].getAsFile(),
relativeFolder: '/'
})
);
}
}
} else {
// safari or FF
const files = FileUtils
.toFileArray(dataTransfer.files)
.map((file) => ({
entry: null,
file,
relativeFolder: '/'
}));
const files = FileUtils.toFileArray(dataTransfer.files).map((file) => ({
entry: null,
file,
relativeFolder: '/'
}));
iterations.push(Promise.resolve(files));
}
@ -255,11 +256,13 @@ export class UploadDirective implements OnInit, OnDestroy {
if (this.isClickMode()) {
const input = event.currentTarget;
const files = FileUtils.toFileArray(input.files);
this.onUploadFiles(files.map((file) => ({
entry: null,
file,
relativeFolder: '/'
})));
this.onUploadFiles(
files.map((file) => ({
entry: null,
file,
relativeFolder: '/'
}))
);
event.target.value = '';
}
}

View File

@ -22,7 +22,6 @@ import { ThemePalette } from '@angular/material/core';
@Directive()
// eslint-disable-next-line @angular-eslint/directive-class-suffix
export abstract class FormBaseComponent {
static SAVE_OUTCOME_ID: string = '$save';
static COMPLETE_OUTCOME_ID: string = '$complete';
static START_PROCESS_OUTCOME_ID: string = '$startProcess';
@ -137,7 +136,7 @@ export abstract class FormBaseComponent {
}
isOutcomeButtonVisible(outcome: FormOutcomeModel, isFormReadOnly: boolean): boolean {
if (outcome && outcome.name) {
if (outcome?.name) {
if (outcome.name === FormOutcomeModel.COMPLETE_ACTION) {
return this.showCompleteButton;
}
@ -162,7 +161,6 @@ export abstract class FormBaseComponent {
*/
onOutcomeClicked(outcome: FormOutcomeModel): boolean {
if (!this.readOnly && outcome && this.form) {
if (!this.onExecuteOutcome(outcome)) {
return false;
}

View File

@ -17,7 +17,8 @@
import {
Compiler,
Component, ComponentFactory,
Component,
ComponentFactory,
ComponentFactoryResolver,
ComponentRef,
Input,
@ -39,19 +40,20 @@ declare const adf: any;
@Component({
selector: 'adf-form-field',
template: `
<div [id]="'field-'+field?.id+'-container'"
<div
[id]="'field-' + field?.id + '-container'"
[style.visibility]="!field?.isVisible ? 'hidden' : 'visible'"
[style.display]="!field?.isVisible ? 'none' : 'block'"
[class.adf-focus]="focus"
(focusin)="focusToggle()"
(focusout)="focusToggle()">
(focusout)="focusToggle()"
>
<div #container></div>
</div>
`,
encapsulation: ViewEncapsulation.None
})
export class FormFieldComponent implements OnInit, OnDestroy {
@ViewChild('container', { read: ViewContainerRef, static: true })
container: ViewContainerRef;
@ -67,11 +69,12 @@ export class FormFieldComponent implements OnInit, OnDestroy {
focus: boolean = false;
constructor(private formRenderingService: FormRenderingService,
private componentFactoryResolver: ComponentFactoryResolver,
private visibilityService: WidgetVisibilityService,
private compiler: Compiler) {
}
constructor(
private formRenderingService: FormRenderingService,
private componentFactoryResolver: ComponentFactoryResolver,
private visibilityService: WidgetVisibilityService,
private compiler: Compiler
) {}
ngOnInit() {
const w: any = window;
@ -114,9 +117,9 @@ export class FormFieldComponent implements OnInit, OnDestroy {
}
private getField(): FormFieldModel {
if (this.field && this.field.params) {
if (this.field?.params) {
const wrappedField = this.field.params.field;
if (wrappedField && wrappedField.type) {
if (wrappedField?.type) {
return wrappedField as FormFieldModel;
}
}
@ -124,7 +127,7 @@ export class FormFieldComponent implements OnInit, OnDestroy {
}
private hasController(type: string): boolean {
return (adf && adf.components && adf.components[type]);
return adf?.components?.[type];
}
private getComponentFactorySync(type: string, template: string): ComponentFactory<any> {

View File

@ -35,7 +35,6 @@ import { FormService } from '../services/form.service';
encapsulation: ViewEncapsulation.None
})
export class FormRendererComponent<T> implements OnChanges, OnDestroy {
/** Toggle debug options. */
@Input()
showDebugButton: boolean = false;
@ -47,8 +46,7 @@ export class FormRendererComponent<T> implements OnChanges, OnDestroy {
fields: FormFieldModel[];
constructor(public formService: FormService, private formRulesManager: FormRulesManager<T>) {
}
constructor(public formService: FormService, private formRulesManager: FormRulesManager<T>) {}
ngOnChanges(): void {
this.formRulesManager.initialize(this.formDefinition);
@ -67,15 +65,15 @@ export class FormRendererComponent<T> implements OnChanges, OnDestroy {
}
onExpanderClicked(content: ContainerModel) {
if (content && content.isCollapsible()) {
if (content?.isCollapsible()) {
content.isExpanded = !content.isExpanded;
}
}
getNumberOfColumns(content: ContainerModel): number {
return (content.json?.numberOfColumns || 1) > (content.columns?.length || 1) ?
(content.json?.numberOfColumns || 1) :
(content.columns?.length || 1);
return (content.json?.numberOfColumns || 1) > (content.columns?.length || 1)
? content.json?.numberOfColumns || 1
: content.columns?.length || 1;
}
/**
@ -106,7 +104,8 @@ export class FormRendererComponent<T> implements OnChanges, OnDestroy {
let maxFieldSize = 0;
if (content?.columns?.length > 0) {
maxFieldSize = content?.columns?.reduce((prevColumn, currentColumn) =>
currentColumn.fields.length > prevColumn?.fields?.length ? currentColumn : prevColumn)?.fields?.length;
currentColumn.fields.length > prevColumn?.fields?.length ? currentColumn : prevColumn
)?.fields?.length;
}
return maxFieldSize;
}
@ -120,5 +119,4 @@ export class FormRendererComponent<T> implements OnChanges, OnDestroy {
const colspan = container ? container.field.colspan : 1;
return (100 / container.field.numberOfColumns) * colspan + '';
}
}

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
/* eslint-disable @angular-eslint/component-selector */
/* eslint-disable @angular-eslint/component-selector */
import { Component, OnInit, ViewEncapsulation, InjectionToken, Inject, Optional } from '@angular/core';
import { FormService } from '../../../services/form.service';
@ -45,7 +45,6 @@ export const ADF_AMOUNT_SETTINGS = new InjectionToken<AmountWidgetSettings>('adf
encapsulation: ViewEncapsulation.None
})
export class AmountWidgetComponent extends WidgetComponent implements OnInit {
static DEFAULT_CURRENCY: string = '$';
private showPlaceholder = true;
@ -71,9 +70,8 @@ export class AmountWidgetComponent extends WidgetComponent implements OnInit {
}
if (this.field.readOnly) {
this.showPlaceholder = this.settings && this.settings.showReadonlyPlaceholder;
this.showPlaceholder = this.settings?.showReadonlyPlaceholder;
}
}
}
}

View File

@ -15,10 +15,9 @@
* limitations under the License.
*/
/* eslint-disable @angular-eslint/component-selector */
export class ContentLinkModel {
/* eslint-disable @angular-eslint/component-selector */
export class ContentLinkModel {
contentAvailable: boolean;
created: Date;
createdBy: any;
@ -36,18 +35,18 @@
thumbnailStatus: string;
constructor(obj?: any) {
this.contentAvailable = obj && obj.contentAvailable;
this.created = obj && obj.created;
this.createdBy = obj && obj.createdBy || {};
this.id = obj && obj.id;
this.link = obj && obj.link;
this.mimeType = obj && obj.mimeType;
this.name = obj && obj.name;
this.previewStatus = obj && obj.previewStatus;
this.relatedContent = obj && obj.relatedContent;
this.simpleType = obj && obj.simpleType;
this.thumbnailStatus = obj && obj.thumbnailStatus;
this.nodeId = obj && obj.nodeId;
this.contentAvailable = obj?.contentAvailable;
this.created = obj?.created;
this.createdBy = obj?.createdBy || {};
this.id = obj?.id;
this.link = obj?.link;
this.mimeType = obj?.mimeType;
this.name = obj?.name;
this.previewStatus = obj?.previewStatus;
this.relatedContent = obj?.relatedContent;
this.simpleType = obj?.simpleType;
this.thumbnailStatus = obj?.thumbnailStatus;
this.nodeId = obj?.nodeId;
}
hasPreviewStatus(): boolean {

View File

@ -18,12 +18,11 @@
/* eslint-disable @angular-eslint/component-selector */
export class ErrorMessageModel {
message: string = '';
attributes: Map<string, string> = null;
constructor(obj?: any) {
this.message = obj && obj.message ? obj.message : '';
this.message = obj?.message || '';
this.attributes = new Map();
}

View File

@ -32,7 +32,6 @@ import { DataColumn } from '../../../../datatable/data/data-column.model';
// Maps to FormFieldRepresentation
export class FormFieldModel extends FormWidgetModel {
private _value: string;
private _readOnly: boolean = false;
private _isValid: boolean = true;
@ -105,7 +104,7 @@ export class FormFieldModel extends FormWidgetModel {
}
get readOnly(): boolean {
if (this.form && this.form.readOnly) {
if (this.form?.readOnly) {
return true;
}
return this._readOnly;
@ -206,7 +205,7 @@ export class FormFieldModel extends FormWidgetModel {
}
if (FormFieldTypes.isReadOnlyType(this.type)) {
if (this.params && this.params.field) {
if (this.params?.field) {
this.setValueForReadonlyType(form);
}
}
@ -241,9 +240,7 @@ export class FormFieldModel extends FormWidgetModel {
private getDefaultDateFormat(jsonField: any): string {
let originalType = jsonField.type;
if (FormFieldTypes.isReadOnlyType(jsonField.type) &&
jsonField.params &&
jsonField.params.field) {
if (FormFieldTypes.isReadOnlyType(jsonField.type) && jsonField.params && jsonField.params.field) {
originalType = jsonField.params.field.type;
}
return originalType === FormFieldTypes.DATETIME ? this.defaultDateTimeFormat : this.defaultDateFormat;
@ -301,7 +298,6 @@ export class FormFieldModel extends FormWidgetModel {
but saving back as object: { id: <id>, name: <name> }
*/
if (json.type === FormFieldTypes.DROPDOWN) {
if (json.options) {
if (json.hasEmptyValue) {
const emptyOption = json.options[0];
@ -328,8 +324,9 @@ export class FormFieldModel extends FormWidgetModel {
// Activiti has a bug with default radio button value where initial selection passed as `name` value
// so try resolving current one with a fallback to first entry via name or id
// TODO: needs to be reported and fixed at Activiti side
const entry: FormFieldOption[] = this.options.filter((opt) =>
opt.id === value || opt.name === value || (value && (opt.id === value.id || opt.name === value.name)));
const entry: FormFieldOption[] = this.options.filter(
(opt) => opt.id === value || opt.name === value || (value && (opt.id === value.id || opt.name === value.name))
);
if (entry.length > 0) {
value = entry[0].id;
}
@ -347,7 +344,7 @@ export class FormFieldModel extends FormWidgetModel {
} else {
dateValue = this.isDateTimeField(json) ? moment.utc(value, 'YYYY-MM-DD hh:mm A') : moment.utc(value.split('T')[0], 'YYYY-M-D');
}
if (dateValue && dateValue.isValid()) {
if (dateValue?.isValid()) {
value = dateValue.utc().format(this.dateDisplayFormat);
}
}
@ -367,7 +364,6 @@ export class FormFieldModel extends FormWidgetModel {
switch (this.type) {
case FormFieldTypes.DROPDOWN:
if (!this.value) {
this.form.values[this.id] = null;
break;
@ -422,7 +418,7 @@ export class FormFieldModel extends FormWidgetModel {
}
const dateValue = moment(this.value, this.dateDisplayFormat, true);
if (dateValue && dateValue.isValid()) {
if (dateValue?.isValid()) {
this.form.values[this.id] = `${dateValue.format('YYYY-MM-DD')}T00:00:00.000Z`;
} else {
this.form.values[this.id] = null;
@ -435,7 +431,7 @@ export class FormFieldModel extends FormWidgetModel {
}
const dateTimeValue = moment.utc(this.value, this.dateDisplayFormat, true);
if (dateTimeValue && dateTimeValue.isValid()) {
if (dateTimeValue?.isValid()) {
/* cspell:disable-next-line */
this.form.values[this.id] = `${dateTimeValue.utc().format('YYYY-MM-DDTHH:mm:ss')}.000Z`;
} else {
@ -450,7 +446,7 @@ export class FormFieldModel extends FormWidgetModel {
this.form.values[this.id] = this.enableFractions ? parseFloat(this.value) : parseInt(this.value, 10);
break;
case FormFieldTypes.BOOLEAN:
this.form.values[this.id] = (this.value !== null && this.value !== undefined) ? this.value : false;
this.form.values[this.id] = this.value !== null && this.value !== undefined ? this.value : false;
break;
case FormFieldTypes.PEOPLE:
this.form.values[this.id] = this.value ? this.value : null;
@ -482,28 +478,18 @@ export class FormFieldModel extends FormWidgetModel {
}
hasOptions() {
return this.options && this.options.length > 0;
return this.options?.length > 0;
}
private isDateField(json: any) {
return (json.params &&
json.params.field &&
json.params.field.type === FormFieldTypes.DATE) ||
json.type === FormFieldTypes.DATE;
return json.params?.field?.type === FormFieldTypes.DATE || json.type === FormFieldTypes.DATE;
}
private isDateTimeField(json: any): boolean {
return (json.params &&
json.params.field &&
json.params.field.type === FormFieldTypes.DATETIME) ||
json.type === FormFieldTypes.DATETIME;
return json.params?.field?.type === FormFieldTypes.DATETIME || json.type === FormFieldTypes.DATETIME;
}
private isCheckboxField(json: any): boolean {
return (json.params &&
json.params.field &&
json.params.field.type === FormFieldTypes.BOOLEAN) ||
json.type === FormFieldTypes.BOOLEAN;
return json.params?.field?.type === FormFieldTypes.BOOLEAN || json.type === FormFieldTypes.BOOLEAN;
}
}

View File

@ -59,7 +59,6 @@ export interface FormRepresentationModel {
};
}
export class FormModel implements ProcessFormModel {
static UNSET_TASK_NAME: string = 'Nameless task';
static SAVE_OUTCOME: string = '$save';
static COMPLETE_OUTCOME: string = '$complete';
@ -112,7 +111,7 @@ export class FormModel implements ProcessFormModel {
this.className = json.className || '';
this.variables = json.variables || json.formDefinition?.variables || [];
this.processVariables = json.processVariables || [];
this.enableFixedSpace = enableFixedSpace ? true : false;
this.enableFixedSpace = enableFixedSpace;
this.confirmMessage = json.confirmMessage || {};
this.tabs = (json.tabs || []).map((tabJson) => new TabModel(this, tabJson));
@ -161,7 +160,6 @@ export class FormModel implements ProcessFormModel {
validateFormEvent.errorsField = errorsField;
this.formService.validateForm.next(validateFormEvent);
}
}
/**
@ -203,7 +201,7 @@ export class FormModel implements ProcessFormModel {
if (json.fields) {
fields = json.fields;
} else if (json.formDefinition && json.formDefinition.fields) {
} else if (json.formDefinition?.fields) {
fields = json.formDefinition.fields;
}
@ -253,11 +251,7 @@ export class FormModel implements ProcessFormModel {
*/
getFormVariable(identifier: string): FormVariableModel {
if (identifier) {
return this.variables.find(
variable =>
variable.name === identifier ||
variable.id === identifier
);
return this.variables.find((variable) => variable.name === identifier || variable.id === identifier);
}
return undefined;
}
@ -271,7 +265,7 @@ export class FormModel implements ProcessFormModel {
getDefaultFormVariableValue(identifier: string): any {
const variable = this.getFormVariable(identifier);
if (variable && variable.hasOwnProperty('value')) {
if (variable?.hasOwnProperty('value')) {
return this.parseValue(variable.type, variable.value);
}
@ -288,11 +282,9 @@ export class FormModel implements ProcessFormModel {
getProcessVariableValue(name: string): any {
let value;
if (this.processVariables?.length) {
const names = [`variables.${ name }`, name];
const names = [`variables.${name}`, name];
const processVariable = this.processVariables.find(
entry => names.includes(entry.name)
);
const processVariable = this.processVariables.find((entry) => names.includes(entry.name));
if (processVariable) {
value = this.parseValue(processVariable.type, processVariable.value);
@ -310,13 +302,9 @@ export class FormModel implements ProcessFormModel {
if (type && value) {
switch (type) {
case 'date':
return value
? `${value}T00:00:00.000Z`
: undefined;
return value ? `${value}T00:00:00.000Z` : undefined;
case 'boolean':
return typeof value === 'string'
? JSON.parse(value)
: value;
return typeof value === 'string' ? JSON.parse(value) : value;
default:
return value;
}
@ -356,7 +344,7 @@ export class FormModel implements ProcessFormModel {
field.field.columns.forEach((column) => {
formFieldModel.push(...column.fields);
});
}else{
} else {
formFieldModel.push(field);
}
}
@ -387,20 +375,14 @@ export class FormModel implements ProcessFormModel {
isSystem: true
});
const customOutcomes = (this.json.outcomes || []).map(
(obj) => new FormOutcomeModel(this, obj)
);
const customOutcomes = (this.json.outcomes || []).map((obj) => new FormOutcomeModel(this, obj));
this.outcomes = [saveOutcome].concat(
customOutcomes.length > 0
? customOutcomes
: [completeOutcome, startProcessOutcome]
);
this.outcomes = [saveOutcome].concat(customOutcomes.length > 0 ? customOutcomes : [completeOutcome, startProcessOutcome]);
}
}
addValuesNotPresent(valuesToSetIfNotPresent: FormValues) {
this.fieldsCache.forEach(field => {
this.fieldsCache.forEach((field) => {
if (valuesToSetIfNotPresent[field.id] && (!this.values[field.id] || this.isValidDropDown(field.id))) {
this.values[field.id] = valuesToSetIfNotPresent[field.id];
field.json.value = this.values[field.id];
@ -423,11 +405,11 @@ export class FormModel implements ProcessFormModel {
setNodeIdValueForViewersLinkedToUploadWidget(linkedUploadWidgetContentSelected: UploadWidgetContentLinkModel) {
const linkedWidgetType = linkedUploadWidgetContentSelected?.options?.linkedWidgetType ?? 'uploadWidget';
const subscribedViewers = this.fieldsCache.filter(field =>
linkedUploadWidgetContentSelected.uploadWidgetId === field.params[linkedWidgetType]
const subscribedViewers = this.fieldsCache.filter(
(field) => linkedUploadWidgetContentSelected.uploadWidgetId === field.params[linkedWidgetType]
);
subscribedViewers.forEach(viewer => {
subscribedViewers.forEach((viewer) => {
this.values[viewer.id] = linkedUploadWidgetContentSelected.id;
viewer.json.value = this.values[viewer.id];
viewer.value = viewer.parseValue(viewer.json);

View File

@ -29,11 +29,8 @@ import { WidgetComponent } from '../widget.component';
styleUrls: ['./error.component.scss'],
animations: [
trigger('transitionMessages', [
state('enter', style({opacity: 1, transform: 'translateY(0%)'})),
transition('void => enter', [
style({opacity: 0, transform: 'translateY(-100%)'}),
animate('300ms cubic-bezier(0.55, 0, 0.55, 0.2)')
])
state('enter', style({ opacity: 1, transform: 'translateY(0%)' })),
transition('void => enter', [style({ opacity: 0, transform: 'translateY(-100%)' }), animate('300ms cubic-bezier(0.55, 0, 0.55, 0.2)')])
])
],
host: {
@ -50,7 +47,6 @@ import { WidgetComponent } from '../widget.component';
encapsulation: ViewEncapsulation.None
})
export class ErrorWidgetComponent extends WidgetComponent implements OnChanges {
@Input()
error: ErrorMessageModel;
@ -70,7 +66,7 @@ export class ErrorWidgetComponent extends WidgetComponent implements OnChanges {
this.required = changes.required.currentValue;
this.subscriptAnimationState = 'enter';
}
if (changes['error'] && changes['error'].currentValue) {
if (changes['error']?.currentValue) {
if (changes.error.currentValue.isActive()) {
this.error = changes.error.currentValue;
this.translateParameters = this.error.getAttributesAsJsonObj();

View File

@ -15,18 +15,9 @@
* limitations under the License.
*/
/* eslint-disable @angular-eslint/component-selector, @typescript-eslint/no-use-before-define, @angular-eslint/no-input-rename */
/* eslint-disable @angular-eslint/component-selector, @typescript-eslint/no-use-before-define, @angular-eslint/no-input-rename */
import {
Directive,
ElementRef,
forwardRef,
HostListener,
Input,
OnChanges,
Renderer2,
SimpleChanges
} from '@angular/core';
import { Directive, ElementRef, forwardRef, HostListener, Input, OnChanges, Renderer2, SimpleChanges } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
export const CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR: any = {
@ -43,7 +34,6 @@ export const CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR: any = {
providers: [CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR]
})
export class InputMaskDirective implements OnChanges, ControlValueAccessor {
/** Object defining mask and "reversed" status. */
@Input('textMask') inputMask: {
mask: string;
@ -62,27 +52,30 @@ export class InputMaskDirective implements OnChanges, ControlValueAccessor {
private value;
private invalidCharacters = [];
constructor(private el: ElementRef, private render: Renderer2) {
}
constructor(private el: ElementRef, private render: Renderer2) {}
_onChange = (_: any) => {
};
_onChange = (_: any) => {};
_onTouched = () => {
};
_onTouched = () => {};
@HostListener('input', ['$event'])
@HostListener('keyup', ['$event']) onTextInput(event: KeyboardEvent) {
if (this.inputMask && this.inputMask.mask) {
this.maskValue(this.el.nativeElement.value, this.el.nativeElement.selectionStart,
this.inputMask.mask, this.inputMask.isReversed, event.keyCode);
@HostListener('keyup', ['$event'])
onTextInput(event: KeyboardEvent) {
if (this.inputMask?.mask) {
this.maskValue(
this.el.nativeElement.value,
this.el.nativeElement.selectionStart,
this.inputMask.mask,
this.inputMask.isReversed,
event.keyCode
);
} else {
this._onChange(this.el.nativeElement.value);
}
}
ngOnChanges(changes: SimpleChanges) {
if (changes['inputMask'] && changes['inputMask'].currentValue['mask']) {
if (changes['inputMask']?.currentValue['mask']) {
this.inputMask = changes['inputMask'].currentValue;
}
}
@ -99,7 +92,7 @@ export class InputMaskDirective implements OnChanges, ControlValueAccessor {
this._onTouched = fn;
}
private maskValue(actualValue, startCaret, maskToApply, isMaskReversed, keyCode) {
private maskValue(actualValue: string, startCaret: number, maskToApply: string, isMaskReversed: boolean, keyCode: number) {
if (this.byPassKeys.indexOf(keyCode) === -1) {
const value = this.getMasked(false, actualValue, maskToApply, isMaskReversed);
const calculatedCaret = this.calculateCaretPosition(startCaret, actualValue, keyCode);
@ -111,12 +104,12 @@ export class InputMaskDirective implements OnChanges, ControlValueAccessor {
}
}
private setCaretPosition(caretPosition) {
private setCaretPosition(caretPosition: number) {
this.el.nativeElement.moveStart = caretPosition;
this.el.nativeElement.moveEnd = caretPosition;
}
calculateCaretPosition(caretPosition, newValue, keyCode) {
calculateCaretPosition(caretPosition: number, newValue: string, keyCode: number): number {
const newValueLength = newValue.length;
const oldValue = this.getValue() || '';
const oldValueLength = oldValue.length;
@ -133,7 +126,7 @@ export class InputMaskDirective implements OnChanges, ControlValueAccessor {
return caretPosition;
}
getMasked(skipMaskChars, val, mask, isReversed = false) {
getMasked(skipMaskChars: boolean, val: string, mask: string, isReversed = false) {
const buf = [];
const value = val;
let maskIndex = 0;
@ -143,9 +136,9 @@ export class InputMaskDirective implements OnChanges, ControlValueAccessor {
let offset = 1;
let addMethod = 'push';
let resetPos = -1;
let lastMaskChar;
let lastUntranslatedMaskChar;
let check;
let lastMaskChar: number;
let lastUntranslatedMaskChar: string;
let check: boolean;
if (isReversed) {
addMethod = 'unshift';
@ -159,8 +152,8 @@ export class InputMaskDirective implements OnChanges, ControlValueAccessor {
check = this.isToCheck(isReversed, maskIndex, maskLen, valueIndex, valueLength);
while (check) {
const maskDigit = mask.charAt(maskIndex);
const valDigit = value.charAt(valueIndex);
const translation = this.translationMask[maskDigit];
const valDigit = value.charAt(valueIndex);
const translation = this.translationMask[maskDigit];
if (translation) {
if (valDigit.match(translation.pattern)) {
@ -211,12 +204,12 @@ export class InputMaskDirective implements OnChanges, ControlValueAccessor {
return buf.join('');
}
private isToCheck(isReversed, maskIndex, maskLen, valueIndex, valueLength) {
private isToCheck(isReversed: boolean, maskIndex: number, maskLen: number, valueIndex: number, valueLength: number): boolean {
let check = false;
if (isReversed) {
check = (maskIndex > -1) && (valueIndex > -1);
check = maskIndex > -1 && valueIndex > -1;
} else {
check = (maskIndex < maskLen) && (valueIndex < valueLength);
check = maskIndex < maskLen && valueIndex < valueLength;
}
return check;
}

View File

@ -43,7 +43,6 @@ import { FormFieldModel } from './core';
encapsulation: ViewEncapsulation.None
})
export class WidgetComponent implements AfterViewInit {
/** Does the widget show a read-only value? (ie, can't be edited) */
@Input()
readOnly: boolean = false;
@ -60,8 +59,7 @@ export class WidgetComponent implements AfterViewInit {
touched: boolean = false;
constructor(public formService?: FormService) {
}
constructor(public formService?: FormService) {}
hasField(): boolean {
return !!this.field;
@ -70,7 +68,7 @@ export class WidgetComponent implements AfterViewInit {
// Note for developers:
// returns <any> object to be able binding it to the <element required="required"> attribute
isRequired(): any {
if (this.field && this.field.required) {
if (this.field?.required) {
return true;
}
return null;
@ -85,9 +83,7 @@ export class WidgetComponent implements AfterViewInit {
}
hasValue(): boolean {
return this.field &&
this.field.value !== null &&
this.field.value !== undefined;
return this.field?.value !== null && this.field?.value !== undefined;
}
isInvalidFieldRequired() {

View File

@ -18,13 +18,7 @@
import { LogService } from '../../common/services/log.service';
import { Injectable } from '@angular/core';
import moment from 'moment';
import {
FormFieldModel,
FormModel,
TabModel,
ContainerModel,
FormOutcomeModel
} from '../components/widgets/core';
import { FormFieldModel, FormModel, TabModel, ContainerModel, FormOutcomeModel } from '../components/widgets/core';
import { TaskProcessVariableModel } from '../models/task-process-variable.model';
import { WidgetVisibilityModel, WidgetTypeEnum } from '../models/widget-visibility.model';
@ -32,27 +26,27 @@ import { WidgetVisibilityModel, WidgetTypeEnum } from '../models/widget-visibili
providedIn: 'root'
})
export class WidgetVisibilityService {
private processVarList: TaskProcessVariableModel[];
private form: FormModel;
constructor(private logService: LogService) {
}
constructor(private logService: LogService) {}
public refreshVisibility(form: FormModel, processVarList?: TaskProcessVariableModel[]) {
this.form = form;
if (processVarList) {
this.processVarList = processVarList;
}
if (form && form.tabs && form.tabs.length > 0) {
form.tabs.map((tabModel) => this.refreshEntityVisibility(tabModel));
}
if (form && form.outcomes && form.outcomes.length > 0) {
form.outcomes.map((outcomeModel) => this.refreshOutcomeVisibility(outcomeModel));
}
if (form) {
if (form.tabs?.length > 0) {
form.tabs.map((tabModel) => this.refreshEntityVisibility(tabModel));
}
if (form.outcomes?.length > 0) {
form.outcomes.map((outcomeModel) => this.refreshOutcomeVisibility(outcomeModel));
}
form.getFormFields().map((field) => this.refreshEntityVisibility(field));
}
}
@ -79,14 +73,14 @@ export class WidgetVisibilityService {
const rightValue = this.getRightValue(form, visibilityObj);
const actualResult = this.evaluateCondition(leftValue, rightValue, visibilityObj.operator);
accumulator.push({value: actualResult, operator: visibilityObj.nextConditionOperator});
accumulator.push({ value: actualResult, operator: visibilityObj.nextConditionOperator });
if (this.isValidCondition(visibilityObj.nextCondition)) {
result = this.isFieldVisible(form, visibilityObj.nextCondition, accumulator);
} else if (accumulator[0] !== undefined) {
result = Function('"use strict";return (' +
accumulator.map((expression) => this.transformToLiteralExpression(expression)).join('') +
')')();
result = Function(
'"use strict";return (' + accumulator.map((expression) => this.transformToLiteralExpression(expression)).join('') + ')'
)();
} else {
result = actualResult;
}
@ -102,7 +96,7 @@ export class WidgetVisibilityService {
switch (currentOperator) {
case 'and':
return '&&';
case 'or' :
case 'or':
return '||';
case 'and-not':
return '&& !';
@ -158,25 +152,25 @@ export class WidgetVisibilityService {
}
public isFormFieldValid(formField: FormFieldModel): boolean {
return formField && formField.isValid;
return formField?.isValid;
}
public getFieldValue(valueList: any, fieldId: string): any {
let labelFilterByName;
let valueFound;
let labelFilterByName: string;
let valueFound: any;
if (fieldId && fieldId.indexOf('_LABEL') > 0) {
labelFilterByName = fieldId.substring(0, fieldId.length - 6);
if (valueList[labelFilterByName]) {
if (Array.isArray(valueList[labelFilterByName])) {
valueFound = valueList[labelFilterByName].map(({name}) => name);
valueFound = valueList[labelFilterByName].map(({ name }) => name);
} else {
valueFound = valueList[labelFilterByName].name;
}
}
} else if (valueList[fieldId] && valueList[fieldId].id) {
} else if (valueList[fieldId]?.id) {
valueFound = valueList[fieldId].id;
} else if (valueList[fieldId] && Array.isArray(valueList[fieldId])) {
valueFound = valueList[fieldId].map(({id}) => id);
valueFound = valueList[fieldId].map(({ id }) => id);
} else {
valueFound = valueList[fieldId];
}
@ -198,7 +192,7 @@ export class WidgetVisibilityService {
fieldValue = this.getObjectValue(formField, fieldId);
if (!fieldValue) {
if (formField.value && formField.value.id) {
if (formField.value?.id) {
fieldValue = formField.value.id;
} else if (!this.isInvalidValue(formField.value)) {
fieldValue = formField.value;
@ -223,7 +217,7 @@ export class WidgetVisibilityService {
}
private getCurrentFieldFromTabById(container: ContainerModel, fieldId: string): FormFieldModel {
const tabFields: FormFieldModel[][] = Object.keys(container.field.fields).map(key => container.field.fields[key]);
const tabFields: FormFieldModel[][] = Object.keys(container.field.fields).map((key) => container.field.fields[key]);
let currentField: FormFieldModel;
for (const tabField of tabFields) {
@ -237,14 +231,14 @@ export class WidgetVisibilityService {
private getFormTabContainers(form: FormModel): ContainerModel[] {
if (!!form) {
return form.fields.filter(field => field.type === 'container' && field.tab) as ContainerModel[];
return form.fields.filter((field) => field.type === 'container' && field.tab) as ContainerModel[];
}
return [];
}
private getObjectValue(field: FormFieldModel, fieldId: string): string {
let value = '';
if (field.value && field.value.name) {
if (field.value?.name) {
value = field.value.name;
} else if (field.options) {
const option = field.options.find((opt) => opt.id === field.value);
@ -267,23 +261,19 @@ export class WidgetVisibilityService {
private isSearchedField(field: FormFieldModel, fieldId: string): boolean {
const fieldToFind = fieldId?.indexOf('_LABEL') > 0 ? fieldId.replace('_LABEL', '') : fieldId;
return (field.id && fieldToFind) ? field.id.toUpperCase() === fieldToFind.toUpperCase() : false;
return field.id && fieldToFind ? field.id.toUpperCase() === fieldToFind.toUpperCase() : false;
}
public getVariableValue(form: FormModel, name: string, processVarList: TaskProcessVariableModel[]): string {
const processVariableValue = this.getProcessVariableValue(name, processVarList);
const variableDefaultValue = form.getDefaultFormVariableValue(name);
return (processVariableValue === undefined) ? variableDefaultValue : processVariableValue;
return processVariableValue === undefined ? variableDefaultValue : processVariableValue;
}
private getProcessVariableValue(name: string, processVarList: TaskProcessVariableModel[]): string {
if (processVarList) {
const processVariable = processVarList.find(
variable =>
variable.id === name ||
variable.id === `variables.${name}`
);
const processVariable = processVarList.find((variable) => variable.id === name || variable.id === `variables.${name}`);
if (processVariable) {
return processVariable.value;
@ -329,6 +319,6 @@ export class WidgetVisibilityService {
}
private isValidCondition(condition: WidgetVisibilityModel): boolean {
return !!(condition && condition.operator);
return !!condition?.operator;
}
}

View File

@ -81,7 +81,7 @@ export class LayoutContainerComponent implements OnInit, OnDestroy, OnChanges {
}
ngOnChanges(changes: SimpleChanges) {
if (changes && changes.direction) {
if (changes?.direction) {
this.contentAnimationState = this.toggledContentAnimation;
}
}
@ -104,9 +104,7 @@ export class LayoutContainerComponent implements OnInit, OnDestroy, OnChanges {
}
private get toggledSidenavAnimation(): any {
return this.sidenavAnimationState === this.SIDENAV_STATES.EXPANDED
? this.SIDENAV_STATES.COMPACT
: this.SIDENAV_STATES.EXPANDED;
return this.sidenavAnimationState === this.SIDENAV_STATES.EXPANDED ? this.SIDENAV_STATES.COMPACT : this.SIDENAV_STATES.EXPANDED;
}
private get toggledContentAnimation(): any {
@ -130,7 +128,6 @@ export class LayoutContainerComponent implements OnInit, OnDestroy, OnChanges {
if (this.position === 'end' && this.direction === 'rtl') {
return { value: 'compact', params: { 'margin-left': this.sidenavMax } };
}
} else {
if (this.position === 'start' && this.direction === 'ltr') {
return { value: 'expanded', params: { 'margin-left': this.sidenavMin } };

View File

@ -42,6 +42,6 @@ export class LoginDialogPanelComponent {
}
isValid() {
return this.login && this.login.form ? this.login.form.valid : false;
return this.login?.form ? this.login.form.valid : false;
}
}

View File

@ -15,10 +15,7 @@
* limitations under the License.
*/
import {
Component, EventEmitter,
Input, OnInit, Output, TemplateRef, ViewEncapsulation, OnDestroy
} from '@angular/core';
import { Component, EventEmitter, Input, OnInit, Output, TemplateRef, ViewEncapsulation, OnDestroy } from '@angular/core';
import { AbstractControl, UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { AuthenticationService } from '../../auth/services/authentication.service';
@ -28,10 +25,7 @@ import { UserPreferencesService } from '../../common/services/user-preferences.s
import { LoginErrorEvent } from '../models/login-error.event';
import { LoginSubmitEvent } from '../models/login-submit.event';
import { LoginSuccessEvent } from '../models/login-success.event';
import {
AppConfigService,
AppConfigValues
} from '../../app-config/app-config.service';
import { AppConfigService, AppConfigValues } from '../../app-config/app-config.service';
import { DomSanitizer, SafeStyle } from '@angular/platform-browser';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@ -136,8 +130,7 @@ export class LoginComponent implements OnInit, OnDestroy {
private userPreferences: UserPreferencesService,
private route: ActivatedRoute,
private sanitizer: DomSanitizer
) {
}
) {}
ngOnInit() {
this.initFormError();
@ -149,12 +142,11 @@ export class LoginComponent implements OnInit, OnDestroy {
if (this.authService.isLoggedIn()) {
this.router.navigate([this.successRoute]);
} else {
if (this.authService.isOauth()) {
const oauth = this.appConfig.oauth2;
if (oauth && oauth.silentLogin) {
if (oauth?.silentLogin) {
this.redirectToImplicitLogin();
} else if (oauth && oauth.implicitFlow) {
} else if (oauth?.implicitFlow) {
this.implicitFlow = true;
}
}
@ -171,9 +163,7 @@ export class LoginComponent implements OnInit, OnDestroy {
this.form = this._fb.group(this.fieldsValidation);
}
this.form.valueChanges
.pipe(takeUntil(this.onDestroy$))
.subscribe(data => this.onValueChanged(data));
this.form.valueChanges.pipe(takeUntil(this.onDestroy$)).subscribe((data) => this.onValueChanged(data));
}
ngOnDestroy() {
@ -193,7 +183,6 @@ export class LoginComponent implements OnInit, OnDestroy {
* Method called on submit form
*
* @param values
* @param event
*/
onSubmit(values: any): void {
this.disableError();
@ -227,14 +216,12 @@ export class LoginComponent implements OnInit, OnDestroy {
if (field) {
this.formError[field] = '';
const hasError =
(this.form.controls[field].errors && data[field] !== '') ||
(this.form.controls[field].dirty &&
!this.form.controls[field].valid);
(this.form.controls[field].errors && data[field] !== '') || (this.form.controls[field].dirty && !this.form.controls[field].valid);
if (hasError) {
for (const key in this.form.controls[field].errors) {
if (key) {
const message = this._message[field][key];
if (message && message.value) {
if (message?.value) {
const translated = this.translateService.instant(message.value, message.params);
this.formError[field] += translated;
}
@ -246,55 +233,40 @@ export class LoginComponent implements OnInit, OnDestroy {
}
performLogin(values: { username: string; password: string }) {
this.authService
.login(values.username, values.password, this.rememberMe)
.subscribe(
(token: any) => {
const redirectUrl = this.authService.getRedirect();
this.authService.login(values.username, values.password, this.rememberMe).subscribe(
(token) => {
const redirectUrl = this.authService.getRedirect();
this.actualLoginStep = LoginSteps.Welcome;
this.userPreferences.setStoragePrefix(values.username);
values.password = null;
this.success.emit(
new LoginSuccessEvent(token, values.username, null)
);
this.actualLoginStep = LoginSteps.Welcome;
this.userPreferences.setStoragePrefix(values.username);
values.password = null;
this.success.emit(new LoginSuccessEvent(token, values.username, null));
if (redirectUrl) {
this.authService.setRedirect(null);
this.router.navigateByUrl(redirectUrl);
} else if (this.successRoute) {
this.router.navigate([this.successRoute]);
}
},
(err: any) => {
this.actualLoginStep = LoginSteps.Landing;
this.displayErrorMessage(err);
this.isError = true;
this.error.emit(new LoginErrorEvent(err));
if (redirectUrl) {
this.authService.setRedirect(null);
this.router.navigateByUrl(redirectUrl);
} else if (this.successRoute) {
this.router.navigate([this.successRoute]);
}
);
},
(err: any) => {
this.actualLoginStep = LoginSteps.Landing;
this.displayErrorMessage(err);
this.isError = true;
this.error.emit(new LoginErrorEvent(err));
}
);
}
/**
* Check and display the right error message in the UI
*/
private displayErrorMessage(err: any): void {
if (
err.error &&
err.error.crossDomain &&
err.error.message.indexOf('Access-Control-Allow-Origin') !== -1
) {
if (err.error?.crossDomain && err.error.message.indexOf('Access-Control-Allow-Origin') !== -1) {
this.errorMsg = err.error.message;
} else if (
err.status === 403 &&
err.message.indexOf('Invalid CSRF-token') !== -1
) {
} else if (err.status === 403 && err.message.indexOf('Invalid CSRF-token') !== -1) {
this.errorMsg = 'LOGIN.MESSAGES.LOGIN-ERROR-CSRF';
} else if (
err.status === 403 &&
err.message.indexOf('The system is currently in read-only mode') !==
-1
) {
} else if (err.status === 403 && err.message.indexOf('The system is currently in read-only mode') !== -1) {
this.errorMsg = 'LOGIN.MESSAGES.LOGIN-ECM-LICENSE';
} else {
this.errorMsg = 'LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS';
@ -317,13 +289,9 @@ export class LoginComponent implements OnInit, OnDestroy {
* @param field
* @param ruleId - i.e. required | minlength | maxlength
* @param msg
* @param params
*/
addCustomValidationError(
field: string,
ruleId: string,
msg: string,
params?: any
) {
addCustomValidationError(field: string, ruleId: string, msg: string, params?: any) {
if (field !== '__proto__' && field !== 'constructor' && field !== 'prototype') {
this._message[field][ruleId] = {
value: msg,
@ -385,7 +353,6 @@ export class LoginComponent implements OnInit, OnDestroy {
minLength: this.minLength
}
}
},
password: {
required: {

View File

@ -20,7 +20,6 @@ import { CookieService } from '../common/services/cookie.service';
@Injectable()
export class CookieServiceMock extends CookieService {
/** @override */
isEnabled(): boolean {
return true;
@ -28,18 +27,18 @@ export class CookieServiceMock extends CookieService {
/** @override */
getItem(key: string): string | null {
return this[key] && this[key].data || null;
return this[key]?.data || null;
}
/** @override */
setItem(key: string, data: string, expiration: Date | null, path: string | null): void {
this[key] = {data, expiration, path};
this[key] = { data, expiration, path };
}
/** @override */
clear() {
Object.keys(this).forEach((key) => {
if (this.hasOwnProperty(key) && typeof(this[key]) !== 'function') {
if (this.hasOwnProperty(key) && typeof this[key] !== 'function') {
this[key] = undefined;
}
});

View File

@ -18,11 +18,11 @@
export class ComponentTranslationModel {
name: string;
path: string;
json: string [];
json: string[];
constructor(obj?: any) {
this.name = obj && obj.name;
this.path = obj && obj.path;
this.json = obj && obj.json || [];
this.name = obj?.name;
this.path = obj?.path;
this.json = obj?.json || [];
}
}

View File

@ -28,7 +28,6 @@ import { takeUntil } from 'rxjs/operators';
pure: false
})
export class DecimalNumberPipe implements PipeTransform, OnDestroy {
static DEFAULT_LOCALE = 'en-US';
static DEFAULT_MIN_INTEGER_DIGITS = 1;
static DEFAULT_MIN_FRACTION_DIGITS = 0;
@ -41,14 +40,11 @@ export class DecimalNumberPipe implements PipeTransform, OnDestroy {
onDestroy$: Subject<boolean> = new Subject<boolean>();
constructor(public userPreferenceService?: UserPreferencesService,
public appConfig?: AppConfigService) {
constructor(public userPreferenceService?: UserPreferencesService, public appConfig?: AppConfigService) {
if (this.userPreferenceService) {
this.userPreferenceService.select(UserPreferenceValues.Locale)
.pipe(
takeUntil(this.onDestroy$)
)
this.userPreferenceService
.select(UserPreferenceValues.Locale)
.pipe(takeUntil(this.onDestroy$))
.subscribe((locale) => {
if (locale) {
this.defaultLocale = locale;
@ -58,15 +54,21 @@ export class DecimalNumberPipe implements PipeTransform, OnDestroy {
if (this.appConfig) {
this.defaultMinIntegerDigits = this.appConfig.get<number>('decimalValues.minIntegerDigits', DecimalNumberPipe.DEFAULT_MIN_INTEGER_DIGITS);
this.defaultMinFractionDigits = this.appConfig.get<number>('decimalValues.minFractionDigits', DecimalNumberPipe.DEFAULT_MIN_FRACTION_DIGITS);
this.defaultMaxFractionDigits = this.appConfig.get<number>('decimalValues.maxFractionDigits', DecimalNumberPipe.DEFAULT_MAX_FRACTION_DIGITS);
this.defaultMinFractionDigits = this.appConfig.get<number>(
'decimalValues.minFractionDigits',
DecimalNumberPipe.DEFAULT_MIN_FRACTION_DIGITS
);
this.defaultMaxFractionDigits = this.appConfig.get<number>(
'decimalValues.maxFractionDigits',
DecimalNumberPipe.DEFAULT_MAX_FRACTION_DIGITS
);
}
}
transform(value: any, digitsInfo?: DecimalNumberModel, locale?: string): any {
const actualMinIntegerDigits: number = digitsInfo && digitsInfo.minIntegerDigits ? digitsInfo.minIntegerDigits : this.defaultMinIntegerDigits;
const actualMinFractionDigits: number = digitsInfo && digitsInfo.minFractionDigits ? digitsInfo.minFractionDigits : this.defaultMinFractionDigits;
const actualMaxFractionDigits: number = digitsInfo && digitsInfo.maxFractionDigits ? digitsInfo.maxFractionDigits : this.defaultMaxFractionDigits;
const actualMinIntegerDigits: number = digitsInfo?.minIntegerDigits ? digitsInfo.minIntegerDigits : this.defaultMinIntegerDigits;
const actualMinFractionDigits: number = digitsInfo?.minFractionDigits ? digitsInfo.minFractionDigits : this.defaultMinFractionDigits;
const actualMaxFractionDigits: number = digitsInfo?.maxFractionDigits ? digitsInfo.maxFractionDigits : this.defaultMaxFractionDigits;
const actualDigitsInfo = `${actualMinIntegerDigits}.${actualMinFractionDigits}-${actualMaxFractionDigits}`;
const actualLocale = locale || this.defaultLocale;

View File

@ -18,17 +18,7 @@
/* eslint-disable @angular-eslint/no-input-rename, @typescript-eslint/no-use-before-define, @angular-eslint/no-input-rename */
import { ENTER, ESCAPE } from '@angular/cdk/keycodes';
import {
ChangeDetectorRef,
Directive,
ElementRef,
forwardRef,
Inject,
Input,
NgZone,
OnDestroy,
Optional
} from '@angular/core';
import { ChangeDetectorRef, Directive, ElementRef, forwardRef, Inject, Input, NgZone, OnDestroy, Optional } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { DOCUMENT } from '@angular/common';
import { Observable, Subject, Subscription, merge, of, fromEvent } from 'rxjs';
@ -71,14 +61,16 @@ export class SearchTriggerDirective implements ControlValueAccessor, OnDestroy {
private closingActionsSubscription: Subscription;
private escapeEventStream = new Subject<void>();
onChange: (value: any) => void = () => { };
onChange: (value: any) => void = () => {};
onTouched = () => { };
onTouched = () => {};
constructor(private element: ElementRef,
private ngZone: NgZone,
private changeDetectorRef: ChangeDetectorRef,
@Optional() @Inject(DOCUMENT) private document: any) { }
constructor(
private element: ElementRef,
private ngZone: NgZone,
private changeDetectorRef: ChangeDetectorRef,
@Optional() @Inject(DOCUMENT) private document: any
) {}
ngOnDestroy() {
this.onDestroy$.next(true);
@ -87,7 +79,7 @@ export class SearchTriggerDirective implements ControlValueAccessor, OnDestroy {
if (this.escapeEventStream) {
this.escapeEventStream = null;
}
if ( this.closingActionsSubscription ) {
if (this.closingActionsSubscription) {
this.closingActionsSubscription.unsubscribe();
}
}
@ -112,10 +104,7 @@ export class SearchTriggerDirective implements ControlValueAccessor, OnDestroy {
}
get panelClosingActions(): Observable<any> {
return merge(
this.escapeEventStream,
this.outsideClickStream
);
return merge(this.escapeEventStream, this.outsideClickStream);
}
private get outsideClickStream(): Observable<any> {
@ -123,10 +112,7 @@ export class SearchTriggerDirective implements ControlValueAccessor, OnDestroy {
return of(null);
}
return merge(
fromEvent(this.document, 'click'),
fromEvent(this.document, 'touchend')
).pipe(
return merge(fromEvent(this.document, 'click'), fromEvent(this.document, 'touchend')).pipe(
filter((event: MouseEvent | TouchEvent) => {
const clickTarget = event.target as HTMLElement;
return this._panelOpen && clickTarget !== this.element.nativeElement;
@ -157,11 +143,10 @@ export class SearchTriggerDirective implements ControlValueAccessor, OnDestroy {
this.escapeEventStream.next();
event.preventDefault();
}
}
handleInput(event: KeyboardEvent): void {
if (document.activeElement === event.target ) {
if (document.activeElement === event.target) {
const inputValue: string = (event.target as HTMLInputElement).value;
this.onChange(inputValue);
if (inputValue && this.searchPanel) {
@ -176,17 +161,15 @@ export class SearchTriggerDirective implements ControlValueAccessor, OnDestroy {
private isPanelOptionClicked(event: MouseEvent) {
let isPanelOption: boolean = false;
if ( event && this.searchPanel ) {
if (event && this.searchPanel) {
const clickTarget = event.target as HTMLElement;
isPanelOption = !this.isNoResultOption() &&
!!this.searchPanel.panel &&
!!this.searchPanel.panel.nativeElement.contains(clickTarget);
isPanelOption = !this.isNoResultOption() && !!this.searchPanel.panel && !!this.searchPanel.panel.nativeElement.contains(clickTarget);
}
return isPanelOption;
}
private isNoResultOption(): boolean {
return this.searchPanel && this.searchPanel.results.list ? this.searchPanel.results.list.entries.length === 0 : true;
return this.searchPanel?.results?.list ? this.searchPanel.results.list.entries.length === 0 : true;
}
private subscribeToClosingActions(): Subscription {
@ -205,8 +188,7 @@ export class SearchTriggerDirective implements ControlValueAccessor, OnDestroy {
}
private setTriggerValue(value: any): void {
const toDisplay = this.searchPanel && this.searchPanel.displayWith ?
this.searchPanel.displayWith(value) : value;
const toDisplay = this.searchPanel?.displayWith ? this.searchPanel.displayWith(value) : value;
const inputValue = toDisplay != null ? toDisplay : '';
this.element.nativeElement.value = inputValue;
}

View File

@ -27,15 +27,13 @@ import { map, catchError, retry } from 'rxjs/operators';
providedIn: 'root'
})
export class TranslateLoaderService implements TranslateLoader {
private prefix: string = 'i18n';
private suffix: string = '.json';
private providers: ComponentTranslationModel[] = [];
private queue: string [][] = [];
private queue: string[][] = [];
private defaultLang: string = 'en';
constructor(private http: HttpClient) {
}
constructor(private http: HttpClient) {}
setDefaultLang(value: string) {
this.defaultLang = value || 'en';
@ -51,7 +49,7 @@ export class TranslateLoaderService implements TranslateLoader {
}
providerRegistered(name: string): boolean {
return this.providers.find((x) => x.name === name) ? true : false;
return !!this.providers.find((x) => x.name === name);
}
fetchLanguageFile(lang: string, component: ComponentTranslationModel, fallbackUrl?: string): Observable<void> {
@ -86,9 +84,7 @@ export class TranslateLoaderService implements TranslateLoader {
if (!this.isComponentInQueue(lang, component.name)) {
this.queue[lang].push(component.name);
observableBatch.push(
this.fetchLanguageFile(lang, component)
);
observableBatch.push(this.fetchLanguageFile(lang, component));
}
});
@ -102,7 +98,7 @@ export class TranslateLoaderService implements TranslateLoader {
}
isComponentInQueue(lang: string, name: string) {
return (this.queue[lang] || []).find((x) => x === name) ? true : false;
return !!(this.queue[lang] || []).find((x) => x === name);
}
getFullTranslationJSON(lang: string): any {
@ -120,7 +116,7 @@ export class TranslateLoaderService implements TranslateLoader {
return a.name.localeCompare(b.name);
})
.forEach((model) => {
if (model.json && model.json[lang]) {
if (model.json?.[lang]) {
result = ObjectUtils.merge(result, model.json[lang]);
}
});
@ -131,16 +127,17 @@ export class TranslateLoaderService implements TranslateLoader {
getTranslation(lang: string): Observable<any> {
let hasFailures = false;
const batch = [
...this.getComponentToFetch(lang).map((observable) => observable.pipe(
catchError((error) => {
hasFailures = true;
return of(error);
})
))
...this.getComponentToFetch(lang).map((observable) =>
observable.pipe(
catchError((error) => {
hasFailures = true;
return of(error);
})
)
)
];
return new Observable((observer) => {
if (batch.length > 0) {
forkJoin(batch).subscribe(
() => {
@ -156,7 +153,8 @@ export class TranslateLoaderService implements TranslateLoader {
},
() => {
observer.error('Failed to load some resources');
});
}
);
} else {
const fullTranslation = this.getFullTranslationJSON(lang);
if (fullTranslation) {

View File

@ -23,7 +23,11 @@ import {
ViewEncapsulation,
ElementRef,
Output,
EventEmitter, AfterViewInit, ViewChild, HostListener, OnDestroy
EventEmitter,
AfterViewInit,
ViewChild,
HostListener,
OnDestroy
} from '@angular/core';
import { AppConfigService } from '../../app-config/app-config.service';
import { UrlService } from '../../common/services/url.service';
@ -37,7 +41,6 @@ import Cropper from 'cropperjs';
encapsulation: ViewEncapsulation.None
})
export class ImgViewerComponent implements AfterViewInit, OnChanges, OnDestroy {
@Input()
showToolbar = true;
@ -64,7 +67,7 @@ export class ImgViewerComponent implements AfterViewInit, OnChanges, OnDestroy {
@Output()
isSaving = new EventEmitter<boolean>();
@ViewChild('image', { static: false})
@ViewChild('image', { static: false })
public imageElement: ElementRef;
public scale: number = 1.0;
@ -75,10 +78,7 @@ export class ImgViewerComponent implements AfterViewInit, OnChanges, OnDestroy {
return Math.round(this.scale * 100) + '%';
}
constructor(
private appConfigService: AppConfigService,
private urlService: UrlService
) {
constructor(private appConfigService: AppConfigService, private urlService: UrlService) {
this.initializeScaling();
}
@ -143,14 +143,14 @@ export class ImgViewerComponent implements AfterViewInit, OnChanges, OnDestroy {
@HostListener('document:fullscreenchange')
fullScreenChangeHandler() {
if(document.fullscreenElement) {
if (document.fullscreenElement) {
this.reset();
}
}
ngOnChanges(changes: SimpleChanges) {
const blobFile = changes['blobFile'];
if (blobFile && blobFile.currentValue) {
if (blobFile?.currentValue) {
this.urlFile = this.urlService.createTrustedUrl(this.blobFile);
return;
}
@ -167,20 +167,20 @@ export class ImgViewerComponent implements AfterViewInit, OnChanges, OnDestroy {
}
zoomIn() {
this.cropper.zoom( 0.2);
this.scale = +((this.scale + 0.2).toFixed(1));
this.cropper.zoom(0.2);
this.scale = +(this.scale + 0.2).toFixed(1);
}
zoomOut() {
if (this.scale > 0.2) {
this.cropper.zoom( -0.2 );
this.scale = +((this.scale - 0.2).toFixed(1));
this.cropper.zoom(-0.2);
this.scale = +(this.scale - 0.2).toFixed(1);
}
}
rotateImage() {
this.isEditing = true;
this.cropper.rotate( -90);
this.cropper.rotate(-90);
}
cropImage() {

View File

@ -23,11 +23,10 @@ import { UrlService } from '../../common/services/url.service';
selector: 'adf-media-player',
templateUrl: './media-player.component.html',
styleUrls: ['./media-player.component.scss'],
host: {class: 'adf-media-player'},
host: { class: 'adf-media-player' },
encapsulation: ViewEncapsulation.None
})
export class MediaPlayerComponent implements OnChanges {
@Input()
urlFile: string;
@ -47,13 +46,12 @@ export class MediaPlayerComponent implements OnChanges {
@Output()
error = new EventEmitter<any>();
constructor(private urlService: UrlService) {
}
constructor(private urlService: UrlService) {}
ngOnChanges(changes: SimpleChanges) {
const blobFile = changes['blobFile'];
if (blobFile && blobFile.currentValue) {
if (blobFile?.currentValue) {
this.urlFile = this.urlService.createTrustedUrl(this.blobFile);
return;
}

View File

@ -48,11 +48,10 @@ declare const pdfjsViewer: any;
templateUrl: './pdf-viewer.component.html',
styleUrls: ['./pdf-viewer-host.component.scss', './pdf-viewer.component.scss'],
providers: [RenderingQueueServices],
host: {class: 'adf-pdf-viewer'},
host: { class: 'adf-pdf-viewer' },
encapsulation: ViewEncapsulation.None
})
export class PdfViewerComponent implements OnChanges, OnDestroy {
@Input()
urlFile: string;
@ -98,7 +97,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
loadingTask: any;
isPanelDisabled = true;
showThumbnails: boolean = false;
pdfThumbnailsContext: { viewer: any } = {viewer: null};
pdfThumbnailsContext: { viewer: any } = { viewer: null };
randomPdfId: string;
get currentScaleText(): string {
@ -119,13 +118,19 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
private dialog: MatDialog,
private renderingQueueServices: RenderingQueueServices,
private logService: LogService,
private appConfigService: AppConfigService) {
private appConfigService: AppConfigService
) {
// needed to preserve "this" context
this.onPageChange = this.onPageChange.bind(this);
this.onPagesLoaded = this.onPagesLoaded.bind(this);
this.onPageRendered = this.onPageRendered.bind(this);
this.randomPdfId = this.generateUuid();
this.pdfjsWorkerDestroy$.pipe(catchError(() => null), delay(700)).subscribe(() => this.destroyPdJsWorker());
this.randomPdfId = window.crypto.randomUUID();
this.pdfjsWorkerDestroy$
.pipe(
catchError(() => null),
delay(700)
)
.subscribe(() => this.destroyPdJsWorker());
}
getUserScaling(): number {
@ -152,7 +157,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
ngOnChanges(changes: SimpleChanges) {
const blobFile = changes['blobFile'];
if (blobFile && blobFile.currentValue) {
if (blobFile?.currentValue) {
const reader = new FileReader();
reader.onload = async () => {
const pdfOptions = {
@ -166,7 +171,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
}
const urlFile = changes['urlFile'];
if (urlFile && urlFile.currentValue) {
if (urlFile?.currentValue) {
const pdfOptions = {
...this.pdfjsDefaultOptions,
url: urlFile.currentValue,
@ -200,14 +205,15 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
this.loadingPercent = Math.round(level * 100);
};
this.loadingTask.promise.then((pdfDocument: PDFDocumentProxy) => {
this.totalPages = pdfDocument.numPages;
this.page = 1;
this.displayPage = 1;
this.initPDFViewer(pdfDocument);
this.loadingTask.promise
.then((pdfDocument: PDFDocumentProxy) => {
this.totalPages = pdfDocument.numPages;
this.page = 1;
this.displayPage = 1;
this.initPDFViewer(pdfDocument);
return pdfDocument.getPage(1);
})
return pdfDocument.getPage(1);
})
.then(() => this.scalePage('init'))
.catch(() => this.error.emit());
}
@ -276,9 +282,8 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
const documentContainer = this.getDocumentContainer();
if (this.pdfViewer && documentContainer) {
let widthContainer;
let heightContainer;
let widthContainer: number;
let heightContainer: number;
if (viewerContainer && viewerContainer.clientWidth <= documentContainer.clientWidth) {
widthContainer = viewerContainer.clientWidth;
@ -291,10 +296,10 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
const currentPage = this.pdfViewer._pages[this.pdfViewer._currentPageNumber - 1];
const padding = 20;
const pageWidthScale = (widthContainer - padding) / currentPage.width * currentPage.scale;
const pageHeightScale = (heightContainer - padding) / currentPage.width * currentPage.scale;
const pageWidthScale = ((widthContainer - padding) / currentPage.width) * currentPage.scale;
const pageHeightScale = ((heightContainer - padding) / currentPage.width) * currentPage.scale;
let scale;
let scale: number;
switch (this.currentScaleMode) {
case 'init':
scale = this.getUserScaling();
@ -322,7 +327,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
break;
default:
this.logService.error('pdfViewSetScale: \'' + scaleMode + '\' is an unknown zoom value.');
this.logService.error(`pdfViewSetScale: '${scaleMode}' is an unknown zoom value.`);
return;
}
@ -331,7 +336,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
}
private autoScaling(pageHeightScale: number, pageWidthScale: number) {
let horizontalScale;
let horizontalScale: number;
if (this.isLandscape) {
horizontalScale = Math.min(pageHeightScale, pageWidthScale);
} else {
@ -387,7 +392,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
*
*/
isSameScale(oldScale: number, newScale: number): boolean {
return (newScale === oldScale);
return newScale === oldScale;
}
/**
@ -397,7 +402,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
* @param height
*/
isLandscape(width: number, height: number): boolean {
return (width > height);
return width > height;
}
/**
@ -507,15 +512,16 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
this.dialog
.open(PdfPasswordDialogComponent, {
width: '400px',
data: {reason}
data: { reason }
})
.afterClosed().subscribe((password) => {
if (password) {
callback(password);
} else {
this.close.emit();
}
});
.afterClosed()
.subscribe((password) => {
if (password) {
callback(password);
} else {
this.close.emit();
}
});
}
/**
@ -528,7 +534,6 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
/**
* Pages Loaded Event
*
* @param event
*/
onPagesLoaded() {
this.isPanelDisabled = false;
@ -537,23 +542,17 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
/**
* Keyboard Event Listener
*
* @param KeyboardEvent event
* @param event KeyboardEvent
*/
@HostListener('document:keydown', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
const key = event.keyCode;
if (key === 39) { // right arrow
if (key === 39) {
// right arrow
this.nextPage();
} else if (key === 37) {// left arrow
} else if (key === 37) {
// left arrow
this.previousPage();
}
}
private generateUuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = Math.random() * 16 | 0;
const v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
}

View File

@ -27,7 +27,6 @@ import { AppConfigService } from '../../app-config/app-config.service';
encapsulation: ViewEncapsulation.None
})
export class TxtViewerComponent implements OnChanges {
@Input()
urlFile: any;
@ -36,18 +35,16 @@ export class TxtViewerComponent implements OnChanges {
content: string | ArrayBuffer;
constructor(private http: HttpClient, private appConfigService: AppConfigService) {
}
constructor(private http: HttpClient, private appConfigService: AppConfigService) {}
ngOnChanges(changes: SimpleChanges): Promise<void> {
const blobFile = changes['blobFile'];
if (blobFile && blobFile.currentValue) {
if (blobFile?.currentValue) {
return this.readBlob(blobFile.currentValue);
}
const urlFile = changes['urlFile'];
if (urlFile && urlFile.currentValue) {
if (urlFile?.currentValue) {
return this.getUrlContent(urlFile.currentValue);
}
@ -62,12 +59,15 @@ export class TxtViewerComponent implements OnChanges {
const withCredentialsMode = this.appConfigService.get<boolean>('auth.withCredentials', false);
return new Promise((resolve, reject) => {
this.http.get(url, { responseType: 'text', withCredentials: withCredentialsMode }).subscribe((res) => {
this.content = res;
resolve();
}, (event) => {
reject(event);
});
this.http.get(url, { responseType: 'text', withCredentials: withCredentialsMode }).subscribe(
(res) => {
this.content = res;
resolve();
},
(event) => {
reject(event);
}
);
});
}

View File

@ -54,12 +54,11 @@ const DEFAULT_NON_PREVIEW_CONFIG = {
selector: 'adf-viewer',
templateUrl: './viewer.component.html',
styleUrls: ['./viewer.component.scss'],
host: {class: 'adf-viewer'},
host: { class: 'adf-viewer' },
encapsulation: ViewEncapsulation.None,
providers: [ViewUtilService]
})
export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
@ContentChild(ViewerToolbarComponent)
toolbar: ViewerToolbarComponent;
@ -220,24 +219,23 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
public downloadPromptTimer: number;
public downloadPromptReminderTimer: number;
constructor(private el: ElementRef,
public dialog: MatDialog,
private viewUtilsService: ViewUtilService,
private appConfigService: AppConfigService
) {
}
constructor(
private el: ElementRef,
public dialog: MatDialog,
private viewUtilsService: ViewUtilService,
private appConfigService: AppConfigService
) {}
ngOnChanges(changes: SimpleChanges){
ngOnChanges(changes: SimpleChanges) {
const { blobFile, urlFile } = changes;
if(blobFile?.currentValue){
if (blobFile?.currentValue) {
this.mimeType = blobFile.currentValue.type;
}
if(urlFile?.currentValue){
if (urlFile?.currentValue) {
this.fileName = this.fileName ? this.fileName : this.viewUtilsService.getFilenameFromUrl(urlFile.currentValue);
}
}
ngOnInit(): void {
@ -246,27 +244,33 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
}
private closeOverlayManager() {
this.dialog.afterOpened.pipe(
skipWhile(() => !this.overlayMode),
takeUntil(this.onDestroy$)
).subscribe(() => this.closeViewer = false);
this.dialog.afterOpened
.pipe(
skipWhile(() => !this.overlayMode),
takeUntil(this.onDestroy$)
)
.subscribe(() => (this.closeViewer = false));
this.dialog.afterAllClosed.pipe(
skipWhile(() => !this.overlayMode),
takeUntil(this.onDestroy$)
).subscribe(() => this.closeViewer = true);
this.dialog.afterAllClosed
.pipe(
skipWhile(() => !this.overlayMode),
takeUntil(this.onDestroy$)
)
.subscribe(() => (this.closeViewer = true));
this.keyDown$.pipe(
skipWhile(() => !this.overlayMode),
filter((e: KeyboardEvent) => e.keyCode === 27),
takeUntil(this.onDestroy$)
).subscribe((event: KeyboardEvent) => {
event.preventDefault();
this.keyDown$
.pipe(
skipWhile(() => !this.overlayMode),
filter((e: KeyboardEvent) => e.keyCode === 27),
takeUntil(this.onDestroy$)
)
.subscribe((event: KeyboardEvent) => {
event.preventDefault();
if (this.closeViewer) {
this.onClose();
}
});
if (this.closeViewer) {
this.onClose();
}
});
}
onNavigateBeforeClick(event: MouseEvent | KeyboardEvent) {
@ -295,7 +299,7 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
@HostListener('document:keyup', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) {
if (event && event.defaultPrevented) {
if (event?.defaultPrevented) {
return;
}
@ -392,20 +396,24 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
private showDownloadPrompt() {
if (!this.isDialogVisible) {
this.isDialogVisible = true;
this.dialog.open(DownloadPromptDialogComponent, { disableClose: true }).afterClosed().pipe(first()).subscribe((result: DownloadPromptActions) => {
this.isDialogVisible = false;
if (result === DownloadPromptActions.DOWNLOAD) {
this.downloadFile.emit();
this.onClose();
} else if (result === DownloadPromptActions.WAIT) {
if (this.enableDownloadPromptReminder) {
this.clearDownloadPromptTimeouts();
this.downloadPromptReminderTimer = window.setTimeout(() => {
this.showOrClearDownloadPrompt();
}, this.downloadPromptReminderDelay * 1000);
this.dialog
.open(DownloadPromptDialogComponent, { disableClose: true })
.afterClosed()
.pipe(first())
.subscribe((result: DownloadPromptActions) => {
this.isDialogVisible = false;
if (result === DownloadPromptActions.DOWNLOAD) {
this.downloadFile.emit();
this.onClose();
} else if (result === DownloadPromptActions.WAIT) {
if (this.enableDownloadPromptReminder) {
this.clearDownloadPromptTimeouts();
this.downloadPromptReminderTimer = window.setTimeout(() => {
this.showOrClearDownloadPrompt();
}, this.downloadPromptReminderDelay * 1000);
}
}
}
});
});
}
}
}

View File

@ -2,6 +2,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"declarationMap": true,
"paths": {
"@alfresco/adf-extensions": ["../../../dist/libs/extensions"],

Some files were not shown because too many files have changed in this diff Show More