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

Add slot for extra form fields in date picker, make non working days toggle configurable

Benjamin Bädorf7401f7c749f7
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
index 9535e46907f..06b73cd0b88 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
@@ -1,16 +1,14 @@
<spot-drop-modal
[open]="opened"
- (closed)="close()"
+ (closed)="opened = false"
>
- <button
+ <input
slot="trigger"
- type="button"
- class="spot-link"
- (click)="open()"
- >
- {{ value || text.date }}
- <span class="spot-icon spot-icon_calendar"></span>
- </button>
+ type="text"
+ class="spot-input"
+ (click)="onInputClick($event)"
+ [value]="value"
+ />
<form
slot="body"
@@ -23,6 +21,7 @@
(submit)="save($event)"
>
<spot-selector-field
+ *ngIf="showIgnoreNonWorkingDays"
[reverseLabel]="true"
[label]="text.ignoreNonWorkingDays.title"
>
@@ -35,6 +34,8 @@
></spot-switch>
</spot-selector-field>
+ <ng-content select="[slot=extra-fields]"></ng-content>
+
<spot-form-field
[label]="text.date"
>
@@ -61,7 +62,7 @@
<div class="spot-action-bar--right">
<button
type="button"
- (click)="close()"
+ (click)="opened = false"
class="button spot-action-bar--action"
data-qa-selector="op-datepicker-modal--action"
[textContent]="text.cancel"
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
index 1a1e76dfa24..4b74e55f436 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
@@ -70,6 +70,8 @@ export const opSingleDatePickerSelector = 'op-single-date-picker';
],
})
export class OpSingleDatePickerComponent implements ControlValueAccessor, OnInit {
+ @Output('closed') closed = new EventEmitter();
+
@Output('valueChange') valueChange = new EventEmitter();
private _value = '';
@@ -91,7 +93,29 @@ export class OpSingleDatePickerComponent implements ControlValueAccessor, OnInit
@Input() minimalDate:Date|null = null;
- @Input() opened = false;
+ private _opened = false;
+
+ @Input() set opened(opened:boolean) {
+ if (this._opened === !!opened) {
+ return;
+ }
+
+ this._opened = !!opened;
+
+ if (this._opened) {
+ this.initializeDatepicker();
+ } else {
+ this.closed.emit();
+ }
+ }
+
+ get opened() {
+ return this.opened;
+ }
+
+ @Input() showIgnoreNonWorkingDays = true;
+
+ @Input() ignoreNonWorkingDays = false;
@ViewChild('flatpickrTarget') flatpickrTarget:ElementRef;
@@ -99,8 +123,6 @@ export class OpSingleDatePickerComponent implements ControlValueAccessor, OnInit
public workingDate:Date = new Date();
- public ignoreNonWorkingDays = false;
-
public datePickerInstance:DatePicker;
text = {
@@ -131,13 +153,8 @@ export class OpSingleDatePickerComponent implements ControlValueAccessor, OnInit
}
}
- open() {
- this.opened = true;
- this.initializeDatepicker();
- }
-
- close() {
- this.opened = false;
+ onInputClick(event:MouseEvent) {
+ event.stopPropagation();
}
save($event:Event) {
@@ -145,7 +162,7 @@ export class OpSingleDatePickerComponent implements ControlValueAccessor, OnInit
this.valueChange.emit(this.workingValue);
this.onChange(this.workingValue);
this.writeValue(this.workingValue);
- this.close();
+ this.opened = false;
}
setToday():void {
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.ts
index cbf5055712e..22a66bef029 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
@@ -40,7 +40,11 @@ export class SpotDropModalComponent implements OnDestroy {
@Input('open')
@HostBinding('class.spot-drop-modal_opened')
set open(value:boolean) {
- this._open = value;
+ if (this._open === !!value) {
+ return;
+ }
+
+ this._open = !!value;
if (this._open) {
/* We have to set these listeners next tick, because they're so far up the tree.
@@ -67,6 +71,8 @@ export class SpotDropModalComponent implements OnDestroy {
document.body.removeEventListener('keydown', this.escapeListener);
window.removeEventListener('resize', this.appHeightListener);
window.removeEventListener('orientationchange', this.appHeightListener);
+
+ console.log('close?', value);
this.closed.emit();
}
diff --git a/frontend/src/global_styles/content/_table.sass b/frontend/src/global_styles/content/_table.sass
index a547cba2c99..56c3e18cac3 100644
--- a/frontend/src/global_styles/content/_table.sass
+++ b/frontend/src/global_styles/content/_table.sass
@@ -62,6 +62,9 @@ $toolbar-height--mobile: 100px
&.-with-footer
padding-bottom: var(--generic-table--footer-height)
+ &_visible-overflow
+ overflow: visible
+
.generic-table--results-container
height: 100%
overflow:
diff --git a/lib/tabular_form_builder.rb b/lib/tabular_form_builder.rb
index 33d82c04382..6d986c8da1b 100644
--- a/lib/tabular_form_builder.rb
+++ b/lib/tabular_form_builder.rb
@@ -82,6 +82,15 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder
super
end
+ def date_field(field, value, options = {})
+ angular_component_tag 'op-single-date-picker',
+ class: 'date costs-date-picker',
+ inputs: {
+ id: field_id(field),
+ name: field_name(field)
+ }
+ end
+
def radio_button(field, value, options = {}, *args)
options[:class] = Array(options[:class]) + %w(form--radio-button)
diff --git a/modules/costs/app/views/cost_types/_rate.html.erb b/modules/costs/app/views/cost_types/_rate.html.erb
index 95f3bc91f77..fd514cc55fe 100644
--- a/modules/costs/app/views/cost_types/_rate.html.erb
+++ b/modules/costs/app/views/cost_types/_rate.html.erb
@@ -50,10 +50,20 @@ See COPYRIGHT and LICENSE files for more details.
<tr class="subform-row <%= classes %>" id="<%= id_prefix %>">
<td>
<label class="hidden-for-sighted" for="<%= "#{id_prefix}_valid_from" %>"><%= Rate.human_attribute_name(:valid_from) %></label>
- <%= rate_form.text_field :valid_from,
- class: 'date costs-date-picker -augmented-datepicker',
+ <!--
+ <%= rate_form.date_field :valid_from,
+ class: 'date costs-date-picker',
index: id_or_index,
required: templated ? false : true %>
+ -->
+ <%= angular_component_tag 'op-single-date-picker',
+ class: 'date costs-date-picker',
+ inputs: {
+ value: @fixed_date,
+ id: "#{id_prefix}_valid_from",
+ name: "cost_type[new_rate_attributes[0][valid_from]"
+ }
+ %>
</td>
<td class="currency">
<span class="inline-label">
diff --git a/modules/costs/app/views/cost_types/index.html.erb b/modules/costs/app/views/cost_types/index.html.erb
index 4b883339900..8575cdf53a5 100644
--- a/modules/costs/app/views/cost_types/index.html.erb
+++ b/modules/costs/app/views/cost_types/index.html.erb
@@ -44,7 +44,13 @@ 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'>
- <%= styled_text_field_tag :fixed_date, @fixed_date, class: '-augmented-datepicker' %>
+ <%= angular_component_tag 'op-single-date-picker',
+ inputs: {
+ value: @fixed_date,
+ id: :start_date,
+ name: :fixed_date
+ }
+ %>
</div>
</li>
<li class="simple-filters--filter">