dbviewer 0.3.6 → 0.3.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,13 +5,158 @@
5
5
  id="tableSearch" placeholder="Filter tables..." aria-label="Filter tables">
6
6
  </div>
7
7
 
8
+ <div class="p-2">
9
+ <div class="accordion accordion-flush" id="creationFilterAccordion">
10
+ <div class="accordion-item border-0">
11
+ <h2 class="accordion-header" id="creationFilterHeading">
12
+ <button class="accordion-button p-2 collapsed" type="button" data-bs-toggle="collapse"
13
+ data-bs-target="#creationFilterCollapse" aria-expanded="false"
14
+ aria-controls="creationFilterCollapse">
15
+ <i class="bi bi-calendar-range me-2"></i> Creation Filter
16
+ <% if @creation_filter_start.present? || @creation_filter_end.present? %>
17
+ <% if @table_name.present? && has_timestamp_column?(@table_name) %>
18
+ <span class="badge bg-success ms-2">Active</span>
19
+ <% else %>
20
+ <span class="badge bg-secondary ms-2">Set</span>
21
+ <% end %>
22
+ <% end %>
23
+ </button>
24
+ </h2>
25
+ <div id="creationFilterCollapse" class="accordion-collapse collapse" aria-labelledby="creationFilterHeading">
26
+ <div class="accordion-body p-2">
27
+ <form id="creationFilterForm" action="<%= request.path %>" method="get" class="mb-0">
28
+ <!-- Preserve existing query parameters -->
29
+ <input type="hidden" name="page" value="<%= @current_page %>">
30
+ <input type="hidden" name="per_page" value="<%= @per_page %>">
31
+ <input type="hidden" name="order_by" value="<%= @order_by %>">
32
+ <input type="hidden" name="order_direction" value="<%= @order_direction %>">
33
+
34
+ <!-- Datetime range fields -->
35
+ <div class="mb-2">
36
+ <label for="creationFilterStart" class="form-label mb-1 small">Start Date/Time</label>
37
+ <input type="datetime-local" id="creationFilterStart" name="creation_filter_start"
38
+ class="form-control form-control-sm" value="<%= @creation_filter_start %>">
39
+ </div>
40
+ <div class="mb-2">
41
+ <label for="creationFilterEnd" class="form-label mb-1 small">End Date/Time</label>
42
+ <input type="datetime-local" id="creationFilterEnd" name="creation_filter_end"
43
+ class="form-control form-control-sm" value="<%= @creation_filter_end %>">
44
+ </div>
45
+
46
+ <div class="d-flex justify-content-between">
47
+ <button type="submit" class="btn btn-primary btn-sm">Apply</button>
48
+ <% if @creation_filter_start.present? || @creation_filter_end.present? %>
49
+ <%
50
+ # Preserve other query params when clearing creation filter
51
+ clear_params = {
52
+ clear_creation_filter: true,
53
+ page: @current_page,
54
+ per_page: @per_page,
55
+ order_by: @order_by,
56
+ order_direction: @order_direction
57
+ }
58
+ %>
59
+ <a href="<%= request.path %>?<%= clear_params.to_query %>" class="btn btn-outline-secondary btn-sm">Clear</a>
60
+ <% end %>
61
+ </div>
62
+ <div class="mt-2 small">
63
+ <% if @table_name.present? && has_timestamp_column?(@table_name) && (@creation_filter_start.present? || @creation_filter_end.present?) %>
64
+ <div class="text-success">
65
+ <i class="bi bi-check-circle-fill"></i>
66
+ Filter active on this table.
67
+ <% if @current_page == 1 && @records && @records.rows && @records.rows.empty? %>
68
+ <div class="alert alert-warning p-1 mt-2 small">
69
+ <i class="bi bi-exclamation-triangle-fill"></i>
70
+ No records match the filter criteria.
71
+ </div>
72
+ <% end %>
73
+ </div>
74
+ <% elsif @table_name.present? && (@creation_filter_start.present? || @creation_filter_end.present?) %>
75
+ <div class="text-warning">
76
+ <i class="bi bi-exclamation-circle-fill"></i>
77
+ This table has no <code>created_at</code> column.
78
+ </div>
79
+ <% elsif !@table_name.present? && (@creation_filter_start.present? || @creation_filter_end.present?) %>
80
+ <div class="text-info">
81
+ <i class="bi bi-info-circle-fill"></i>
82
+ Filter will be applied on tables with <code>created_at</code> column.
83
+ </div>
84
+ <% else %>
85
+ <div class="text-muted">
86
+ <i class="bi bi-info-circle-fill"></i>
87
+ Filters apply to tables with a <code>created_at</code> column.
88
+ </div>
89
+ <% end %>
90
+ </div>
91
+ </form>
92
+ </div>
93
+ </div>
94
+ </div>
95
+ </div>
96
+ </div>
97
+
98
+ <!-- Add custom styling for datetime inputs -->
99
+ <style>
100
+ /* Better datetime input styling */
101
+ input[type="datetime-local"] {
102
+ padding-right: 0.5rem;
103
+ }
104
+
105
+ /* Dark mode support for datetime inputs */
106
+ [data-bs-theme="dark"] input[type="datetime-local"] {
107
+ background-color: rgba(255,255,255,0.1);
108
+ color: #fff;
109
+ border-color: rgba(255,255,255,0.15);
110
+ }
111
+
112
+ [data-bs-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator {
113
+ filter: invert(1);
114
+ }
115
+ </style>
116
+
117
+ <script>
118
+ // Set default values for datetime inputs when empty
119
+ document.addEventListener('DOMContentLoaded', function() {
120
+ const startInput = document.getElementById('creationFilterStart');
121
+ const endInput = document.getElementById('creationFilterEnd');
122
+
123
+ // When applying filter with empty start date, default to beginning of current month
124
+ if (startInput) {
125
+ startInput.addEventListener('click', function() {
126
+ if (!this.value) {
127
+ const now = new Date();
128
+ const firstDay = new Date(now.getFullYear(), now.getMonth(), 1);
129
+ const formattedDate = firstDay.toISOString().slice(0, 16); // Format: YYYY-MM-DDTHH:MM
130
+ this.value = formattedDate;
131
+ }
132
+ });
133
+ }
134
+
135
+ // When applying filter with empty end date, default to current datetime
136
+ if (endInput) {
137
+ endInput.addEventListener('click', function() {
138
+ if (!this.value) {
139
+ const now = new Date();
140
+ const formattedDate = now.toISOString().slice(0, 16); // Format: YYYY-MM-DDTHH:MM
141
+ this.value = formattedDate;
142
+ }
143
+ });
144
+ }
145
+ });
146
+ </script>
8
147
  </div>
9
148
 
10
149
  <div class="dbviewer-sidebar-content">
11
150
  <% if @tables.any? %>
12
151
  <div class="list-group list-group-flush" id="tablesList">
13
152
  <% @tables.each do |table| %>
14
- <%= link_to table_path(table[:name]), title: table[:name],
153
+ <%
154
+ # Build table URL with creation filter params if they exist
155
+ table_url_params = {}
156
+ table_url_params[:creation_filter_start] = @creation_filter_start if @creation_filter_start.present?
157
+ table_url_params[:creation_filter_end] = @creation_filter_end if @creation_filter_end.present?
158
+ %>
159
+ <%= link_to table_path(table[:name], table_url_params), title: table[:name],
15
160
  class: "list-group-item list-group-item-action d-flex align-items-center #{'active' if current_table?(table[:name])}",
16
161
  tabindex: "0",
17
162
  data: { table_name: table[:name] },
@@ -44,7 +44,13 @@
44
44
  <% @tables.each do |table| %>
45
45
  <tr>
46
46
  <td class="fw-medium">
47
- <%= link_to table[:name], table_path(table[:name]), class: "text-decoration-none" %>
47
+ <%
48
+ # Include creation filter params in table links
49
+ filter_params = {}
50
+ filter_params[:creation_filter_start] = session[:creation_filter_start] if session[:creation_filter_start].present?
51
+ filter_params[:creation_filter_end] = session[:creation_filter_end] if session[:creation_filter_end].present?
52
+ %>
53
+ <%= link_to table[:name], table_path(table[:name], filter_params), class: "text-decoration-none" %>
48
54
  </td>
49
55
  <td class="text-end">
50
56
  <span class="badge bg-secondary-subtle"><%= table[:record_count] %></span>