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
Start on using Primer components inside the datepicker modal
Henriette Dargec484150944ff
diff --git a/app/components/work_packages/date_picker/banner_component.html.erb b/app/components/work_packages/date_picker/banner_component.html.erbnew file mode 100644index 00000000000..cc1ad5083ec--- /dev/null+++ b/app/components/work_packages/date_picker/banner_component.html.erb@@ -0,0 +1,11 @@+<%=+ render(Primer::Alpha::Banner.new(scheme:,+ full: true,+ icon: :info,+ description:,+ mb: 3,+ classes: "rounded-top-2")) do |banner|+ banner.with_action_button(tag: :a, href: link, target: "_blank") { I18n.t("work_packages.datepicker_modal.show_relations") }+ title+ end+%>diff --git a/app/components/work_packages/date_picker/banner_component.rb b/app/components/work_packages/date_picker/banner_component.rbnew file mode 100644index 00000000000..7a1d2f70626--- /dev/null+++ b/app/components/work_packages/date_picker/banner_component.rb@@ -0,0 +1,122 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++# frozen_string_literal: true++module WorkPackages+ module DatePicker+ class BannerComponent < ApplicationComponent+ def initialize(work_package:, manually_scheduled: true)+ super++ @work_package = work_package+ @manually_scheduled = manually_scheduled+ end++ private++ def scheme+ @manually_scheduled ? :warning : :default+ end++ def link+ gantt_index_path(+ query_props: {+ c: %w[id subject type status assignee project startDate dueDate],+ tll: '{"left":"startDate","right":"subject","farRight":null}',+ tzl: "auto",+ t: "id:asc",+ tv: true,+ hi: true,+ f: [+ { "n" => "id", "o" => "=", "v" => all_relational_wp_ids }+ ]+ }.to_json.freeze+ )+ end++ def title+ if @manually_scheduled+ I18n.t("work_packages.datepicker_modal.banner.title.manually_scheduled")+ elsif children.any?+ I18n.t("work_packages.datepicker_modal.banner.title.automatic_with_children")+ elsif predecessor_relations.any?+ I18n.t("work_packages.datepicker_modal.banner.title.automatic_with_predecessor")+ end+ end++ def description+ if @manually_scheduled+ if children.any?+ return I18n.t("work_packages.datepicker_modal.banner.description.manual_with_children")+ elsif predecessor_relations.any?+ if overlapping_predecessor?+ return I18n.t("work_packages.datepicker_modal.banner.description.manual_overlap_with_predecessors")+ elsif predecessor_with_large_gap?+ return I18n.t("work_packages.datepicker_modal.banner.description.manual_gap_between_predecessors")+ end+ end+ end++ I18n.t("work_packages.datepicker_modal.banner.description.click_on_show_relations_to_open_gantt",+ button_name: I18n.t("work_packages.datepicker_modal.show_relations"))+ end++ def overlapping_predecessor?+ predecessor_work_packages.any? { |wp| wp.due_date.after?(@work_package.start_date) }+ end++ def predecessor_with_large_gap?+ sorted = predecessor_work_packages.sort_by(&:due_date)+ sorted.last.due_date.before?(@work_package.start_date - 2)+ end++ def predecessor_relations+ @predecessor_relations ||= @work_package.follows_relations+ end++ def predecessor_work_packages+ @predecessor_work_packages ||= predecessor_relations+ .includes(:to)+ .map(&:to)+ end++ def children+ @children ||= @work_package.children+ end++ def all_relational_wp_ids+ @work_package+ .relations+ .pluck(:from_id, :to_id)+ .flatten+ .uniq+ end+ end+ end+enddiff --git a/app/components/work_packages/date_picker/dialog_content_component.html.erb b/app/components/work_packages/date_picker/dialog_content_component.html.erbnew file mode 100644index 00000000000..a60a86b4470--- /dev/null+++ b/app/components/work_packages/date_picker/dialog_content_component.html.erb@@ -0,0 +1,64 @@+<%=+ component_wrapper do+ component_collection do |collection|+ if show_banner?+ collection.with_component(WorkPackages::DatePicker::BannerComponent.new(work_package:, manually_scheduled:))+ end++ collection.with_component(Primer::Alpha::Dialog::Body.new) do+ flex_layout do |body|+ body.with_row(mb: 3) do+ flex_layout(align_items: :flex_end, justify_content: :space_between) do |first_row|+ first_row.with_column do+ render(Primer::Alpha::FormControl.new(label: I18n.t("work_packages.datepicker_modal.mode.title"))) do |component|+ component.with_input do+ render(Primer::Alpha::SegmentedControl.new("aria-label": I18n.t("work_packages.datepicker_modal.mode.title"))) do |control|+ control.with_item(tag: :a,+ href: datepicker_dialog_content_work_package_path(manually_scheduled: true),+ data: { turbo_stream: true },+ label: I18n.t("work_packages.datepicker_modal.mode.manual"),+ title: I18n.t("work_packages.datepicker_modal.mode.manual"),+ selected: manually_scheduled)+ control.with_item(tag: :a,+ href: datepicker_dialog_content_work_package_path(manually_scheduled: false),+ data: { turbo_stream: true },+ label: I18n.t("work_packages.datepicker_modal.mode.automatic"),+ title: I18n.t("work_packages.datepicker_modal.mode.automatic"),+ selected: !manually_scheduled)+ end+ end+ end+ end++ first_row.with_column(mb: 1) do+ render(Primer::Alpha::CheckBox.new(name: "name",+ label: I18n.t("work_packages.datepicker_modal.ignore_non_working_days.title"),+ checked: work_package.ignore_non_working_days))+ end+ end+ end++ body.with_row(mb: 3) do+ flex_layout(justify_content: :space_between, gap: 3) do |second_row|+ second_row.with_column do+ render(Primer::Alpha::TextField.new(name: :start_date,+ label: I18n.t("attributes.start_date"),+ value: work_package.start_date))+ end+ second_row.with_column do+ render(Primer::Alpha::TextField.new(name: :due_date,+ label: I18n.t("attributes.due_date"),+ value: work_package.due_date))+ end+ second_row.with_column do+ render(Primer::Alpha::TextField.new(name: :duration,+ label: I18n.t("activerecord.attributes.work_package.duration"),+ value: work_package.duration))+ end+ end+ end+ end+ end+ end+ end+%>diff --git a/app/components/work_packages/date_picker/dialog_content_component.rb b/app/components/work_packages/date_picker/dialog_content_component.rbnew file mode 100644index 00000000000..338b89310e2--- /dev/null+++ b/app/components/work_packages/date_picker/dialog_content_component.rb@@ -0,0 +1,52 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++# frozen_string_literal: true+module WorkPackages+ module DatePicker+ class DialogContentComponent < ApplicationComponent+ include OpPrimer::ComponentHelpers+ include OpTurbo::Streamable++ attr_accessor :work_package, :manually_scheduled++ def initialize(work_package:, manually_scheduled: true)+ super++ @work_package = work_package+ @manually_scheduled = ActiveModel::Type::Boolean.new.cast(manually_scheduled)+ end++ private++ def show_banner?+ true # TODO+ end+ end+ end+enddiff --git a/app/controllers/work_packages_controller.rb b/app/controllers/work_packages_controller.rbindex 5040331d917..2cd4f895b35 100644--- a/app/controllers/work_packages_controller.rb+++ b/app/controllers/work_packages_controller.rb@@ -38,12 +38,13 @@ class WorkPackagesController < ApplicationControllerbefore_action :authorize_on_work_package,:project, only: %i[show generate_pdf_dialog generate_pdf]+ before_action :authorize_on_work_package, only: %i[datepicker_dialog_content]before_action :load_and_authorize_in_optional_project,:check_allowed_export,:protect_from_unauthorized_export, only: %i[index export_dialog]before_action :authorize, only: :show_conflict_flash_message- authorization_checked! :index, :show, :export_dialog, :generate_pdf_dialog, :generate_pdf+ authorization_checked! :index, :show, :export_dialog, :generate_pdf_dialog, :generate_pdf, :datepicker_dialog_contentbefore_action :load_and_validate_query, only: :index, unless: -> { request.format.html? }before_action :load_work_packages, only: :index, if: -> { request.format.atom? }@@ -105,6 +106,29 @@ class WorkPackagesController < ApplicationControllerredirect_back(fallback_location: work_package_path(work_package))end+ def datepicker_dialog_content+ manually_scheduled = if params[:manually_scheduled].present?+ params.delete(:manually_scheduled)+ else+ work_package.schedule_manually+ end++ respond_to do |format|+ format.html do+ render :datepicker_dialog_content,+ locals: { work_package:, manually_scheduled:, params: },+ layout: false+ end++ format.turbo_stream do+ replace_via_turbo_stream(+ component: WorkPackages::DatePicker::DialogContentComponent.new(work_package:, manually_scheduled:)+ )+ render turbo_stream: turbo_streams+ end+ end+ end+def work_package_exportercase params[:template]when "contract"@@ -183,7 +207,7 @@ class WorkPackagesController < ApplicationControllerenddef project- @project ||= work_package ? work_package.project : nil+ @project ||= work_package&.projectenddef work_packagediff --git a/app/views/work_packages/datepicker_dialog_content.html.erb b/app/views/work_packages/datepicker_dialog_content.html.erbnew file mode 100644index 00000000000..41f3b4acece--- /dev/null+++ b/app/views/work_packages/datepicker_dialog_content.html.erb@@ -0,0 +1,5 @@+<%=+ content_tag("turbo-frame", id: "wp-datepicker-dialog--content") do+ render(WorkPackages::DatePicker::DialogContentComponent.new(work_package:, manually_scheduled:))+ end+%>diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 2b73395fd52..ee6fbacb738 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -702,6 +702,25 @@ en:no_results_title_text: There are currently no workflows.work_packages:+ datepicker_modal:+ banner:+ description:+ click_on_show_relations_to_open_gantt: 'Click on "%{button_name}" for Gantt overview.'+ manual_gap_between_predecessors: "There is a gap between this and all predecessors."+ manual_overlap_with_predecessors: "Overlaps with at least one predecessor."+ manual_with_children: "This has child work package but their start dates are ignored."+ title:+ automatic_with_children: "The dates are determined by child work packages."+ automatic_with_predecessor: "The start date is set by a predecessor."+ manually_scheduled: "Manually scheduled. Dates not affected by relations."+ ignore_non_working_days:+ title: "Working days only"+ mode:+ title: "Scheduling mode"+ automatic: "Automatic"+ manual: "Manual"+ show_relations: "Show relations"+x_descendants:one: "One descendant work package"other: "%{count} work package descendants"diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex 05c51103e72..1c950574ec2 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -982,15 +982,6 @@ en:comment_send_failed: "An error has occurred. Could not submit the comment."comment_updated: "The comment was successfully updated."confirm_edit_cancel: "Are you sure you want to cancel editing the work package?"- datepicker_modal:- automatically_scheduled_parent: "Automatically scheduled. Dates are derived from relations."- manually_scheduled: "Manual scheduling enabled, all relations ignored."- start_date_limited_by_relations: "Available start and finish dates are limited by relations."- changing_dates_affects_follow_relations: "Changing these dates will affect dates of related work packages."- click_on_show_relations_to_open_gantt: 'Click on "%{button_name}" for GANTT overview.'- show_relations: "Show relations"- ignore_non_working_days:- title: "Working days only"description_filter: "Filter"description_enter_text: "Enter text"description_options_hide: "Hide options"diff --git a/config/routes.rb b/config/routes.rbindex ad87e08fcf0..75bebd5bb77 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -667,6 +667,7 @@ Rails.application.routes.draw doget "/export_dialog" => "work_packages#export_dialog", on: :collection, as: "export_dialog"get :show_conflict_flash_message, on: :collection # we don't need a specific work package for this+ get "/datepicker_dialog_content" => "work_packages#datepicker_dialog_content", on: :member, as: "datepicker_dialog_content"get "/split_view/update_counter" => "work_packages/split_view#update_counter",on: :memberdiff --git a/frontend/src/app/core/path-helper/path-helper.service.ts b/frontend/src/app/core/path-helper/path-helper.service.tsindex af2408a19e4..758d1f448e7 100644--- a/frontend/src/app/core/path-helper/path-helper.service.ts+++ b/frontend/src/app/core/path-helper/path-helper.service.ts@@ -308,6 +308,10 @@ export class PathHelperService {return `${this.workPackagePath(workPackageId)}/split_view/get_relations_counter`;}+ public workPackageDatepickerDialogContentPath(workPackageId:string|number) {+ return `${this.workPackagePath(workPackageId)}/datepicker_dialog_content`;+ }+// Work Package Bulk pathspublic workPackagesBulkEditPath() {diff --git a/frontend/src/app/shared/components/datepicker/datepicker.module.ts b/frontend/src/app/shared/components/datepicker/datepicker.module.tsindex 3cfc24d62ef..25f56ca82c2 100644--- a/frontend/src/app/shared/components/datepicker/datepicker.module.ts+++ b/frontend/src/app/shared/components/datepicker/datepicker.module.ts@@ -17,6 +17,7 @@ import { OpBasicDatePickerModule } from './basic-datepicker.module';import { OpSpotModule } from 'core-app/spot/spot.module';import { OpenprojectModalModule } from '../modal/modal.module';import { OpDatePickerSheetComponent } from 'core-app/shared/components/datepicker/sheet/date-picker-sheet.component';+import { OpenprojectContentLoaderModule } from 'core-app/shared/components/op-content-loader/openproject-content-loader.module';@NgModule({imports: [@@ -27,6 +28,7 @@ import { OpDatePickerSheetComponent } from 'core-app/shared/components/datepickeOpSpotModule,OpBasicDatePickerModule,OpenprojectModalModule,+ OpenprojectContentLoaderModule,],providers: [diff --git a/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.html b/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.htmlindex 90d1fb36540..96e219433d6 100644--- a/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.html+++ b/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.html@@ -7,13 +7,22 @@tabindex="0"(submit)="doSave($event)">- <op-datepicker-banner- [scheduleManually]="scheduleManually"- class="op-datepicker-modal--banner"- ></op-datepicker-banner>+ <turbo-frame *ngIf="turboFrameSrc"+ [src]="turboFrameSrc"+ id="wp-datepicker-dialog--content">+ <op-content-loader viewBox="0 0 100 100">+ <svg:rect x="0" y="0" width="70" height="5" rx="1"/>- <div class="spot-container op-datepicker-modal--stretch-content">- <div class="op-datepicker-modal--toggle-actions-container">+ <svg:rect x="75" y="0" width="25" height="5" rx="1"/>++ <svg:rect x="0" y="10" width="100" height="8" rx="1"/>++ <svg:rect x="0" y="25" width="100" height="12" rx="1"/>+ </op-content-loader>+ </turbo-frame>++ <!--<div class="spot-container op-datepicker-modal--stretch-content">+ <div class="op-datepicker-modal--toggle-actions-container"><op-datepicker-scheduling-togglename="scheduleManually"[(ngModel)]="scheduleManually"@@ -27,7 +36,7 @@></op-datepicker-working-days-toggle></div>- <div class="op-datepicker-modal--dates-container">+ <div class="op-datepicker-modal--dates-container"><spot-form-field[label]="text.startDate"data-test-selector="datepicker-start-date"@@ -35,10 +44,10 @@<spot-text-fieldslot="input"name="startDate"- data-test-selector="op-datepicker-modal--start-date-field"- class="op-datepicker-modal--date-field"+ data-test-selector="op-datepicker-modal--start-date-field"+ class="op-datepicker-modal--date-field"[attr.data-qa-highlighted]="showFieldAsActive('start') || undefined"- [ngClass]="{'op-datepicker-modal--date-field_current' : showFieldAsActive('start')}"+ [ngClass]="{'op-datepicker-modal--date-field_current' : showFieldAsActive('start')}"[ngModel]="dates.start"(ngModelChange)="startDateChanged$.next($event)"[disabled]="!isSchedulable"@@ -49,7 +58,7 @@slot="action"type="button"class="spot-link"- [ngClass]="{ 'op-datepicker-modal--hidden-link': !showTodayLink() }"+ [ngClass]="{ 'op-datepicker-modal--hidden-link': !showTodayLink() }"(click)="setToday('start')"[textContent]="text.today"></button>@@ -61,10 +70,10 @@<spot-text-fieldslot="input"name="endDate"- data-test-selector="op-datepicker-modal--end-date-field"- class="op-datepicker-modal--date-field"+ data-test-selector="op-datepicker-modal--end-date-field"+ class="op-datepicker-modal--date-field"[attr.data-qa-highlighted]="showFieldAsActive('end') || undefined"- [ngClass]="{'op-datepicker-modal--date-field_current' : showFieldAsActive('end')}"+ [ngClass]="{'op-datepicker-modal--date-field_current' : showFieldAsActive('end')}"[ngModel]="dates.end"(ngModelChange)="endDateChanged$.next($event)"[disabled]="!isSchedulable"@@ -75,7 +84,7 @@slot="action"type="button"class="spot-link"- [ngClass]="{ 'op-datepicker-modal--hidden-link': !showTodayLink() }"+ [ngClass]="{ 'op-datepicker-modal--hidden-link': !showTodayLink() }"(click)="setToday('end')"[textContent]="text.today"></button>@@ -88,10 +97,10 @@#durationFieldslot="input"name="duration"- data-test-selector="op-datepicker-modal--duration-field"- class="op-datepicker-modal--date-field"+ data-test-selector="op-datepicker-modal--duration-field"+ class="op-datepicker-modal--date-field"[attr.data-qa-highlighted]=" showFieldAsActive('duration') || undefined"- [ngClass]="{'op-datepicker-modal--date-field_current' : showFieldAsActive('duration')}"+ [ngClass]="{'op-datepicker-modal--date-field_current' : showFieldAsActive('duration')}"[ngModel]="durationFocused ? duration : displayedDuration"[showClearButton]="currentlyActivatedDateField === 'duration'"pattern="\d*"@@ -109,7 +118,7 @@id="flatpickr-input"hidden/>- </div>+ </div>--><div class="spot-action-bar"><div class="spot-action-bar--right">diff --git a/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.ts b/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.tsindex d1dd3a218f9..357015d8c6d 100644--- a/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.ts+++ b/frontend/src/app/shared/components/datepicker/wp-multi-date-form/wp-multi-date-form.component.ts@@ -82,6 +82,7 @@ import { WorkPackageChangeset } from 'core-app/features/work-packages/componentsimport { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';import isNewResource from 'core-app/features/hal/helpers/is-new-resource';import { DateModalSchedulingService } from '../services/date-modal-scheduling.service';+import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';export type DateKeys = 'start'|'end';export type DateFields = DateKeys|'duration';@@ -132,6 +133,8 @@ export class OpWpMultiDateFormComponent extends UntilDestroyedMixin implements A@Output() save = new EventEmitter();+ public turboFrameSrc:string;+text = {save: this.I18n.t('js.button_save'),cancel: this.I18n.t('js.button_cancel'),@@ -243,6 +246,7 @@ export class OpWpMultiDateFormComponent extends UntilDestroyedMixin implements Areadonly deviceService:DeviceService,readonly weekdayService:WeekdayService,readonly focusHelper:FocusHelperService,+ readonly pathHelper:PathHelperService,) {super();@@ -289,6 +293,8 @@ export class OpWpMultiDateFormComponent extends UntilDestroyedMixin implements Athis.dates.start = this.changeset.value('startDate');this.dates.end = this.changeset.value('dueDate');this.setCurrentActivatedField(this.initialActivatedField);++ this.turboFrameSrc = this.pathHelper.workPackageDatepickerDialogContentPath(this.changeset.id);}ngAfterViewInit():void {