db-gui 0.2.1 → 0.2.3

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: 38eb8b2669f281d3dddb78945f259d5fe8dea12eb31b51f5761ce4ced71381e9
4
- data.tar.gz: a0cb8959b31975f176302f20404011e3a8115d5e597461de0f90fe57a5305cf3
3
+ metadata.gz: 9e8f8e99fbe6234688995ab9ba3c043520735be325f436d6a77b6645c000f949
4
+ data.tar.gz: ff6bbf33071bb6820260f6d583c448d218c448b9b304f242c2a448f197262c8c
5
5
  SHA512:
6
- metadata.gz: b664e4ed31d076e644451b58bd809dc9e9f58b8526d96d052d41eef238c4f293413f886eb0b4fe7f0d9fe19b66eba563d7d98f936fad43d0032b0e4f590ed9ec
7
- data.tar.gz: 43696e4a6cb8ecd26363a5dc9f33588b1b88895aa5c16a63a88caa6fce393c9d2907f05e52b9ce66ecc3e35d6de8549e85e29f34af1191b81a1fda5b03e8cf5e
6
+ metadata.gz: cb7ca28a2bc3c176c364e2708b8c2793d2b1cb0bb13e117511b83d4c35a021b76a47621a43cd6e41dacc3995c8d1e2e326946205dcd879a89e882560a01923ef
7
+ data.tar.gz: 9266bf6fe826ca5045f0c0819c8a9a673d5cb654465f5fa0366c3103e27f3fd7d896d3ee47a2f533ff734bc1a41c93b5d0e728b7ed4ffb9e7aba94e062fbdb10
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.3
4
+
5
+ - Edit -> Copy Table (with query & headers) menu item to copy table data with query (e.g. SQL) & headers as a formatted string to the clipboard
6
+
7
+ ## 0.2.2
8
+
9
+ - Edit -> Copy Table (with headers) menu item to copy table data with headers as a formatted string to the clipboard
10
+ - Edit -> Copy Selected Row (with headers) menu item to copy selected row data with headers as a formatted string to the clipboard
11
+
3
12
  ## 0.2.1
4
13
 
5
14
  - Fix bug in 0.2.0 with crashing whenever running a DB query for the second time.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # DB GUI (Database Graphical User Interface) 0.2.1
1
+ # DB GUI (Database Graphical User Interface) 0.2.3
2
2
  ## [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=40 /> Glimmer DSL for LibUI Application](https://github.com/AndyObtiva/glimmer-dsl-libui)
