diff --git a/assets/javascripts/discourse-staff-notes/connectors/admin-user-controls-after/add-staff-notes-button.js.es6 b/assets/javascripts/discourse-staff-notes/connectors/admin-user-controls-after/add-staff-notes-button.js.es6 new file mode 100644 index 0000000..a846230 --- /dev/null +++ b/assets/javascripts/discourse-staff-notes/connectors/admin-user-controls-after/add-staff-notes-button.js.es6 @@ -0,0 +1,4 @@ +import connector from 'discourse/plugins/staff-notes/discourse-staff-notes/connectors/user-profile-controls/show-notes-on-profile'; + +// Same as other connector +export default connector; diff --git a/assets/javascripts/discourse-staff-notes/connectors/user-profile-controls/show-notes-on-profile.js.es6 b/assets/javascripts/discourse-staff-notes/connectors/user-profile-controls/show-notes-on-profile.js.es6 index ef377cf..db13a50 100644 --- a/assets/javascripts/discourse-staff-notes/connectors/user-profile-controls/show-notes-on-profile.js.es6 +++ b/assets/javascripts/discourse-staff-notes/connectors/user-profile-controls/show-notes-on-profile.js.es6 @@ -9,7 +9,10 @@ export default { setupComponent(args, component) { const { model } = args; - component.set('staffNotesCount', model.get('custom_fields.staff_notes_count') || 0); + component.set( + 'staffNotesCount', + model.get('staff_notes_count') || model.get('custom_fields.staff_notes_count') || 0 + ); }, actions: { diff --git a/assets/javascripts/discourse-staff-notes/templates/connectors/admin-user-controls-after/add-staff-notes-button.hbs b/assets/javascripts/discourse-staff-notes/templates/connectors/admin-user-controls-after/add-staff-notes-button.hbs new file mode 100644 index 0000000..15c8b7b --- /dev/null +++ b/assets/javascripts/discourse-staff-notes/templates/connectors/admin-user-controls-after/add-staff-notes-button.hbs @@ -0,0 +1 @@ +{{show-staff-notes show="showStaffNotes" count=staffNotesCount}} diff --git a/assets/javascripts/discourse-staff-notes/templates/connectors/user-profile-controls/show-notes-on-profile.hbs b/assets/javascripts/discourse-staff-notes/templates/connectors/user-profile-controls/show-notes-on-profile.hbs index 14c0efe..fa4c53d 100644 --- a/assets/javascripts/discourse-staff-notes/templates/connectors/user-profile-controls/show-notes-on-profile.hbs +++ b/assets/javascripts/discourse-staff-notes/templates/connectors/user-profile-controls/show-notes-on-profile.hbs @@ -1,9 +1 @@ -{{#if siteSettings.staff_notes_enabled}} - {{#if currentUser.staff}} - {{#if staffNotesCount}} -
  • {{fa-icon "pencil"}}{{i18n 'staff_notes.show' count=staffNotesCount}}
  • - {{else}} -
  • {{fa-icon "pencil"}}{{i18n 'staff_notes.title'}}
  • - {{/if}} - {{/if}} -{{/if}} +
  • {{show-staff-notes show="showStaffNotes" count=staffNotesCount}}
  • diff --git a/assets/javascripts/discourse/components/show-staff-notes.js.es6 b/assets/javascripts/discourse/components/show-staff-notes.js.es6 new file mode 100644 index 0000000..fdbc665 --- /dev/null +++ b/assets/javascripts/discourse/components/show-staff-notes.js.es6 @@ -0,0 +1,14 @@ +import computed from 'ember-addons/ember-computed-decorators'; + +export default Ember.Component.extend({ + tagName: '', + + @computed('count') + showCount: count => count && count > 0, + + actions: { + show() { + this.sendAction('show'); + } + } +}); diff --git a/assets/javascripts/discourse/templates/components/show-staff-notes.hbs b/assets/javascripts/discourse/templates/components/show-staff-notes.hbs new file mode 100644 index 0000000..11b7d71 --- /dev/null +++ b/assets/javascripts/discourse/templates/components/show-staff-notes.hbs @@ -0,0 +1,8 @@ + + {{fa-icon "pencil"}} + {{#if showCount}} + {{i18n 'staff_notes.show' count=count}} + {{else}} + {{i18n 'staff_notes.title'}} + {{/if}} + diff --git a/plugin.rb b/plugin.rb index 9dccb37..614ca0c 100644 --- a/plugin.rb +++ b/plugin.rb @@ -142,6 +142,10 @@ after_initialize do (SiteSetting.staff_notes_moderators_delete? && user.staff?) || user.admin? end + add_to_serializer(:admin_detailed_user, :staff_notes_count, false) do + object.custom_fields && object.custom_fields['staff_notes_count'].to_i + end + DiscourseStaffNotes::Engine.routes.draw do get '/' => 'staff_notes#index' post '/' => 'staff_notes#create'