0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-26 02:50:28 +01:00

Merge pull request #213 from paviliondev/interpolate_user_avatar

Add avatar interpolation support
Dieser Commit ist enthalten in:
Marcos 2022-12-13 12:05:03 -04:00 committet von GitHub
Commit 17fe4d732a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
5 geänderte Dateien mit 56 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -5,11 +5,7 @@ import { scheduleOnce } from "@ember/runloop";
import Component from "@ember/component"; import Component from "@ember/component";
import I18n from "I18n"; import I18n from "I18n";
const excludedUserProperties = [ const excludedUserProperties = ["profile_background", "card_background"];
"avatar",
"profile_background",
"card_background",
];
export default Component.extend({ export default Component.extend({
classNames: "wizard-text-editor", classNames: "wizard-text-editor",
@ -52,12 +48,12 @@ export default Component.extend({
@discourseComputed("wizardFields") @discourseComputed("wizardFields")
wizardFieldList(wizardFields) { wizardFieldList(wizardFields) {
return wizardFields.map((f) => ` w{${f.id}}`); return (wizardFields || []).map((f) => ` w{${f.id}}`);
}, },
@discourseComputed("wizardActions") @discourseComputed("wizardActions")
wizardActionList(wizardActions) { wizardActionList(wizardActions) {
return wizardActions.map((a) => ` w{${a.id}}`); return (wizardActions || []).map((a) => ` w{${a.id}}`);
}, },
actions: { actions: {

Datei anzeigen

@ -211,6 +211,8 @@ class CustomWizard::Mapper
user.send(value) user.send(value)
elsif USER_OPTION_FIELDS.include?(value) elsif USER_OPTION_FIELDS.include?(value)
user.user_option.send(value) user.user_option.send(value)
elsif value.include?('avatar')
get_avatar_url(value)
else else
nil nil
end end
@ -269,4 +271,15 @@ class CustomWizard::Mapper
def bool(value) def bool(value)
ActiveRecord::Type::Boolean.new.cast(value) ActiveRecord::Type::Boolean.new.cast(value)
end end
def get_avatar_url(value)
parts = value.split('.')
valid_sizes = Discourse.avatar_sizes.to_a
if value === 'avatar' || parts.size === 1 || valid_sizes.exclude?(parts.last.to_i)
user.small_avatar_url
else
user.avatar_template_url.gsub("{size}", parts.last)
end
end
end end

Datei anzeigen

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
# name: discourse-custom-wizard # name: discourse-custom-wizard
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more.
# version: 2.1.2 # version: 2.1.3
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever
# url: https://github.com/paviliondev/discourse-custom-wizard # url: https://github.com/paviliondev/discourse-custom-wizard
# contact_emails: development@pavilion.tech # contact_emails: development@pavilion.tech

Datei anzeigen

@ -1,4 +1,4 @@
# frozen_string_literal: true # rubocop:disable Style/FrozenStringLiteralComment
describe CustomWizard::Mapper do describe CustomWizard::Mapper do
fab!(:user1) { fab!(:user1) {
@ -254,6 +254,36 @@ describe CustomWizard::Mapper do
user: user1 user: user1
).perform).to eq("Time: #{Time.now.strftime("%B %-d, %Y")}") ).perform).to eq("Time: #{Time.now.strftime("%B %-d, %Y")}")
end end
it "avatar" do
expect(CustomWizard::Mapper.new(
inputs: inputs['interpolate_avatar'],
data: data,
user: user1
).perform).to eq("Avatar: ![avatar](#{user1.small_avatar_url})")
end
it "avatar with invalid size" do
avatar_inputs = inputs['interpolate_avatar'].dup
avatar_inputs[0]["output"] = "Avatar: ![avatar](u{avatar.345})"
expect(CustomWizard::Mapper.new(
inputs: avatar_inputs,
data: data,
user: user1
).perform).to eq("Avatar: ![avatar](#{user1.small_avatar_url})")
end
it "avatar with valid size" do
avatar_inputs = inputs['interpolate_avatar'].dup
avatar_inputs[0]["output"] = "Avatar: ![avatar](u{avatar.120})"
expect(CustomWizard::Mapper.new(
inputs: avatar_inputs,
data: data,
user: user1
).perform).to eq("Avatar: ![avatar](#{user1.avatar_template_url.gsub("{size}", "120")})")
end
end end
it "handles greater than pairs" do it "handles greater than pairs" do

Datei anzeigen

@ -89,6 +89,14 @@
"output": "Time: v{time}" "output": "Time: v{time}"
} }
], ],
"interpolate_avatar": [
{
"type": "assignment",
"output_type": "text",
"output_connector": "set",
"output": "Avatar: ![avatar](u{avatar})"
}
],
"validation": [ "validation": [
{ {
"type": "validation", "type": "validation",