Admin custom fields subscription differentiation
Dieser Commit ist enthalten in:
Ursprung
5334d12f10
Commit
a806e14c64
7 geänderte Dateien mit 132 neuen und 51 gelöschten Zeilen
|
@ -4,27 +4,12 @@ import { alias, equal, or } from "@ember/object/computed";
|
|||
import { computed } from "@ember/object";
|
||||
import I18n from "I18n";
|
||||
|
||||
const klasses = ["topic", "post", "group", "category"];
|
||||
const types = ["string", "boolean", "integer", "json"];
|
||||
const subscriptionTypes = {
|
||||
klass: ["group", "category"],
|
||||
type: ["json"],
|
||||
};
|
||||
|
||||
const generateContent = function (array, type, subscribed = false) {
|
||||
return array.reduce((result, key) => {
|
||||
let subArr = subscriptionTypes[type];
|
||||
let subscription = subArr && subArr.includes(key);
|
||||
if (!subscription || subscribed) {
|
||||
result.push({
|
||||
id: key,
|
||||
name: I18n.t(`admin.wizard.custom_field.${type}.${key}`),
|
||||
subscription,
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}, []);
|
||||
};
|
||||
import wizardSchema, {
|
||||
customFieldsKlassesRequiringAdditionalSubscription,
|
||||
customFieldsKlassSubscriptionLevel,
|
||||
customFieldsTypesRequiringAdditionalSubscription,
|
||||
customFieldsTypeSubscriptionLevel,
|
||||
} from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema";
|
||||
|
||||
export default Component.extend({
|
||||
tagName: "tr",
|
||||
|
@ -32,12 +17,6 @@ export default Component.extend({
|
|||
postSerializers: ["post"],
|
||||
groupSerializers: ["basic_group"],
|
||||
categorySerializers: ["basic_category"],
|
||||
klassContent: computed("subscribed", function () {
|
||||
return generateContent(klasses, "klass", this.subscribed);
|
||||
}),
|
||||
typeContent: computed("subscribed", function () {
|
||||
return generateContent(types, "type", this.subscribed);
|
||||
}),
|
||||
showInputs: or("field.new", "field.edit"),
|
||||
classNames: ["custom-field-input"],
|
||||
loading: or("saving", "destroying"),
|
||||
|
@ -49,15 +28,49 @@ 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 generateContent(serializers, "serializers", this.subscribed);
|
||||
// } else {
|
||||
// return [];
|
||||
// }
|
||||
// },
|
||||
|
||||
@discourseComputed("subscription")
|
||||
customFieldTypes(subscription) {
|
||||
let unsubscribedCustomFields = customFieldsTypesRequiringAdditionalSubscription(
|
||||
subscription
|
||||
);
|
||||
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: customFieldsTypeSubscriptionLevel(type),
|
||||
disabled: disabled,
|
||||
});
|
||||
return result;
|
||||
}, []);
|
||||
},
|
||||
|
||||
@discourseComputed("subscription")
|
||||
customFieldKlasses(subscription) {
|
||||
let unsubscribedCustomFields = customFieldsKlassesRequiringAdditionalSubscription(
|
||||
subscription
|
||||
);
|
||||
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: customFieldsKlassSubscriptionLevel(klass),
|
||||
disabled: disabled,
|
||||
});
|
||||
return result;
|
||||
}, []);
|
||||
},
|
||||
|
||||
@observes("field.klass")
|
||||
|
|
|
@ -208,10 +208,24 @@ const action = {
|
|||
objectArrays: {},
|
||||
};
|
||||
|
||||
const custom_field = {
|
||||
klasses: ["topic", "post", "group", "category"],
|
||||
types: ["string", "boolean", "integer", "json"],
|
||||
customFieldKlassWithSubscription: {
|
||||
standard: [],
|
||||
business: ["group", "category"],
|
||||
},
|
||||
customFieldTypeWithSubscription: {
|
||||
standard: ["json"],
|
||||
business: [],
|
||||
},
|
||||
}
|
||||
|
||||
const wizardSchema = {
|
||||
wizard,
|
||||
step,
|
||||
field,
|
||||
custom_field,
|
||||
action,
|
||||
};
|
||||
|
||||
|
@ -242,6 +256,58 @@ export function actionSubscriptionLevel(type) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function customFieldsKlassesRequiringAdditionalSubscription(
|
||||
currentSubscription
|
||||
) {
|
||||
switch (currentSubscription) {
|
||||
case "business":
|
||||
return [];
|
||||
case "standard":
|
||||
return custom_field.customFieldKlassWithSubscription["business"];
|
||||
default:
|
||||
return custom_field.customFieldKlassWithSubscription["business"].concat(custom_field.customFieldKlassWithSubscription["standard"]);
|
||||
}
|
||||
}
|
||||
|
||||
export function customFieldsKlassSubscriptionLevel(type) {
|
||||
if (custom_field.customFieldKlassWithSubscription["business"].includes(type)) {
|
||||
return "business"
|
||||
} else {
|
||||
if (custom_field.customFieldKlassWithSubscription["standard"].includes(type)) {
|
||||
return "standard"
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function customFieldsTypesRequiringAdditionalSubscription(
|
||||
currentSubscription
|
||||
) {
|
||||
switch (currentSubscription) {
|
||||
case "business":
|
||||
return [];
|
||||
case "standard":
|
||||
return custom_field.customFieldTypeWithSubscription["business"];
|
||||
default:
|
||||
return custom_field.customFieldTypeWithSubscription["business"].concat(custom_field.customFieldTypeWithSubscription["standard"]);
|
||||
}
|
||||
}
|
||||
|
||||
export function customFieldsTypeSubscriptionLevel(type) {
|
||||
if (custom_field.customFieldTypeWithSubscription["business"].includes(type)) {
|
||||
return "business"
|
||||
} else {
|
||||
if (custom_field.customFieldTypeWithSubscription["standard"].includes(type)) {
|
||||
return "standard"
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function buildFieldTypes(types) {
|
||||
wizardSchema.field.types = types;
|
||||
}
|
||||
|
|
|
@ -10,10 +10,12 @@ export default DiscourseRoute.extend({
|
|||
setupController(controller, model) {
|
||||
const customFields = A(model.custom_fields || []);
|
||||
const subscribed = model.subscribed;
|
||||
const subscription = model.subscription;
|
||||
|
||||
controller.setProperties({
|
||||
customFields,
|
||||
subscribed,
|
||||
subscription,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
field=field
|
||||
removeField=(action "removeField")
|
||||
saveField=(action "saveField")
|
||||
subscribed=subscribed}}
|
||||
subscribed=subscribed
|
||||
subscription=subscription}}
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
<td>
|
||||
{{wizard-subscription-selector
|
||||
value=field.klass
|
||||
content=klassContent
|
||||
content=customFieldKlasses
|
||||
none="admin.wizard.custom_field.klass.select"
|
||||
onChange=(action (mut field.klass))}}
|
||||
</td>
|
||||
<td>
|
||||
{{wizard-subscription-selector
|
||||
value=field.type
|
||||
content=typeContent
|
||||
content=customFieldTypes
|
||||
none="admin.wizard.custom_field.type.select"
|
||||
onChange=(action (mut field.type))}}
|
||||
</td>
|
||||
|
|
|
@ -427,10 +427,6 @@
|
|||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.wizard-custom-action .select-kit-row.disabled {
|
||||
background: var(--primary-low);
|
||||
}
|
||||
|
||||
.select-box-kit-header {
|
||||
height: initial;
|
||||
}
|
||||
|
@ -792,11 +788,6 @@
|
|||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.subscription-label {
|
||||
color: var(--tertiary);
|
||||
font-size: 0.75em;
|
||||
}
|
||||
|
||||
.admin-wizards-subscription {
|
||||
.admin-wizard-controls {
|
||||
h3,
|
||||
|
@ -857,14 +848,21 @@
|
|||
}
|
||||
|
||||
.wizard-subscription-selector.select-kit.single-select {
|
||||
.select-kit-row .texts {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
.select-kit-row {
|
||||
.texts {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
&.disabled {
|
||||
background: var(--primary-low);
|
||||
}
|
||||
}
|
||||
|
||||
.subscription-label {
|
||||
margin-left: 0.75em;
|
||||
padding-top: 0.25em;
|
||||
color: var(--tertiary);
|
||||
font-size: 0.75em;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,8 @@ class CustomWizard::AdminCustomFieldsController < CustomWizard::AdminController
|
|||
def index
|
||||
render_json_dump(
|
||||
custom_fields: custom_field_list,
|
||||
subscribed: CustomWizard::Subscription.subscribed?
|
||||
subscribed: CustomWizard::Subscription.subscribed?,
|
||||
subscription: CustomWizard::Subscription.type
|
||||
)
|
||||
end
|
||||
|
||||
|
|
Laden …
In neuem Issue referenzieren