Browse Source

sidebar for popular and recent links; new members

pull/1/head
Rob Colbert 3 years ago
parent
commit
1fab21c756
  1. 5
      app/controllers/home.js
  2. 2
      app/models/lib/resource-stats.js
  3. 18
      app/services/link.js
  4. 10
      app/services/user.js
  5. 65
      app/views/components/page-sidebar.pug
  6. 44
      app/views/index-logged-in.pug
  7. 3
      app/views/layouts/main-sidebar.pug

5
app/controllers/home.js

@ -70,11 +70,14 @@ class HomeController extends SiteController {
} }
async getHome (req, res, next) { async getHome (req, res, next) {
const { link: linkService } = this.dtp.services; const { link: linkService, user: userService } = this.dtp.services;
try { try {
res.locals.pagination = this.getPaginationParameters(req, 20); res.locals.pagination = this.getPaginationParameters(req, 20);
if (req.user) { if (req.user) {
res.locals.links = await linkService.getForUser(req.user, res.locals.pagination); 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'); res.render('index-logged-in');
} else { } else {
res.render('index'); res.render('index');

2
app/models/lib/resource-stats.js

@ -9,7 +9,7 @@ const mongoose = require('mongoose');
const Schema = mongoose.Schema; const Schema = mongoose.Schema;
module.exports.ResourceStats = new 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 }, totalVisitCount: { type: Number, default: 0, required: true },
}); });

18
app/services/link.js

@ -94,6 +94,24 @@ class LinkService extends SiteService {
return links; 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) { async remove (link) {
this.log.debug('removing link visit records', { link: link._id }); this.log.debug('removing link visit records', { link: link._id });
await LinkVisit.deleteMany({ link: link._id }); await LinkVisit.deleteMany({ link: link._id });

10
app/services/user.js

@ -303,6 +303,16 @@ class UserService {
return user; 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) { async setUserSettings (user, settings) {
const { const {
crypto: cryptoService, crypto: cryptoService,

65
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 ( ) 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 .uk-margin
each episode in gabTvChannel.items.slice(0, 3) +renderSectionTitle('Popular Links')
li if Array.isArray(popularLinks) && (popularLinks.length > 0)
+renderSidebarEpisode(episode) 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 .uk-margin
div(uk-sticky={ offset: 60, bottom: '#dtp-content-grid' }) +renderSectionTitle('New Links')
+renderSectionTitle('Mailing List') if Array.isArray(recentLinks) && (recentLinks.length > 0)
.uk-margin ul.uk-list
form(method="post", action="/newsletter", onsubmit="return dtp.app.submitForm(event, 'Subscribe to newsletter');").uk-form each link in recentLinks
.uk-card.uk-card-secondary.uk-card-small li
.uk-card-body form(method="POST", action=`/link/visit/${link._id}`).uk-form.uk-display-block.uk-width-1-1
p Join the #{site.name} FREE newsletter to get show updates in your inbox. button(type="submit").uk-button.dtp-button-secondary.uk-display-block.uk-border-rounded.uk-width-1-1= link.label
.uk-margin else
label(for="email").uk-form-label.sr-only Email Address div No new links. Check back later.
input(id="email", name="email", type="email", placeholder="[email protected]").uk-input
.uk-card-footer .uk-margin
button(type="submit").uk-button.dtp-button-primary.uk-button-small Sign Up +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.

44
app/views/index-logged-in.pug

@ -1,34 +1,32 @@
extends layouts/main extends layouts/main-sidebar
block content block content
include link/components/list-item include link/components/list-item
include link/components/editor include link/components/editor
section.uk-section.uk-section-default .uk-margin-large
.uk-container.uk-width-xlarge div(uk-grid).uk-grid-small.uk-flex-middle
.uk-margin .uk-width-expand
div(uk-grid).uk-grid-small h1.uk-margin-remove= user.displayName || user.username
.uk-width-expand .uk-width-auto
h3.uk-heading-bullet.uk-margin-small Your links a(href='/dashboard').uk-button.dtp-button-default.uk-button-small
.uk-width-auto +renderButtonIcon('fa-tachometer-alt', 'Dashboard')
a(href='/dashboard').uk-button.dtp-button-default.uk-button-small .uk-width-auto
+renderButtonIcon('fa-tachometer-alt', 'Dashboard') button(type="button", uk-toggle={ target: '#link-editor' }).uk-button.dtp-button-primary.uk-button-small
.uk-width-auto +renderButtonIcon('fa-plus', 'Add Link')
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-margin-large
#link-editor(hidden).uk-card.uk-card-secondary.uk-card-small.uk-card-body .uk-card.uk-card-secondary.uk-card-small.uk-card-body
+renderLinkEditor('#link-editor') +renderLinkEditor('#link-editor')
.uk-margin .uk-margin
if Array.isArray(links) && (links.length > 0) if Array.isArray(links) && (links.length > 0)
ul#links-list.uk-list ul#links-list.uk-list.uk-list-divider
each link in links each link in links
+renderLinksListItem(link) +renderLinksListItem(link)
else else
div You have no links. div You have no links.
block viewjs block viewjs
script. script.

3
app/views/layouts/main-sidebar.pug

@ -7,7 +7,8 @@ block content-container
div(class="uk-width-1-1 uk-width-2-3@m") div(class="uk-width-1-1 uk-width-2-3@m")
block content block content
div(class="uk-width-1-1 uk-width-1-3@m") div(class="uk-width-1-1 uk-width-1-3@m")
+renderPageSidebar() block sidebar
+renderPageSidebar()
block page-footer block page-footer
include ../components/page-footer include ../components/page-footer
Loading…
Cancel
Save