3
3
  [![Gem Version](https://badge.fury.io/rb/db-gui.svg)](http://badge.fury.io/rb/db-gui)
4
4
 
@@ -12,7 +12,7 @@ It currently supports PostgreSQL as a start, with the potential of supporting ma
12
12
 
13
13
  Run:
14
14
  ```
15
- gem install db-gui -v0.2.1
15
+ gem install db-gui -v0.2.3
16
16
  ```
17
17
 
18
18
  ## Usage
@@ -32,10 +32,22 @@ Note that it stores the last connection details under `~/.db_gui`, and will auto
32
32
 
33
33
  Click on this menu item to copy the table data as a formatted string to the clipboard.
34
34
 
35
+ **Edit -> Copy Table (with headers)**
36
+
37
+ Click on this menu item to copy the table data with headers as a formatted string to the clipboard.
38
+
39
+ **Edit -> Copy Table (with query & headers)**
40
+
41
+ Click on this menu item to copy the table data with query (e.g. SQL) & headers as a formatted string to the clipboard.
42
+
35
43
  **Edit -> Copy Selected Row**
36
44
 
37
45
  Click on this menu item to copy the selected row data as a formatted string to the clipboard.
38
46
 
47
+ **Edit -> Copy Selected Row (with headers)**
48
+
49
+ Click on this menu item to copy the selected row data with headers as a formatted string to the clipboard.
50
+
39
51
  ## Change Log
40
52
 
41
53
  [CHANGELOG.md](/CHANGELOG.md)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.3
@@ -103,23 +103,45 @@ class DbGui
103
103
  Clipboard.copy(formatted_table_string)
104
104
  end
105
105
 
106
+ def copy_table_with_headers
107
+ return if db_command_result_rows.empty?
108
+ Clipboard.copy(formatted_table_string(include_headers: true))
109
+ end
110
+
111
+ def copy_table_with_query_and_headers
112
+ return if db_command_result_rows.empty?
113
+ Clipboard.copy(formatted_table_string(include_query: true, include_headers: true))
114
+ end
115
+
106
116
  def copy_selected_row
107
117
  return if db_command_result_rows.empty?
108
118
  Clipboard.copy(formatted_selected_row_string)
109
119
  end
110
120
 
111
- def formatted_table_string
112
- column_max_lengths = db_command_result_column_max_lengths
113
- db_command_result_rows.map do |row|
121
+ def copy_selected_row_with_headers
122
+ return if db_command_result_rows.empty?
123
+ Clipboard.copy(formatted_selected_row_string(include_headers: true))
124
+ end
125
+
126
+ def formatted_table_string(rows = nil, include_query: false, include_headers: false)
127
+ rows ||= db_command_result_rows
128
+ rows = rows.dup
129
+ rows.prepend(db_command_result_headers) if include_headers
130
+ column_max_lengths = row_column_max_lengths(rows) # TODO calculate those after prepending headers
131
+ formatted_string = rows.map do |row|
114
132
  row.each_with_index.map do |data, column_index|
115
133
  data.ljust(column_max_lengths[column_index])
116
134
  end.join(" | ")
117
135
  end.join(NEW_LINE)
136
+ formatted_string.prepend("#{db_command}\n\n") if include_query
137
+ formatted_string
118
138
  end
119
139
 
120
- def formatted_selected_row_string
140
+ def formatted_selected_row_string(include_headers: false)
121
141
  selected_row = db_command_result_rows[db_command_result_selection]
122
142
  selected_row.join(' | ')
143
+ rows = [selected_row]
144
+ formatted_table_string(rows, include_headers:)
123
145
  end
124
146
 
125
147
  private
@@ -203,10 +225,11 @@ class DbGui
203
225
  [count, headers, rows]
204
226
  end
205
227
 
206
- def db_command_result_column_max_lengths
207
- column_count = db_command_result_rows.first.size
228
+ def row_column_max_lengths(rows = nil)
229
+ rows ||= db_command_result_rows
230
+ column_count = rows.first.size
208
231
  column_max_lengths = []
209
- db_command_result_rows.each do |row|
232
+ rows.each do |row|
210
233
  row.each_with_index do |value, column_index|
211
234
  column_max_lengths[column_index] ||= 0
212
235
  column_max_lengths[column_index] = [column_max_lengths[column_index], value.size].max
@@ -1,5 +1,6 @@
1
1
  require 'db_gui/model/db'
2
2
 
3
+ require 'db_gui/view/db_gui_menu_bar'
3
4
  require 'db_gui/view/db_config_form'
4
5
  require 'db_gui/view/db_command_form'
5
6
  require 'db_gui/view/db_command_result_table'
@@ -13,7 +14,7 @@ class DbGui
13
14
 
14
15
  before_body do
15
16
  @db = Model::Db.new
16
- menu_bar
17
+ db_gui_menu_bar(db:)
17
18
  end
18
19
 
19
20
  body {
@@ -34,72 +35,6 @@ class DbGui
34
35
  }
35
36
  }
36
37
  }
