maquina 0.2.1 → 0.2.3

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: 253e32217b0c2f5e0a8a352ff4ac26a1e0d904184293205135f1d60fd43392d2
4
- data.tar.gz: a347016c5e76c08fc3165662b47684ff181667a4bea70c25e340bc71e760b1cc
3
+ metadata.gz: b7ab60b2cea0b2831706a45cfc1978c870cd116e8cbffa0b7e1c2571c07f2f00
4
+ data.tar.gz: 1dc50dfe21922c104bcf39dafb4d9c48c56005b8ac699c2539182cb4bc1460ed
5
5
  SHA512:
6
- metadata.gz: 77c5d7eb9e6927194b0ea5635f8a535b898010b755e42e254258e2af675c6c4ba08c70372141056e2fd296008d7a120d938019f5fa55966d3d3314cc61744621
7
- data.tar.gz: 1013008ff3b86923b4d055c894d62e01ba23e84c4cad7d029454d1d8f9e80865ac038be1f5693c39a9828cebec1fc57c0a6591d6b16c4c7d134a83d321ef4acd
6
+ metadata.gz: b6c5e01ae51066b823f75a917cd7241175f339c80e490a1279b1cfc2ff590ee3bbd065eb080e0113ac539e84802b43eb81c60a2cfd56271e94222dc5f94f725d
7
+ data.tar.gz: 40bb78e88253d90fcc01af052e767a8b1d44dfdb05b14c360d099bfa5dd9a134f13b03c04ae8b29bb588407c0cb64ed04963a655f2058edac131ed3987ffb95d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- maquina (0.2.1)
4
+ maquina (0.2.3)
5
5
  action_policy (~> 0.6.3)
6
6
  bcrypt (~> 3.1.7)
7
7
  importmap-rails (~> 1.2.0)
@@ -0,0 +1,10 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+ import { useTransition } from "stimulus-use";
3
+
4
+ export default class extends Controller {
5
+ static targets = ["backdrop"]
6
+
7
+ connect() {
8
+ useTransition(this, { element: this.backdropTarget })
9
+ }
10
+ }
@@ -2,38 +2,92 @@ import { Controller } from "@hotwired/stimulus"
2
2
  import { useTransition } from "stimulus-use"
3
3
 
