Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 28x 28x 28x 28x 1x 1x 1x 95x 95x 56x 28x 1x 1x 1x 1x 67x 67x 67x 28x 39x 1x 1x 1x 1x 1x 1x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 172x 19x 172x 172x 172x 1x 1x 1x 19x 19x 1x 1x 1x 4x 4x 1x 1x 1x 2x 2x 2x 2x 1x 1x 1x 608x 608x 608x 608x 608x 608x 608x 608x 608x 608x 608x 608x 608x 267x 267x 267x 267x 267x 267x 267x 341x 341x 608x 608x 1x | /*******************************************************************************
* Copyright bei
* Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
*
*******************************************************************************/
import {
ChangeDetectionStrategy,
Component,
ElementRef,
NgZone,
OnDestroy,
computed,
contentChild,
contentChildren,
effect,
input,
output,
signal,
viewChild,
} from '@angular/core';
import { Item, Key, WidgetKeySet } from '../../utils/util.types';
import { createWidgetKeySet } from '../../utils/utilities';
import { LabelContainerErrorMessageDirective } from '../label-container-error-message.directive';
import {
EndSlotContentDirective,
StartSlotContentDirective,
} from './ext-search-label-container.directive';
/**
* Component used for combining one or two input elements/components and optionally contains a settings-/remove-button.
*/
@Component({
selector: 'gc-ext-search-label-container',
templateUrl: './ext-search-label-container.component.html',
styleUrls: ['./ext-search-label-container.component.css'],
changeDetection: ChangeDetectionStrategy.Eager,
standalone: false,
})
export class ExtSearchLabelContainerComponent implements OnDestroy {
/**
* Sets the text in the label slot
*/
public readonly label = input.required<string>();
/**
* Items displayed in the settings-menu
*/
public readonly settingsMenuItems = input<readonly Item[]>();
/**
* Add remove-button to the container
*/
public readonly showRemoveButton = input(false);
/**
* Decides which slots contain errors. Undefined === none
*/
public readonly errorSlots = input<'start' | 'end' | 'both'>();
/**
* Sets the settings-menu default item key
*/
public readonly defaultSettingsKey = input<Key>();
/**
* Sets the settings-menu selected item key
*/
public readonly selectedSettingsKey = input<Key>();
/**
* Overrides the internal vertical mode state to allow a consistent responsive view for all components inside a container/group
*/
public readonly globalVerticalMode = input<boolean>();
/**
* Overrides focus border visibility.
*/
public readonly hideFocusBorder = input(false);
/**
* Marks the input field as required.
*/
public readonly required = input(false);
/**
* Action that is fired when clicked on remove-button
*/
public readonly onRemoveButtonAction = output();
/**
* Action that is fired when selected settings-item changes
*/
public readonly onSettingsMenuAction = output<Item>();
/**
* Fires when component responsive mode changes
*/
public readonly onVerticalModeChange = output<boolean>();
/**
* Fires when the user clicks on the label
*/
public readonly onLabelClicked = output();
/** @ignore */
protected readonly startSlotTemplate = contentChild(
StartSlotContentDirective,
);
/** @ignore */
protected readonly endSlotTemplate = contentChild(EndSlotContentDirective);
/** @ignore */
protected readonly sizeHelper =
viewChild.required<ElementRef<HTMLElement>>('sizeHelper');
/** @ignore */
protected readonly errorMessageElements = contentChildren(
LabelContainerErrorMessageDirective,
);
/** @ignore */
protected readonly verticalMode = signal(false);
/** @ignore */
protected readonly widgetKeys: WidgetKeySet = createWidgetKeySet(
'gc-ext-search-label-container',
);
/** @ignore */
protected readonly settingsButtonDescriptionId =
this.widgetKeys.baseKey + '-settings-desc';
protected readonly settingsSelectionText = computed(() => {
const selectedItem = this.settingsMenuItems()?.find(
i => i.key === this.selectedSettingsKey(),
);
return selectedItem ? `${selectedItem.label} aktiv` : '';
});
protected readonly hasNonDefaultSettingsSelection = computed(() => {
return (
this.defaultSettingsKey() &&
this.selectedSettingsKey() &&
this.selectedSettingsKey() !== this.defaultSettingsKey()
);
});
protected readonly tooltipText = computed(() => {
const defaultSettingsMenuTooltipText = 'Einstellungen öffnen';
return this.hasNonDefaultSettingsSelection()
? `**${defaultSettingsMenuTooltipText}** (${this.settingsSelectionText()})`
: defaultSettingsMenuTooltipText;
});
/** @ignore */
private readonly containerResizeObserver: ResizeObserver;
constructor(
private readonly el: ElementRef<HTMLElement>,
private readonly zone: NgZone,
) {
this.containerResizeObserver = this.zone.runOutsideAngular(() => {
return new ResizeObserver(entries =>
this.computeWidths(entries[0].target),
);
});
this.containerResizeObserver.observe(this.el.nativeElement);
effect(onCleanup => {
const sizeHelperEl = this.sizeHelper().nativeElement;
this.containerResizeObserver.observe(sizeHelperEl);
onCleanup(() => {
this.containerResizeObserver.unobserve(sizeHelperEl);
});
});
}
/** @ignore */
ngOnDestroy(): void {
this.containerResizeObserver.disconnect();
}
/** @ignore */
protected handleRemoveButtonAction(): void {
this.onRemoveButtonAction.emit();
}
/** @ignore */
protected selectSettingsMenuAction(settingsMenuAction: Item): void {
if (this.selectedSettingsKey() !== settingsMenuAction.key) {
this.onSettingsMenuAction.emit(settingsMenuAction);
}
}
/** @ignore */
private computeWidths(target: Element): void {
NgZone.assertNotInAngularZone();
const calcVerticalMode = () => {
const sizeHelper = this.sizeHelper();
const verticalMode =
this.el.nativeElement.clientWidth <
sizeHelper.nativeElement.clientWidth;
if (verticalMode !== this.verticalMode()) {
this.zone.run(() => {
this.verticalMode.set(verticalMode);
this.onVerticalModeChange.emit(verticalMode);
});
}
};
if (target === this.el.nativeElement) {
/**
* setTimeout is needed, because otherwise the sizeHelper is not rendered yet with the new value,
* which leads to an enabled verticalMode everytime a character gets removed for a short time period until the sizeHelper is finally rendered
*/
setTimeout(() => {
calcVerticalMode();
});
} else {
calcVerticalMode();
}
}
}
|