Skip to content

Commit f00daa6

Browse files
authored
Introduce TableCell component (#112)
* Remove outdated table methods * Add table-cell component * Fix filter service reset * Fix tooltip generation
1 parent f381274 commit f00daa6

File tree

12 files changed

+183
-47
lines changed

12 files changed

+183
-47
lines changed

src/ng-generate/components/shared/generators/services/filter/files/__name@dasherize__-filter.service.ts.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class <%= classify(name) %>FilterService {
178178
const appliedFilters = [...this.activeFilters];
179179

180180
appliedFilters.forEach((filter) => {
181-
this.resetFilter(filter)
181+
this.removeFilter(filter)
182182
})
183183
}
184184

src/ng-generate/components/shared/methods/generation/extended-table.html.template

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div [hidden]="!!customTemplate && !dataSource.data.length">
1+
<div class="js-sdk-component-container--inner" [hidden]="!!customTemplate && !dataSource.data.length">
22

33
<div data-test="table-container" class="mat-table-container">
44
<table data-test="table" mat-table class="full-width-table"
@@ -60,28 +60,21 @@
6060
</th>
6161

6262
<td data-test="table-cell"
63-
64-
<% if(options.templateHelper.isEnumPropertyWithEntityValues(value.property)) { %>
65-
[matTooltip]="!('<%= isEmptyValue %>') ? (row.<%= cellPropertyPath %><%= descriptionPipe %>:true<%= language %>) :''" [matTooltipDisabled]="'<%= isEmptyValue %>'"
66-
<% } %>
67-
6863
mat-cell *matCellDef="let row"
6964

7065
<% if(options.templateHelper.isNumberProperty(value.property)) { %>
7166
class="table-cell-number"
7267
<% } %>
7368
>
7469

75-
<% if(options.hasSearchBar) { %>
76-
<ng-container [ngTemplateOutlet]="highlightCell" [ngTemplateOutletContext]="{ value: <%= cellContent %> }"></ng-container>
77-
<% } else { %>
78-
{{<%= cellContent %>}}
79-
<% } %>
80-
81-
<mat-icon data-test="copy-to-clipboard-icon" *ngIf="!(<%= isEmptyValue %>)" class="material-icons copy-to-clipboard"
82-
(click)="copyToClipboard(row.<%= cellPropertyPath %><%= language %>, $event)">
83-
content_copy
84-
</mat-icon>
70+
<esmf-table-cell
71+
[value]="<%= cellContent %>"
72+
<% if(options.hasSearchBar) { %>
73+
[configs]="configs"
74+
[highlightString]="highlightString"
75+
<% } %>
76+
(copyToClipboardEvent)="copyToClipboard($event)"
77+
></esmf-table-cell>
8578
</td>
8679
</ng-container>
8780
<% } %>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!--
2+
* Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
3+
*
4+
* See the AUTHORS file(s) distributed with this work for
5+
* additional information regarding authorship.
6+
*
7+
* This Source Code Form is subject to the terms of the Mozilla Public
8+
* License, v. 2.0. If a copy of the MPL was not distributed with this
9+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
10+
*
11+
* SPDX-License-Identifier: MPL-2.0
12+
-->
13+
14+
<span
15+
[tableCellTooltip]="value"
16+
[highlight]="highlightString"
17+
[highlightSource]="value"
18+
[highlightColor]="highlightConfigColor"
19+
[selected]="highlightConfigSelector"
20+
>
21+
{{ value === null ? '-' : value }}
22+
</span>
23+
24+
<mat-icon
25+
class="material-icons copy-to-clipboard"
26+
*ngIf="!(value === null || value === undefined)"
27+
(click)="copyToClipboard(value, $event)"
28+
data-test="copy-to-clipboard-icon"
29+
>
30+
content_copy
31+
</mat-icon>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/** <%= options.generationDisclaimerText %> **/
2+
3+
import {Clipboard} from '@angular/cdk/clipboard';
4+
import {Component, EventEmitter, Input, Output} from '@angular/core';
5+
import {Config} from '../product-instance-table/v020/product-instance-table.component';
6+
7+
@Component({
8+
selector: '<%= dasherize(name) %>',
9+
templateUrl: './<%= dasherize(name) %>.component.html',
10+
})
11+
export class EsmfTableCellComponent {
12+
@Input() value: any;
13+
@Input() highlightString: string[];
14+
@Input() configs: Array<Config> = [];
15+
@Output() copyToClipboardEvent = new EventEmitter<any>();
16+
17+
get highlightConfigColor(): string | undefined {
18+
return this.configs.find((config: Config) => config.name.includes('highlight'))?.color;
19+
}
20+
21+
get highlightConfigSelector(): boolean | undefined {
22+
return this.configs.find((config: Config) => config.name.includes('highlight'))?.selected;
23+
}
24+
25+
constructor(private clipboard: Clipboard) {}
26+
27+
copyToClipboard(value: any, event: MouseEvent): void {
28+
event.stopPropagation();
29+
event.preventDefault();
30+
this.clipboard.copy(value);
31+
this.copyToClipboardEvent.emit(value);
32+
}
33+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
3+
*
4+
* See the AUTHORS file(s) distributed with this work for
5+
* additional information regarding authorship.
6+
*
7+
* This Source Code Form is subject to the terms of the Mozilla Public
8+
* License, v. 2.0. If a copy of the MPL was not distributed with this
9+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
10+
*
11+
* SPDX-License-Identifier: MPL-2.0
12+
*/
13+
14+
import {apply, applyTemplates, MergeStrategy, mergeWith, move, Rule, SchematicContext, Tree, url} from '@angular-devkit/schematics';
15+
import {strings} from '@angular-devkit/core';
16+
17+
export function generateTableCellComponent(options: any): Rule {
18+
return (tree: Tree, _context: SchematicContext) => {
19+
return mergeWith(
20+
apply(url('./generators/components/table-cell/files'), [
21+
applyTemplates({
22+
classify: strings.classify,
23+
dasherize: strings.dasherize,
24+
options: options,
25+
name: 'esmf-table-cell',
26+
}),
27+
move('src/app/shared/components/table-cell'),
28+
]),
29+
options.overwrite ? MergeStrategy.Overwrite : MergeStrategy.Error,
30+
);
31+
};
32+
}

src/ng-generate/components/table/generators/components/table/files/__name@dasherize__.component.html.template

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,3 @@
4444

4545
<%= options.include('/generation/extended-table.html.template') %>
4646
</div>
47-
48-
<% if (options.hasSearchBar) { %>
49-
<!-- Highlighting search values -->
50-
<ng-template #highlightCell let-value="value">
51-
<span
52-
[highlight]="highlightString"
53-
[highlightSource]="value"
54-
[highlightColor]="highlightConfigColor"
55-
[selected]="highlightConfigSelector"
56-
>
57-
{{ value === null ? '-' : value }}
58-
</span>
59-
</ng-template>
60-
<% } %>

src/ng-generate/components/table/generators/components/table/files/__name@dasherize__.component.ts.template

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import { MatTable } from '@angular/material/table';
3030
import { FilterEnums, <%= options.filterServiceName %>} from './<%= dasherize(name) %>-filter.service';
3131
<% } %>
3232

