FEATURE: Display "Last Updated At" on user directory
This commit is contained in:
parent
0996c3b7b3
commit
db35baba26
|
@ -1,4 +1,5 @@
|
|||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
import { longDate } from "discourse/lib/formatter";
|
||||
|
||||
export default DiscourseRoute.extend({
|
||||
queryParams: {
|
||||
|
@ -22,7 +23,8 @@ export default DiscourseRoute.extend({
|
|||
asc: null,
|
||||
name: "",
|
||||
group: null,
|
||||
exclude_usernames: null
|
||||
exclude_usernames: null,
|
||||
lastUpdatedAt: null
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -41,8 +43,10 @@ export default DiscourseRoute.extend({
|
|||
|
||||
setupController(controller, model) {
|
||||
const params = this._params;
|
||||
const lastUpdatedAt = model.get("resultSetMeta.last_updated_at");
|
||||
controller.setProperties({
|
||||
model,
|
||||
lastUpdatedAt: lastUpdatedAt ? longDate(lastUpdatedAt) : null,
|
||||
period: params.period,
|
||||
nameInput: params.name
|
||||
});
|
||||
|
|
|
@ -3,8 +3,14 @@
|
|||
<div class='directory'>
|
||||
{{plugin-outlet name="users-top" connectorTagName='div' args=(hash model=model)}}
|
||||
|
||||
<div class='clearfix user-controls'>
|
||||
<div class='directory-controls'>
|
||||
{{period-chooser period=period onChange=(action (mut period))}}
|
||||
{{#if lastUpdatedAt}}
|
||||
<div class='directory-last-updated'>
|
||||
{{i18n "directory.last_updated"}}
|
||||
{{lastUpdatedAt}}
|
||||
</div>
|
||||
{{/if}}
|
||||
{{text-field value=nameInput placeholderKey="directory.filter_name" class="filter-name no-blur"}}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -3,8 +3,16 @@
|
|||
<div class="container">
|
||||
<div class='directory'>
|
||||
{{plugin-outlet name="users-top" connectorTagName='div' args=(hash model=model)}}
|
||||
<div class='clearfix'>
|
||||
{{period-chooser period=period onChange=(action (mut period))}}
|
||||
<div class='directory-controls'>
|
||||
<div class='period-controls'>
|
||||
{{period-chooser period=period onChange=(action (mut period))}}
|
||||
{{#if lastUpdatedAt}}
|
||||
<div class='directory-last-updated'>
|
||||
{{i18n "directory.last_updated"}}
|
||||
{{lastUpdatedAt}}
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{text-field value=nameInput placeholderKey="directory.filter_name" class="filter-name no-blur"}}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -5,16 +5,22 @@
|
|||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.period-chooser {
|
||||
float: left;
|
||||
}
|
||||
.filter-name {
|
||||
float: right;
|
||||
}
|
||||
.spinner {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.directory-controls {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
.filter-name {
|
||||
height: 1em;
|
||||
}
|
||||
}
|
||||
.directory-last-updated {
|
||||
margin-bottom: 0.5em;
|
||||
color: $primary-medium;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
margin-bottom: 1em;
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
margin-bottom: 0.25em;
|
||||
}
|
||||
|
||||
.filter-name {
|
||||
float: left;
|
||||
.directory-controls {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.total-rows {
|
||||
|
|
|
@ -79,7 +79,9 @@ class DirectoryItemsController < ApplicationController
|
|||
|
||||
end
|
||||
|
||||
last_updated_at = DirectoryItem.last_updated_at(period_type)
|
||||
render_json_dump(directory_items: serialize_data(result, DirectoryItemSerializer),
|
||||
meta: { last_updated_at: last_updated_at },
|
||||
total_rows_directory_items: result_count,
|
||||
load_more_directory_items: directory_items_path(more_params))
|
||||
end
|
||||
|
|
|
@ -27,8 +27,17 @@ class DirectoryItem < ActiveRecord::Base
|
|||
period_types.each_key { |p| refresh_period!(p) }
|
||||
end
|
||||
|
||||
def self.last_updated_at(period_type)
|
||||
val = Discourse.redis.get("directory_#{period_type}")
|
||||
return nil if val.nil?
|
||||
|
||||
Time.zone.at(val.to_i)
|
||||
end
|
||||
|
||||
def self.refresh_period!(period_type, force: false)
|
||||
|
||||
Discourse.redis.set("directory_#{period_types[period_type]}", Time.zone.now.to_i)
|
||||
|
||||
# Don't calculate it if the user directory is disabled
|
||||
return unless SiteSetting.enable_user_directory? || force
|
||||
|
||||
|
|
|
@ -587,6 +587,7 @@ en:
|
|||
days_visited_long: "Days Visited"
|
||||
posts_read: "Read"
|
||||
posts_read_long: "Posts Read"
|
||||
last_updated: "Last Updated:"
|
||||
total_rows:
|
||||
one: "%{count} user"
|
||||
other: "%{count} users"
|
||||
|
|
|
@ -46,6 +46,7 @@ describe DirectoryItemsController do
|
|||
expect(json['directory_items']).to be_present
|
||||
expect(json['total_rows_directory_items']).to be_present
|
||||
expect(json['load_more_directory_items']).to be_present
|
||||
expect(json['meta']['last_updated_at']).to be_present
|
||||
|
||||
expect(json['directory_items'].length).to eq(4)
|
||||
expect(json['total_rows_directory_items']).to eq(4)
|
||||
|
|
Loading…
Reference in New Issue