2017-09-23 10:34:07 +08:00
|
|
|
# name: discourse-custom-wizard
|
2017-10-05 08:36:46 +08:00
|
|
|
# about: Create custom wizards
|
2017-09-23 10:34:07 +08:00
|
|
|
# version: 0.1
|
|
|
|
# authors: Angus McLeod
|
2018-01-12 15:23:57 +08:00
|
|
|
# url: https://github.com/angusmcleod/discourse-custom-wizard
|
2017-09-23 10:34:07 +08:00
|
|
|
|
2017-10-13 21:02:34 +08:00
|
|
|
register_asset 'stylesheets/wizard_custom_admin.scss'
|
2017-11-01 12:21:14 +08:00
|
|
|
register_asset 'lib/jquery.timepicker.min.js'
|
|
|
|
register_asset 'lib/jquery.timepicker.scss'
|
2017-09-23 10:34:07 +08:00
|
|
|
|
2019-12-05 17:48:32 +11:00
|
|
|
enabled_site_setting :custom_wizard_enabled
|
|
|
|
|
2017-09-25 22:47:40 +08:00
|
|
|
config = Rails.application.config
|
2019-12-05 19:05:21 +11: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 22:47:40 +08:00
|
|
|
|
2017-11-01 19:47:27 +08:00
|
|
|
if Rails.env.production?
|
2017-12-03 15:57:54 +08:00
|
|
|
config.assets.precompile += %w{
|
2019-10-09 10:09:30 +11:00
|
|
|
wizard-custom-guest.js
|
2017-12-03 15:57:54 +08:00
|
|
|
wizard-custom-lib.js
|
|
|
|
wizard-custom.js
|
|
|
|
wizard-plugin.js
|
2019-01-18 11:34:52 +11:00
|
|
|
wizard-custom-start.js
|
2019-01-29 11:42:23 +11:00
|
|
|
wizard-raw-templates.js.erb
|
2017-12-03 15:57:54 +08:00
|
|
|
stylesheets/wizard/wizard_custom.scss
|
2018-02-08 12:30:55 +08:00
|
|
|
stylesheets/wizard/wizard_composer.scss
|
|
|
|
stylesheets/wizard/wizard_variables.scss
|
2017-12-03 15:57:54 +08:00
|
|
|
stylesheets/wizard/wizard_custom_mobile.scss
|
|
|
|
}
|
2017-11-01 19:47:27 +08:00
|
|
|
end
|
|
|
|
|
2019-02-20 17:27:17 +11: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 13:03:42 +11:00
|
|
|
|
2017-09-23 10:34:07 +08:00
|
|
|
after_initialize do
|
2019-12-05 17:48:32 +11:00
|
|
|
[
|
|
|
|
'../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 19:05:21 +11:00
|
|
|
'../controllers/application_controller.rb',
|
|
|
|
'../controllers/extra_locales_controller.rb',
|
|
|
|
'../controllers/invites_controller.rb',
|
2019-12-05 17:48:32 +11:00
|
|
|
'../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 19:05:21 +11:00
|
|
|
'../lib/wizard/choice.rb',
|
|
|
|
'../lib/wizard/field.rb',
|
|
|
|
'../lib/wizard/step.rb',
|
2019-12-05 17:48:32 +11:00
|
|
|
'../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 19:05:21 +11:00
|
|
|
'../serializers/custom_wizard/api/log_serializer.rb',
|
2019-12-12 15:43:11 +11:00
|
|
|
'../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'
|
2019-12-05 17:48:32 +11:00
|
|
|
].each do |path|
|
|
|
|
load File.expand_path(path, __FILE__)
|
|
|
|
end
|
|
|
|
|
2019-12-05 19:05:21 +11: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 17:48:32 +11:00
|
|
|
|
2019-12-05 19:05:21 +11:00
|
|
|
custom_redirect = false
|
2019-12-05 17:48:32 +11:00
|
|
|
|
2019-12-05 19:05:21 +11:00
|
|
|
if user &&
|
|
|
|
user.first_seen_at.blank? &&
|
|
|
|
wizard_id = CustomWizard::Wizard.after_signup
|
|
|
|
|
|
|
|
wizard = CustomWizard::Wizard.create(user, wizard_id)
|
2017-10-15 11:58:22 +08:00
|
|
|
|
2019-12-05 19:05:21 +11:00
|
|
|
if !wizard.completed? && wizard.permitted?
|
|
|
|
custom_redirect = true
|
|
|
|
CustomWizard::Wizard.set_wizard_redirect(user, wizard_id)
|
2019-12-05 17:48:32 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-05 19:05:21 +11:00
|
|
|
!!custom_redirect
|
2019-12-05 17:48:32 +11:00
|
|
|
end
|
|
|
|
|
2019-12-05 19:05:21 +11: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 12:21:14 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-05 19:05:21 +11:00
|
|
|
add_to_serializer(:current_user, :redirect_to_wizard) do
|
|
|
|
object.custom_fields['redirect_to_wizard']
|
2017-11-03 21:43:57 +08:00
|
|
|
end
|
2018-01-16 15:13:50 +08:00
|
|
|
|
2018-06-05 12:25:44 +10:00
|
|
|
DiscourseEvent.on(:user_approved) do |user|
|
|
|
|
if wizard_id = CustomWizard::Wizard.after_signup
|
2018-07-06 10:58:53 +10:00
|
|
|
CustomWizard::Wizard.set_wizard_redirect(user, wizard_id)
|
2018-06-05 12:25:44 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-16 15:13:50 +08:00
|
|
|
DiscourseEvent.trigger(:custom_wizard_ready)
|
2017-09-23 10:34:07 +08:00
|
|
|
end
|