From 0ee592607a44bda320dd3baf75353cd111d7d044 Mon Sep 17 00:00:00 2001 From: Maurizio Vitale Date: Wed, 7 Nov 2018 19:26:13 +0000 Subject: [PATCH] Add fullName pipe and change example (#3946) --- .../task-list-demo.component.html | 5 ++ .../process-list.component.md | 2 +- docs/process-services/task-list.component.md | 2 +- lib/core/pipes/full-name.pipe.spec.ts | 48 +++++++++++++++++++ lib/core/pipes/full-name.pipe.ts | 35 ++++++++++++++ lib/core/pipes/pipe.module.ts | 3 ++ lib/core/pipes/public-api.ts | 1 + .../components/process-list.component.spec.ts | 2 +- .../components/task-list.component.spec.ts | 2 +- 9 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 lib/core/pipes/full-name.pipe.spec.ts create mode 100644 lib/core/pipes/full-name.pipe.ts diff --git a/demo-shell/src/app/components/task-list-demo/task-list-demo.component.html b/demo-shell/src/app/components/task-list-demo/task-list-demo.component.html index b4eac64779..10baf72c96 100644 --- a/demo-shell/src/app/components/task-list-demo/task-list-demo.component.html +++ b/demo-shell/src/app/components/task-list-demo/task-list-demo.component.html @@ -169,6 +169,11 @@ #taskList> + + +
{{entry.row.obj.assignee | fullName}}
+
+
diff --git a/docs/process-services/process-list.component.md b/docs/process-services/process-list.component.md index cc907366ed..2f5218b276 100644 --- a/docs/process-services/process-list.component.md +++ b/docs/process-services/process-list.component.md @@ -139,7 +139,7 @@ information defined in `app.config.json` as in the example below: -
{{getFullName(entry.row.obj.assignee)}}
+
{{entry.row.obj.assignee | fullName}}
diff --git a/docs/process-services/task-list.component.md b/docs/process-services/task-list.component.md index 6ff3e61b42..ee5eb81a50 100644 --- a/docs/process-services/task-list.component.md +++ b/docs/process-services/task-list.component.md @@ -162,7 +162,7 @@ You can use an HTML-based schema and an `app.config.json` custom schema declarat -
{{getFullName(entry.row.obj.assignee)}}
+
{{entry.row.obj.assignee | fullName}}
diff --git a/lib/core/pipes/full-name.pipe.spec.ts b/lib/core/pipes/full-name.pipe.spec.ts new file mode 100644 index 0000000000..b6ed581f4b --- /dev/null +++ b/lib/core/pipes/full-name.pipe.spec.ts @@ -0,0 +1,48 @@ +/*! + * @license + * Copyright 2016 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 { FullNamePipe } from './full-name.pipe'; +import { async } from '@angular/core/testing'; + +describe('FullNamePipe', () => { + + let pipe: FullNamePipe; + + beforeEach(async(() => { + pipe = new FullNamePipe(); + })); + + it('should return empty string when there is no name', () => { + const user = {}; + expect(pipe.transform(user)).toBe(''); + }); + + it('should return only firstName as fullName when there is no lastName ', () => { + const user = {firstName : 'Abc'}; + expect(pipe.transform(user)).toBe('Abc'); + }); + + it('should return only lastName as fullName when there is no firstName ', () => { + const user = {lastName : 'Xyz'}; + expect(pipe.transform(user)).toBe('Xyz'); + }); + + it('should return fullName when firstName and lastName are available', () => { + const user = {firstName : 'Abc', lastName : 'Xyz'}; + expect(pipe.transform(user)).toBe('Abc Xyz'); + }); +}); diff --git a/lib/core/pipes/full-name.pipe.ts b/lib/core/pipes/full-name.pipe.ts new file mode 100644 index 0000000000..10e27a499a --- /dev/null +++ b/lib/core/pipes/full-name.pipe.ts @@ -0,0 +1,35 @@ +/*! + * @license + * Copyright 2016 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'; + +@Pipe({ name: 'fullName' }) +export class FullNamePipe implements PipeTransform { + transform(user: any): string { + let fullName = ''; + if (user) { + if (user.firstName) { + fullName += user.firstName; + } + if (user.lastName) { + fullName += fullName.length > 0 ? ' ' : ''; + fullName += user.lastName; + } + } + return fullName; + } +} diff --git a/lib/core/pipes/pipe.module.ts b/lib/core/pipes/pipe.module.ts index 2b71703d1a..e9e7fbdc38 100644 --- a/lib/core/pipes/pipe.module.ts +++ b/lib/core/pipes/pipe.module.ts @@ -24,6 +24,7 @@ import { NodeNameTooltipPipe } from './node-name-tooltip.pipe'; import { HighlightPipe } from './text-highlight.pipe'; import { TimeAgoPipe } from './time-ago.pipe'; import { InitialUsernamePipe } from './user-initial.pipe'; +import { FullNamePipe } from './full-name.pipe'; @NgModule({ imports: [ @@ -35,6 +36,7 @@ import { InitialUsernamePipe } from './user-initial.pipe'; TimeAgoPipe, MimeTypeIconPipe, InitialUsernamePipe, + FullNamePipe, NodeNameTooltipPipe ], providers: [ @@ -51,6 +53,7 @@ import { InitialUsernamePipe } from './user-initial.pipe'; TimeAgoPipe, MimeTypeIconPipe, InitialUsernamePipe, + FullNamePipe, NodeNameTooltipPipe ] }) diff --git a/lib/core/pipes/public-api.ts b/lib/core/pipes/public-api.ts index 3ff5d5af91..6d3a4c16de 100644 --- a/lib/core/pipes/public-api.ts +++ b/lib/core/pipes/public-api.ts @@ -21,5 +21,6 @@ export * from './node-name-tooltip.pipe'; export * from './text-highlight.pipe'; export * from './time-ago.pipe'; export * from './user-initial.pipe'; +export * from './full-name.pipe'; export * from './pipe.module'; diff --git a/lib/process-services/process-list/components/process-list.component.spec.ts b/lib/process-services/process-list/components/process-list.component.spec.ts index db27e934df..0628999770 100644 --- a/lib/process-services/process-list/components/process-list.component.spec.ts +++ b/lib/process-services/process-list/components/process-list.component.spec.ts @@ -463,7 +463,7 @@ describe('ProcessInstanceListComponent', () => { -
{{getFullName(entry.row.obj.startedBy)}}
+
{{entry.row.obj.startedBy | fullName}}
diff --git a/lib/process-services/task-list/components/task-list.component.spec.ts b/lib/process-services/task-list/components/task-list.component.spec.ts index af8834aec1..fda5266109 100644 --- a/lib/process-services/task-list/components/task-list.component.spec.ts +++ b/lib/process-services/task-list/components/task-list.component.spec.ts @@ -520,7 +520,7 @@ describe('TaskListComponent', () => { -
{{getFullName(entry.row.obj.startedBy)}}
+
{{entry.row.obj.startedBy | fullName}}