mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-1404] Data Column enhancements for Document List (#2220)
* support 'timeAgo' format for data-column * file size column type and bug fixes * readme updates * location column type * readme fixes * update unit tests * file size pipe tests
This commit is contained in:
committed by
Mario Romano
parent
9e5b19e34c
commit
06e03ad1e9
@@ -126,6 +126,7 @@ export { ContextMenuModule } from './src/components/context-menu/context-menu.mo
|
||||
export { CardViewModule } from './src/components/view/card-view.module';
|
||||
export { CollapsableModule } from './src/components/collapsable/collapsable.module';
|
||||
export { CardViewItem } from './src/interface/card-view-item.interface';
|
||||
export { TimeAgoPipe } from './src/pipes/time-ago.pipe';
|
||||
|
||||
export * from './src/components/data-column/data-column.component';
|
||||
export * from './src/components/data-column/data-column-list.component';
|
||||
|
@@ -0,0 +1,75 @@
|
||||
/*!
|
||||
* @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 { FileSizePipe } from './file-size.pipe';
|
||||
|
||||
describe('FileSizePipe', () => {
|
||||
|
||||
let pipe: FileSizePipe;
|
||||
|
||||
beforeEach(() => {
|
||||
pipe = new FileSizePipe();
|
||||
});
|
||||
|
||||
it('returns empty string with invalid input', () => {
|
||||
expect(pipe.transform(null)).toBe('');
|
||||
expect(pipe.transform(undefined)).toBe('');
|
||||
});
|
||||
|
||||
it('should convert value to Bytes', () => {
|
||||
expect(pipe.transform(0)).toBe('0 Bytes');
|
||||
expect(pipe.transform(1023)).toBe('1023 Bytes');
|
||||
});
|
||||
|
||||
it('should convert value to KB', () => {
|
||||
expect(pipe.transform(1024)).toBe('1 KB');
|
||||
expect(pipe.transform(1048575)).toBe('1024 KB');
|
||||
});
|
||||
|
||||
it('should convert value to MB', () => {
|
||||
expect(pipe.transform(1048576)).toBe('1 MB');
|
||||
expect(pipe.transform(1073741823)).toBe('1024 MB');
|
||||
});
|
||||
|
||||
it('should convert value to GB', () => {
|
||||
expect(pipe.transform(1073741824)).toBe('1 GB');
|
||||
expect(pipe.transform(1099511627775)).toBe('1024 GB');
|
||||
});
|
||||
|
||||
it('should convert value to TB and PB', () => {
|
||||
expect(pipe.transform(1099511627776)).toBe('1 TB');
|
||||
expect(pipe.transform(1125899906842623)).toBe('1 PB');
|
||||
});
|
||||
|
||||
it('should convert value with custom precision', () => {
|
||||
const tests = [
|
||||
{ size: 10, precision: 2, expectancy: '10 Bytes'},
|
||||
{ size: 1023, precision: 1, expectancy: '1023 Bytes'},
|
||||
{ size: 1025, precision: 2, expectancy: '1 KB'},
|
||||
{ size: 1499, precision: 0, expectancy: '1.46 KB'},
|
||||
{ size: 1999, precision: 0, expectancy: '1.95 KB'},
|
||||
{ size: 2000, precision: 2, expectancy: '1.95 KB'},
|
||||
{ size: 5000000, precision: 4, expectancy: '4.7684 MB'},
|
||||
{ size: 12345678901234, precision: 3, expectancy: '11.228 TB'}
|
||||
];
|
||||
|
||||
tests.forEach(({ size, precision, expectancy }) => {
|
||||
expect(pipe.transform(size, precision)).toBe(expectancy);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@@ -18,19 +18,25 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'adfFileSize'
|
||||
name: 'adfFileSize'
|
||||
})
|
||||
export class FileSizePipe implements PipeTransform {
|
||||
|
||||
transform(bytes: number = 0, decimals: number = 2): string {
|
||||
if (bytes === 0) {
|
||||
return '0 Bytes';
|
||||
transform(bytes: number, decimals: number = 2): string {
|
||||
if (bytes == null || bytes === undefined) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (bytes === 0) {
|
||||
return '0 Bytes';
|
||||
}
|
||||
|
||||
const k = 1024,
|
||||
dm = decimals || 2,
|
||||
sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
||||
i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
||||
}
|
||||
const k = 1024,
|
||||
dm = decimals || 2,
|
||||
sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
||||
i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user