data_pact 0.1.2 → 0.2

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: 70cc442650880adb3b16dfc6850796590544c20c2e6dddddff7fa0ea7904e533
4
- data.tar.gz: 2520a6195b1b9b3ad402a155bc99416ee8fe86693fbc59e870732763c140ac89
3
+ metadata.gz: a57ddb8ccc047c98891a248b5999721d6e3c59c388fc6686940f81dd80d9f00c
4
+ data.tar.gz: 7525beaf8daf186d95531ae9dc21e24b12090c1dcd7f889db34e9c6ca3273ccb
5
5
  SHA512:
6
- metadata.gz: 5dd1e478cf376f3f692b82bd5224b7c3ffb93dda68c9202b480da40ec2de7834a078f0fb9ade965affbc653e5d17bb70d42073ba6ef8c96d80be4370c2258fed
7
- data.tar.gz: 8d83a2a956f296e735fcfedbea5dd8318348724b61daa0a9cb940ca7d406761a16c5948446a3e95943d37aca7a2b8d18987ccd3cb855b4f42b39a5f659e6f97a
6
+ metadata.gz: 3f1a7fc17da8c0dbb0d1e74ff64749877e2208fa7d3bdc44a17facf57c79d2896ea8c248829a6553d04c57193ed7a2f839a9d8ae949e5ba940d1f8881590b948
7
+ data.tar.gz: eec78b1de7ef58344113ad3d9b8fb890720e85c5bcdefde181dd874cbea51139c84791e95d3f9b346d231bc49862f4eeb1ae38ca6244022e2fc984cf1a072223
@@ -1,5 +1,10 @@
1
1
  module DataPact
2
2
  class ApplicationController < ActionController::Base
3
+
4
+ def index
5
+ redirect_to routes_path
6
+ end
7
+
3
8
  def routes
4
9
  @routes = Rails.application.routes.routes.map do |route|
5
10
  {
@@ -7,12 +12,29 @@ module DataPact
7
12
  verb: route.verb,
8
13
  path: route.path.spec.to_s,
9
14
  format: route.defaults[:format],
10
- controller_action: [route.defaults[:controller], '#', route.defaults[:action]].join,
15
+ controller: route.defaults[:controller],
16
+ action: route.defaults[:action]
11
17
  }
12
18
  end
19
+
20
+ respond_to do |format|
21
+ format.html
22
+ format.json do
23
+ render json: {
24
+ partial: render_to_string(partial: 'data_pact/routes/list', formats: [:html]),
25
+ }
26
+ end
27
+ end
13
28
  end
14
29
 
15
30
  def settings
16
31
  end
32
+
33
+ def jobs
34
+ @jobs = Sidekiq::Queue.all.flat_map(&:to_a).sort_by(&:enqueued_at)
35
+ @redis = true
36
+ rescue Redis::CannotConnectError => e
37
+ @redis = false
38
+ end
17
39
  end
18
40
  end
