From 1670ed4b67e27373811637a87d26a8ab27120463 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Wed, 11 Sep 2019 09:30:38 +0100 Subject: [PATCH] NEW FEATURE: ability to request national flag update in wizard --- .../components/wizard-custom-field.js.es6 | 9 +- .../wizard/initializers/custom.js.es6 | 16 + .../components/wizard-field-dropdown.hbs | 3 + assets/stylesheets/wizard/wizard_custom.scss | 23 +- config/locales/client.en.yml | 1 + lib/builder.rb | 4 + lib/flags.rb | 819 ++++++++++++++++++ plugin.rb | 1 + 8 files changed, 873 insertions(+), 3 deletions(-) create mode 100644 lib/flags.rb diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 index 56fe9529..1afb1683 100644 --- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 @@ -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') diff --git a/assets/javascripts/wizard/initializers/custom.js.es6 b/assets/javascripts/wizard/initializers/custom.js.es6 index d2154467..a52f7559 100644 --- a/assets/javascripts/wizard/initializers/custom.js.es6 +++ b/assets/javascripts/wizard/initializers/custom.js.es6 @@ -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) diff --git a/assets/javascripts/wizard/templates/components/wizard-field-dropdown.hbs b/assets/javascripts/wizard/templates/components/wizard-field-dropdown.hbs index f92000e0..011a2e3f 100644 --- a/assets/javascripts/wizard/templates/components/wizard-field-dropdown.hbs +++ b/assets/javascripts/wizard/templates/components/wizard-field-dropdown.hbs @@ -5,3 +5,6 @@ none=(hash id="__none__" label=field.dropdown_none) nameProperty="label" tabindex="9"}} +{{#if isFlagSelector}} + +{{/if}} diff --git a/assets/stylesheets/wizard/wizard_custom.scss b/assets/stylesheets/wizard/wizard_custom.scss index 5209b8e9..88d406ad 100644 --- a/assets/stylesheets/wizard/wizard_custom.scss +++ b/assets/stylesheets/wizard/wizard_custom.scss @@ -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 { diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 1c0bd172..9372570c 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -101,6 +101,7 @@ en: categories: "Categories" groups: "Groups" tags: "Tags" + flags: "Flags" filter: "Preset Filter" choice: value: "Value" diff --git a/lib/builder.rb b/lib/builder.rb index 39180039..82ec20f2 100644 --- a/lib/builder.rb +++ b/lib/builder.rb @@ -277,6 +277,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| diff --git a/lib/flags.rb b/lib/flags.rb new file mode 100644 index 00000000..93d5ecc0 --- /dev/null +++ b/lib/flags.rb @@ -0,0 +1,819 @@ +class CustomWizard::Flag + def initialize(id, name, value) + @id = id + @name = name + @value = value + end + + def id + @id + end + + def name + @name + end + + def value + @value + end +end + +class CustomWizard::Flags + + def self.list + + flags = [ + { "id" => 0, + "name"=> "none", + "value"=> "none.png" + }, { + "id"=> 1, + "name"=> "ad", + "value"=> "ad.png" + }, { + "id"=> 2, + "name"=> "ae", + "value"=> "ae.png" + }, { + "name"=> "af", + "value"=> "af.png" + }, { + "name"=> "ag", + "value"=> "ag.png" + }, { + "name"=> "ai", + "value"=> "ai.png" + }, { + "name"=> "al", + "value"=> "al.png" + }, { + "name"=> "am", + "value"=> "am.png" + }, { + "name"=> "ao", + "value"=> "ao.png" + }, { + "name"=> "aq", + "value"=> "aq.png" + }, { + "name"=> "ar", + "value"=> "ar.png" + }, { + "name"=> "as", + "value"=> "as.png" + }, { + "name"=> "at", + "value"=> "at.png" + }, { + "name"=> "au", + "value"=> "au.png" + }, { + "name"=> "aw", + "value"=> "aw.png" + }, { + "name"=> "ax", + "value"=> "ax.png" + }, { + "name"=> "az", + "value"=> "az.png" + }, { + "name"=> "ba", + "value"=> "ba.png" + }, { + "name"=> "bb", + "value"=> "bb.png" + }, { + "name"=> "bd", + "value"=> "bd.png" + }, { + "name"=> "be", + "value"=> "be.png" + }, { + "name"=> "bf", + "value"=> "bf.png" + }, { + "name"=> "bg", + "value"=> "bg.png" + }, { + "name"=> "bh", + "value"=> "bh.png" + }, { + "name"=> "bi", + "value"=> "bi.png" + }, { + "name"=> "bj", + "value"=> "bj.png" + }, { + "name"=> "bl", + "value"=> "bl.png" + }, { + "name"=> "bm", + "value"=> "bm.png" + }, { + "name"=> "bn", + "value"=> "bn.png" + }, { + "name"=> "bo", + "value"=> "bo.png" + }, { + "name"=> "bq", + "value"=> "bq.png" + }, { + "name"=> "br", + "value"=> "br.png" + }, { + "name"=> "bs", + "value"=> "bs.png" + }, { + "name"=> "bt", + "value"=> "bt.png" + }, { + "name"=> "bv", + "value"=> "bv.png" + }, { + "name"=> "bw", + "value"=> "bw.png" + }, { + "name"=> "by", + "value"=> "by.png" + }, { + "name"=> "bz", + "value"=> "bz.png" + }, { + "name"=> "ca", + "value"=> "ca.png" + }, { + "name"=> "cc", + "value"=> "cc.png" + }, { + "name"=> "cd", + "value"=> "cd.png" + }, { + "name"=> "cf", + "value"=> "cf.png" + }, { + "name"=> "cg", + "value"=> "cg.png" + }, { + "name"=> "ch", + "value"=> "ch.png" + }, { + "name"=> "ci", + "value"=> "ci.png" + }, { + "name"=> "ck", + "value"=> "ck.png" + }, { + "name"=> "cl", + "value"=> "cl.png" + }, { + "name"=> "cm", + "value"=> "cm.png" + }, { + "name"=> "cn", + "value"=> "cn.png" + }, { + "name"=> "co", + "value"=> "co.png" + }, { + "name"=> "cr", + "value"=> "cr.png" + }, { + "name"=> "cu", + "value"=> "cu.png" + }, { + "name"=> "cv", + "value"=> "cv.png" + }, { + "name"=> "cw", + "value"=> "cw.png" + }, { + "name"=> "cx", + "value"=> "cx.png" + }, { + "name"=> "cy", + "value"=> "cy.png" + }, { + "name"=> "cz", + "value"=> "cz.png" + }, { + "name"=> "de", + "value"=> "de.png" + }, { + "name"=> "de-at", + "value"=> "de-at.png" + }, { + "name"=> "dj", + "value"=> "dj.png" + }, { + "name"=> "dk", + "value"=> "dk.png" + }, { + "name"=> "dm", + "value"=> "dm.png" + }, { + "name"=> "do", + "value"=> "do.png" + }, { + "name"=> "dz", + "value"=> "dz.png" + }, { + "name"=> "ec", + "value"=> "ec.png" + }, { + "name"=> "ee", + "value"=> "ee.png" + }, { + "name"=> "eg", + "value"=> "eg.png" + }, { + "name"=> "eh", + "value"=> "eh.png" + }, { + "name"=> "er", + "value"=> "er.png" + }, { + "name"=> "es", + "value"=> "es.png" + }, { + "name"=> "et", + "value"=> "et.png" + }, { + "name"=> "eu", + "value"=> "eu.png" + }, { + "name"=> "fi", + "value"=> "fi.png" + }, { + "name"=> "fj", + "value"=> "fj.png" + }, { + "name"=> "fk", + "value"=> "fk.png" + }, { + "name"=> "fm", + "value"=> "fm.png" + }, { + "name"=> "fo", + "value"=> "fo.png" + }, { + "name"=> "fr", + "value"=> "fr.png" + }, { + "name"=> "fr-br", + "value"=> "fr-br.png" + }, { + "name"=> "ga", + "value"=> "ga.png" + }, { + "name"=> "gb-eng", + "value"=> "gb-eng.png" + }, { + "name"=> "gb-nir", + "value"=> "gb-nir.png" + }, { + "name"=> "gb-sct", + "value"=> "gb-sct.png" + }, { + "name"=> "gb-wls", + "value"=> "gb-wls.png" + }, { + "name"=> "gb", + "value"=> "gb.png" + }, { + "name"=> "gd", + "value"=> "gd.png" + }, { + "name"=> "ge", + "value"=> "ge.png" + }, { + "name"=> "gf", + "value"=> "gf.png" + }, { + "name"=> "gg", + "value"=> "gg.png" + }, { + "name"=> "gh", + "value"=> "gh.png" + }, { + "name"=> "gi", + "value"=> "gi.png" + }, { + "name"=> "gl", + "value"=> "gl.png" + }, { + "name"=> "gm", + "value"=> "gm.png" + }, { + "name"=> "gn", + "value"=> "gn.png" + }, { + "name"=> "gp", + "value"=> "gp.png" + }, { + "name"=> "gq", + "value"=> "gq.png" + }, { + "name"=> "gr", + "value"=> "gr.png" + }, { + "name"=> "gs", + "value"=> "gs.png" + }, { + "name"=> "gt", + "value"=> "gt.png" + }, { + "name"=> "gu", + "value"=> "gu.png" + }, { + "name"=> "gw", + "value"=> "gw.png" + }, { + "name"=> "gy", + "value"=> "gy.png" + }, { + "name"=> "hk", + "value"=> "hk.png" + }, { + "name"=> "hm", + "value"=> "hm.png" + }, { + "name"=> "hn", + "value"=> "hn.png" + }, { + "name"=> "hr", + "value"=> "hr.png" + }, { + "name"=> "ht", + "value"=> "ht.png" + }, { + "name"=> "hu", + "value"=> "hu.png" + }, { + "name"=> "id", + "value"=> "id.png" + }, { + "name"=> "ie", + "value"=> "ie.png" + }, { + "name"=> "il", + "value"=> "il.png" + }, { + "name"=> "im", + "value"=> "im.png" + }, { + "name"=> "in", + "value"=> "in.png" + }, { + "name"=> "io", + "value"=> "io.png" + }, { + "name"=> "iq", + "value"=> "iq.png" + }, { + "name"=> "ir", + "value"=> "ir.png" + }, { + "name"=> "is", + "value"=> "is.png" + }, { + "name"=> "it", + "value"=> "it.png" + }, { + "name"=> "je", + "value"=> "je.png" + }, { + "name"=> "jm", + "value"=> "jm.png" + }, { + "name"=> "jo", + "value"=> "jo.png" + }, { + "name"=> "jp", + "value"=> "jp.png" + }, { + "name"=> "ke", + "value"=> "ke.png" + }, { + "name"=> "kg", + "value"=> "kg.png" + }, { + "name"=> "kh", + "value"=> "kh.png" + }, { + "name"=> "ki", + "value"=> "ki.png" + }, { + "name"=> "km", + "value"=> "km.png" + }, { + "name"=> "kn", + "value"=> "kn.png" + }, { + "name"=> "kp", + "value"=> "kp.png" + }, { + "name"=> "kr", + "value"=> "kr.png" + }, { + "name"=> "kw", + "value"=> "kw.png" + }, { + "name"=> "ky", + "value"=> "ky.png" + }, { + "name"=> "kz", + "value"=> "kz.png" + }, { + "name"=> "la", + "value"=> "la.png" + }, { + "name"=> "lb", + "value"=> "lb.png" + }, { + "name"=> "lc", + "value"=> "lc.png" + }, { + "name"=> "li", + "value"=> "li.png" + }, { + "name"=> "lk", + "value"=> "lk.png" + }, { + "name"=> "lr", + "value"=> "lr.png" + }, { + "name"=> "ls", + "value"=> "ls.png" + }, { + "name"=> "lt", + "value"=> "lt.png" + }, { + "name"=> "lu", + "value"=> "lu.png" + }, { + "name"=> "lv", + "value"=> "lv.png" + }, { + "name"=> "ly", + "value"=> "ly.png" + }, { + "name"=> "ma", + "value"=> "ma.png" + }, { + "name"=> "mc", + "value"=> "mc.png" + }, { + "name"=> "md", + "value"=> "md.png" + }, { + "name"=> "me", + "value"=> "me.png" + }, { + "name"=> "mf", + "value"=> "mf.png" + }, { + "name"=> "mg", + "value"=> "mg.png" + }, { + "name"=> "mh", + "value"=> "mh.png" + }, { + "name"=> "mk", + "value"=> "mk.png" + }, { + "name"=> "ml", + "value"=> "ml.png" + }, { + "name"=> "mm", + "value"=> "mm.png" + }, { + "name"=> "mn", + "value"=> "mn.png" + }, { + "name"=> "mo", + "value"=> "mo.png" + }, { + "name"=> "mp", + "value"=> "mp.png" + }, { + "name"=> "mq", + "value"=> "mq.png" + }, { + "name"=> "mr", + "value"=> "mr.png" + }, { + "name"=> "ms", + "value"=> "ms.png" + }, { + "name"=> "mt", + "value"=> "mt.png" + }, { + "name"=> "mu", + "value"=> "mu.png" + }, { + "name"=> "mv", + "value"=> "mv.png" + }, { + "name"=> "mw", + "value"=> "mw.png" + }, { + "name"=> "mx", + "value"=> "mx.png" + }, { + "name"=> "my", + "value"=> "my.png" + }, { + "name"=> "mz", + "value"=> "mz.png" + }, { + "name"=> "na", + "value"=> "na.png" + }, { + "name"=> "nc", + "value"=> "nc.png" + }, { + "name"=> "ne", + "value"=> "ne.png" + }, { + "name"=> "nf", + "value"=> "nf.png" + }, { + "name"=> "ng", + "value"=> "ng.png" + }, { + "name"=> "ni", + "value"=> "ni.png" + }, { + "name"=> "nl", + "value"=> "nl.png" + }, { + "name"=> "no", + "value"=> "no.png" + }, { + "name"=> "np", + "value"=> "np.png" + }, { + "name"=> "nr", + "value"=> "nr.png" + }, { + "name"=> "nu", + "value"=> "nu.png" + }, { + "name"=> "nz", + "value"=> "nz.png" + }, { + "name"=> "om", + "value"=> "om.png" + }, { + "name"=> "pa", + "value"=> "pa.png" + }, { + "name"=> "pe", + "value"=> "pe.png" + }, { + "name"=> "pf", + "value"=> "pf.png" + }, { + "name"=> "pg", + "value"=> "pg.png" + }, { + "name"=> "ph", + "value"=> "ph.png" + }, { + "name"=> "pk", + "value"=> "pk.png" + }, { + "name"=> "pl", + "value"=> "pl.png" + }, { + "name"=> "pm", + "value"=> "pm.png" + }, { + "name"=> "pn", + "value"=> "pn.png" + }, { + "name"=> "pr", + "value"=> "pr.png" + }, { + "name"=> "ps", + "value"=> "ps.png" + }, { + "name"=> "pt", + "value"=> "pt.png" + }, { + "name"=> "pw", + "value"=> "pw.png" + }, { + "name"=> "py", + "value"=> "py.png" + }, { + "name"=> "qa", + "value"=> "qa.png" + }, { + "name"=> "re", + "value"=> "re.png" + }, { + "name"=> "ro", + "value"=> "ro.png" + }, { + "name"=> "rs", + "value"=> "rs.png" + }, { + "name"=> "ru", + "value"=> "ru.png" + }, { + "name"=> "rw", + "value"=> "rw.png" + }, { + "name"=> "sa", + "value"=> "sa.png" + }, { + "name"=> "sb", + "value"=> "sb.png" + }, { + "name"=> "sc", + "value"=> "sc.png" + }, { + "name"=> "sd", + "value"=> "sd.png" + }, { + "name"=> "se", + "value"=> "se.png" + }, { + "name"=> "sg", + "value"=> "sg.png" + }, { + "name"=> "sh", + "value"=> "sh.png" + }, { + "name"=> "si", + "value"=> "si.png" + }, { + "name"=> "sj", + "value"=> "sj.png" + }, { + "name"=> "sk", + "value"=> "sk.png" + }, { + "name"=> "sl", + "value"=> "sl.png" + }, { + "name"=> "sm", + "value"=> "sm.png" + }, { + "name"=> "sn", + "value"=> "sn.png" + }, { + "name"=> "so", + "value"=> "so.png" + }, { + "name"=> "sr", + "value"=> "sr.png" + }, { + "name"=> "ss", + "value"=> "ss.png" + }, { + "name"=> "st", + "value"=> "st.png" + }, { + "name"=> "sv", + "value"=> "sv.png" + }, { + "name"=> "sx", + "value"=> "sx.png" + }, { + "name"=> "sy", + "value"=> "sy.png" + }, { + "name"=> "sz", + "value"=> "sz.png" + }, { + "name"=> "tc", + "value"=> "tc.png" + }, { + "name"=> "td", + "value"=> "td.png" + }, { + "name"=> "tf", + "value"=> "tf.png" + }, { + "name"=> "tg", + "value"=> "tg.png" + }, { + "name"=> "th", + "value"=> "th.png" + }, { + "name"=> "tj", + "value"=> "tj.png" + }, { + "name"=> "tk", + "value"=> "tk.png" + }, { + "name"=> "tl", + "value"=> "tl.png" + }, { + "name"=> "tm", + "value"=> "tm.png" + }, { + "name"=> "tn", + "value"=> "tn.png" + }, { + "name"=> "to", + "value"=> "to.png" + }, { + "name"=> "tr", + "value"=> "tr.png" + }, { + "name"=> "tt", + "value"=> "tt.png" + }, { + "name"=> "tv", + "value"=> "tv.png" + }, { + "name"=> "tw", + "value"=> "tw.png" + }, { + "name"=> "tz", + "value"=> "tz.png" + }, { + "name"=> "ua", + "value"=> "ua.png" + }, { + "name"=> "ug", + "value"=> "ug.png" + }, { + "name"=> "um", + "value"=> "um.png" + }, { + "name"=> "un", + "value"=> "un.png" + }, { + "name"=> "us", + "value"=> "us.png" + }, { + "name"=> "us-at", + "value"=> "us-at.png" + }, { + "name"=> "uy", + "value"=> "uy.png" + }, { + "name"=> "uz", + "value"=> "uz.png" + }, { + "name"=> "va", + "value"=> "va.png" + }, { + "name"=> "vc", + "value"=> "vc.png" + }, { + "name"=> "ve", + "value"=> "ve.png" + }, { + "name"=> "vg", + "value"=> "vg.png" + }, { + "name"=> "vi", + "value"=> "vi.png" + }, { + "name"=> "vn", + "value"=> "vn.png" + }, { + "name"=> "vu", + "value"=> "vu.png" + }, { + "name"=> "wf", + "value"=> "wf.png" + }, { + "name"=> "ws", + "value"=> "ws.png" + }, { + "name"=> "ye", + "value"=> "ye.png" + }, { + "name"=> "yt", + "value"=> "yt.png" + }, { + "name"=> "za", + "value"=> "za.png" + }, { + "name"=> "zm", + "value"=> "zm.png" + }, { + "name"=> "zw", + "value"=> "zw.png" + } + ] + + flagscollection = [] + id = 0 + + flags.each do |f| + flagscollection << CustomWizard::Flag.new(f['name'], f['name'], f['value']) + id += 1 + end + + return flagscollection + end +end + \ No newline at end of file diff --git a/plugin.rb b/plugin.rb index 957682ef..f8dac434 100644 --- a/plugin.rb +++ b/plugin.rb @@ -87,6 +87,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__)