motor-admin 0.1.29 → 0.1.35

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: 2f18c5fae6ca2c70b739f68d0a9b45f456b6c9f9592b4c44d216210a067b2e33
4
- data.tar.gz: 4a65316ecce576b9de027fe93ff14bf9307826269af771fbfc9a7bbf3699f051
3
+ metadata.gz: 97e438ff28fa0c1532dc6e732da194852c6be1374040947297093abeb32d5ded
4
+ data.tar.gz: 36fabae905bc320122b67e15d27bc9d34025b5b183822a2fc21420a5395a896c
5
5
  SHA512:
6
- metadata.gz: f51029e47fe84f67f34ced365523f2214c44986f241ad35a77405f067a556bbca8ca124cb09812b007a709101729ae3dfc35aa94284c46dbbf2f63a990459001
7
- data.tar.gz: 555b5570c50258d3ee00a317795868cee3281e0d3675d894e25773f26977d21d40781b031a4e3835469fa580d39b3e1ba5b87f11dcad83986b0bd144f612bc5c
6
+ metadata.gz: c35efea7e04d6fa2d85587508dd1828e4cbe253b8a07c5f1b28f8a7c5112c184af4910dc9b889db55930d48353c60d23fecd10718a61a4a2b1dd07acd58df2f4
7
+ data.tar.gz: 103000ffc82b09b09a48416ea348ecde3537056c330fc26d41f48c2f96be84fddf7f6fd688573d526efcf2e74b64bdde2d45db19de3fc4a3f48e76debef38dc0
@@ -86,6 +86,8 @@ module Motor
86
86
  self,
87
87
  options
88
88
  ).load_and_authorize_resource
89
+ rescue ActiveRecord::RecordNotFound
90
+ head :not_found
89
91
  rescue StandardError => e
90
92
  render json: { errors: [e.message] }, status: :unprocessable_entity
91
93
  end
@@ -107,6 +109,8 @@ module Motor
107
109
  else
108
110
  render json: { message: 'Unknown association' }, status: :not_found
109
111
  end
112
+ rescue ActiveRecord::RecordNotFound
113
+ head :not_found
110
114
  rescue StandardError => e
111
115
  render json: { errors: [e.message] }, status: :unprocessable_entity
112
116
  end
@@ -10,5 +10,13 @@ module Motor
10
10
  serialize :preferences, HashSerializer
11
11
 
12
12
  scope :active, -> { where(deleted_at: nil) }
13
+
14
+ def result(variables_hash = {})
15
+ result = Motor::Queries::RunQuery.call(self, variables_hash: variables_hash)
16
+ column_names = result.columns.pluck(:name)
17
+
18
+ result.data.map { |row| column_names.zip(row).to_h }
19
+ end
20
+ alias run result
13
21
  end
14
22
  end
@@ -77,7 +77,7 @@
77
77
  <% if @query_result.data.length > 1 %>
78
78
  <p style="margin: 7px 0; float: left">Showing <%= @query_result.data.first(40).size %> of <%= @query_result.data.size %> rows</p>
79
79
  <% end %>
80
- <a href="<%= Motor::Admin.routes.url_helpers.motor_ui_query_url(@alert.query, { host: 'localhost:3000'}.merge(Rails.application.config.action_mailer.default_url_options || {})) %>" target="blank" style="margin: 7px 0; float: right">Open query </a>
80
+ <a href="<%= Motor::Admin.routes.url_helpers.motor_ui_query_url(@alert.query, { host: 'localhost:3000' }.merge(Rails.application.config.action_mailer.default_url_options || {})) %>" target="blank" style="margin: 7px 0; float: right">Open query </a>
81
81
  <table class="main" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%; background: #ffffff; border-radius: 3px;">
82
82
  <tr>
83
83
  <td class="wrapper" style="font-family: sans-serif; font-size: 14px; vertical-align: top; box-sizing: border-box; padding: 20px; max-width: 0px; overflow: scroll">
