Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 09:20:29 +01:00
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 { computed } from "@ember/object";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
|
|
||||||
const klasses = ["topic", "post", "group", "category"];
|
import wizardSchema, {
|
||||||
const types = ["string", "boolean", "integer", "json"];
|
customFieldsKlassesRequiringAdditionalSubscription,
|
||||||
const subscriptionTypes = {
|
customFieldsKlassSubscriptionLevel,
|
||||||
klass: ["group", "category"],
|
customFieldsTypesRequiringAdditionalSubscription,
|
||||||
type: ["json"],
|
customFieldsTypeSubscriptionLevel,
|
||||||
};
|
} from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema";
|
||||||
|
|
||||||
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;
|
|
||||||
}, []);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Component.extend({
|
export default Component.extend({
|
||||||
tagName: "tr",
|
tagName: "tr",
|
||||||
|
@ -32,12 +17,6 @@ export default Component.extend({
|
||||||
postSerializers: ["post"],
|
postSerializers: ["post"],
|
||||||
groupSerializers: ["basic_group"],
|
groupSerializers: ["basic_group"],
|
||||||
categorySerializers: ["basic_category"],
|
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"),
|
showInputs: or("field.new", "field.edit"),
|
||||||
classNames: ["custom-field-input"],
|
classNames: ["custom-field-input"],
|
||||||
loading: or("saving", "destroying"),
|
loading: or("saving", "destroying"),
|
||||||
|
@ -49,15 +28,49 @@ export default Component.extend({
|
||||||
this.set("originalField", JSON.parse(JSON.stringify(this.field)));
|
this.set("originalField", JSON.parse(JSON.stringify(this.field)));
|
||||||
},
|
},
|
||||||
|
|
||||||
@discourseComputed("field.klass")
|
// @discourseComputed("field.klass")
|
||||||
serializerContent(klass) {
|
// serializerContent(klass) {
|
||||||
const serializers = this.get(`${klass}Serializers`);
|
// const serializers = this.get(`${klass}Serializers`);
|
||||||
|
|
||||||
if (serializers) {
|
// if (serializers) {
|
||||||
return generateContent(serializers, "serializers", this.subscribed);
|
// return generateContent(serializers, "serializers", this.subscribed);
|
||||||
} else {
|
// } else {
|
||||||
return [];
|
// 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")
|
@observes("field.klass")
|
||||||
|
|
|
@ -208,10 +208,24 @@ const action = {
|
||||||
objectArrays: {},
|
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 = {
|
const wizardSchema = {
|
||||||
wizard,
|
wizard,
|
||||||
step,
|
step,
|
||||||
field,
|
field,
|
||||||
|
custom_field,
|
||||||
action,
|
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) {
|
export function buildFieldTypes(types) {
|
||||||
wizardSchema.field.types = types;
|
wizardSchema.field.types = types;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,12 @@ export default DiscourseRoute.extend({
|
||||||
setupController(controller, model) {
|
setupController(controller, model) {
|
||||||
const customFields = A(model.custom_fields || []);
|
const customFields = A(model.custom_fields || []);
|
||||||
const subscribed = model.subscribed;
|
const subscribed = model.subscribed;
|
||||||
|
const subscription = model.subscription;
|
||||||
|
|
||||||
controller.setProperties({
|
controller.setProperties({
|
||||||
customFields,
|
customFields,
|
||||||
subscribed,
|
subscribed,
|
||||||
|
subscription,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -33,7 +33,8 @@
|
||||||
field=field
|
field=field
|
||||||
removeField=(action "removeField")
|
removeField=(action "removeField")
|
||||||
saveField=(action "saveField")
|
saveField=(action "saveField")
|
||||||
subscribed=subscribed}}
|
subscribed=subscribed
|
||||||
|
subscription=subscription}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -2,14 +2,14 @@
|
||||||
<td>
|
<td>
|
||||||
{{wizard-subscription-selector
|
{{wizard-subscription-selector
|
||||||
value=field.klass
|
value=field.klass
|
||||||
content=klassContent
|
content=customFieldKlasses
|
||||||
none="admin.wizard.custom_field.klass.select"
|
none="admin.wizard.custom_field.klass.select"
|
||||||
onChange=(action (mut field.klass))}}
|
onChange=(action (mut field.klass))}}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{wizard-subscription-selector
|
{{wizard-subscription-selector
|
||||||
value=field.type
|
value=field.type
|
||||||
content=typeContent
|
content=customFieldTypes
|
||||||
none="admin.wizard.custom_field.type.select"
|
none="admin.wizard.custom_field.type.select"
|
||||||
onChange=(action (mut field.type))}}
|
onChange=(action (mut field.type))}}
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -427,10 +427,6 @@
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.wizard-custom-action .select-kit-row.disabled {
|
|
||||||
background: var(--primary-low);
|
|
||||||
}
|
|
||||||
|
|
||||||
.select-box-kit-header {
|
.select-box-kit-header {
|
||||||
height: initial;
|
height: initial;
|
||||||
}
|
}
|
||||||
|
@ -792,11 +788,6 @@
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
.subscription-label {
|
|
||||||
color: var(--tertiary);
|
|
||||||
font-size: 0.75em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.admin-wizards-subscription {
|
.admin-wizards-subscription {
|
||||||
.admin-wizard-controls {
|
.admin-wizard-controls {
|
||||||
h3,
|
h3,
|
||||||
|
@ -857,14 +848,21 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.wizard-subscription-selector.select-kit.single-select {
|
.wizard-subscription-selector.select-kit.single-select {
|
||||||
.select-kit-row .texts {
|
.select-kit-row {
|
||||||
display: flex;
|
.texts {
|
||||||
align-items: center;
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
&.disabled {
|
||||||
|
background: var(--primary-low);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.subscription-label {
|
.subscription-label {
|
||||||
margin-left: 0.75em;
|
margin-left: 0.75em;
|
||||||
padding-top: 0.25em;
|
padding-top: 0.25em;
|
||||||
|
color: var(--tertiary);
|
||||||
|
font-size: 0.75em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@ class CustomWizard::AdminCustomFieldsController < CustomWizard::AdminController
|
||||||
def index
|
def index
|
||||||
render_json_dump(
|
render_json_dump(
|
||||||
custom_fields: custom_field_list,
|
custom_fields: custom_field_list,
|
||||||
subscribed: CustomWizard::Subscription.subscribed?
|
subscribed: CustomWizard::Subscription.subscribed?,
|
||||||
|
subscription: CustomWizard::Subscription.type
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Laden …
In neuem Issue referenzieren