Skip to content

Commit 20a964d

Browse files
feat: Show/Hide widget header (#2005)
--------- Co-authored-by: Antoine Hurard <[email protected]>
1 parent 2c32eb4 commit 20a964d

File tree

12 files changed

+92
-24
lines changed

12 files changed

+92
-24
lines changed

libs/shared/src/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,6 +2127,7 @@
21272127
},
21282128
"display": {
21292129
"border": "Show widget border",
2130+
"header": "Show widget header",
21302131
"searchable": "Allow search",
21312132
"sortable": "Allow sorting",
21322133
"title": "Widget display"

libs/shared/src/i18n/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,7 @@
21432143
},
21442144
"display": {
21452145
"border": "Afficher la bordure du widget",
2146+
"header": "Afficher l'en-tête du widget",
21462147
"searchable": "Autoriser la recherche",
21472148
"sortable": "Autoriser le tri",
21482149
"title": "Affichage des widgets"

libs/shared/src/i18n/test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,6 +2127,7 @@
21272127
},
21282128
"display": {
21292129
"border": "******",
2130+
"header": "******",
21302131
"searchable": "******",
21312132
"sortable": "******",
21322133
"title": "******"

libs/shared/src/lib/components/widget-grid/widget-actions/widget-actions.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
<ng-template #defaultTemplate>
7575
<ui-button
76-
*ngIf="!(widget.component === 'map')"
76+
*ngIf="!(widget.component === 'map') && showHeader"
7777
[isIcon]="true"
7878
icon="open_in_full"
7979
[uiTooltip]="'components.widget.expand' | translate"

libs/shared/src/lib/components/widget-grid/widget-actions/widget-actions.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TranslateService } from '@ngx-translate/core';
55
import { Dialog } from '@angular/cdk/dialog';
66
import { takeUntil } from 'rxjs';
77
import { UnsubscribeComponent } from '../../utils/unsubscribe/unsubscribe.component';
8+
import get from 'lodash/get';
89

910
/**
1011
* Button on top left of each widget, if user can see it, with menu of possible
@@ -29,6 +30,11 @@ export class WidgetActionsComponent extends UnsubscribeComponent {
2930
@Output() expand: EventEmitter<any> = new EventEmitter();
3031
@Output() style: EventEmitter<any> = new EventEmitter();
3132

33+
/** @returns should show widget header, based on widget settings */
34+
get showHeader() {
35+
return get(this.widget, 'settings.widgetDisplay.showHeader', true);
36+
}
37+
3238
/**
3339
* Button on top left of each widget, if user can see it, with menu of possible
3440
* actions for that widget.

libs/shared/src/lib/components/widget/widget.component.html

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
1-
<kendo-tilelayout-item-header
2-
*ngIf="header"
3-
class="widget-header border-b"
4-
[ngClass]="{
5-
'!border-transparent': !(widget.settings.widgetDisplay?.showBorder ?? true),
6-
'!border-b-gray-300': widget.settings.widgetDisplay?.showBorder ?? true
7-
}"
8-
>
9-
<ng-container
10-
*ngIf="headerLeftTemplate"
11-
[ngTemplateOutlet]="headerLeftTemplate"
12-
></ng-container>
13-
<ng-container
14-
*ngIf="widgetContentComponent?.headerTemplate"
15-
[ngTemplateOutlet]="widgetContentComponent.headerTemplate"
16-
></ng-container>
17-
<ng-container
18-
*ngIf="headerRightTemplate"
19-
[ngTemplateOutlet]="headerRightTemplate"
20-
></ng-container>
21-
</kendo-tilelayout-item-header>
1+
<ng-container *ngIf="header">
2+
<ng-container *ngIf="!showHeader; else defaultHeaderTemplate">
3+
<kendo-tilelayout-item-header class="floating-widget-header">
4+
<ng-container
5+
*ngIf="headerLeftTemplate"
6+
[ngTemplateOutlet]="headerLeftTemplate"
7+
></ng-container>
8+
<div class="bg-white/70 rounded-2xl">
9+
<ng-container
10+
*ngIf="headerRightTemplate"
11+
[ngTemplateOutlet]="headerRightTemplate"
12+
></ng-container>
13+
</div>
14+
</kendo-tilelayout-item-header>
15+
</ng-container>
16+
17+
<ng-template #defaultHeaderTemplate>
18+
<kendo-tilelayout-item-header
19+
class="widget-header border-b"
20+
[ngClass]="{
21+
'!border-transparent': !(
22+
widget.settings.widgetDisplay?.showBorder ?? true
23+
),
24+
'!border-b-gray-300': widget.settings.widgetDisplay?.showBorder ?? true
25+
}"
26+
>
27+
<ng-container
28+
*ngIf="headerLeftTemplate"
29+
[ngTemplateOutlet]="headerLeftTemplate"
30+
></ng-container>
31+
<ng-container
32+
*ngIf="widgetContentComponent?.headerTemplate"
33+
[ngTemplateOutlet]="widgetContentComponent.headerTemplate"
34+
></ng-container>
35+
<ng-container
36+
*ngIf="headerRightTemplate"
37+
[ngTemplateOutlet]="headerRightTemplate"
38+
></ng-container>
39+
</kendo-tilelayout-item-header>
40+
</ng-template>
41+
</ng-container>
42+
2243
<ng-container [ngSwitch]="widget.component">
2344
<!-- CHART -->
2445
<shared-chart

libs/shared/src/lib/components/widget/widget.component.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ import { DOCUMENT } from '@angular/common';
2828
styleUrls: ['./widget.component.scss'],
2929
})
3030
export class WidgetComponent implements OnInit, OnDestroy {
31+
/** Current widget definition */
3132
@Input() widget: any;
33+
// todo: rename or delete
34+
/** Is widget in fullscreen mode */
3235
@Input() header = true;
36+
/** Can user update widget */
3337
@Input() canUpdate = false;
38+
/** Template to display on the left of widget header */
3439
@Input() headerLeftTemplate?: TemplateRef<any>;
40+
/** Template to display on the right of widget header */
3541
@Input() headerRightTemplate?: TemplateRef<any>;
3642

