-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start on using Primer components inside the datepicker modal
- Loading branch information
Showing
9 changed files
with
131 additions
and
10 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
app/components/work_packages/date_picker/dialog_content_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<%= | ||
content_tag("turbo-frame", id: "wp-datepicker-dialog--content") do | ||
render(Primer::Alpha::Banner.new(scheme: banner_scheme, | ||
full: true, | ||
icon: :info, | ||
description: banner_description)) do |banner| | ||
banner.with_action_button(href: "/todo") { I18n.t("js.work_packages.datepicker_modal.show_relations") } | ||
banner_title | ||
end | ||
end | ||
%> |
75 changes: 75 additions & 0 deletions
75
app/components/work_packages/date_picker/dialog_content_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# frozen_string_literal: true | ||
|
||
module WorkPackages | ||
module DatePicker | ||
class DialogContentComponent < ApplicationComponent | ||
include OpPrimer::ComponentHelpers | ||
|
||
def initialize(work_package:) | ||
super | ||
|
||
@work_package = work_package | ||
end | ||
|
||
private | ||
|
||
def manually_scheduled? | ||
@work_package.schedule_manually | ||
end | ||
|
||
def banner_scheme | ||
manually_scheduled? ? :warning : :default | ||
end | ||
|
||
def banner_title | ||
if manually_scheduled? | ||
I18n.t("js.work_packages.datepicker_modal.banner.title.manually_scheduled") | ||
elsif children.any? | ||
I18n.t("js.work_packages.datepicker_modal.banner.title.automatic_with_children") | ||
elsif predecessor_relations.any? | ||
I18n.t("js.work_packages.datepicker_modal.banner.title.automatic_with_predecessor") | ||
end | ||
end | ||
|
||
def banner_description | ||
if manually_scheduled? | ||
if children.any? | ||
return I18n.t("js.work_packages.datepicker_modal.banner.description.manual_with_children") | ||
elsif predecessor_relations.any? | ||
if overlapping_predecessor? | ||
return I18n.t("js.work_packages.datepicker_modal.banner.description.manual_overlap_with_predecessors") | ||
elsif predecessor_with_large_gap? | ||
return I18n.t("js.work_packages.datepicker_modal.banner.description.manual_gap_between_predecessors") | ||
end | ||
end | ||
end | ||
|
||
I18n.t("js.work_packages.datepicker_modal.banner.description.click_on_show_relations_to_open_gantt", | ||
button_name: I18n.t("js.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 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters