Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-16 06:40:29 +01:00
af3e61fe75
* Add custom field improvements This PR does a few things to improve our support of custom fields 1. Adds custom fields added by other plugins to the list in admin/wizards/custom-fields and the custom field list in the mapper selector 2. Adds support for json custom fields in the wizard actions * Make eslint happy * Make prettier happy * Make rubocop happy * Make ember template lint happy * Don't assume we have the context in the selector * Ensure custom fields don't require optional attributes (with tests)
46 Zeilen
1,2 KiB
JavaScript
46 Zeilen
1,2 KiB
JavaScript
import CustomWizard from "../models/custom-wizard";
|
|
import { ajax } from "discourse/lib/ajax";
|
|
import DiscourseRoute from "discourse/routes/discourse";
|
|
import I18n from "I18n";
|
|
|
|
export default DiscourseRoute.extend({
|
|
model(params) {
|
|
if (params.wizardId === "create") {
|
|
return { create: true };
|
|
} else {
|
|
return ajax(`/admin/wizards/wizard/${params.wizardId}`);
|
|
}
|
|
},
|
|
|
|
afterModel(model) {
|
|
if (model.none) {
|
|
return this.transitionTo("adminWizardsWizard");
|
|
}
|
|
},
|
|
|
|
setupController(controller, model) {
|
|
const parentModel = this.modelFor("adminWizardsWizard");
|
|
const wizard = CustomWizard.create(!model || model.create ? {} : model);
|
|
const fieldTypes = Object.keys(parentModel.field_types).map((type) => {
|
|
return {
|
|
id: type,
|
|
name: I18n.t(`admin.wizard.field.type.${type}`),
|
|
};
|
|
});
|
|
|
|
let props = {
|
|
wizardList: parentModel.wizard_list,
|
|
fieldTypes,
|
|
userFields: parentModel.userFields,
|
|
customFields: parentModel.custom_fields,
|
|
apis: parentModel.apis,
|
|
themes: parentModel.themes,
|
|
wizard,
|
|
currentStep: wizard.steps[0],
|
|
currentAction: wizard.actions[0],
|
|
creating: model.create,
|
|
};
|
|
|
|
controller.setProperties(props);
|
|
},
|
|
});
|