FEATURE: Display "Last Updated At" on user directory

FEATURE: Display “Last Updated At” on user directory

diff --git a/app/assets/javascripts/discourse/routes/users.js b/app/assets/javascripts/discourse/routes/users.js
index 4fec3c1..76f310d 100644
--- a/app/assets/javascripts/discourse/routes/users.js
+++ b/app/assets/javascripts/discourse/routes/users.js
@@ -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
     });
diff --git a/app/assets/javascripts/discourse/templates/mobile/users.hbs b/app/assets/javascripts/discourse/templates/mobile/users.hbs
index 776409d..7f208e2 100644
--- a/app/assets/javascripts/discourse/templates/mobile/users.hbs
+++ b/app/assets/javascripts/discourse/templates/mobile/users.hbs
@@ -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>
 
diff --git a/app/assets/javascripts/discourse/templates/users.hbs b/app/assets/javascripts/discourse/templates/users.hbs
index 6a44c7c..09f4ba4 100644
--- a/app/assets/javascripts/discourse/templates/users.hbs
+++ b/app/assets/javascripts/discourse/templates/users.hbs
@@ -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>
 
diff --git a/app/assets/stylesheets/common/base/directory.scss b/app/assets/stylesheets/common/base/directory.scss
index 4bc304f..8104526 100644
--- a/app/assets/stylesheets/common/base/directory.scss
+++ b/app/assets/stylesheets/common/base/directory.scss
@@ -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;
diff --git a/app/assets/stylesheets/mobile/directory.scss b/app/assets/stylesheets/mobile/directory.scss
index 90de7b3..c1057bd 100644
--- a/app/assets/stylesheets/mobile/directory.scss
+++ b/app/assets/stylesheets/mobile/directory.scss
@@ -6,8 +6,8 @@
     margin-bottom: 0.25em;
   }
 
-  .filter-name {
-    float: left;
+  .directory-controls {
+    display: block;
   }
 
   .total-rows {
diff --git a/app/controllers/directory_items_controller.rb b/app/controllers/directory_items_controller.rb
index 5cf99b7..9acc1a2 100644
--- a/app/controllers/directory_items_controller.rb
+++ b/app/controllers/directory_items_controller.rb
@@ -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
diff --git a/app/models/directory_item.rb b/app/models/directory_item.rb
index 89f8daf..930c782 100644
--- a/app/models/directory_item.rb
+++ b/app/models/directory_item.rb
@@ -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
 
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index c60d83b..98d4a5b 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -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"
diff --git a/spec/requests/directory_items_controller_spec.rb b/spec/requests/directory_items_controller_spec.rb
index 6d1e777..8dc0cca 100644
--- a/spec/requests/directory_items_controller_spec.rb
+++ b/spec/requests/directory_items_controller_spec.rb
@@ -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)

GitHub sha: db35baba