3743
/** @returns would component block navigation */
@@ -43,6 +49,11 @@ export class WidgetComponent implements OnInit, OnDestroy {
4349
}
4450
}
4551

52+
/** @returns should show widget header, based on widget settings */
53+
get showHeader() {
54+
return get(this.widget, 'settings.widgetDisplay.showHeader', true);
55+
}
56+
4657
private customStyle?: HTMLStyleElement;
4758

4859
@HostBinding()

libs/shared/src/lib/components/widgets/common/display-settings/display-settings.component.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ <h2>
88
'models.widget.display.border' | translate
99
}}</ng-container>
1010
</ui-toggle>
11+
<ui-toggle formControlName="showHeader">
12+
<ng-container ngProjectAs="label">{{
13+
'models.widget.display.header' | translate
14+
}}</ng-container>
15+
</ui-toggle>
1116
</ng-container>
1217
<!-- Other specific options for each widget type -->
1318
<ng-content></ng-content>

libs/shared/src/lib/components/widgets/common/display-settings/extendWidgetForm.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { get } from 'lodash';
77
* @param form widget form
88
* @param settings settings to apply
99
* @param settings.showBorder show border setting
10+
* @param settings.showHeader show border header
1011
* @param settings.style custom style of the widget
1112
* @param specificControls specific controls to add to the form, on a widget basis
1213
* @returns form with the common fields
@@ -18,12 +19,14 @@ export const extendWidgetForm = <
1819
form: FormGroup<T>,
1920
settings?: {
2021
showBorder?: boolean;
22+
showHeader?: boolean;
2123
style?: string;
2224
},
2325
specificControls?: T2
2426
) => {
2527
const controls = {
2628
showBorder: new FormControl(get(settings, 'showBorder', true)),
29+
showHeader: new FormControl(get(settings, 'showHeader', true)),
2730
style: new FormControl(get(settings, 'style', '')),
2831
};
2932
Object.assign(controls, specificControls);
@@ -34,6 +37,7 @@ export const extendWidgetForm = <
3437
widgetDisplay: FormGroup<
3538
{
3639
showBorder: FormControl<boolean>;
40+
showHeader: FormControl<boolean>;
3741
style: FormControl<string>;
3842
} & T2
3943
>;

libs/shared/src/lib/components/widgets/grid/grid.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@
6767
<ng-template #floatingButtonsTemplate>
6868
<div
6969
class="flex overflow-hidden flex-1 max-w-fit"
70-
*ngIf="settings.floatingButtons?.length > 0"
70+
*ngIf="floatingButtons.length > 0"
7171
>
72-
<ng-container *ngFor="let floatingButton of settings.floatingButtons">
72+
<ng-container *ngFor="let floatingButton of floatingButtons">
7373
<ui-button
7474
variant="primary"
7575
(click)="onQuickAction(floatingButton)"

0 commit comments

Comments
 (0)