11defmodule DashboardWeb.Live.Modal.DateTimePatternsModal do
22 use DashboardWeb , :component
3+ import Dashboard.Helpers
34
45 @ date_time_pattern_hints [
56 { "{YYYY}" , "full year number (0..9999)" } ,
@@ -18,14 +19,17 @@ defmodule DashboardWeb.Live.Modal.DateTimePatternsModal do
1819 ]
1920
2021 def date_time_patterns_modal ( assigns ) do
21- custom_date_patterns_added =
22+ custom_date_time_patterns_added =
2223 assigns . changeset |> Ecto.Changeset . get_field ( :date_time_patterns , [ ] ) |> length ( ) != 0
2324
25+ custom_date_patterns_added =
26+ assigns . changeset |> Ecto.Changeset . get_field ( :date_patterns , [ ] ) |> length ( ) != 0
27+
2428 ~H"""
2529 < DashboardWeb.Live.Modals . modal title = "Add additional Date Time patterns " >
2630 < div >
2731 < div class = "fst-italic mt-2 ms-2 " >
28- Add datetime patterns
32+ Add date patterns
2933 </ div >
3034
3135 <!-- TODO: Make this better: data list only works on double click -->
@@ -37,28 +41,65 @@ defmodule DashboardWeb.Live.Modal.DateTimePatternsModal do
3741
3842 < div class = "container " >
3943 < div class = "row " >
40- < div class = "col-6 border " id = "date-time-patterns-container " >
41- <%= if custom_date_patterns_added do %>
42- <%= for { date_time_patterns_form , index } <- Enum . with_index ( inputs_for ( @ form , :date_time_patterns ) , 1 ) do %>
43- < div class = "d-flex flex-row " >
44- < div class = "input-group mb-3 " >
45- < span class = "input-group-text fw-bold pe-2 pt-1 " > <%= index %> .</ span >
46- <%= text_input date_time_patterns_form , :pattern , class: "form-control" , placeholder: "Pattern" , list: "date-time-patterns-suggestions" %>
44+ < div class = "col-6 " >
45+ < div class = "border " >
46+ < div class = "scrollable-container " id = "date-patterns-container " class = "border " >
47+ <%= if custom_date_patterns_added do %>
48+ <%= for { date_patterns_form , index } <- Enum . with_index ( inputs_for ( @ form , :date_patterns ) , 1 ) do %>
49+ < div class = "d-flex flex-row " >
50+ < div class = "input-group mb-3 " >
51+ < span class = "input-group-text fw-bold pe-2 pt-1 " > <%= index %> .</ span >
52+ <%= text_input date_patterns_form , :pattern , class: input_class ( index , :date , @ matching_date_time ) , placeholder: "Pattern" , list: "date-patterns-suggestions" %>
53+ </ div >
54+
55+ <%= hidden_input ( date_patterns_form , :id ) %>
56+
57+ < div role = "button " phx-click = "remove-date-pattern " phx-value-attrid = { Ecto.Changeset . get_field ( date_patterns_form . source , :id ) } >
58+ < IconSvg . remove_icon class = "ms-2 pt-1 " />
59+ </ div >
60+ </ div >
61+ <% end %>
62+ <% else %>
63+ < div class = "text-center mt-4 pt-4 " >
64+ < div > < IconSvg . empty_icon { % { height: 100 , width: 100 } } /> </ div >
65+ < div class = "fw-bold fst-italic font-monospace text-danger " > No custom date patterns added! </ div >
4766 </ div >
67+ <% end %>
68+ </ div >
69+ < div class = "add-pattern " phx-click = "add-new-date-pattern " >
70+ < IconSvg . add_icon { % { width: 28 } } />
71+ < span > Add datetime pattern </ span >
72+ </ div >
73+ </ div >
74+ < div class = "border " >
75+ < div class = "scrollable-container " id = "date-time-patterns-container " >
76+ <%= if custom_date_time_patterns_added do %>
77+ <%= for { date_time_patterns_form , index } <- Enum . with_index ( inputs_for ( @ form , :date_time_patterns ) , 1 ) do %>
78+ < div class = "d-flex flex-row " >
79+ < div class = "input-group mb-3 " >
80+ < span class = "input-group-text fw-bold pe-2 pt-1 " > <%= index %> .</ span >
81+ <%= text_input date_time_patterns_form , :pattern , class: input_class ( index , :date_time , @ matching_date_time ) , placeholder: "Pattern" , list: "date-time-patterns-suggestions" %>
82+ </ div >
4883
49- <%= hidden_input ( date_time_patterns_form , :id ) %>
84+ <%= hidden_input ( date_time_patterns_form , :id ) %>
5085
51- < div role = "button " phx-click = "remove-date-time-pattern " phx-value-attrid = { Ecto.Changeset . get_field ( date_time_patterns_form . source , :id ) } >
52- < IconSvg . remove_icon class = "ms-2 pt-1 " />
86+ < div role = "button " phx-click = "remove-date-time-pattern " phx-value-attrid = { Ecto.Changeset . get_field ( date_time_patterns_form . source , :id ) } >
87+ < IconSvg . remove_icon class = "ms-2 pt-1 " />
88+ </ div >
89+ </ div >
90+ <% end %>
91+ <% else %>
92+ < div class = "text-center mt-4 pt-4 " >
93+ < div > < IconSvg . empty_icon { % { height: 100 , width: 100 } } /> </ div >
94+ < div class = "fw-bold fst-italic font-monospace text-danger " > No custom date time patterns added! </ div >
5395 </ div >
54- </ div >
55- <% end %>
56- <% else %>
57- < div class = "text-center mt-4 pt-4 " >
58- < div > < IconSvg . empty_icon { % { height: 100 , width: 100 } } /> </ div >
59- < div class = "fw-bold fst-italic font-monospace text-danger " > No custom date time patterns added! </ div >
96+ <% end %>
97+ </ div >
98+ < div class = "add-pattern " phx-click = "add-new-date-time-pattern " >
99+ < IconSvg . add_icon { % { width: 28 } } />
100+ < span > Add datetime pattern </ span >
60101 </ div >
61- <% end % >
102+ </ div >
62103 </ div >
63104 < div class = "col-6 border " >
64105 < p >
@@ -75,10 +116,20 @@ defmodule DashboardWeb.Live.Modal.DateTimePatternsModal do
75116 <% end %>
76117 </ div >
77118 < p > *Fractional seconds and timezones are not supported. </ p >
78- </ div >
79- < div class = "col-8 add-link text-center " >
80- < IconSvg . add_icon { % { width: 28 } } />
81- < span phx-click = "add-new-date-time-pattern " > Add datetime pattern </ span >
119+
120+ < div id = "date-time-try-it " >
121+ < div class = "d-flex flex-row " >
122+ <!-- TODO: Fix tolltip title gone on hook init -->
123+ < . popup
124+ title = "Enter a sample date or date time to check if it matches any added custom patterns "
125+ id = "date-time-try-it-hint " />
126+ < label for = "date-time-trial " > Enter sample date time </ label >
127+ </ div >
128+ <%= if present? ( Ecto.Changeset . get_field ( @ changeset , :date_time_trial ) ) && is_nil ( @ matching_date_time ) do %>
129+ < span > No matching patterns found </ span >
130+ <% end %>
131+ <%= text_input @ form , :date_time_trial , class: "form-control" , placeholder: "Pattern" , id: "date-time-trial" %>
132+ </ div >
82133 </ div >
83134 </ div >
84135 </ div >
@@ -88,4 +139,7 @@ defmodule DashboardWeb.Live.Modal.DateTimePatternsModal do
88139 end
89140
90141 defp date_time_pattern_hints , do: @ date_time_pattern_hints
142+
143+ defp input_class ( index , type , { match_type , match_index } ) when type == match_type and index == match_index + 1 , do: "form-control matched-input"
144+ defp input_class ( _index , _type , _ ) , do: "form-control"
91145end
0 commit comments