0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-09 20:02:54 +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>
Dieser Commit ist enthalten in:
Faizaan Gagan 2021-09-22 13:52:05 +05:30 committet von GitHub
Ursprung 11192182e7
Commit 2678ee153d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
9 geänderte Dateien mit 81 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -14,6 +14,7 @@ const wizard = {
required: null,
prompt_completion: null,
restart_on_revisit: null,
resume_on_revisit: null,
theme_id: null,
permitted: null,
},

Datei anzeigen

@ -151,6 +151,16 @@
</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>
{{/if}}
</div>

Datei anzeigen

@ -15,6 +15,10 @@ const CustomWizard = EmberObject.extend({
}
CustomWizard.skip(this.id);
},
restart() {
CustomWizard.restart(this.id);
},
});
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) {
let url = "/";
if (result.redirect_on_complete) {

Datei anzeigen

@ -2,6 +2,7 @@
import { findCustomWizard, updateCachedWizard } from "../models/custom";
import { ajax } from "wizard/lib/ajax";
import WizardI18n from "../lib/wizard-i18n";
export default Ember.Route.extend({
beforeModel(transition) {
@ -12,6 +13,48 @@ export default Ember.Route.extend({
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) {
updateCachedWizard(model);

Datei anzeigen

@ -35,6 +35,8 @@ en:
prompt_completion_label: "Prompt user to complete wizard."
restart_on_revisit: "Restart"
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"
no_theme: "Select a Theme (optional)"
save: "Save Changes"
@ -496,6 +498,10 @@ en:
requires_login: "You need to be logged in to access this wizard."
reset: "Reset this wizard."
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:
one: "%{count} Character"
other: "%{count} Characters"

Datei anzeigen

@ -79,6 +79,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
:required,
:prompt_completion,
:restart_on_revisit,
:resume_on_revisit,
:theme_id,
permitted: mapped_params,
steps: [

Datei anzeigen

@ -21,6 +21,7 @@ class CustomWizard::Wizard
:required,
:prompt_completion,
:restart_on_revisit,
:resume_on_revisit,
:permitted,
:needs_categories,
:needs_groups,
@ -47,6 +48,7 @@ class CustomWizard::Wizard
@multiple_submissions = cast_bool(attrs['multiple_submissions'])
@prompt_completion = cast_bool(attrs['prompt_completion'])
@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_time = cast_bool(attrs['after_time'])
@after_time_scheduled = attrs['after_time_scheduled']

Datei anzeigen

@ -1,7 +1,7 @@
# frozen_string_literal: true
# name: discourse-custom-wizard
# about: Create custom wizards
# version: 1.13.34
# version: 1.14.0
# authors: Angus McLeod
# url: https://github.com/paviliondev/discourse-custom-wizard
# contact emails: angus@thepavilion.io

Datei anzeigen

@ -4,12 +4,14 @@ class CustomWizard::WizardSerializer < CustomWizard::BasicWizardSerializer
attributes :start,
:background,
:submission_last_updated_at,
:theme_id,
:completed,
:required,
:permitted,
:uncategorized_category_id,
:categories
:categories,
:resume_on_revisit
has_many :steps, serializer: ::CustomWizard::StepSerializer, embed: :objects
has_one :user, serializer: ::BasicUserSerializer, embed: :objects
@ -37,6 +39,10 @@ class CustomWizard::WizardSerializer < CustomWizard::BasicWizardSerializer
include_steps? && object.start.present?
end
def submission_last_updated_at
object.current_submission.updated_at
end
def include_steps?
!include_completed?
end