4
4
  export default class extends Controller {
5
- static targets = ["content", "container", "frame"]
5
+ static targets = ["modal", "container", "frame", "form", "submit"]
6
+ static outlets = ["backdrop"]
6
7
 
7
8
  connect() {
8
- useTransition(this, { element: this.contentTarget })
9
+ this.timeouts = []
10
+ this.root = document.querySelector("html")
9
11
 
10
- this.resultCallback = this.modalResult.bind(this)
11
- addEventListener("turbo:submit-end", this.resultCallback)
12
+ useTransition(this, { element: this.modalTarget })
13
+
14
+ if (this.hasFormTarget) addEventListener("turbo:submit-end", this.submitResult.bind(this))
12
15
  }
13
16
 
14
17
  disconnect() {
15
- removeEventListener("turbo:submit-end", this.resultCallback)
18
+ this.timeouts.forEach(t => clearTimeout(t))
19
+
20
+ if (this.hasFormTarget) removeEventListener("turbo:submit-end", this.submitResult.bind(this))
16
21
  }
17
22
 
18
- modalResult(event) {
19
- if (event.detail.fetchResponse.response.status == 202) {
20
- this.toggleModal(event)
23
+ submitResult(event) {
24
+ if (this.hasFormTarget) this.submitTarget.removeAttribute("disabled")
25
+
26
+ const status = event.detail.fetchResponse.response.status
27
+ if (status == 201 || status == 202) {
28
+ this.close(event)
21
29
  }
22
30
  }
23
31
 
24
- toggleModal(event) {
32
+ submit(event) {
25
33
  event.preventDefault()
26
34
 
27
- if (this.hasFrameTarget && this.contentTarget.classList.contains("hidden")) {
28
- let url = event.target.getAttribute("href") || this.element.dataset["frameSrc"]
29
- this.frameTarget.setAttribute("src", url)
30
- } else if (!this.contentTarget.classList.contains("hidden")) {
31
- this.frameTarget.setAttribute("src", "")
32
- this.frameTarget.innerText = ""
35
+ if (!this.hasFormTarget) {
36
+ return
33
37
  }
34
38
 
35
- document.documentElement.classList.toggle("overflow-hidden")
36
- this.containerTarget.classList.toggle("hidden")
39
+ this.submitTarget.setAttribute("disabled", "true")
40
+ this.formTarget.requestSubmit()
41
+ }
42
+
43
+ open(event) {
44
+ event.preventDefault()
45
+
46
+ this.configureModal(event.target)
47
+ this.root.classList.toggle("overflow-hidden")
48
+
49
+ this.toggleBackdrop()
50
+ this.toggleTransition()
51
+ }
52
+
53
+ close(event) {
54
+ event.preventDefault()
55
+
56
+ this.timeouts.forEach(t => clearTimeout(t))
57
+
58
+ this.root.classList.toggle("overflow-hidden")
37
59
  this.toggleTransition()
60
+ this.toggleBackdrop()
61
+
62
+
63
+ this.timeouts.push(
64
+ setTimeout(() => this.restoreModal(), 500)
65
+ )
66
+ }
67
+
68
+ configureModal(target) {
69
+ if (this.hasSubmitTarget) {
70
+ const label = target.dataset["submit-label"]
71
+ this.submitTarget.innerText = label
72
+ }
73
+
74
+ const url = target.getAttribute("href")
75
+ this.frameTarget.setAttribute("src", url)
76
+
77
+ this.containerTarget.classList.toggle("hidden")
78
+ }
79
+
80
+ restoreModal() {
81
+ this.containerTarget.classList.toggle("hidden")
82
+
83
+ if (this.hasSubmitTarget) {
84
+ this.submitTarget.innerText = ""
85
+ this.submitTarget.removeAttribute("disabled")
86
+ }
87
+ this.frameTarget.setAttribute("src", "")
88
+ }
89
+
90
+ toggleBackdrop() {
91
+ this.backdropOutlets.forEach(backdrop => backdrop.toggleTransition())
38
92
  }
39
93
  }
@@ -5,6 +5,6 @@ export default class extends Controller {
5
5
 
6
6
  open(event) {
7
7
  event.preventDefault()
8
- this.modalOutlets.forEach(modal => modal.toggleModal(event))
8
+ this.modalOutlets.forEach(modal => modal.open(event))
9
9
  }
10
10
  }
@@ -16,6 +16,7 @@ module Maquina
16
16
  end
17
17
 
18
18
  @status = @resource.errors.empty? ? :created : :unprocessable_entity
19
+ Rails.logger.debug "CREATE validation: #{@resource.errors.inspect}" if status == :unprocessable_entity
19
20
  response.status = @status
20
21
  set_flash_message(@status)
21
22
 
@@ -8,10 +8,11 @@ module Maquina
8
8
  def destroy(&block)
9
9
  @resource ||= begin
10
10
  scope = resource_class
11
- # TODO: Implement policy authorization (ActionPolicy)
12
- # scope = scope.where(organization)
13
- # TODO: Implement filtering by organization
11
+ scope = authorized_scope(scope) if policy_class.present?
12
+
14
13
  scope.find_by!(find_by_param => params[:id])
14
+
15
+ authorize! resource, with: policy_class if policy_class.present?
15
16
  end
16
17
 
17
18
  @resource.destroy
@@ -8,8 +8,7 @@ module Maquina
8
8
  def edit(&block)
9
9
  @resource ||= begin
10
10
  scope = resource_class
11
- # TODO: Implement filtering by organization
12
- # scope = scope.where(organization)
11
+ scope = authorized_scope(scope) if policy_class.present?
13
12
  scope = yield(scope) if block.present?
14
13
 
15
14
  resource = scope.find_by!(find_by_param => params[:id])
@@ -14,7 +14,7 @@ module Maquina
14
14
  scope = authorized_scope(scope) if policy_class.present?
15
15
 
16
16
  search_value = params[:q]&.strip
17
- scope = scope.search_full(search_value) if search_value.present?
17
+ scope = scope.search_full(search_value) if search_value.present? && resource_class.searchable?
18
18
 
19
19
  scope = yield(scope) if block.present?
20
20
 
@@ -8,8 +8,8 @@ module Maquina
8
8
  def update(&block)
9
9
  @resource ||= begin
10
10
  scope = resource_class
11
- # scope = scope.where(organization)
12
- # TODO: Implement filtering by organization
11
+ scope = authorized_scope(scope) if policy_class.present?
12
+
13
13
  resource = scope.find_by!(find_by_param => params[:id])
14
14
 
15
15
  authorize! resource, with: policy_class if policy_class.present?
@@ -20,6 +20,7 @@ module Maquina
20
20
  saved = @resource.update(resource_secure_params)
21
21
 
22
22
  status = saved ? :accepted : :unprocessable_entity
23
+ Rails.logger.debug "UPDATE validation: #{@resource.errors.inspect}" if status == :unprocessable_entity
23
24
  response.status = status
24
25
  set_flash_message(status)
25
26
 
@@ -30,7 +30,7 @@ module Maquina
30
30
 
31
31
  div(class: "pt-5") do
32
32
  div(class: "flex justify-end") do
33
- link_to t("helpers.cancel"), collection_path, class: "button", data: @modal ? {action: "modal#toggleModal"} : {turbo_frame: :_top}
33
+ link_to t("helpers.cancel"), collection_path, class: "button", data: @modal ? {action: "modal#close"} : {turbo_frame: :_top}
34
34
  form.submit class: "ml-3 button button-accented"
35
35
  end
36
36
  end
@@ -7,11 +7,13 @@ module Maquina
7
7
  register_element :turbo_frame
8
8
 
9
9
  def template
10
- div(data_controller: "modal", class: "modal", data_frame_src: "") do
11
- div(class: "fixed inset-0 z-30 hidden overflow-y-auto", aria_labelledby: "modal-title", role: "dialog",
10
+ div(data_controller: "modal", class: "modal", data_modal_backdrop_outlet: ".modal-backdrop") do
11
+ div(class: "hidden fixed inset-0 z-30 overflow-y-auto", aria_labelledby: "modal-title", role: "dialog",
12
12
  aria_modal: "true", data_modal_target: "container") do
13
13
  div(class: "flex items-end justify-center min-h-screen px-4 pt-4 pb-20 text-center sm:block sm:p-0") do
14
- div(class: "fixed inset-0 transition-opacity",
14
+ div(class: "hidden fixed inset-0 transition-opacity modal-backdrop",
15
+ data_controller: "backdrop",
16
+ data_backdrop_target: "backdrop",
15
17
  data_transition_enter: "ease-out duration-300",
16
18
  data_transition_enter_active: "opacity-0",
17
19
  data_transition_enter_to: "opacity-100",
@@ -22,8 +24,8 @@ module Maquina
22
24
  div(class: "fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity", aria_hidden: "true")
23
25
  end
24
26
  span(class: "hidden sm:inline-block sm:align-middle sm:h-screen", aria_hidden: "true") { "​" }
25
- div(class: "inline-block align-bottom bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full sm:p-6",
26
- data_modal_target: "content",
27
+ div(class: "hidden inline-block align-bottom bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full sm:p-6",
28
+ data_modal_target: "modal",
27
29
  data_transition_enter: "ease-out duration-300",
28
30
  data_transition_enter_active: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",
29
31
  data_transition_enter_to: "opacity-100 translate-y-0 sm:scale-100",
@@ -47,8 +47,8 @@ module Maquina
47
47
  def field_attributes(field_name, scope = nil)
48
48
  scope ||= "sessions"
49
49
  {
50
- maxlength: t("maxlength.#{scope}.#{field_name}", default: t("maxlength.default")),
51
- placeholder: t("placeholder.#{scope}.#{field_name}", default: "")
50
+ maxlength: t("helpers.maxlength.#{scope}.#{field_name}", default: t("helpers.maxlength.default")),
51
+ placeholder: t("helpers.placeholder.#{scope}.#{field_name}", default: "")
52
52
  }
53
53
  end
54
54
  end
@@ -3,7 +3,8 @@ en:
3
3
  maquina/plan:
4
4
  title: Configure a plan for your customers
5
5
  maquina/invitation:
6
- title: User will receive an invitation to join this application in the provided email.
6
+ title: Invite user to collaborate
7
+ description: User will receive an invitation to join this application in the provided email.
7
8
 
8
9
  form:
9
10
  sessions:
@@ -26,18 +27,6 @@ en:
26
27
  maquina/invitation:
27
28
  email: Enter user's email
28
29
 
29
- maxlength:
30
- default: 30
31
-
32
- maquina/plan:
33
- name: 60
34
- trial: 3
35
- price: 9
36
-
37
- sessions:
38
- email: 60
39
- password: 60
40
-
41
30
  help:
42
31
  maquina/plan:
43
32
  name: Descriptive plan name
@@ -56,3 +45,14 @@ en:
56
45
  maquina/invitation:
57
46
  create: Send invitation
58
47
 
48
+ maxlength:
49
+ default: 30
50
+
51
+ maquina/plan:
52
+ name: 60
53
+ trial: 3
54
+ price: 9
55
+
56
+ sessions:
57
+ email: 60
58
+ password: 60
@@ -1,3 +1,3 @@
1
1
  module Maquina
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maquina
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Alberto Chávez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-04 00:00:00.000000000 Z
11
+ date: 2023-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -307,6 +307,7 @@ files:
307
307
  - app/assets/javascripts/maquina/application.js
308
308
  - app/assets/javascripts/maquina/controllers/alert_controller.js
309
309
  - app/assets/javascripts/maquina/controllers/application.js
310
+ - app/assets/javascripts/maquina/controllers/backdrop_controller.js
310
311
  - app/assets/javascripts/maquina/controllers/file_controller.js
311
312
  - app/assets/javascripts/maquina/controllers/index.js
312
313
  - app/assets/javascripts/maquina/controllers/mobile_menu_controller.js