2019-10-30 03:23:50 +08:00
|
|
|
import EmberObject from "@ember/object";
|
2022-06-05 00:04:00 +08:00
|
|
|
import Evented from "@ember/object/evented";
|
2016-08-26 01:14:56 +08:00
|
|
|
import Step from "wizard/models/step";
|
|
|
|
import WizardField from "wizard/models/wizard-field";
|
2022-06-17 20:50:21 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import { readOnly } from "@ember/object/computed";
|
2016-08-26 01:14:56 +08:00
|
|
|
|
2022-06-05 00:04:00 +08:00
|
|
|
const Wizard = EmberObject.extend(Evented, {
|
2022-06-17 20:50:21 +08:00
|
|
|
totalSteps: readOnly("steps.length"),
|
2016-09-17 04:12:56 +08:00
|
|
|
|
2016-09-17 05:02:45 +08:00
|
|
|
getTitle() {
|
2019-05-27 16:15:39 +08:00
|
|
|
const titleStep = this.steps.findBy("id", "forum-title");
|
2016-09-17 05:02:45 +08:00
|
|
|
if (!titleStep) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return titleStep.get("fieldsById.title.value");
|
|
|
|
},
|
|
|
|
|
2016-09-22 04:09:18 +08:00
|
|
|
getLogoUrl() {
|
2019-05-27 16:15:39 +08:00
|
|
|
const logoStep = this.steps.findBy("id", "logos");
|
2016-09-22 04:09:18 +08:00
|
|
|
if (!logoStep) {
|
|
|
|
return;
|
|
|
|
}
|
2020-10-06 01:40:41 +08:00
|
|
|
return logoStep.get("fieldsById.logo.value");
|
2016-09-22 04:09:18 +08:00
|
|
|
},
|
|
|
|
|
2022-06-07 03:01:47 +08:00
|
|
|
get currentColors() {
|
2021-08-26 05:10:12 +08:00
|
|
|
const colorStep = this.steps.findBy("id", "styling");
|
2016-09-17 04:12:56 +08:00
|
|
|
if (!colorStep) {
|
2020-05-27 01:56:36 +08:00
|
|
|
return this.current_color_scheme;
|
2016-09-17 04:12:56 +08:00
|
|
|
}
|
|
|
|
|
2022-06-07 03:01:47 +08:00
|
|
|
const themeChoice = colorStep.fieldsById.color_scheme;
|
2016-09-17 04:12:56 +08:00
|
|
|
if (!themeChoice) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-07 03:01:47 +08:00
|
|
|
return themeChoice.choices?.findBy("id", themeChoice.value)?.data.colors;
|
2020-08-31 18:14:09 +08:00
|
|
|
},
|
|
|
|
|
2022-06-07 03:01:47 +08:00
|
|
|
get font() {
|
|
|
|
const fontChoice = this.steps.findBy("id", "styling")?.fieldsById
|
|
|
|
?.body_font;
|
|
|
|
return fontChoice.choices?.findBy("id", fontChoice.value)?.label;
|
|
|
|
},
|
2020-08-31 18:14:09 +08:00
|
|
|
|
2022-06-07 03:01:47 +08:00
|
|
|
get headingFont() {
|
|
|
|
const fontChoice = this.steps.findBy("id", "styling")?.fieldsById
|
|
|
|
?.heading_font;
|
|
|
|
return fontChoice.choices?.findBy("id", fontChoice.value)?.label;
|
2016-09-17 04:12:56 +08:00
|
|
|
},
|
2016-08-26 01:14:56 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
export function findWizard() {
|
2022-06-17 20:50:21 +08:00
|
|
|
return ajax({ url: "/wizard.json" }).then(({ wizard }) => {
|
2016-08-26 01:14:56 +08:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|