1
0
Fork 0

Add prompt completion feature

Dieser Commit ist enthalten in:
Angus McLeod 2017-11-22 17:34:21 +08:00
Ursprung c40bf06953
Commit b45d26c143
9 geänderte Dateien mit 127 neuen und 17 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,25 @@
import { withPluginApi } from 'discourse/lib/plugin-api';
export default {
name: 'custom-wizard-edits',
initialize() {
withPluginApi('0.8.12', api => {
api.modifyClass('component:global-notice', {
buildBuffer(buffer) {
this._super(...arguments);
const wizards = this.site.get('complete_custom_wizard');
if (wizards) {
wizards.forEach((w) => {
const text = I18n.t('wizard.complete_custom', {
wizard_url: w.url,
wizard_name: w.name,
site_name: this.siteSettings.title
});
buffer.push(`<div class='row'><div class='alert alert-info alert-wizard'>${text}</div></div>`);
});
}
}
});
});
}
};

Datei anzeigen

@ -8,7 +8,8 @@ const wizardProperties = [
'after_signup', 'after_signup',
'after_time', 'after_time',
'after_time_scheduled', 'after_time_scheduled',
'required' 'required',
'prompt_completion'
]; ];
const CustomWizard = Discourse.Model.extend({ const CustomWizard = Discourse.Model.extend({
@ -235,6 +236,7 @@ CustomWizard.reopenClass({
props['after_signup'] = false; props['after_signup'] = false;
props['after_time'] = false; props['after_time'] = false;
props['required'] = false; props['required'] = false;
props['prompt_completion'] = false;
props['steps'] = Ember.A(); props['steps'] = Ember.A();
}; };

Datei anzeigen

@ -82,6 +82,16 @@
</div> </div>
</div> </div>
<div class="setting">
<div class="setting-label">
<h3>{{i18n 'admin.wizard.prompt_completion'}}</h3>
</div>
<div class="setting-value">
{{input type='checkbox' checked=model.prompt_completion}}
<span for="save">{{i18n 'admin.wizard.prompt_completion_label'}}</span>
</div>
</div>
<div class="setting full"> <div class="setting full">
<div class="setting-label"> <div class="setting-label">
<h3>{{i18n 'admin.wizard.url'}}</h3> <h3>{{i18n 'admin.wizard.url'}}</h3>

Datei anzeigen

@ -1,6 +1,10 @@
.custom-wizard { .custom-wizard {
background-color: initial; background-color: initial;
.wizard-step-contents {
position: relative;
}
.wizard-step-description { .wizard-step-description {
line-height: 1.7; line-height: 1.7;
@ -15,7 +19,18 @@
} }
.image-container { .image-container {
margin: 10px 0; margin: 30px 0;
padding: 0 40px;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
&.group {
padding: 0;
margin: 0;
width: 140px;
height: 140px;
}
} }
img.large { img.large {
@ -27,6 +42,29 @@
width: 120; width: 120;
padding: 10px; padding: 10px;
} }
img.x-small {
width: 60px;
height: 60px;
padding: 3px;
}
label {
display: block;
text-align: center;
}
.tip {
position: absolute;
bottom: 0;
font-style: italic;
img {
width: 30px;
height: 30px;
vertical-align: middle;
}
}
} }
.wizard-column .wizard-step-banner { .wizard-column .wizard-step-banner {
@ -88,6 +126,7 @@
line-height: 0; line-height: 0;
text-align: center; text-align: center;
transition: all .2s; transition: all .2s;
z-index: 2;
&.success { &.success {
height: 60px; height: 60px;
@ -190,15 +229,3 @@
transform: rotate(360deg); transform: rotate(360deg);
} }
} }
// 3rd party styles TO BE REMOVED / REFACTORED
#custom-wizard-main.place-petition {
.wizard-step.intro .image-container {
margin: 30px 0;
img {
padding: 20px 40px;
}
}
}

Datei anzeigen

@ -1,4 +1,7 @@
en: en:
js:
wizard:
complete_custom: "Welcome to %{site_name}! Get started with <a href='%{wizard_url}' data-auto-route='true'>the %{wizard_name} wizard</a> ✨"
admin_js: admin_js:
admin: admin:
wizard: wizard:
@ -27,6 +30,8 @@ en:
clear: "Clear" clear: "Clear"
required: "Required" required: "Required"
required_label: "Users cannot skip the wizard." required_label: "Users cannot skip the wizard."
prompt_completion: "Prompt"
prompt_completion_label: "Prompt user to complete wizard."
save: "Save Changes" save: "Save Changes"
remove: "Delete Wizard" remove: "Delete Wizard"
header: "Wizard" header: "Wizard"

Datei anzeigen

@ -6,6 +6,7 @@ class CustomWizard::Template
:background, :background,
:save_submissions, :save_submissions,
:multiple_submissions, :multiple_submissions,
:prompt_completion,
:after_signup, :after_signup,
:after_time, :after_time,
:after_time_scheduled, :after_time_scheduled,
@ -19,9 +20,10 @@ class CustomWizard::Template
@background = data['background'] @background = data['background']
@save_submissions = data['save_submissions'] || false @save_submissions = data['save_submissions'] || false
@multiple_submissions = data['multiple_submissions'] || false @multiple_submissions = data['multiple_submissions'] || false
@prompt_completion = data['prompt_completion'] || false
@after_signup = data['after_signup'] @after_signup = data['after_signup']
@after_time = data['after_time'] @after_time = data['after_time']
@after_time_scheduled = data['after_time_scheduled'] @after_time_scheduled = data['after_time_scheduled']
@required = data['required'] @required = data['required'] || false
end end
end end

Datei anzeigen

@ -13,7 +13,8 @@ class CustomWizard::Wizard
:multiple_submissions, :multiple_submissions,
:after_time, :after_time,
:after_signup, :after_signup,
:required :required,
:prompt_completion
def initialize(user, attrs = {}) def initialize(user, attrs = {})
@steps = [] @steps = []
@ -116,6 +117,22 @@ class CustomWizard::Wizard
end end
end end
def self.prompt_completion(user)
rows = PluginStoreRow.where(plugin_name: 'custom_wizard')
wizards = [*rows].select { |r| r.value['prompt_completion'] }
if wizards.any?
wizards.reduce([]) do |result, w|
data = ::JSON.parse(w.value)
id = data['id']
name = data['name']
wizard = CustomWizard::Wizard.new(user, id: id, name: name)
result.push(id: id, name: name) if !wizard.completed?
end
else
false
end
end
def self.steps(wizard_id) def self.steps(wizard_id)
wizard = PluginStore.get('custom_wizard', wizard_id) wizard = PluginStore.get('custom_wizard', wizard_id)
wizard ? wizard['steps'] : nil wizard ? wizard['steps'] : nil

Datei anzeigen

@ -71,7 +71,9 @@ end
end end
def include_completed? def include_completed?
object.completed? && !object.multiple_submissions && !scope.current_user.admin? object.completed? &&
(!object.respond_to?(:multiple_submissions) || !object.multiple_submissions) &&
!scope.current_user.admin?
end end
def include_start? def include_start?
@ -89,6 +91,14 @@ end
def include_required? def include_required?
object.respond_to?(:required) object.respond_to?(:required)
end end
def prompt_completion
object.prompt_completion
end
def include_prompt_completion?
object.respond_to?(:prompt_completion)
end
end end
::WizardStepSerializer.class_eval do ::WizardStepSerializer.class_eval do

Datei anzeigen

@ -112,8 +112,20 @@ after_initialize do
## TODO limit this to the first admin ## TODO limit this to the first admin
SiteSerializer.class_eval do SiteSerializer.class_eval do
attributes :complete_custom_wizard
def include_wizard_required? def include_wizard_required?
scope.is_admin? && Wizard.user_requires_completion?(scope.user) scope.is_admin? && Wizard.user_requires_completion?(scope.user)
end end
def complete_custom_wizard
if requires_completion = CustomWizard::Wizard.prompt_completion(scope.user)
requires_completion.map { |w| { name: w[:name], url: "/w/#{w[:id]}" } }
end
end
def include_complete_custom_wizard?
complete_custom_wizard.present?
end
end end
end end