0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-10 04:12:53 +01:00

Show but differentiate unsubbed action options

Dieser Commit ist enthalten in:
merefield 2021-10-14 13:41:24 +01:00
Ursprung a13096c8f1
Commit a42e23d352
8 geänderte Dateien mit 61 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -1,6 +1,7 @@
import { default as discourseComputed } from "discourse-common/utils/decorators"; import { default as discourseComputed } from "discourse-common/utils/decorators";
import wizardSchema, { import wizardSchema, {
actionsAvailableWithAdditionalSubscription, actionsAvailableWithAdditionalSubscription,
actionsAvailableWithCurrentSubscription
} from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema"; } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema";
import { empty, equal, or } from "@ember/object/computed"; import { empty, equal, or } from "@ember/object/computed";
import { notificationLevels, selectKitContent } from "../lib/wizard"; import { notificationLevels, selectKitContent } from "../lib/wizard";
@ -100,11 +101,16 @@ export default Component.extend(UndoChanges, {
actionTypes(subscribed, subscription) { actionTypes(subscribed, subscription) {
let unsubscribedActions = let unsubscribedActions =
actionsAvailableWithAdditionalSubscription(subscription); actionsAvailableWithAdditionalSubscription(subscription);
let subscribedActions = actionsAvailableWithCurrentSubscription(subscription);
return Object.keys(wizardSchema.action.types).reduce((result, type) => { return Object.keys(wizardSchema.action.types).reduce((result, type) => {
let subscriptionLabel = (subscribedActions.includes(type) || unsubscribedActions.includes(type));
let disabled = unsubscribedActions.includes(type);
console.log(subscriptionLabel, disabled);
result.push({ result.push({
id: type, id: type,
name: I18n.t(`admin.wizard.action.${type}.label`), name: I18n.t(`admin.wizard.action.${type}.label`),
subscribed: unsubscribedActions.includes(type), subscription: subscriptionLabel,
disabled: disabled,
}); });
return result; return result;
}, []); }, []);

Datei anzeigen

@ -1,3 +1,20 @@
import SelectKitRowComponent from "select-kit/components/select-kit/select-kit-row"; import SelectKitRowComponent from "select-kit/components/select-kit/select-kit-row";
import { default as discourseComputed } from "discourse-common/utils/decorators";
export default SelectKitRowComponent.extend(); export default SelectKitRowComponent.extend({
classNameBindings: ["isDisabled:disabled"],
@discourseComputed("item")
isDisabled() {
return this.item.disabled;
},
click(event) {
event.preventDefault();
event.stopPropagation();
if (!this.item.disabled) {
this.selectKit.select(this.rowValue, this.item);
}
return false;
}
});

Datei anzeigen

@ -201,8 +201,8 @@ const action = {
"send_to_api", "send_to_api",
], ],
actionTypesWithSubscription: { actionTypesWithSubscription: {
advanced: ["send_message", "add_to_group", "watch_categories"], basic: ["send_message", "add_to_group", "watch_categories"],
business: ["create_category", "create_group", "send_to_api"], advanced: ["create_category", "create_group", "send_to_api"],
}, },
dependent: {}, dependent: {},
objectArrays: {}, objectArrays: {},
@ -219,17 +219,31 @@ export function actionsAvailableWithAdditionalSubscription(
currentSubscription currentSubscription
) { ) {
switch (currentSubscription) { switch (currentSubscription) {
case "complete":
return [];
case "advanced": case "advanced":
return action.actionTypesWithSubscription["business"]; return [];
case "core": case "basic":
return action.actionTypesWithSubscription["advanced"].concat( return action.actionTypesWithSubscription["advanced"];
action.actionTypesWithSubscription["business"] case "none", "":
return action.actionTypesWithSubscription["basic"].concat(
action.actionTypesWithSubscription["advanced"]
); );
} }
} }
export function actionsAvailableWithCurrentSubscription(
currentSubscription
) {
switch (currentSubscription) {
case "advanced":
return action.actionTypesWithSubscription["advanced"].concat(
action.actionTypesWithSubscription["basic"]);
case "basic":
return action.actionTypesWithSubscription["basic"];
case "none", "":
return [];
}
}
export function buildFieldTypes(types) { export function buildFieldTypes(types) {
wizardSchema.field.types = types; wizardSchema.field.types = types;
} }

Datei anzeigen

@ -10,6 +10,12 @@
<div class="texts"> <div class="texts">
<span class="name">{{html-safe label}}</span> <span class="name">{{html-safe label}}</span>
{{#if item.subscription}} {{#if item.subscription}}
<span class="subscription-label">{{i18n "admin.wizard.subscription.label"}}</span> <span class="subscription-label">
{{#if item.disabled}}
{{i18n "admin.wizard.subscription.additional_label"}}
{{else}}
{{i18n "admin.wizard.subscription.label"}}
{{/if}}
</span>
{{/if}} {{/if}}
</div> </div>

Datei anzeigen

@ -427,6 +427,10 @@
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;
} }

Datei anzeigen

@ -467,6 +467,7 @@ en:
subscription: subscription:
nav_label: Subscription nav_label: Subscription
label: Subscription label: Subscription
additional_label: "Add subscription"
title: Custom Wizard Subscription title: Custom Wizard Subscription
authorize: Authorize authorize: Authorize
authorized: Authorized authorized: Authorized

Datei anzeigen

@ -5,7 +5,7 @@ class CustomWizard::AdminController < ::Admin::AdminController
def index def index
render_json_dump( render_json_dump(
#TODO replace with appropriate static? #TODO replace with appropriate static?
api_section: ["complete"].include?(CustomWizard::Subscription.type), api_section: ["advanced"].include?(CustomWizard::Subscription.type),
notices: ActiveModel::ArraySerializer.new( notices: ActiveModel::ArraySerializer.new(
CustomWizard::Notice.list, CustomWizard::Notice.list,
each_serializer: CustomWizard::NoticeSerializer each_serializer: CustomWizard::NoticeSerializer

Datei anzeigen

@ -13,7 +13,7 @@ class CustomWizard::Subscription::Subscription
end end
def types def types
%w(core advanced complete) %w(none basic advanced)
end end
def active? def active?