Merge pull request #1 from angusmcleod/master
bring my fork up to date
Dieser Commit ist enthalten in:
Commit
d607c5cd08
14 geänderte Dateien mit 81 neuen und 36 gelöschten Zeilen
|
@ -10,4 +10,4 @@ export default Ember.Component.extend({
|
||||||
CustomWizard.skip(this.get('wizardId'));
|
CustomWizard.skip(this.get('wizardId'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
queryParams: ['reset']
|
queryParams: ['reset']
|
||||||
})
|
});
|
||||||
|
|
|
@ -71,6 +71,10 @@ export default {
|
||||||
return index === 0 && !required;
|
return index === 0 && !required;
|
||||||
}.property('step.index', 'wizard.required'),
|
}.property('step.index', 'wizard.required'),
|
||||||
|
|
||||||
|
cookedTitle: function() {
|
||||||
|
return cook(this.get('step.title'));
|
||||||
|
}.property('step.title'),
|
||||||
|
|
||||||
cookedDescription: function() {
|
cookedDescription: function() {
|
||||||
return cook(this.get('step.description'));
|
return cook(this.get('step.description'));
|
||||||
}.property('step.description'),
|
}.property('step.description'),
|
||||||
|
|
|
@ -37,7 +37,6 @@ export function findCustomWizard(wizardId, opts = {}) {
|
||||||
|
|
||||||
return ajax({ url, cache: false, dataType: 'json' }).then(result => {
|
return ajax({ url, cache: false, dataType: 'json' }).then(result => {
|
||||||
const wizard = result.wizard;
|
const wizard = result.wizard;
|
||||||
|
|
||||||
if (!wizard) return null;
|
if (!wizard) return null;
|
||||||
|
|
||||||
if (!wizard.completed) {
|
if (!wizard.completed) {
|
||||||
|
|
|
@ -16,8 +16,13 @@ export default Ember.Route.extend({
|
||||||
const permitted = model.get('permitted');
|
const permitted = model.get('permitted');
|
||||||
const minTrust = model.get('min_trust');
|
const minTrust = model.get('min_trust');
|
||||||
const wizardId = model.get('id');
|
const wizardId = model.get('id');
|
||||||
|
const user = model.get('user');
|
||||||
|
const name = model.get('name');
|
||||||
|
|
||||||
controller.setProperties({
|
controller.setProperties({
|
||||||
|
requiresLogin: !user,
|
||||||
|
user,
|
||||||
|
name,
|
||||||
completed,
|
completed,
|
||||||
notPermitted: !permitted,
|
notPermitted: !permitted,
|
||||||
minTrust,
|
minTrust,
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { ajax } from 'wizard/lib/ajax';
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
model(params) {
|
model(params) {
|
||||||
let opts = {};
|
let opts = {};
|
||||||
if (params.reset == 'true') opts['reset'] = true;
|
if (params.reset === 'true') opts['reset'] = true;
|
||||||
return findCustomWizard(params.wizard_id, opts);
|
return findCustomWizard(params.wizard_id, opts);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<div class='wizard-step-contents'>
|
<div class='wizard-step-contents'>
|
||||||
{{#if step.title}}
|
{{#if step.title}}
|
||||||
<h1 class='wizard-step-title'>{{step.title}}</h1>
|
<h1 class='wizard-step-title'>{{cookedTitle}}</h1>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if step.description}}
|
{{#if step.description}}
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
{{#if completed}}
|
{{#if noWizard}}
|
||||||
{{wizard-no-access text=(i18n 'wizard.completed') wizardId=wizardId}}
|
{{wizard-no-access text=(i18n 'wizard.none') wizardId=wizardId}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{#if notPermitted}}
|
{{#if requiresLogin}}
|
||||||
{{wizard-no-access text=(i18n 'wizard.not_permitted' level=minTrust) wizardId=wizardId}}
|
{{wizard-no-access text=(i18n 'wizard.requires_login' name=name) wizardId=wizardId}}
|
||||||
{{/if}}
|
{{else}}
|
||||||
{{#if noWizard}}
|
{{#if notPermitted}}
|
||||||
{{wizard-no-access text=(i18n 'wizard.none') wizardId=wizardId}}
|
{{wizard-no-access text=(i18n 'wizard.not_permitted' name=name level=minTrust) wizardId=wizardId}}
|
||||||
|
{{else}}
|
||||||
|
{{#if completed}}
|
||||||
|
{{wizard-no-access text=(i18n 'wizard.completed' name=name) wizardId=wizardId}}
|
||||||
|
{{/if}}
|
||||||
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -157,7 +157,12 @@
|
||||||
////
|
////
|
||||||
|
|
||||||
.d-editor {
|
.d-editor {
|
||||||
max-height: 250px;
|
min-height: 200px;
|
||||||
|
|
||||||
|
.d-editor-input {
|
||||||
|
resize: vertical;
|
||||||
|
flex: initial;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.d-editor-modal.hidden {
|
.d-editor-modal.hidden {
|
||||||
|
|
|
@ -177,10 +177,11 @@ en:
|
||||||
filter_placeholder: "Search..."
|
filter_placeholder: "Search..."
|
||||||
|
|
||||||
wizard:
|
wizard:
|
||||||
completed: "You have completed this wizard."
|
completed: "You have completed the {{name}} wizard."
|
||||||
not_permitted: "You need to be trust level {{level}} or higher to access this wizard."
|
not_permitted: "You need to be trust level {{level}} or higher to access the {{name}} wizard."
|
||||||
none: "There is no wizard here."
|
none: "There is no wizard here."
|
||||||
return_to_site: "Return to {{siteName}}"
|
return_to_site: "Return to {{siteName}}"
|
||||||
|
requires_login: "You need to be logged in to access the {{name}} wizard."
|
||||||
|
|
||||||
wizard_composer:
|
wizard_composer:
|
||||||
show_preview: "Preview Post"
|
show_preview: "Preview Post"
|
||||||
|
|
|
@ -2,7 +2,6 @@ class CustomWizard::WizardController < ::ApplicationController
|
||||||
prepend_view_path(Rails.root.join('plugins', 'discourse-custom-wizard', 'views'))
|
prepend_view_path(Rails.root.join('plugins', 'discourse-custom-wizard', 'views'))
|
||||||
layout 'wizard'
|
layout 'wizard'
|
||||||
|
|
||||||
requires_login
|
|
||||||
helper_method :wizard_page_title
|
helper_method :wizard_page_title
|
||||||
helper_method :theme_ids
|
helper_method :theme_ids
|
||||||
|
|
||||||
|
@ -22,7 +21,6 @@ class CustomWizard::WizardController < ::ApplicationController
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
builder = CustomWizard::Builder.new(current_user, params[:wizard_id].underscore)
|
builder = CustomWizard::Builder.new(current_user, params[:wizard_id].underscore)
|
||||||
|
|
||||||
builder_opts = {}
|
builder_opts = {}
|
||||||
builder_opts[:reset] = params[:reset] if params[:reset]
|
builder_opts[:reset] = params[:reset] if params[:reset]
|
||||||
|
|
||||||
|
@ -52,19 +50,22 @@ class CustomWizard::WizardController < ::ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
result = success_json
|
result = success_json
|
||||||
submission = Array.wrap(PluginStore.get("#{wizard_id}_submissions", user.id)).last
|
|
||||||
|
|
||||||
if submission && submission['redirect_to']
|
if user
|
||||||
result.merge!(redirect_to: submission['redirect_to'])
|
submission = Array.wrap(PluginStore.get("#{wizard_id}_submissions", user.id)).last
|
||||||
end
|
|
||||||
|
|
||||||
if submission && !wizard.save_submissions
|
if submission && submission['redirect_to']
|
||||||
PluginStore.remove("#{wizard_id}_submissions", user.id)
|
result.merge!(redirect_to: submission['redirect_to'])
|
||||||
end
|
end
|
||||||
|
|
||||||
if user.custom_fields['redirect_to_wizard'] === wizard_id
|
if submission && !wizard.save_submissions
|
||||||
user.custom_fields.delete('redirect_to_wizard')
|
PluginStore.remove("#{wizard_id}_submissions", user.id)
|
||||||
user.save_custom_fields(true)
|
end
|
||||||
|
|
||||||
|
if user.custom_fields['redirect_to_wizard'] === wizard_id
|
||||||
|
user.custom_fields.delete('redirect_to_wizard')
|
||||||
|
user.save_custom_fields(true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: result
|
render json: result
|
||||||
|
|
|
@ -2,14 +2,16 @@ class CustomWizard::Builder
|
||||||
|
|
||||||
attr_accessor :wizard, :updater, :submissions
|
attr_accessor :wizard, :updater, :submissions
|
||||||
|
|
||||||
def initialize(user, wizard_id)
|
def initialize(user=nil, wizard_id)
|
||||||
data = PluginStore.get('custom_wizard', wizard_id)
|
data = PluginStore.get('custom_wizard', wizard_id)
|
||||||
|
|
||||||
return if data.blank?
|
return if data.blank?
|
||||||
|
|
||||||
@steps = data['steps']
|
@steps = data['steps']
|
||||||
@wizard = CustomWizard::Wizard.new(user, data)
|
@wizard = CustomWizard::Wizard.new(user, data)
|
||||||
@submissions = Array.wrap(PluginStore.get("#{wizard_id}_submissions", user.id))
|
|
||||||
|
if user
|
||||||
|
@submissions = Array.wrap(PluginStore.get("#{wizard_id}_submissions", user.id))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.sorted_handlers
|
def self.sorted_handlers
|
||||||
|
@ -227,7 +229,11 @@ class CustomWizard::Builder
|
||||||
|
|
||||||
def validate_field(field, updater, step_template)
|
def validate_field(field, updater, step_template)
|
||||||
value = updater.fields[field['id']]
|
value = updater.fields[field['id']]
|
||||||
min_length = field['min_length']
|
min_length = false
|
||||||
|
|
||||||
|
if is_text_type(field)
|
||||||
|
min_length = field['min_length']
|
||||||
|
end
|
||||||
|
|
||||||
if min_length && value.is_a?(String) && value.strip.length < min_length.to_i
|
if min_length && value.is_a?(String) && value.strip.length < min_length.to_i
|
||||||
label = field['label'] || I18n.t("#{field['key']}.label")
|
label = field['label'] || I18n.t("#{field['key']}.label")
|
||||||
|
@ -246,6 +252,10 @@ class CustomWizard::Builder
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_text_type(field)
|
||||||
|
['text', 'textarea'].include? field['type']
|
||||||
|
end
|
||||||
|
|
||||||
def standardise_boolean(value)
|
def standardise_boolean(value)
|
||||||
!!HasCustomFields::Helpers::CUSTOM_FIELD_TRUE.include?(value)
|
!!HasCustomFields::Helpers::CUSTOM_FIELD_TRUE.include?(value)
|
||||||
end
|
end
|
||||||
|
@ -309,6 +319,7 @@ class CustomWizard::Builder
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
value = [value] if key === 'tags'
|
||||||
params[key.to_sym] = value
|
params[key.to_sym] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@ class CustomWizard::Wizard
|
||||||
:required,
|
:required,
|
||||||
:prompt_completion
|
:prompt_completion
|
||||||
|
|
||||||
def initialize(user, attrs = {})
|
def initialize(user=nil, attrs = {})
|
||||||
@steps = []
|
@steps = []
|
||||||
@user = user
|
@user = user
|
||||||
@first_step = nil
|
@first_step = nil
|
||||||
|
@ -54,6 +54,8 @@ class CustomWizard::Wizard
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
|
return nil if !@user
|
||||||
|
|
||||||
if unfinished? && last_completed_step = ::UserHistory.where(
|
if unfinished? && last_completed_step = ::UserHistory.where(
|
||||||
acting_user_id: @user.id,
|
acting_user_id: @user.id,
|
||||||
action: ::UserHistory.actions[:custom_wizard_step],
|
action: ::UserHistory.actions[:custom_wizard_step],
|
||||||
|
@ -76,6 +78,8 @@ class CustomWizard::Wizard
|
||||||
end
|
end
|
||||||
|
|
||||||
def unfinished?
|
def unfinished?
|
||||||
|
return nil if !@user
|
||||||
|
|
||||||
most_recent = ::UserHistory.where(
|
most_recent = ::UserHistory.where(
|
||||||
acting_user_id: @user.id,
|
acting_user_id: @user.id,
|
||||||
action: ::UserHistory.actions[:custom_wizard_step],
|
action: ::UserHistory.actions[:custom_wizard_step],
|
||||||
|
@ -94,6 +98,8 @@ class CustomWizard::Wizard
|
||||||
end
|
end
|
||||||
|
|
||||||
def completed?
|
def completed?
|
||||||
|
return nil if !@user
|
||||||
|
|
||||||
steps = CustomWizard::Wizard.step_ids(@id)
|
steps = CustomWizard::Wizard.step_ids(@id)
|
||||||
|
|
||||||
history = ::UserHistory.where(
|
history = ::UserHistory.where(
|
||||||
|
@ -112,7 +118,7 @@ class CustomWizard::Wizard
|
||||||
end
|
end
|
||||||
|
|
||||||
def permitted?
|
def permitted?
|
||||||
user.staff? || user.trust_level.to_i >= min_trust.to_i
|
user && (user.staff? || user.trust_level.to_i >= min_trust.to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset
|
def reset
|
||||||
|
|
|
@ -64,7 +64,7 @@ class ::Wizard::Step
|
||||||
end
|
end
|
||||||
|
|
||||||
::WizardSerializer.class_eval do
|
::WizardSerializer.class_eval do
|
||||||
attributes :id, :background, :completed, :required, :min_trust, :permitted
|
attributes :id, :name, :background, :completed, :required, :min_trust, :permitted, :user
|
||||||
|
|
||||||
def id
|
def id
|
||||||
object.id
|
object.id
|
||||||
|
@ -74,6 +74,10 @@ end
|
||||||
object.respond_to?(:id)
|
object.respond_to?(:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def name
|
||||||
|
object.name
|
||||||
|
end
|
||||||
|
|
||||||
def background
|
def background
|
||||||
object.background
|
object.background
|
||||||
end
|
end
|
||||||
|
@ -123,12 +127,16 @@ end
|
||||||
def include_required?
|
def include_required?
|
||||||
object.respond_to?(:required)
|
object.respond_to?(:required)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def user
|
||||||
|
object.user
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
::WizardStepSerializer.class_eval do
|
::WizardStepSerializer.class_eval do
|
||||||
def title
|
def title
|
||||||
return object.title if object.title
|
return PrettyText.cook(object.title) if object.title
|
||||||
I18n.t("#{object.key || i18n_key}.title", default: '')
|
PrettyText.cook(I18n.t("#{object.key || i18n_key}.title", default: ''))
|
||||||
end
|
end
|
||||||
|
|
||||||
def description
|
def description
|
||||||
|
|
Laden …
In neuem Issue referenzieren