diff --git a/assets/javascripts/discourse/components/custom-field-input.js.es6 b/assets/javascripts/discourse/components/custom-field-input.js.es6 index 877b83fb..a673112b 100644 --- a/assets/javascripts/discourse/components/custom-field-input.js.es6 +++ b/assets/javascripts/discourse/components/custom-field-input.js.es6 @@ -6,20 +6,20 @@ import I18n from "I18n"; const klasses = ["topic", "post", "group", "category"]; const types = ["string", "boolean", "integer", "json"]; -const proTypes = { +const subscriptionTypes = { klass: ["group", "category"], type: ["json"], }; -const generateContent = function (array, type, proSubscribed = false) { +const generateContent = function (array, type, subscribed = false) { return array.reduce((result, key) => { - let proArr = proTypes[type]; - let pro = proArr && proArr.includes(key); - if (!pro || proSubscribed) { + 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}`), - pro, + subscription, }); } return result; @@ -32,11 +32,11 @@ export default Component.extend({ postSerializers: ["post"], groupSerializers: ["basic_group"], categorySerializers: ["basic_category"], - klassContent: computed("proSubscribed", function () { - return generateContent(klasses, "klass", this.proSubscribed); + klassContent: computed("subscribed", function () { + return generateContent(klasses, "klass", this.subscribed); }), - typeContent: computed("proSubscribed", function () { - return generateContent(types, "type", this.proSubscribed); + typeContent: computed("subscribed", function () { + return generateContent(types, "type", this.subscribed); }), showInputs: or("field.new", "field.edit"), classNames: ["custom-field-input"], @@ -54,7 +54,7 @@ export default Component.extend({ const serializers = this.get(`${klass}Serializers`); if (serializers) { - return generateContent(serializers, "serializers", this.proSubscribed); + return generateContent(serializers, "serializers", this.subscribed); } else { return []; } diff --git a/assets/javascripts/discourse/components/subscription-container.js.es6 b/assets/javascripts/discourse/components/subscription-container.js.es6 new file mode 100644 index 00000000..08498f6f --- /dev/null +++ b/assets/javascripts/discourse/components/subscription-container.js.es6 @@ -0,0 +1,21 @@ +import Component from "@ember/component"; +import discourseComputed from "discourse-common/utils/decorators"; + +export default Component.extend({ + classNameBindings: [":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`; + } +}) \ No newline at end of file diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index c50be2ba..ffe5b514 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -94,15 +94,15 @@ export default Component.extend(UndoChanges, { return apis.find((a) => a.name === api).endpoints; }, - @discourseComputed("proSubscribed") - actionTypes(proSubscribed) { + @discourseComputed("subscribed") + actionTypes(subscribed) { return Object.keys(wizardSchema.action.types).reduce((result, type) => { - let pro = wizardSchema.action.proTypes.includes(type); - if (proSubscribed || !pro) { + let subscription = wizardSchema.action.subscriptionTypes.includes(type); + if (subscribed || !subscription) { result.push({ id: type, name: I18n.t(`admin.wizard.action.${type}.label`), - pro, + subscription, }); } return result; diff --git a/assets/javascripts/discourse/components/wizard-notice.js.es6 b/assets/javascripts/discourse/components/wizard-notice.js.es6 new file mode 100644 index 00000000..86a82c94 --- /dev/null +++ b/assets/javascripts/discourse/components/wizard-notice.js.es6 @@ -0,0 +1,34 @@ +import Component from "@ember/component"; +import discourseComputed from "discourse-common/utils/decorators"; +import { notEmpty, not } from "@ember/object/computed"; +import I18n from "I18n"; + +export default Component.extend({ + classNameBindings: [':wizard-notice', 'notice.type', 'dismissed', 'expired'], + showFull: false, + resolved: notEmpty('notice.expired_at'), + dismissed: notEmpty('notice.dismissed_at'), + canDismiss: not('dismissed'), + + @discourseComputed('notice.type') + title(type) { + return I18n.t(`admin.wizard.notice.title.${type}`); + }, + + @discourseComputed('notice.type') + icon(type) { + return { + warning: 'exclamation-circle', + info: 'info-circle' + }[type]; + }, + + actions: { + dismiss() { + this.set('dismissing', true) + this.notice.dismiss().then(() => { + this.set('dismissing', false); + }); + } + } +}); \ No newline at end of file diff --git a/assets/javascripts/discourse/components/wizard-realtime-validations.js.es6 b/assets/javascripts/discourse/components/wizard-realtime-validations.js.es6 index 04123e3d..b1d8a0f5 100644 --- a/assets/javascripts/discourse/components/wizard-realtime-validations.js.es6 +++ b/assets/javascripts/discourse/components/wizard-realtime-validations.js.es6 @@ -6,7 +6,7 @@ import discourseComputed from "discourse-common/utils/decorators"; import I18n from "I18n"; export default Component.extend({ - classNames: ["realtime-validations", "setting", "full", "pro"], + classNames: ["realtime-validations", "setting", "full", "subscription"], @discourseComputed timeUnits() { diff --git a/assets/javascripts/discourse/components/wizard-pro-selector.js.es6 b/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6 similarity index 58% rename from assets/javascripts/discourse/components/wizard-pro-selector.js.es6 rename to assets/javascripts/discourse/components/wizard-subscription-selector.js.es6 index 8e472782..ec94bce5 100644 --- a/assets/javascripts/discourse/components/wizard-pro-selector.js.es6 +++ b/assets/javascripts/discourse/components/wizard-subscription-selector.js.es6 @@ -1,18 +1,18 @@ import SingleSelectComponent from "select-kit/components/single-select"; export default SingleSelectComponent.extend({ - classNames: ["combo-box", "wizard-pro-selector"], + classNames: ["combo-box", "wizard-subscription-selector"], selectKitOptions: { autoFilterable: false, filterable: false, showFullTitle: true, - headerComponent: "wizard-pro-selector/wizard-pro-selector-header", + headerComponent: "wizard-subscription-selector/wizard-subscription-selector-header", caretUpIcon: "caret-up", caretDownIcon: "caret-down", }, modifyComponentForRow() { - return "wizard-pro-selector/wizard-pro-selector-row"; + return "wizard-subscription-selector/wizard-subscription-selector-row"; }, }); diff --git a/assets/javascripts/discourse/components/wizard-pro-selector/wizard-pro-selector-header.js.es6 b/assets/javascripts/discourse/components/wizard-subscription-selector/wizard-subscription-selector-header.js.es6 similarity index 88% rename from assets/javascripts/discourse/components/wizard-pro-selector/wizard-pro-selector-header.js.es6 rename to assets/javascripts/discourse/components/wizard-subscription-selector/wizard-subscription-selector-header.js.es6 index c1f7251c..74f29f08 100644 --- a/assets/javascripts/discourse/components/wizard-pro-selector/wizard-pro-selector-header.js.es6 +++ b/assets/javascripts/discourse/components/wizard-subscription-selector/wizard-subscription-selector-header.js.es6 @@ -3,7 +3,7 @@ import { computed } from "@ember/object"; import { reads } from "@ember/object/computed"; export default SingleSelectHeaderComponent.extend({ - classNames: ["combo-box-header", "wizard-pro-selector-header"], + classNames: ["combo-box-header", "wizard-subscription-selector-header"], caretUpIcon: reads("selectKit.options.caretUpIcon"), caretDownIcon: reads("selectKit.options.caretDownIcon"), caretIcon: computed( diff --git a/assets/javascripts/discourse/components/wizard-pro-selector/wizard-pro-selector-row.js.es6 b/assets/javascripts/discourse/components/wizard-subscription-selector/wizard-subscription-selector-row.js.es6 similarity index 100% rename from assets/javascripts/discourse/components/wizard-pro-selector/wizard-pro-selector-row.js.es6 rename to assets/javascripts/discourse/components/wizard-subscription-selector/wizard-subscription-selector-row.js.es6 diff --git a/assets/javascripts/discourse/components/wizard-pro-subscription.js.es6 b/assets/javascripts/discourse/components/wizard-subscription.js.es6 similarity index 75% rename from assets/javascripts/discourse/components/wizard-pro-subscription.js.es6 rename to assets/javascripts/discourse/components/wizard-subscription.js.es6 index 7824cb83..0d839a5f 100644 --- a/assets/javascripts/discourse/components/wizard-pro-subscription.js.es6 +++ b/assets/javascripts/discourse/components/wizard-subscription.js.es6 @@ -1,12 +1,12 @@ import Component from "@ember/component"; -import CustomWizardPro from "../models/custom-wizard-pro"; +import CustomWizardSubscription from "../models/custom-wizard-subscription"; import { notEmpty } from "@ember/object/computed"; import discourseComputed from "discourse-common/utils/decorators"; import I18n from "I18n"; export default Component.extend({ classNameBindings: [ - ":custom-wizard-pro-subscription", + ":custom-wizard-subscription", "subscription.active:active:inactive", ], subscribed: notEmpty("subscription"), @@ -14,8 +14,8 @@ export default Component.extend({ @discourseComputed("subscription.type") title(type) { return type - ? I18n.t(`admin.wizard.pro.subscription.title.${type}`) - : I18n.t("admin.wizard.pro.not_subscribed"); + ? I18n.t(`admin.wizard.subscription.subscription.title.${type}`) + : I18n.t("admin.wizard.subscription.not_subscribed"); }, @discourseComputed("subscription.active") @@ -25,13 +25,13 @@ export default Component.extend({ @discourseComputed("stateClass") stateLabel(stateClass) { - return I18n.t(`admin.wizard.pro.subscription.status.${stateClass}`); + return I18n.t(`admin.wizard.subscription.subscription.status.${stateClass}`); }, actions: { update() { this.set("updating", true); - CustomWizardPro.update_subscription() + CustomWizardSubscription.update() .then((result) => { if (result.success) { this.setProperties({ diff --git a/assets/javascripts/discourse/connectors/admin-dashboard-top/custom-wizard-issue-notice.hbs b/assets/javascripts/discourse/connectors/admin-dashboard-top/custom-wizard-issue-notice.hbs new file mode 100644 index 00000000..a8aad815 --- /dev/null +++ b/assets/javascripts/discourse/connectors/admin-dashboard-top/custom-wizard-issue-notice.hbs @@ -0,0 +1,3 @@ +{{#if wizardWarningNotice}} + {{wizard-notice notice=wizardWarningNotice}} +{{/if}} \ No newline at end of file diff --git a/assets/javascripts/discourse/connectors/admin-dashboard-top/custom-wizard-issue-notice.js.es6 b/assets/javascripts/discourse/connectors/admin-dashboard-top/custom-wizard-issue-notice.js.es6 new file mode 100644 index 00000000..b92e7897 --- /dev/null +++ b/assets/javascripts/discourse/connectors/admin-dashboard-top/custom-wizard-issue-notice.js.es6 @@ -0,0 +1,12 @@ +import { getOwner } from "discourse-common/lib/get-owner"; + +export default { + setupComponent() { + const controller = getOwner(this).lookup('controller:admin-dashboard') + const wizardWarningNotice = controller.get('wizardWarningNotice'); + + if (wizardWarningNotice) { + this.set('wizardWarningNotice', wizardWarningNotice); + } + } +} \ No newline at end of file diff --git a/assets/javascripts/discourse/connectors/admin-menu/wizards-nav-button.hbs b/assets/javascripts/discourse/connectors/admin-menu/wizards-nav-button.hbs index f76722fc..f893d4ac 100644 --- a/assets/javascripts/discourse/connectors/admin-menu/wizards-nav-button.hbs +++ b/assets/javascripts/discourse/connectors/admin-menu/wizards-nav-button.hbs @@ -1,3 +1,7 @@ {{#if currentUser.admin}} {{nav-item route="adminWizards" label="admin.wizard.nav_label"}} + + {{#if wizardErrorNotice}} + {{d-icon "exclaimation-circle"}} + {{/if}} {{/if}} diff --git a/assets/javascripts/discourse/controllers/admin-wizards-pro.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-subscription.js.es6 similarity index 95% rename from assets/javascripts/discourse/controllers/admin-wizards-pro.js.es6 rename to assets/javascripts/discourse/controllers/admin-wizards-subscription.js.es6 index 61012d8f..844d5a25 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-pro.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-subscription.js.es6 @@ -1,6 +1,6 @@ import Controller from "@ember/controller"; import discourseComputed from "discourse-common/utils/decorators"; -import CustomWizardPro from "../models/custom-wizard-pro"; +import CustomWizardSubscription from "../models/custom-wizard-subscription"; import { alias } from "@ember/object/computed"; export default Controller.extend({ diff --git a/assets/javascripts/discourse/controllers/admin-wizards.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards.js.es6 new file mode 100644 index 00000000..a94222c1 --- /dev/null +++ b/assets/javascripts/discourse/controllers/admin-wizards.js.es6 @@ -0,0 +1,20 @@ +import Controller from "@ember/controller"; +import { popupAjaxError } from "discourse/lib/ajax-error"; +import { ajax } from "discourse/lib/ajax"; + +export default Controller.extend({ + actions: { + dismissNotice(noticeId) { + ajax(`/admin/wizards/notice/${this.id}`, { + type: "DELETE", + }) + .then(result => { + if (result.success) { + const notices = this.notices; + notices.removeObject(notices.findBy('id', noticeId)); + } + }) + .catch(popupAjaxError); + } + } +}); \ No newline at end of file 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 1ca6d41b..67b91f87 100644 --- a/assets/javascripts/discourse/custom-wizard-admin-route-map.js.es6 +++ b/assets/javascripts/discourse/custom-wizard-admin-route-map.js.es6 @@ -59,8 +59,8 @@ export default { resetNamespace: true, }); - this.route("adminWizardsPro", { - path: "/pro", + this.route("adminWizardsSubscription", { + path: "/subscription", resetNamespace: true, }); } diff --git a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 index 63ddd5e8..4bf50fa9 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 @@ -1,4 +1,8 @@ import DiscourseURL from "discourse/lib/url"; +import { withPluginApi } from "discourse/lib/plugin-api"; +import { ajax } from "discourse/lib/ajax"; +import CustomWizardNotice from "../models/custom-wizard-notice"; +import { A } from "@ember/array"; export default { name: "custom-wizard-edits", @@ -16,5 +20,29 @@ export default { } return existing.apply(this, [path, opts]); }; + + withPluginApi("0.8.36", (api) => { + api.modifyClass('route:admin-dashboard', { + afterModel() { + return CustomWizardNotice.list().then(result => { + if (result && result.length) { + this.set('notices', A(result.map(n => CustomWizardNotice.create(n)))); + } + }); + }, + + setupController(controller, model) { + if (this.notices) { + let warningNotices = this.notices.filter(n => n.type === 'warning'); + + if (warningNotices.length) { + controller.set('wizardWarningNotice', warningNotices[0]); + } + } + + this._super(...arguments); + } + }); + }); }, }; diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index a20b61a7..5d876ed0 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -193,6 +193,14 @@ const action = { "members_visibility_level", ], required: ["id", "type"], + subscriptionTypes: [ + "send_message", + "add_to_group", + "create_category", + "create_group", + "send_to_api", + ], + required: ["id", "type"], proTypes: [ "send_message", "add_to_group", diff --git a/assets/javascripts/discourse/models/custom-wizard-notice.js.es6 b/assets/javascripts/discourse/models/custom-wizard-notice.js.es6 new file mode 100644 index 00000000..bae81822 --- /dev/null +++ b/assets/javascripts/discourse/models/custom-wizard-notice.js.es6 @@ -0,0 +1,23 @@ +import EmberObject from "@ember/object"; +import { ajax } from "discourse/lib/ajax"; +import { popupAjaxError } from "discourse/lib/ajax-error"; + +const CustomWizardNotice = EmberObject.extend(); + +CustomWizardNotice.reopen({ + dismiss() { + return ajax(`/admin/wizards/notice/${this.id}`, { type: 'PUT' }).then(result => { + if (result.success) { + this.set('dismissed_at', result.dismissed_at); + } + }).catch(popupAjaxError) + } +}); + +CustomWizardNotice.reopenClass({ + list() { + return ajax('/admin/wizards/notice').catch(popupAjaxError) + } +}); + +export default CustomWizardNotice; \ No newline at end of file diff --git a/assets/javascripts/discourse/models/custom-wizard-pro.js.es6 b/assets/javascripts/discourse/models/custom-wizard-subscription.js.es6 similarity index 68% rename from assets/javascripts/discourse/models/custom-wizard-pro.js.es6 rename to assets/javascripts/discourse/models/custom-wizard-subscription.js.es6 index 76429726..469460d5 100644 --- a/assets/javascripts/discourse/models/custom-wizard-pro.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard-subscription.js.es6 @@ -2,11 +2,11 @@ import { ajax } from "discourse/lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; import EmberObject from "@ember/object"; -const CustomWizardPro = EmberObject.extend(); +const CustomWizardSubscription = EmberObject.extend(); -const basePath = "/admin/wizards/pro"; +const basePath = "/admin/wizards/subscription"; -CustomWizardPro.reopenClass({ +CustomWizardSubscription.reopenClass({ status() { return ajax(basePath, { type: "GET", @@ -23,11 +23,11 @@ CustomWizardPro.reopenClass({ }).catch(popupAjaxError); }, - update_subscription() { - return ajax(`${basePath}/subscription`, { + update() { + return ajax(basePath, { type: "POST", }).catch(popupAjaxError); }, }); -export default CustomWizardPro; +export default CustomWizardSubscription; 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 45ca9ae7..ca9c4c40 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-custom-fields.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-custom-fields.js.es6 @@ -9,11 +9,11 @@ export default DiscourseRoute.extend({ setupController(controller, model) { const customFields = A(model.custom_fields || []); - const proSubscribed = model.pro_subscribed; + const subscribed = model.subscribed; controller.setProperties({ customFields, - proSubscribed, + subscribed, }); }, }); diff --git a/assets/javascripts/discourse/routes/admin-wizards-pro.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-subscription.js.es6 similarity index 61% rename from assets/javascripts/discourse/routes/admin-wizards-pro.js.es6 rename to assets/javascripts/discourse/routes/admin-wizards-subscription.js.es6 index d5c7fbd7..4824425a 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-pro.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-subscription.js.es6 @@ -1,9 +1,9 @@ -import CustomWizardPro from "../models/custom-wizard-pro"; +import CustomWizardSubscription from "../models/custom-wizard-subscription"; import DiscourseRoute from "discourse/routes/discourse"; export default DiscourseRoute.extend({ model() { - return CustomWizardPro.status(); + return CustomWizardSubscription.status(); }, setupController(controller, model) { @@ -13,7 +13,7 @@ export default DiscourseRoute.extend({ actions: { authorize() { - CustomWizardPro.authorize(); + CustomWizardSubscription.authorize(); }, }, }); 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 7032b974..046fc6d4 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 @@ -39,7 +39,7 @@ export default DiscourseRoute.extend({ currentStep: wizard.steps[0], currentAction: wizard.actions[0], creating: model.create, - proSubscribed: parentModel.pro_subscribed, + subscribed: parentModel.subscribed, }; controller.setProperties(props); diff --git a/assets/javascripts/discourse/routes/admin-wizards.js.es6 b/assets/javascripts/discourse/routes/admin-wizards.js.es6 index 5de271a8..da184d93 100644 --- a/assets/javascripts/discourse/routes/admin-wizards.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards.js.es6 @@ -1,9 +1,19 @@ import DiscourseRoute from "discourse/routes/discourse"; +import { ajax } from "discourse/lib/ajax"; +import { A } from "@ember/array"; export default DiscourseRoute.extend({ - beforeModel(transition) { + model() { + return ajax('/admin/wizards'); + }, + + setupController(controller, model) { + controller.set('notices', A(model.notices)); + }, + + 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 09a0d569..361d2d44 100644 --- a/assets/javascripts/discourse/templates/admin-wizards-custom-fields.hbs +++ b/assets/javascripts/discourse/templates/admin-wizards-custom-fields.hbs @@ -33,7 +33,7 @@ field=field removeField=(action "removeField") saveField=(action "saveField") - proSubscribed=proSubscribed}} + subscribed=subscribed}} {{/each}} diff --git a/assets/javascripts/discourse/templates/admin-wizards-pro.hbs b/assets/javascripts/discourse/templates/admin-wizards-pro.hbs deleted file mode 100644 index b4f0691b..00000000 --- a/assets/javascripts/discourse/templates/admin-wizards-pro.hbs +++ /dev/null @@ -1,34 +0,0 @@ -