37
-
38
- def menu_bar
39
- menu('Edit') {
40
- menu_item('Copy Table') {
41
- enabled <= [db, :db_command_result_rows, computed_by: :db_command_result, on_read: -> (data) { !data.empty? }]
42
-
43
- on_clicked do
44
- db.copy_table
45
- end
46
- }
47
-
48
- menu_item('Copy Selected Row') {
49
- enabled <= [db, :db_command_result_rows, computed_by: :db_command_result, on_read: -> (data) { !data.empty? }]
50
-
51
- on_clicked do
52
- db.copy_selected_row
53
- end
54
- }
55
-
56
- quit_menu_item if OS.mac?
57
- }
58
- menu('Help') {
59
- if OS.mac?
60
- about_menu_item {
61
- on_clicked do
62
- display_about_dialog
63
- end
64
- }
65
- end
66
-
67
- menu_item('About') {
68
- on_clicked do
69
- display_about_dialog
70
- end
71
- }
72
- }
73
- end
74
-
75
- def display_about_dialog
76
- message = "DB GUI #{VERSION}\n\n#{LICENSE}"
77
- msg_box('About', message)
78
- end
79
-
80
- # def display_preferences_dialog
81
- # window {
82
- # title 'Preferences'
83
- # content_size 200, 100
84
- #
85
- # margined true
86
- #
87
- # vertical_box {
88
- # padded true
89
- #
90
- # label('Greeting:') {
91
- # stretchy false
92
- # }
93
- #
94
- # radio_buttons {
95
- # stretchy false
96
- #
97
- # items Model::Greeting::GREETINGS
98
- # selected <=> [@greeting, :text_index]
99
- # }
100
- # }
101
- # }.show
102
- # end
103
38
  end
104
39
  end
105
40
  end
@@ -0,0 +1,83 @@
1
+ class DbGui
2
+ module View
3
+ class DbGuiMenuBar
4
+ include Glimmer::LibUI::CustomControl
5
+
6
+ option :db
7
+
8
+ body {
9
+ menu('Query') {
10
+ menu_item('Run') {
11
+ on_clicked do
12
+ db.run_db_command
13
+ end
14
+ }
15
+ }
16
+
17
+ menu('Edit') {
18
+ menu_item('Copy Table') {
19
+ enabled <= [db, :db_command_result_rows, computed_by: :db_command_result, on_read: -> (data) { !data.empty? }]
20
+
21
+ on_clicked do
22
+ db.copy_table
23
+ end
24
+ }
25
+
26
+ menu_item('Copy Table (with headers)') {
27
+ enabled <= [db, :db_command_result_rows, computed_by: :db_command_result, on_read: -> (data) { !data.empty? }]
28
+
29
+ on_clicked do
30
+ db.copy_table_with_headers
31
+ end
32
+ }
33
+
34
+ menu_item('Copy Table (with query & headers)') {
35
+ enabled <= [db, :db_command_result_rows, computed_by: :db_command_result, on_read: -> (data) { !data.empty? }]
36
+
37
+ on_clicked do
38
+ db.copy_table_with_query_and_headers
39
+ end
40
+ }
41
+
42
+ menu_item('Copy Selected Row') {
43
+ enabled <= [db, :db_command_result_rows, computed_by: :db_command_result, on_read: -> (data) { !data.empty? }]
44
+
45
+ on_clicked do
46
+ db.copy_selected_row
47
+ end
48
+ }
49
+
50
+ menu_item('Copy Selected Row (with headers)') {
51
+ enabled <= [db, :db_command_result_rows, computed_by: :db_command_result, on_read: -> (data) { !data.empty? }]
52
+
53
+ on_clicked do
54
+ db.copy_selected_row_with_headers
55
+ end
56
+ }
57
+
58
+ quit_menu_item if OS.mac?
59
+ }
60
+ menu('Help') {
61
+ if OS.mac?
62
+ about_menu_item {
63
+ on_clicked do
64
+ display_about_dialog
65
+ end
66
+ }
67
+ end
68
+
69
+ menu_item('About') {
70
+ on_clicked do
71
+ display_about_dialog
72
+ end
73
+ }
74
+ }
75
+ }
76
+ end
77
+
78
+ def display_about_dialog
79
+ message = "DB GUI #{VERSION}\n\n#{LICENSE}"
80
+ msg_box('About', message)
81
+ end
82
+ end
83
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db-gui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
@@ -104,6 +104,7 @@ files:
104
104
  - app/db_gui/view/db_command_result_table.rb
105
105
  - app/db_gui/view/db_config_form.rb
106
106
  - app/db_gui/view/db_gui_application.rb
107
+ - app/db_gui/view/db_gui_menu_bar.rb
107
108
  - bin/db-gui
108
109
  - bin/db-ui
109
110
  - bin/dbgui