Skip to content

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

[42358] Standardise date pickers outside of the main work package date field (#12222)

Behrokh Satarnejad6df0cf569462
diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb
index 03d6d3406dc..47f4e90ce66 100644
--- a/app/helpers/custom_fields_helper.rb
+++ b/app/helpers/custom_fields_helper.rb
@@ -78,7 +78,7 @@ module CustomFieldsHelper
tag = case field_format.try(:edit_as)
when 'date'
- angular_component_tag 'op-single-date-picker',
+ angular_component_tag 'op-basic-single-date-picker',
inputs: {
required: custom_field.is_required,
value: custom_value.value,
@@ -155,7 +155,7 @@ module CustomFieldsHelper
field_format = OpenProject::CustomFieldFormat.find_by_name(custom_field.field_format)
case field_format.try(:edit_as)
when 'date'
- angular_component_tag 'op-single-date-picker',
+ angular_component_tag 'op-modal-single-date-picker',
inputs: {
id: field_id,
name: field_name,
diff --git a/frontend/src/app/core/setup/global-dynamic-components.const.ts b/frontend/src/app/core/setup/global-dynamic-components.const.ts
index 2ded15c2f1e..0062e4f1656 100644
--- a/frontend/src/app/core/setup/global-dynamic-components.const.ts
+++ b/frontend/src/app/core/setup/global-dynamic-components.const.ts
@@ -211,10 +211,6 @@ import {
OpModalOverlayComponent,
opModalOverlaySelector,
} from 'core-app/shared/components/modal/modal-overlay.component';
-import {
- OpSingleDatePickerComponent,
- opSingleDatePickerSelector,
-} from 'core-app/shared/components/datepicker/single-date-picker/single-date-picker.component';
import {
OpModalSingleDatePickerComponent,
opModalSingleDatePickerSelector,
@@ -284,7 +280,6 @@ export const globalDynamicComponents:OptionalBootstrapDefinition[] = [
{ selector: spotDropModalPortalComponentSelector, cls: SpotDropModalPortalComponent },
{ selector: spotSwitchSelector, cls: SpotSwitchComponent },
- { selector: opSingleDatePickerSelector, cls: OpSingleDatePickerComponent, embeddable: true },
{ selector: opModalSingleDatePickerSelector, cls: OpModalSingleDatePickerComponent, embeddable: true },
{ selector: opBasicSingleDatePickerSelector, cls: OpBasicSingleDatePickerComponent, embeddable: true },
diff --git a/frontend/src/app/features/work-packages/components/wp-custom-actions/date-action/custom-date-action-admin.html b/frontend/src/app/features/work-packages/components/wp-custom-actions/date-action/custom-date-action-admin.html
index 5fe6acfb3fc..99f15a7d473 100644
--- a/frontend/src/app/features/work-packages/components/wp-custom-actions/date-action/custom-date-action-admin.html
+++ b/frontend/src/app/features/work-packages/components/wp-custom-actions/date-action/custom-date-action-admin.html
@@ -11,13 +11,13 @@
</select>
</span>
<span class="form--text-field-container -slim" *ngIf="valueVisible">
- <op-single-date-picker
+ <op-basic-single-date-picker
[id]="fieldId + '_visible'"
[name]="fieldId + '_input'"
[value]="fieldValue"
(valueChange)="updateField($event)"
classes="form--text-field">
- </op-single-date-picker>
+ </op-basic-single-date-picker>
</span>
<input type="hidden"
[name]="fieldName"
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.html
deleted file mode 100644
index a170f40304c..00000000000
--- a/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.html
+++ /dev/null
@@ -1,94 +0,0 @@
-<spot-drop-modal
- [opened]="opened"
- (closed)="opened = false"
- data-qa-selector="op-single-date-picker"
->
- <ng-content
- slot="trigger"
- select="[slot=trigger]"
- ></ng-content>
- <ng-template [ngIf]="useDefaultTrigger" slot="trigger">
- <input
- type="text"
- class="spot-input"
- [attr.data-value]="value"
- [id]="id"
- [(ngModel)]="value"
- (ngModelChange)="changeValueFromInputDebounced($event)"
- (click)="onInputClick($event)"
- (focus)="opened = true"
- />
- </ng-template>
-
- <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)"
- >
- <div class="spot-container op-datepicker-modal--stretch-content">
- <div class="op-datepicker-modal--toggle-actions-container">
- <op-datepicker-working-days-toggle
- *ngIf="showIgnoreNonWorkingDays"
- name="ignoreNonWorkingDays"
- [(ngModel)]="ignoreNonWorkingDays"
- (ngModelChange)="changeNonWorkingDays()"
- ></op-datepicker-working-days-toggle>
- </div>
-
- <ng-content select="[slot=extra-fields]"></ng-content>
-
- <spot-form-field
- [label]="text.date"
- [required]="required"
- >
- <spot-text-field
- slot="input"
- name="date"
- class="op-datepicker-modal--date-field"
- [ngModel]="workingValue"
- [required]="required"
- (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>
-
- <div class="spot-action-bar">
- <div class="spot-action-bar--right">
- <button
- type="button"
- (click)="opened = false"
- class="button spot-modal--cancel-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]="applyLabel"
- ></button>
- </div>
- </div>
- </form>
- </ng-container>
-</spot-drop-modal>
-
-<input
- [name]="name"
- [value]="value"
- hidden
->
diff --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.ts
deleted file mode 100644
index fcd00b526a7..00000000000
--- a/frontend/src/app/shared/components/datepicker/single-date-picker/single-date-picker.component.ts
+++ /dev/null
@@ -1,296 +0,0 @@
-// -- copyright
-// OpenProject is an open source project management software.
-// Copyright (C) 2012-2022 the OpenProject GmbH
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License version 3.
-//
-// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-// Copyright (C) 2006-2013 Jean-Philippe Lang
-// Copyright (C) 2010-2013 the ChiliProject Team
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-//
-// See COPYRIGHT and LICENSE files for more details.
-//++
-
-import {
- AfterContentInit,
- ChangeDetectionStrategy,
- ChangeDetectorRef,
- Component,
- ElementRef,
- EventEmitter,
- forwardRef,
- Injector,
- Input,
- OnInit,
- Output,
- ViewChild,
- ViewEncapsulation,
-} from '@angular/core';
-import { I18nService } from 'core-app/core/i18n/i18n.service';
-import {
- ControlValueAccessor,
- NG_VALUE_ACCESSOR,
-} from '@angular/forms';
-import {
- onDayCreate,
- parseDate,
- setDates,
-} from 'core-app/shared/components/datepicker/helpers/date-modal.helpers';
-import { TimezoneService } from 'core-app/core/datetime/timezone.service';
-import { DatePicker } from '../datepicker';
-import flatpickr from 'flatpickr';
-import { DayElement } from 'flatpickr/dist/types/instance';
-import { populateInputsFromDataset } from '../../dataset-inputs';
-import { debounce } from 'lodash';
-import { SpotDropModalTeleportationService } from 'core-app/spot/components/drop-modal/drop-modal-teleportation.service';
-
-export const opSingleDatePickerSelector = 'op-single-date-picker';
-
-@Component({
- selector: opSingleDatePickerSelector,
- templateUrl: './single-date-picker.component.html',
- styleUrls: ['../styles/datepicker.modal.sass'],
- changeDetection: ChangeDetectionStrategy.OnPush,
- encapsulation: ViewEncapsulation.None,
- providers: [
- {
- provide: NG_VALUE_ACCESSOR,
- useExisting: forwardRef(() => OpSingleDatePickerComponent),
- multi: true,
- },
- ],
-})
-export class OpSingleDatePickerComponent implements ControlValueAccessor, OnInit, AfterContentInit {
- @Output('closed') closed = new EventEmitter();
-
- @Output('valueChange') valueChange = new EventEmitter();
-
- private _value = '';
-
- @Input() set value(newValue:string) {
- this._value = newValue;
- this.writeWorkingValue(newValue);
- }
-
- get value() {
- return this._value;
- }
-
- @Input() id = `flatpickr-input-${+(new Date())}`;
-
- @Input() name = '';
-
- @Input() required = false;
-
- @Input() minimalDate:Date|null = null;
-
- @Input() applyLabel:string;
-
- private _opened = false;
-
- @Input() set opened(opened:boolean) {
- if (this._opened === !!opened) {
- return;
- }
-
- this._opened = !!opened;
-
- if (this._opened) {
- this.initializeDatepickerAfterOpen();
- } else {
- this.closed.emit();
- }
- }
-
- get opened() {
- return this._opened;
- }
-
- @Input() showIgnoreNonWorkingDays = false;
-
- // When the "Working days only" switch is shown, it should be on, otherwise is off.
- @Input() ignoreNonWorkingDays = !this.showIgnoreNonWorkingDays;
-
- @ViewChild('flatpickrTarget') flatpickrTarget:ElementRef;
-
- public workingValue = '';
-
- public workingDate:Date|null = null;
-
- public datePickerInstance:DatePicker;
-
- public useDefaultTrigger = false;
-
- text = {
- apply: this.I18n.t('js.modals.button_apply'),
- cancel: this.I18n.t('js.button_cancel'),
- date: this.I18n.t('js.work_packages.properties.date'),
- placeholder: this.I18n.t('js.placeholders.default'),
- today: this.I18n.t('js.label_today'),
- ignoreNonWorkingDays: {
- title: this.I18n.t('js.work_packages.datepicker_modal.ignore_non_working_days.title'),
- },
- };
-
- constructor(
- readonly I18n:I18nService,
- readonly timezoneService:TimezoneService,
- readonly injector:Injector,
- readonly cdRef:ChangeDetectorRef,
- readonly elementRef:ElementRef,
- readonly spotDropModalTeleportationService:SpotDropModalTeleportationService,
- ) {
- populateInputsFromDataset(this);
- }
-
- ngOnInit() {
- this.applyLabel = this.applyLabel || this.text.apply;
- // The showIgnoreNonWorkingDays can come from the populateInputsFromDataset,
- // hence we need to set the ignoreNonWorkingDays default here as well.
- this.ignoreNonWorkingDays = !this.showIgnoreNonWorkingDays;
- }
-
- ngAfterContentInit() {
- const trigger = (this.elementRef.nativeElement as HTMLElement).querySelector("[slot='trigger']");
- this.useDefaultTrigger = trigger === null;
- }
-
- onInputClick(event:MouseEvent) {
- event.stopPropagation();
- }
-
- save($event:Event) {
- const form = $event.target as HTMLFormElement;
-
- if (form.reportValidity()) {
- $event.preventDefault();
- this.valueChange.emit(this.workingValue);
- this.onChange(this.workingValue);
- this.writeValue(this.workingValue);
- this.opened = false;
- this.workingValue = '';
- this.cdRef.detectChanges();
- }
- }
-
- setToday():void {
- const today = parseDate(new Date()) as Date;
- this.writeWorkingValue(this.timezoneService.formattedISODate(today));
- this.enforceManualChangesToDatepicker(today);
- }
-
- changeNonWorkingDays():void {
- this.initializeDatepicker(false);
- this.cdRef.detectChanges();
- }
-
- changeValueFromInputDebounced = debounce(this.changeValueFromInput.bind(this), 16);
-
- changeValueFromInput(value:string) {
- this.valueChange.emit(value);
- this.onChange(value);
- this.writeValue(value);
-
- const date = parseDate(value || '');
-
- if (date !== '') {
- const dateString = this.timezoneService.formattedISODate(date);
- this.writeWorkingValue(dateString);
- this.enforceManualChangesToDatepicker(date);
- this.onTouched(dateString);
- }
- this.cdRef.detectChanges();
- }
-
- private enforceManualChangesToDatepicker(enforceDate?:Date) {
- const date = parseDate(this.workingDate || '');
- setDates(date, this.datePickerInstance, enforceDate);
- }
-
- private initializeDatepickerAfterOpen():void {
- this.spotDropModalTeleportationService
- .afterRenderOnce$(true)
- .subscribe(() => {
- this.initializeDatepicker();
- });
- }
-
- private initializeDatepicker(setInitialDate = true) {
- this.datePickerInstance?.destroy();
-
- if (setInitialDate) {
- const initialDate = parseDate(this.value || new Date()) as Date;
- this.writeWorkingValue(this.timezoneService.formattedISODate(initialDate));
- }
-
- this.datePickerInstance = new DatePicker(
- this.injector,
- this.id,
- this.workingDate || '',
- {
- mode: 'single',
- showMonths: 1,
- inline: true,
- onReady: (_date:Date[], _datestr:string, instance:flatpickr.Instance) => {
- instance.calendarContainer.classList.add('op-datepicker-modal--flatpickr-instance');
- },
- onChange: (dates:Date[]) => {
- if (dates.length > 0) {
- const dateString = this.timezoneService.formattedISODate(dates[0]);
- this.writeWorkingValue(dateString);
- this.enforceManualChangesToDatepicker(dates[0]);
- this.onTouched(dateString);
- }
-
- this.cdRef.detectChanges();
- },
- onDayCreate: async (dObj:Date[], dStr:string, fp:flatpickr.Instance, dayElem:DayElement) => {
- onDayCreate(
- dayElem,
- this.ignoreNonWorkingDays,
- await this.datePickerInstance?.isNonWorkingDay(dayElem.dateObj),
- !!this.minimalDate && dayElem.dateObj <= this.minimalDate,
- );
- },
- },
- this.flatpickrTarget.nativeElement as HTMLElement,
- );
- }
-
- writeWorkingValue(value:string):void {
- this.workingValue = value;
- this.workingDate = new Date(value);
- }
-
- writeValue(value:string):void {
- this.writeWorkingValue(value);
- this.value = value;
- }
-
- onChange = (_:string):void => {};
-
- onTouched = (_:string):void => {};
-
- registerOnChange(fn:(_:string) => void):void {
- this.onChange = fn;
- }
-
- registerOnTouched(fn:(_:string) => void):void {
- this.onTouched = fn;
- }
-}
diff --git a/frontend/src/app/shared/components/op-non-working-days-list/op-non-working-days-list.component.html b/frontend/src/app/shared/components/op-non-working-days-list/op-non-working-days-list.component.html
index b97b5d1b354..acd7caeec96 100644
--- a/frontend/src/app/shared/components/op-non-working-days-list/op-non-working-days-list.component.html
+++ b/frontend/src/app/shared/components/op-non-working-days-list/op-non-working-days-list.component.html
@@ -19,7 +19,7 @@
<div
class="op-non-working-days-list--add-button"
>
- <op-single-date-picker
+ <op-modal-single-date-picker
id="test"
name="test"
[showIgnoreNonWorkingDays]="false"
@@ -54,6 +54,6 @@
<span class="spot-icon spot-icon_add"></span>
<span [textContent]="text.add_non_working_day"></span>
</button>
- </op-single-date-picker>
+ </op-modal-single-date-picker>
</div>
diff --git a/frontend/src/app/shared/shared.module.ts b/frontend/src/app/shared/shared.module.ts
index 93b4199c07c..2c1b554262f 100644
--- a/frontend/src/app/shared/shared.module.ts
+++ b/frontend/src/app/shared/shared.module.ts
@@ -79,7 +79,6 @@ import { OpDatePickerWorkingDaysToggleComponent } from 'core-app/shared/componen
import { OpDatePickerSchedulingToggleComponent } from 'core-app/shared/components/datepicker/scheduling-mode/datepicker-scheduling-toggle.component';
// Old datepickers
-import { OpSingleDatePickerComponent } from 'core-app/shared/components/datepicker/single-date-picker/single-date-picker.component';
import { OpMultiDatePickerComponent } from 'core-app/shared/components/datepicker/multi-date-picker/multi-date-picker.component';
import { ToastsContainerComponent } from './components/toaster/toasts-container.component';
@@ -222,9 +221,8 @@ export function bootstrapModule(injector:Injector):void {
OpWpMultiDateFormComponent,
OpDatePickerWorkingDaysToggleComponent,
OpDatePickerSchedulingToggleComponent,
-
+
// Old datepickers
- OpSingleDatePickerComponent,
OpMultiDatePickerComponent,
OpNonWorkingDaysListComponent,
@@ -294,9 +292,8 @@ export function bootstrapModule(injector:Injector):void {
OpWpMultiDateFormComponent,
OpDatePickerWorkingDaysToggleComponent,
OpDatePickerSchedulingToggleComponent,
-
+
// Old datepickers
- OpSingleDatePickerComponent,
OpMultiDatePickerComponent,
],
})
diff --git a/modules/costs/app/views/cost_types/index.html.erb b/modules/costs/app/views/cost_types/index.html.erb
index 8575cdf53a5..28b17e0575e 100644
--- a/modules/costs/app/views/cost_types/index.html.erb
+++ b/modules/costs/app/views/cost_types/index.html.erb
@@ -44,7 +44,7 @@ See COPYRIGHT and LICENSE files for more details.
<li class="simple-filters--filter">
<%= styled_label_tag :fixed_date, t(:'attributes.fixed_date'), class: 'simple-filters--filter-name' %>
<div class='simple-filters--filter-value'>
- <%= angular_component_tag 'op-single-date-picker',
+ <%= angular_component_tag 'op-basic-single-date-picker',
inputs: {
value: @fixed_date,
id: :start_date,
diff --git a/spec/features/work_packages/custom_actions/custom_actions_spec.rb b/spec/features/work_packages/custom_actions/custom_actions_spec.rb
index b269debadfd..822b7a1b829 100644
--- a/spec/features/work_packages/custom_actions/custom_actions_spec.rb
+++ b/spec/features/work_packages/custom_actions/custom_actions_spec.rb
@@ -293,7 +293,6 @@ describe 'Custom actions', js: true do
find("#custom_action_actions_custom_field_#{date_custom_field.id}_visible").click
datepicker = Components::Datepicker.new 'body'
datepicker.set_date date
- datepicker.save!
new_ca_page.add_action('Type', other_type.name)
new_ca_page.expect_action('type', other_type.id)