diff --git a/app/controllers/home.js b/app/controllers/home.js index 7cd6326..1426454 100644 --- a/app/controllers/home.js +++ b/app/controllers/home.js @@ -70,11 +70,14 @@ class HomeController extends SiteController { } async getHome (req, res, next) { - const { link: linkService } = this.dtp.services; + const { link: linkService, user: userService } = this.dtp.services; try { res.locals.pagination = this.getPaginationParameters(req, 20); if (req.user) { res.locals.links = await linkService.getForUser(req.user, res.locals.pagination); + res.locals.recentLinks = await linkService.getRecent(3); + res.locals.popularLinks = await linkService.getPopular(3); + res.locals.recentUsers = await userService.getRecent(3); res.render('index-logged-in'); } else { res.render('index'); diff --git a/app/models/lib/resource-stats.js b/app/models/lib/resource-stats.js index e90b4dc..420c064 100644 --- a/app/models/lib/resource-stats.js +++ b/app/models/lib/resource-stats.js @@ -9,7 +9,7 @@ const mongoose = require('mongoose'); const Schema = mongoose.Schema; module.exports.ResourceStats = new Schema({ - uniqueVisitCount: { type: Number, default: 0, required: true }, + uniqueVisitCount: { type: Number, default: 0, required: true, index: -1 }, totalVisitCount: { type: Number, default: 0, required: true }, }); diff --git a/app/services/link.js b/app/services/link.js index 70d2e33..0ba51e4 100644 --- a/app/services/link.js +++ b/app/services/link.js @@ -94,6 +94,24 @@ class LinkService extends SiteService { return links; } + async getRecent (maxCount = 3) { + const links = await Link + .find() + .sort({ created: -1 }) + .limit(maxCount) + .lean(); + return links; + } + + async getPopular (maxCount) { + const links = await Link + .find() + .sort({ 'stats.uniqueVisitCount': -1 }) + .limit(maxCount) + .lean(); + return links; + } + async remove (link) { this.log.debug('removing link visit records', { link: link._id }); await LinkVisit.deleteMany({ link: link._id }); diff --git a/app/services/user.js b/app/services/user.js index d2430f9..3612095 100644 --- a/app/services/user.js +++ b/app/services/user.js @@ -303,6 +303,16 @@ class UserService { return user; } + async getRecent (maxCount = 3) { + const users = User + .find() + .select('_id created username username_lc displayName bio picture') + .sort({ created: -1 }) + .limit(maxCount) + .lean(); + return users; + } + async setUserSettings (user, settings) { const { crypto: cryptoService, diff --git a/app/views/components/page-sidebar.pug b/app/views/components/page-sidebar.pug index b799af1..7d91b1a 100644 --- a/app/views/components/page-sidebar.pug +++ b/app/views/components/page-sidebar.pug @@ -1,40 +1,33 @@ -mixin renderSidebarEpisode(episode) - .uk-card.uk-card-secondary.uk-card-small.uk-card-hover - - .uk-card-media-top - a(href= episode.url, target="_blank", title="Watch on Gab TV") - img(src=episode.image).responsive - - .uk-card-body - .uk-card-title.uk-margin-remove.uk-text-truncate - a(href= episode.url, target="_blank", title= `Watch "${episode.title}" on Gab TV`)= episode.title - .uk-text-small Posted: #{moment(episode.date_modified).format("MMM DD YYYY HH:MM a")} - mixin renderPageSidebar ( ) - //- Gab TV 3 Most Recent Episodes - .uk-margin - +renderSectionTitle('Gab TV', { - label: 'Visit Channel', - title: gabTvChannel.title, - url: gabTvChannel.home_page_url, - }) - ul.uk-list - each episode in gabTvChannel.items.slice(0, 3) - li - +renderSidebarEpisode(episode) + .uk-margin + +renderSectionTitle('Popular Links') + if Array.isArray(popularLinks) && (popularLinks.length > 0) + ul.uk-list + each link in popularLinks + li + form(method="POST", action=`/link/visit/${link._id}`).uk-form.uk-display-block.uk-width-1-1 + button(type="submit").uk-button.dtp-button-secondary.uk-display-block.uk-border-rounded.uk-width-1-1= link.label + else + div No links available. Check back later. - //- Newsletter Signup - div(uk-sticky={ offset: 60, bottom: '#dtp-content-grid' }) - +renderSectionTitle('Mailing List') - .uk-margin - form(method="post", action="/newsletter", onsubmit="return dtp.app.submitForm(event, 'Subscribe to newsletter');").uk-form - .uk-card.uk-card-secondary.uk-card-small - .uk-card-body - p Join the #{site.name} FREE newsletter to get show updates in your inbox. - .uk-margin - label(for="email").uk-form-label.sr-only Email Address - input(id="email", name="email", type="email", placeholder="johnsmith@example.com").uk-input + .uk-margin + +renderSectionTitle('New Links') + if Array.isArray(recentLinks) && (recentLinks.length > 0) + ul.uk-list + each link in recentLinks + li + form(method="POST", action=`/link/visit/${link._id}`).uk-form.uk-display-block.uk-width-1-1 + button(type="submit").uk-button.dtp-button-secondary.uk-display-block.uk-border-rounded.uk-width-1-1= link.label + else + div No new links. Check back later. - .uk-card-footer - button(type="submit").uk-button.dtp-button-primary.uk-button-small Sign Up \ No newline at end of file + .uk-margin + +renderSectionTitle('New Members') + if Array.isArray(recentUsers) && (recentUsers.length > 0) + ul.uk-list + each newUser in recentUsers + li + a(href=`/${newUser.username}`).uk-button.dtp-button-secondary.uk-display-block.uk-border-rounded.uk-width-1-1= newUser.displayName || newUser.username + else + div No new members. Check back later. \ No newline at end of file diff --git a/app/views/index-logged-in.pug b/app/views/index-logged-in.pug index 7f2507d..c4db4e6 100644 --- a/app/views/index-logged-in.pug +++ b/app/views/index-logged-in.pug @@ -1,34 +1,32 @@ -extends layouts/main +extends layouts/main-sidebar block content include link/components/list-item include link/components/editor - section.uk-section.uk-section-default - .uk-container.uk-width-xlarge - .uk-margin - div(uk-grid).uk-grid-small - .uk-width-expand - h3.uk-heading-bullet.uk-margin-small Your links - .uk-width-auto - a(href='/dashboard').uk-button.dtp-button-default.uk-button-small - +renderButtonIcon('fa-tachometer-alt', 'Dashboard') - .uk-width-auto - button(type="button", uk-toggle={ target: '#link-editor' }).uk-button.dtp-button-primary.uk-button-small - +renderButtonIcon('fa-plus', 'Add Link') - - .uk-margin - #link-editor(hidden).uk-card.uk-card-secondary.uk-card-small.uk-card-body - +renderLinkEditor('#link-editor') + .uk-margin-large + div(uk-grid).uk-grid-small.uk-flex-middle + .uk-width-expand + h1.uk-margin-remove= user.displayName || user.username + .uk-width-auto + a(href='/dashboard').uk-button.dtp-button-default.uk-button-small + +renderButtonIcon('fa-tachometer-alt', 'Dashboard') + .uk-width-auto + button(type="button", uk-toggle={ target: '#link-editor' }).uk-button.dtp-button-primary.uk-button-small + +renderButtonIcon('fa-plus', 'Add Link') + + #link-editor(hidden).uk-margin-large + .uk-card.uk-card-secondary.uk-card-small.uk-card-body + +renderLinkEditor('#link-editor') - .uk-margin - if Array.isArray(links) && (links.length > 0) - ul#links-list.uk-list - each link in links - +renderLinksListItem(link) + .uk-margin + if Array.isArray(links) && (links.length > 0) + ul#links-list.uk-list.uk-list-divider + each link in links + +renderLinksListItem(link) - else - div You have no links. + else + div You have no links. block viewjs script. diff --git a/app/views/layouts/main-sidebar.pug b/app/views/layouts/main-sidebar.pug index 55e474a..cf3ea63 100644 --- a/app/views/layouts/main-sidebar.pug +++ b/app/views/layouts/main-sidebar.pug @@ -7,7 +7,8 @@ block content-container div(class="uk-width-1-1 uk-width-2-3@m") block content div(class="uk-width-1-1 uk-width-1-3@m") - +renderPageSidebar() + block sidebar + +renderPageSidebar() block page-footer include ../components/page-footer \ No newline at end of file