mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 02:44:39 +08:00
DEV: Make wizard an ember addon (#17027)
Co-authored-by: David Taylor <david@taylorhq.com>
This commit is contained in:
64
app/assets/javascripts/wizard/addon/models/wizard.js
Normal file
64
app/assets/javascripts/wizard/addon/models/wizard.js
Normal file
@ -0,0 +1,64 @@
|
||||
import EmberObject from "@ember/object";
|
||||
import Evented from "@ember/object/evented";
|
||||
import Step from "wizard/models/step";
|
||||
import WizardField from "wizard/models/wizard-field";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import { readOnly } from "@ember/object/computed";
|
||||
|
||||
const Wizard = EmberObject.extend(Evented, {
|
||||
totalSteps: readOnly("steps.length"),
|
||||
|
||||
getTitle() {
|
||||
const titleStep = this.steps.findBy("id", "forum-title");
|
||||
if (!titleStep) {
|
||||
return;
|
||||
}
|
||||
return titleStep.get("fieldsById.title.value");
|
||||
},
|
||||
|
||||
getLogoUrl() {
|
||||
const logoStep = this.steps.findBy("id", "logos");
|
||||
if (!logoStep) {
|
||||
return;
|
||||
}
|
||||
return logoStep.get("fieldsById.logo.value");
|
||||
},
|
||||
|
||||
get currentColors() {
|
||||
const colorStep = this.steps.findBy("id", "styling");
|
||||
if (!colorStep) {
|
||||
return this.current_color_scheme;
|
||||
}
|
||||
|
||||
const themeChoice = colorStep.fieldsById.color_scheme;
|
||||
if (!themeChoice) {
|
||||
return;
|
||||
}
|
||||
|
||||
return themeChoice.choices?.findBy("id", themeChoice.value)?.data.colors;
|
||||
},
|
||||
|
||||
get font() {
|
||||
const fontChoice = this.steps.findBy("id", "styling")?.fieldsById
|
||||
?.body_font;
|
||||
return fontChoice.choices?.findBy("id", fontChoice.value)?.label;
|
||||
},
|
||||
|
||||
get headingFont() {
|
||||
const fontChoice = this.steps.findBy("id", "styling")?.fieldsById
|
||||
?.heading_font;
|
||||
return fontChoice.choices?.findBy("id", fontChoice.value)?.label;
|
||||
},
|
||||
});
|
||||
|
||||
export function findWizard() {
|
||||
return ajax({ url: "/wizard.json" }).then(({ wizard }) => {
|
||||
wizard.steps = wizard.steps.map((step) => {
|
||||
const stepObj = Step.create(step);
|
||||
stepObj.fields = stepObj.fields.map((f) => WizardField.create(f));
|
||||
return stepObj;
|
||||
});
|
||||
|
||||
return Wizard.create(wizard);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user