Skip to content

Commit ae776ac

Browse files
authored
Merge pull request #12 from doximity/file-dir
Add Search Filtering, Reduce Dependencies, Fix Bug in Dir Existing
2 parents cd0266b + b0fe9da commit ae776ac

30 files changed

+265
-181
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/test/dummy/db/*.sqlite3
77
/test/dummy/db/*.sqlite3-*
88
/test/dummy/log/*.log
9+
/test/dummy/tmp/rake_ui/*
910
/test/dummy/storage/
1011
/test/dummy/tmp/cache/
1112
/test/dummy/tmp/development_secret.txt

Gemfile

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
44
# Specify your gem's dependencies in rake-ui.gemspec.
55
gemspec
66

7-
gem "jbuilder"
8-
97
group :development do
108
gem "sqlite3"
119
end

Gemfile.lock

-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ PATH
44
rake-ui (0.1.0)
55
actionpack
66
activesupport
7-
jbuilder
87
railties
98
rake
109

@@ -75,8 +74,6 @@ GEM
7574
activesupport (>= 4.2.0)
7675
i18n (1.8.8)
7776
concurrent-ruby (~> 1.0)
78-
jbuilder (2.11.2)
79-
activesupport (>= 5.0.0)
8077
loofah (2.9.0)
8178
crass (~> 1.0.2)
8279
nokogiri (>= 1.5.9)
@@ -151,7 +148,6 @@ PLATFORMS
151148
x86_64-linux
152149

153150
DEPENDENCIES
154-
jbuilder
155151
pry
156152
rails
157153
rake-ui!

README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# RakeUi
2-
Short description and motivation.
3-
4-
## Usage
5-
How to use my plugin.
2+
Rake UI is a Rails engine that enables the discovery and execution rake tasks in a UI.
63

74
## Installation
85
Add this line to your application's Gemfile:

app/controllers/rake_ui/rake_task_logs_controller.rb

+34-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22

33
module RakeUi
44
class RakeTaskLogsController < ApplicationController
5+
RAKE_TASK_LOG_ATTRS = [:id,
6+
:name,
7+
:args,
8+
:environment,
9+
:rake_command,
10+
:rake_definition_file,
11+
:log_file_name,
12+
:log_file_full_path].freeze
13+
514
def index
615
@rake_task_logs = RakeUi::RakeTaskLog.all.sort_by(&:id)
716

817
respond_to do |format|
918
format.html
10-
format.json
19+
format.json do
20+
render json: {
21+
rake_task_logs: rake_task_logs_as_json(@rake_task_logs)
22+
}
23+
end
1124
end
1225
end
1326

@@ -20,8 +33,27 @@ def show
2033

2134
respond_to do |format|
2235
format.html
23-
format.json
36+
format.json do
37+
render json: {
38+
rake_task_log: rake_task_log_as_json(@rake_task_log),
39+
rake_task_log_content: @rake_task_log_content,
40+
rake_task_log_content_url: @rake_task_log_content_url,
41+
is_rake_task_log_finished: @is_rake_task_log_finished
42+
}
43+
end
2444
end
2545
end
46+
47+
private
48+
49+
def rake_task_log_as_json(task)
50+
RAKE_TASK_LOG_ATTRS.each_with_object({}) do |param, obj|
51+
obj[param] = task.send(param)
52+
end
53+
end
54+
55+
def rake_task_logs_as_json(tasks = [])
56+
tasks.map { |task| rake_task_log_as_json(task) }
57+
end
2658
end
2759
end

app/controllers/rake_ui/rake_tasks_controller.rb

+31-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
module RakeUi
44
class RakeTasksController < RakeUi::ApplicationController
5+
RAKE_TASK_ATTRS = [:id,
6+
:name,
7+
:name_with_args,
8+
:arg_description,
9+
:full_comment,
10+
:locations,
11+
:is_internal_task,
12+
:sources].freeze
13+
514
def index
615
@rake_tasks = RakeUi::RakeTask.all
716

@@ -10,17 +19,25 @@ def index
1019
end
1120

1221
respond_to do |format|
13-
format.json
1422
format.html
23+
format.json do
24+
render json: {
25+
rake_tasks: rake_tasks_as_json(@rake_tasks)
26+
}
27+
end
1528
end
1629
end
1730

1831
def show
1932
@rake_task = RakeUi::RakeTask.find_by_id(params[:id])
2033

2134
respond_to do |format|
22-
format.json
2335
format.html
36+
format.json do
37+
render json: {
38+
rake_task: rake_task_as_json(@rake_task)
39+
}
40+
end
2441
end
2542
end
2643

@@ -31,5 +48,17 @@ def execute
3148

3249
redirect_to rake_task_log_path rake_task_log.id
3350
end
51+
52+
private
53+
54+
def rake_task_as_json(task)
55+
RAKE_TASK_ATTRS.each_with_object({}) do |param, obj|
56+
obj[param] = task.send(param)
57+
end
58+
end
59+
60+
def rake_tasks_as_json(tasks)
61+
tasks.map { |task| rake_task_as_json(task) }
62+
end
3463
end
3564
end

app/models/rake_ui/rake_task.rb

+8-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,14 @@ def id
4141

4242
# actions will be something like #<Proc:0x000055a2737fe778@/some/rails/app/lib/tasks/auto_annotate_models.rake:4>
4343
def rake_definition_file
44-
actions.first
45-
rescue StandardError
44+
definition = actions.first || ""
45+
46+
if definition.respond_to?(:source_location)
47+
definition.source_location.join(":")
48+
else
49+
definition
50+
end
51+
rescue
4652
"unable_to_determine_defining_file"
4753
end
4854

app/models/rake_ui/rake_task_log.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ class RakeTaskLog < OpenStruct
1010
TASK_HEADER_OUTPUT_DELIMITER = "-------------------------------"
1111
FILE_ITEM_SEPARATOR = ": "
1212

13+
def self.create_tmp_file_dir
14+
FileUtils.mkdir_p(REPOSITORY_DIR.to_s)
15+
end
16+
1317
def self.truncate
1418
FileUtils.rm_rf(Dir.glob(REPOSITORY_DIR.to_s + "/*"))
1519
end
@@ -25,10 +29,12 @@ def self.build_from_file(log_file_name)
2529
end
2630

2731
def self.build_new_for_command(name:, rake_definition_file:, rake_command:, raker_id:, args: nil, environment: nil)
32+
create_tmp_file_dir
33+
2834
date = Time.now.strftime(ID_DATE_FORMAT)
2935
id = "#{date}#{FILE_DELIMITER}#{raker_id}"
3036
log_file_name = "#{id}.txt"
31-
log_file_full_path = Rails.root.join("tmp", "rake_ui", log_file_name).to_s
37+
log_file_full_path = REPOSITORY_DIR.join(log_file_name).to_s
3238

3339
File.open(log_file_full_path, "w+") do |f|
3440
f.puts "id#{FILE_ITEM_SEPARATOR}#{id}"
@@ -57,6 +63,8 @@ def self.build_new_for_command(name:, rake_definition_file:, rake_command:, rake
5763
end
5864

5965
def self.all
66+
create_tmp_file_dir
67+
6068
Dir.entries(REPOSITORY_DIR).reject { |file|
6169
file == "." || file == ".."
6270
}.map do |log|

app/views/layouts/rake_ui/application.html.erb

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
<%= csp_meta_tag %>
77

88
<link rel="stylesheet" href="https://cdn.rawgit.com/doximity/vital/v2.2.1/dist/css/vital.min.css">
9-
10-
<%= stylesheet_link_tag "rake_ui/application", media: "all" %>
119
</head>
1210
<body>
1311

@@ -22,7 +20,12 @@
2220
</nav>
2321
</div>
2422
</div>
23+
24+
<p id="notice"><%= notice %></p>
25+
2526
<!-- End Nav Menu -->
26-
<%= yield %>
27+
<div class="contents">
28+
<%= yield %>
29+
</div>
2730
</body>
2831
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<script type="application/javascript">
2+
function hide(elm) {
3+
elm.style.display = "none";
4+
}
5+
6+
function show(elm) {
7+
elm.style.display = "";
8+
}
9+
10+
function toggle(elm) {
11+
if (elm.style.display === "none") {
12+
show(elm);
13+
} else {
14+
hide(elm);
15+
}
16+
}
17+
18+
function filterTable(value) {
19+
var tableRows = document.querySelectorAll('[data-table-filterable]');
20+
21+
for (var i = 0; i < tableRows.length; i++) {
22+
var row = tableRows[i];
23+
24+
if (value == "") {
25+
show(row)
26+
} else {
27+
if (row.dataset.tableFilterable.includes(value)) {
28+
show(row)
29+
} else {
30+
hide(row)
31+
}
32+
}
33+
}
34+
}
35+
36+
var input = document.querySelector('[data-table-filter]');
37+
38+
input.addEventListener('input', function handleInput(input) {
39+
filterTable(input.target.value)
40+
})
41+
</script>

app/views/rake_ui/rake_task_logs/_rake_task_log.json.jbuilder

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
1-
<p id="notice"><%= notice %></p>
1+
<div class="row">
2+
<div class="section">
3+
<h1>Status</h1>
24

3-
<h1>Status</h1>
5+
<hr >
46

5-
<hr >
7+
<div class="section">
8+
<p>
9+
Filter Table <input data-table-filter placeholder="Enter Text" />
10+
</p>
11+
</div>
612

7-
<table>
8-
<thead>
9-
<tr>
10-
<th colspan="3"></th>
11-
</tr>
12-
</thead>
13+
<table>
14+
<thead>
15+
<tr>
16+
<th>Rake Task</th>
17+
<th>Date Ran</th>
18+
<th>Actions</th>
19+
</tr>
20+
</thead>
1321

14-
<tbody>
15-
<tr>
16-
<td>Name</td>
17-
<td>Date Ran</td>
18-
<td></td>
19-
</tr>
20-
<% @rake_task_logs.each do |rake_task_log| %>
21-
<tr>
22-
<td><%= link_to rake_task_log.name, rake_task_log_path(rake_task_log.id) %></td>
23-
<td><%= rake_task_log.date %></td>
24-
<td><%= link_to "View Logs", rake_task_log_path(rake_task_log.id), { class: 'btn' } %></td>
25-
</tr>
26-
<% end %>
27-
</tbody>
28-
</table>
22+
<tbody>
23+
<% @rake_task_logs.each do |rake_task_log| %>
24+
<tr data-table-filterable="<%= rake_task_log.name %>">
25+
<td><%= link_to rake_task_log.name, rake_task_log_path(rake_task_log.id) %></td>
26+
<td><%= rake_task_log.date %></td>
27+
<td><%= link_to "View Logs", rake_task_log_path(rake_task_log.id), { class: 'btn' } %></td>
28+
</tr>
29+
<% end %>
30+
</tbody>
31+
</table>
32+
</div>
33+
</div>
34+
35+
<%= render "partials/rake_ui/table_filterable" %>

app/views/rake_ui/rake_task_logs/index.json.jbuilder

-5
This file was deleted.

0 commit comments

Comments
 (0)