[AAE-10776] NodeNameTooltipPipe moved in content service pkg (#8048)

* NodeNameTooltipPipe moved in content service pkg

* [ci:force] fix lint and build
This commit is contained in:
Eugenio Romano
2022-12-19 16:17:02 +00:00
committed by GitHub
parent 7fa5c0faa6
commit 9077572199
12 changed files with 110 additions and 7 deletions

View File

@@ -44,9 +44,11 @@ import { AspectListModule } from './aspect-list/aspect-list.module';
import { VersionCompatibilityModule } from './version-compatibility/version-compatibility.module';
import { versionCompatibilityFactory } from './version-compatibility/version-compatibility-factory';
import { VersionCompatibilityService } from './version-compatibility/version-compatibility.service';
import { ContentPipeModule } from './pipes/content-pipe.module';
@NgModule({
imports: [
ContentPipeModule,
CoreModule,
SocialModule,
TagModule,
@@ -84,6 +86,7 @@ import { VersionCompatibilityService } from './version-compatibility/version-com
}
],
exports: [
ContentPipeModule,
SocialModule,
TagModule,
WebScriptModule,

View File

@@ -22,6 +22,8 @@ import { CoreModule, EditJsonDialogModule } from '@alfresco/adf-core';
import { MaterialModule } from '../material.module';
import { UploadModule } from '../upload/upload.module';
import { ContentPipeModule } from '../pipes/content-pipe.module';
import { SearchModule } from './../search/search.module';
import { ContentActionListComponent } from './components/content-action/content-action-list.component';
import { ContentActionComponent } from './components/content-action/content-action.component';
@@ -33,12 +35,12 @@ import { LibraryRoleColumnComponent } from './components/library-role-column/lib
import { LibraryNameColumnComponent } from './components/library-name-column/library-name-column.component';
import { NameColumnComponent } from './components/name-column/name-column.component';
import { FilterHeaderComponent } from './components/filter-header/filter-header.component';
import { SearchModule } from './../search/search.module';
@NgModule({
imports: [
CoreModule,
CommonModule,
ContentPipeModule,
FlexLayoutModule,
MaterialModule,
UploadModule,

View File

@@ -0,0 +1,39 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* 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.
*/
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { NodeNameTooltipPipe } from './node-name-tooltip.pipe';
import { TranslateModule } from '@ngx-translate/core';
@NgModule({
imports: [
CommonModule,
TranslateModule
],
declarations: [
NodeNameTooltipPipe
],
providers: [
NodeNameTooltipPipe
],
exports: [
NodeNameTooltipPipe
]
})
export class ContentPipeModule {
}

View File

@@ -0,0 +1,18 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* 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.
*/
export * from './public-api';

View File

@@ -0,0 +1,145 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* 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.
*/
import { NodeEntry } from '@alfresco/js-api';
import { NodeNameTooltipPipe } from './node-name-tooltip.pipe';
describe('NodeNameTooltipPipe', () => {
const nodeName = 'node-name';
const nodeTitle = 'node-title';
const nodeDescription = 'node-description';
let pipe: NodeNameTooltipPipe;
beforeEach(() => {
pipe = new NodeNameTooltipPipe();
});
it('should not transform when missing node', () => {
expect(pipe.transform(null)).toBe(null);
});
it('should not transform when missing node entry', () => {
expect(pipe.transform({} as any)).toBe(null);
});
it('should use title and description when all fields present', () => {
const node: any = {
entry: {
name: nodeName,
properties: {
'cm:title': nodeTitle,
'cm:description': nodeDescription
}
}
};
const tooltip = pipe.transform(node);
expect(tooltip).toBe(`${nodeTitle}\n${nodeDescription}`);
});
it('should use name when other properties are missing', () => {
const node = {
entry: {
name: nodeName
}
} as NodeEntry;
const tooltip = pipe.transform(node);
expect(tooltip).toBe(nodeName);
});
it('should display name when title and description are missing', () => {
const node: any = {
entry: {
name: nodeName,
properties: {}
}
};
const tooltip = pipe.transform(node);
expect(tooltip).toBe(nodeName);
});
it('should use name and description when title is missing', () => {
const node: any = {
entry: {
name: nodeName,
properties: {
'cm:title': null,
'cm:description': nodeDescription
}
}
};
const tooltip = pipe.transform(node);
expect(tooltip).toBe(`${nodeName}\n${nodeDescription}`);
});
it('should use name and title when description is missing', () => {
const node: any = {
entry: {
name: nodeName,
properties: {
'cm:title': nodeTitle,
'cm:description': null
}
}
};
const tooltip = pipe.transform(node);
expect(tooltip).toBe(`${nodeName}\n${nodeTitle}`);
});
it('should use name if name and description are the same', () => {
const node: any = {
entry: {
name: nodeName,
properties: {
'cm:title': null,
'cm:description': nodeName
}
}
};
const tooltip = pipe.transform(node);
expect(tooltip).toBe(nodeName);
});
it('should use name if name and title are the same', () => {
const node: any = {
entry: {
name: nodeName,
properties: {
'cm:title': nodeName,
'cm:description': null
}
}
};
const tooltip = pipe.transform(node);
expect(tooltip).toBe(nodeName);
});
it('should use name if all values are the same', () => {
const node: any = {
entry: {
name: nodeName,
properties: {
'cm:title': nodeName,
'cm:description': nodeName
}
}
};
const tooltip = pipe.transform(node);
expect(tooltip).toBe(nodeName);
});
});

View File

@@ -0,0 +1,78 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* 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.
*/
import { Pipe, PipeTransform } from '@angular/core';
import { NodeEntry } from '@alfresco/js-api';
@Pipe({
name: 'adfNodeNameTooltip'
})
export class NodeNameTooltipPipe implements PipeTransform {
transform(node: NodeEntry): string {
if (node) {
return this.getNodeTooltip(node);
}
return null;
}
private containsLine(lines: string[], line: string): boolean {
return lines.some((item: string) => item.toLowerCase() === line.toLowerCase());
}
private removeDuplicateLines(lines: string[]): string[] {
const reducer = (acc: string[], line: string): string[] => {
if (!this.containsLine(acc, line)) {
acc.push(line);
}
return acc;
};
return lines.reduce(reducer, []);
}
private getNodeTooltip(node: NodeEntry): string {
if (!node || !node.entry) {
return null;
}
const { entry: { properties, name } } = node;
const lines = [ name ];
if (properties) {
const {
'cm:title': title,
'cm:description': description
} = properties;
if (title && description) {
lines[0] = title;
lines[1] = description;
}
if (title) {
lines[1] = title;
}
if (description) {
lines[1] = description;
}
}
return this.removeDuplicateLines(lines).join(`\n`);
}
}

View File

@@ -0,0 +1,19 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* 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.
*/
export * from './node-name-tooltip.pipe';
export * from './content-pipe.module';

View File

@@ -38,6 +38,7 @@ export * from './lib/content-type/index';
export * from './lib/new-version-uploader';
export * from './lib/interfaces/index';
export * from './lib/version-compatibility/index';
export * from './lib/pipes/index';
export * from './lib/services/index';
export * from './lib/content.module';