2021-04-12 07:10:02 +02:00
|
|
|
import { get, set } from "@ember/object";
|
2021-05-05 08:05:53 +02:00
|
|
|
import { getOwner } from "discourse-common/lib/get-owner";
|
2020-04-16 04:04:27 +02:00
|
|
|
|
|
|
|
const wizard = {
|
|
|
|
basic: {
|
|
|
|
id: null,
|
|
|
|
name: null,
|
|
|
|
background: null,
|
|
|
|
save_submissions: true,
|
|
|
|
multiple_submissions: null,
|
|
|
|
after_signup: null,
|
|
|
|
after_time: null,
|
|
|
|
after_time_scheduled: null,
|
|
|
|
required: null,
|
|
|
|
prompt_completion: null,
|
|
|
|
restart_on_revisit: null,
|
2021-09-22 10:22:05 +02:00
|
|
|
resume_on_revisit: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
theme_id: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
permitted: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
2021-03-28 11:06:49 +02:00
|
|
|
mapped: ["permitted"],
|
|
|
|
required: ["id"],
|
2020-04-16 04:04:27 +02:00
|
|
|
dependent: {
|
2021-03-28 11:06:49 +02:00
|
|
|
after_time: "after_time_scheduled",
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
objectArrays: {
|
|
|
|
step: {
|
2021-03-28 11:06:49 +02:00
|
|
|
property: "steps",
|
|
|
|
required: false,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
action: {
|
2021-03-28 11:06:49 +02:00
|
|
|
property: "actions",
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
},
|
2020-04-16 04:04:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const step = {
|
|
|
|
basic: {
|
|
|
|
id: null,
|
2021-04-20 19:58:19 +02:00
|
|
|
index: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
title: null,
|
|
|
|
banner: null,
|
2022-08-02 13:39:56 +02:00
|
|
|
banner_upload_id: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
raw_description: null,
|
|
|
|
required_data: null,
|
|
|
|
required_data_message: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
permitted_params: null,
|
2021-04-20 19:58:19 +02:00
|
|
|
condition: null,
|
|
|
|
force_final: false,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
2021-04-20 19:58:19 +02:00
|
|
|
mapped: ["required_data", "permitted_params", "condition", "index"],
|
2021-03-28 11:06:49 +02:00
|
|
|
required: ["id"],
|
|
|
|
dependent: {},
|
2020-04-16 04:04:27 +02:00
|
|
|
objectArrays: {
|
|
|
|
field: {
|
2021-03-28 11:06:49 +02:00
|
|
|
property: "fields",
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2020-04-16 04:04:27 +02:00
|
|
|
|
|
|
|
const field = {
|
|
|
|
basic: {
|
|
|
|
id: null,
|
2021-04-20 19:58:19 +02:00
|
|
|
index: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
label: null,
|
|
|
|
image: null,
|
2022-08-02 13:39:56 +02:00
|
|
|
image_upload_id: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
description: null,
|
2021-09-03 10:46:32 +02:00
|
|
|
property: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
required: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
type: null,
|
2021-04-20 19:58:19 +02:00
|
|
|
condition: null,
|
2023-03-08 11:10:46 +01:00
|
|
|
tag_groups: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
types: {},
|
2021-04-20 19:58:19 +02:00
|
|
|
mapped: ["prefill", "content", "condition", "index"],
|
2021-03-28 11:06:49 +02:00
|
|
|
required: ["id", "type"],
|
|
|
|
dependent: {},
|
|
|
|
objectArrays: {},
|
|
|
|
};
|
2020-04-16 04:04:27 +02:00
|
|
|
|
|
|
|
const action = {
|
|
|
|
basic: {
|
|
|
|
id: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
run_after: "wizard_completion",
|
|
|
|
type: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
types: {
|
|
|
|
create_topic: {
|
|
|
|
title: null,
|
|
|
|
post: null,
|
|
|
|
post_builder: null,
|
|
|
|
post_template: null,
|
|
|
|
category: null,
|
|
|
|
tags: null,
|
2020-07-20 06:26:11 +02:00
|
|
|
visible: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
custom_fields: null,
|
2020-10-20 02:42:10 +02:00
|
|
|
skip_redirect: null,
|
|
|
|
suppress_notifications: null,
|
2022-09-19 12:09:34 +02:00
|
|
|
add_event: null,
|
2022-10-10 14:04:55 +02:00
|
|
|
add_location: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
send_message: {
|
|
|
|
title: null,
|
|
|
|
post: null,
|
|
|
|
post_builder: null,
|
|
|
|
post_template: null,
|
2023-09-22 04:31:15 +02:00
|
|
|
tags: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
skip_redirect: null,
|
|
|
|
custom_fields: null,
|
|
|
|
required: null,
|
2020-10-20 02:42:10 +02:00
|
|
|
recipient: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
suppress_notifications: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
open_composer: {
|
|
|
|
title: null,
|
|
|
|
post: null,
|
|
|
|
post_builder: null,
|
|
|
|
post_template: null,
|
|
|
|
category: null,
|
|
|
|
tags: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
custom_fields: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
update_profile: {
|
|
|
|
profile_updates: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
custom_fields: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
2020-05-23 00:42:26 +02:00
|
|
|
watch_categories: {
|
2020-05-24 09:56:27 +02:00
|
|
|
categories: null,
|
2020-05-25 15:59:31 +02:00
|
|
|
notification_level: null,
|
2020-07-20 05:06:36 +02:00
|
|
|
mute_remainder: null,
|
|
|
|
wizard_user: true,
|
2021-03-28 11:06:49 +02:00
|
|
|
usernames: null,
|
2020-05-23 00:42:26 +02:00
|
|
|
},
|
2022-12-23 17:28:09 +01:00
|
|
|
watch_tags: {
|
|
|
|
tags: null,
|
|
|
|
notification_level: null,
|
|
|
|
wizard_user: true,
|
|
|
|
usernames: null,
|
|
|
|
},
|
2020-05-30 21:26:14 +02:00
|
|
|
send_to_api: {
|
|
|
|
api: null,
|
|
|
|
api_endpoint: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
api_body: null,
|
2020-05-30 21:26:14 +02:00
|
|
|
},
|
2020-04-16 04:04:27 +02:00
|
|
|
add_to_group: {
|
2021-03-28 11:06:49 +02:00
|
|
|
group: null,
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
route_to: {
|
|
|
|
url: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
code: null,
|
2020-07-09 04:19:36 +02:00
|
|
|
},
|
|
|
|
create_category: {
|
|
|
|
name: null,
|
|
|
|
slug: null,
|
|
|
|
color: null,
|
|
|
|
text_color: "FFFFFF",
|
|
|
|
parent_category_id: null,
|
2020-07-17 04:10:59 +02:00
|
|
|
permissions: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
custom_fields: null,
|
2020-07-16 07:25:06 +02:00
|
|
|
},
|
|
|
|
create_group: {
|
|
|
|
name: null,
|
|
|
|
full_name: null,
|
|
|
|
title: null,
|
|
|
|
bio_raw: null,
|
2020-07-16 09:50:09 +02:00
|
|
|
owner_usernames: null,
|
|
|
|
usernames: null,
|
2020-07-16 07:25:06 +02:00
|
|
|
grant_trust_level: null,
|
|
|
|
mentionable_level: null,
|
|
|
|
messageable_level: null,
|
|
|
|
visibility_level: null,
|
2020-07-17 04:10:59 +02:00
|
|
|
members_visibility_level: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
custom_fields: null,
|
|
|
|
},
|
2020-04-16 04:04:27 +02:00
|
|
|
},
|
|
|
|
mapped: [
|
2021-03-28 11:06:49 +02:00
|
|
|
"title",
|
|
|
|
"category",
|
|
|
|
"tags",
|
|
|
|
"visible",
|
|
|
|
"custom_fields",
|
|
|
|
"required",
|
|
|
|
"recipient",
|
|
|
|
"profile_updates",
|
|
|
|
"group",
|
|
|
|
"url",
|
|
|
|
"categories",
|
|
|
|
"mute_remainder",
|
|
|
|
"name",
|
|
|
|
"slug",
|
|
|
|
"color",
|
|
|
|
"text_color",
|
|
|
|
"parent_category_id",
|
|
|
|
"permissions",
|
|
|
|
"full_name",
|
|
|
|
"bio_raw",
|
|
|
|
"owner_usernames",
|
|
|
|
"usernames",
|
|
|
|
"grant_trust_level",
|
|
|
|
"mentionable_level",
|
|
|
|
"messageable_level",
|
|
|
|
"visibility_level",
|
|
|
|
"members_visibility_level",
|
2022-09-19 12:09:34 +02:00
|
|
|
"add_event",
|
2022-10-10 14:04:55 +02:00
|
|
|
"add_location",
|
2020-04-16 04:04:27 +02:00
|
|
|
],
|
2021-03-28 11:06:49 +02:00
|
|
|
required: ["id", "type"],
|
|
|
|
dependent: {},
|
|
|
|
objectArrays: {},
|
|
|
|
};
|
2020-04-16 04:04:27 +02:00
|
|
|
|
2022-12-24 09:42:09 +01:00
|
|
|
const filters = {
|
|
|
|
allow_guests: {
|
2023-02-09 14:18:25 +01:00
|
|
|
field: {
|
|
|
|
type: [
|
|
|
|
"text",
|
|
|
|
"textarea",
|
|
|
|
"text_only",
|
|
|
|
"date",
|
|
|
|
"time",
|
|
|
|
"date_time",
|
|
|
|
"number",
|
|
|
|
"checkbox",
|
|
|
|
"url",
|
|
|
|
"dropdown",
|
|
|
|
"tag",
|
|
|
|
"category",
|
|
|
|
"group",
|
|
|
|
"user_selector",
|
|
|
|
],
|
|
|
|
},
|
2022-12-24 09:42:09 +01:00
|
|
|
action: {
|
2023-01-26 11:26:24 +01:00
|
|
|
type: ["route_to", "send_message"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2022-12-24 09:42:09 +01:00
|
|
|
|
2021-10-23 14:06:12 +02:00
|
|
|
const custom_field = {
|
2021-11-02 09:58:15 +01:00
|
|
|
klass: ["topic", "post", "group", "category"],
|
|
|
|
type: ["string", "boolean", "integer", "json"],
|
2021-10-27 16:01:29 +02:00
|
|
|
};
|
2021-10-23 14:06:12 +02:00
|
|
|
|
2023-03-02 10:36:06 +01:00
|
|
|
export function buildFieldTypes(types) {
|
|
|
|
wizardSchema.field.types = types;
|
2023-04-03 04:37:09 +02:00
|
|
|
wizardSchema.field.type = Object.keys(types);
|
2023-03-02 10:36:06 +01:00
|
|
|
}
|
|
|
|
|
2022-03-25 12:18:54 +01:00
|
|
|
field.type = Object.keys(field.types);
|
|
|
|
action.type = Object.keys(action.types);
|
2021-10-25 16:31:44 +02:00
|
|
|
|
2020-04-16 04:04:27 +02:00
|
|
|
const wizardSchema = {
|
|
|
|
wizard,
|
|
|
|
step,
|
|
|
|
field,
|
2021-10-23 14:06:12 +02:00
|
|
|
custom_field,
|
2022-03-25 12:22:27 +01:00
|
|
|
action,
|
2023-01-26 11:26:24 +01:00
|
|
|
filters,
|
2021-10-27 16:01:29 +02:00
|
|
|
};
|
2021-10-25 16:31:44 +02:00
|
|
|
|
2021-01-27 06:08:26 +01:00
|
|
|
export function buildFieldValidations(validations) {
|
|
|
|
wizardSchema.field.validations = validations;
|
2021-11-02 10:06:00 +01:00
|
|
|
}
|
2021-01-27 06:08:26 +01:00
|
|
|
|
2023-02-09 14:18:25 +01:00
|
|
|
export function filterValues(currentWizard, feature, attribute, values = null) {
|
|
|
|
values = values || wizardSchema[feature][attribute];
|
|
|
|
|
2023-03-02 10:36:06 +01:00
|
|
|
if (currentWizard && currentWizard.allowGuests) {
|
2023-02-09 14:18:25 +01:00
|
|
|
const filteredFeature = wizardSchema.filters.allow_guests[feature];
|
|
|
|
if (filteredFeature) {
|
|
|
|
const filtered = filteredFeature[attribute];
|
|
|
|
if (filtered) {
|
|
|
|
values = values.filter((v) => filtered.includes(v));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
2022-08-15 13:53:31 +02:00
|
|
|
const siteSettings = getOwner(this).lookup("service:site-settings");
|
2021-05-05 08:05:53 +02:00
|
|
|
if (siteSettings.wizard_apis_enabled) {
|
2020-04-16 04:04:27 +02:00
|
|
|
wizardSchema.action.types.send_to_api = {
|
|
|
|
api: null,
|
|
|
|
api_endpoint: null,
|
2021-03-28 11:06:49 +02:00
|
|
|
api_body: null,
|
|
|
|
};
|
2021-11-02 10:06:00 +01:00
|
|
|
}
|
2020-04-16 04:04:27 +02:00
|
|
|
|
2021-04-12 07:44:47 +02:00
|
|
|
export function setWizardDefaults(obj, itemType) {
|
2020-04-20 11:41:13 +02:00
|
|
|
const objSchema = wizardSchema[itemType];
|
|
|
|
const basicDefaults = objSchema.basic;
|
2021-03-28 11:06:49 +02:00
|
|
|
|
|
|
|
Object.keys(basicDefaults).forEach((property) => {
|
2020-04-20 11:41:13 +02:00
|
|
|
let defaultValue = get(basicDefaults, property);
|
|
|
|
if (defaultValue) {
|
|
|
|
set(obj, property, defaultValue);
|
2020-04-16 04:04:27 +02:00
|
|
|
}
|
|
|
|
});
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-04-20 23:21:44 +02:00
|
|
|
if (objSchema.types) {
|
|
|
|
const typeDefaults = objSchema.types[obj.type];
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-04-20 23:21:44 +02:00
|
|
|
if (typeDefaults) {
|
2021-03-28 11:06:49 +02:00
|
|
|
Object.keys(typeDefaults).forEach((property) => {
|
2020-04-20 23:21:44 +02:00
|
|
|
if (typeDefaults.hasOwnProperty(property)) {
|
|
|
|
set(obj, property, get(typeDefaults, property));
|
2021-03-28 11:06:49 +02:00
|
|
|
}
|
2020-04-20 23:21:44 +02:00
|
|
|
});
|
|
|
|
}
|
2020-04-16 04:04:27 +02:00
|
|
|
}
|
2021-03-28 11:06:49 +02:00
|
|
|
|
2020-04-20 11:41:13 +02:00
|
|
|
return obj;
|
2021-11-02 10:06:00 +01:00
|
|
|
}
|
2020-04-16 04:04:27 +02:00
|
|
|
|
2021-03-28 11:06:49 +02:00
|
|
|
export default wizardSchema;
|