mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
Add fullName pipe and change example (#3946)
This commit is contained in:
parent
c885f6d303
commit
0ee592607a
@ -169,6 +169,11 @@
|
||||
#taskList>
|
||||
<data-columns>
|
||||
<data-column key="id" title="Id"></data-column>
|
||||
<data-column key="assignee" title="Assignee" class="full-width name-column">
|
||||
<ng-template let-entry="$implicit">
|
||||
<div>{{entry.row.obj.assignee | fullName}}</div>
|
||||
</ng-template>
|
||||
</data-column>
|
||||
<data-column key="name" title="Name"></data-column>
|
||||
<data-column key="description" title="Description"></data-column>
|
||||
<data-column key="created" title="Created"></data-column>
|
||||
|
@ -139,7 +139,7 @@ information defined in `app.config.json` as in the example below:
|
||||
<data-columns>
|
||||
<data-column key="key" title="title" class="full-width name-column">
|
||||
<ng-template let-entry="$implicit">
|
||||
<div>{{getFullName(entry.row.obj.assignee)}}</div>
|
||||
<div>{{entry.row.obj.assignee | fullName}}</div>
|
||||
</ng-template>
|
||||
</data-column>
|
||||
</data-columns>
|
||||
|
@ -162,7 +162,7 @@ You can use an HTML-based schema and an `app.config.json` custom schema declarat
|
||||
<data-columns>
|
||||
<data-column key="assignee" title="Assignee" class="full-width name-column">
|
||||
<ng-template let-entry="$implicit">
|
||||
<div>{{getFullName(entry.row.obj.assignee)}}</div>
|
||||
<div>{{entry.row.obj.assignee | fullName}}</div>
|
||||
</ng-template>
|
||||
</data-column>
|
||||
</data-columns>
|
||||
|
48
lib/core/pipes/full-name.pipe.spec.ts
Normal file
48
lib/core/pipes/full-name.pipe.spec.ts
Normal file
@ -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');
|
||||
});
|
||||
});
|
35
lib/core/pipes/full-name.pipe.ts
Normal file
35
lib/core/pipes/full-name.pipe.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -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
|
||||
]
|
||||
})
|
||||
|
@ -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';
|
||||
|
@ -463,7 +463,7 @@ describe('ProcessInstanceListComponent', () => {
|
||||
<data-column key="created" title="ADF_PROCESS_LIST.PROPERTIES.END_DATE" class="hidden"></data-column>
|
||||
<data-column key="startedBy" title="ADF_PROCESS_LIST.PROPERTIES.CREATED" class="desktop-only dw-dt-col-3 ellipsis-cell">
|
||||
<ng-template let-entry="$implicit">
|
||||
<div>{{getFullName(entry.row.obj.startedBy)}}</div>
|
||||
<div>{{entry.row.obj.startedBy | fullName}}</div>
|
||||
</ng-template>
|
||||
</data-column>
|
||||
</data-columns>
|
||||
|
@ -520,7 +520,7 @@ describe('TaskListComponent', () => {
|
||||
<data-column key="created" title="ADF_TASK_LIST.PROPERTIES.CREATED" class="hidden"></data-column>
|
||||
<data-column key="startedBy" title="ADF_TASK_LIST.PROPERTIES.CREATED" class="desktop-only dw-dt-col-3 ellipsis-cell">
|
||||
<ng-template let-entry="$implicit">
|
||||
<div>{{getFullName(entry.row.obj.startedBy)}}</div>
|
||||
<div>{{entry.row.obj.startedBy | fullName}}</div>
|
||||
</ng-template>
|
||||
</data-column>
|
||||
</data-columns>
|
||||
|
Loading…
x
Reference in New Issue
Block a user