solid_litequeen 0.7.0 → 0.8.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9e57ed5cad271d83a2a34e75779abfdbd3c28cfde1c8ecb1f2d2aed1a46ce69
4
- data.tar.gz: 9dc4ed53f255a0d8f926985426ddd2eca248aa6de1c6f4398e6c0b86127c85f2
3
+ metadata.gz: ce04a632e602957b48d2bd64d2ad207621e8da3e20de6dc9fe7f3cb831b343d9
4
+ data.tar.gz: 0dd4d0ca3fc6a0c152a406568f8e0836734b42c456ed83f82824547bfe8661c0
5
5
  SHA512:
6
- metadata.gz: 919d4743f19a2ac203bcb68a192625c2bbf9854403332d6c42828075920308b5cf54fd6e1fc447b149011b84ccca28d265daecd94d65f7a461020fb6242733bd
7
- data.tar.gz: ab1380c616424ca7b3e6b246f828ff704991407a0e436409a8bace5ee5429b39486efe3d7e98a253ddf229b8f9fe73104ceafd5dd34423b9591143bf660a2e4d
6
+ metadata.gz: f7bd81c0a47b0ae3d06c1442a6a0459fa73a5b8eacc3814fdb6d97935f8c64194cdb9ea1a4044504293b33a729d49c1de348aed15f267ac158368f857240fece
7
+ data.tar.gz: a46276c2d8128c73f58db823b7e3b723a72a3a09fab87742a2c4686ffbddc51f014a181b484390fcac1a51273e9a57b316ae6a8bd1e8fabeba6d824b409874d3
@@ -32,6 +32,26 @@ module SolidLitequeen
32
32
  @database_id = params.expect(:database_id)
33
33
  @table_name = params.expect(:table)
34
34
 
35
+ # Create a unique key for this table's sort preferences
36
+ sort_key = "#{@database_id}_#{@table_name}_sort"
37
+
38
+ # Update session if new sort params are provided
39
+ if params[:sort_column].present?
40
+ session[sort_key] = {
41
+ sort_column: params[:sort_column].to_s,
42
+ sort_direction: (params[:sort_direction]&.upcase == "DESC" ? "DESC" : "ASC")
43
+ }.stringify_keys # Ensure all keys are strings in session
44
+ end
45
+
46
+ # Get sort preferences from session or set defaults with string keys
47
+ sort_prefs = session[sort_key]&.with_indifferent_access || {
48
+ "sort_column" => nil,
49
+ "sort_direction" => "ASC"
50
+ }
51
+
52
+ @sort_column = sort_prefs["sort_column"]
53
+ @sort_direction = sort_prefs["sort_direction"]
54
+
35
55
  @database_location = Base64.urlsafe_decode64(@database_id)
36
56
 
37
57
  DynamicDatabase.establish_connection(
@@ -39,7 +59,19 @@ module SolidLitequeen
39
59
  database: @database_location
40
60
  )
41
61
 
42
- @data = DynamicDatabase.connection.select_all("SELECT * FROM #{@table_name} LIMIT 50")
62
+ # Verify the sort column exists in the table to prevent SQL injection
63
+ valid_columns = DynamicDatabase.connection.columns(@table_name).map(&:name)
64
+
65
+ order_clause = if @sort_column.present? && valid_columns.include?(@sort_column)
66
+ "#{DynamicDatabase.connection.quote_column_name(@sort_column)} #{@sort_direction}"
67
+ end
68
+
69
+ sql = [ "SELECT * FROM #{@table_name}" ]
70
+ sql << "ORDER BY #{order_clause}" if order_clause
71
+ sql << "LIMIT 50"
72
+
73
+
74
+ @data = DynamicDatabase.connection.select_all(sql.join(" "))
43
75
  @row_count = row_count = DynamicDatabase.connection.select_value("SELECT COUNT(*) FROM #{@table_name}").to_i
44
76
  end
45
77
 
@@ -22,7 +22,7 @@
22
22
  <%= yield :head %>
23
23
  </head>
24
24
  <body class="">
25
- <header>
25
+ <header class="container mx-auto mt-4 mb-8">
26
26
  <%= render "solid_litequeen/database-selector" %>
27
27
  </header>
28
28
  <%= yield %>
@@ -21,7 +21,19 @@
21
21
  <thead class="">
22
22
  <tr class="bg-gray-100 border-b border-gray-200">
23
23
  <% @data.columns.each do |column| %>
24
- <th class="px-6 py-3 text-left text-sm font-medium text-gray-700 whitespace-nowrap"><%= column %></th>
24
+ <th class="px-6 py-3 text-left text-sm font-medium text-gray-700 whitespace-nowrap">
25
+ <%#= column %>
26
+
27
+ <%= link_to column,
28
+ database_table_rows_path(
29
+ database_id: @database_id,
30
+ table: @table_name,
31
+ sort_column: column,
32
+ sort_direction: (@sort_column == column && @sort_direction == 'ASC') ? 'DESC' : 'ASC'
33
+ ) %>
34
+ <%= '▼' if @sort_column == column && @sort_direction == 'DESC' %>
35
+ <%= '▲' if @sort_column == column && @sort_direction == 'ASC' %>
36
+ </th>
25
37
  <% end %>
26
38
  </tr>
27
39
  </thead>
@@ -1,3 +1,3 @@
1
1
  module SolidLitequeen
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_litequeen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vik Borges
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-03-08 00:00:00.000000000 Z
11
+ date: 2025-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails