-
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
11 changed files
with
264 additions
and
30 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
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,72 @@ | ||
<%= | ||
component_wrapper do | ||
component_collection do |collection| | ||
if show_banner? | ||
collection.with_component(Primer::Alpha::Banner.new(scheme: banner_scheme, | ||
full: true, | ||
icon: :info, | ||
description: banner_description, | ||
mb: 3, | ||
classes: "rounded-top-2")) do |banner| | ||
banner.with_action_button(tag: :a, href: banner_link, target: "_blank") { I18n.t("work_packages.datepicker_modal.show_relations") } | ||
banner_title | ||
end | ||
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 | ||
%> |
101 changes: 101 additions & 0 deletions
101
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,101 @@ | ||
# frozen_string_literal: true | ||
|
||
module WorkPackages | ||
module DatePicker | ||
class DialogContentComponent < ApplicationComponent | ||
include OpPrimer::ComponentHelpers | ||
include OpTurbo::Streamable | ||
|
||
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 | ||
|
||
def banner_scheme | ||
@manually_scheduled ? :warning : :default | ||
end | ||
|
||
def banner_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 banner_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 banner_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 | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= | ||
content_tag("turbo-frame", id: "wp-datepicker-dialog--content") do | ||
render(WorkPackages::DatePicker::DialogContentComponent.new(work_package:, manually_scheduled:)) | ||
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
Oops, something went wrong.