Browse Source

Merge branch 'develop' of git.digitaltelepresence.com:digital-telepresence/dtp-base into develop

pull/36/head
Rob Colbert 2 years ago
parent
commit
333cc23367
  1. 9
      app/controllers/home.js
  2. 14
      app/controllers/user.js
  3. 11
      app/services/feed.js
  4. 2
      app/views/admin/layouts/main.pug
  5. 4
      app/views/components/library.pug
  6. 2
      app/views/components/navbar.pug
  7. 2
      app/views/components/off-canvas.pug
  8. 2
      app/views/layouts/main-sidebar.pug
  9. 10
      app/views/newsroom/components/feed-entry-list-item.pug
  10. 7
      client/less/site/main.less
  11. 5
      dtp-sites.js
  12. 7
      lib/site-common.js

9
app/controllers/home.js

@ -63,12 +63,7 @@ class HomeController extends SiteController {
}
async getHome (req, res, next) {
const {
announcement: announcementService,
feed: feedService,
hive: hiveService,
post: postService,
} = this.dtp.services;
const { announcement: announcementService, hive: hiveService, post: postService } = this.dtp.services;
try {
res.locals.announcements = await announcementService.getLatest(req.user);
res.locals.featuredPosts = await postService.getFeaturedPosts(3);
@ -77,8 +72,6 @@ class HomeController extends SiteController {
res.locals.pagination = this.getPaginationParameters(req, 20);
res.locals.posts = await postService.getPosts(res.locals.pagination);
res.locals.newsfeed = await feedService.getNewsfeed();
res.render('index');
} catch (error) {
this.log.error('failed to render home view', { error });

14
app/controllers/user.js

@ -33,12 +33,12 @@ class UserController extends SiteController {
const otpSetup = otpAuthService.middleware('Account', {
adminRequired: false,
otpRequired: true,
otpRedirectURL: async (req) => { return `/user/${req.user._id}`; },
otpRedirectURL: async (req) => { return `/user/${req.user.username}`; },
});
const otpMiddleware = otpAuthService.middleware('Account', {
adminRequired: false,
otpRequired: false,
otpRedirectURL: async (req) => { return `/user/${req.user._id}`; },
otpRedirectURL: async (req) => { return `/user/${req.user.username}`; },
});
router.use(
@ -61,8 +61,8 @@ class UserController extends SiteController {
}
router.param('username', this.populateUsername.bind(this));
router.param('userId', this.populateUser.bind(this));
router.param('coreUserId', this.populateCoreUser.bind(this));
router.param('userId', this.populateUserId.bind(this));
router.param('coreUserId', this.populateCoreUserId.bind(this));
router.post(
'/core/:coreUserId/settings',
@ -162,7 +162,7 @@ class UserController extends SiteController {
}
}
async populateUser (req, res, next, userId) {
async populateUserId (req, res, next, userId) {
const { user: userService } = this.dtp.services;
try {
userId = mongoose.Types.ObjectId(userId);
@ -178,7 +178,7 @@ class UserController extends SiteController {
}
}
async populateCoreUser (req, res, next, coreUserId) {
async populateCoreUserId (req, res, next, coreUserId) {
const { coreNode: coreNodeService } = this.dtp.services;
try {
coreUserId = mongoose.Types.ObjectId(coreUserId);
@ -218,7 +218,7 @@ class UserController extends SiteController {
if (error) {
return next(error);
}
res.redirect(`/user/${res.locals.user._id}`);
res.redirect(`/user/${res.locals.user.username}`);
});
} catch (error) {
this.log.error('failed to create new user', { error });

11
app/services/feed.js

@ -30,6 +30,17 @@ class FeedService extends SiteService {
this.jobQueue = await this.getJobQueue('newsroom', this.dtp.config.jobQueues.newsroom);
}
middleware (options) {
options = Object.assign({ maxEntryCount: 5 }, options);
return async (req, res, next) => {
if (this.isSystemRoute(req.path)) {
return next(); // don't load newsfeeds for non-content routes
}
res.locals.newsfeed = await this.getNewsfeed({ skip: 0, cpp: options.maxEntryCount });
return next();
};
}
async create (feedDefinition) {
feedDefinition.url = feedDefinition.url.trim();
const feedContent = await this.load(feedDefinition.url);

2
app/views/admin/layouts/main.pug

@ -16,4 +16,4 @@ block content-container
include ../components/menu
div(class="uk-width-1-1 uk-flex-first uk-width-expand@m").uk-width-expand
block content
block content

4
app/views/components/library.pug

@ -40,7 +40,7 @@ include section-title
function getUserProfileUrl (user) {
if (user.core) {
return `/user/core/${user._id}`;
return `/user/core/${user.username}`;
}
return `/user/${user.username}`;
}
@ -60,6 +60,6 @@ mixin renderBackButton (options)
mixin renderUserLink (user)
if user.coreUserId
a(href=`/user/core/${user._id}`)= `${user.username}@${user.core.meta.domainKey}`
a(href=`/user/core/${user.username}`)= `${user.username}@${user.core.meta.domainKey}`
else
a(href=`/user/${user.username}`)= user.displayName || user.username

2
app/views/components/navbar.pug

@ -67,7 +67,7 @@ nav(uk-navbar).uk-navbar-container.uk-position-fixed.uk-position-top
li.uk-nav-heading.uk-text-center= user.displayName || user.username
li.uk-nav-divider
li
a(href= user.core ? `/user/core/${user._id}` : `/user/${user.username}`)
a(href= user.core ? `/user/core/${user.username}` : `/user/${user.username}`)
span.nav-item-icon
i.fas.fa-user
span Profile

2
app/views/components/off-canvas.pug

@ -60,7 +60,7 @@ mixin renderMenuItem (iconClass, label)
.uk-width-expand Chat
li(class={ "uk-active": (currentView === 'user-settings') })
a(href=`/user/${user._id}`).uk-display-block
a(href=`/user/${user.username}`).uk-display-block
div(uk-grid).uk-grid-collapse
.uk-width-auto
.app-menu-icon

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

@ -1,6 +1,8 @@
extends main
block content-container
block content-header
section.uk-section.uk-section-default.uk-section-small
.uk-container
div(uk-grid)#dtp-content-grid

10
app/views/newsroom/components/feed-entry-list-item.pug

@ -1,9 +1,9 @@
mixin renderNewsroomFeedEntryListItem (entry)
.uk-text-bold
a(href= entry.link, target="_blank").uk-link-reset= entry.title
.uk-text-small
div(uk-grid).uk-grid-small
.uk-width-expand
a(href= entry.link, target="_blank").dtp-link
div= entry.title
.uk-article-meta
div(uk-grid).uk-grid-small.uk-grid-divider
.uk-width-auto.uk-text-truncate
a(href= entry.feed.link, target="_blank").uk-link-reset= entry.feed.title
.uk-width-auto
div= moment(entry.published).fromNow()

7
client/less/site/main.less

@ -50,6 +50,13 @@ body {
}
}
a.dtp-link {
color: inherit;
&:hover {
color: @global-link-hover-color;
}
}
.dtp-site-footer {
.uk-subnav {
a.dtp-social-link {

5
dtp-sites.js

@ -22,15 +22,16 @@ module.config = {
http: require(path.join(module.rootPath, 'config', 'http')),
https: require(path.join(module.rootPath, 'config', 'https')),
registerMiddleware: async (dtp, app) => {
module.log.info('registering Page service middleware');
const {
feed: feedService,
gabTV: gabTvService,
page: pageService,
siteLink: siteLinkService,
venue: venueService,
} = module.services;
app.use(
feedService.middleware({ maxEntryCount: 5 }),
pageService.menuMiddleware.bind(pageService),
siteLinkService.middleware(),
venueService.channelMiddleware(),
@ -42,7 +43,7 @@ module.config = {
module.log = new SiteLog(module, module.config.component);
module.shutdown = async ( ) => {
await SitePlatform.shutdown();
};
(async ( ) => {

7
lib/site-common.js

@ -106,6 +106,13 @@ class SiteCommon extends EventEmitter2 {
});
}
isSystemRoute (pathname) {
return pathname.startsWith('/auth') ||
pathname.startsWith('/image') ||
pathname.startsWith('/manifest')
;
}
isValidString (text) {
return text && (typeof text === 'string') && (text.length > 0);
}

Loading…
Cancel
Save