super 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -13
  3. data/app/assets/javascripts/super/application.js +10970 -64
  4. data/app/assets/stylesheets/super/application.css +33270 -14020
  5. data/app/controllers/super/application_controller.rb +1 -0
  6. data/app/views/super/application/_form.html.erb +1 -2
  7. data/app/views/super/application/_form_field__destroy.html.erb +5 -0
  8. data/app/views/super/application/{_form_generic_select.html.erb → _form_field_select.html.erb} +3 -5
  9. data/app/views/super/application/{_form_generic_text.html.erb → _form_field_text.html.erb} +1 -3
  10. data/app/views/super/application/_form_fieldset.html.erb +8 -0
  11. data/app/views/super/application/_form_has_many.html.erb +21 -0
  12. data/app/views/super/application/_form_has_one.html.erb +11 -0
  13. data/app/views/super/application/_form_inline_errors.html.erb +10 -0
  14. data/frontend/super-frontend/build.js +3 -1
  15. data/frontend/super-frontend/dist/application.css +33270 -14020
  16. data/frontend/super-frontend/dist/application.js +10970 -64
  17. data/frontend/super-frontend/package.json +5 -2
  18. data/frontend/super-frontend/src/javascripts/super/{application.js → application.ts} +3 -1
  19. data/frontend/super-frontend/src/javascripts/super/nested_attributes_controller.ts +33 -0
  20. data/frontend/super-frontend/src/javascripts/super/rails__ujs.d.ts +1 -0
  21. data/frontend/super-frontend/tsconfig.json +13 -0
  22. data/frontend/super-frontend/yarn.lock +1559 -1523
  23. data/lib/super/action_inquirer.rb +13 -0
  24. data/lib/super/assets.rb +1 -0
  25. data/lib/super/configuration.rb +59 -44
  26. data/lib/super/controls.rb +31 -15
  27. data/lib/super/display/schema_types.rb +15 -16
  28. data/lib/super/engine.rb +1 -0
  29. data/lib/super/error.rb +1 -0
  30. data/lib/super/form/schema_types.rb +89 -21
  31. data/lib/super/navigation/automatic.rb +2 -0
  32. data/lib/super/schema.rb +50 -1
  33. data/lib/super/test_support/copy_app_templates/controllers/favorite_things_controller.rb +50 -0
  34. data/lib/super/test_support/copy_app_templates/{members_controller.rb → controllers/members_controller.rb} +10 -5
  35. data/lib/super/test_support/copy_app_templates/{ships_controller.rb → controllers/ships_controller.rb} +3 -3
  36. data/lib/super/test_support/copy_app_templates/{20190216224956_create_members.rb → migrations/20190216224956_create_members.rb} +0 -0
  37. data/lib/super/test_support/copy_app_templates/{20190803143320_create_ships.rb → migrations/20190803143320_create_ships.rb} +0 -0
  38. data/lib/super/test_support/copy_app_templates/{20190806014121_add_ship_to_members.rb → migrations/20190806014121_add_ship_to_members.rb} +0 -0
  39. data/lib/super/test_support/copy_app_templates/migrations/20191126050453_create_favorite_things.rb +10 -0
  40. data/lib/super/test_support/copy_app_templates/models/favorite_thing.rb +7 -0
  41. data/lib/super/test_support/copy_app_templates/{member.rb → models/member.rb} +7 -0
  42. data/lib/super/test_support/copy_app_templates/{ship.rb → models/ship.rb} +0 -0
  43. data/lib/super/test_support/copy_app_templates/routes.rb +1 -0
  44. data/lib/super/test_support/fixtures/favorite_things.yml +9 -0
  45. data/lib/super/test_support/generate_copy_app.rb +5 -16
  46. data/lib/super/test_support/generate_dummy.rb +0 -1
  47. data/lib/super/test_support/starfleet_seeder.rb +1 -0
  48. data/lib/super/version.rb +1 -1
  49. metadata +25 -14
  50. data/app/views/super/application/_form_field.html.erb +0 -7
