mirror of
https://github.com/discourse/discourse-signatures.git
synced 2025-12-12 18:03:31 +00:00
1.0.0 Version
This version adds advanced mode, and some little refactors
This commit is contained in:
parent
8ed18d772f
commit
319230e703
@ -27,6 +27,10 @@ And each user need to enable and select a signature on his/her profile:
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
- 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)
|
||||
- Get some sane defaults for CSS
|
||||
- Cache the cooked signatures
|
||||
|
||||
@ -1,27 +1,25 @@
|
||||
import Post from 'discourse/models/post';
|
||||
import Preferences from 'discourse/controllers/preferences';
|
||||
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||
|
||||
function oldPluginCode() {
|
||||
Post.reopen({
|
||||
showSignatures: function() {
|
||||
return Discourse.User.currentProp("custom_fields.see_signatures");
|
||||
}.property()
|
||||
});
|
||||
}
|
||||
import RawHtml from 'discourse/widgets/raw-html';
|
||||
|
||||
function attachSignature(api) {
|
||||
api.includePostAttributes('user_signature_url');
|
||||
api.includePostAttributes('user_signature');
|
||||
|
||||
api.decorateWidget('post-contents:after', dec => {
|
||||
|
||||
const attrs = dec.attrs;
|
||||
if (Ember.isEmpty(attrs.user_signature_url)) { return; }
|
||||
if (Ember.isEmpty(attrs.user_signature)) { return; }
|
||||
|
||||
const currentUser = api.getCurrentUser();
|
||||
const siteSettings = Discourse.SiteSettings; // TODO: change way to get the sitesettings
|
||||
if (currentUser) {
|
||||
const enabled = currentUser.get('custom_fields.see_signatures');
|
||||
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) {
|
||||
const siteSettings = container.lookup('site-settings:main');
|
||||
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()
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
{{#if showSignatures}}
|
||||
{{#if user_signature_url}}
|
||||
<hr>
|
||||
<img src="{{user_signature_url}}" class="signature-img">
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
@ -1,10 +1,22 @@
|
||||
<div class='controls'>
|
||||
<label class='checkbox-label'>
|
||||
{{input type="checkbox" checked=controller.model.custom_fields.see_signatures}}
|
||||
See user signatures below posts
|
||||
</label>
|
||||
<label class='text-label'>
|
||||
{{input type="text" value=controller.model.custom_fields.signature_url}}
|
||||
Signature URL Image
|
||||
</label>
|
||||
</div>
|
||||
{{#if signaturesEnabled}}
|
||||
<div class="control-group signatures">
|
||||
<label class="control-label">Signatures</label>
|
||||
<div class="controls">
|
||||
<label class='checkbox-label'>
|
||||
{{input type="checkbox" checked=controller.model.custom_fields.see_signatures}}
|
||||
See user signatures below posts
|
||||
</label>
|
||||
</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}}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
en:
|
||||
site_settings:
|
||||
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"
|
||||
|
||||
@ -2,3 +2,6 @@ plugins:
|
||||
signatures_enabled:
|
||||
default: true
|
||||
client: true
|
||||
signatures_advanced_mode:
|
||||
default: false
|
||||
client: true
|
||||
|
||||
13
plugin.rb
13
plugin.rb
@ -1,6 +1,6 @@
|
||||
# name: discourse-signatures
|
||||
# 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>
|
||||
# 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 << "signature_url"
|
||||
DiscoursePluginRegistry.serialized_current_user_fields << "signature_raw"
|
||||
|
||||
after_initialize do
|
||||
|
||||
User.register_custom_field_type('see_signatures', :boolean)
|
||||
User.register_custom_field_type('signature_url', :text)
|
||||
User.register_custom_field_type('signature_raw', :text)
|
||||
|
||||
if SiteSetting.signatures_enabled then
|
||||
add_to_serializer(:post, :user_signature_url, false) {
|
||||
object.user.custom_fields['signature_url']
|
||||
add_to_serializer(:post, :user_signature, false) {
|
||||
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?
|
||||
@ -31,5 +37,4 @@ after_initialize do
|
||||
end
|
||||
|
||||
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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user