OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Non-wp datepickers and other drop modals work
Benjamin Bädorf7e8996148585
diff --git a/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.html b/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.htmlindex c3779d50e73..9ada0761617 100644--- a/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.html+++ b/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.html@@ -16,72 +16,73 @@/></ng-template>- <form- slot="body"- class="spot-container op-datepicker-modal"- data-qa-selector="op-datepicker-modal"- tabindex="0"- cdkFocusInitial- cdkTrapFocus- [cdkTrapFocusAutoCapture]="true"- (submit)="save($event)"- >- <spot-selector-field- *ngIf="showIgnoreNonWorkingDays"- [reverseLabel]="true"- [label]="text.ignoreNonWorkingDays.title"+ <ng-container slot="body">+ <form+ class="spot-container op-datepicker-modal"+ data-qa-selector="op-datepicker-modal"+ tabindex="0"+ cdkFocusInitial+ cdkTrapFocus+ [cdkTrapFocusAutoCapture]="true"+ (submit)="save($event)">- <spot-switch- slot="input"- name="ignoreNonWorkingDays"- [(ngModel)]="ignoreNonWorkingDays"- (ngModelChange)="changeNonWorkingDays()"- data-qa-selector="op-datepicker-modal--include-non-working-days"- ></spot-switch>- </spot-selector-field>+ <spot-selector-field+ *ngIf="showIgnoreNonWorkingDays"+ [reverseLabel]="true"+ [label]="text.ignoreNonWorkingDays.title"+ >+ <spot-switch+ slot="input"+ name="ignoreNonWorkingDays"+ [(ngModel)]="ignoreNonWorkingDays"+ (ngModelChange)="changeNonWorkingDays()"+ data-qa-selector="op-datepicker-modal--include-non-working-days"+ ></spot-switch>+ </spot-selector-field>- <ng-content select="[slot=extra-fields]"></ng-content>+ <ng-content select="[slot=extra-fields]"></ng-content>- <spot-form-field- [label]="text.date"- >- <spot-text-field- slot="input"- name="date"- class="op-datepicker-modal--date-field"- [ngModel]="workingValue"- (ngModelChange)="writeWorkingValue($event)"- [showClearButton]="true"- ></spot-text-field>- <button- slot="action"- type="button"- class="spot-link"- (click)="setToday()"- [textContent]="text.today">- </button>- </spot-form-field>-- <div #flatpickrTarget></div>-- <div class="spot-action-bar">- <div class="spot-action-bar--right">+ <spot-form-field+ [label]="text.date"+ >+ <spot-text-field+ slot="input"+ name="date"+ class="op-datepicker-modal--date-field"+ [ngModel]="workingValue"+ (ngModelChange)="writeWorkingValue($event)"+ [showClearButton]="true"+ ></spot-text-field><button+ slot="action"type="button"- (click)="opened = false"- class="button spot-action-bar--action"- data-qa-selector="op-datepicker-modal--action"- [textContent]="text.cancel"- ></button>- <button- type="submit"- class="button -highlight spot-action-bar--action"- data-qa-selector="op-datepicker-modal--action"- [textContent]="text.save"- ></button>+ class="spot-link"+ (click)="setToday()"+ [textContent]="text.today">+ </button>+ </spot-form-field>++ <div #flatpickrTarget></div>++ <div class="spot-action-bar">+ <div class="spot-action-bar--right">+ <button+ type="button"+ (click)="opened = false"+ class="button spot-action-bar--action"+ data-qa-selector="op-datepicker-modal--action"+ [textContent]="text.cancel"+ ></button>+ <button+ type="submit"+ class="button -highlight spot-action-bar--action"+ data-qa-selector="op-datepicker-modal--action"+ [textContent]="text.save"+ ></button>+ </div></div>- </div>- </form>+ </form>+ </ng-container></spot-drop-modal><inputdiff --git a/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.ts b/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.tsindex 14587d4efc5..a81f3a936d2 100644--- a/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.ts+++ b/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.ts@@ -53,6 +53,7 @@ import { DatePicker } from '../datepicker';import flatpickr from 'flatpickr';import { DayElement } from 'flatpickr/dist/types/instance';import { populateInputsFromDataset } from '../../dataset-inputs';+import { debounce } from 'lodash';export const opSingleDatePickerSelector = 'op-single-date-picker';@@ -104,7 +105,7 @@ export class OpSingleDatePickerComponent implements ControlValueAccessor, OnInitthis._opened = !!opened;if (this._opened) {- this.initializeDatepicker();+ this.initializeDatepickerDebounced();} else {this.closed.emit();}@@ -180,7 +181,7 @@ export class OpSingleDatePickerComponent implements ControlValueAccessor, OnInit}changeNonWorkingDays():void {- this.initializeDatepicker();+ this.initializeDatepickerDebounced();this.cdRef.detectChanges();}@@ -189,8 +190,20 @@ export class OpSingleDatePickerComponent implements ControlValueAccessor, OnInitsetDates(date, this.datePickerInstance, enforceDate);}- private initializeDatepicker() {+ private initializeDatepickerDebounced = debounce(this.initializeDatepicker.bind(this), 16);++ private initializeDatepicker(numberOfTries = 0) {this.datePickerInstance?.destroy();++ // If we're too early somehow, try again in a bit+ if (!this.flatpickrTarget?.nativeElement) {+ if (numberOfTries >= 3) {+ console.warn('Tried initializing flatpickr 3 times in a row with no success. Bailing out');+ return;+ }+ this.initializeDatepickerDebounced(numberOfTries + 1);+ }+this.datePickerInstance = new DatePicker(this.injector,this.id,diff --git a/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.html b/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.htmlindex 4e6e753e6d7..26aa64644ed 100644--- a/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.html+++ b/frontend/src/app/shared/components/fields/edit/field-types/combined-date-edit-field.component.html@@ -12,21 +12,21 @@(focus)="showDatePickerModal()"/>- <op-wp-single-date-form- *ngIf="opened && !isMultiDate"- [value]="dates"- [changeset]="change"- (save)="save()"- (cancel)="cancel()"- slot="body"- ></op-wp-single-date-form>- <op-wp-multi-date-form- *ngIf="opened && isMultiDate"- [value]="dates"- [changeset]="change"- [fieldName]="name"- (save)="save()"- (cancel)="cancel()"- slot="body"- ></op-wp-multi-date-form>+ <ng-container slot="body">+ <op-wp-single-date-form+ *ngIf="opened && !isMultiDate"+ [value]="dates"+ [changeset]="change"+ (save)="save()"+ (cancel)="cancel()"+ ></op-wp-single-date-form>+ <op-wp-multi-date-form+ *ngIf="opened && isMultiDate"+ [value]="dates"+ [changeset]="change"+ [fieldName]="name"+ (save)="save()"+ (cancel)="cancel()"+ ></op-wp-multi-date-form>+ </ng-container></spot-drop-modal>diff --git a/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts b/frontend/src/app/spot/components/drop-modal/drop-modal.component.tsindex 234974b4ba7..034c068e46a 100644--- a/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts+++ b/frontend/src/app/spot/components/drop-modal/drop-modal.component.ts@@ -67,7 +67,6 @@ export class SpotDropModalComponent implements OnDestroy {@Input('opened')@HostBinding('class.spot-drop-modal_opened')set opened(value:boolean) {- console.log('opened change', this._opened, !!value);if (this._opened === !!value) {return;@@ -129,6 +128,7 @@ export class SpotDropModalComponent implements OnDestroy {) {}open() {+ this._opened = true;this.repositionAnchor();this.updateAppHeight();@@ -145,59 +145,52 @@ export class SpotDropModalComponent implements OnDestroy {this.teleportationService.hasRendered$.pipe(take(1)).subscribe(() => {- this._opened = true;+ /*+ * We have to set these listeners next tick, because they're so far up the tree.+ * If the open value was set because of a click listener in the trigger slot,+ * that event would reach the event listener added here and close the modal right away.+ */setTimeout(() => {- /*- * We have to set these listeners next tick, because they're so far up the tree.- * If the open value was set because of a click listener in the trigger slot,- * that event would reach the event listener added here and close the modal right away.- */- document.body.addEventListener('click', this.close.bind(this));- document.body.addEventListener('keydown', this.onEscape.bind(this));- document.body.addEventListener('scroll', this.repositionAnchor.bind(this), true);- window.addEventListener('resize', this.onResizeDebounced.bind(this));- window.addEventListener('orientationchange', this.onResizeDebounced.bind(this));-- setTimeout(() => {- this.recalculateAlignment();- });-- // If we already have focus within the modal, don't move it- if (this.elementRef.nativeElement.contains(document.activeElement)) {- return;- }+ document.body.addEventListener('click', this.onGlobalClick);+ document.body.addEventListener('keydown', this.onEscape);+ document.body.addEventListener('scroll', this.onScroll, true);+ window.addEventListener('resize', this.onResize);+ window.addEventListener('orientationchange', this.onResize);++ this.recalculateAlignment();const focusCatcherContainer = document.querySelectorAll("[data-modal-focus-catcher-container='true']")[0];if (focusCatcherContainer) {- (findAllFocusableElementsWithin(focusCatcherContainer as HTMLElement)[0] as HTMLElement).focus();+ (findAllFocusableElementsWithin(focusCatcherContainer as HTMLElement)[0] as HTMLElement)?.focus();} else {// Index 1 because the element at index 0 is the trigger button to open the modal- (findAllFocusableElementsWithin(this.elementRef.nativeElement)[1] as HTMLElement).focus();+ (findAllFocusableElementsWithin(this.elementRef.nativeElement)[1] as HTMLElement)?.focus();}});- });+ });}close():void {- console.log('close');this.teleportationService.clear();this._opened = false;- document.body.removeEventListener('click', this.close);+ document.body.removeEventListener('click', this.onGlobalClick);document.body.removeEventListener('keydown', this.onEscape);- document.body.removeEventListener('scroll', this.repositionAnchor);- window.removeEventListener('resize', this.onResizeDebounced);- window.removeEventListener('orientationchange', this.onResizeDebounced);+ document.body.removeEventListener('scroll', this.onScroll);+ window.removeEventListener('resize', this.onResize);+ window.removeEventListener('orientationchange', this.onResize);this.closed.emit();}+ private onGlobalClick = this.close.bind(this);+ngOnDestroy():void {- document.body.removeEventListener('click', this.close);+ document.body.removeEventListener('click', this.onGlobalClick);document.body.removeEventListener('keydown', this.onEscape);- document.body.removeEventListener('scroll', this.repositionAnchor);- window.removeEventListener('resize', this.onResizeDebounced);- window.removeEventListener('orientationchange', this.onResizeDebounced);+ document.body.removeEventListener('scroll', this.onScroll);+ window.removeEventListener('resize', this.onResize);+ window.removeEventListener('orientationchange', this.onResize);}onBodyClick(e:MouseEvent):void {@@ -241,19 +234,21 @@ export class SpotDropModalComponent implements OnDestroy {this.cdRef.detectChanges();}- private onEscape = (evt:KeyboardEvent) => {+ private escapeCallback = (evt:KeyboardEvent) => {if (evt.keyCode === KeyCodes.ESCAPE) {this.close();}};- private onResize():void {+ private onEscape = debounce(this.escapeCallback.bind(this), 10);++ private resizeCallback():void {this.updateAppHeight();this.repositionAnchor();this.recalculateAlignment();}- private onResizeDebounced = debounce(this.onResize.bind(this), 10);+ private onResize = debounce(this.resizeCallback.bind(this), 10);private updateAppHeight = () => {const doc = document.documentElement;@@ -267,4 +262,6 @@ export class SpotDropModalComponent implements OnDestroy {this.anchorStyles.width = `${elementRect.width}px`;this.anchorStyles.height = `${elementRect.height}px`;}++ private onScroll = debounce(this.repositionAnchor.bind(this), 16);}