@@ -0,0 +1,50 @@
1
+ module Admin
2
+ class FavoriteThingsController < AdminController
3
+ private
4
+
5
+ def new_controls
6
+ Controls.new
7
+ end
8
+
9
+ class Controls
10
+ def title
11
+ FavoriteThing.name.pluralize
12
+ end
13
+
14
+ def model
15
+ FavoriteThing
16
+ end
17
+
18
+ def scope(action:)
19
+ FavoriteThing.all
20
+ end
21
+
22
+ def permitted_params(params, action:)
23
+ params.require(:favorite_thing).permit(:name, member_attributes: [:id, :name, :rank, :position, :ship_id])
24
+ end
25
+
26
+ def display_schema(action:)
27
+ Super::Schema.new(Super::Display::SchemaTypes.new) do |fields, type|
28
+ fields[:name] = type.dynamic(&:itself)
29
+ fields[:member] = type.dynamic { |member| "#{member.name} (member ##{member.id})" }
30
+ end
31
+ end
32
+
33
+ def form_schema(action:)
34
+ Super::Schema.new(Super::Form::SchemaTypes.new) do |fields, type|
35
+ fields[:name] = type.generic("form_field_text")
36
+
37
+ fields[:member_attributes] = type.belongs_to(:member) do
38
+ fields[:name] = type.generic("form_field_text")
39
+ fields[:rank] = type.generic("form_field_select", collection: Member.ranks.keys)
40
+ fields[:position] = type.generic("form_field_text")
41
+ fields[:ship_id] = type.generic(
42
+ "form_field_select",
43
+ collection: Ship.all.map { |s| ["#{s.name} (Ship ##{s.id})", s.id] },
44
+ )
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -20,7 +20,7 @@ module Admin
20
20
  end
21
21
 
22
22
  def permitted_params(params, action:)
23
- params.require(:member).permit(:name, :rank, :position, :ship_id)
23
+ params.require(:member).permit(:name, :rank, :position, :ship_id, favorite_things_attributes: [:id, :name, :_destroy])
24
24
  end
25
25
 
26
26
  def display_schema(action:)
@@ -38,13 +38,18 @@ module Admin
38
38
 
39
39
  def form_schema(action:)
40
40
  Super::Schema.new(Super::Form::SchemaTypes.new) do |fields, type|
41
- fields[:name] = type.generic("form_generic_text")
42
- fields[:rank] = type.generic("form_generic_select", collection: Member.ranks.keys)
43
- fields[:position] = type.generic("form_generic_text")
41
+ fields[:name] = type.generic("form_field_text")
42
+ fields[:rank] = type.generic("form_field_select", collection: Member.ranks.keys)
43
+ fields[:position] = type.generic("form_field_text")
44
44
  fields[:ship_id] = type.generic(
45
- "form_generic_select",
45
+ "form_field_select",
46
46
  collection: Ship.all.map { |s| ["#{s.name} (Ship ##{s.id})", s.id] },
47
47
  )
48
+
49
+ fields[:favorite_things_attributes] = type.has_many(:favorite_things) do
50
+ fields[:name] = type.generic("form_field_text")
51
+ fields[:_destroy] = type._destroy
52
+ end
48
53
  end
49
54
  end
50
55
  end
@@ -37,9 +37,9 @@ module Admin
37
37
 
38
38
  def form_schema(action:)
39
39
  Super::Schema.new(Super::Form::SchemaTypes.new) do |fields, type|
40
- fields[:name] = type.generic("form_generic_text")
41
- fields[:registry] = type.generic("form_generic_text")
42
- fields[:class_name] = type.generic("form_generic_text")
40
+ fields[:name] = type.generic("form_field_text")
41
+ fields[:registry] = type.generic("form_field_text")
42
+ fields[:class_name] = type.generic("form_field_text")
43
43
  end
44
44
  end
45
45
  end
@@ -0,0 +1,10 @@
1
+ class CreateFavoriteThings < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :favorite_things do |t|
4
+ t.references :member, null: false, foreign_key: true
5
+ t.text :name
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ class FavoriteThing < ApplicationRecord
2
+ belongs_to :member
3
+
4
+ validates :name, presence: true
5
+
6
+ accepts_nested_attributes_for :member
7
+ end
@@ -10,6 +10,13 @@ class Member < ApplicationRecord
10
10
  }
