import { HostService } from '../../../../shared/api/host.service';
import { OrchestratorService } from '../../../../shared/api/orchestrator.service';
import { TableComponent } from '../../../../shared/datatable/table/table.component';
+import { CellTemplate } from '../../../../shared/enum/cell-template.enum';
import { CdTableColumn } from '../../../../shared/models/cd-table-column';
import { CdTableFetchDataContext } from '../../../../shared/models/cd-table-fetch-data-context';
import { Daemon } from '../../../../shared/models/daemon.interface';
name: this.i18n('Container ID'),
prop: 'container_id',
flexGrow: 3,
- filterable: true
+ filterable: true,
+ cellTransformation: CellTemplate.truncate,
+ customTemplateConfig: {
+ length: 12
+ }
},
{
name: this.i18n('Container Image name'),
name: this.i18n('Container Image ID'),
prop: 'container_image_id',
flexGrow: 3,
- filterable: true
+ filterable: true,
+ cellTransformation: CellTemplate.truncate,
+ customTemplateConfig: {
+ length: 12
+ }
},
{
name: this.i18n('Version'),
import { CephServiceService } from '../../../shared/api/ceph-service.service';
import { OrchestratorService } from '../../../shared/api/orchestrator.service';
import { TableComponent } from '../../../shared/datatable/table/table.component';
+import { CellTemplate } from '../../../shared/enum/cell-template.enum';
import { CdTableColumn } from '../../../shared/models/cd-table-column';
import { CdTableFetchDataContext } from '../../../shared/models/cd-table-fetch-data-context';
import { CdTableSelection } from '../../../shared/models/cd-table-selection';
{
name: this.i18n('Container image ID'),
prop: 'status.container_image_id',
- flexGrow: 3
+ flexGrow: 3,
+ cellTransformation: CellTemplate.truncate,
+ customTemplateConfig: {
+ length: 12
+ }
},
{
name: this.i18n('Running'),
let-value="value">
<span>{{ value | map:column?.customTemplateConfig }}</span>
</ng-template>
+
+<ng-template #truncateTpl
+ let-column="column"
+ let-value="value">
+ <span data-toggle="tooltip"
+ [title]="value">{{ value | truncate:column?.customTemplateConfig?.length:column?.customTemplateConfig?.omission }}</span>
+</ng-template>
badgeTpl: TemplateRef<any>;
@ViewChild('mapTpl', { static: true })
mapTpl: TemplateRef<any>;
+ @ViewChild('truncateTpl', { static: true })
+ truncateTpl: TemplateRef<any>;
// This is the array with the items to be shown.
@Input()
this.cellTemplates.classAdding = this.classAddingTpl;
this.cellTemplates.badge = this.badgeTpl;
this.cellTemplates.map = this.mapTpl;
+ this.cellTemplates.truncate = this.truncateTpl;
}
useCustomClass(value: any): string {
// [key: any]: any
// }
// }
- map = 'map'
+ map = 'map',
+ // Truncates string if it's longer than the given maximum
+ // string length.
+ // {
+ // ...
+ // cellTransformation: CellTemplate.truncate,
+ // customTemplateConfig: {
+ // length?: number; // Defaults to 30.
+ // omission?: string; // Defaults to empty string.
+ // }
+ // }
+ truncate = 'truncate'
}
import { RbdConfigurationSourcePipe } from './rbd-configuration-source.pipe';
import { RelativeDatePipe } from './relative-date.pipe';
import { RoundPipe } from './round.pipe';
+import { TruncatePipe } from './truncate.pipe';
import { UpperFirstPipe } from './upper-first.pipe';
@NgModule({
UpperFirstPipe,
RbdConfigurationSourcePipe,
DurationPipe,
- MapPipe
+ MapPipe,
+ TruncatePipe
],
exports: [
ArrayPipe,
UpperFirstPipe,
RbdConfigurationSourcePipe,
DurationPipe,
- MapPipe
+ MapPipe,
+ TruncatePipe
],
providers: [
ArrayPipe,
MillisecondsPipe,
NotAvailablePipe,
UpperFirstPipe,
- MapPipe
+ MapPipe,
+ TruncatePipe
]
})
export class PipesModule {}
--- /dev/null
+import { TruncatePipe } from './truncate.pipe';
+
+describe('TruncatePipe', () => {
+ const pipe = new TruncatePipe();
+
+ it('create an instance', () => {
+ expect(pipe).toBeTruthy();
+ });
+
+ it('should truncate string (1)', () => {
+ expect(pipe.transform('fsdfdsfs asdasd', 5, '')).toEqual('fsdfd');
+ });
+
+ it('should truncate string (2)', () => {
+ expect(pipe.transform('fsdfdsfs asdasd', 10, '...')).toEqual('fsdfdsf...');
+ });
+
+ it('should not truncate number', () => {
+ expect(pipe.transform(2, 6, '...')).toBe(2);
+ });
+});
--- /dev/null
+import { Pipe, PipeTransform } from '@angular/core';
+
+import * as _ from 'lodash';
+
+@Pipe({
+ name: 'truncate'
+})
+export class TruncatePipe implements PipeTransform {
+ transform(value: any, length: number, omission?: string): any {
+ if (!_.isString(value)) {
+ return value;
+ }
+ omission = _.defaultTo(omission, '');
+ return _.truncate(value, { length, omission });
+ }
+}