Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-24 10:20:28 +01:00
wip
Dieser Commit ist enthalten in:
Ursprung
0d0fb83bd1
Commit
1a6a9e691c
14 geänderte Dateien mit 139 neuen und 6 gelöschten Zeilen
|
@ -0,0 +1,24 @@
|
|||
import { observes } from "discourse-common/utils/decorators";
|
||||
import Topic from "discourse/models/topic";
|
||||
import Component from "@ember/component";
|
||||
|
||||
export default Component.extend({
|
||||
topics: [],
|
||||
|
||||
didInsertElement() {
|
||||
const value = this.field.value;
|
||||
|
||||
if (value) {
|
||||
this.set("topics", value);
|
||||
}
|
||||
console.log(this.field)
|
||||
},
|
||||
|
||||
actions: {
|
||||
setValue(topicIds, topics) {
|
||||
if (topics.length) {
|
||||
this.set("field.value", topics);
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
|
@ -0,0 +1,72 @@
|
|||
import MultiSelectComponent from "select-kit/components/multi-select";
|
||||
import { computed } from "@ember/object";
|
||||
import { mapBy } from "@ember/object/computed";
|
||||
import { isEmpty } from "@ember/utils";
|
||||
import { searchForTerm } from "discourse/lib/search";
|
||||
import { makeArray } from "discourse-common/lib/helpers";
|
||||
|
||||
export default MultiSelectComponent.extend({
|
||||
classNames: ["topic-selector", "wizard-topic-selector"],
|
||||
topics: null,
|
||||
value: [],
|
||||
content: [],
|
||||
nameProperty: "fancy_title",
|
||||
labelProperty: "title",
|
||||
titleProperty: "title",
|
||||
|
||||
selectKitOptions: {
|
||||
clearable: true,
|
||||
filterable: true,
|
||||
filterPlaceholder: "choose_topic.title.placeholder",
|
||||
allowAny: false,
|
||||
},
|
||||
|
||||
didReceiveAttrs() {
|
||||
if (this.topics && !this.selectKit.hasSelection) {
|
||||
const values = makeArray(this.topics.map(t => t.id));
|
||||
const content = makeArray(this.topics);
|
||||
this.selectKit.change(values, content);
|
||||
}
|
||||
this._super(...arguments);
|
||||
},
|
||||
|
||||
modifyComponentForRow() {
|
||||
return "topic-row";
|
||||
},
|
||||
|
||||
search(filter) {
|
||||
if (isEmpty(filter)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const searchParams = {};
|
||||
searchParams.typeFilter = "topic";
|
||||
searchParams.restrictToArchetype = "regular";
|
||||
searchParams.searchForId = true;
|
||||
|
||||
return searchForTerm(
|
||||
filter,
|
||||
searchParams
|
||||
).then((results) => {
|
||||
if (results?.posts?.length > 0) {
|
||||
return results.posts.mapBy("topic");
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
actions: {
|
||||
onChange(value, items) {
|
||||
const content = items.map(t => {
|
||||
return {
|
||||
id: t.id,
|
||||
title: t.title,
|
||||
fancy_title: t.fancy_title,
|
||||
url: t.url
|
||||
}
|
||||
});
|
||||
console.log("onChange: ", value, content)
|
||||
this.setProperties({ value, content });
|
||||
this.onChange(value, content);
|
||||
},
|
||||
},
|
||||
});
|
|
@ -15,15 +15,16 @@ export default Component.extend(UndoChanges, {
|
|||
isDropdown: equal("field.type", "dropdown"),
|
||||
isUpload: equal("field.type", "upload"),
|
||||
isCategory: equal("field.type", "category"),
|
||||
isTopic: equal("field.type", "topic"),
|
||||
isGroup: equal("field.type", "group"),
|
||||
isTag: equal("field.type", "tag"),
|
||||
isText: equal("field.type", "text"),
|
||||
isTextarea: equal("field.type", "textarea"),
|
||||
isUrl: equal("field.type", "url"),
|
||||
isComposer: equal("field.type", "composer"),
|
||||
showPrefill: or("isText", "isCategory", "isTag", "isGroup", "isDropdown"),
|
||||
showContent: or("isCategory", "isTag", "isGroup", "isDropdown"),
|
||||
showLimit: or("isCategory", "isTag"),
|
||||
showPrefill: or("isText", "isCategory", "isTag", "isGroup", "isDropdown", "isTopic"),
|
||||
showContent: or("isCategory", "isTag", "isGroup", "isDropdown", "isTopic"),
|
||||
showLimit: or("isCategory", "isTag", "isTopic"),
|
||||
isTextType: or("isText", "isTextarea", "isComposer"),
|
||||
isComposerPreview: equal("field.type", "composer_preview"),
|
||||
categoryPropertyTypes: selectKitContent(["id", "slug"]),
|
||||
|
|
|
@ -18,6 +18,7 @@ export default Component.extend({
|
|||
isDropdown: equal("value.type", "dropdown"),
|
||||
isTag: equal("value.type", "tag"),
|
||||
isCategory: equal("value.type", "category"),
|
||||
isTopic: equal("value.type", "topic"),
|
||||
isGroup: equal("value.type", "group"),
|
||||
isUserSelector: equal("value.type", "user_selector"),
|
||||
isSubmittedAt: equal("field", "submitted_at"),
|
||||
|
|
|
@ -227,6 +227,7 @@ const filters = {
|
|||
"dropdown",
|
||||
"tag",
|
||||
"category",
|
||||
"topic",
|
||||
"group",
|
||||
"user_selector",
|
||||
],
|
||||
|
|
|
@ -14,6 +14,7 @@ const StandardFieldValidation = [
|
|||
"text_only",
|
||||
"composer",
|
||||
"category",
|
||||
"topic",
|
||||
"group",
|
||||
"date",
|
||||
"time",
|
||||
|
|
|
@ -63,7 +63,8 @@ export default EmberObject.extend(ValidState, {
|
|||
return ajax({
|
||||
url: `/w/${wizardId}/steps/${this.get("id")}`,
|
||||
type: "PUT",
|
||||
data: { fields },
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify({ fields })
|
||||
}).catch((response) => {
|
||||
if (response.jqXHR) {
|
||||
response = response.jqXHR;
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{{custom-wizard-topic-selector
|
||||
topics=topics
|
||||
onChange=(action "setValue")
|
||||
options=(hash maximum=field.limit)
|
||||
}}
|
|
@ -122,6 +122,22 @@
|
|||
</a>
|
||||
{{/if}}
|
||||
|
||||
{{#if isTopic}}
|
||||
<strong>
|
||||
{{i18n "admin.wizard.submissions.topic_id"}}:
|
||||
</strong>
|
||||
{{#each value.value as |topic|}}
|
||||
<a
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
href={{topic.url}}
|
||||
title={{topic.fancy_title}}
|
||||
>
|
||||
{{topic.id}}
|
||||
</a>
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
|
||||
{{#if isGroup}}
|
||||
<strong>
|
||||
{{i18n "admin.wizard.submissions.group_id"}}:
|
||||
|
|
|
@ -182,7 +182,8 @@ body.custom-wizard {
|
|||
}
|
||||
}
|
||||
|
||||
.wizard-category-selector {
|
||||
.wizard-category-selector,
|
||||
.wizard-topic-selector {
|
||||
width: 500px;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -212,6 +212,7 @@ en:
|
|||
user_field_options: "user field options"
|
||||
user: "user"
|
||||
category: "category"
|
||||
topic: "topic"
|
||||
tag: "tag"
|
||||
group: "group"
|
||||
list: "list"
|
||||
|
@ -229,6 +230,7 @@ en:
|
|||
user_field_options: "Select field"
|
||||
user: "Select user"
|
||||
category: "Select category"
|
||||
topic: "Select a topic"
|
||||
tag: "Select tag"
|
||||
group: "Select group"
|
||||
list: "Enter item"
|
||||
|
@ -311,6 +313,7 @@ en:
|
|||
dropdown: Dropdown
|
||||
tag: Tag
|
||||
category: Category
|
||||
topic: Topic
|
||||
group: Group
|
||||
user_selector: User Selector
|
||||
date: Date
|
||||
|
@ -469,6 +472,7 @@ en:
|
|||
download: "Download"
|
||||
group_id: "Group ID"
|
||||
category_id: "Category ID"
|
||||
topic_id: "Topic ID"
|
||||
composer_preview: "Composer Preview"
|
||||
|
||||
api:
|
||||
|
|
|
@ -131,7 +131,7 @@ class CustomWizard::Builder
|
|||
params[:format] = field_template['format']
|
||||
end
|
||||
|
||||
if field_template['type'] === 'category' || field_template['type'] === 'tag'
|
||||
if %w[category tag topic].include?(field_template['type'])
|
||||
params[:limit] = field_template['limit']
|
||||
end
|
||||
|
||||
|
|
|
@ -129,6 +129,11 @@ class CustomWizard::Field
|
|||
prefill: nil,
|
||||
content: nil
|
||||
},
|
||||
topic: {
|
||||
limit: 1,
|
||||
prefill: nil,
|
||||
content: nil
|
||||
},
|
||||
group: {
|
||||
prefill: nil,
|
||||
content: nil
|
||||
|
|
|
@ -33,6 +33,7 @@ module DiscoursePluginStatistics
|
|||
upload: 0,
|
||||
tag: 0,
|
||||
category: 0,
|
||||
topic: 0,
|
||||
group: 0,
|
||||
user_selector: 0,
|
||||
},
|
||||
|
|
Laden …
In neuem Issue referenzieren