11
11
 
12
12
  belongs_to :ship
13
+ has_many :favorite_things, dependent: :delete_all
14
+
15
+ accepts_nested_attributes_for(
16
+ :favorite_things,
17
+ allow_destroy: true,
18
+ reject_if: -> (record) { record[:name].blank? }
19
+ )
13
20
 
14
21
  validates :name, presence: true
15
22
  validates :rank, presence: true
@@ -2,6 +2,7 @@ Rails.application.routes.draw do
2
2
  namespace :admin do
3
3
  resources :members
4
4
  resources :ships
5
+ resources :favorite_things
5
6
 
6
7
  root to: redirect("admin/members", status: 302)
7
8
  end
@@ -0,0 +1,9 @@
1
+ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ tea:
4
+ member: picard
5
+ name: Tea, earl grey, hot
6
+
7
+ spot:
8
+ member: data
9
+ name: Spot
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "rails/generators"
4
+ require_relative "../../generators/super/install/install_generator"
4
5
 
5
6
  class SuperCopyAppGenerator < Rails::Generators::Base
6
7
  source_root(File.expand_path("copy_app_templates", __dir__))
@@ -19,28 +20,16 @@ class SuperCopyAppGenerator < Rails::Generators::Base
19
20
  end
20
21
 
21
22
  def install_super
22
- Rails::Generators.invoke("super:install", [], destination_root: destination_root)
23
+ Super::InstallGenerator.start([], destination_root: destination_root)
23
24
  end
24
25
 
25
26
  def copy_app
26
- copy_file "member.rb", "app/models/member.rb"
27
- copy_file "ship.rb", "app/models/ship.rb"
28
-
29
- copy_file "ships_controller.rb", "app/controllers/admin/ships_controller.rb"
30
- copy_file "members_controller.rb", "app/controllers/admin/members_controller.rb"
27
+ directory "models", "app/models"
28
+ directory "controllers", "app/controllers/admin"
31
29
  end
32
30
 
33
31
  def copy_db
34
- migrations = [
35
- "20190216224956_create_members.rb",
36
- "20190803143320_create_ships.rb",
37
- "20190806014121_add_ship_to_members.rb",
38
- ]
39
-
40
- migrations.each do |migration|
41
- copy_file migration, "db/migrate/#{migration}"
42
- end
43
-
32
+ directory "migrations", "db/migrate"
44
33
  copy_file "seeds.rb", "db/seeds.rb"
45
34
  end
46
35
 
@@ -67,7 +67,6 @@ class SuperDummyGenerator < Rails::Generators::Base
67
67
  remove_file("app/channels/")
68
68
  remove_file("public/apple-touch-icon-precomposed.png")
69
69
  remove_file("public/apple-touch-icon.png")
70
- remove_file("public/favicon.ico")
71
70
  end
72
71
  end
73
72
 
@@ -3,6 +3,7 @@ class StarfleetSeeder
3
3
  seeder = StarfleetSeeder.new
4
4
  seeder.seed_from_fixture("ships", Ship)
5
5
  seeder.seed_from_fixture("members", Member)
6
+ seeder.seed_from_fixture("favorite_things", FavoriteThing)
6
7
  end
7
8
 
8
9
  def initialize
data/lib/super/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Super
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Ahn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-24 00:00:00.000000000 Z
11
+ date: 2020-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -139,9 +139,13 @@ files:
139
139
  - app/views/layouts/super/application.html.erb
140
140
  - app/views/super/application/_flash.html.erb
141
141
  - app/views/super/application/_form.html.erb
142
- - app/views/super/application/_form_field.html.erb
143
- - app/views/super/application/_form_generic_select.html.erb
144
- - app/views/super/application/_form_generic_text.html.erb
142
+ - app/views/super/application/_form_field__destroy.html.erb
143
+ - app/views/super/application/_form_field_select.html.erb
144
+ - app/views/super/application/_form_field_text.html.erb
145
+ - app/views/super/application/_form_fieldset.html.erb
146
+ - app/views/super/application/_form_has_many.html.erb
147
+ - app/views/super/application/_form_has_one.html.erb
148
+ - app/views/super/application/_form_inline_errors.html.erb
145
149
  - app/views/super/application/_index.html.erb
