1.0.0 Version

This version adds advanced mode, and some little refactors
This commit is contained in:
Rafael dos Santos Silva 2016-04-08 17:30:39 -04:00
parent 8ed18d772f
commit 319230e703
7 changed files with 60 additions and 35 deletions

View File

@ -27,6 +27,10 @@ And each user need to enable and select a signature on his/her profile:
and thats it! and thats it!
## Advanced Mode
You can now enable **advanced mode** on the plugin settings and use a full blow post editor to create your signature! With text, multiple images, etc.
## About ## About
This is a work in progress! Feel free to use and ask questions here, or on [Meta](meta.discourse.org). This is a work in progress! Feel free to use and ask questions here, or on [Meta](meta.discourse.org).
@ -34,5 +38,4 @@ This is a work in progress! Feel free to use and ask questions here, or on [Meta
## TODO ## TODO
- Figure out a way so the user doens't have to refresh te browser to change the `see signatures` options. - Figure out a way so the user doens't have to refresh te browser to change the `see signatures` options.
- Use d-editor instead of a simple text field. (Allow text sigs, multi-images, etc) - Cache the cooked signatures
- Get some sane defaults for CSS

View File

@ -1,27 +1,25 @@
import Post from 'discourse/models/post'; import Preferences from 'discourse/controllers/preferences';
import { withPluginApi } from 'discourse/lib/plugin-api'; import { withPluginApi } from 'discourse/lib/plugin-api';
import RawHtml from 'discourse/widgets/raw-html';
function oldPluginCode() {
Post.reopen({
showSignatures: function() {
return Discourse.User.currentProp("custom_fields.see_signatures");
}.property()
});
}
function attachSignature(api) { function attachSignature(api) {
api.includePostAttributes('user_signature_url'); api.includePostAttributes('user_signature');
api.decorateWidget('post-contents:after', dec => { api.decorateWidget('post-contents:after', dec => {
const attrs = dec.attrs; const attrs = dec.attrs;
if (Ember.isEmpty(attrs.user_signature_url)) { return; } if (Ember.isEmpty(attrs.user_signature)) { return; }
const currentUser = api.getCurrentUser(); const currentUser = api.getCurrentUser();
const siteSettings = Discourse.SiteSettings; // TODO: change way to get the sitesettings
if (currentUser) { if (currentUser) {
const enabled = currentUser.get('custom_fields.see_signatures'); const enabled = currentUser.get('custom_fields.see_signatures');
if (enabled) { if (enabled) {
return [dec.h('hr'), dec.h('img.signature-img', { attributes: { src: attrs.user_signature_url } } )]; if (siteSettings.signatures_advanced_mode) {
return [dec.h('hr'), dec.h('div', new RawHtml({html: `<div class='user-signature'>${Discourse.Markdown.cook(attrs.user_signature)}</div>`}))];
} else {
return [dec.h('hr'), dec.h('img.signature-img', {attributes: {src: attrs.user_signature}})];
}
} }
} }
}); });
@ -32,7 +30,16 @@ export default {
initialize(container) { initialize(container) {
const siteSettings = container.lookup('site-settings:main'); const siteSettings = container.lookup('site-settings:main');
if (siteSettings.signatures_enabled) { if (siteSettings.signatures_enabled) {
withPluginApi('0.1', attachSignature, { noApi: oldPluginCode }); withPluginApi('0.1', attachSignature);
Preferences.reopen({
signaturesEnabled: function() {
return Discourse.SiteSettings.signatures_enabled;
}.property(),
signaturesAdvancedMode: function() {
return Discourse.SiteSettings.signatures_advanced_mode;
}.property()
});
} }
} }
}; };

View File

@ -1,6 +0,0 @@
{{#if showSignatures}}
{{#if user_signature_url}}
<hr>
<img src="{{user_signature_url}}" class="signature-img">
{{/if}}
{{/if}}

View File

@ -1,10 +1,22 @@
<div class='controls'> {{#if signaturesEnabled}}
<label class='checkbox-label'> <div class="control-group signatures">
{{input type="checkbox" checked=controller.model.custom_fields.see_signatures}} <label class="control-label">Signatures</label>
See user signatures below posts <div class="controls">
</label> <label class='checkbox-label'>
<label class='text-label'> {{input type="checkbox" checked=controller.model.custom_fields.see_signatures}}
{{input type="text" value=controller.model.custom_fields.signature_url}} See user signatures below posts
Signature URL Image </label>
</label> </div>
</div> <div class="controls">
<label>Signature</label>
{{#if signaturesAdvancedMode}}
{{d-editor value=controller.model.custom_fields.signature_raw showUploadModal="showUploadModal"}}
{{else}}
<label class='text-label'>
{{input type="text" value=controller.model.custom_fields.signature_url}}
</label>
{{/if}}
</div>
<div class="instructions">Signature Code</div>
</div>
{{/if}}

View File

@ -1,3 +1,4 @@
en: en:
site_settings: site_settings:
signatures_enabled: "Enable user-made signatures below posts?" signatures_enabled: "Enable user-made signatures below posts?"
signatures_advanced_mode: "Let users use a full blow post editor to create signatures. RESETS all existing signatures. Needs a server restart"

View File

@ -2,3 +2,6 @@ plugins:
signatures_enabled: signatures_enabled:
default: true default: true
client: true client: true
signatures_advanced_mode:
default: false
client: true

View File

@ -1,6 +1,6 @@
# name: discourse-signatures # name: discourse-signatures
# about: A plugin to get that nostalgia signatures in Discourse Foruns # about: A plugin to get that nostalgia signatures in Discourse Foruns
# version: 0.1.0 # version: 1.0.0
# author: Rafael Silva <xfalcox@gmail.com> # author: Rafael Silva <xfalcox@gmail.com>
# url: https://github.com/xfalcox/discourse-signatures # url: https://github.com/xfalcox/discourse-signatures
@ -8,15 +8,21 @@ enabled_site_setting :signatures_enabled
DiscoursePluginRegistry.serialized_current_user_fields << "see_signatures" DiscoursePluginRegistry.serialized_current_user_fields << "see_signatures"
DiscoursePluginRegistry.serialized_current_user_fields << "signature_url" DiscoursePluginRegistry.serialized_current_user_fields << "signature_url"
DiscoursePluginRegistry.serialized_current_user_fields << "signature_raw"
after_initialize do after_initialize do
User.register_custom_field_type('see_signatures', :boolean) User.register_custom_field_type('see_signatures', :boolean)
User.register_custom_field_type('signature_url', :text) User.register_custom_field_type('signature_url', :text)
User.register_custom_field_type('signature_raw', :text)
if SiteSetting.signatures_enabled then if SiteSetting.signatures_enabled then
add_to_serializer(:post, :user_signature_url, false) { add_to_serializer(:post, :user_signature, false) {
object.user.custom_fields['signature_url'] if SiteSetting.signatures_advanced_mode then
object.user.custom_fields['signature_raw']
else
object.user.custom_fields['signature_url']
end
} }
# I guess this should be the default @ discourse. PR maybe? # I guess this should be the default @ discourse. PR maybe?
@ -31,5 +37,4 @@ after_initialize do
end end
register_asset "javascripts/discourse/templates/connectors/user-custom-preferences/signature-preferences.hbs" register_asset "javascripts/discourse/templates/connectors/user-custom-preferences/signature-preferences.hbs"
register_asset "javascripts/discourse/templates/connectors/post-after-cooked/signature.hbs"
register_asset "stylesheets/common/signatures.scss" register_asset "stylesheets/common/signatures.scss"