2021-03-28 11:06:49 +02:00
|
|
|
import { default as discourseComputed } from "discourse-common/utils/decorators";
|
2021-10-12 13:51:38 +02:00
|
|
|
import wizardSchema, {
|
2021-10-22 20:56:00 +02:00
|
|
|
actionsRequiringAdditionalSubscription,
|
|
|
|
actionSubscriptionLevel,
|
2021-10-12 13:51:38 +02:00
|
|
|
} from "discourse/plugins/discourse-custom-wizard/discourse/lib/wizard-schema";
|
2021-09-07 14:06:13 +02:00
|
|
|
import { empty, equal, or } from "@ember/object/computed";
|
2021-04-12 07:44:47 +02:00
|
|
|
import { notificationLevels, selectKitContent } from "../lib/wizard";
|
2020-04-20 11:41:13 +02:00
|
|
|
import { computed } from "@ember/object";
|
2021-03-28 11:06:49 +02:00
|
|
|
import UndoChanges from "../mixins/undo-changes";
|
2020-04-05 03:37:09 +02:00
|
|
|
import Component from "@ember/component";
|
2020-05-28 05:06:06 +02:00
|
|
|
import I18n from "I18n";
|
2017-10-13 15:02:34 +02:00
|
|
|
|
2020-04-20 11:41:13 +02:00
|
|
|
export default Component.extend(UndoChanges, {
|
2021-03-28 11:06:49 +02:00
|
|
|
componentType: "action",
|
|
|
|
classNameBindings: [":wizard-custom-action", "visible"],
|
|
|
|
visible: computed("currentActionId", function () {
|
|
|
|
return this.action.id === this.currentActionId;
|
|
|
|
}),
|
|
|
|
createTopic: equal("action.type", "create_topic"),
|
|
|
|
updateProfile: equal("action.type", "update_profile"),
|
|
|
|
watchCategories: equal("action.type", "watch_categories"),
|
|
|
|
sendMessage: equal("action.type", "send_message"),
|
|
|
|
openComposer: equal("action.type", "open_composer"),
|
|
|
|
sendToApi: equal("action.type", "send_to_api"),
|
|
|
|
addToGroup: equal("action.type", "add_to_group"),
|
|
|
|
routeTo: equal("action.type", "route_to"),
|
|
|
|
createCategory: equal("action.type", "create_category"),
|
|
|
|
createGroup: equal("action.type", "create_group"),
|
|
|
|
apiEmpty: empty("action.api"),
|
|
|
|
groupPropertyTypes: selectKitContent(["id", "name"]),
|
|
|
|
hasCustomFields: or(
|
|
|
|
"basicTopicFields",
|
|
|
|
"updateProfile",
|
|
|
|
"createGroup",
|
|
|
|
"createCategory"
|
|
|
|
),
|
|
|
|
basicTopicFields: or("createTopic", "sendMessage", "openComposer"),
|
|
|
|
publicTopicFields: or("createTopic", "openComposer"),
|
|
|
|
showPostAdvanced: or("createTopic", "sendMessage"),
|
2021-04-12 07:44:47 +02:00
|
|
|
availableNotificationLevels: notificationLevels.map((type) => {
|
2020-05-25 15:59:31 +02:00
|
|
|
return {
|
|
|
|
id: type,
|
2021-03-28 11:06:49 +02:00
|
|
|
name: I18n.t(
|
|
|
|
`admin.wizard.action.watch_categories.notification_level.${type}`
|
|
|
|
),
|
2020-05-25 15:59:31 +02:00
|
|
|
};
|
|
|
|
}),
|
2021-03-28 11:06:49 +02:00
|
|
|
|
|
|
|
messageUrl: "https://thepavilion.io/t/2810",
|
|
|
|
|
|
|
|
@discourseComputed("action.type")
|
2020-04-20 13:40:32 +02:00
|
|
|
messageKey(type) {
|
2021-03-28 11:06:49 +02:00
|
|
|
let key = "type";
|
2020-04-20 13:40:32 +02:00
|
|
|
if (type) {
|
2021-03-28 11:06:49 +02:00
|
|
|
key = "edit";
|
2020-04-20 13:40:32 +02:00
|
|
|
}
|
|
|
|
return key;
|
|
|
|
},
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2021-06-08 13:39:49 +02:00
|
|
|
@discourseComputed("action.type")
|
|
|
|
customFieldsContext(type) {
|
|
|
|
return `action.${type}`;
|
|
|
|
},
|
|
|
|
|
2021-03-28 11:06:49 +02:00
|
|
|
@discourseComputed("wizard.steps")
|
2020-04-08 04:52:07 +02:00
|
|
|
runAfterContent(steps) {
|
2021-03-28 11:06:49 +02:00
|
|
|
let content = steps.map(function (step) {
|
2020-04-08 09:59:54 +02:00
|
|
|
return {
|
|
|
|
id: step.id,
|
2021-03-28 11:06:49 +02:00
|
|
|
name: step.title || step.id,
|
2020-04-08 09:59:54 +02:00
|
|
|
};
|
|
|
|
});
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-04-08 04:52:07 +02:00
|
|
|
content.unshift({
|
2021-03-28 11:06:49 +02:00
|
|
|
id: "wizard_completion",
|
|
|
|
name: I18n.t("admin.wizard.action.run_after.wizard_completion"),
|
2020-04-08 04:52:07 +02:00
|
|
|
});
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-04-08 04:52:07 +02:00
|
|
|
return content;
|
2019-06-03 09:09:24 +02:00
|
|
|
},
|
|
|
|
|
2021-03-28 11:06:49 +02:00
|
|
|
@discourseComputed("apis")
|
2019-06-03 09:09:24 +02:00
|
|
|
availableApis(apis) {
|
2021-03-28 11:06:49 +02:00
|
|
|
return apis.map((a) => {
|
2019-06-03 09:09:24 +02:00
|
|
|
return {
|
|
|
|
id: a.name,
|
2021-03-28 11:06:49 +02:00
|
|
|
name: a.title,
|
2019-06-03 09:09:24 +02:00
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2021-03-28 11:06:49 +02:00
|
|
|
@discourseComputed("apis", "action.api")
|
2019-06-03 09:09:24 +02:00
|
|
|
availableEndpoints(apis, api) {
|
2021-04-12 08:12:20 +02:00
|
|
|
if (!api) {
|
|
|
|
return [];
|
|
|
|
}
|
2021-03-28 11:06:49 +02:00
|
|
|
return apis.find((a) => a.name === api).endpoints;
|
|
|
|
},
|
2021-09-03 10:46:32 +02:00
|
|
|
|
2021-10-12 13:51:38 +02:00
|
|
|
@discourseComputed("subscribed", "subscription")
|
|
|
|
actionTypes(subscribed, subscription) {
|
2021-10-22 20:56:00 +02:00
|
|
|
let unsubscribedActions = actionsRequiringAdditionalSubscription(
|
2021-10-19 14:49:06 +02:00
|
|
|
subscription
|
|
|
|
);
|
2021-09-03 10:46:32 +02:00
|
|
|
return Object.keys(wizardSchema.action.types).reduce((result, type) => {
|
2021-10-14 14:41:24 +02:00
|
|
|
let disabled = unsubscribedActions.includes(type);
|
2021-10-12 13:51:38 +02:00
|
|
|
result.push({
|
|
|
|
id: type,
|
|
|
|
name: I18n.t(`admin.wizard.action.${type}.label`),
|
2021-10-22 20:56:00 +02:00
|
|
|
subscription: actionSubscriptionLevel(type),
|
2021-10-14 14:41:24 +02:00
|
|
|
disabled: disabled,
|
2021-10-12 13:51:38 +02:00
|
|
|
});
|
2021-09-03 10:46:32 +02:00
|
|
|
return result;
|
|
|
|
}, []);
|
2021-09-07 14:13:01 +02:00
|
|
|
},
|
2017-09-23 04:34:07 +02:00
|
|
|
});
|