data/config/routes.rb CHANGED
@@ -47,15 +47,4 @@ Motor::Admin.routes.draw do
47
47
  end
48
48
  end
49
49
 
50
- Motor::Api.routes.draw do
51
- namespace :motor, path: '' do
52
- resources :resources, path: '/:resource',
53
- only: %i[index show update create destroy],
54
- controller: 'data' do
55
- put '/:method', to: 'data#execute'
56
- resources :association, path: '/:association',
57
- only: %i[index create],
58
- controller: 'data'
59
- end
60
- end
61
- end
50
+ ActiveSupport::Notifications.instrument('motor.routes.loaded')
@@ -16,6 +16,8 @@ module Motor
16
16
 
17
17
  def copy_migration
18
18
  migration_template 'install.rb', 'db/migrate/install_motor_admin.rb'
19
+
20
+ route "mount Motor::Admin => '/motor_admin'"
19
21
  end
20
22
  end
21
23
  end
data/lib/motor.rb CHANGED
@@ -45,7 +45,6 @@ end
45
45
 
46
46
  require 'motor/version'
47
47
  require 'motor/admin'
48
- require 'motor/api'
49
48
  require 'motor/assets'
50
49
  require 'motor/build_schema'
51
50
  require 'motor/api_query'
data/lib/motor/admin.rb CHANGED
@@ -2,6 +2,32 @@
2
2
 
3
3
  module Motor
4
4
  class Admin < ::Rails::Engine
5
+ initializer 'motor.startup_message' do
6
+ ActiveSupport::Notifications.subscribe('motor.routes.loaded') do
7
+ next unless Motor.server?
8
+
9
+ if Rails.application.routes.url_helpers.respond_to?(:motor_admin_path)
10
+ url =
11
+ begin
12
+ Rails.application.routes.url_helpers.motor_admin_url
13
+ rescue ArgumentError
14
+ Rails.application.routes.url_helpers.motor_admin_path
15
+ end
16
+
17
+ puts
18
+ puts "⚡ Motor::Admin is starting under #{url}"
19
+ else
20
+ puts
21
+ puts '⚠️ Motor::Admin is not mounted.'
22
+ puts 'Add the following line to your config/routes.rb:'
23
+ puts
24
+ puts " mount Motor::Admin => '/admin'"
25
+ end
26
+
27
+ puts
28
+ end
29
+ end
30
+
5
31
  initializer 'motor.filter_params' do
6
32
  Rails.application.config.filter_parameters += %i[io]
7
33
  end
@@ -34,20 +34,29 @@ module Motor
34
34
 
35
35
  def normalize_filter_hash(hash)
36
36
  hash.each_with_object({}) do |(action, value), acc|
37
- acc[action] =
37
+ new_action, new_value =
38
38
  if value.is_a?(Hash)
39
- normalize_filter_hash(value)
39
+ [action, normalize_filter_hash(value)]
40
40
  else
41
- normalize_action_value(action, value)
41
+ normalize_action(action, value)
42
42
  end
43
+
44
+ acc[new_action] = new_value
45
+
46
+ acc
43
47
  end
44
48
  end
45
49
 
46
- def normalize_action_value(action, value)
47
- if %w[like ilike].include?(action)
48
- value.sub(LIKE_FILTER_VALUE_REGEXP, '%\1%')
50
+ def normalize_action(action, value)
51
+ case action
52
+ when 'contains'
53
+ ['ilike', value.sub(LIKE_FILTER_VALUE_REGEXP, '%\1%')]
54
+ when 'starts_with'
55
+ ['ilike', value.sub(LIKE_FILTER_VALUE_REGEXP, '\1%')]
56
+ when 'ends_with'
57
+ ['ilike', value.sub(LIKE_FILTER_VALUE_REGEXP, '%\1')]
49
58
  else
50
- value
59
+ [action, value]
51
60
  end