146
150
  - app/views/super/application/_show.html.erb
147
151
  - app/views/super/application/edit.html.erb
@@ -157,9 +161,12 @@ files:
157
161
  - frontend/super-frontend/dist/application.js
158
162
  - frontend/super-frontend/package.json
159
163
  - frontend/super-frontend/postcss.config.js
160
- - frontend/super-frontend/src/javascripts/super/application.js
164
+ - frontend/super-frontend/src/javascripts/super/application.ts
165
+ - frontend/super-frontend/src/javascripts/super/nested_attributes_controller.ts
166
+ - frontend/super-frontend/src/javascripts/super/rails__ujs.d.ts
161
167
  - frontend/super-frontend/src/stylesheets/super/application.css
162
168
  - frontend/super-frontend/tailwind.config.js
169
+ - frontend/super-frontend/tsconfig.json
163
170
  - frontend/super-frontend/yarn.lock
164
171
  - lib/generators/super/install/USAGE
165
172
  - lib/generators/super/install/install_generator.rb
@@ -186,15 +193,19 @@ files:
186
193
  - lib/super/pagination.rb
187
194
  - lib/super/plugin.rb
188
195
  - lib/super/schema.rb
189
- - lib/super/test_support/copy_app_templates/20190216224956_create_members.rb
190
- - lib/super/test_support/copy_app_templates/20190803143320_create_ships.rb
191
- - lib/super/test_support/copy_app_templates/20190806014121_add_ship_to_members.rb
192
- - lib/super/test_support/copy_app_templates/member.rb
193
- - lib/super/test_support/copy_app_templates/members_controller.rb
196
+ - lib/super/test_support/copy_app_templates/controllers/favorite_things_controller.rb
197
+ - lib/super/test_support/copy_app_templates/controllers/members_controller.rb
198
+ - lib/super/test_support/copy_app_templates/controllers/ships_controller.rb
199
+ - lib/super/test_support/copy_app_templates/migrations/20190216224956_create_members.rb
200
+ - lib/super/test_support/copy_app_templates/migrations/20190803143320_create_ships.rb
201
+ - lib/super/test_support/copy_app_templates/migrations/20190806014121_add_ship_to_members.rb
202
+ - lib/super/test_support/copy_app_templates/migrations/20191126050453_create_favorite_things.rb
203
+ - lib/super/test_support/copy_app_templates/models/favorite_thing.rb
204
+ - lib/super/test_support/copy_app_templates/models/member.rb
205
+ - lib/super/test_support/copy_app_templates/models/ship.rb
194
206
  - lib/super/test_support/copy_app_templates/routes.rb
195
207
  - lib/super/test_support/copy_app_templates/seeds.rb
196
- - lib/super/test_support/copy_app_templates/ship.rb
197
- - lib/super/test_support/copy_app_templates/ships_controller.rb
208
+ - lib/super/test_support/fixtures/favorite_things.yml
198
209
  - lib/super/test_support/fixtures/members.yml
199
210
  - lib/super/test_support/fixtures/ships.yml
200
211
  - lib/super/test_support/generate_copy_app.rb
@@ -225,5 +236,5 @@ requirements: []
225
236
  rubygems_version: 3.0.3
226
237
  signing_key:
227
238
  specification_version: 4
228
- summary: A simple, powerful, single dependency Rails admin framework
239
+ summary: A simple, powerful, zero* dependency Rails admin framework
229
240
  test_files: []
@@ -1,7 +0,0 @@
1
- <div class="lg:w-1/3">
2
- <%= f.label column %>
3
- <%= f.text_field column, class: "appearance-none border rounded w-full py-2 px-2 text-gray-900 leading-tight border border-gray-400 focus:border-blue-400 mt-2" %>
4
- <% resource.errors.full_messages_for(column).each do |error_message| %>
5
- <p class="text-red-400 text-xs italic pt-1"><%= error_message %></p>
6
- <% end %>
7
- </div>