super 0.0.14 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/app/assets/javascripts/super/application.js +148 -15
  4. data/app/assets/stylesheets/super/application.css +15 -22
  5. data/app/controllers/super/application_controller.rb +44 -42
  6. data/app/controllers/super/substructure_controller.rb +313 -0
  7. data/app/helpers/super/form_builder_helper.rb +7 -0
  8. data/app/views/layouts/super/application.html.erb +3 -21
  9. data/app/views/super/application/_collection_header.html.erb +2 -2
  10. data/app/views/super/application/_display_actions.html.erb +1 -1
  11. data/app/views/super/application/_display_index.html.erb +2 -2
  12. data/app/views/super/application/_display_show.html.erb +1 -1
  13. data/app/views/super/application/_filter.html.erb +62 -2
  14. data/app/views/super/application/_form_field.html.erb +5 -0
  15. data/app/views/super/application/_member_header.html.erb +2 -2
  16. data/app/views/super/application/_pagination.html.erb +1 -1
  17. data/app/views/super/application/_site_footer.html.erb +3 -0
  18. data/app/views/super/application/_site_header.html.erb +17 -0
  19. data/app/views/super/application/_sort_expression.html.erb +2 -2
  20. data/app/views/super/application/index.csv.erb +14 -0
  21. data/app/views/super/feather/README.md +0 -1
  22. data/frontend/super-frontend/dist/application.css +15 -22
  23. data/frontend/super-frontend/dist/application.js +148 -15
  24. data/lib/generators/super/install/install_generator.rb +0 -16
  25. data/lib/generators/super/install/templates/base_controller.rb.tt +0 -8
  26. data/lib/generators/super/resource/templates/resources_controller.rb.tt +4 -4
  27. data/lib/super/action_inquirer.rb +18 -3
  28. data/lib/super/badge.rb +60 -0
  29. data/lib/super/cheat.rb +6 -6
  30. data/lib/super/display/guesser.rb +1 -1
  31. data/lib/super/display/schema_types.rb +49 -1
  32. data/lib/super/display.rb +2 -1
  33. data/lib/super/error.rb +3 -0
  34. data/lib/super/filter/form_object.rb +74 -48
  35. data/lib/super/filter/guesser.rb +2 -0
  36. data/lib/super/filter/operator.rb +90 -64
  37. data/lib/super/filter/schema_types.rb +63 -80
  38. data/lib/super/filter.rb +1 -1
  39. data/lib/super/form/builder.rb +30 -39
  40. data/lib/super/form/field_transcript.rb +43 -0
  41. data/lib/super/form/guesser.rb +4 -4
  42. data/lib/super/form/schema_types.rb +66 -22
  43. data/lib/super/link.rb +2 -2
  44. data/lib/super/pagination.rb +2 -44
  45. data/lib/super/reset.rb +25 -0
  46. data/lib/super/schema.rb +4 -0
  47. data/lib/super/useful/builder.rb +4 -4
  48. data/lib/super/version.rb +1 -1
  49. data/lib/super.rb +3 -1
  50. data/lib/tasks/super/cheat.rake +1 -1
  51. metadata +25 -19
  52. data/app/views/super/application/_filter_type_select.html.erb +0 -21
  53. data/app/views/super/application/_filter_type_text.html.erb +0 -18
  54. data/app/views/super/application/_filter_type_timestamp.html.erb +0 -24
  55. data/app/views/super/application/_form_field_checkbox.html.erb +0 -1
  56. data/app/views/super/application/_form_field_flatpickr_date.html.erb +0 -8
  57. data/app/views/super/application/_form_field_flatpickr_datetime.html.erb +0 -8
  58. data/app/views/super/application/_form_field_flatpickr_time.html.erb +0 -8
  59. data/app/views/super/application/_form_field_rich_text_area.html.erb +0 -1
  60. data/app/views/super/application/_form_field_select.html.erb +0 -1
  61. data/app/views/super/application/_form_field_text.html.erb +0 -1
  62. data/app/views/super/feather/_chevron_down.html +0 -1
  63. data/docs/cheat.md +0 -41
  64. data/lib/super/controls/optional.rb +0 -113
  65. data/lib/super/controls/steps.rb +0 -106
  66. data/lib/super/controls/view.rb +0 -55
  67. data/lib/super/controls.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcc7c1db8a9e8c3a88b6fae8284f086f7e6ec66eb1190ce0164fa7252b4e2719
