bullet_train 1.0.45 → 1.1.0
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 +4 -4
- data/.bt-link +0 -0
- data/README.md +4 -3
- data/app/controllers/concerns/account/controllers/base.rb +9 -0
- data/app/controllers/concerns/account/invitations/controller_base.rb +11 -6
- data/app/controllers/concerns/account/teams/controller_base.rb +1 -1
- data/app/controllers/concerns/controllers/base.rb +26 -2
- data/app/controllers/concerns/registrations/controller_base.rb +4 -7
- data/app/controllers/concerns/root_redirect.rb +1 -5
- data/app/controllers/concerns/sessions/controller_base.rb +0 -6
- data/app/controllers/sessions_controller.rb +11 -0
- data/app/controllers/turbo_devise_controller.rb +19 -0
- data/app/helpers/account/dates_helper.rb +10 -8
- data/app/helpers/account/forms_helper.rb +0 -4
- data/app/helpers/account/locale_helper.rb +2 -2
- data/app/helpers/base_helper.rb +5 -1
- data/app/helpers/concerns/helpers/base.rb +18 -0
- data/app/helpers/invitations_helper.rb +0 -15
- data/app/javascript/controllers/bulk_action_form_controller.js +88 -0
- data/app/javascript/controllers/bulk_actions_controller.js +95 -0
- data/app/javascript/controllers/clipboard_controller.js +1 -1
- data/app/javascript/controllers/form_controller.js +1 -1
- data/app/javascript/controllers/index.js +7 -1
- data/app/javascript/controllers/mobile_menu_controller.js +19 -17
- data/app/javascript/controllers/text_toggle_controller.js +33 -0
- data/app/mailers/concerns/mailers/base.rb +1 -0
- data/app/models/concerns/current_attributes/base.rb +1 -1
- data/app/models/concerns/memberships/base.rb +10 -2
- data/app/models/concerns/records/base.rb +35 -0
- data/app/models/concerns/teams/base.rb +19 -0
- data/app/models/concerns/users/base.rb +12 -11
- data/app/models/invitation.rb +1 -1
- data/app/models/membership.rb +1 -1
- data/app/models/team.rb +2 -2
- data/app/models/user.rb +1 -1
- data/app/views/account/memberships/show.html.erb +3 -1
- data/app/views/account/onboarding/user_details/edit.html.erb +1 -1
- data/app/views/account/users/_oauth.html.erb +2 -0
- data/app/views/account/users/edit.html.erb +2 -3
- data/app/views/bullet_train/partial_resolver.html.erb +1 -0
- data/app/views/devise/registrations/new.html.erb +1 -1
- data/app/views/devise/sessions/new.html.erb +6 -6
- data/app/views/layouts/docs.html.erb +25 -24
- data/app/views/layouts/mailer.html.erb +1 -425
- data/config/initializers/concerns/inflections_base.rb +6 -0
- data/config/initializers/concerns/turbo_failure_app.rb +14 -0
- data/config/locales/en/billing/products.en.yml +17 -0
- data/config/locales/en/devise.en.yml +1 -0
- data/config/locales/en/framework_packages.yml +43 -0
- data/config/locales/en/invitations.en.yml +1 -0
- data/config/locales/en/teams.en.yml +1 -0
- data/docs/action-models.md +148 -0
- data/docs/authentication.md +2 -2
- data/docs/billing/stripe.md +95 -39
- data/docs/field-partials/super-select.md +70 -1
- data/docs/field-partials.md +25 -18
- data/docs/getting-started.md +12 -12
- data/docs/index.md +4 -1
- data/docs/indirection.md +30 -7
- data/docs/invitation_only.md +13 -0
- data/docs/javascript.md +18 -0
- data/docs/namespacing.md +1 -1
- data/docs/onboarding.md +10 -10
- data/docs/overriding.md +1 -1
- data/docs/permissions.md +1 -1
- data/docs/super-scaffolding/delegated-types.md +31 -3
- data/docs/super-scaffolding/sortable.md +137 -0
- data/docs/super-scaffolding.md +7 -1
- data/docs/tunneling.md +4 -4
- data/lib/bullet_train/core_ext/string_emoji_helper.rb +18 -0
- data/lib/bullet_train/resolver.rb +61 -47
- data/lib/bullet_train/version.rb +1 -1
- data/lib/bullet_train.rb +23 -9
- data/lib/tasks/bullet_train_tasks.rake +148 -7
- metadata +115 -33
- data/app/assets/javascripts/bullet-train.esm.js +0 -2
- data/app/assets/javascripts/bullet-train.esm.js.map +0 -1
- data/app/assets/javascripts/bullet-train.js +0 -2
- data/app/assets/javascripts/bullet-train.js.map +0 -1
- data/app/assets/javascripts/bullet-train.modern.js +0 -2
- data/app/assets/javascripts/bullet-train.modern.js.map +0 -1
- data/app/assets/javascripts/bullet-train.umd.js +0 -2
- data/app/assets/javascripts/bullet-train.umd.js.map +0 -1
- data/lib/string/emoji.rb +0 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0a785a7c7fad5eb5409e133c0775eddcceb2dea5a72bd9906d21f3bb1d6e3f2c
|
|
4
|
+
data.tar.gz: 694e09c9486754e3337a2672407b49e48b0e9a968e25a2779b74fa086512d3b1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1ed9a76122fc82fb2e39cf43c21d220e6011657590514d50bf0264ae4cb7120341d52f12e439576c13f1d2b407325265bbf3394646432d78147c4dfa14e34742
|
|
7
|
+
data.tar.gz: 0beecd36dbcf762880fa730e65a7216c880a52e29747166657419c78ed2318151c4df53f570ecd56d383c3c390800594cd35a6717faf3e03f2dcd60e72d31dbd
|
data/.bt-link
ADDED
|
File without changes
|
data/README.md
CHANGED
|
@@ -13,16 +13,17 @@ gem "bullet_train"
|
|
|
13
13
|
|
|
14
14
|
And then execute:
|
|
15
15
|
```bash
|
|
16
|
-
|
|
16
|
+
bundle
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
Or install it yourself as:
|
|
20
20
|
```bash
|
|
21
|
-
|
|
21
|
+
gem install bullet_train
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
## Contributing
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
See `RELEASE.md` for instructions on local development and for publishing both the gem and the npm package.
|
|
26
27
|
|
|
27
28
|
## License
|
|
28
29
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -5,6 +5,10 @@ module Account::Controllers::Base
|
|
|
5
5
|
include LoadsAndAuthorizesResource
|
|
6
6
|
include Fields::ControllerSupport
|
|
7
7
|
|
|
8
|
+
if billing_enabled?
|
|
9
|
+
include Billing::ControllerSupport
|
|
10
|
+
end
|
|
11
|
+
|
|
8
12
|
before_action :set_last_seen_at, if: proc {
|
|
9
13
|
user_signed_in? && (current_user.last_seen_at.nil? || current_user.last_seen_at < 1.minute.ago)
|
|
10
14
|
}
|
|
@@ -106,6 +110,11 @@ module Account::Controllers::Base
|
|
|
106
110
|
end
|
|
107
111
|
end
|
|
108
112
|
|
|
113
|
+
# TODO Maybe in this context we should check whether `Billing::ControllerSupport` is included instead of just defined?
|
|
114
|
+
if defined?(Billing::ControllerSupport)
|
|
115
|
+
enforce_billing_requirements
|
|
116
|
+
# See `app/controllers/concerns/billing_support.rb` for details.
|
|
117
|
+
end
|
|
109
118
|
end
|
|
110
119
|
|
|
111
120
|
true
|
|
@@ -42,9 +42,13 @@ module Account::Invitations::ControllerBase
|
|
|
42
42
|
# POST /invitations/1/accept
|
|
43
43
|
# POST /invitations/1/accept.json
|
|
44
44
|
def accept
|
|
45
|
+
# The user should be alerted when there is no
|
|
46
|
+
# invitation regardless if they're registered or not.
|
|
47
|
+
@invitation = Invitation.find_by(uuid: params[:id])
|
|
48
|
+
flash[:alert] = t("invitations.notifications.doesnt_exist") if @invitation.nil?
|
|
49
|
+
|
|
45
50
|
# unless the user is signed in.
|
|
46
51
|
if !current_user.present?
|
|
47
|
-
|
|
48
52
|
# keep track of the uuid of the invitation so we can reload it
|
|
49
53
|
# after they sign up. at this point we don't even know if it's
|
|
50
54
|
# valid, but that's fine.
|
|
@@ -57,9 +61,9 @@ module Account::Invitations::ControllerBase
|
|
|
57
61
|
# this is not the default for devise, but a sensible default here.
|
|
58
62
|
redirect_to new_user_registration_path
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
# session[:invitation_uuid] should only be present if the user is registering for the first time.
|
|
65
|
+
elsif (@invitation = Invitation.find_by(uuid: session[:invitation_uuid] || params[:id]))
|
|
66
|
+
session.delete(:invitation_uuid) if session[:invitation_uuid].present?
|
|
63
67
|
|
|
64
68
|
if @invitation
|
|
65
69
|
@team = @invitation.team
|
|
@@ -70,9 +74,10 @@ module Account::Invitations::ControllerBase
|
|
|
70
74
|
redirect_to account_invitation_path(@invitation.uuid)
|
|
71
75
|
end
|
|
72
76
|
else
|
|
73
|
-
redirect_to
|
|
77
|
+
redirect_to account_invitation_path(@invitation.uuid)
|
|
74
78
|
end
|
|
75
|
-
|
|
79
|
+
else
|
|
80
|
+
redirect_to account_dashboard_path
|
|
76
81
|
end
|
|
77
82
|
end
|
|
78
83
|
|
|
@@ -81,7 +81,7 @@ module Account::Teams::ControllerBase
|
|
|
81
81
|
format.html { redirect_to [:account, @team], notice: I18n.t("teams.notifications.created") }
|
|
82
82
|
format.json { render :show, status: :created, location: [:account, @team] }
|
|
83
83
|
else
|
|
84
|
-
format.html { render :new, layout: "devise" }
|
|
84
|
+
format.html { render :new, layout: "devise", status: :unprocessable_entity }
|
|
85
85
|
format.json { render json: @team.errors, status: :unprocessable_entity }
|
|
86
86
|
end
|
|
87
87
|
end
|
|
@@ -7,6 +7,7 @@ module Controllers::Base
|
|
|
7
7
|
include InvitationsHelper
|
|
8
8
|
|
|
9
9
|
include DeviseCurrentAttributes
|
|
10
|
+
include Pagy::Backend
|
|
10
11
|
|
|
11
12
|
around_action :set_locale
|
|
12
13
|
layout :layout_by_resource
|
|
@@ -32,13 +33,18 @@ module Controllers::Base
|
|
|
32
33
|
end
|
|
33
34
|
else
|
|
34
35
|
respond_to do |format|
|
|
35
|
-
|
|
36
|
-
format.html { redirect_to [:account, current_user.teams.first], alert: exception.message }
|
|
36
|
+
format.html { redirect_to account_teams_url, alert: exception.message }
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
class_methods do
|
|
43
|
+
def strong_parameters_from_api
|
|
44
|
+
(name.gsub(regex_to_remove_controller_namespace, "Api::#{BulletTrain::Api.current_version.upcase}::") + "::StrongParameters").constantize
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
42
48
|
# this is an ugly hack, but it's what is recommended at
|
|
43
49
|
# https://github.com/plataformatec/devise/wiki/How-To:-Create-custom-layouts
|
|
44
50
|
def layout_by_resource
|
|
@@ -116,4 +122,22 @@ module Controllers::Base
|
|
|
116
122
|
)
|
|
117
123
|
end
|
|
118
124
|
end
|
|
125
|
+
|
|
126
|
+
def permitted_fields
|
|
127
|
+
[]
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def permitted_arrays
|
|
131
|
+
{}
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def process_params(strong_params)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def delegate_json_to_api
|
|
138
|
+
respond_to do |format|
|
|
139
|
+
format.html
|
|
140
|
+
format.json { render "#{params[:controller].gsub(/^account\//, "api/#{BulletTrain::Api.current_version}/")}/#{params[:action]}" }
|
|
141
|
+
end
|
|
142
|
+
end
|
|
119
143
|
end
|
|
@@ -19,14 +19,11 @@ module Registrations::ControllerBase
|
|
|
19
19
|
|
|
20
20
|
# if current_user is defined, that means they were successful registering.
|
|
21
21
|
if current_user
|
|
22
|
-
|
|
23
|
-
# TODO i think this might be redundant. we've added a hook into `session["user_return_to"]` in the
|
|
24
|
-
# `invitations#accept` action and that might be enough to get them where they're supposed to be after
|
|
25
|
-
# either creating a new account or signing into an existing account.
|
|
26
|
-
handle_outstanding_invitation
|
|
27
|
-
|
|
28
22
|
# if the user doesn't have a team at this point, create one.
|
|
29
|
-
|
|
23
|
+
# If the user is accepting an invitation, then the user's current_team is populated
|
|
24
|
+
# with the information attached to their invitation via `@invitation.accept_for` later on,
|
|
25
|
+
# so we don't have to create a default team for them here.
|
|
26
|
+
unless current_user.teams.any? || session[:invitation_uuid].present?
|
|
30
27
|
current_user.create_default_team
|
|
31
28
|
end
|
|
32
29
|
|
|
@@ -2,10 +2,6 @@ module RootRedirect
|
|
|
2
2
|
extend ActiveSupport::Concern
|
|
3
3
|
|
|
4
4
|
def index
|
|
5
|
-
|
|
6
|
-
redirect_to ENV["MARKETING_SITE_URL"]
|
|
7
|
-
else
|
|
8
|
-
redirect_to new_user_session_path
|
|
9
|
-
end
|
|
5
|
+
redirect_to ENV["MARKETING_SITE_URL"] || new_user_session_path
|
|
10
6
|
end
|
|
11
7
|
end
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
module Sessions::ControllerBase
|
|
2
2
|
extend ActiveSupport::Concern
|
|
3
3
|
|
|
4
|
-
included do
|
|
5
|
-
# TODO I'm not sure why the sign-in page started throwing a `ActionController::InvalidAuthenticityToken`. I'm doing
|
|
6
|
-
# this as a temporary workaround, but this shouldn't be here long-term.
|
|
7
|
-
skip_before_action :verify_authenticity_token, only: [:create]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
4
|
def pre_otp
|
|
11
5
|
if (@email = params["user"]["email"].downcase.strip.presence)
|
|
12
6
|
@user = User.find_by(email: @email)
|
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
class SessionsController < Devise::SessionsController
|
|
2
2
|
include Sessions::ControllerBase
|
|
3
|
+
|
|
4
|
+
def destroy
|
|
5
|
+
if params.include?(:onboard_logout)
|
|
6
|
+
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
|
|
7
|
+
set_flash_message! :notice, :signed_out if signed_out
|
|
8
|
+
yield if block_given?
|
|
9
|
+
redirect_to root_path
|
|
10
|
+
else
|
|
11
|
+
super
|
|
12
|
+
end
|
|
13
|
+
end
|
|
3
14
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# NOTE: This is a workaround to get Devise working with Turbo
|
|
2
|
+
class TurboDeviseController < ApplicationController
|
|
3
|
+
class Responder < ActionController::Responder
|
|
4
|
+
def to_turbo_stream
|
|
5
|
+
controller.render(options.merge(formats: :html))
|
|
6
|
+
rescue ActionView::MissingTemplate => error
|
|
7
|
+
if get?
|
|
8
|
+
raise error
|
|
9
|
+
elsif has_errors? && default_action
|
|
10
|
+
render rendering_options.merge(formats: :html, status: :unprocessable_entity)
|
|
11
|
+
else
|
|
12
|
+
redirect_to navigation_location
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
self.responder = Responder
|
|
18
|
+
respond_to :html, :turbo_stream
|
|
19
|
+
end
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
module Account::DatesHelper
|
|
2
2
|
# e.g. October 11, 2018
|
|
3
|
-
def display_date(timestamp)
|
|
3
|
+
def display_date(timestamp, custom_date_format = nil)
|
|
4
4
|
return nil unless timestamp
|
|
5
|
-
if
|
|
5
|
+
if custom_date_format
|
|
6
|
+
local_time(timestamp).strftime(custom_date_format)
|
|
7
|
+
elsif local_time(timestamp).year == local_time(Time.now).year
|
|
6
8
|
local_time(timestamp).strftime("%B %-d")
|
|
7
9
|
else
|
|
8
10
|
local_time(timestamp).strftime("%B %-d, %Y")
|
|
@@ -12,23 +14,23 @@ module Account::DatesHelper
|
|
|
12
14
|
# e.g. October 11, 2018 at 4:22 PM
|
|
13
15
|
# e.g. Yesterday at 2:12 PM
|
|
14
16
|
# e.g. April 24 at 7:39 AM
|
|
15
|
-
def display_date_and_time(timestamp)
|
|
17
|
+
def display_date_and_time(timestamp, custom_date_format = nil, custom_time_format = nil)
|
|
16
18
|
return nil unless timestamp
|
|
17
19
|
|
|
18
20
|
# today?
|
|
19
21
|
if local_time(timestamp).to_date == local_time(Time.now).to_date
|
|
20
|
-
"Today at #{display_time(timestamp)}"
|
|
22
|
+
"Today at #{display_time(timestamp, custom_time_format)}"
|
|
21
23
|
# yesterday?
|
|
22
24
|
elsif (local_time(timestamp).to_date) == (local_time(Time.now).to_date - 1.day)
|
|
23
|
-
"Yesterday at #{display_time(timestamp)}"
|
|
25
|
+
"Yesterday at #{display_time(timestamp, custom_time_format)}"
|
|
24
26
|
else
|
|
25
|
-
"#{display_date(timestamp)} at #{display_time(timestamp)}"
|
|
27
|
+
"#{display_date(timestamp, custom_date_format)} at #{display_time(timestamp, custom_time_format)}"
|
|
26
28
|
end
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
# e.g. 4:22 PM
|
|
30
|
-
def display_time(timestamp)
|
|
31
|
-
local_time(timestamp).strftime("%l:%M %p")
|
|
32
|
+
def display_time(timestamp, custom_time_format = nil)
|
|
33
|
+
local_time(timestamp).strftime(custom_time_format || "%l:%M %p")
|
|
32
34
|
end
|
|
33
35
|
|
|
34
36
|
def local_time(time)
|
|
@@ -27,10 +27,6 @@ module Account::FormsHelper
|
|
|
27
27
|
string.present? ? string : nil
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
def id_for(form, method)
|
|
31
|
-
[form.object.class.name, form.index, method].compact.join("_").underscore
|
|
32
|
-
end
|
|
33
|
-
|
|
34
30
|
def model_key(form)
|
|
35
31
|
form.object.class.name.pluralize.underscore
|
|
36
32
|
end
|
|
@@ -46,7 +46,7 @@ module Account::LocaleHelper
|
|
|
46
46
|
begin
|
|
47
47
|
super(key + "💣", options.except(:default))
|
|
48
48
|
rescue I18n::MissingTranslationData => exception
|
|
49
|
-
full_key = exception.message.rpartition(" ").last.
|
|
49
|
+
full_key = exception.message.rpartition(" ").last.delete("💣")
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
end
|
|
@@ -75,7 +75,7 @@ module Account::LocaleHelper
|
|
|
75
75
|
end
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
result
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
# like 't', but if the key isn't found, it returns nil.
|
data/app/helpers/base_helper.rb
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
module BaseHelper
|
|
2
2
|
# TODO This is for the billing package to override, but I feel like there has got to be a better way to do this.
|
|
3
3
|
def hide_team_resource_menus?
|
|
4
|
-
|
|
4
|
+
if billing_enabled?
|
|
5
|
+
current_team.needs_billing_subscription?
|
|
6
|
+
else
|
|
7
|
+
false
|
|
8
|
+
end
|
|
5
9
|
end
|
|
6
10
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Helpers::Base
|
|
2
|
+
include Pagy::Frontend
|
|
3
|
+
include Pagy::Backend
|
|
4
|
+
|
|
5
|
+
def has_order?(scope)
|
|
6
|
+
# This scope has an order if the SQL changes when we remove any order clause.
|
|
7
|
+
scope.to_sql != scope.reorder("").to_sql
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# TODO This should really be in the API package and included from there.
|
|
11
|
+
if defined?(BulletTrain::Api)
|
|
12
|
+
def render_pagination(json)
|
|
13
|
+
if @pagy
|
|
14
|
+
json.has_more @pagy.has_more
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -1,17 +1,2 @@
|
|
|
1
1
|
module InvitationsHelper
|
|
2
|
-
def handle_outstanding_invitation
|
|
3
|
-
# was this user registering to claim an invitation?
|
|
4
|
-
if session[:invitation_uuid].present?
|
|
5
|
-
|
|
6
|
-
# try to find the invitation, if it still exists.
|
|
7
|
-
invitation = Invitation.find_by_uuid(session[:invitation_uuid])
|
|
8
|
-
|
|
9
|
-
# if the invitation was found, claim it for this user.
|
|
10
|
-
invitation&.accept_for(current_user)
|
|
11
|
-
|
|
12
|
-
# remove the uuid from the session.
|
|
13
|
-
session.delete(:invitation_uuid)
|
|
14
|
-
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
2
|
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus'
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static targets = [ "button", "idsHiddenField", "allHiddenField" ]
|
|
5
|
+
static classes = [ "hidden" ]
|
|
6
|
+
static values = {
|
|
7
|
+
buttonIfAll: String,
|
|
8
|
+
buttonIfIds: String,
|
|
9
|
+
ids: Array,
|
|
10
|
+
all: Boolean,
|
|
11
|
+
objectName: String,
|
|
12
|
+
idsFieldName: String,
|
|
13
|
+
allFieldName: String
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
connect() {
|
|
17
|
+
this.updateAvailability()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
updateFormAndSubmit(event) {
|
|
21
|
+
this.recreateIdsHiddenFields()
|
|
22
|
+
this.createOrUpdateAllField()
|
|
23
|
+
return true
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
updateIds(event) {
|
|
27
|
+
if (event?.detail?.ids) {
|
|
28
|
+
this.idsValue = event.detail.ids
|
|
29
|
+
this.allValue = event.detail.all
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.updateAvailability()
|
|
33
|
+
this.updateButtonLabel()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
updateAvailability() {
|
|
37
|
+
this.element.classList.toggle(this.hiddenClass, this.idsValue.length === 0)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
updateButtonLabel() {
|
|
41
|
+
let label = this.buttonIfAllValue
|
|
42
|
+
if (this.idsValue.length && this.allValue === false) {
|
|
43
|
+
label = this.buttonIfIdsValue.replace('{num}', this.idsValue.length)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
switch (this.buttonTarget.tagName) {
|
|
47
|
+
case 'INPUT': this.buttonTarget.value = label; break;
|
|
48
|
+
default: this.buttonTarget.textContent = label; break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
recreateIdsHiddenFields() {
|
|
53
|
+
this.removeIdsHiddenFields()
|
|
54
|
+
this.createIdsHiddenFields()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
removeIdsHiddenFields() {
|
|
58
|
+
this.idsHiddenFieldTargets.forEach(field => {
|
|
59
|
+
this.element.removeChild(field)
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
createIdsHiddenFields() {
|
|
64
|
+
this.idsValue.forEach(id => {
|
|
65
|
+
let field = document.createElement('input')
|
|
66
|
+
field.type = 'hidden'
|
|
67
|
+
field.name = `${this.objectNameValue}[${this.idsFieldNameValue}][]`
|
|
68
|
+
field.value = id
|
|
69
|
+
this.element.appendChild(field)
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
createOrUpdateAllField() {
|
|
74
|
+
if (this.hasAllHiddenFieldTarget) {
|
|
75
|
+
this.allHiddenFieldTarget.value = this.allValue? 'true': 'false'
|
|
76
|
+
} else {
|
|
77
|
+
this.createAllField()
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
createAllField() {
|
|
82
|
+
let field = document.createElement('input')
|
|
83
|
+
field.type = 'hidden'
|
|
84
|
+
field.name = `${this.objectNameValue}[${this.allFieldNameValue}]`
|
|
85
|
+
field.value = this.allValue? 'true': 'false'
|
|
86
|
+
this.element.appendChild(field)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus'
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static targets = [ "checkbox", "selectAllCheckbox", "action", "selectableToggle", "selectAllLabel" ]
|
|
5
|
+
static classes = [ "selectableAvailable", "selectable" ]
|
|
6
|
+
static values = {
|
|
7
|
+
selectable: Boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
connect() {
|
|
11
|
+
this.element.classList.add(this.selectableAvailableClass)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
toggleSelectable() {
|
|
15
|
+
this.selectableValue = !this.selectableValue
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
updateSelectedIds() {
|
|
19
|
+
this.updateActions()
|
|
20
|
+
this.updateSelectAllCheckbox()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
updateActions() {
|
|
24
|
+
this.actionTargets.forEach(actionTarget => {
|
|
25
|
+
actionTarget.dispatchEvent(new CustomEvent('update-ids', { detail: {
|
|
26
|
+
ids: this.selectedIds,
|
|
27
|
+
all: this.allSelected
|
|
28
|
+
}}))
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
selectAllOrNone(event) {
|
|
33
|
+
if (this.allSelected) {
|
|
34
|
+
this.selectNone()
|
|
35
|
+
} else {
|
|
36
|
+
this.selectAll()
|
|
37
|
+
}
|
|
38
|
+
this.updateSelectAllCheckbox()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
selectAll() {
|
|
42
|
+
this.checkboxTargets.forEach(checkbox => {
|
|
43
|
+
checkbox.checked = true
|
|
44
|
+
})
|
|
45
|
+
this.updateActions()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
selectNone() {
|
|
49
|
+
this.checkboxTargets.forEach(checkbox => {
|
|
50
|
+
checkbox.checked = false
|
|
51
|
+
})
|
|
52
|
+
this.updateActions()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
updateSelectAllCheckbox() {
|
|
56
|
+
let checkbox = this.selectAllCheckboxTarget
|
|
57
|
+
let label = this.selectAllLabelTarget
|
|
58
|
+
|
|
59
|
+
if (this.allSelected) {
|
|
60
|
+
checkbox.checked = true
|
|
61
|
+
checkbox.indeterminate = false
|
|
62
|
+
label.dispatchEvent(new CustomEvent('toggle', { detail: { useAlternate: true }} ))
|
|
63
|
+
} else if (this.selectedIds.length > 0) {
|
|
64
|
+
checkbox.indeterminate = true
|
|
65
|
+
label.dispatchEvent(new CustomEvent('toggle', { detail: { useAlternate: false }} ))
|
|
66
|
+
} else {
|
|
67
|
+
checkbox.checked = false
|
|
68
|
+
checkbox.indeterminate = false
|
|
69
|
+
label.dispatchEvent(new CustomEvent('toggle', { detail: { useAlternate: false }} ))
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
selectableValueChanged() {
|
|
74
|
+
this.element.classList.toggle(this.selectableClass, this.selectableValue)
|
|
75
|
+
this.updateToggleLabel()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
updateToggleLabel() {
|
|
79
|
+
this.selectableToggleTarget.dispatchEvent(new CustomEvent('toggle', { detail: { useAlternate: this.selectableValue }} ))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get selectedIds() {
|
|
83
|
+
let ids = []
|
|
84
|
+
this.checkboxTargets.forEach(checkbox => {
|
|
85
|
+
if (checkbox.checked) {
|
|
86
|
+
ids.push(checkbox.value)
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
return ids
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
get allSelected() {
|
|
93
|
+
return this.selectedIds.length === this.checkboxTargets.length
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import { identifierForContextKey } from "@stimulus
|
|
1
|
+
import { identifierForContextKey } from "@hotwired/stimulus-webpack-helpers"
|
|
2
2
|
|
|
3
|
+
import BulkActionFormController from './bulk_action_form_controller'
|
|
4
|
+
import BulkActionsController from './bulk_actions_controller'
|
|
3
5
|
import ClipboardController from './clipboard_controller'
|
|
4
6
|
import FormController from './form_controller'
|
|
5
7
|
import MobileMenuController from './mobile_menu_controller'
|
|
8
|
+
import TextToggleController from './text_toggle_controller'
|
|
6
9
|
|
|
7
10
|
export const controllerDefinitions = [
|
|
11
|
+
[BulkActionFormController, 'bulk_action_form_controller.js'],
|
|
12
|
+
[BulkActionsController, 'bulk_actions_controller.js'],
|
|
8
13
|
[ClipboardController, 'clipboard_controller.js'],
|
|
9
14
|
[FormController, 'form_controller.js'],
|
|
10
15
|
[MobileMenuController, 'mobile_menu_controller.js'],
|
|
16
|
+
[TextToggleController, 'text_toggle_controller.js'],
|
|
11
17
|
].map(function(d) {
|
|
12
18
|
const key = d[1]
|
|
13
19
|
const controller = d[0]
|
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import { Controller } from "stimulus"
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
|
2
|
+
import { enter, leave } from "el-transition"
|
|
2
3
|
|
|
3
4
|
export default class extends Controller {
|
|
4
|
-
static targets = [ "wrapper"]
|
|
5
|
-
static classes = [ "hidden" ] // necessary because
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const eventName = this.isWrapperHidden? this.showEventNameValue: this.hideEventNameValue
|
|
13
|
-
if (this.isWrapperHidden) {
|
|
14
|
-
this.showWrapper()
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
this.wrapperTarget.dispatchEvent(new CustomEvent(eventName))
|
|
5
|
+
static targets = [ "wrapper", "revealable"]
|
|
6
|
+
static classes = [ "hidden" ] // necessary because we're always hiding the mobile menu on larger screens and this is the class used for only mobile screen sizes
|
|
7
|
+
|
|
8
|
+
open() {
|
|
9
|
+
this.showWrapper()
|
|
10
|
+
this.revealableTargets.forEach(revealableTarget => {
|
|
11
|
+
enter(revealableTarget)
|
|
12
|
+
})
|
|
18
13
|
}
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
close() {
|
|
16
|
+
Promise.all(
|
|
17
|
+
this.revealableTargets.map(revealableTarget => {
|
|
18
|
+
return leave(revealableTarget)
|
|
19
|
+
})
|
|
20
|
+
).then(() => {
|
|
21
|
+
this.hideWrapper()
|
|
22
|
+
})
|
|
23
|
+
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
showWrapper() {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
|
2
|
+
|
|
3
|
+
export default class extends Controller {
|
|
4
|
+
static values = {
|
|
5
|
+
label: String,
|
|
6
|
+
labelAlternate: String,
|
|
7
|
+
useAlternate: Boolean,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
connect() {
|
|
11
|
+
this.updateLabel()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
toggle(event) {
|
|
15
|
+
if (undefined !== event?.detail?.useAlternate) {
|
|
16
|
+
this.useAlternateValue = event.detail.useAlternate
|
|
17
|
+
} else {
|
|
18
|
+
this.useAlternateValue = !this.useAlternateValue
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
useAlternateValueChanged() {
|
|
23
|
+
this.updateLabel()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
updateLabel() {
|
|
27
|
+
if (!this.hasLabelValue || !this.hasLabelAlternateValue || !this.hasUseAlternateValue) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
this.element.textContent = this.useAlternateValue === true ? this.labelAlternateValue : this.labelValue
|
|
32
|
+
}
|
|
33
|
+
}
|