Skip to content

Commit 5bfd9e4

Browse files
Arpan-KreetiArp-G
authored andcommitted
improve ui and handle empty csv files
1 parent c1e4425 commit 5bfd9e4

File tree

8 files changed

+86
-24
lines changed

8 files changed

+86
-24
lines changed

apps/csv2sql/lib/csv2sql.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defmodule Csv2sql do
66
# escript was build and cannot be changed later
77
update_config(args)
88

9+
# Start supervision tree
910
{:ok, sup_pid} = Csv2sql.Application.start(:no_args, :no_args)
1011

1112
# Wait for finish and stop supervion tree

apps/csv2sql/lib/csv2sql/import_validator.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ defmodule Csv2sql.ImportValidator do
2828
Application.get_env(:csv2sql, Csv2sql.MainServer)[:validated_csv_directory]
2929

3030
imported_csv_directory =
31-
Application.get_env(:csv2sql, Csv2sql.MainServer)[:imported_csv_directory]
31+
if Application.get_env(:csv2sql, Csv2sql.Worker)[:set_insert_data],
32+
do: Application.get_env(:csv2sql, Csv2sql.MainServer)[:imported_csv_directory],
33+
else: Application.get_env(:csv2sql, Csv2sql.MainServer)[:source_csv_directory]
3234

3335
File.rename!(
3436
"#{imported_csv_directory}/#{file}.csv",

apps/csv2sql/lib/csv2sql/main_server.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ defmodule Csv2sql.MainServer do
5353

5454
wait_for_pending_jobs()
5555

56-
:timer.sleep(500)
56+
:timer.sleep(1000)
5757

5858
start_validation_message()
5959

apps/csv2sql/lib/csv2sql/worker.ex

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ defmodule Csv2sql.Worker do
2626
]},
2727
_
2828
) do
29-
file = Csv2sql.Observer.next_file()
29+
{file, row_count} = Csv2sql.Observer.next_file()
3030

3131
if file do
3232
if(set_make_schema) do
@@ -41,12 +41,14 @@ defmodule Csv2sql.Worker do
4141
end
4242
end
4343

44-
if(set_insert_data) do
44+
if(set_insert_data && row_count != 0) do
4545
Observer.update_file_status(file, :insert_data)
4646

4747
insert_data(file)
4848
end
4949

50+
if set_insert_data && row_count == 0, do: handle_empty_file(file)
51+
5052
send(self(), {:start_new_work, work_config})
5153

5254
{:noreply, nil}
@@ -70,4 +72,16 @@ defmodule Csv2sql.Worker do
7072
Csv2sql.DataTransfer.process_file(file)
7173
file
7274
end
75+
76+
# Handle csvs having 0 rows, change status to finish and move to imported directory
77+
defp handle_empty_file(file) do
78+
Observer.update_file_status(file, :finish)
79+
80+
File.rename!(
81+
file,
82+
"#{Application.get_env(:csv2sql, Csv2sql.MainServer)[:imported_csv_directory]}/#{
83+
Path.basename(file)
84+
}"
85+
)
86+
end
7387
end

apps/dashboard/assets/css/app.scss

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,39 @@ spinner.loading {
119119
font-weight: bold;
120120
}
121121

122+
.stage_pending,
123+
.stage_infer_schema,
124+
.stage_loading_schema,
125+
.stage_insert_data,
126+
.stage_finished {
127+
border-radius: 10px;
128+
border: 1px solid black;
129+
padding: 5px;
130+
font-weight: bold;
131+
}
132+
133+
.stage_pending {
134+
background-color: #FFA07A;
135+
}
136+
137+
.stage_infer_schema {
138+
background-color: #8A2BE2;
139+
color: white;
140+
}
141+
142+
.stage_loading_schema {
143+
background-color: #BDB76B;
144+
}
145+
146+
.stage_insert_data {
147+
background-color: #0000FF;
148+
color: white;
149+
}
150+
151+
.stage_finished {
152+
background-color: #3CB371;
153+
}
154+
122155
// .file-name {
123156

