From cff3d510f28061faf7373e8b5cb08c862c1dc30e Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 1 Jul 2021 17:50:38 +0100 Subject: [PATCH] FIX: Update for Discourse core changes (#3) - Adds support for core's customizable user directory: https://meta.discourse.org/t/195263 - Adds a new theme component setting which allows the statistics to be hidden completely from the user cards - Uses core's new group filter functionality - Adds .discourse-compatibility so that this component can still be installed successfully on older Discourse versions --- .discourse-compatibility | 1 + .../initializers/user-card-directory.js.es6 | 24 +------ javascripts/discourse/templates/users.hbs | 63 ++++++++++++++----- locales/en.yml | 1 + settings.yml | 1 + 5 files changed, 51 insertions(+), 39 deletions(-) create mode 100644 .discourse-compatibility diff --git a/.discourse-compatibility b/.discourse-compatibility new file mode 100644 index 0000000..9d40fd3 --- /dev/null +++ b/.discourse-compatibility @@ -0,0 +1 @@ +2.8.0.beta1: d9ed154f9887dcf48e648d7fa8af76c65caa5006 \ No newline at end of file diff --git a/javascripts/discourse/initializers/user-card-directory.js.es6 b/javascripts/discourse/initializers/user-card-directory.js.es6 index 409efca..6100e42 100644 --- a/javascripts/discourse/initializers/user-card-directory.js.es6 +++ b/javascripts/discourse/initializers/user-card-directory.js.es6 @@ -29,34 +29,12 @@ export default { this._super(...arguments); }, - stats: [ - { name: "likes_received", icon: "heart" }, - { name: "likes_given", icon: "heart" }, - { name: "topic_count" }, - { name: "post_count" }, - { name: "topics_entered" }, - { name: "posts_read" }, - { name: "days_visited" } - ], - - @discourseComputed("site.groups") - availableGroups(groups) { - return groups - .map(g => { - // prevents group "everyone" to be listed - if (g.id !== 0) { - return { name: g.name, value: g.name }; - } - }) - .filter(Boolean); - }, - @discourseComputed("model.content.@each") userCards(allUsers) { if (!allUsers) return []; const toLoad = []; if (settings.hide_current_user && this.currentUser) { - allUsers = allUsers.filter((u) => u.id !== this.currentUser.id) + allUsers = allUsers.filter((u) => u.id !== this.currentUser.id); } const userCardInfos = allUsers.map(u => { if (this.cachedUserCardInfo[u.id]) { diff --git a/javascripts/discourse/templates/users.hbs b/javascripts/discourse/templates/users.hbs index 271f9df..3ba2129 100644 --- a/javascripts/discourse/templates/users.hbs +++ b/javascripts/discourse/templates/users.hbs @@ -2,8 +2,7 @@ {{#load-more selector=".user-card-directory .user-card-container" action=(action "loadMore")}}
- {{plugin-outlet name="users-top" connectorTagName='div' args=(hash model=model)}} - + {{plugin-outlet name="users-top" connectorTagName="div" args=(hash model=model)}}
{{period-chooser period=period onChange=(action (mut period)) fullDay=false}} @@ -14,20 +13,38 @@
{{/if}}
-
- - {{combo-box content=availableGroups - value=group - options=(hash clearable=true none=(theme-prefix 'filter_by_group')) - valueAttribute="value"}} - - - {{text-field value=nameInput placeholderKey="directory.filter_name" class="filter-name no-blur"}} +
+ + {{#if model.totalRows}} + {{i18n "directory.total_rows" count=model.totalRows}} + {{/if}} + {{input + value=(readonly nameInput) + input=(action "onUsernameFilterChanged" value="target.value") + placeholderKey="directory.filter_name" + class="filter-name no-blur" + }} + {{combo-box + class="directory-group-selector" + value=group + content=groupOptions + onChange=(action groupChanged) + options=(hash + none="directory.group.all" + ) + }} + {{#if currentUser.staff}} + {{d-button + icon="wrench" + action=(action "showEditColumnsModal") + class="btn-default open-edit-columns-btn" + }} + {{/if}}
- {{#conditional-loading-spinner condition=model.loading}} + {{#conditional-loading-spinner condition=isLoading}} {{#if userCards.length}}
{{#each userCards as |userCard|}} @@ -38,24 +55,38 @@ loading=userCard.loading username=userCard.user.username }} + {{#if (theme-setting 'show_stats')}} + {{/if}}
{{/each}}
{{conditional-loading-spinner condition=model.loadingMore}} {{else}} -
+

{{i18n "directory.no_results"}}

{{/if}} {{/conditional-loading-spinner}} diff --git a/locales/en.yml b/locales/en.yml index f10a209..2bdb2ee 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -3,4 +3,5 @@ en: description: Replaces the user directory with a grid of user cards settings: hide_current_user: Always hide the current user from the grid + show_stats: Show statistics under each user card filter_by_group: filter by group diff --git a/settings.yml b/settings.yml index 2ad2763..7fb3489 100644 --- a/settings.yml +++ b/settings.yml @@ -1 +1,2 @@ hide_current_user: false +show_stats: true