0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-26 11:00:28 +01:00
discourse-custom-wizard/plugin.rb

124 Zeilen
4,1 KiB
Ruby

2017-09-23 04:34:07 +02:00
# name: discourse-custom-wizard
2017-10-05 02:36:46 +02:00
# about: Create custom wizards
2017-09-23 04:34:07 +02:00
# version: 0.1
# authors: Angus McLeod
2018-01-12 08:23:57 +01:00
# url: https://github.com/angusmcleod/discourse-custom-wizard
2017-09-23 04:34:07 +02:00
2017-10-13 15:02:34 +02:00
register_asset 'stylesheets/wizard_custom_admin.scss'
2017-11-01 05:21:14 +01:00
register_asset 'lib/jquery.timepicker.min.js'
register_asset 'lib/jquery.timepicker.scss'
2017-09-23 04:34:07 +02:00
enabled_site_setting :custom_wizard_enabled
2017-09-25 16:47:40 +02:00
config = Rails.application.config
2019-12-05 09:05:21 +01:00
plugin_asset_path = "#{Rails.root}/plugins/discourse-custom-wizard/assets"
config.assets.paths << "#{plugin_asset_path}/javascripts"
config.assets.paths << "#{plugin_asset_path}/stylesheets/wizard"
2017-09-25 16:47:40 +02:00
2017-11-01 12:47:27 +01:00
if Rails.env.production?
2017-12-03 08:57:54 +01:00
config.assets.precompile += %w{
2019-10-09 01:09:30 +02:00
wizard-custom-guest.js
2017-12-03 08:57:54 +01:00
wizard-custom-lib.js
wizard-custom.js
wizard-plugin.js
2019-01-18 01:34:52 +01:00
wizard-custom-start.js
2019-01-29 01:42:23 +01:00
wizard-raw-templates.js.erb
2020-04-03 10:49:36 +02:00
stylesheets/wizard/wizard_autocomplete.scss
2017-12-03 08:57:54 +01:00
stylesheets/wizard/wizard_custom.scss
2018-02-08 05:30:55 +01:00
stylesheets/wizard/wizard_composer.scss
stylesheets/wizard/wizard_variables.scss
2017-12-03 08:57:54 +01:00
stylesheets/wizard/wizard_custom_mobile.scss
2020-04-03 10:49:36 +02:00
stylesheets/wizard/wizard_locations.scss
2020-04-02 15:21:19 +02:00
stylesheets/wizard/wizard_events.scss
2017-12-03 08:57:54 +01:00
}
2017-11-01 12:47:27 +01:00
end
2019-02-20 07:27:17 +01:00
if respond_to?(:register_svg_icon)
register_svg_icon "calendar-o"
register_svg_icon "chevron-right"
register_svg_icon "chevron-left"
end
2019-01-14 03:03:42 +01:00
2017-09-23 04:34:07 +02:00
after_initialize do
[
'../lib/custom_wizard/engine.rb',
'../config/routes.rb',
'../controllers/custom_wizard/wizard.rb',
'../controllers/custom_wizard/steps.rb',
'../controllers/custom_wizard/admin.rb',
'../controllers/custom_wizard/transfer.rb',
'../controllers/custom_wizard/api.rb',
2019-12-05 09:05:21 +01:00
'../controllers/application_controller.rb',
'../controllers/extra_locales_controller.rb',
'../controllers/invites_controller.rb',
'../jobs/clear_after_time_wizard.rb',
'../jobs/refresh_api_access_token.rb',
'../jobs/set_after_time_wizard.rb',
'../lib/custom_wizard/builder.rb',
'../lib/custom_wizard/field.rb',
'../lib/custom_wizard/step_updater.rb',
'../lib/custom_wizard/template.rb',
'../lib/custom_wizard/wizard.rb',
'../lib/custom_wizard/api/api.rb',
'../lib/custom_wizard/api/authorization.rb',
'../lib/custom_wizard/api/endpoint.rb',
'../lib/custom_wizard/api/log_entry.rb',
2019-12-05 09:05:21 +01:00
'../lib/wizard/choice.rb',
'../lib/wizard/field.rb',
'../lib/wizard/step.rb',
'../serializers/custom_wizard/api/authorization_serializer.rb',
'../serializers/custom_wizard/api/basic_endpoint_serializer.rb',
'../serializers/custom_wizard/api/endpoint_serializer.rb',
2019-12-05 09:05:21 +01:00
'../serializers/custom_wizard/api/log_serializer.rb',
'../serializers/custom_wizard/api_serializer.rb',
'../serializers/custom_wizard/basic_api_serializer.rb',
'../serializers/custom_wizard/wizard_field_serializer.rb',
'../serializers/custom_wizard/wizard_step_serializer.rb',
'../serializers/custom_wizard/wizard_serializer.rb',
'../serializers/site_serializer.rb'
].each do |path|
load File.expand_path(path, __FILE__)
end
2019-12-05 09:05:21 +01:00
add_class_method(:wizard, :user_requires_completion?) do |user|
wizard_result = self.new(user).requires_completion?
return wizard_result if wizard_result
2019-12-05 09:05:21 +01:00
custom_redirect = false
2019-12-05 09:05:21 +01:00
if user &&
user.first_seen_at.blank? &&
wizard_id = CustomWizard::Wizard.after_signup
wizard = CustomWizard::Wizard.create(user, wizard_id)
2017-10-15 05:58:22 +02:00
2019-12-05 09:05:21 +01:00
if !wizard.completed? && wizard.permitted?
custom_redirect = true
CustomWizard::Wizard.set_wizard_redirect(user, wizard_id)
end
end
2019-12-05 09:05:21 +01:00
!!custom_redirect
end
2019-12-05 09:05:21 +01:00
add_to_class(:users_controller, :wizard_path) do
if custom_wizard_redirect = current_user.custom_fields['redirect_to_wizard']
"#{Discourse.base_url}/w/#{custom_wizard_redirect.dasherize}"
else
"#{Discourse.base_url}/wizard"
2017-11-01 05:21:14 +01:00
end
end
2019-12-05 09:05:21 +01:00
add_to_serializer(:current_user, :redirect_to_wizard) do
object.custom_fields['redirect_to_wizard']
end
2018-01-16 08:13:50 +01:00
DiscourseEvent.on(:user_approved) do |user|
if wizard_id = CustomWizard::Wizard.after_signup
CustomWizard::Wizard.set_wizard_redirect(user, wizard_id)
end
end
2018-01-16 08:13:50 +01:00
DiscourseEvent.trigger(:custom_wizard_ready)
2017-09-23 04:34:07 +02:00
end