Skip to content

Commit

Permalink
Merge pull request #12 from doximity/file-dir
Browse files Browse the repository at this point in the history
Add Search Filtering, Reduce Dependencies, Fix Bug in Dir Existing
  • Loading branch information
Austio committed Feb 11, 2021
2 parents cd0266b + b0fe9da commit ae776ac
Show file tree
Hide file tree
Showing 30 changed files with 265 additions and 181 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/test/dummy/db/*.sqlite3
/test/dummy/db/*.sqlite3-*
/test/dummy/log/*.log
/test/dummy/tmp/rake_ui/*
/test/dummy/storage/
/test/dummy/tmp/cache/
/test/dummy/tmp/development_secret.txt
Expand Down
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Specify your gem's dependencies in rake-ui.gemspec.
gemspec

gem "jbuilder"

group :development do
gem "sqlite3"
end
Expand Down
4 changes: 0 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ PATH
rake-ui (0.1.0)
actionpack
activesupport
jbuilder
railties
rake

Expand Down Expand Up @@ -75,8 +74,6 @@ GEM
activesupport (>= 4.2.0)
i18n (1.8.8)
concurrent-ruby (~> 1.0)
jbuilder (2.11.2)
activesupport (>= 5.0.0)
loofah (2.9.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand Down Expand Up @@ -151,7 +148,6 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
jbuilder
pry
rails
rake-ui!
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# RakeUi
Short description and motivation.

## Usage
How to use my plugin.
Rake UI is a Rails engine that enables the discovery and execution rake tasks in a UI.

## Installation
Add this line to your application's Gemfile:
Expand Down
36 changes: 34 additions & 2 deletions app/controllers/rake_ui/rake_task_logs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@

module RakeUi
class RakeTaskLogsController < ApplicationController
RAKE_TASK_LOG_ATTRS = [:id,
:name,
:args,
:environment,
:rake_command,
:rake_definition_file,
:log_file_name,
:log_file_full_path].freeze

def index
@rake_task_logs = RakeUi::RakeTaskLog.all.sort_by(&:id)

respond_to do |format|
format.html
format.json
format.json do
render json: {
rake_task_logs: rake_task_logs_as_json(@rake_task_logs)
}
end
end
end

Expand All @@ -20,8 +33,27 @@ def show

respond_to do |format|
format.html
format.json
format.json do
render json: {
rake_task_log: rake_task_log_as_json(@rake_task_log),
rake_task_log_content: @rake_task_log_content,
rake_task_log_content_url: @rake_task_log_content_url,
is_rake_task_log_finished: @is_rake_task_log_finished
}
end
end
end

private

def rake_task_log_as_json(task)
RAKE_TASK_LOG_ATTRS.each_with_object({}) do |param, obj|
obj[param] = task.send(param)
end
end

def rake_task_logs_as_json(tasks = [])
tasks.map { |task| rake_task_log_as_json(task) }
end
end
end
33 changes: 31 additions & 2 deletions app/controllers/rake_ui/rake_tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

module RakeUi
class RakeTasksController < RakeUi::ApplicationController
RAKE_TASK_ATTRS = [:id,
:name,
:name_with_args,
:arg_description,
:full_comment,
:locations,
:is_internal_task,
:sources].freeze

def index
@rake_tasks = RakeUi::RakeTask.all

Expand All @@ -10,17 +19,25 @@ def index
end

respond_to do |format|
format.json
format.html
format.json do
render json: {
rake_tasks: rake_tasks_as_json(@rake_tasks)
}
end
end
end

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

respond_to do |format|
format.json
format.html
format.json do
render json: {
rake_task: rake_task_as_json(@rake_task)
}
end
end
end

Expand All @@ -31,5 +48,17 @@ def execute

redirect_to rake_task_log_path rake_task_log.id
end

private

def rake_task_as_json(task)
RAKE_TASK_ATTRS.each_with_object({}) do |param, obj|
obj[param] = task.send(param)
end
end

def rake_tasks_as_json(tasks)
tasks.map { |task| rake_task_as_json(task) }
end
end
end
10 changes: 8 additions & 2 deletions app/models/rake_ui/rake_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ def id

# actions will be something like #<Proc:0x000055a2737fe778@/some/rails/app/lib/tasks/auto_annotate_models.rake:4>
def rake_definition_file
actions.first
rescue StandardError
definition = actions.first || ""

if definition.respond_to?(:source_location)
definition.source_location.join(":")
else
definition
end
rescue
"unable_to_determine_defining_file"
end

Expand Down
10 changes: 9 additions & 1 deletion app/models/rake_ui/rake_task_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class RakeTaskLog < OpenStruct
TASK_HEADER_OUTPUT_DELIMITER = "-------------------------------"
FILE_ITEM_SEPARATOR = ": "

def self.create_tmp_file_dir
FileUtils.mkdir_p(REPOSITORY_DIR.to_s)
end

def self.truncate
FileUtils.rm_rf(Dir.glob(REPOSITORY_DIR.to_s + "/*"))
end
Expand All @@ -25,10 +29,12 @@ def self.build_from_file(log_file_name)
end

def self.build_new_for_command(name:, rake_definition_file:, rake_command:, raker_id:, args: nil, environment: nil)
create_tmp_file_dir

date = Time.now.strftime(ID_DATE_FORMAT)
id = "#{date}#{FILE_DELIMITER}#{raker_id}"
log_file_name = "#{id}.txt"
log_file_full_path = Rails.root.join("tmp", "rake_ui", log_file_name).to_s
log_file_full_path = REPOSITORY_DIR.join(log_file_name).to_s

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

def self.all
create_tmp_file_dir

Dir.entries(REPOSITORY_DIR).reject { |file|
file == "." || file == ".."
}.map do |log|
Expand Down
9 changes: 6 additions & 3 deletions app/views/layouts/rake_ui/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<%= csp_meta_tag %>

<link rel="stylesheet" href="https://cdn.rawgit.com/doximity/vital/v2.2.1/dist/css/vital.min.css">

<%= stylesheet_link_tag "rake_ui/application", media: "all" %>
</head>
<body>

Expand All @@ -22,7 +20,12 @@
</nav>
</div>
</div>

<p id="notice"><%= notice %></p>

<!-- End Nav Menu -->
<%= yield %>
<div class="contents">
<%= yield %>
</div>
</body>
</html>
41 changes: 41 additions & 0 deletions app/views/partials/rake_ui/_table_filterable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<script type="application/javascript">
function hide(elm) {
elm.style.display = "none";
}

function show(elm) {
elm.style.display = "";
}

function toggle(elm) {
if (elm.style.display === "none") {
show(elm);
} else {
hide(elm);
}
}

function filterTable(value) {
var tableRows = document.querySelectorAll('[data-table-filterable]');

for (var i = 0; i < tableRows.length; i++) {
var row = tableRows[i];

if (value == "") {
show(row)
} else {
if (row.dataset.tableFilterable.includes(value)) {
show(row)
} else {
hide(row)
}
}
}
}

var input = document.querySelector('[data-table-filter]');

input.addEventListener('input', function handleInput(input) {
filterTable(input.target.value)
})
</script>
11 changes: 0 additions & 11 deletions app/views/rake_ui/rake_task_logs/_rake_task_log.json.jbuilder

This file was deleted.

55 changes: 31 additions & 24 deletions app/views/rake_ui/rake_task_logs/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
<p id="notice"><%= notice %></p>
<div class="row">
<div class="section">
<h1>Status</h1>

<h1>Status</h1>
<hr >

<hr >
<div class="section">
<p>
Filter Table <input data-table-filter placeholder="Enter Text" />
</p>
</div>

<table>
<thead>
<tr>
<th colspan="3"></th>
</tr>
</thead>
<table>
<thead>
<tr>
<th>Rake Task</th>
<th>Date Ran</th>
<th>Actions</th>
</tr>
</thead>

<tbody>
<tr>
<td>Name</td>
<td>Date Ran</td>
<td></td>
</tr>
<% @rake_task_logs.each do |rake_task_log| %>
<tr>
<td><%= link_to rake_task_log.name, rake_task_log_path(rake_task_log.id) %></td>
<td><%= rake_task_log.date %></td>
<td><%= link_to "View Logs", rake_task_log_path(rake_task_log.id), { class: 'btn' } %></td>
</tr>
<% end %>
</tbody>
</table>
<tbody>
<% @rake_task_logs.each do |rake_task_log| %>
<tr data-table-filterable="<%= rake_task_log.name %>">
<td><%= link_to rake_task_log.name, rake_task_log_path(rake_task_log.id) %></td>
<td><%= rake_task_log.date %></td>
<td><%= link_to "View Logs", rake_task_log_path(rake_task_log.id), { class: 'btn' } %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>

<%= render "partials/rake_ui/table_filterable" %>
5 changes: 0 additions & 5 deletions app/views/rake_ui/rake_task_logs/index.json.jbuilder

This file was deleted.

Loading

0 comments on commit ae776ac

Please sign in to comment.