124157
// }
@@ -135,9 +168,22 @@ spinner.loading {
135168

136169
// }
137170

138-
// .status {
171+
.status {
172+
margin-top: 10px;
173+
margin-bottom: 10px;
174+
}
139175

140-
// }
176+
.overall-status {
177+
text-transform: capitalize;
178+
border: 1px solid #FAEBD7;
179+
background-color: #FAEBD7;
180+
border-radius: 15px;
181+
padding: 5px;
182+
font-variant: small-caps;
183+
font-weight: bold;
184+
font-style: italic;
185+
box-shadow: rgba(17, 17, 26, 0.1) 0px 8px 24px, rgba(17, 17, 26, 0.1) 0px 16px 56px, rgba(17, 17, 26, 0.1) 0px 24px 80px;
186+
}
141187

142188
.config-page {
143189
background-color: #f8f9fa;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ defmodule DashboardWeb.Helper.ConfigHelper do
5050
defp get_initial_config do
5151
%{
5252
"schema-file-path": "",
53-
"source-csv-directory": "",
53+
"source-csv-directory": "/home/arpan/Desktop/test/bulk_csvs", #"",
5454
"imported-csv-directory": "",
5555
"validated-csv-directory": "",
5656
"skip-make-schema": nil,
5757
"skip-insert-schema": nil,
5858
"skip-insert-data": nil,
5959
"skip-validate-import": nil,
60-
csv2sql_username: "",
61-
csv2sql_password: "",
60+
csv2sql_username: "root",
61+
csv2sql_password: "mysql",
6262
csv2sql_host: "localhost",
63-
csv2sql_database_name: "",
63+
csv2sql_database_name: "csvsql_test",
6464
"connection-socket": "/var/run/mysqld/mysqld.sock",
6565
"varchar-limit": 100,
6666
"schema-infer-chunk-size": 100,

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ defmodule DashboardWeb.MainLive do
3030
new_stage =
3131
case assigns.stage do
3232
:waiting ->
33-
ConfigHelper.get_to_config_arg()
34-
|> Csv2sql.main()
35-
33+
ConfigHelper.get_to_config_arg() |> Csv2sql.main()
3634
send(self(), :tick)
35+
3736
:working
3837

3938
:finish ->

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="main-container">
22
<div class="current-stats">
3-
<div><strong> Stage: </strong> <%= @stage %></div>
3+
<div><strong> Stage: </strong> <span class="overall-status"> <%= @stage %> </span> </div>
44
<%= if @stage != :waiting do %>
55
<div><strong> Total Files: </strong><%= Enum.count(@file_list) %> </div>
66
<div><strong> Files Imported: </strong><%= Enum.count(@file_list, fn %{status: status} -> status == :finish end) %> </div>
@@ -30,29 +30,29 @@
3030
<span class="file-path"> <strong> Path: </strong> <a href="file:///<%= path %>" target="_blank"><%= path %></a> </span>
3131
<span class="file-size"> <strong> Size: </strong> <%= humanised_size %> </span>
3232
<span class="row_count"> <strong> Total Number of Records: </strong> <%= row_count %> </span>
33-
<span class="status">
34-
<Strong> Status: </Strong>
33+
<span>
34+
<Strong class="status"> Status: </Strong>
3535
<%= case status do %>
36-
<% :pending -> %> Pending
36+
<% :pending -> %> <span class="stage_pending"> Pending </span>
3737

38-
<% :infer_schema -> %> Infering Schema
38+
<% :infer_schema -> %> <span class="stage_infer_schema"> Infering Schema </span>
3939

40-
<% :insert_schema -> %> Loading Schema
40+
<% :insert_schema -> %> <span class="stage_loading_schema"> Loading Schema </span>
4141

4242
<% {:insert_data, progress} -> %>
43-
Inserting Data
43+
<span class="stage_insert_data"> Inserting Data </span>
4444
<span class="records_inserted"> <strong> Record Inserted: </strong> <%= progress %> </span>
4545
<div class="progress">
46-
<%= percentage_progress = if(row_count == 0, do: 100, else: (progress / row_count) * 100) %>
46+
<% percentage_progress = if(row_count == 0, do: 100, else: (progress / row_count) * 100) %>
4747
<div
4848
class="progress-bar progress-bar-striped progress-bar-animated bg-success"
4949
role="progressbar"
5050
style="width: <%= percentage_progress %>%">
51-
<span class="progress-percentage"> <%= Float.round(percentage_progress * 1.0 , 2) %>% </span>
52-
</div> %>
51+
<span class="progress-percentage justify-content-center d-flex position-absolute w-100"> <%= Float.round(percentage_progress * 1.0 , 2) %>% </span>
52+
</div>
5353
</div>
5454

55-
<% :finish -> %> Finisihed
55+
<% :finish -> %> <span class="stage_finished"> Finisihed </span>
5656
<% end %>
5757
</span>
5858
</div>

0 commit comments

Comments
 (0)