4
- data.tar.gz: e5f9ab4bb05db043f3872a64c9766183518ff4d065568bdfb9bb31bf88c43359
3
+ metadata.gz: 7f2150ed8df48ecbdc8c2e2cdc9a7e4661d5b101f3bd179fe8d6cf539dec2307
4
+ data.tar.gz: a5377bf3a75715dd13e014ba47c5eb1d14e7c24f9dfeb0aae7e29683c6a13e7d
5
5
  SHA512:
6
- metadata.gz: e1b0ec9d2fb309afbc2bc1ee7dc866e1f1f7515005f58d448cd3ee004170cd25a95029f94a17ae1decfb88459fa17d20cea9ca671a059922c5ccf6a53e399039
7
- data.tar.gz: d96daea67a5bc024749a5523ee66375aef9760ff40bf3be8eaf53b4c526f85d94df9ceff529f58526102eb8d3d3e0c4cf4c97433414ebb7f88a3dda8bd468a68
6
+ metadata.gz: 92d351640382343c76fe914a4fac0838445bf1f7d1d00884f3f20d897131d280dac0f8a6a4d66ad2bde5ee6d801a9362fc8364eb8f99dad46621f9e640bf3ada
7
+ data.tar.gz: 1027b4d5e7ebd58189f1e8aec89b93578d36a71dadfcae7a04bb59a45129ac1967b7a800876a3ef659fb2777b2490cb52e3eb2f2a391510ad06e5da12ade6e23
data/README.md CHANGED
@@ -14,8 +14,8 @@ application. It does this by having zero dependencies—this lets you update you
14
14
  app's dependencies without worrying about breaking your admin pages, and vice
15
15
  versa, update your admin pages without breaking your app.
16
16
 
17
- Note: There may be lots of breaking changes since Super is still fairly young.
18
- See the [stability doc](./STABILITY.md) for an idea of what might be changed.
17
+ Note: Super is under active development and will likely have a few more breaking
18
+ changes before 1.0.
19
19
 
20
20
 
21
21
  ## Features
