UX: sort admins and moderators by last seen date on /about page

UX: only show active admins and moderators on /about page
This commit is contained in:
Arpit Jalan 2019-01-15 17:25:22 +05:30
parent ff8f9dc1c9
commit c4422fdc13
4 changed files with 44 additions and 7 deletions

View File

@ -1,7 +1,23 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
export default Discourse.Route.extend({ export default Discourse.Route.extend({
model() { model() {
return ajax("/about.json").then(result => result.about); return ajax("/about.json").then(result => {
let activeAdmins = [];
let activeModerators = [];
const yearAgo = moment()
.locale("en")
.utc()
.subtract(1, "year");
result.about.admins.forEach(r => {
if (moment(r.last_seen_at) > yearAgo) activeAdmins.push(r);
});
result.about.moderators.forEach(r => {
if (moment(r.last_seen_at) > yearAgo) activeModerators.push(r);
});
result.about.admins = activeAdmins;
result.about.moderators = activeModerators;
return result.about;
});
}, },
titleToken() { titleToken() {

View File

@ -36,11 +36,13 @@ class About
def moderators def moderators
@moderators ||= User.where(moderator: true, admin: false) @moderators ||= User.where(moderator: true, admin: false)
.human_users .human_users
.order(:username_lower) .order("last_seen_at DESC")
end end
def admins def admins
@admins ||= User.where(admin: true).human_users.order(:username_lower) @admins ||= User.where(admin: true)
.human_users
.order("last_seen_at DESC")
end end
def stats def stats

View File

@ -1,6 +1,11 @@
class AboutSerializer < ApplicationSerializer class AboutSerializer < ApplicationSerializer
has_many :moderators, serializer: UserNameSerializer, embed: :objects
has_many :admins, serializer: UserNameSerializer, embed: :objects class UserAboutSerializer < BasicUserSerializer
attributes :title, :last_seen_at
end
has_many :moderators, serializer: UserAboutSerializer, embed: :objects
has_many :admins, serializer: UserAboutSerializer, embed: :objects
attributes :stats, attributes :stats,
:description, :description,

View File

@ -21,37 +21,43 @@ export default {
id: 3, id: 3,
username: "supermathie", username: "supermathie",
uploaded_avatar_id: 5247, uploaded_avatar_id: 5247,
avatar_template: "/images/avatar.png" avatar_template: "/images/avatar.png",
last_seen_at: "2019-01-15T06:17:45.799Z"
}, },
{ {
id: 32, id: 32,
username: "codinghorror", username: "codinghorror",
uploaded_avatar_id: 5297, uploaded_avatar_id: 5297,
avatar_template: "/images/avatar.png" avatar_template: "/images/avatar.png",
last_seen_at: "2019-01-15T06:17:45.799Z"
}, },
{ {
id: 19, id: 19,
username: "eviltrout", username: "eviltrout",
uploaded_avatar_id: 5275, uploaded_avatar_id: 5275,
avatar_template: "/images/avatar.png" avatar_template: "/images/avatar.png"
last_seen_at: "2019-01-15T06:17:45.799Z"
}, },
{ {
id: 2, id: 2,
username: "neil", username: "neil",
uploaded_avatar_id: 5245, uploaded_avatar_id: 5245,
avatar_template: "/images/avatar.png" avatar_template: "/images/avatar.png"
last_seen_at: "2019-01-15T06:17:45.799Z"
}, },
{ {
id: 1, id: 1,
username: "sam", username: "sam",
uploaded_avatar_id: 5243, uploaded_avatar_id: 5243,
avatar_template: "/images/avatar.png" avatar_template: "/images/avatar.png"
last_seen_at: "2019-01-15T06:17:45.799Z"
}, },
{ {
id: 1995, id: 1995,
username: "zogstrip", username: "zogstrip",
uploaded_avatar_id: 8630, uploaded_avatar_id: 8630,
avatar_template: "/images/avatar.png" avatar_template: "/images/avatar.png"
last_seen_at: "2019-01-15T06:17:45.799Z"
} }
], ],
admins: [ admins: [
@ -60,48 +66,56 @@ export default {
username: "supermathie", username: "supermathie",
uploaded_avatar_id: 5247, uploaded_avatar_id: 5247,
avatar_template: "/images/avatar.png" avatar_template: "/images/avatar.png"
last_seen_at: "2019-01-15T06:17:45.799Z"
}, },
{ {
id: 32, id: 32,
username: "codinghorror", username: "codinghorror",
uploaded_avatar_id: 5297, uploaded_avatar_id: 5297,
avatar_template: "/images/avatar.png" avatar_template: "/images/avatar.png"
last_seen_at: "2019-01-15T06:17:45.799Z"
}, },
{ {
id: 19, id: 19,
username: "eviltrout", username: "eviltrout",
uploaded_avatar_id: 5275, uploaded_avatar_id: 5275,
avatar_template: "/images/avatar.png" avatar_template: "/images/avatar.png"
last_seen_at: "2019-01-15T06:17:45.799Z"
}, },
{ {
id: 38, id: 38,
username: "frandallfarmer", username: "frandallfarmer",
uploaded_avatar_id: 5307, uploaded_avatar_id: 5307,
avatar_template: "/images/avatar.png" avatar_template: "/images/avatar.png"
last_seen_at: "2019-01-15T06:17:45.799Z"
}, },
{ {
id: 6626, id: 6626,
username: "riking", username: "riking",
uploaded_avatar_id: 9779, uploaded_avatar_id: 9779,
avatar_template: "/images/avatar.png" avatar_template: "/images/avatar.png"
last_seen_at: "2019-01-15T06:17:45.799Z"
}, },
{ {
id: 2, id: 2,
username: "neil", username: "neil",
uploaded_avatar_id: 5245, uploaded_avatar_id: 5245,
avatar_template: "/images/avatar.png" avatar_template: "/images/avatar.png"
last_seen_at: "2019-01-15T06:17:45.799Z"
}, },
{ {
id: 1, id: 1,
username: "sam", username: "sam",
uploaded_avatar_id: 5243, uploaded_avatar_id: 5243,
avatar_template: "/images/avatar.png" avatar_template: "/images/avatar.png"
last_seen_at: "2019-01-15T06:17:45.799Z"
}, },
{ {
id: 1995, id: 1995,
username: "zogstrip", username: "zogstrip",
uploaded_avatar_id: 8630, uploaded_avatar_id: 8630,
avatar_template: "/images/avatar.png" avatar_template: "/images/avatar.png"
last_seen_at: "2019-01-15T06:17:45.799Z"
} }
] ]
} }