|
| 1 | +<style> |
| 2 | + .form-grid { |
| 3 | + display: grid; |
| 4 | + grid-template-columns: 1fr 1fr 1fr 30% 15%; |
| 5 | + gap: 20px; |
| 6 | + align-items: center; |
| 7 | + } |
| 8 | + |
| 9 | + .form-group { |
| 10 | + display: flex; |
| 11 | + flex-direction: column; |
| 12 | + padding: 10px; |
| 13 | + } |
| 14 | + |
| 15 | + /* Hide default radio buttons */ |
| 16 | + .radio-group input[type="radio"] { |
| 17 | + display: none; |
| 18 | + } |
| 19 | + |
| 20 | + /* Style the labels to look like buttons */ |
| 21 | + .radio-btn { |
| 22 | + display: inline-block; |
| 23 | + padding: 10px 20px; |
| 24 | + margin: 5px; |
| 25 | + font-size: 14px; |
| 26 | + border: 1px solid #838a90; |
| 27 | + background: white; |
| 28 | + color: #838a90; |
| 29 | + border-radius: 5px; |
| 30 | + cursor: pointer; |
| 31 | + transition: all 0.3s; |
| 32 | + } |
| 33 | + |
| 34 | + /* Change appearance when selected */ |
| 35 | + .radio-group input[type="radio"]:checked + .radio-btn { |
| 36 | + background: #838a90; |
| 37 | + color: white; |
| 38 | + } |
| 39 | + |
| 40 | + /* Hover effect */ |
| 41 | + .radio-btn:hover { |
| 42 | + background: #838a90; |
| 43 | + color: white; |
| 44 | + } |
| 45 | +</style> |
| 46 | + |
| 47 | +<%= form_with url: admin_dashboard_path, method: :get, html: { class: "form-horizontal" } do |f| %> |
| 48 | + <fieldset class="inputs"> |
| 49 | + <legend class="fieldset-title"> |
| 50 | + <span>Customize The Dashboard</span> |
| 51 | + </legend> |
| 52 | + <div class="form-grid"> |
| 53 | + <div class="form-group"> |
| 54 | + <%= f.label :from, "Filter From" %> |
| 55 | + <%= f.text_field :from, value: Admin::CustomizationHelper.parse_date(params[:from], Date.today.last_year), id: 'from_date' %> |
| 56 | + </div> |
| 57 | + <div class="form-group"> |
| 58 | + <%= f.label :to, "To" %> |
| 59 | + <%= f.text_field :to, value: Admin::CustomizationHelper.parse_date(params[:to], Date.today), id: 'to_date' %> |
| 60 | + </div> |
| 61 | + <div class="form-group"> |
| 62 | + <%= f.label :chart_type, "Chart Type" %> |
| 63 | + <div class="radio-group"> |
| 64 | + <%= f.radio_button :chart_type, "line", id: "chart_type_line", checked: !Admin::CustomizationHelper.is_bar_chart(params[:chart_type]) %> |
| 65 | + <%= f.label :chart_type_line, "Line", class: "radio-btn" %> |
| 66 | + |
| 67 | + <%= f.radio_button :chart_type, "bar", id: "chart_type_bar", checked: Admin::CustomizationHelper.is_bar_chart(params[:chart_type]) %> |
| 68 | + <%= f.label :chart_type_bar, "Bar", class: "radio-btn" %> |
| 69 | + </div> |
| 70 | + </div> |
| 71 | + <div class="form-group"> |
| 72 | + <%= f.label :group, "Group By" %> |
| 73 | + <div class="radio-group"> |
| 74 | + <%= f.radio_button :group, "day", id: "group_day", checked: Admin::CustomizationHelper.parse_group(params[:group]) == 'day' %> |
| 75 | + <%= f.label :group_day, "Day", class: "radio-btn" %> |
| 76 | + |
| 77 | + <%= f.radio_button :group, "week", id: "group_week", checked: Admin::CustomizationHelper.parse_group(params[:group]) == 'week' %> |
| 78 | + <%= f.label :group_week, "Week", class: "radio-btn" %> |
| 79 | + |
| 80 | + <%= f.radio_button :group, "month", id: "group_month", checked: Admin::CustomizationHelper.parse_group(params[:group]) == 'month' %> |
| 81 | + <%= f.label :group_month, "Month", class: "radio-btn" %> |
| 82 | + |
| 83 | + <%= f.radio_button :group, "year", id: "group_year", checked: Admin::CustomizationHelper.parse_group(params[:group]) == 'year' %> |
| 84 | + <%= f.label :group_year, "Year", class: "radio-btn" %> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | + <div class="form-group"> |
| 88 | + <%= f.submit "Apply" %> |
| 89 | + </div> |
| 90 | + </ol> |
| 91 | + </fieldset> |
| 92 | +<% end %> |
| 93 | + |
| 94 | +<script> |
| 95 | + $(document).ready(function() { |
| 96 | + let $from_date = $("#from_date") |
| 97 | + let $to_date = $("#to_date") |
| 98 | + |
| 99 | + $from_date.datepicker({ |
| 100 | + dateFormat: "yy-mm-dd", |
| 101 | + onSelect: function(selectedDate) { |
| 102 | + updateToDateMin() |
| 103 | + } |
| 104 | + }); |
| 105 | + $from_date.on("change", function() { |
| 106 | + updateToDateMin(); |
| 107 | + }); |
| 108 | + |
| 109 | + $to_date.datepicker({ |
| 110 | + dateFormat: "yy-mm-dd", |
| 111 | + onSelect: function(selectedDate) { |
| 112 | + updateFromDateMax(); |
| 113 | + } |
| 114 | + }); |
| 115 | + $from_date.on("change", function() { |
| 116 | + updateFromDateMax(); |
| 117 | + }); |
| 118 | + |
| 119 | + if ($from_date.val() !== "") { |
| 120 | + updateToDateMin(); |
| 121 | + } |
| 122 | + if ($to_date.val() !== "") { |
| 123 | + updateFromDateMax(); |
| 124 | + } |
| 125 | + |
| 126 | + function updateToDateMin() { |
| 127 | + let selectedDate = $from_date.val(); |
| 128 | + if (selectedDate === "") { |
| 129 | + $to_date.datepicker("option", "minDate", null); |
| 130 | + } else { |
| 131 | + $to_date.datepicker("option", "minDate", selectedDate); |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + function updateFromDateMax() { |
| 136 | + let selectedDate = $to_date.val(); |
| 137 | + if (selectedDate === "") { |
| 138 | + $from_date.datepicker("option", "maxDate", null); |
| 139 | + } else { |
| 140 | + $from_date.datepicker("option", "maxDate", selectedDate); |
| 141 | + } |
| 142 | + } |
| 143 | + }); |
| 144 | +</script> |
0 commit comments