Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-26 19:10:29 +01:00
FEATURE: add resume wizard popup (#146)
* FEATURE: add resume wizard popup
* code cleanup, copy edits
* FIX: address functionality, setting and copy issues
@fzngagan a few issues fixed
1. The resume button wasn't working (old reference to ``resumeDialog`` remained in callback.
2. This needs a wizard setting
3. It's not necessary to serialize the first step separately. We have all the steps in ``steps`` and steps have indexes.
4. Button copy
* Fix linting
* Ensure aa submission exists
* Apply prettier
Co-authored-by: angusmcleod <angus@mcleod.org.au>
(cherry picked from commit 2678ee153d
)
Dieser Commit ist enthalten in:
Ursprung
de2faf893f
Commit
21cf81b7a5
8 geänderte Dateien mit 80 neuen und 1 gelöschten Zeilen
|
@ -14,6 +14,7 @@ const wizard = {
|
||||||
required: null,
|
required: null,
|
||||||
prompt_completion: null,
|
prompt_completion: null,
|
||||||
restart_on_revisit: null,
|
restart_on_revisit: null,
|
||||||
|
resume_on_revisit: null,
|
||||||
theme_id: null,
|
theme_id: null,
|
||||||
permitted: null,
|
permitted: null,
|
||||||
},
|
},
|
||||||
|
|
|
@ -151,6 +151,16 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="setting">
|
||||||
|
<div class="setting-label">
|
||||||
|
<label>{{i18n "admin.wizard.resume_on_revisit"}}</label>
|
||||||
|
</div>
|
||||||
|
<div class="setting-value">
|
||||||
|
{{input type="checkbox" checked=wizard.resume_on_revisit}}
|
||||||
|
<span>{{i18n "admin.wizard.resume_on_revisit_label"}}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -15,6 +15,10 @@ const CustomWizard = EmberObject.extend({
|
||||||
}
|
}
|
||||||
CustomWizard.skip(this.id);
|
CustomWizard.skip(this.id);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
restart() {
|
||||||
|
CustomWizard.restart(this.id);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
CustomWizard.reopenClass({
|
CustomWizard.reopenClass({
|
||||||
|
@ -24,6 +28,12 @@ CustomWizard.reopenClass({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
restart(wizardId) {
|
||||||
|
ajax({ url: `/w/${wizardId}/skip`, type: "PUT" }).then(() => {
|
||||||
|
window.location.href = `/w/${wizardId}`;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
finished(result) {
|
finished(result) {
|
||||||
let url = "/";
|
let url = "/";
|
||||||
if (result.redirect_on_complete) {
|
if (result.redirect_on_complete) {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import { findCustomWizard, updateCachedWizard } from "../models/custom";
|
import { findCustomWizard, updateCachedWizard } from "../models/custom";
|
||||||
import { ajax } from "wizard/lib/ajax";
|
import { ajax } from "wizard/lib/ajax";
|
||||||
|
import WizardI18n from "../lib/wizard-i18n";
|
||||||
|
|
||||||
export default Ember.Route.extend({
|
export default Ember.Route.extend({
|
||||||
beforeModel(transition) {
|
beforeModel(transition) {
|
||||||
|
@ -12,6 +13,48 @@ export default Ember.Route.extend({
|
||||||
return findCustomWizard(params.wizard_id, this.get("queryParams"));
|
return findCustomWizard(params.wizard_id, this.get("queryParams"));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
renderTemplate() {
|
||||||
|
this.render("custom");
|
||||||
|
const wizardModel = this.modelFor("custom");
|
||||||
|
const stepModel = this.modelFor("custom.step");
|
||||||
|
|
||||||
|
if (
|
||||||
|
wizardModel.resume_on_revisit &&
|
||||||
|
wizardModel.submission_last_updated_at &&
|
||||||
|
stepModel.index > 0
|
||||||
|
) {
|
||||||
|
this.showDialog(wizardModel);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
showDialog(wizardModel) {
|
||||||
|
const title = WizardI18n("wizard.incomplete_submission.title", {
|
||||||
|
date: moment(wizardModel.submission_last_updated_at).format(
|
||||||
|
"MMMM Do YYYY"
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
const buttons = [
|
||||||
|
{
|
||||||
|
label: WizardI18n("wizard.incomplete_submission.restart"),
|
||||||
|
class: "btn btn-default",
|
||||||
|
callback: () => {
|
||||||
|
wizardModel.restart();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: WizardI18n("wizard.incomplete_submission.resume"),
|
||||||
|
class: "btn btn-primary",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
onEscape: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
bootbox.dialog(title, buttons, options);
|
||||||
|
},
|
||||||
|
|
||||||
afterModel(model) {
|
afterModel(model) {
|
||||||
updateCachedWizard(model);
|
updateCachedWizard(model);
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@ en:
|
||||||
prompt_completion_label: "Prompt user to complete wizard."
|
prompt_completion_label: "Prompt user to complete wizard."
|
||||||
restart_on_revisit: "Restart"
|
restart_on_revisit: "Restart"
|
||||||
restart_on_revisit_label: "Clear submissions on each visit."
|
restart_on_revisit_label: "Clear submissions on each visit."
|
||||||
|
resume_on_revisit: "Resume"
|
||||||
|
resume_on_revisit_label: "Ask the user if they want to resume on each visit."
|
||||||
theme_id: "Theme"
|
theme_id: "Theme"
|
||||||
no_theme: "Select a Theme (optional)"
|
no_theme: "Select a Theme (optional)"
|
||||||
save: "Save Changes"
|
save: "Save Changes"
|
||||||
|
@ -496,6 +498,10 @@ en:
|
||||||
requires_login: "You need to be logged in to access this wizard."
|
requires_login: "You need to be logged in to access this wizard."
|
||||||
reset: "Reset this wizard."
|
reset: "Reset this wizard."
|
||||||
step_not_permitted: "You're not permitted to view this step."
|
step_not_permitted: "You're not permitted to view this step."
|
||||||
|
incomplete_submission:
|
||||||
|
title: "Continue editing your draft submission from %{date}?"
|
||||||
|
resume: "Continue"
|
||||||
|
restart: "Start over"
|
||||||
x_characters:
|
x_characters:
|
||||||
one: "%{count} Character"
|
one: "%{count} Character"
|
||||||
other: "%{count} Characters"
|
other: "%{count} Characters"
|
||||||
|
|
|
@ -79,6 +79,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
|
||||||
:required,
|
:required,
|
||||||
:prompt_completion,
|
:prompt_completion,
|
||||||
:restart_on_revisit,
|
:restart_on_revisit,
|
||||||
|
:resume_on_revisit,
|
||||||
:theme_id,
|
:theme_id,
|
||||||
permitted: mapped_params,
|
permitted: mapped_params,
|
||||||
steps: [
|
steps: [
|
||||||
|
|
|
@ -21,6 +21,7 @@ class CustomWizard::Wizard
|
||||||
:required,
|
:required,
|
||||||
:prompt_completion,
|
:prompt_completion,
|
||||||
:restart_on_revisit,
|
:restart_on_revisit,
|
||||||
|
:resume_on_revisit,
|
||||||
:permitted,
|
:permitted,
|
||||||
:needs_categories,
|
:needs_categories,
|
||||||
:needs_groups,
|
:needs_groups,
|
||||||
|
@ -47,6 +48,7 @@ class CustomWizard::Wizard
|
||||||
@multiple_submissions = cast_bool(attrs['multiple_submissions'])
|
@multiple_submissions = cast_bool(attrs['multiple_submissions'])
|
||||||
@prompt_completion = cast_bool(attrs['prompt_completion'])
|
@prompt_completion = cast_bool(attrs['prompt_completion'])
|
||||||
@restart_on_revisit = cast_bool(attrs['restart_on_revisit'])
|
@restart_on_revisit = cast_bool(attrs['restart_on_revisit'])
|
||||||
|
@resume_on_revisit = cast_bool(attrs['resume_on_revisit'])
|
||||||
@after_signup = cast_bool(attrs['after_signup'])
|
@after_signup = cast_bool(attrs['after_signup'])
|
||||||
@after_time = cast_bool(attrs['after_time'])
|
@after_time = cast_bool(attrs['after_time'])
|
||||||
@after_time_scheduled = attrs['after_time_scheduled']
|
@after_time_scheduled = attrs['after_time_scheduled']
|
||||||
|
|
|
@ -4,12 +4,14 @@ class CustomWizard::WizardSerializer < CustomWizard::BasicWizardSerializer
|
||||||
|
|
||||||
attributes :start,
|
attributes :start,
|
||||||
:background,
|
:background,
|
||||||
|
:submission_last_updated_at,
|
||||||
:theme_id,
|
:theme_id,
|
||||||
:completed,
|
:completed,
|
||||||
:required,
|
:required,
|
||||||
:permitted,
|
:permitted,
|
||||||
:uncategorized_category_id,
|
:uncategorized_category_id,
|
||||||
:categories
|
:categories,
|
||||||
|
:resume_on_revisit
|
||||||
|
|
||||||
has_many :steps, serializer: ::CustomWizard::StepSerializer, embed: :objects
|
has_many :steps, serializer: ::CustomWizard::StepSerializer, embed: :objects
|
||||||
has_one :user, serializer: ::BasicUserSerializer, embed: :objects
|
has_one :user, serializer: ::BasicUserSerializer, embed: :objects
|
||||||
|
@ -37,6 +39,10 @@ class CustomWizard::WizardSerializer < CustomWizard::BasicWizardSerializer
|
||||||
include_steps? && object.start.present?
|
include_steps? && object.start.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def submission_last_updated_at
|
||||||
|
object.current_submission.updated_at
|
||||||
|
end
|
||||||
|
|
||||||
def include_steps?
|
def include_steps?
|
||||||
!include_completed?
|
!include_completed?
|
||||||
end
|
end
|
||||||
|
|
Laden …
In neuem Issue referenzieren