@@ -0,0 +1,37 @@
1
+ module DataPact
2
+ class RouteDataController < ApplicationController
3
+ def index
4
+ @routes = Rails.application.routes.routes.map do |route|
5
+ {
6
+ name: route.name,
7
+ verb: route.verb,
8
+ path: route.path.spec.to_s,
9
+ format: route.defaults[:format],
10
+ controller: route.defaults[:controller],
11
+ action: route.defaults[:action]
12
+ }
13
+ end
14
+
15
+ if params[:controller_filter].present?
16
+ @routes = @routes.select { |r| r[:controller] == params[:controller_filter] }
17
+ end
18
+
19
+ if params[:search_term].present?
20
+ @routes = @routes.select { |r| r.values.map(&:to_s).any? { |v| v&.include?(params[:search_term]) } }
21
+ end
22
+
23
+ @controllers = @routes.collect { |r| r[:controller] }
24
+ respond_to do |format|
25
+ format.html { render 'routes' }
26
+ format.json do
27
+ render json: {
28
+ partial: render_to_string(partial: 'data_pact/routes/list', formats: [:html]),
29
+ }
30
+ end
31
+ end
32
+ end
33
+
34
+ def list
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,39 @@
1
+ <% if @redis %>
2
+
3
+ <div class="px-4">
4
+ <div class="overflow-x-auto">
5
+ <table class="table table-sm">
6
+ <thead>
7
+ <tr>
8
+ <th>Enqueued At</th>
9
+ <th>Class</th>
10
+ <th>Queue</th>
11
+ <th>Args</th>
12
+ </tr>
13
+ </thead>
14
+ <tbody>
15
+ <% @jobs.each do |job| %>
16
+ <tr>
17
+ <td class="whitespace-nowrap"><%= Time.at(job['enqueued_at']).strftime('%b %d %H:%M') %></td>
18
+ <td><%= job['class'] %></td>
19
+ <td><%= job['queue'] %></td>
20
+ <td><%= job['args'] %></td>
21
+ </tr>
22
+ <% end %>
23
+ </tbody>
24
+ </table>
25
+ </div>
26
+ </div>
27
+ <% else %>
28
+ <div class="flex justify-center">
29
+ <div class="alert alert-error shadow-lg w-1/2 mt-24">
30
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="stroke-info shrink-0 w-6 h-6">
31
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
32
+ </svg>
33
+ <div>
34
+ <h3 class="font-bold">Redis is not running</h3>
35
+ <div class="text-xs">Start Redis and refresh this page</div>
36
+ </div>
37
+ </div>
38
+ </div>
39
+ <% end %>
@@ -1,17 +1,48 @@
1
- <div class="flex flex-col gap-y-2">
2
- <% @routes.each do |route_data| %>
3
- <div class="collapse collapse-arrow bg-base-200">
4
- <input type="radio" name="my-accordion-2" checked="checked"/>
5
- <div class="collapse-title text-xl font-medium flex items-center">
6
- <div class="flex items-center gap-6 flex-1">
7
- <%= tag.div route_data.fetch(:verb), class: 'badge badge-neutral badge-lg' if route_data[:verb].present? %>
8
- <span><%= route_data[:path]&.sub('(.:format)', '') %></span>
9
- </div>
10
- <span><%= route_data.fetch(:name, :controller_action) %></span>
11
- </div>
12
- <div class="collapse-content">
13
- <p><%= route_data %></p>
1
+ <div x-data="routes" class="flex flex-col gap-y-2">
2
+ <div class="flex justify-between">
3
+ <div class="form-control w-1/3">
4
+ <label class="label">
5
+ <span class="label-text">Search</span>
6
+ </label>
7
+ <input x-model="searchTerm" @input.debounce="refreshList()" type="text" placeholder="Search by route, pathname, controller, action" class="input input-bordered w-24 md:w-auto"/>
8
+ </div>
9
+ <div class="form-control w-1/5">
10
+ <div class="form-control w-full max-w-xs">
11
+ <label class="label">
12
+ <span class="label-text">Filter by controller</span>
13
+ <span x-cloak x-show="controllerFilter" @click="controllerFilter = '';refreshList()" class="label-text-alt cursor-pointer">Clear</span>
14
+ </label>
15
+ <%= select_tag 'controller_filter', options_for_select(@controllers.uniq.compact.sort), prompt: 'Select one', class: 'select select-bordered', '@change': 'refreshList()', 'x-model':'controllerFilter' %>
14
16
  </div>
15
17
  </div>
16
- <% end %>
17
- </div>
18
+ </div>
19
+ <div id="routes-list" class="flex flex-col gap-y-2">
20
+ <%= render partial: 'data_pact/routes/list', locals: { route_data: @routes } %>
21
+ </div>
22
+ </div>
23
+
24
+ <script type="text/javascript" charset="utf-8">
25
+ document.addEventListener('alpine:init', () => {
26
+ Alpine.data('routes', () => ({
27
+ searchTerm: '',
28
+ controllerFilter: '',
29
+ refreshList() {
30
+ fetch("<%= routes_path %>?" + new URLSearchParams({controller_filter: this.controllerFilter, search_term: this.searchTerm}), {
31
+ headers: {
32
+ 'accept': 'application/json'
33
+ },
34
+ })
35
+ .then(response => response.json())
36
+ .then(html => {
37
+ console.log('success', html)
38
+ document.querySelector('#routes-list').innerHTML = html.partial
39
+ })
40
+ },
41
+ showRoute(e) {
42
+ let string = e.dataset.route
43
+ let regex = new RegExp(this.searchTerm, 'i')
44
+ return regex.test(string)
45
+ }
46
+ }))
47
+ })
48
+ </script>
@@ -1,9 +1,9 @@
1
1
  <div x-data="settings" class="w-2/3">
2
2
  <div class="rounded bg-base-100 place-content-center py-4">
3
3
  <div class="flex flex-1 items-center justify-between px-6">
4
- <span class="text-primary-content text-xl font-medium">Theme</span>
4
+ <span class="text-base-content text-xl font-medium">Theme</span>
5
5
 
6
- <select @change="changeTheme($event)" class="select select-bordered w-full max-w-xs text-primary-content">
6
+ <select @change="changeTheme($event)" class="select select-bordered w-full max-w-xs text-base-content">
7
7
  <%= options_for_select(themes_for_select) %>
