data_pact 0.1.21 → 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: bd60138d89edaccd6d3af12e2707466f902fa8fd829ac0519ebea8a8d729ea05
4
- data.tar.gz: a83694196765d57ad7f50e5e14ddd9a07a63117f689ce2ccea1306a473520381
3
+ metadata.gz: a57ddb8ccc047c98891a248b5999721d6e3c59c388fc6686940f81dd80d9f00c
4
+ data.tar.gz: 7525beaf8daf186d95531ae9dc21e24b12090c1dcd7f889db34e9c6ca3273ccb
5
5
  SHA512:
6
- metadata.gz: 5f545d3f23194fcf52f573e70692e97699f53bef28aa40fb004b7048b9fdf13975324eb0f84452ad0c25caf83b2ed1a6512cfd2fa728f82071ebe9d73ce800f9
7
- data.tar.gz: 3f4159c8d145bce31816ee7cdf3992c007054ea69dab7659d1178c1b25c112f1995797a7835fff5bed7ce4340a970e4a710788a286556a3445373f3db3d0c437
6
+ metadata.gz: 3f1a7fc17da8c0dbb0d1e74ff64749877e2208fa7d3bdc44a17facf57c79d2896ea8c248829a6553d04c57193ed7a2f839a9d8ae949e5ba940d1f8881590b948
7
+ data.tar.gz: eec78b1de7ef58344113ad3d9b8fb890720e85c5bcdefde181dd874cbea51139c84791e95d3f9b346d231bc49862f4eeb1ae38ca6244022e2fc984cf1a072223
@@ -12,13 +12,17 @@ module DataPact
12
12
  verb: route.verb,
13
13
  path: route.path.spec.to_s,
14
14
  format: route.defaults[:format],
15
- controller_action: [route.defaults[:controller], '#', route.defaults[:action]].join,
15
+ controller: route.defaults[:controller],
16
+ action: route.defaults[:action]
16
17
  }
17
18
  end
18
19
 
19
20
  respond_to do |format|
20
21
  format.html
21
22
  format.json do
23
+ render json: {
24
+ partial: render_to_string(partial: 'data_pact/routes/list', formats: [:html]),
25
+ }
22
26
  end
23
27
  end
24
28
  end
@@ -28,6 +32,9 @@ module DataPact
28
32
 
29
33
  def jobs
30
34
  @jobs = Sidekiq::Queue.all.flat_map(&:to_a).sort_by(&:enqueued_at)
35
+ @redis = true
36
+ rescue Redis::CannotConnectError => e
37
+ @redis = false
31
38
  end
32
39
  end
33
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
@@ -1,24 +1,39 @@
1
- <div class="px-4">
2
- <div class="overflow-x-auto">
3
- <table class="table table-sm">
4
- <thead>
5
- <tr>
6
- <th>Enqueued At</th>
7
- <th>Class</th>
8
- <th>Queue</th>
9
- <th>Args</th>
10
- </tr>
11
- </thead>
12
- <tbody>
13
- <% @jobs.each do |job| %>
1
+ <% if @redis %>
2
+
3
+ <div class="px-4">
4
+ <div class="overflow-x-auto">
5
+ <table class="table table-sm">
6
+ <thead>
14
7
  <tr>
15
- <td class="whitespace-nowrap"><%= Time.at(job['enqueued_at']).strftime('%b %d %H:%M') %></td>
16
- <td><%= job['class'] %></td>
17
- <td><%= job['queue'] %></td>
18
- <td><%= job['args'] %></td>
8
+ <th>Enqueued At</th>
9
+ <th>Class</th>
10
+ <th>Queue</th>
11
+ <th>Args</th>
19
12
  </tr>
20
- <% end %>
21
- </tbody>
22
- </table>
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>
23
26
  </div>
24
- </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,47 +1,47 @@
1
1
  <div x-data="routes" class="flex flex-col gap-y-2">
2
- <div class="form-control w-1/2">
3
- <input x-model="searchTerm" type="text" placeholder="Search" class="input input-bordered w-24 md:w-auto"/>
4
- </div>
5
- <% @routes.each do |route_data| %>
6
- <div x-show="showRoute($el)" class="collapse collapse-arrow bg-base-200" data-route="<%= route_data.inspect %>">
7
- <div class="collapse-title text-xl font-medium flex items-center">
8
- <div class="flex items-center gap-6 flex-1">
9
- <%= tag.div route_data.fetch(:verb), class: 'badge badge-neutral badge-lg' if route_data[:verb].present? %>
10
- <span><%= route_data[:path]&.sub('(.:format)', '') %></span>
11
- </div>
12
- <span><%= route_data.fetch(:name, :controller_action) %></span>
13
- </div>
14
- <div class="collapse-content">
15
- <p><%= route_data %></p>
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' %>
16
16
  </div>
17
17
  </div>
18
- <% end %>
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>
19
22
  </div>
20
23
 
21
24
  <script type="text/javascript" charset="utf-8">
22
25
  document.addEventListener('alpine:init', () => {
23
26
  Alpine.data('routes', () => ({
24
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
+ },
25
41
  showRoute(e) {
26
- if (this.searchTerm === '') return true
27
-
28
-
29
-
30
- // fetch('/routes', {
31
- // headers: {
32
- // 'Content-Type': 'application/json'
33
- // },
34
- // body: JSON.stringify({search_term: this.searchTerm})
35
- // })
36
- // .then(response => response.json())
37
- // .then(data => {
38
- // console/.log(data)
39
- // })
40
- // .catch(error => console.error(error)
41
- // )
42
- // let string = e.dataset.route
43
- // let regex = new RegExp(this.searchTerm, 'i')
44
- // return regex.test(string)
42
+ let string = e.dataset.route
43
+ let regex = new RegExp(this.searchTerm, 'i')
44
+ return regex.test(string)
45
45
  }
46
46
  }))
47
47
  })
@@ -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 %>
@@ -22,16 +22,11 @@
22
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 'Jobs', jobs_path, class: 'btn btn-ghost normal-case text-lg font-medium' %>
29
- <%= link_to 'Settings', settings_path, class: 'btn btn-ghost normal-case text-lg font-medium' %>
30
- </div>
31
- <div class="flex-none gap-2">
32
- <!-- <div class="form-control">-->
33
- <!-- <input type="text" placeholder="Search" class="input input-bordered w-24 md:w-auto"/>-->
34
- <!-- </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' %>
35
30
  </div>
36
31
  </div>
37
32
  <div class="my-3 mx-6">
data/config/routes.rb CHANGED
@@ -3,7 +3,7 @@ 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
8
  get 'jobs', to: 'application#jobs'
9
9
  root to: 'application#index'
@@ -1,3 +1,3 @@
1
1
  module DataPact
2
- VERSION = "0.1.21"
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.21
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-08 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,6 +43,7 @@ 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
@@ -52,6 +53,7 @@ files:
52
53
  - app/views/data_pact/application/jobs.html.erb
53
54
  - app/views/data_pact/application/routes.html.erb
54
55
  - app/views/data_pact/application/settings.html.erb
56
+ - app/views/data_pact/routes/_list.html.erb
55
57
  - app/views/data_pact/session_data/index.html.erb
56
58
  - app/views/layouts/data_pact/application.html.erb
57
59
  - config/routes.rb