diff --git a/.rubocop.yml b/.rubocop.yml index d46296cf..69fcfc56 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,2 +1,8 @@ inherit_gem: rubocop-discourse: default.yml + +RSpec/ContextWording: + Enabled: false + +RSpec/DescribeClass: + Enabled: false diff --git a/assets/javascripts/discourse/components/wizard-subscription-badge.js.es6 b/assets/javascripts/discourse/components/wizard-subscription-badge.js.es6 index 87c985a4..301c618e 100644 --- a/assets/javascripts/discourse/components/wizard-subscription-badge.js.es6 +++ b/assets/javascripts/discourse/components/wizard-subscription-badge.js.es6 @@ -11,7 +11,7 @@ export default Component.extend(Subscription, { @discourseComputed("subscriptionType") i18nKey(type) { - return `admin.wizard.subscription_container.type.${type ? type : "none"}`; + return `admin.wizard.subscription.type.${type ? type : "none"}`; }, @discourseComputed("i18nKey") diff --git a/assets/javascripts/discourse/components/wizard-subscription-container.js.es6 b/assets/javascripts/discourse/components/wizard-subscription-container.js.es6 index ccaf2f48..5cc6b17c 100644 --- a/assets/javascripts/discourse/components/wizard-subscription-container.js.es6 +++ b/assets/javascripts/discourse/components/wizard-subscription-container.js.es6 @@ -12,14 +12,14 @@ export default Component.extend(Subscription, { @discourseComputed("subscribed") subscribedLabel(subscribed) { - return `admin.wizard.subscription_container.${ + return `admin.wizard.subscription.${ subscribed ? "subscribed" : "not_subscribed" }.label`; }, @discourseComputed("subscribed") subscribedTitle(subscribed) { - return `admin.wizard.subscription_container.${ + return `admin.wizard.subscription.${ subscribed ? "subscribed" : "not_subscribed" }.title`; }, diff --git a/assets/javascripts/discourse/components/wizard-subscription-cta.js.es6 b/assets/javascripts/discourse/components/wizard-subscription-cta.js.es6 new file mode 100644 index 00000000..4fb3002b --- /dev/null +++ b/assets/javascripts/discourse/components/wizard-subscription-cta.js.es6 @@ -0,0 +1,34 @@ +import Component from "@ember/component"; +import discourseComputed from "discourse-common/utils/decorators"; +import Subscription from "../mixins/subscription"; +import I18n from "I18n"; + +export default Component.extend(Subscription, { + tagName: "a", + classNameBindings: [":btn", ":btn-pavilion-support", "subscriptionType"], + attributeBindings: ["title"], + + @discourseComputed("subscribed") + i18nKey(subscribed) { + return `admin.wizard.subscription.cta.${subscribed ? "subscribed" : "none"}`; + }, + + @discourseComputed("subscribed") + icon(subscribed) { + return subscribed ? "far-life-ring" : "external-link-alt"; + }, + + @discourseComputed("i18nKey") + title(i18nKey) { + return I18n.t(`${i18nKey}.title`); + }, + + @discourseComputed("i18nKey") + label(i18nKey) { + return I18n.t(`${i18nKey}.label`); + }, + + click() { + window.open(this.subscriptionCtaLink, "_blank").focus(); + }, +}); diff --git a/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6 b/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6 index 8ef6896a..06f705b3 100644 --- a/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6 +++ b/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6 @@ -1,10 +1,6 @@ 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"; import I18n from "I18n"; @@ -29,45 +25,50 @@ export default SingleSelectComponent.extend(Subscription, { caretDownIcon: "caret-down", }, - requiredSubscriptionType(feature, attribute, value) { + allowedSubscriptionTypes(feature, attribute, value) { let attributes = this.subscriptionAttributes[feature]; if (!attributes || !attributes[attribute]) { - return null; + return ['none']; } - - let requiredType = null; - Object.keys(attributes[attribute]).some((subscriptionType) => { + let allowedTypes = []; + Object.keys(attributes[attribute]).forEach((subscriptionType) => { let values = attributes[attribute][subscriptionType]; if (values[0] === "*" || values.includes(value)) { - if (subscriptionTypes.includes(subscriptionType)) { - requiredType = subscriptionType; - } - return true; + allowedTypes.push(subscriptionType); } - return false; }); - - return requiredType; + return allowedTypes; }, @discourseComputed("feature", "attribute") content(feature, attribute) { return wizardSchema[feature][attribute] .map((value) => { - let requiredSubscriptionType = this.requiredSubscriptionType( + let allowedSubscriptionTypes = this.allowedSubscriptionTypes( feature, attribute, value ); - return { + + let subscriptionRequired = allowedSubscriptionTypes.length && + !allowedSubscriptionTypes.includes('none'); + + let attrs = { id: value, name: I18n.t(nameKey(feature, attribute, value)), - subscriptionType: requiredSubscriptionType, - disabled: !subscriptionTypeSufficient( - this.subscriptionType, - requiredSubscriptionType - ), + subscriptionRequired }; + + if (subscriptionRequired) { + let subscribed = allowedSubscriptionTypes.includes(this.subscriptionType); + let selectorKey = subscribed ? "subscribed" : "not_subscribed"; + let selectorLabel = `admin.wizard.subscription.${selectorKey}.selector`; + + attrs.disabled = !subscribed; + attrs.selectorLabel = selectorLabel; + } + + return attrs; }) .sort(function (a, b) { if (a.subscriptionType && !b.subscriptionType) { diff --git a/assets/javascripts/discourse/controllers/admin-wizards.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards.js.es6 index f99c06cc..15c6ea85 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards.js.es6 @@ -1,7 +1,9 @@ import Controller from "@ember/controller"; -import { equal } from "@ember/object/computed"; +import { equal, or } from "@ember/object/computed"; export default Controller.extend({ businessSubscription: equal("subscriptionType", "business"), + communitySubscription: equal("subscriptionType", "community"), standardSubscription: equal("subscriptionType", "standard"), + showApi: or('businessSubscription', 'communitySubscription') }); diff --git a/assets/javascripts/discourse/lib/wizard-subscription.js.es6 b/assets/javascripts/discourse/lib/wizard-subscription.js.es6 deleted file mode 100644 index adecf063..00000000 --- a/assets/javascripts/discourse/lib/wizard-subscription.js.es6 +++ /dev/null @@ -1,22 +0,0 @@ -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 index 574f8585..072b57e9 100644 --- a/assets/javascripts/discourse/mixins/subscription.js.es6 +++ b/assets/javascripts/discourse/mixins/subscription.js.es6 @@ -3,8 +3,12 @@ import { getOwner } from "discourse-common/lib/get-owner"; import { readOnly } from "@ember/object/computed"; import discourseComputed from "discourse-common/utils/decorators"; +const PRODUCT_PAGE = "https://custom-wizard.pavilion.tech"; +const SUPPORT_MESSAGE = "https://coop.pavilion.tech/new-message?username=support&title=Custom%20Wizard%20Support"; +const MANAGER_CATEGORY = "https://discourse.pluginmanager.org/c/discourse-custom-wizard"; + export default Mixin.create({ - subscriptionLandingUrl: "https://custom-wizard.pavilion.tech", + subscriptionLandingUrl: PRODUCT_PAGE, subscriptionClientUrl: "/admin/plugins/subscription-client", @discourseComputed @@ -15,6 +19,7 @@ export default Mixin.create({ subscribed: readOnly("adminWizards.subscribed"), subscriptionType: readOnly("adminWizards.subscriptionType"), businessSubscription: readOnly("adminWizards.businessSubscription"), + communitySubscription: readOnly("adminWizards.communitySubscription"), standardSubscription: readOnly("adminWizards.standardSubscription"), subscriptionAttributes: readOnly("adminWizards.subscriptionAttributes"), subscriptionClientInstalled: readOnly( @@ -27,4 +32,15 @@ export default Mixin.create({ ? this.subscriptionClientUrl : this.subscriptionLandingUrl; }, + + @discourseComputed("subscriptionType") + subscriptionCtaLink(subscriptionType) { + switch (subscriptionType) { + case "none": return PRODUCT_PAGE; + case "standard": return SUPPORT_MESSAGE; + case "business": return SUPPORT_MESSAGE; + case "community": return MANAGER_CATEGORY; + default: return PRODUCT_PAGE; + } + }, }); diff --git a/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 index 17b03e78..5a9d6046 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-submissions-show.js.es6 @@ -2,7 +2,6 @@ import { A } from "@ember/array"; import EmberObject from "@ember/object"; import CustomWizardAdmin from "../models/custom-wizard-admin"; import DiscourseRoute from "discourse/routes/discourse"; -import CustomWizard from "../models/custom-wizard"; export default DiscourseRoute.extend({ model(params) { diff --git a/assets/javascripts/discourse/templates/admin-wizards.hbs b/assets/javascripts/discourse/templates/admin-wizards.hbs index 236444cd..cea77942 100644 --- a/assets/javascripts/discourse/templates/admin-wizards.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards.hbs @@ -2,17 +2,15 @@ {{nav-item route="adminWizardsWizard" label="admin.wizard.nav_label"}} {{nav-item route="adminWizardsCustomFields" label="admin.wizard.custom_field.nav_label"}} {{nav-item route="adminWizardsSubmissions" label="admin.wizard.submissions.nav_label"}} - {{#if businessSubscription}} + {{#if showApi}} {{nav-item route="adminWizardsApi" label="admin.wizard.api.nav_label"}} {{/if}} {{nav-item route="adminWizardsLogs" label="admin.wizard.log.nav_label"}} {{nav-item route="adminWizardsManager" label="admin.wizard.manager.nav_label"}} -