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
Use basic single date picker in the tabular form builder (#12134)
Yulea06aa9b5faf1
diff --git a/app/views/customizable/_form.html.erb b/app/views/customizable/_form.html.erbindex 9f15c092b75..319a09f7edb 100644--- a/app/views/customizable/_form.html.erb+++ b/app/views/customizable/_form.html.erb@@ -48,9 +48,16 @@ See COPYRIGHT and LICENSE files for more details.custom_field.attribute_name,(show_required ? '-required' : ''),wide_labels] do- options = {- container_class: custom_field.field_format == 'text' ? '-xxwide' : input_size,- }+ container_class = case custom_field.field_format+ when 'text'+ '-xxwide'+ when 'date'+ '-xslim'+ else+ input_size+ end++ options = { container_class: }if help_textoptions[:help_text] = help_text.merge(attribute: custom_field.attribute_name(:camel_case))diff --git a/app/views/versions/_form.html.erb b/app/views/versions/_form.html.erbindex baefea364fd..5c45368e950 100644--- a/app/views/versions/_form.html.erb+++ b/app/views/versions/_form.html.erb@@ -58,11 +58,11 @@ See COPYRIGHT and LICENSE files for more details.</div><div class="form--field">- <%= f.date_picker :start_date, container_class: '-xslim' %>+ <%= f.date_picker :start_date %></div><div class="form--field">- <%= f.date_picker :effective_date, container_class: '-xslim' %>+ <%= f.date_picker :effective_date %></div><div class="form--field">diff --git a/frontend/src/app/shared/components/datepicker/basic-single-date-picker/basic-single-date-picker.component.html b/frontend/src/app/shared/components/datepicker/basic-single-date-picker/basic-single-date-picker.component.htmlindex 617ca8c7dae..cab75064a89 100644--- a/frontend/src/app/shared/components/datepicker/basic-single-date-picker/basic-single-date-picker.component.html+++ b/frontend/src/app/shared/components/datepicker/basic-single-date-picker/basic-single-date-picker.component.html@@ -12,4 +12,5 @@[ngModel]="value"(ngModelChange)="changeValueFromInputDebounced($event)"(focus)="showDatePicker()"+ [attr.data-remote-field-key]="remoteFieldKey"/>diff --git a/frontend/src/app/shared/components/datepicker/basic-single-date-picker/basic-single-date-picker.component.ts b/frontend/src/app/shared/components/datepicker/basic-single-date-picker/basic-single-date-picker.component.tsindex f08ea00e1d3..624d2f03a7b 100644--- a/frontend/src/app/shared/components/datepicker/basic-single-date-picker/basic-single-date-picker.component.ts+++ b/frontend/src/app/shared/components/datepicker/basic-single-date-picker/basic-single-date-picker.component.ts@@ -27,7 +27,7 @@//++import {- AfterViewInit,+ AfterViewInit,ChangeDetectionStrategy,ChangeDetectorRef,Component,@@ -98,6 +98,8 @@ export class OpBasicSingleDatePickerComponent implements ControlValueAccessor, A@Input() inputClassNames = '';+ @Input() remoteFieldKey = null;+@ViewChild('input') input:ElementRef;text = {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 a1e0324b48a..370c210857e 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@@ -92,7 +92,5 @@<input[name]="name"[value]="value"- [ngClass]="{ 'remote-field--input': !!remoteFieldKey }"- [attr.data-remote-field-key]="remoteFieldKey"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.tsindex 0206a00cf0b..f5b4e3d5965 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@@ -95,8 +95,6 @@ export class OpSingleDatePickerComponent implements ControlValueAccessor, OnInit@Input() name = '';- @Input() remoteFieldKey = '';-@Input() required = false;@Input() minimalDate:Date|null = null;diff --git a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/date-input/date-input.component.ts b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/date-input/date-input.component.tsindex 0f9cc3a5888..6240f376eec 100644--- a/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/date-input/date-input.component.ts+++ b/frontend/src/app/shared/components/dynamic-forms/components/dynamic-inputs/date-input/date-input.component.ts@@ -1,9 +1,18 @@-import { Component } from '@angular/core';+import { ChangeDetectionStrategy, Component, HostBinding } from '@angular/core';import { FieldType } from '@ngx-formly/core';@Component({selector: 'op-date-input',+ changeDetection: ChangeDetectionStrategy.OnPush,templateUrl: './date-input.component.html',styleUrls: ['./date-input.component.scss'],})-export class DateInputComponent extends FieldType {}+export class DateInputComponent extends FieldType {+ @HostBinding('class') get class() {+ return (this.model?.id === 'projects' && this.key.toString().startsWith('customField'))+ ? 'form--date-picker-container -xslim'+ : null;+ }++ model:IOPFormModel;+}diff --git a/frontend/src/app/shared/components/time_entries/form/form.component.html b/frontend/src/app/shared/components/time_entries/form/form.component.htmlindex 6aed2845647..1e36f04786c 100644--- a/frontend/src/app/shared/components/time_entries/form/form.component.html+++ b/frontend/src/app/shared/components/time_entries/form/form.component.html@@ -83,7 +83,8 @@</div><div class="attributes-map--value"><op-editable-attribute-field [resource]="entry"- [fieldName]="cf.key">+ [fieldName]="cf.key"+ [wrapperClasses]="cf.type === 'Date' ? '-tiny' : null"></op-editable-attribute-field></div></ng-container>diff --git a/frontend/src/app/shared/components/time_entries/form/form.component.ts b/frontend/src/app/shared/components/time_entries/form/form.component.tsindex 2faf1063993..48853dcaeaf 100644--- a/frontend/src/app/shared/components/time_entries/form/form.component.ts+++ b/frontend/src/app/shared/components/time_entries/form/form.component.ts@@ -44,7 +44,7 @@ export class TimeEntryFormComponent extends UntilDestroyedMixin implements OnInipublic schema:SchemaResource;- public customFields:{ key:string, label:string }[] = [];+ public customFields:{ key:string, label:string, type:string }[] = [];constructor(readonly halEditing:HalResourceEditingService,readonly cdRef:ChangeDetectorRef,@@ -100,9 +100,13 @@ export class TimeEntryFormComponent extends UntilDestroyedMixin implements OnIniprivate setCustomFields() {Object.entries(this.schema).forEach(([key, keySchema]) => {- if (/customField\d+/.exec(key)) {- this.customFields.push({ key, label: keySchema.name });+ if (/customField\d+/.exec(key) && this.isACustomField(keySchema)) {+ this.customFields.push({ key, label: keySchema.name || '', type: keySchema.type });}});}++ private isACustomField(obj:unknown):obj is IOPFieldSchema {+ return !!(obj as IOPFieldSchema).type;+ }}diff --git a/lib/tabular_form_builder.rb b/lib/tabular_form_builder.rbindex ad43f05ebdd..09b30c678cc 100644--- a/lib/tabular_form_builder.rb+++ b/lib/tabular_form_builder.rb@@ -85,6 +85,7 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilderdef date_picker(field, options = {})options[:class] = Array(options[:class])+ options[:container_class] ||= '-xslim'merge_required_attributes(options[:required], options)options[:visible_overflow] = true@@ -104,6 +105,7 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilderif options.dig(:data, :'remote-field-key')inputs['remote-field-key'] = options.dig(:data, :'remote-field-key')+ inputs[:inputClassNames] = 'remote-field--input'endif !options[:show_ignore_non_working_days].nil?@@ -111,7 +113,7 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilderendlabel = label_for_field(field, label_options)- input = angular_component_tag('op-single-date-picker',+ input = angular_component_tag('op-basic-single-date-picker',class: options[:class],inputs:)(label + container_wrap_field(input, :date_picker, options))diff --git a/modules/costs/spec/features/members_hourly_rates_spec.rb b/modules/costs/spec/features/members_hourly_rates_spec.rbindex a468bf40e4f..d701b216c4a 100644--- a/modules/costs/spec/features/members_hourly_rates_spec.rb+++ b/modules/costs/spec/features/members_hourly_rates_spec.rb@@ -57,9 +57,8 @@ describe 'hourly rates on a member', js: true dosleep(0.1)click_link_or_button 'Add rate'- datepicker = Components::Datepicker.new+ datepicker = Components::BasicDatepicker.newdatepicker.set_date(date.strftime('%Y-%m-%d'))- datepicker.save!within "tr[id^='user_new_rate_attributes_']" dofill_in 'Rate', with: rate@@ -69,9 +68,8 @@ describe 'hourly rates on a member', js: true dodef change_rate_date(from:, to:)input = find("table.rates .date input[data-value='#{from.strftime('%Y-%m-%d')}']")input.click- datepicker = Components::Datepicker.new+ datepicker = Components::BasicDatepicker.newdatepicker.set_date(to.strftime('%Y-%m-%d'))- datepicker.save!endbefore dodiff --git a/modules/meeting/app/views/meetings/_form.html.erb b/modules/meeting/app/views/meetings/_form.html.erbindex 76fcb67b69d..371ec4d76ae 100644--- a/modules/meeting/app/views/meetings/_form.html.erb+++ b/modules/meeting/app/views/meetings/_form.html.erb@@ -50,8 +50,7 @@ See COPYRIGHT and LICENSE files for more details.<%= f.date_picker :start_date,id: 'meeting-form-start-date',required: true,- no_label: true,- container_class: '-xslim'+ no_label: true%><label for="meeting-form-start-time" class="hidden-for-sighted"><%= Meeting.human_attribute_name(:start_time) %>diff --git a/modules/meeting/spec/support/pages/meetings/new.rb b/modules/meeting/spec/support/pages/meetings/new.rbindex 3ee3174ea14..d9fc77915e1 100644--- a/modules/meeting/spec/support/pages/meetings/new.rb+++ b/modules/meeting/spec/support/pages/meetings/new.rb@@ -49,9 +49,8 @@ module Pages::Meetingsdef set_start_date(date)find_by_id('meeting_start_date').click- datepicker = Components::Datepicker.new+ datepicker = Components::BasicDatepicker.newdatepicker.set_date(date)- datepicker.save!enddef set_start_time(time)diff --git a/spec/lib/custom_field_form_builder_spec.rb b/spec/lib/custom_field_form_builder_spec.rbindex c7126bff451..f8d9ff26f4e 100644--- a/spec/lib/custom_field_form_builder_spec.rb+++ b/spec/lib/custom_field_form_builder_spec.rb@@ -98,9 +98,16 @@ describe CustomFieldFormBuilder doendit 'outputs element' do- expect(output).to be_html_eql(%{-<op-single-date-picker class="custom-class" data-value="null" data-id='"user_custom_field_#{custom_field.id}"' data-name='"user[custom_field_#{custom_field.id}]"'></op-single-date-picker>- }).at_path('op-single-date-picker')+ expect(output).to be_html_eql(+ <<~HTML+ <op-basic-single-date-picker+ class="custom-class"+ data-value="null"+ data-id='"user_custom_field_#{custom_field.id}"'+ data-name='"user[custom_field_#{custom_field.id}]"'+ ></op-basic-single-date-picker>+ HTML+ ).at_path('op-basic-single-date-picker')endend