Skip to content
2 changes: 2 additions & 0 deletions app/controllers/custom_wizard/admin/wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ def save_wizard_params
custom_fields: mapped_params,
visible: mapped_params,
required: mapped_params,
poster: mapped_params,
guest_email: mapped_params,
recipient: mapped_params,
categories: mapped_params,
mute_remainder: mapped_params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import discourseComputed from "discourse-common/utils/decorators";
import Component from "@ember/component";
import { dasherize } from "@ember/string";
import getURL from "discourse-common/lib/get-url";
import cookie from "discourse/lib/cookie";
import { getOwner } from "@ember/application";

export default Component.extend({
classNameBindings: [":wizard-no-access", "reasonClass"],
Expand All @@ -17,6 +19,11 @@ export default Component.extend({
return this.siteSettings.title || "";
},

@discourseComputed("reason")
showLoginButton(reason) {
return reason === "requiresLogin";
},

actions: {
skip() {
if (this.currentUser) {
Expand All @@ -25,5 +32,10 @@ export default Component.extend({
window.location = getURL("/");
}
},

showLogin() {
cookie("destination_url", getURL(`/w/${this.get("wizardId")}`));
getOwner(this).lookup("route:application").send("showLogin");
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ export default Component.extend({
guestGroup: computed("options.guestGroup", "inputType", function () {
return this.optionEnabled("guestGroup");
}),
includeMessageableGroups: computed(
"options.includeMessageableGroups",
"inputType",
function () {
return this.optionEnabled("includeMessageableGroups");
}
),
userEnabled: computed("options.userSelection", "inputType", function () {
return this.optionEnabled("userSelection");
}),
Expand Down Expand Up @@ -352,6 +359,17 @@ export default Component.extend({
return result;
},

@discourseComputed("includeMessageableGroups", "options.userLimit")
userOptions(includeMessageableGroups, userLimit) {
const opts = {
includeMessageableGroups,
};
if (userLimit) {
opts.maximum = userLimit;
}
return opts;
},

optionEnabled(type) {
const options = this.options;
if (!options) {
Expand Down
2 changes: 2 additions & 0 deletions assets/javascripts/discourse/components/wizard-mapper.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export default Component.extend({
outputConnector: options.outputConnector || null,
context: options.context || null,
guestGroup: options.guestGroup || false,
includeMessageableGroups: options.includeMessageableGroups || false,
userLimit: options.userLimit || null,
};

let inputTypes = ["key", "value", "output"];
Expand Down
58 changes: 58 additions & 0 deletions assets/javascripts/discourse/components/wizard-user-chooser.js.es6
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import UserChooserComponent from "select-kit/components/user-chooser";
import I18n from "I18n";

export const WIZARD_USER = "wizard-user";

export default UserChooserComponent.extend({
pluginApiIdentifiers: ["wizard-user-chooser"],
classNames: ["user-chooser", "wizard-user-chooser"],
classNameBindings: ["selectKit.options.fullWidthWrap:full-width-wrap"],
valueProperty: "id",
nameProperty: "name",

modifyComponentForRow() {
return "wizard-user-chooser/wizard-user-chooser-row";
},

modifyNoSelection() {
return this.defaultItem(
WIZARD_USER,
I18n.t("admin.wizard.action.poster.wizard_user")
);
},

selectKitOptions: {
fullWidthWrap: false,
autoWrap: false,
},

search() {
const superPromise = this._super(...arguments);
if (!superPromise) {
return;
}
return superPromise.then((results) => {
if (!results || results.length === 0) {
return;
}
return results.map((item) => {
const reconstructed = {};
if (item.username) {
reconstructed.id = item.username;
if (item.username.includes("@")) {
reconstructed.isEmail = true;
} else {
reconstructed.isUser = true;
reconstructed.name = item.name;
reconstructed.showUserStatus = this.showUserStatus;
}
} else if (item.name) {
reconstructed.id = item.name;
reconstructed.name = item.full_name;
reconstructed.isGroup = true;
}
return { ...item, ...reconstructed };
});
});
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import SelectKitRowComponent from "select-kit/components/select-kit/select-kit-row";

export default SelectKitRowComponent.extend({
classNames: ["user-row", "wizard-user-chooser-row"],
});
5 changes: 5 additions & 0 deletions assets/javascripts/discourse/lib/wizard-schema.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ const action = {
custom_fields: null,
skip_redirect: null,
suppress_notifications: null,
poster: "wizard-user",
guest_email: null,
add_event: null,
add_location: null,
},
Expand All @@ -111,6 +113,8 @@ const action = {
skip_redirect: null,
custom_fields: null,
required: null,
poster: "wizard-user",
guest_email: null,
recipient: null,
suppress_notifications: null,
},
Expand Down Expand Up @@ -184,6 +188,7 @@ const action = {
"custom_fields",
"required",
"recipient",
"poster",
"profile_updates",
"group",
"url",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<div>{{text}}</div>
<div class="no-access-gutter">
<button
class="wizard-btn primary return-to-site"
{{action "skip"}}
type="button"
>
<a class="return-to-site" {{action "skip"}} role="button">
{{i18n "wizard.return_to_site" siteName=siteName}}
{{d-icon "sign-out-alt"}}
</button>
</a>
{{#if showLoginButton}}
<DButton
class="btn-primary btn-small login-button"
@action={{action "showLogin"}}
@label="log_in"
@icon="user"
/>
{{/if}}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
userSelection="output"
outputDefaultSelection="user"
context="action"
includeMessageableGroups="true"
)
}}
</div>
Expand Down Expand Up @@ -919,6 +920,48 @@
{{/if}}

{{#if showPostAdvanced}}
<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.poster.label"}}</label>
</div>

<div class="setting-value">
{{wizard-mapper
inputs=this.action.poster
property="poster"
onUpdate=(action "mappedFieldUpdated")
options=(hash
textSelection="key,value"
wizardFieldSelection=true
userSelection="output"
outputDefaultSelection="user"
userLimit="1"
context="action"
)
}}
</div>
</div>

<div class="setting full field-mapper-setting">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.guest_email.label"}}</label>
</div>

<div class="setting-value">
{{wizard-mapper
inputs=this.action.guest_email
property="guest_email"
onUpdate=(action "mappedFieldUpdated")
options=(hash
textSelection="key,value"
wizardFieldSelection=true
outputPlaceholder="admin.wizard.action.guest_email.placeholder"
context="action"
)
}}
</div>
</div>

<div class="setting full">
<div class="setting-label">
<label>{{i18n "admin.wizard.action.skip_redirect.label"}}</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@
{{/if}}

{{#if showUser}}
{{email-group-user-chooser
{{wizard-user-chooser
placeholderKey=placeholderKey
value=value
autocomplete="discourse"
onChange=(action "changeUserValue")
options=(hash includeMessageableGroups="true")
options=userOptions
}}
{{/if}}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{#if this.item.isUser}}
{{avatar this.item imageSize="tiny"}}
<div>
<span class="identifier">{{format-username this.item.id}}</span>
<span class="name">{{this.item.name}}</span>
</div>
{{#if (and this.item.showUserStatus this.item.status)}}
<UserStatusMessage @status={{this.item.status}} @showDescription={{true}} />
{{/if}}
{{decorate-username-selector this.item.id}}
{{else if this.item.isGroup}}
{{d-icon "users"}}
<div>
<span class="identifier">{{this.item.id}}</span>
<span class="name">{{this.item.full_name}}</span>
</div>
{{else}}
{{d-icon "envelope"}}
<span class="identifier">{{this.item.id}}</span>
{{/if}}
7 changes: 6 additions & 1 deletion assets/stylesheets/common/wizard/wizard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ body.custom-wizard {
.no-access-gutter {
margin-top: 10px;
display: flex;
justify-content: flex-end;
justify-content: space-between;

.return-to-site {
display: flex;
align-items: center;
}
}

.powered-by-discourse {
Expand Down
8 changes: 7 additions & 1 deletion config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ en:
completed: "You have completed this wizard."
not_permitted: "You are not permitted to access this wizard."
none: "There is no wizard here."
return_to_site: "Return to {{siteName}}"
return_to_site: "Return to {{siteName}}."
requires_login: "You need to be logged in to access this wizard."
reset: "Reset this wizard."
step_not_permitted: "You're not permitted to view this step."
Expand Down Expand Up @@ -344,6 +344,12 @@ en:
include: "Include Fields"
title: "Title"
post: "Post"
poster:
label: "Poster"
wizard_user: "Wizard user"
guest_email:
label: "Guest email"
placeholder: "Field for guest email"
topic_attr: "Topic Attribute"
interpolate_fields: "Insert wizard fields using the field_id in w{}. Insert user fields using field key in u{}."

Expand Down
Loading