33-
import {Clipboard} from '@angular/cdk/clipboard';
34-
3533
<% if (options.addCommandBar) { %>
3634
import {unparse} from 'papaparse';
3735
import {Action, ExportTableDialogComponent} from '<% if (options.enableVersionSupport) { %>../<% } %>../export-confirmation-dialog/export-table-dialog.component';
@@ -228,14 +226,6 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit, Af
228226

229227
<% if (options.hasSearchBar) { %>
230228
highlightString: string[] = [];
231-
232-
get highlightConfigColor(): string | undefined {
233-
return this.configs.find((config: Config) => config.name.includes('highlight'))?.color;
234-
}
235-
236-
get highlightConfigSelector(): boolean | undefined {
237-
return this.configs.find((config: Config) => config.name.includes('highlight'))?.selected;
238-
}
239229
<% } %>
240230

241231
<%= byValueFunction %>
@@ -404,10 +394,7 @@ export class <%= classify(name) %>Component implements OnInit, AfterViewInit, Af
404394
this.rowDblClickEvent.emit({data: row});
405395
}
406396

407-
copyToClipboard(value: any, event: MouseEvent): void {
408-
event.stopPropagation();
409-
event.preventDefault();
410-
this.clipboard.copy(value);
397+
copyToClipboard(value: any): void {
411398
this.copyToClipboardEvent.emit(value);
412399
}
413400

src/ng-generate/components/table/generators/components/table/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ function commonImports(): string {
153153
private sanitizer: DomSanitizer,
154154
private translateService: TranslocoService,
155155
public dialog: MatDialog,
156-
private clipboard: Clipboard,
157156
private storageService: JSSdkLocalStorageService,
158157
@Inject(PaginatorSelectConfigInjector) public paginatorSelectConfig: MatPaginatorSelectConfig,
159158
${sharedOptions.hasFilters ? `public filterService: ${sharedOptions.filterServiceName},` : ''}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/** <%= options.generationDisclaimerText %> **/
2+
3+
import {Directive, ElementRef, HostListener, Input} from '@angular/core';
4+
import {MatTooltip} from '@angular/material/tooltip';
5+
6+
@Directive({
7+
selector: '[tableCellTooltip]',
8+
hostDirectives: [MatTooltip]
9+
})
10+
export class TableCellTooltipDirective {
11+
@Input()
12+
get tableCellTooltip() {
13+
return this.matTooltip.message;
14+
}
15+
set tableCellTooltip(txt: string) {
16+
this.matTooltip.message = txt;
17+
}
18+
19+
// average space taken by the 3 dots that trim the text
20+
private readonly ellipsisSpace = 56;
21+
22+
constructor(
23+
private el: ElementRef,
24+
private matTooltip: MatTooltip
25+
) {}
26+
27+
@HostListener('mouseenter')
28+
check(): void {
29+
// offsetParent.offsetWidth is the width of the table cell (td element)
30+
// offsetWidth width of the span that contains the text inside the table cell
31+
this.matTooltip.disabled = this.el.nativeElement.offsetParent.offsetWidth - this.ellipsisSpace >= this.el.nativeElement.offsetWidth;
32+
}
33+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
3+
*
4+
* See the AUTHORS file(s) distributed with this work for
5+
* additional information regarding authorship.
6+
*
7+
* This Source Code Form is subject to the terms of the Mozilla Public
8+
* License, v. 2.0. If a copy of the MPL was not distributed with this
9+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
10+
*
11+
* SPDX-License-Identifier: MPL-2.0
12+
*/
13+
14+
import {strings} from '@angular-devkit/core';
15+
import {apply, applyTemplates, MergeStrategy, mergeWith, move, noop, Rule, url} from '@angular-devkit/schematics';
16+
17+
export function generateTableCellTooltipDirective(options: any): Rule {
18+
return () => {
19+
if (!options.hasSearchBar) {
20+
return noop;
21+
}
22+
23+
return mergeWith(
24+
apply(url('./generators/directives/table-cell-tooltip/files'), [
25+
applyTemplates({
26+
classify: strings.classify,
27+
dasherize: strings.dasherize,
28+
options: options,
29+
name: 'table-cell-tooltip',
30+
}),
31+
move('src/app/shared/directives'),
32+
]),
33+
options.overwrite ? MergeStrategy.Overwrite : MergeStrategy.Error,
34+
);
35+
};
36+
}

0 commit comments

Comments
 (0)