From bd5edaffe99027385df62ebc79903150b4b6f647 Mon Sep 17 00:00:00 2001 From: merefield Date: Tue, 2 Nov 2021 08:58:15 +0000 Subject: [PATCH] custom field input: further make generic, fix serializers dropdown --- .../components/custom-field-input.js.es6 | 66 +++++++++---------- .../discourse/lib/wizard-schema.js.es6 | 12 ++-- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/assets/javascripts/discourse/components/custom-field-input.js.es6 b/assets/javascripts/discourse/components/custom-field-input.js.es6 index 6d4c6366..f60052c9 100644 --- a/assets/javascripts/discourse/components/custom-field-input.js.es6 +++ b/assets/javascripts/discourse/components/custom-field-input.js.es6 @@ -8,6 +8,22 @@ import wizardSchema, { subscriptionLevel, } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; +const generateContent = function (kategory, subscription) { + let unsubscribedCustomFields = requiringAdditionalSubscription( + subscription, "custom_fields", kategory + ); + return wizardSchema.custom_field[kategory].reduce((result, item) => { + let disabled = unsubscribedCustomFields.includes(item); + result.push({ + id: item, + name: I18n.t(`admin.wizard.custom_field.${kategory}.${item}`), + subscription: subscriptionLevel(item, "custom_fields", kategory), + disabled, + }); + return result; + }, []); +}; + export default Component.extend({ tagName: "tr", topicSerializers: ["topic_view", "topic_list_item"], @@ -25,49 +41,29 @@ export default Component.extend({ this.set("originalField", JSON.parse(JSON.stringify(this.field))); }, - // @discourseComputed("field.klass") - // serializerContent(klass) { - // const serializers = this.get(`${klass}Serializers`); + @discourseComputed("field.klass") + serializerContent(klass) { + const serializers = this.get(`${klass}Serializers`); - // if (serializers) { - // return generateContent(serializers, "serializers", this.subscribed); - // } else { - // return []; - // } - // }, + if (serializers) { + return serializers.reduce((result, key) => { + result.push({ + id: key, + name: I18n.t(`admin.wizard.custom_field.serializers.${key}`), + }); + return result; + }, []); + } + }, @discourseComputed("subscription") customFieldTypes(subscription) { - let unsubscribedCustomFields = requiringAdditionalSubscription( - subscription, "custom_fields", "types" - ); - return wizardSchema.custom_field.types.reduce((result, type) => { - let disabled = unsubscribedCustomFields.includes(type); - result.push({ - id: type, - name: I18n.t(`admin.wizard.custom_field.type.${type}`), - subscription: subscriptionLevel(type, "custom_fields", "types"), - disabled, - }); - return result; - }, []); + return generateContent("type", this.subscription); }, @discourseComputed("subscription") customFieldKlasses(subscription) { - let unsubscribedCustomFields = requiringAdditionalSubscription( - subscription, "custom_fields", "klasses" - ); - return wizardSchema.custom_field.klasses.reduce((result, klass) => { - let disabled = unsubscribedCustomFields.includes(klass); - result.push({ - id: klass, - name: I18n.t(`admin.wizard.custom_field.klass.${klass}`), - subscription: subscriptionLevel(klass, "custom_fields", "klasses"), - disabled, - }); - return result; - }, []); + return generateContent("klass", this.subscription); }, @observes("field.klass") diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index fcdd37b4..fb2e697d 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -198,24 +198,24 @@ const action = { }; const custom_field = { - klasses: ["topic", "post", "group", "category"], - types: ["string", "boolean", "integer", "json"], + klass: ["topic", "post", "group", "category"], + type: ["string", "boolean", "integer", "json"], }; const subscription_levels = { standard: { actions: ["send_message", "add_to_group", "watch_categories"], custom_fields: { - klasses: [], - types: ["json"] + klass: [], + type: ["json"] } }, business: { actions: ["create_category", "create_group", "send_to_api"], custom_fields: { - klasses: ["group", "category"], - types: [] + klass: ["group", "category"], + type: [] } } };