1
0
Fork 0

Merge pull request #15 from merefield/juless_extensions

NEW FEATURES:  support for user avatars, national flags plugin and optional messages
Dieser Commit ist enthalten in:
Angus McLeod 2019-10-15 12:13:23 +11:00 committet von GitHub
Commit 2f02ca0fb2
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
16 geänderte Dateien mit 403 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -12,6 +12,7 @@ const ACTION_TYPES = [
const PROFILE_FIELDS = [
'name',
'user_avatar',
'date_of_birth',
'title',
'locale',

Datei anzeigen

@ -20,7 +20,7 @@ export default Ember.Component.extend({
@computed()
presetChoices() {
return [
let presets = [
{
id: 'categories',
name: I18n.t('admin.wizard.field.choices_preset.categories')
@ -32,6 +32,13 @@ export default Ember.Component.extend({
name: I18n.t('admin.wizard.field.choices_preset.tags')
}
];
if (Discourse.SiteSettings.nationalflag_enabled) {
presets.push({
id: 'flags',
name: I18n.t('admin.wizard.field.choices_preset.flags')
})
}
return presets;
},
@on('didInsertElement')

Datei anzeigen

@ -143,6 +143,17 @@
{{/if}}
{{#if sendMessage}}
<div class="setting">
<div class="setting-label">
<h3>{{i18n 'admin.wizard.required'}}</h3>
</div>
<div class="setting-value">
{{combo-box content=availableFields
nameProperty='label'
none='admin.wizard.select_field'
value=action.required}}
</div>
</div>
<div class="setting">
<div class="setting-label">
<h3>{{i18n "admin.wizard.action.send_message.recipient"}}</h3>

Datei anzeigen

@ -3,7 +3,9 @@ import { getToken } from "wizard/lib/ajax";
export default Ember.Component.extend({
classNames: ["wizard-field-upload"],
classNameBindings: ["isImage"],
uploading: false,
isImage: false,
didInsertElement() {
this._super();
@ -30,6 +32,11 @@ export default Ember.Component.extend({
"field.value": response.result,
"uploading": false
});
if ( Discourse.SiteSettings.wizard_recognised_image_upload_formats.split('|').includes(response.result.extension)) {
this.setProperties({
"isImage": true
})
}
});
$upload.on("fileuploadfail", (e, response) => {

Datei anzeigen

@ -1,3 +1,5 @@
import { default as computed } from 'ember-addons/ember-computed-decorators';
export default {
name: 'custom-routes',
@ -16,6 +18,20 @@ export default {
const autocomplete = requirejs('discourse/lib/autocomplete').default;
const cook = requirejs('discourse/plugins/discourse-custom-wizard/wizard/lib/text-lite').cook;
const Singleton = requirejs("discourse/mixins/singleton").default;
const WizardFieldDropdown = requirejs('wizard/components/wizard-field-dropdown').default;
WizardFieldDropdown.reopen({
tagName: 'span',
classNames: ['wizard-select-value'],
@computed
isFlagSelector() {
const field = this.get('field');
//TODO improve the way this detects a flag dropdown (currently it relies on the string 'Nation', e.g. 'Nationality' or 'National Flag' appearing in label)
return (field.label.includes('Nation')) ? true : false;
}
});
// IE11 Polyfill - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries#Polyfill
if (!Object.entries)
@ -240,6 +256,8 @@ export default {
valid = val;
} else if (type === 'category') {
valid = val && val.toString().length > 0;
} else if (type === 'upload') {
valid = val && val.id > 0;
} else if (StandardFieldValidation.indexOf(type) > -1) {
valid = val && val.length > 0;
}

Datei anzeigen

@ -5,3 +5,6 @@
none=(hash id="__none__" label=field.dropdown_none)
nameProperty="label"
tabindex="9"}}
{{#if isFlagSelector}}
<img class="nationalflag-usersummary" src="/plugins/discourse-nationalflags/images/nationalflags/{{field.value}}.png" />
{{/if}}

Datei anzeigen

@ -11,6 +11,10 @@
{{#if field.value}}
<a href="{{field.value.url}}" class="filename">
{{field.value.original_filename}}
{{#unless isImage}}
{{field.value.original_filename}}
{{else}}
<img src={{field.value.url}} class="wizard-image-preview">
{{/unless}}
</a>
{{/if}}

Datei anzeigen

@ -229,8 +229,27 @@
margin: 20px 0;
}
.wizard-image-row .wizard-btn-upload {
margin: 0;
.wizard-image-row {
.wizard-btn-upload {
margin: 0;
}
}
.wizard-image-preview {
max-width: 200px;
max-height: 200px;
overflow: hidden;
img {
max-width:100%;
max-height:100%;
}
}
.wizard-select-value img {
vertical-align: middle;
}
.wizard-field-upload {
@ -415,8 +434,9 @@
div.ac-wrap {
width: 98.5% !important;
overflow: auto;
overflow: visible;
max-height: 150px;
min-height: 34px;
background-color: white;
border: 1px solid #e9e9e9;
padding: 5px 4px 1px 4px;

Datei anzeigen

@ -101,6 +101,7 @@ en:
categories: "Categories"
groups: "Groups"
tags: "Tags"
flags: "Flags"
filter: "Preset Filter"
choice:
value: "Value"

Datei anzeigen

@ -22,3 +22,4 @@ en:
site_settings:
wizard_redirect_exclude_paths: "Routes excluded from wizard redirects."
wizard_recognised_image_upload_formats: "File types which will result in upload displaying an image preview"

259
config/national_flags.yml Normale Datei
Datei anzeigen

@ -0,0 +1,259 @@
none: none.png
ad: ad.png
ae: ae.png
af: af.png
ag: ag.png
ai: ai.png
al: al.png
am: am.png
ao: ao.png
aq: aq.png
ar: ar.png
as: as.png
at: at.png
au: au.png
aw: aw.png
ax: ax.png
az: az.png
ba: ba.png
bb: bb.png
bd: bd.png
be: be.png
bf: bf.png
bg: bg.png
bh: bh.png
bi: bi.png
bj: bj.png
bl: bl.png
bm: bm.png
bn: bn.png
bo: bo.png
bq: bq.png
br: br.png
bs: bs.png
bt: bt.png
bv: bv.png
bw: bw.png
by: by.png
bz: bz.png
ca: ca.png
cc: cc.png
cd: cd.png
cf: cf.png
cg: cg.png
ch: ch.png
ci: ci.png
ck: ck.png
cl: cl.png
cm: cm.png
cn: cn.png
co: co.png
cr: cr.png
cu: cu.png
cv: cv.png
cw: cw.png
cx: cx.png
cy: cy.png
cz: cz.png
de: de.png
de-at: de-at.png
dj: dj.png
dk: dk.png
dm: dm.png
do: do.png
dz: dz.png
ec: ec.png
ee: ee.png
eg: eg.png
eh: eh.png
er: er.png
es: es.png
et: et.png
eu: eu.png
fi: fi.png
fj: fj.png
fk: fk.png
fm: fm.png
fo: fo.png
fr: fr.png
fr-br: fr-br.png
ga: ga.png
gb-eng: gb-eng.png
gb-nir: gb-nir.png
gb-sct: gb-sct.png
gb-wls: gb-wls.png
gb: gb.png
gd: gd.png
ge: ge.png
gf: gf.png
gg: gg.png
gh: gh.png
gi: gi.png
gl: gl.png
gm: gm.png
gn: gn.png
gp: gp.png
gq: gq.png
gr: gr.png
gs: gs.png
gt: gt.png
gu: gu.png
gw: gw.png
gy: gy.png
hk: hk.png
hm: hm.png
hn: hn.png
hr: hr.png
ht: ht.png
hu: hu.png
id: id.png
ie: ie.png
il: il.png
im: im.png
in: in.png
io: io.png
iq: iq.png
ir: ir.png
is: is.png
it: it.png
je: je.png
jm: jm.png
jo: jo.png
jp: jp.png
ke: ke.png
kg: kg.png
kh: kh.png
ki: ki.png
km: km.png
kn: kn.png
kp: kp.png
kr: kr.png
kw: kw.png
ky: ky.png
kz: kz.png
la: la.png
lb: lb.png
lc: lc.png
li: li.png
lk: lk.png
lr: lr.png
ls: ls.png
lt: lt.png
lu: lu.png
lv: lv.png
ly: ly.png
ma: ma.png
mc: mc.png
md: md.png
me: me.png
mf: mf.png
mg: mg.png
mh: mh.png
mk: mk.png
ml: ml.png
mm: mm.png
mn: mn.png
mo: mo.png
mp: mp.png
mq: mq.png
mr: mr.png
ms: ms.png
mt: mt.png
mu: mu.png
mv: mv.png
mw: mw.png
mx: mx.png
my: my.png
mz: mz.png
na: na.png
nc: nc.png
ne: ne.png
nf: nf.png
ng: ng.png
ni: ni.png
nl: nl.png
no: no.png
np: np.png
nr: nr.png
nu: nu.png
nz: nz.png
om: om.png
pa: pa.png
pe: pe.png
pf: pf.png
pg: pg.png
ph: ph.png
pk: pk.png
pl: pl.png
pm: pm.png
pn: pn.png
pr: pr.png
ps: ps.png
pt: pt.png
pw: pw.png
py: py.png
qa: qa.png
re: re.png
ro: ro.png
rs: rs.png
ru: ru.png
rw: rw.png
sa: sa.png
sb: sb.png
sc: sc.png
sd: sd.png
se: se.png
sg: sg.png
sh: sh.png
si: si.png
sj: sj.png
sk: sk.png
sl: sl.png
sm: sm.png
sn: sn.png
so: so.png
sr: sr.png
ss: ss.png
st: st.png
sv: sv.png
sx: sx.png
sy: sy.png
sz: sz.png
tc: tc.png
td: td.png
tf: tf.png
tg: tg.png
th: th.png
tj: tj.png
tk: tk.png
tl: tl.png
tm: tm.png
tn: tn.png
to: to.png
tr: tr.png
tt: tt.png
tv: tv.png
tw: tw.png
tz: tz.png
ua: ua.png
ug: ug.png
um: um.png
un: un.png
us: us.png
us-at: us-at.png
uy: uy.png
uz: uz.png
va: va.png
vc: vc.png
ve: ve.png
vg: vg.png
vi: vi.png
vn: vn.png
vu: vu.png
wf: wf.png
ws: ws.png
ye: ye.png
yt: yt.png
za: za.png
zm: zm.png
zw: zw.png

Datei anzeigen

@ -6,3 +6,9 @@ plugins:
choices:
- admin
- privacy
wizard_recognised_image_upload_formats:
client: true
default: "jpg|jpeg|png|gif"
refresh: true
type: list
list_type: compact

Datei anzeigen

@ -291,6 +291,10 @@ class CustomWizard::Builder
objects = Tag.top_tags(guardian: guardian).map { |tag| TagStruct.new(tag,tag) }
end
if field_template['choices_preset'] === 'flags'
objects = CustomWizard::Flags.list
end
if field_template['choices_filters'] && field_template['choices_filters'].length > 0
field_template['choices_filters'].each do |f|
objects.reject! do |o|
@ -420,7 +424,16 @@ class CustomWizard::Builder
end
def send_message(user, action, data)
title = data[action['title']]
if action['required'].present? && data[action['required']].blank?
return
end
if action['custom_title_enabled']
title = CustomWizard::Builder.fill_placeholders(action['custom_title'], user, data)
else
title = data[action['title']]
end
if action['post_builder']
post = CustomWizard::Builder.fill_placeholders(action['post_template'], user, data)
@ -474,13 +487,20 @@ class CustomWizard::Builder
custom_fields[user_field || custom_field] = data[key]
else
updater_key = value
if ['profile_background', 'card_background'].include?(value)
updater_key = "#{value}_upload_url"
end
attributes[updater_key.to_sym] = data[key] if updater_key
end
if ['user_avatar'].include?(value)
this_upload_id = data[key][:id]
user.create_user_avatar unless user.user_avatar
user.user_avatar.custom_upload_id = this_upload_id
user.uploaded_avatar_id = this_upload_id
user.save!
user.user_avatar.save!
end
end
if custom_fields.present?

31
lib/flags.rb Normale Datei
Datei anzeigen

@ -0,0 +1,31 @@
class CustomWizard::Flag
def initialize(id, name)
@id = id
@name = name
end
def id
@id
end
def name
@name
end
end
class CustomWizard::Flags
def self.list
raw_flags = YAML.safe_load(File.read(File.join(Rails.root, 'plugins', 'discourse-custom-wizard', 'config', 'national_flags.yml')))
flagscollection = []
raw_flags.map do |name, pic|
# This is super hacky. Adding the trailing space actually stops search breaking in the dropdown! (and doesn't compromise the view!)
# Feeding just name, name will break search
flagscollection << CustomWizard::Flag.new(name, "#{name} ")
end
flagscollection
end
end

Datei anzeigen

@ -90,6 +90,10 @@ end
object.name
end
def include_name?
object.respond_to?(:name)
end
def background
object.background
end

Datei anzeigen

@ -52,7 +52,6 @@ after_initialize do
put ':wizard_id/steps/:step_id' => 'steps#update'
end
require_dependency 'admin_constraint'
Discourse::Application.routes.append do
mount ::CustomWizard::Engine, at: 'w'
post 'wizard/authorization/callback' => "custom_wizard/authorization#callback"
@ -76,7 +75,6 @@ after_initialize do
delete 'admin/wizards/apis/logs/:name' => 'api#clearlogs'
get 'admin/wizards/apis/:name/redirect' => 'api#redirect'
get 'admin/wizards/apis/:name/authorize' => 'api#authorize'
#transfer code
get 'admin/wizards/transfer' => 'transfer#index'
get 'admin/wizards/transfer/export' => 'transfer#export'
post 'admin/wizards/transfer/import' => 'transfer#import'
@ -87,6 +85,7 @@ after_initialize do
load File.expand_path('../jobs/set_after_time_wizard.rb', __FILE__)
load File.expand_path('../lib/builder.rb', __FILE__)
load File.expand_path('../lib/field.rb', __FILE__)
load File.expand_path('../lib/flags.rb', __FILE__)
load File.expand_path('../lib/step_updater.rb', __FILE__)
load File.expand_path('../lib/template.rb', __FILE__)
load File.expand_path('../lib/wizard.rb', __FILE__)