@@ -237,7 +237,7 @@ var Super = (function (exports) {
237
237
 
238
238
  /*
239
239
  Unobtrusive JavaScript
240
- https://github.com/rails/rails/blob/master/actionview/app/assets/javascripts
240
+ https://github.com/rails/rails/blob/main/actionview/app/assets/javascripts
241
241
  Released under the MIT license
242
242
  */
243
243
  createCommonjsModule(function (module) {
@@ -413,7 +413,7 @@ var Super = (function (exports) {
413
413
  }).call(this);
414
414
  (function () {
415
415
  var AcceptHeaders, CSRFProtection, createXHR, cspNonce, prepareOptions, processResponse;
416
- cspNonce = Rails.cspNonce, CSRFProtection = Rails.CSRFProtection, Rails.fire;
416
+ cspNonce = Rails.cspNonce, CSRFProtection = Rails.CSRFProtection;
417
417
  AcceptHeaders = {
418
418
  '*': '*/*',
419
419
  text: 'text/plain',
@@ -489,9 +489,9 @@ var Super = (function (exports) {
489
489
 
490
490
  if (!options.crossDomain) {
491
491
  xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
492
+ CSRFProtection(xhr);
492
493
  }
493
494
 
494
- CSRFProtection(xhr);
495
495
  xhr.withCredentials = !!options.withCredentials;
496
496
 
497
497
  xhr.onreadystatechange = function () {
@@ -3975,7 +3975,7 @@ var Super = (function (exports) {
3975
3975
  };
3976
3976
  }
3977
3977
 
3978
- var _default$6 = /*#__PURE__*/function (_Controller) {
3978
+ var _default$8 = /*#__PURE__*/function (_Controller) {
3979
3979
  _inherits(_default, _Controller);
3980
3980
 
3981
3981
  var _super = _createSuper(_default);
@@ -4004,7 +4004,7 @@ var Super = (function (exports) {
4004
4004
  return _default;
4005
4005
  }(Controller);
4006
4006
 
4007
- var _default$5 = /*#__PURE__*/function (_Controller) {
4007
+ var _default$7 = /*#__PURE__*/function (_Controller) {
4008
4008
  _inherits(_default, _Controller);
4009
4009
 
4010
4010
  var _super = _createSuper(_default);
@@ -4040,7 +4040,7 @@ var Super = (function (exports) {
4040
4040
  return _default;
4041
4041
  }(Controller);
4042
4042
 
4043
- var _default$4 = /*#__PURE__*/function (_Controller) {
4043
+ var _default$6 = /*#__PURE__*/function (_Controller) {
4044
4044
  _inherits(_default, _Controller);
4045
4045
 
4046
4046
  var _super = _createSuper(_default);
@@ -4064,7 +4064,7 @@ var Super = (function (exports) {
4064
4064
  return _default;
4065
4065
  }(Controller);
4066
4066
 
4067
- var _default$3 = /*#__PURE__*/function (_Controller) {
4067
+ var _default$5 = /*#__PURE__*/function (_Controller) {
4068
4068
  _inherits(_default, _Controller);
4069
4069
 
4070
4070
  var _super = _createSuper(_default);
@@ -4094,7 +4094,7 @@ var Super = (function (exports) {
4094
4094
  return _default;
4095
4095
  }(Controller);
4096
4096
 
4097
- var _default$2 = /*#__PURE__*/function (_Controller) {
4097
+ var _default$4 = /*#__PURE__*/function (_Controller) {
4098
4098
  _inherits(_default, _Controller);
4099
4099
 
4100
4100
  var _super = _createSuper(_default);
@@ -6354,7 +6354,7 @@ var Super = (function (exports) {
6354
6354
  window.flatpickr = flatpickr;
6355
6355
  }
6356
6356
 
6357
- var _default$1 = /*#__PURE__*/function (_Controller) {
6357
+ var _default$3 = /*#__PURE__*/function (_Controller) {
6358
6358
  _inherits(_default, _Controller);
6359
6359
 
6360
6360
  var _super = _createSuper(_default);
@@ -6382,6 +6382,137 @@ var Super = (function (exports) {
6382
6382
  return _default;
6383
6383
  }(Controller);
6384
6384
 
6385
+ var _default$2 = /*#__PURE__*/function (_Controller) {
6386
+ _inherits(_default, _Controller);
6387
+
6388
+ var _super = _createSuper(_default);
6389
+
6390
+ function _default() {
6391
+ _classCallCheck(this, _default);
6392
+
6393
+ return _super.apply(this, arguments);
6394
+ }
6395
+
6396
+ _createClass(_default, [{
6397
+ key: "connect",
6398
+ value: function connect() {
6399
+ var _this = this;
6400
+
6401
+ this.tabTargets.forEach(function (tab) {
6402
+ tab.tabContainer = _this;
6403
+ });
6404
+ }
6405
+ }, {
6406
+ key: "activeTabIdentifier",
6407
+ get: function get() {
6408
+ return this.controlTarget.value;
6409
+ }
6410
+ }, {
6411
+ key: "change",
6412
+ value: function change(event) {
6413
+ this.update(event.target.value);
6414
+ }
6415
+ }, {
6416
+ key: "update",
6417
+ value: function update(newActiveTabIdentifier) {
6418
+ var _this2 = this;
6419
+
6420
+ this.tabTargets.forEach(function (tab) {
6421
+ var tabController = _this2.application.getControllerForElementAndIdentifier(tab, _this2.tabControllerNameValue);
6422
+
6423
+ if (tab.dataset[_this2.tabIdentifierGetterValue] == newActiveTabIdentifier) {
6424
+ tabController.show();
6425
+ } else {
6426
+ tabController.hide();
6427
+ }
6428
+ });
6429
+ }
6430
+ }], [{
6431
+ key: "targets",
6432
+ get: function get() {
6433
+ return ["control", "tab"];
6434
+ }
6435
+ }, {
6436
+ key: "values",
6437
+ get: function get() {
6438
+ return {
6439
+ tabIdentifierGetter: String,
6440
+ tabControllerName: String
6441
+ };
6442
+ }
6443
+ }]);
6444
+
6445
+ return _default;
6446
+ }(Controller);
6447
+
6448
+ var _default$1 = /*#__PURE__*/function (_Controller) {
6449
+ _inherits(_default, _Controller);
6450
+
6451
+ var _super = _createSuper(_default);
6452
+
6453
+ function _default() {
6454
+ _classCallCheck(this, _default);
6455
+
6456
+ return _super.apply(this, arguments);
6457
+ }
6458
+
6459
+ _createClass(_default, [{
6460
+ key: "connect",
6461
+ value: function connect() {
6462
+ var tabContainer = this.element[this.tabContainerGetterValue];
6463
+
6464
+ if (tabContainer.activeTabIdentifier === this.identifierValue) {
6465
+ this.show();
6466
+ } else {
6467
+ this.hide();
6468
+ }
6469
+ }
6470
+ }, {
6471
+ key: "toggle",
6472
+ value: function toggle() {
6473
+ if (this.hasContentTarget) {
6474
+ this.hide();
6475
+ } else {
6476
+ this.show();
6477
+ }
6478
+ }
6479
+ }, {
6480
+ key: "show",
6481
+ value: function show() {
6482
+ if (this.hasContentTarget) {
6483
+ return;
6484
+ }
6485
+
6486
+ var pocketContent = this.pocketTarget.content.cloneNode(true);
6487
+ this.element.appendChild(pocketContent);
6488
+ }
6489
+ }, {
6490
+ key: "hide",
6491
+ value: function hide() {
6492
+ if (!this.hasContentTarget) {
6493
+ return;
6494
+ }
6495
+
6496
+ this.contentTarget.remove();
6497
+ }
6498
+ }], [{
6499
+ key: "targets",
6500
+ get: function get() {
6501
+ return ["pocket", "content"];
6502
+ }
6503
+ }, {
6504
+ key: "values",
6505
+ get: function get() {
6506
+ return {
6507
+ identifier: String,
6508
+ tabContainerGetter: String
6509
+ };
6510
+ }
6511
+ }]);
6512
+
6513
+ return _default;
6514
+ }(Controller);
6515
+
6385
6516
  var _default = /*#__PURE__*/function (_Controller) {
6386
6517
  _inherits(_default, _Controller);
6387
6518
 
@@ -6412,12 +6543,14 @@ var Super = (function (exports) {
6412
6543
  }(Controller);
6413
6544
 
6414
6545
  var StimulusApplication = Application.start();
6415
- StimulusApplication.register("apply-template", _default$6);
6416
- StimulusApplication.register("clean-filter-param", _default$5);
6417
- StimulusApplication.register("clean-filter-params", _default$4);
6418
- StimulusApplication.register("click-outside-to-close", _default$3);
6419
- StimulusApplication.register("delete", _default$2);
6420
- StimulusApplication.register("flatpickr", _default$1);
6546
+ StimulusApplication.register("apply-template", _default$8);
6547
+ StimulusApplication.register("clean-filter-param", _default$7);
6548
+ StimulusApplication.register("clean-filter-params", _default$6);
6549
+ StimulusApplication.register("click-outside-to-close", _default$5);
6550
+ StimulusApplication.register("delete", _default$4);
6551
+ StimulusApplication.register("flatpickr", _default$3);
6552
+ StimulusApplication.register("tab-container", _default$2);
6553
+ StimulusApplication.register("tab", _default$1);
6421
6554
  StimulusApplication.register("toggle-pending-destruction", _default);
6422
6555
 
6423
6556
  exports.StimulusApplication = StimulusApplication;
@@ -1,6 +1,6 @@
1
- /*! tailwindcss v2.1.1 | MIT License | https://tailwindcss.com */
1
+ /*! tailwindcss v2.1.2 | MIT License | https://tailwindcss.com */
2
2
 
3
- /*! modern-normalize v1.0.0 | MIT License | https://github.com/sindresorhus/modern-normalize */
3
+ /*! modern-normalize v1.1.0 | MIT License | https://github.com/sindresorhus/modern-normalize */
4
4
 
5
5
  /*
6
6
  Document
@@ -12,8 +12,8 @@ Use a better box model (opinionated).
12
12
  */
13
13
 
14
14
  *,
15
- *::before,
16
- *::after {
15
+ ::before,
16
+ ::after {
17
17
  box-sizing: border-box;
18
18
  }
19
19
 
@@ -21,7 +21,7 @@ Use a better box model (opinionated).
21
21
  Use a more readable tab size (opinionated).
22
22
  */
23
23
 
24
- :root {
24
+ html {
25
25
  -moz-tab-size: 4;
26
26
  -o-tab-size: 4;
27
27
  tab-size: 4;
@@ -1475,28 +1475,21 @@ span.flatpickr-day.selected {
1475
1475
  .super-input:focus {
1476
1476
  --tw-border-opacity: 1;
1477
1477
  border-color: rgba(99, 179, 237, var(--tw-border-opacity));
1478
+ outline: 2px solid transparent;
1479
+ outline-offset: 2px;
1478
1480
  }
1479
1481
 
1480
- .super-input-select {
1481
- position: relative;
1482
+ .super-input:disabled {
1483
+ opacity: 0.5;
1484
+ --tw-bg-opacity: 1;
1485
+ background-color: rgba(247, 250, 252, var(--tw-bg-opacity));
1482
1486
  }
1483
1487
 
1484
- .super-input-select-field {
1488
+ .super-input-select {
1485
1489
  padding-right: 2rem;
1486
- width: 100%;
1487
- }
1488
-
1489
- .super-input-select-icon {
1490
- pointer-events: none;
1491
- position: absolute;
1492
- top: 0px;
1493
- bottom: 0px;
1494
- right: 0px;
1495
- display: flex;
1496
- align-items: center;
1497
- padding-left: 0.5rem;
1498
- padding-right: 0.5rem;
1499
- fill: currentColor;
1490
+ background-repeat: no-repeat;
1491
+ background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%232b6cb0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E %3Cpolyline points='6 9 12 15 18 9'/%3E %3C/svg%3E");
1492
+ background-position: right 0.5rem center;
1500
1493
  }
1501
1494
 
1502
1495
  .super-button {
@@ -2,76 +2,78 @@
2
2
 
3
3
  module Super
4
4
  # Provides a default implementation for each of the resourceful actions
5
- class ApplicationController < ActionController::Base
5
+ class ApplicationController < SubstructureController
6
6
  include ClientError::Handling
7
7
 
8
- helper_method :action_inquirer
9
- helper_method :controls
10
- helper_method :navigation
8
+ helper_method :current_action
11
9
 
12
10
  # Displays a list of records to the user
13
11
  def index
14
- @records = controls.load_records(action: action_inquirer, params: params)
15
- @display = controls.display_schema(action: action_inquirer).apply(action: action_inquirer)
16
- @view = controls.index_view
17
- @query_form = controls.initialize_query_form(params: params, current_path: request.path)
18
- controls.initialize_filter_form(query_form: @query_form)
19
- controls.initialize_sort_form(query_form: @query_form)
20
- @records = controls.apply_queries(query_form: @query_form, records: @records)
12
+ @records = load_records
13
+ @display = display_schema.apply(action: current_action, format: request.format)
14
+ @view = index_view
15
+ @query_form = initialize_query_form
16
+ initialize_filter_form
17
+ initialize_sort_form
18
+ @records = apply_queries
21
19
  end
22
20
 
23
21
  # Displays a specific record to the user
24
22
  def show
25
- @record = controls.load_record(action: action_inquirer, params: params)
26
- @display = controls.display_schema(action: action_inquirer).apply(action: action_inquirer)
27
- @view = controls.show_view
23
+ @record = load_record
24
+ @display = display_schema.apply(action: current_action, format: request.format)
25
+ @view = show_view
28
26
  end
29
27
 
30
28
  # Displays a form to allow the user to create a new record
31
29
  def new
32
- @record = controls.build_record(action: action_inquirer)
33
- @form = controls.form_schema(action: action_inquirer)
34
- @view = controls.new_view
30
+ @record = build_record
31
+ @form = form_schema
32
+ @view = new_view
35
33
  end
36
34
 
37
35
  # Creates a record, or shows the validation errors
38
36
  def create
39
- @record = controls.build_record_with_params(action: action_inquirer, params: params)
37
+ @record = build_record
38
+ set_record_attributes
40
39
 
41
- if controls.save_record(action: action_inquirer, record: @record, params: params)
40
+ if save_record
42
41
  redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
43
42
  else
44
- @form = controls.form_schema(action: action_inquirer_for("new"))
45
- @view = controls.new_view
43
+ @current_action = ActionInquirer.new!
44
+ @form = form_schema
45
+ @view = new_view
46
46
  render :new, status: :bad_request
47
47
  end
48
48
  end
49
49
 
50
50
  # Displays a form to allow the user to update an existing record
51
51
  def edit
52
- @record = controls.load_record(action: action_inquirer, params: params)
53
- @form = controls.form_schema(action: action_inquirer)
54
- @view = controls.edit_view
52
+ @record = load_record
53
+ @form = form_schema
54
+ @view = edit_view
55
55
  end
56
56
 
57
57
  # Updates a record, or shows validation errors
58
58
  def update
59
- @record = controls.load_record(action: action_inquirer, params: params)
59
+ @record = load_record
60
+ set_record_attributes
60
61
 
61
- if controls.update_record(action: action_inquirer, record: @record, params: params)
62
+ if save_record
62
63
  redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
63
64
  else
64
- @form = controls.form_schema(action: action_inquirer_for("edit"))
65
- @view = controls.edit_view
65
+ @current_action = ActionInquirer.edit!
66
+ @form = form_schema
67
+ @view = edit_view
66
68
  render :edit, status: :bad_request
67
69
  end
68
70
  end
69
71
 
70
72
  # Deletes a record, or shows validation errors
71
73
  def destroy
72
- @record = controls.load_record(action: action_inquirer, params: params)
74
+ @record = load_record
73
75
 
74
- if controls.destroy_record(action: action_inquirer, record: @record, params: params)
76
+ if destroy_record
75
77
  redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
76
78
  else
77
79
  flash.alert = "Couldn't delete record"
@@ -84,23 +86,23 @@ module Super
84
86
 
85
87
  private
86
88
 
87
- def controls
88
- @controls ||= new_controls
89
+ def current_action
90
+ @current_action ||=
91
+ ActionInquirer.new(
92
+ ActionInquirer.default_for_resources,
93
+ params[:action]
94
+ )
89
95
  end
90
96
 
91
- def action_inquirer
92
- @action_inquirer ||= action_inquirer_for(params[:action])
93
- end
94
-
95
- def action_inquirer_for(action)
96
- ActionInquirer.new(
97
+ def with_current_action(action)
98
+ original = @current_action
99
+ @current_action = ActionInquirer.new(
97
100
  ActionInquirer.default_for_resources,
98
101
  action
99
102
  )
100
- end
101
-
102
- def navigation
103
- Navigation.new(&:all)
103
+ yield
104
+ ensure
105
+ @current_action = original
104
106
  end
105
107
  end
106
108
  end