Skip to content

Commit 5af8d98

Browse files
Arpan-KreetiArp-G
authored andcommitted
fix config bug, and minor ui improvements
1 parent dd810c6 commit 5af8d98

File tree

8 files changed

+66
-133
lines changed

8 files changed

+66
-133
lines changed

apps/csv2sql/lib/csv2sql.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ defmodule Csv2sql do
208208
]
209209
]
210210

211+
IO.inspect(current_config)
212+
211213
Application.put_all_env(current_config)
212214
end
213215

apps/dashboard/assets/css/app.scss

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
@import "./phoenix.css";
33
@import "../node_modules/nprogress/nprogress.css";
44

5-
65
spinner.loading {
76
display: none;
87
text-align: center;
@@ -35,6 +34,11 @@ spinner.loading {
3534
}
3635
}
3736

37+
.required-config{
38+
color: red;
39+
font-size: 1em;
40+
}
41+
3842
#spinnerText{
3943
font-size: 2.2em;
4044
font-weight: bolder;
@@ -60,6 +64,7 @@ spinner.loading {
6064
background-image: linear-gradient(red, yellow);
6165
border: 1px solid rgb(168, 159, 159);
6266
box-shadow: 0 2px 5px rgba(201,209,230,.5), 0 7px 20px rgba(201,209,230,.75);
67+
cursor: pointer;
6368
// center item
6469
left: 0;
6570
right: 0;
@@ -68,6 +73,8 @@ spinner.loading {
6873
}
6974

7075
.current-stats{
76+
display: flex;
77+
flex-wrap: wrap;
7178
border-radius: 10px;
7279
width: 90%;
7380
min-height: 150px;
@@ -76,10 +83,11 @@ spinner.loading {
7683
margin-bottom: 50px;
7784
margin-top: 20px;
7885
padding: 10px;
86+
font-size: 2em;
7987
}
8088

81-
.current-stats {
82-
font-size: 2em;
89+
.current-stats > div {
90+
width: 50%;
8391
}
8492

8593
.finish-check {

apps/dashboard/lib/dashboard_web/helpers/config_helper.ex

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,9 @@ defmodule DashboardWeb.Helper.ConfigHelper do
2121
|> Enum.map(fn {:entry, key, _, _, value} ->
2222
{"--" <> to_string(key), to_string(value)}
2323
end)
24-
|> Enum.reject(fn {_, value} -> value == "" || value == nil end)
2524
|> Enum.reduce([], fn {key, value}, acc ->
26-
#IO.inspect([key, value])
2725
acc ++ [key, value]
2826
end)
29-
30-
[
31-
"--source-csv-directory",
32-
"/home/arpan/Desktop/test/csvs",
33-
"--db-connection-string",
34-
"root:mysql@localhost/csvsql_test"
35-
]
3627
end
3728

3829
defp add_db_connection_config(config) do
@@ -61,10 +52,10 @@ defmodule DashboardWeb.Helper.ConfigHelper do
6152
"source-csv-directory": "",
6253
"imported-csv-directory": "",
6354
"validated-csv-directory": "",
64-
"skip-make-schema": "false",
65-
"skip-insert-schema": "false",
66-
"skip-insert-data": "false",
67-
"skip-validate-import": "false",
55+
"skip-make-schema": nil,
56+
"skip-insert-schema": nil,
57+
"skip-insert-data": nil,
58+
"skip-validate-import": nil,
6859
csv2sql_username: "",
6960
csv2sql_password: "",
7061
csv2sql_host: "localhost",

apps/dashboard/lib/dashboard_web/live/config_live.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defmodule DashboardWeb.ConfigLive do
2121
) do
2222
value =
2323
case param["value"] do
24-
nil -> "false"
24+
nil -> nil
2525
"on" -> "true"
2626
value -> if String.trim(value) == "", do: nil, else: value
2727
end

apps/dashboard/lib/dashboard_web/live/config_live.html.leex

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
aria-describedby="basic-addon1"
4545
phx-blur="update_config"
4646
phx-value-config="schema-file-path"
47-
value=<%= @config[:"schema-file-path"] %>
47+
value="<%= @config[:"schema-file-path"] %>"
4848
/>
4949
</div>
5050

@@ -55,7 +55,7 @@
5555
<span aria-label="The source directory where the csvs are located, Example: /home/user/Desktop/csvs"
5656
data-microtip-size="large" class="popup" data-microtip-position="top" role="tooltip">
5757
<i class="fa fa-info-circle" aria-hidden="true" style="font-size: 1.5em; margin: 5px" /></i>
58-
<span style="font-size: 1.3em; margin: 5px"> Source CSV Directory </span>
58+
<span style="font-size: 1.3em; margin: 5px"> <span class="required-config"> * </span> Source CSV Directory </span>
5959
</span>
6060
</h5>
6161
</div>
@@ -65,7 +65,7 @@
6565
class="form-control"
6666
phx-blur="update_config"
6767
phx-value-config="source-csv-directory"
68-
value=<%= @config[:"source-csv-directory"] %>
68+
value="<%= @config[:"source-csv-directory"] %>"
6969
/>
7070
</div>
7171

@@ -86,7 +86,7 @@
8686
class="form-control"
8787
phx-blur="update_config"
8888
phx-value-config="imported-csv-directory"
89-
value=<%= @config[:"imported-csv-directory"] %>
89+
value="<%= @config[:"imported-csv-directory"] %>"
9090
/>
9191
</div>
9292

@@ -107,7 +107,7 @@
107107
class="form-control"
108108
phx-blur="update_config"
109109
phx-value-config="validated-csv-directory"
110-
value=<%= @config[:"validated-csv-directory"] %>
110+
value="<%= @config[:"validated-csv-directory"] %>"
111111
/>
112112
</div>
113113

@@ -194,7 +194,7 @@
194194
<span aria-label="mysql username, required field if database access is required" data-microtip-size="large" class="popup"
195195
data-microtip-position="top" role="tooltip">
196196
<i class="fa fa-info-circle" aria-hidden="true" style="font-size: 1.5em; margin: 5px" /></i>
197-
<span style="font-size: 1.3em; margin: 5px"> Database Username </span>
197+
<span style="font-size: 1.3em; margin: 5px"> <span class="required-config"> * </span> Database Username </span>
198198
</span>
199199
</h5>
200200
</div>
@@ -204,7 +204,7 @@
204204
class="form-control"
205205
phx-blur="update_config"
206206
phx-value-config="csv2sql_username"
207-
value=<%= @config[:csv2sql_username] %>
207+
value="<%= @config[:csv2sql_username] %>"
208208
/>
209209
</div>
210210

@@ -214,7 +214,7 @@
214214
<span aria-label="mysql password, required field if database access is required" data-microtip-size="large" class="popup"
215215
data-microtip-position="top" role="tooltip">
216216
<i class="fa fa-info-circle" aria-hidden="true" style="font-size: 1.5em; margin: 5px" /></i>
217-
<span style="font-size: 1.3em; margin: 5px"> Database Password </span>
217+
<span style="font-size: 1.3em; margin: 5px"> <span class="required-config"> * </span> Database Password </span>
218218
</span>
219219
</h5>
220220
</div>
@@ -223,7 +223,7 @@
223223
class="form-control"
224224
phx-blur="update_config"
225225
phx-value-config="csv2sql_password"
226-
value=<%= @config[:csv2sql_password] %>
226+
value="<%= @config[:csv2sql_password] %>"
227227
/>
228228
</div>
229229

@@ -242,7 +242,7 @@
242242
placeholder="Type here..."
243243
phx-blur="update_config"
244244
phx-value-config="csv2sql_host"
245-
value=<%= @config[:csv2sql_host] %>
245+
value="<%= @config[:csv2sql_host] %>"
246246
/>
247247
</div>
248248

@@ -253,7 +253,7 @@
253253
aria-label="This is the name of the database which will be created (if not present already), required field if database access is required"
254254
data-microtip-size="large" class="popup" data-microtip-position="top" role="tooltip">
255255
<i class="fa fa-info-circle" aria-hidden="true" style="font-size: 1.5em; margin: 5px" /></i>
256-
<span style="font-size: 1.3em; margin: 5px"> Database Name </span>
256+
<span style="font-size: 1.3em; margin: 5px"> <span class="required-config"> * </span> Database Name </span>
257257
</span>
258258
</h5>
259259
</div>
@@ -263,7 +263,7 @@
263263
class="form-control"
264264
phx-blur="update_config"
265265
phx-value-config="csv2sql_database_name"
266-
value=<%= @config[:csv2sql_database_name] %>
266+
value="<%= @config[:csv2sql_database_name] %>"
267267
/>
268268
</div>
269269

@@ -283,7 +283,7 @@
283283
class="form-control"
284284
phx-blur="update_config"
285285
phx-value-config="connection-socket"
286-
value=<%= @config[:"connection-socket"] %>
286+
value="<%= @config[:"connection-socket"] %>"
287287
/>
288288
</div>
289289

@@ -304,7 +304,7 @@
304304
max="500"
305305
phx-blur="update_config"
306306
phx-value-config="varchar-limit"
307-
value=<%= @config[:"varchar-limit"] %>
307+
value="<%= @config[:"varchar-limit"] %>"
308308
/>
309309
</div>
310310

@@ -327,7 +327,7 @@
327327
max="500"
328328
phx-blur="update_config"
329329
phx-value-config="schema-infer-chunk-size"
330-
value=<%= @config[:"schema-infer-chunk-size"] %>
330+
value="<%= @config[:"schema-infer-chunk-size"] %>"
331331
/>
332332
</div>
333333

@@ -348,7 +348,7 @@
348348
max="50"
349349
phx-blur="update_config"
350350
phx-value-config="worker-count"
351-
value=<%= @config[:"worker-count"] %>
351+
value="<%= @config[:"worker-count"] %>"
352352
/>
353353
</div>
354354

@@ -369,7 +369,7 @@
369369
class="form-control"
370370
phx-blur="update_config"
371371
phx-value-config="db-worker-count"
372-
value=<%= @config[:"db-worker-count"] %>
372+
value="<%= @config[:"db-worker-count"] %>"
373373
/>
374374
</div>
375375

@@ -391,7 +391,7 @@
391391
max="500"
392392
phx-blur="update_config"
393393
phx-value-config="insertion-chunk-size"
394-
value=<%= @config[:"insertion-chunk-size"] %>
394+
value="<%= @config[:"insertion-chunk-size"] %>"
395395
/>
396396
</div>
397397

@@ -412,7 +412,7 @@
412412
max="500"
413413
phx-blur="update_config"
414414
phx-value-config="job-count-limit"
415-
value=<%= @config[:"job-count-limit"] %>
415+
value="<%= @config[:"job-count-limit"] %>"
416416
/>
417417
</div>
418418

@@ -433,7 +433,7 @@
433433
min="10000"
434434
phx-blur="update_config"
435435
phx-value-config="timeout"
436-
value=<%= @config[:timeout] %>
436+
value="<%= @config[:timeout] %>"
437437
/>
438438
</div>
439439

@@ -455,7 +455,7 @@
455455
min="10000"
456456
phx-blur="update_config"
457457
phx-value-config="connect-timeout"
458-
value=<%= @config[:"connect-timeout"] %>
458+
value="<%= @config[:"connect-timeout"] %>"
459459
/>
460460
</div>
461461

@@ -480,7 +480,7 @@
480480
min="1"
481481
phx-blur="update_config"
482482
phx-value-config="pool-size"
483-
value=<%= @config[:"pool-size"] %>
483+
value="<%= @config[:"pool-size"] %>"
484484
/>
485485
</div>
486486

@@ -504,7 +504,7 @@
504504
min="1000"
505505
phx-blur="update_config"
506506
phx-value-config="queue-target"
507-
value=<%= @config[:"queue-target"] %>
507+
value="<%= @config[:"queue-target"] %>"
508508
/>
509509
</div>
510510

@@ -528,7 +528,7 @@
528528
min="10"
529529
phx-blur="update_config"
530530
phx-value-config="queue-interval"
531-
value=<%= @config[:"queue-interval"] %>
531+
value="<%= @config[:"queue-interval"] %>"
532532
/>
533533
</div>
534534
</div>

apps/dashboard/lib/dashboard_web/live/main_live.html.leex

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
<div class="main-container">
22
<div class="current-stats">
3-
<strong> Stage: </strong> <%= @stage %> <br>
3+
<div><strong> Stage: </strong> <%= @stage %></div>
44
<%= if @stage != :waiting do %>
5-
<strong> Total Files: </strong><%= Enum.count(@file_list) %> <br>
6-
<strong> Files Imported: </strong><%= Enum.count(@file_list, fn %{status: status} -> status == :finish end) %> <br>
7-
<strong> Total Completion: </strong> <%= calc_total_progress(@file_list) %>% <br>
8-
<strong> Total Workers: </strong> <%= @stats.worker_count %> <br>
9-
<strong> Total Database Workers: </strong> <%= @stats.db_worker_count %> <br>
10-
<strong> Active Workers: </strong> <%= @stats.active_workers %> <br>
11-
<strong> CPU Usage: </strong> <%= @stats.cpu_usage %>% <br>
12-
<strong> Memory Usage of Application: </strong> <%= @stats.memory_usage %><br>
13-
<strong> Time Elapsed: </strong> <%= @stats.time_spend %> seconds
5+
<div><strong> Total Files: </strong><%= Enum.count(@file_list) %> </div>
6+
<div><strong> Files Imported: </strong><%= Enum.count(@file_list, fn %{status: status} -> status == :finish end) %> </div>
7+
<div><strong> Total Completion: </strong> <%= calc_total_progress(@file_list) %>% </div>
8+
<div><strong> Total Workers: </strong> <%= @stats.worker_count %> </div>
9+
<div><strong> Total Database Workers: </strong> <%= @stats.db_worker_count %> </div>
10+
<div><strong> Active Workers: </strong> <%= @stats.active_workers %> </div>
11+
<div><strong> CPU Usage: </strong> <%= @stats.cpu_usage %>% </div>
12+
<div><strong> Memory Usage of Application: </strong> <%= @stats.memory_usage %></div>
13+
<div><strong> Time Elapsed: </strong> <%= @stats.time_spend %> seconds </div>
14+
<%= if(Application.get_env(:csv2sql, Csv2sql.Worker)[:set_make_schema]) do %>
15+
<% schema_file = Application.get_env(:csv2sql, Csv2sql.SchemaMaker)[:schema_file_path] %>
16+
<div><strong> Schema File: </strong> <a href="file:///<%= schema_file %>" target="_blank"><%= schema_file %></a></div>
17+
<% end %>
1418
<% end %>
1519
</div>
1620

@@ -72,3 +76,9 @@
7276
</div>
7377
</div>
7478
</footer>
79+
80+
<script>
81+
window.onbeforeunload = function() {
82+
return "CSV2SQL is working, are you sure you want to leave? You can't come back to this page if you leave !";
83+
}
84+
</script>

apps/dashboard/lib/dashboard_web/live/page_live.ex

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,4 @@ defmodule DashboardWeb.PageLive do
55
def mount(_params, _session, socket) do
66
{:ok, assign(socket, query: "", results: %{})}
77
end
8-
9-
@impl true
10-
def handle_event("suggest", %{"q" => query}, socket) do
11-
{:noreply, assign(socket, results: search(query), query: query)}
12-
end
13-
14-
@impl true
15-
def handle_event("search", %{"q" => query}, socket) do
16-
case search(query) do
17-
%{^query => vsn} ->
18-
{:noreply, redirect(socket, external: "https://hexdocs.pm/#{query}/#{vsn}")}
19-
20-
_ ->
21-
{:noreply,
22-
socket
23-
|> put_flash(:error, "No dependencies found matching \"#{query}\"")
24-
|> assign(results: %{}, query: query)}
25-
end
26-
end
27-
28-
defp search(query) do
29-
if not DashboardWeb.Endpoint.config(:code_reloader) do
30-
raise "action disabled when not in development"
31-
end
32-
33-
for {app, desc, vsn} <- Application.started_applications(),
34-
app = to_string(app),
35-
String.starts_with?(app, query) and not List.starts_with?(desc, ~c"ERTS"),
36-
into: %{},
37-
do: {app, vsn}
38-
end
398
end

0 commit comments

Comments
 (0)