diff --git a/app/controllers/custom_wizard/admin/admin.rb b/app/controllers/custom_wizard/admin/admin.rb
index e011e094..867be56c 100644
--- a/app/controllers/custom_wizard/admin/admin.rb
+++ b/app/controllers/custom_wizard/admin/admin.rb
@@ -3,8 +3,12 @@ class CustomWizard::AdminController < ::Admin::AdminController
before_action :ensure_admin
def index
+ subcription = CustomWizard::Subscription.new
render_json_dump(
- api_section: ["business"].include?(CustomWizard::Subscription.type)
+ subscribed: subcription.subscribed?,
+ subscription_type: subcription.type,
+ subscription_attributes: CustomWizard::Subscription.attributes,
+ subscription_client_installed: subcription.client_installed?
)
end
diff --git a/app/controllers/custom_wizard/admin/custom_fields.rb b/app/controllers/custom_wizard/admin/custom_fields.rb
index 1cd20f5d..111e9faf 100644
--- a/app/controllers/custom_wizard/admin/custom_fields.rb
+++ b/app/controllers/custom_wizard/admin/custom_fields.rb
@@ -2,9 +2,7 @@
class CustomWizard::AdminCustomFieldsController < CustomWizard::AdminController
def index
render_json_dump(
- custom_fields: custom_field_list,
- subscribed: CustomWizard::Subscription.subscribed?,
- subscription: CustomWizard::Subscription.type
+ custom_fields: custom_field_list
)
end
diff --git a/app/controllers/custom_wizard/admin/wizard.rb b/app/controllers/custom_wizard/admin/wizard.rb
index ad63209a..0a59e02b 100644
--- a/app/controllers/custom_wizard/admin/wizard.rb
+++ b/app/controllers/custom_wizard/admin/wizard.rb
@@ -10,9 +10,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController
),
field_types: CustomWizard::Field.types,
realtime_validations: CustomWizard::RealtimeValidation.types,
- custom_fields: custom_field_list,
- subscribed: CustomWizard::Subscription.subscribed?,
- subscription: CustomWizard::Subscription.type
+ custom_fields: custom_field_list
)
end
diff --git a/assets/javascripts/discourse/components/custom-field-input.js.es6 b/assets/javascripts/discourse/components/custom-field-input.js.es6
index 7ee70716..5d2d6c3b 100644
--- a/assets/javascripts/discourse/components/custom-field-input.js.es6
+++ b/assets/javascripts/discourse/components/custom-field-input.js.es6
@@ -3,29 +3,6 @@ import discourseComputed, { observes } from "discourse-common/utils/decorators";
import { alias, equal, or } from "@ember/object/computed";
import I18n from "I18n";
-import wizardSchema, {
- requiringAdditionalSubscription,
- 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"],
@@ -58,16 +35,6 @@ export default Component.extend({
}
},
- @discourseComputed("subscription")
- customFieldTypes(subscription) {
- return generateContent("type", subscription);
- },
-
- @discourseComputed("subscription")
- customFieldKlasses(subscription) {
- return generateContent("klass", subscription);
- },
-
@observes("field.klass")
clearSerializersWhenClassChanges() {
this.set("field.serializers", null);
diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6
index 6cf22942..a0a9cc72 100644
--- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6
+++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6
@@ -1,8 +1,6 @@
import { default as discourseComputed } from "discourse-common/utils/decorators";
-import wizardSchema, {
- requiringAdditionalSubscription,
- subscriptionLevel,
-} from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema";
+import wizardSchema from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema";
+import { subscriptionSelectKitContent } from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-subscription";
import { empty, equal, or } from "@ember/object/computed";
import { notificationLevels, selectKitContent } from "../lib/wizard";
import { computed } from "@ember/object";
@@ -97,22 +95,8 @@ export default Component.extend(UndoChanges, {
return apis.find((a) => a.name === api).endpoints;
},
- @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: subscriptionLevel(type, "actions", ""),
- disabled,
- });
- return result;
- }, []);
+ @discourseComputed
+ actionTypes() {
+ return subscriptionSelectKitContent("action", "types");
},
});
diff --git a/assets/javascripts/discourse/components/wizard-subscription-badge.js.es6 b/assets/javascripts/discourse/components/wizard-subscription-badge.js.es6
new file mode 100644
index 00000000..7a63f4d3
--- /dev/null
+++ b/assets/javascripts/discourse/components/wizard-subscription-badge.js.es6
@@ -0,0 +1,30 @@
+import Component from "@ember/component";
+import discourseComputed from "discourse-common/utils/decorators";
+import Subscription from "../mixins/subscription";
+import DiscourseURL from "discourse/lib/url";
+import I18n from "I18n";
+
+export default Component.extend(Subscription, {
+ tagName: 'a',
+ classNameBindings: [":wizard-subscription-badge", "subscriptionType"],
+ attributeBindings: ["title"],
+
+ @discourseComputed("subscriptionType")
+ i18nKey(type) {
+ return `admin.wizard.subscription_container.type.${type ? type : "none"}`;
+ },
+
+ @discourseComputed("i18nKey")
+ title(i18nKey) {
+ return I18n.t(`${i18nKey}.title`);
+ },
+
+ @discourseComputed("i18nKey")
+ label(i18nKey) {
+ return I18n.t(`${i18nKey}.label`);
+ },
+
+ click() {
+ DiscourseURL.routeTo(this.subscriptionLink);
+ }
+});
diff --git a/assets/javascripts/discourse/components/wizard-subscription-container.js.es6 b/assets/javascripts/discourse/components/wizard-subscription-container.js.es6
new file mode 100644
index 00000000..3569276c
--- /dev/null
+++ b/assets/javascripts/discourse/components/wizard-subscription-container.js.es6
@@ -0,0 +1,26 @@
+import Component from "@ember/component";
+import discourseComputed from "discourse-common/utils/decorators";
+import Subscription from "../mixins/subscription";
+
+export default Component.extend(Subscription, {
+ classNameBindings: [":wizard-subscription-container", "subscribed"],
+
+ @discourseComputed("subscribed")
+ subscribedIcon(subscribed) {
+ return subscribed ? "check" : "dash";
+ },
+
+ @discourseComputed("subscribed")
+ subscribedLabel(subscribed) {
+ return `admin.wizard.subscription_container.${
+ subscribed ? "subscribed" : "not_subscribed"
+ }.label`;
+ },
+
+ @discourseComputed("subscribed")
+ subscribedTitle(subscribed) {
+ return `admin.wizard.subscription_container.${
+ subscribed ? "subscribed" : "not_subscribed"
+ }.title`;
+ }
+});
diff --git a/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6 b/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6
index ea1aa5d9..59714578 100644
--- a/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6
+++ b/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6
@@ -1,6 +1,21 @@
import SingleSelectComponent from "select-kit/components/single-select";
+import Subscription from "../mixins/subscription";
+import wizardSchema from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema";
+import {
+ subscriptionTypeSufficient,
+ subscriptionTypes
+} from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-subscription";
+import discourseComputed from "discourse-common/utils/decorators";
-export default SingleSelectComponent.extend({
+const nameKey = function(feature, attribute, value) {
+ if (feature === 'action') {
+ return `admin.wizard.action.${value}.label`;
+ } else {
+ return `admin.wizard.${feature}.${attribute}.${value}`;
+ }
+}
+
+export default SingleSelectComponent.extend(Subscription, {
classNames: ["combo-box", "wizard-subscription-selector"],
selectKitOptions: {
@@ -13,6 +28,38 @@ export default SingleSelectComponent.extend({
caretDownIcon: "caret-down",
},
+ requiredSubscriptionType(feature, attribute, value) {
+ let attributes = this.subscriptionAttributes[feature];
+ if (!attributes || !attributes[attribute]) return null;
+
+ let requiredType = null;
+ Object.keys(attributes[attribute]).some(subscriptionType => {
+ let values = attributes[attribute][subscriptionType];
+ if (values[0] === "*" || values.includes(value)) {
+ if (subscriptionTypes.includes(subscriptionType)) {
+ requiredType = subscriptionType;
+ }
+ return true;
+ }
+ return false;
+ });
+
+ return requiredType;
+ },
+
+ @discourseComputed('feature', 'attribute')
+ content(feature, attribute) {
+ return wizardSchema[feature][attribute].map((value) => {
+ let requiredSubscriptionType = this.requiredSubscriptionType(feature, attribute, value);
+ return {
+ id: value,
+ name: I18n.t(nameKey(feature, attribute, value)),
+ subscriptionType: requiredSubscriptionType,
+ disabled: !subscriptionTypeSufficient(this.subscriptionType, requiredSubscriptionType)
+ };
+ });
+ },
+
modifyComponentForRow() {
return "wizard-subscription-selector/wizard-subscription-selector-row";
},
diff --git a/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs
index 4b5d673d..5ce96f2f 100644
--- a/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs
+++ b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs
@@ -6,11 +6,11 @@
{{combo-box
- value=wizardListVal
- content=wizardList
- onChange=(action "changeWizard")
- options=(hash
- none="admin.wizard.select"
- )}}
+ value=wizardListVal
+ content=wizardList
+ onChange=(action "changeWizard")
+ options=(hash
+ none="admin.wizard.select"
+ )}}
diff --git a/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6
index e6b0ad04..2ecc42da 100644
--- a/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6
+++ b/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6
@@ -14,6 +14,7 @@ import I18n from "I18n";
export default Controller.extend({
hasName: notEmpty("wizard.name"),
+
@observes("currentStep")
resetCurrentObjects() {
const currentStep = this.currentStep;
diff --git a/assets/javascripts/discourse/controllers/admin-wizards.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards.js.es6
index 33841460..b69b878a 100644
--- a/assets/javascripts/discourse/controllers/admin-wizards.js.es6
+++ b/assets/javascripts/discourse/controllers/admin-wizards.js.es6
@@ -1,26 +1,7 @@
-import Controller, { inject as controller } from "@ember/controller";
-import { isPresent } from "@ember/utils";
-import { A } from "@ember/array";
+import Controller from "@ember/controller";
+import { equal } from "@ember/object/computed";
export default Controller.extend({
- adminWizardsNotices: controller(),
-
- unsubscribe() {
- this.messageBus.unsubscribe("/custom-wizard/notices");
- },
-
- subscribe() {
- this.unsubscribe();
- this.messageBus.subscribe("/custom-wizard/notices", (data) => {
- if (isPresent(data.active_notice_count)) {
- this.set("activeNoticeCount", data.active_notice_count);
- this.adminWizardsNotices.setProperties({
- notices: A(),
- page: 0,
- canLoadMore: true,
- });
- this.adminWizardsNotices.loadMoreNotices();
- }
- });
- },
+ businessSubscription: equal('subscriptionType', 'business'),
+ standardSubscription: equal('subscriptionType', 'standard')
});
diff --git a/assets/javascripts/discourse/custom-wizard-admin-route-map.js.es6 b/assets/javascripts/discourse/custom-wizard-admin-route-map.js.es6
index c3c95e48..272e276e 100644
--- a/assets/javascripts/discourse/custom-wizard-admin-route-map.js.es6
+++ b/assets/javascripts/discourse/custom-wizard-admin-route-map.js.es6
@@ -58,16 +58,6 @@ export default {
path: "/manager",
resetNamespace: true,
});
-
- this.route("adminWizardsSubscription", {
- path: "/subscription",
- resetNamespace: true,
- });
-
- this.route("adminWizardsNotices", {
- path: "/notices",
- resetNamespace: true,
- });
}
);
},
diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6
index 26c21bd2..ca5c30ee 100644
--- a/assets/javascripts/discourse/lib/wizard-schema.js.es6
+++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6
@@ -203,101 +203,17 @@ const custom_field = {
type: ["string", "boolean", "integer", "json"],
};
-const subscription_levels = {
- standard: {
- actions: ["send_message", "add_to_group", "watch_categories"],
- custom_fields: {
- klass: [],
- type: ["json"],
- },
- },
-
- business: {
- actions: ["create_category", "create_group", "send_to_api"],
- custom_fields: {
- klass: ["group", "category"],
- type: [],
- },
- },
-};
+field.type = Object.keys(field.types);
+action.type = Object.keys(action.types);
const wizardSchema = {
wizard,
step,
field,
custom_field,
- action,
- subscription_levels,
+ action
};
-export function requiringAdditionalSubscription(
- currentSubscription,
- category,
- subCategory
-) {
- 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 [];
- }
-}
-
-export function subscriptionLevel(type, category, subCategory) {
- switch (category) {
- case "actions":
- if (subscription_levels["business"].actions.includes(type)) {
- return "business";
- } else {
- if (subscription_levels["standard"].actions.includes(type)) {
- return "standard";
- } else {
- return "";
- }
- }
- case "custom_fields":
- if (
- subscription_levels["business"].custom_fields[subCategory].includes(
- type
- )
- ) {
- return "business";
- } else {
- if (
- subscription_levels["standard"].custom_fields[subCategory].includes(
- type
- )
- ) {
- return "standard";
- } else {
- return "";
- }
- }
- default:
- return "";
- }
-}
-
export function buildFieldTypes(types) {
wizardSchema.field.types = types;
}
diff --git a/assets/javascripts/discourse/lib/wizard-subscription.js.es6 b/assets/javascripts/discourse/lib/wizard-subscription.js.es6
new file mode 100644
index 00000000..deff32ca
--- /dev/null
+++ b/assets/javascripts/discourse/lib/wizard-subscription.js.es6
@@ -0,0 +1,17 @@
+const subscriptionTypes = [
+ 'standard',
+ 'business'
+]
+
+function subscriptionTypeSufficient(subscriptionType, requiredType) {
+ if (requiredType && !subscriptionType) return false;
+ if (requiredType === 'none' || requiredType === null) return true;
+ if (requiredType === 'standard' && subscriptionTypes.includes(subscriptionType)) return true;
+ if (requiredType === 'business' && subscriptionType === 'business') return true;
+ return false;
+}
+
+export {
+ subscriptionTypeSufficient,
+ subscriptionTypes
+}
diff --git a/assets/javascripts/discourse/mixins/subscription.js.es6 b/assets/javascripts/discourse/mixins/subscription.js.es6
new file mode 100644
index 00000000..00f77bb2
--- /dev/null
+++ b/assets/javascripts/discourse/mixins/subscription.js.es6
@@ -0,0 +1,26 @@
+import Mixin from "@ember/object/mixin";
+import { getOwner } from "discourse-common/lib/get-owner";
+import { readOnly } from "@ember/object/computed";
+import discourseComputed from "discourse-common/utils/decorators";
+
+export default Mixin.create({
+ subscriptionLandingUrl: "https://custom-wizard.pavilion.tech",
+ subscriptionClientUrl: "/admin/plugins/subscription-client",
+
+ @discourseComputed
+ adminWizards() {
+ return getOwner(this).lookup('controller:admin-wizards');
+ },
+
+ subscribed: readOnly('adminWizards.subscribed'),
+ subscriptionType: readOnly('adminWizards.subscriptionType'),
+ businessSubscription: readOnly('adminWizards.businessSubscription'),
+ standardSubscription: readOnly('adminWizards.standardSubscription'),
+ subscriptionAttributes: readOnly('adminWizards.subscriptionAttributes'),
+ subscriptionClientInstalled: readOnly('adminWizards.subscriptionClientInstalled'),
+
+ @discourseComputed("subscriptionClientInstalled")
+ subscriptionLink(subscriptionClientInstalled) {
+ return subscriptionClientInstalled ? this.subscriptionClientUrl : this.subscriptionLandingUrl;
+ }
+});
diff --git a/assets/javascripts/discourse/routes/admin-wizards-custom-fields.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-custom-fields.js.es6
index 4992f92d..4d9de2c4 100644
--- a/assets/javascripts/discourse/routes/admin-wizards-custom-fields.js.es6
+++ b/assets/javascripts/discourse/routes/admin-wizards-custom-fields.js.es6
@@ -9,13 +9,9 @@ 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,
+ customFields
});
},
});
diff --git a/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6
index d6263471..63ff564e 100644
--- a/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6
+++ b/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6
@@ -38,9 +38,7 @@ export default DiscourseRoute.extend({
wizard,
currentStep: wizard.steps[0],
currentAction: wizard.actions[0],
- creating: model.create,
- subscribed: parentModel.subscribed,
- subscription: parentModel.subscription,
+ creating: model.create
};
controller.setProperties(props);
diff --git a/assets/javascripts/discourse/routes/admin-wizards.js.es6 b/assets/javascripts/discourse/routes/admin-wizards.js.es6
index 5c39c0d6..0286926d 100644
--- a/assets/javascripts/discourse/routes/admin-wizards.js.es6
+++ b/assets/javascripts/discourse/routes/admin-wizards.js.es6
@@ -7,21 +7,17 @@ export default DiscourseRoute.extend({
},
setupController(controller, model) {
- controller.set("api_section", model.api_section);
-
- if (model.active_notice_count) {
- controller.set("activeNoticeCount", model.active_notice_count);
- }
- if (model.featured_notices) {
- controller.set("featuredNotices", model.featured_notices);
- }
-
- controller.subscribe();
+ controller.setProperties({
+ subscribed: model.subscribed,
+ subscriptionType: model.subscription_type,
+ subscriptionAttributes: model.subscription_attributes,
+ subscriptionClientInstalled: model.subscription_client_installed
+ });
},
afterModel(model, transition) {
if (transition.targetName === "adminWizards.index") {
this.transitionTo("adminWizardsWizard");
}
- },
+ }
});
diff --git a/assets/javascripts/discourse/templates/admin-wizards-custom-fields.hbs b/assets/javascripts/discourse/templates/admin-wizards-custom-fields.hbs
index dceed458..10501498 100644
--- a/assets/javascripts/discourse/templates/admin-wizards-custom-fields.hbs
+++ b/assets/javascripts/discourse/templates/admin-wizards-custom-fields.hbs
@@ -32,9 +32,7 @@
{{custom-field-input
field=field
removeField=(action "removeField")
- saveField=(action "saveField")
- subscribed=subscribed
- subscription=subscription}}
+ saveField=(action "saveField")}}
{{/each}}
diff --git a/assets/javascripts/discourse/templates/admin-wizards-wizard-show.hbs b/assets/javascripts/discourse/templates/admin-wizards-wizard-show.hbs
index abf06ba9..5d1c2166 100644
--- a/assets/javascripts/discourse/templates/admin-wizards-wizard-show.hbs
+++ b/assets/javascripts/discourse/templates/admin-wizards-wizard-show.hbs
@@ -126,7 +126,7 @@
- {{#subscription-container subscribed=subscribed}}
+ {{#wizard-subscription-container}}
@@ -146,7 +146,7 @@
{{i18n "admin.wizard.restart_on_revisit_label"}}
- {{/subscription-container}}
+ {{/wizard-subscription-container}}
{{wizard-links
@@ -177,9 +177,7 @@
wizard=wizard
apis=apis
removeAction="removeAction"
- wizardFields=wizardFields
- subscribed=subscribed
- subscription=subscription}}
+ wizardFields=wizardFields}}
{{/each}}