Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 01:10:28 +01:00
REFACTOR: abstract subscription logic to reduce code
Dieser Commit ist enthalten in:
Ursprung
7b129debac
Commit
9350db5424
3 geänderte Dateien mit 39 neuen und 128 gelöschten Zeilen
|
@ -5,10 +5,8 @@ import { computed } from "@ember/object";
|
|||
import I18n from "I18n";
|
||||
|
||||
import wizardSchema, {
|
||||
customFieldsKlassesRequiringAdditionalSubscription,
|
||||
customFieldsKlassSubscriptionLevel,
|
||||
customFieldsTypesRequiringAdditionalSubscription,
|
||||
customFieldsTypeSubscriptionLevel,
|
||||
requiringAdditionalSubscription,
|
||||
subscriptionLevel,
|
||||
} from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema";
|
||||
|
||||
export default Component.extend({
|
||||
|
@ -41,15 +39,15 @@ export default Component.extend({
|
|||
|
||||
@discourseComputed("subscription")
|
||||
customFieldTypes(subscription) {
|
||||
let unsubscribedCustomFields = customFieldsTypesRequiringAdditionalSubscription(
|
||||
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: customFieldsTypeSubscriptionLevel(type),
|
||||
subscription: subscriptionLevel(type, "custom_fields", "types"),
|
||||
disabled: disabled,
|
||||
});
|
||||
return result;
|
||||
|
@ -58,15 +56,15 @@ export default Component.extend({
|
|||
|
||||
@discourseComputed("subscription")
|
||||
customFieldKlasses(subscription) {
|
||||
let unsubscribedCustomFields = customFieldsKlassesRequiringAdditionalSubscription(
|
||||
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: customFieldsKlassSubscriptionLevel(klass),
|
||||
subscription: subscriptionLevel(klass, "custom_fields", "klasses"),
|
||||
disabled: disabled,
|
||||
});
|
||||
return result;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { default as discourseComputed } from "discourse-common/utils/decorators";
|
||||
import wizardSchema, {
|
||||
actionsRequiringAdditionalSubscription,
|
||||
requiringAdditionalSubscription,
|
||||
actionSubscriptionLevel,
|
||||
subscriptionLevel,
|
||||
} from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema";
|
||||
import { empty, equal, or } from "@ember/object/computed";
|
||||
import { notificationLevels, selectKitContent } from "../lib/wizard";
|
||||
|
@ -98,19 +97,15 @@ export default Component.extend(UndoChanges, {
|
|||
return apis.find((a) => a.name === api).endpoints;
|
||||
},
|
||||
|
||||
@discourseComputed("subscribed", "subscription")
|
||||
actionTypes(subscribed, subscription) {
|
||||
let unsubscribedActions = requiringAdditionalSubscription (subscription, "actions");
|
||||
debugger;
|
||||
let unsubscribedActionslong = actionsRequiringAdditionalSubscription(
|
||||
subscription
|
||||
);
|
||||
@discourseComputed("subscription")
|
||||
actionTypes(subscription) {
|
||||
let unsubscribedActions = requiringAdditionalSubscription (subscription, "actions", "");
|
||||
return Object.keys(wizardSchema.action.types).reduce((result, type) => {
|
||||
let disabled = unsubscribedActions.includes(type);
|
||||
result.push({
|
||||
id: type,
|
||||
name: I18n.t(`admin.wizard.action.${type}.label`),
|
||||
subscription: actionSubscriptionLevel(type),
|
||||
subscription: subscriptionLevel(type, "actions", ""),
|
||||
disabled: disabled,
|
||||
});
|
||||
return result;
|
||||
|
|
|
@ -193,17 +193,6 @@ const action = {
|
|||
"members_visibility_level",
|
||||
],
|
||||
required: ["id", "type"],
|
||||
subscriptionTypes: [
|
||||
"send_message",
|
||||
"add_to_group",
|
||||
"create_category",
|
||||
"create_group",
|
||||
"send_to_api",
|
||||
],
|
||||
actionTypesWithSubscription: {
|
||||
standard: ["send_message", "add_to_group", "watch_categories"],
|
||||
business: ["create_category", "create_group", "send_to_api"],
|
||||
},
|
||||
dependent: {},
|
||||
objectArrays: {},
|
||||
};
|
||||
|
@ -211,14 +200,6 @@ const action = {
|
|||
const custom_field = {
|
||||
klasses: ["topic", "post", "group", "category"],
|
||||
types: ["string", "boolean", "integer", "json"],
|
||||
customFieldKlassWithSubscription: {
|
||||
standard: [],
|
||||
business: ["group", "category"],
|
||||
},
|
||||
customFieldTypeWithSubscription: {
|
||||
standard: ["json"],
|
||||
business: [],
|
||||
},
|
||||
}
|
||||
|
||||
const subscription_levels = {
|
||||
|
@ -249,22 +230,38 @@ const wizardSchema = {
|
|||
}
|
||||
|
||||
export function requiringAdditionalSubscription(
|
||||
currentSubscription, category
|
||||
currentSubscription, category, subCategory
|
||||
) {
|
||||
switch (currentSubscription) {
|
||||
case "business":
|
||||
return [];
|
||||
case "standard":
|
||||
return subscription_levels["business"].[category];
|
||||
switch (category) {
|
||||
case "actions":
|
||||
switch (currentSubscription) {
|
||||
case "business":
|
||||
return [];
|
||||
case "standard":
|
||||
return subscription_levels["business"].[category];
|
||||
default:
|
||||
return subscription_levels["standard"].[category].concat(
|
||||
subscription_levels["business"].[category]
|
||||
);
|
||||
}
|
||||
case "custom_fields":
|
||||
switch (currentSubscription) {
|
||||
case "business":
|
||||
return [];
|
||||
case "standard":
|
||||
return subscription_levels["business"].[category].[subCategory];
|
||||
default:
|
||||
return subscription_levels["standard"].[category].[subCategory].concat(
|
||||
subscription_levels["business"].[category].[subCategory]
|
||||
);
|
||||
}
|
||||
default:
|
||||
return subscription_levels["standard"].[category].concat(
|
||||
subscription_levels["business"].[category]
|
||||
);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function SubscriptionLevel(category, type, subCategory) {
|
||||
export function subscriptionLevel(type, category, subCategory) {
|
||||
switch (category) {
|
||||
case "actions":
|
||||
if (subscription_levels.["business"].actions.includes(type)) {
|
||||
|
@ -291,85 +288,6 @@ export function SubscriptionLevel(category, type, subCategory) {
|
|||
}
|
||||
}
|
||||
|
||||
export function actionsRequiringAdditionalSubscription(
|
||||
currentSubscription
|
||||
) {
|
||||
switch (currentSubscription) {
|
||||
case "business":
|
||||
return [];
|
||||
case "standard":
|
||||
return action.actionTypesWithSubscription["business"];
|
||||
default:
|
||||
return action.actionTypesWithSubscription["standard"].concat(
|
||||
action.actionTypesWithSubscription["business"]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function actionSubscriptionLevel(type) {
|
||||
if (action.actionTypesWithSubscription["business"].includes(type)) {
|
||||
return "business"
|
||||
} else {
|
||||
if (action.actionTypesWithSubscription["standard"].includes(type)) {
|
||||
return "standard"
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Laden …
In neuem Issue referenzieren