8
8
  </select>
9
9
  </div>
@@ -0,0 +1,16 @@
1
+ <% @routes.each do |route_data| %>
2
+ <!-- add collapse-arrow class to re-enable accordion-->
3
+ <div class="collapse bg-base-200" data-route="<%= route_data.inspect %>">
4
+ <input type="radio" name="routes-accordion-2" checked="checked"/>
5
+ <div class="collapse-title text-xl font-medium flex items-center">
6
+ <div class="flex items-center gap-6 flex-1">
7
+ <%= tag.div route_data.fetch(:verb), class: 'badge badge-neutral badge-lg' if route_data[:verb].present? %>
8
+ <span><%= route_data[:path]&.sub('(.:format)', '') %></span>
9
+ </div>
10
+ <span><%= route_data.fetch(:name, :controller_action) %></span>
11
+ </div>
12
+ <div class="collapse-content">
13
+ <p><%= route_data.inspect %></p>
14
+ </div>
15
+ </div>
16
+ <% end %>
@@ -19,18 +19,14 @@
19
19
  })();
20
20
  </script>
21
21
 
22
- <div class="h-screen w-screen">
22
+ <div class="min-h-screen w-screen">
23
23
  <div class="navbar bg-base-100 border-b border-base-200">
24
24
  <div class="flex-1">
25
- <div class="btn btn-ghost normal-case text-xl">DataPact</div>
26
- <%= link_to 'Routes', routes_path, class: 'btn btn-ghost normal-case text-lg font-medium' %>
27
- <%= link_to 'Session Data', session_data_path, class: 'btn btn-ghost normal-case text-lg font-medium' %>
28
- <%= link_to 'Settings', settings_path, class: 'btn btn-ghost normal-case text-lg font-medium' %>
29
- </div>
30
- <div class="flex-none gap-2">
31
- <div class="form-control">
32
- <input type="text" placeholder="Search" class="input input-bordered w-24 md:w-auto"/>
33
- </div>
25
+ <div class="mx-4 font-bold text-base-content normal-case text-xl">DataPact</div>
26
+ <%= link_to 'Routes', routes_path, class: 'btn btn-ghost text-base-content normal-case text-lg font-medium' %>
27
+ <%= link_to 'Session Data', session_data_path, class: 'btn btn-ghost text-base-content normal-case text-lg font-medium' %>
28
+ <%#= link_to 'Jobs', jobs_path, class: 'btn btn-ghost text-base-content normal-case text-lg font-medium' %>
29
+ <%= link_to 'Settings', settings_path, class: 'btn btn-ghost text-base-content normal-case text-lg font-medium' %>
34
30
  </div>
35
31
  </div>
36
32
  <div class="my-3 mx-6">
data/config/routes.rb CHANGED
@@ -3,8 +3,9 @@ DataPact::Engine.routes.draw do
3
3
  resources :session_data, only: [:index, :create] do
4
4
  delete :destroy, on: :collection
5
5
  end
6
- get 'routes', to: 'application#routes'
6
+ get 'routes', to: 'route_data#index'
7
7
  get 'settings', to: 'application#settings'
8
+ get 'jobs', to: 'application#jobs'
8
9
  root to: 'application#index'
9
10
 
10
11
  end
@@ -1,3 +1,3 @@
1
1
  module DataPact
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_pact
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Shyman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-06 00:00:00.000000000 Z
11
+ date: 2023-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -43,14 +43,17 @@ files:
43
43
  - app/assets/config/data_pact_manifest.js
44
44
  - app/assets/stylesheets/data_pact/application.css
45
45
  - app/controllers/data_pact/application_controller.rb
46
+ - app/controllers/data_pact/route_data_controller.rb
46
47
  - app/controllers/data_pact/session_data_controller.rb
47
48
  - app/helpers/data_pact/application_helper.rb
48
49
  - app/jobs/data_pact/application_job.rb
49
50
  - app/mailers/data_pact/application_mailer.rb
50
51
  - app/models/data_pact/application_record.rb
51
52
  - app/views/application/index.html.erb
53
+ - app/views/data_pact/application/jobs.html.erb
52
54
  - app/views/data_pact/application/routes.html.erb
53
55
  - app/views/data_pact/application/settings.html.erb
56
+ - app/views/data_pact/routes/_list.html.erb
54
57
  - app/views/data_pact/session_data/index.html.erb
55
58
  - app/views/layouts/data_pact/application.html.erb
56
59
  - config/routes.rb