0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-27 11:20:28 +01:00
discourse-custom-wizard/assets/javascripts/discourse/lib/wizard-schema.js.es6

317 Zeilen
6,3 KiB
Text

2021-04-12 07:10:02 +02:00
import { get, set } from "@ember/object";
import { getOwner } from "discourse-common/lib/get-owner";
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,
resume_on_revisit: null,
theme_id: null,
permitted: null,
},
mapped: ["permitted"],
required: ["id"],
dependent: {
after_time: "after_time_scheduled",
},
objectArrays: {
step: {
property: "steps",
required: false,
},
action: {
property: "actions",
required: false,
},
},
};
const step = {
basic: {
id: null,
index: null,
title: null,
banner: null,
2022-08-02 13:39:56 +02:00
banner_upload_id: null,
raw_description: null,
required_data: null,
required_data_message: null,
permitted_params: null,
condition: null,
force_final: false,
},
mapped: ["required_data", "permitted_params", "condition", "index"],
required: ["id"],
dependent: {},
objectArrays: {
field: {
property: "fields",
required: false,
},
},
};
const field = {
basic: {
id: null,
index: null,
label: null,
image: null,
2022-08-02 13:39:56 +02:00
image_upload_id: null,
description: null,
2021-09-03 10:46:32 +02:00
property: null,
required: null,
type: null,
condition: null,
2023-03-08 11:10:46 +01:00
tag_groups: null,
},
types: {},
mapped: ["prefill", "content", "condition", "index"],
required: ["id", "type"],
dependent: {},
objectArrays: {},
};
const action = {
basic: {
id: null,
run_after: "wizard_completion",
type: null,
},
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,
custom_fields: null,
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,
},
send_message: {
title: null,
post: null,
post_builder: null,
post_template: null,
skip_redirect: null,
custom_fields: null,
required: null,
recipient: null,
suppress_notifications: null,
},
open_composer: {
title: null,
post: null,
post_builder: null,
post_template: null,
category: null,
tags: null,
custom_fields: null,
},
update_profile: {
profile_updates: null,
custom_fields: null,
},
watch_categories: {
2020-05-24 09:56:27 +02:00
categories: null,
notification_level: null,
2020-07-20 05:06:36 +02:00
mute_remainder: null,
wizard_user: true,
usernames: null,
},
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,
api_body: null,
2020-05-30 21:26:14 +02:00
},
add_to_group: {
group: null,
},
route_to: {
url: null,
code: null,
},
create_category: {
name: null,
slug: null,
color: null,
text_color: "FFFFFF",
parent_category_id: null,
permissions: null,
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,
members_visibility_level: null,
custom_fields: null,
},
},
mapped: [
"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",
],
required: ["id", "type"],
dependent: {},
objectArrays: {},
};
2022-12-24 09:42:09 +01:00
const filters = {
allow_guests: {
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
const custom_field = {
klass: ["topic", "post", "group", "category"],
type: ["string", "boolean", "integer", "json"],
2021-10-27 16:01:29 +02:00
};
2023-03-02 10:36:06 +01:00
export function buildFieldTypes(types) {
wizardSchema.field.types = types;
}
field.type = Object.keys(field.types);
action.type = Object.keys(action.types);
const wizardSchema = {
wizard,
step,
field,
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-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
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) {
const filteredFeature = wizardSchema.filters.allow_guests[feature];
if (filteredFeature) {
const filtered = filteredFeature[attribute];
if (filtered) {
values = values.filter((v) => filtered.includes(v));
}
}
}
return values;
}
const siteSettings = getOwner(this).lookup("service:site-settings");
if (siteSettings.wizard_apis_enabled) {
wizardSchema.action.types.send_to_api = {
api: null,
api_endpoint: null,
api_body: null,
};
2021-11-02 10:06:00 +01: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;
Object.keys(basicDefaults).forEach((property) => {
2020-04-20 11:41:13 +02:00
let defaultValue = get(basicDefaults, property);
if (defaultValue) {
set(obj, property, defaultValue);
}
});
if (objSchema.types) {
const typeDefaults = objSchema.types[obj.type];
if (typeDefaults) {
Object.keys(typeDefaults).forEach((property) => {
if (typeDefaults.hasOwnProperty(property)) {
set(obj, property, get(typeDefaults, property));
}
});
}
}
2020-04-20 11:41:13 +02:00
return obj;
2021-11-02 10:06:00 +01:00
}
export default wizardSchema;