52
61
  end
53
62
  end
@@ -48,8 +48,8 @@ module Motor
48
48
 
49
49
  DEFAULT_TABS = [
50
50
  {
51
- name: 'summary',
52
- display_name: 'Summary',
51
+ name: 'details',
52
+ display_name: 'Details',
53
53
  tab_type: 'default',
54
54
  preferences: {},
55
55
  visible: true
data/lib/motor/tags.rb CHANGED
@@ -21,7 +21,8 @@ module Motor
21
21
  end
22
22
 
23
23
  def remove_missing_tags(taggable, tags)
24
- tags_to_remove = taggable.tags.reject { |tt| tt.name.downcase.in?(tags) }
24
+ downcase_tags = tags.map(&:downcase)
25
+ tags_to_remove = taggable.tags.reject { |tt| tt.name.downcase.in?(downcase_tags) }
25
26
 
26
27
  taggable.tags -= tags_to_remove
27
28
 
data/lib/motor/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Motor
4
- VERSION = '0.1.29'
4
+ VERSION = '0.1.35'
5
5
  end
@@ -5,9 +5,9 @@
5
5
  "fonts/ionicons.ttf?v=3.0.0-alpha.3": "fonts/ionicons.ttf",
6
6
  "fonts/ionicons.woff2?v=3.0.0-alpha.3": "fonts/ionicons.woff2",
7
7
  "fonts/ionicons.woff?v=3.0.0-alpha.3": "fonts/ionicons.woff",
8
- "main-482137e0bc1ba9f875dc.css.gz": "main-482137e0bc1ba9f875dc.css.gz",
9
- "main-482137e0bc1ba9f875dc.js.LICENSE.txt": "main-482137e0bc1ba9f875dc.js.LICENSE.txt",
10
- "main-482137e0bc1ba9f875dc.js.gz": "main-482137e0bc1ba9f875dc.js.gz",
11
- "main.css": "main-482137e0bc1ba9f875dc.css",
12
- "main.js": "main-482137e0bc1ba9f875dc.js"
8
+ "main-03c3b1d3390877206e02.css.gz": "main-03c3b1d3390877206e02.css.gz",
9
+ "main-03c3b1d3390877206e02.js.LICENSE.txt": "main-03c3b1d3390877206e02.js.LICENSE.txt",
10
+ "main-03c3b1d3390877206e02.js.gz": "main-03c3b1d3390877206e02.js.gz",
11
+ "main.css": "main-03c3b1d3390877206e02.css",
12
+ "main.js": "main-03c3b1d3390877206e02.js"
13
13
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motor-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.29
4
+ version: 0.1.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Matsyburka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-07 00:00:00.000000000 Z
11
+ date: 2021-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-filter
@@ -183,7 +183,6 @@ files:
183
183
  - lib/motor/alerts/persistance.rb
184
184
  - lib/motor/alerts/scheduled_alerts_cache.rb
185
185
  - lib/motor/alerts/scheduler.rb
186
- - lib/motor/api.rb
187
186
  - lib/motor/api_query.rb
188
187
  - lib/motor/api_query/apply_scope.rb
189
188
  - lib/motor/api_query/build_json.rb
@@ -215,8 +214,8 @@ files:
215
214
  - lib/motor/ui_configs.rb
216
215
  - lib/motor/version.rb
217
216
  - ui/dist/fonts/ionicons.woff2
218
- - ui/dist/main-482137e0bc1ba9f875dc.css.gz
219
- - ui/dist/main-482137e0bc1ba9f875dc.js.gz
217
+ - ui/dist/main-03c3b1d3390877206e02.css.gz
218
+ - ui/dist/main-03c3b1d3390877206e02.js.gz
220
219
  - ui/dist/manifest.json
221
220
  homepage:
222
221
  licenses:
data/lib/motor/api.rb DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Motor
4
- class Api < ::Rails::Engine
5
- end
6
- end